Add Zthes tag-set -- where was it?!
[yaz-moved-to-github.git] / util / oid.c
1 /*
2  * Copyright (c) 1995-2002, Index Data
3  * See the file LICENSE for details.
4  *
5  * $Id: oid.c,v 1.58 2002-12-01 23:22:10 mike Exp $
6  */
7
8 /*
9  * More or less protocol-transparent OID database.
10  * We could (and should?) extend this so that the user app can add new
11  * entries to the list at initialization.
12  */
13 #if HAVE_CONFIG_H
14 #include <config.h>
15 #endif
16
17 #include <stdlib.h>
18 #include <string.h>
19 #include <ctype.h>
20
21 #include <yaz/oid.h>
22 #include <yaz/yaz-util.h>
23
24 static int z3950_prefix[] = { 1, 2, 840, 10003, -1 };
25 static int sr_prefix[]    = { 1, 0, 10163, -1 };
26
27 struct oident_list {
28     struct oident oident;
29     struct oident_list *next;
30 };
31
32 static struct oident_list *oident_table = NULL;
33 static int oid_value_dynamic = VAL_DYNAMIC;
34 static int oid_init_flag = 0;
35 static NMEM_MUTEX oid_mutex = 0;
36 static NMEM oid_nmem = 0;
37
38 /*
39  * OID database
40  */
41 static oident standard_oids[] =
42 {
43     /* General definitions */
44     {PROTO_GENERAL, CLASS_TRANSYN, VAL_BER,          {2,1,1,-1},
45      "BER" },
46     {PROTO_GENERAL, CLASS_TRANSYN, VAL_ISO2709,      {1,0,2709,1,1,-1},
47      "ISO2709"},
48     {PROTO_GENERAL, CLASS_GENERAL, VAL_ISO_ILL_1,    {1,0,10161,2,1,-1},
49      "ISOILL-1"},
50     /* Z39.50v3 definitions */
51     {PROTO_Z3950,   CLASS_ABSYN,   VAL_APDU,         {2,1,-1},
52      "Z-APDU"},    
53     {PROTO_Z3950,   CLASS_APPCTX,  VAL_BASIC_CTX,    {1,1,-1},
54      "Z-BASIC"},
55     {PROTO_Z3950,   CLASS_ATTSET,  VAL_BIB1,         {3,1,-1},
56      "Bib-1"},
57     {PROTO_Z3950,   CLASS_ATTSET,  VAL_EXP1,         {3,2,-1},
58      "Exp-1"},
59     {PROTO_Z3950,   CLASS_ATTSET,  VAL_EXT1,         {3,3,-1},
60      "Ext-1"},
61     {PROTO_Z3950,   CLASS_ATTSET,  VAL_CCL1,         {3,4,-1},
62      "CCL-1"},
63     {PROTO_Z3950,   CLASS_ATTSET,  VAL_GILS,         {3,5,-1},
64      "GILS-attset"},
65     {PROTO_Z3950,   CLASS_ATTSET,  VAL_GILS,         {3,5,-1},
66      "GILS"},
67     {PROTO_Z3950,   CLASS_ATTSET,  VAL_STAS,         {3,6,-1},
68      "STAS-attset"},
69     {PROTO_Z3950,   CLASS_ATTSET,  VAL_COLLECT1,     {3,7,-1},
70      "Collections-attset"},
71     {PROTO_Z3950,   CLASS_ATTSET,  VAL_CIMI1,        {3,8,-1},
72      "CIMI-attset"},
73     {PROTO_Z3950,   CLASS_ATTSET,  VAL_GEO,          {3,9,-1},
74      "Geo-attset"},
75
76     {PROTO_Z3950,   CLASS_ATTSET,  VAL_ZBIG,         {3,10,-1},
77      "ZBIG"},
78     {PROTO_Z3950,   CLASS_ATTSET,  VAL_UTIL,         {3,11,-1},
79      "Util"},
80     {PROTO_Z3950,   CLASS_ATTSET,  VAL_XD1,          {3,12,-1},
81      "XD-1"},
82     {PROTO_Z3950,   CLASS_ATTSET,  VAL_ZTHES,        {3,13,-1},
83      "Zthes"},
84     {PROTO_Z3950,   CLASS_ATTSET,  VAL_FIN1,         {3,14,-1},
85      "Fin-1"},
86     {PROTO_Z3950,   CLASS_ATTSET,  VAL_DAN1,         {3,15,-1},
87      "Dan-1"},
88     {PROTO_Z3950,   CLASS_ATTSET,  VAL_HOLDINGS,     {3,16,-1},
89      "Holdings"},
90     {PROTO_Z3950,   CLASS_ATTSET,  VAL_USMARC,       {3,17,-1},
91      "MARC"},
92     {PROTO_Z3950,   CLASS_ATTSET,  VAL_BIB2,         {3,18,-1},
93      "Bib-2"},
94     {PROTO_Z3950,   CLASS_ATTSET,  VAL_ZEEREX,       {3,19,-1},
95      "ZeeRex"},
96
97     {PROTO_Z3950,   CLASS_ATTSET,  VAL_THESAURUS,    {3,1000,81,1,-1},     
98      "Thesaurus-attset"},
99     {PROTO_Z3950,   CLASS_ATTSET,  VAL_IDXPATH,      {3,1000,81,2,-1},
100      "IDXPATH"},
101     {PROTO_Z3950,   CLASS_DIAGSET, VAL_BIB1,         {4,1,-1},
102      "Bib-1"},
103     {PROTO_Z3950,   CLASS_DIAGSET, VAL_DIAG1,        {4,2,-1},
104      "Diag-1"},
105     {PROTO_Z3950,   CLASS_DIAGSET, VAL_DIAG_ES,      {4,3,-1},
106      "Diag-ES"},
107     {PROTO_Z3950,   CLASS_DIAGSET, VAL_DIAG_GENERAL, {4,3,-1},
108      "Diag-General"},
109     {PROTO_Z3950,   CLASS_RECSYN,  VAL_UNIMARC,      {5,1,-1},
110      "Unimarc"},
111     {PROTO_Z3950,   CLASS_RECSYN,  VAL_INTERMARC,    {5,2,-1},
112      "Intermarc"},
113     {PROTO_Z3950,   CLASS_RECSYN,  VAL_CCF,          {5,3,-1},
114      "CCF"},
115     {PROTO_Z3950,   CLASS_RECSYN,  VAL_USMARC,       {5,10,-1},
116      "USmarc"},
117     {PROTO_Z3950,   CLASS_RECSYN,  VAL_UKMARC,       {5,11,-1},
118      "UKmarc"},
119     {PROTO_Z3950,   CLASS_RECSYN,  VAL_NORMARC,      {5,12,-1},
120      "Normarc"},
121     {PROTO_Z3950,   CLASS_RECSYN,  VAL_LIBRISMARC,   {5,13,-1},
122      "Librismarc"},
123     {PROTO_Z3950,   CLASS_RECSYN,  VAL_DANMARC,      {5,14,-1},
124      "Danmarc"},
125     {PROTO_Z3950,   CLASS_RECSYN,  VAL_FINMARC,      {5,15,-1},
126      "Finmarc"},
127     {PROTO_Z3950,   CLASS_RECSYN,  VAL_MAB,          {5,16,-1},
128      "MAB"},
129     {PROTO_Z3950,   CLASS_RECSYN,  VAL_CANMARC,      {5,17,-1},
130      "Canmarc"},
131     {PROTO_Z3950,   CLASS_RECSYN,  VAL_SBN,          {5,18,-1},
132      "SBN"},
133     {PROTO_Z3950,   CLASS_RECSYN,  VAL_PICAMARC,     {5,19,-1},
134      "Picamarc"},
135     {PROTO_Z3950,   CLASS_RECSYN,  VAL_AUSMARC,      {5,20,-1},
136      "Ausmarc"},
137     {PROTO_Z3950,   CLASS_RECSYN,  VAL_IBERMARC,     {5,21,-1},
138      "Ibermarc"},
139     {PROTO_Z3950,   CLASS_RECSYN,  VAL_CATMARC,      {5,22,-1},
140      "Carmarc"},
141     {PROTO_Z3950,   CLASS_RECSYN,  VAL_MALMARC,      {5,23,-1},
142      "Malmarc"},
143     {PROTO_Z3950,   CLASS_RECSYN,  VAL_JPMARC,       {5,24,-1},
144      "JPmarc"},
145     {PROTO_Z3950,   CLASS_RECSYN,  VAL_SWEMARC,      {5,25,-1},
146      "SWEmarc"},
147     {PROTO_Z3950,   CLASS_RECSYN,  VAL_SIGLEMARC,    {5,26,-1},
148      "SIGLEmarc"},
149     {PROTO_Z3950,   CLASS_RECSYN,  VAL_ISDSMARC,     {5,27,-1},
150      "ISDSmarc"},
151     {PROTO_Z3950,   CLASS_RECSYN,  VAL_RUSMARC,      {5,28,-1},
152      "RUSmarc"},
153     {PROTO_Z3950,   CLASS_RECSYN,  VAL_HUNMARC,      {5,29,-1},
154      "Hunmarc"},
155     {PROTO_Z3950,   CLASS_RECSYN,  VAL_EXPLAIN,      {5,100,-1},
156      "Explain"},
157     {PROTO_Z3950,   CLASS_RECSYN,  VAL_SUTRS,        {5,101,-1},
158      "SUTRS"},
159     {PROTO_Z3950,   CLASS_RECSYN,  VAL_OPAC,         {5,102,-1},
160      "OPAC"},
161     {PROTO_Z3950,   CLASS_RECSYN,  VAL_SUMMARY,      {5,103,-1},
162      "Summary"},
163     {PROTO_Z3950,   CLASS_RECSYN,  VAL_GRS0,         {5,104,-1},
164      "GRS-0"},
165     {PROTO_Z3950,   CLASS_RECSYN,  VAL_GRS1,         {5,105,-1},
166      "GRS-1"},
167     {PROTO_Z3950,   CLASS_RECSYN,  VAL_EXTENDED,     {5,106,-1},
168      "Extended"},
169     {PROTO_Z3950,   CLASS_RECSYN,  VAL_FRAGMENT,     {5,107,-1},
170      "Fragment"},
171     {PROTO_Z3950,   CLASS_RECSYN,  VAL_PDF,          {5,109,1,-1},
172      "pdf"},
173     {PROTO_Z3950,   CLASS_RECSYN,  VAL_POSTSCRIPT,   {5,109,2,-1},
174      "postscript"},
175     {PROTO_Z3950,   CLASS_RECSYN,  VAL_HTML,         {5,109,3,-1},
176      "html"},
177     {PROTO_Z3950,   CLASS_RECSYN,  VAL_TIFF,         {5,109,4,-1},
178      "tiff"},
179     {PROTO_Z3950,   CLASS_RECSYN,  VAL_GIF,          {5,109,5,-1},
180      "gif"},
181     {PROTO_Z3950,   CLASS_RECSYN,  VAL_JPEG,         {5,109,6,-1},
182      "jpeg"},
183     {PROTO_Z3950,   CLASS_RECSYN,  VAL_PNG,          {5,109,7,-1},
184      "png"},
185     {PROTO_Z3950,   CLASS_RECSYN,  VAL_MPEG,         {5,109,8,-1},
186      "mpeg"},
187     {PROTO_Z3950,   CLASS_RECSYN,  VAL_SGML,         {5,109,9,-1},
188      "sgml"},
189
190     {PROTO_Z3950,   CLASS_RECSYN,  VAL_TIFFB,        {5,110,1,-1},
191      "tiff-b"},
192     {PROTO_Z3950,   CLASS_RECSYN,  VAL_WAV,          {5,110,2,-1},
193      "wav"},
194
195     {PROTO_Z3950,   CLASS_RECSYN,  VAL_SQLRS,        {5,111,-1},
196      "SQL-RS"},
197     {PROTO_Z3950,   CLASS_RECSYN,  VAL_SOIF,         {5,1000,81,2,-1},
198      "SOIF" },
199     {PROTO_Z3950,   CLASS_RECSYN,  VAL_TEXT_XML,     {5,109,10,-1},
200      "text-XML" },
201     {PROTO_Z3950,   CLASS_RECSYN,  VAL_TEXT_XML,     {5,109,10,-1},
202      "XML" },
203     {PROTO_Z3950,   CLASS_RECSYN,  VAL_APPLICATION_XML, {5,109,11,-1},
204      "application-XML" },
205     {PROTO_Z3950,   CLASS_RESFORM, VAL_RESOURCE1,    {7,1,-1},
206      "Resource-1"},
207     {PROTO_Z3950,   CLASS_RESFORM, VAL_RESOURCE2,    {7,2,-1},
208      "Resource-2"},
209     {PROTO_Z3950,   CLASS_RESFORM, VAL_UNIVERSE_REPORT, {7,1000,81,1,-1},
210      "UNIverse-Resource-Report"},
211
212     {PROTO_Z3950,   CLASS_ACCFORM, VAL_PROMPT1,      {8,1,-1},
213      "Prompt-1"},
214     {PROTO_Z3950,   CLASS_ACCFORM, VAL_DES1,         {8,2,-1},
215      "Des-1"},
216     {PROTO_Z3950,   CLASS_ACCFORM, VAL_KRB1,         {8,3,-1},
217      "Krb-1"},
218     {PROTO_Z3950,   CLASS_EXTSERV, VAL_PRESSET,      {9,1,-1},
219      "Pers. set"},
220     {PROTO_Z3950,   CLASS_EXTSERV, VAL_PQUERY,       {9,2,-1},
221      "Pers. query"},
222     {PROTO_Z3950,   CLASS_EXTSERV, VAL_PCQUERY,      {9,3,-1},
223      "Per'd query"},
224     {PROTO_Z3950,   CLASS_EXTSERV, VAL_ITEMORDER,    {9,4,-1},
225      "Item order"},
226     {PROTO_Z3950,   CLASS_EXTSERV, VAL_DBUPDATE0,    {9,5,1,-1},
227      "DB. Update (old version)"},
228     {PROTO_Z3950,   CLASS_EXTSERV, VAL_DBUPDATE,     {9,5,1,1,-1},
229      "DB. Update"},
230     {PROTO_Z3950,   CLASS_EXTSERV, VAL_EXPORTSPEC,   {9,6,-1},
231      "exp. spec."},
232     {PROTO_Z3950,   CLASS_EXTSERV, VAL_EXPORTINV,    {9,7,-1},
233      "exp. inv."},
234     {PROTO_Z3950,   CLASS_EXTSERV, VAL_ADMINSERVICE, {9,81,1,-1},
235      "Admin"},
236     {PROTO_Z3950,   CLASS_USERINFO,VAL_SEARCHRES1,   {10,1,-1},
237      "searchResult-1"},
238     {PROTO_Z3950,   CLASS_USERINFO,VAL_CHARLANG,     {10,2,-1},
239      "CharSetandLanguageNegotiation"},
240     {PROTO_Z3950,   CLASS_USERINFO,VAL_USERINFO1,    {10,3,-1},
241      "UserInfo-1"},
242     {PROTO_Z3950,   CLASS_USERINFO,VAL_MULTISRCH1,   {10,4,-1},
243      "MultipleSearchTerms-1"},
244     {PROTO_Z3950,   CLASS_USERINFO,VAL_MULTISRCH2,   {10,5,-1},
245      "MultipleSearchTerms-2"},
246     {PROTO_Z3950,   CLASS_USERINFO,VAL_DATETIME,     {10,6,-1},
247      "DateTime"},
248     {PROTO_Z3950,   CLASS_USERINFO,VAL_PROXY,        {10,1000,81,1,-1},
249      "Proxy" },
250     {PROTO_Z3950,   CLASS_USERINFO,VAL_COOKIE,       {10,1000,81,2,-1},
251      "Cookie" },
252     {PROTO_Z3950,   CLASS_USERINFO,VAL_CLIENT_IP,    {10,1000,81,3,-1},
253      "Client-IP" },
254     {PROTO_Z3950,   CLASS_ELEMSPEC,VAL_ESPEC1,       {11,1,-1},
255      "Espec-1"},
256     {PROTO_Z3950,   CLASS_VARSET,  VAL_VAR1,         {12,1,-1},
257      "Variant-1"},
258     {PROTO_Z3950,   CLASS_SCHEMA,  VAL_WAIS,         {13,1,-1},
259      "WAIS-schema"},
260     {PROTO_Z3950,   CLASS_SCHEMA,  VAL_GILS,         {13,2,-1},
261      "GILS-schema"},
262     {PROTO_Z3950,   CLASS_SCHEMA,  VAL_COLLECT1,     {13,3,-1},
263      "Collections-schema"},
264     {PROTO_Z3950,   CLASS_SCHEMA,  VAL_GEO,          {13,4,-1},
265      "Geo-schema"},
266     {PROTO_Z3950,   CLASS_SCHEMA,  VAL_CIMI1,        {13,5,-1},
267      "CIMI-schema"},
268     {PROTO_Z3950,   CLASS_SCHEMA,  VAL_UPDATEES,     {13,6,-1},
269      "Update ES"},
270     {PROTO_Z3950,   CLASS_SCHEMA,  VAL_HOLDINGS,     {13,7,-1},
271      "Holdings"},
272     {PROTO_Z3950,   CLASS_SCHEMA,  VAL_ZTHES,        {13,8,-1},
273      "Zthes"},
274     {PROTO_Z3950,   CLASS_SCHEMA,  VAL_THESAURUS,    {13,1000,81,1,-1},
275      "thesaurus-schema"},
276     {PROTO_Z3950,   CLASS_SCHEMA,  VAL_EXPLAIN,      {13,1000,81,2,-1},
277      "Explain-schema"},
278     {PROTO_Z3950,   CLASS_TAGSET,  VAL_SETM,         {14,1,-1},
279      "TagsetM"},
280     {PROTO_Z3950,   CLASS_TAGSET,  VAL_SETG,         {14,2,-1},
281      "TagsetG"},
282     {PROTO_Z3950,   CLASS_TAGSET,  VAL_STAS,         {14,3,-1},
283      "STAS-tagset"},
284     {PROTO_Z3950,   CLASS_TAGSET,  VAL_GILS,         {14,4,-1},
285      "GILS-tagset"},
286     {PROTO_Z3950,   CLASS_TAGSET,  VAL_COLLECT1,     {14,5,-1},
287      "Collections-tagset"},
288     {PROTO_Z3950,   CLASS_TAGSET,  VAL_CIMI1,        {14,6,-1},
289      "CIMI-tagset"},
290     {PROTO_Z3950,   CLASS_TAGSET,  VAL_THESAURUS,    {14,1000,81,1,-1},
291      "thesaurus-tagset"},       /* What is this Satan-spawn doing here? */
292     {PROTO_Z3950,   CLASS_TAGSET,  VAL_EXPLAIN,      {14,1000,81,2,-1},
293      "Explain-tagset"},
294     {PROTO_Z3950,   CLASS_TAGSET,  VAL_ZTHES,        {14,8,-1},
295      "Zthes-tagset"},
296     {PROTO_Z3950,   CLASS_NEGOT,   VAL_CHARNEG3,     {15,3,-1},
297      "CharSetandLanguageNegotiation-3"},
298     {PROTO_GENERAL, CLASS_GENERAL, VAL_UCS2,    {1,0,10646,1,0,2,-1},
299      "UCS-2"},
300     {PROTO_GENERAL, CLASS_GENERAL, VAL_UCS4,    {1,0,10646,1,0,4,-1},
301      "UCS-4"},
302     {PROTO_GENERAL, CLASS_GENERAL, VAL_UTF16,   {1,0,10646,1,0,5,-1},
303      "UTF-16"},
304     {PROTO_GENERAL, CLASS_GENERAL, VAL_UTF8,    {1,0,10646,1,0,8,-1},
305      "UTF-8"},
306     {PROTO_NOP,     CLASS_NOP,     VAL_NOP,       {-1},        0          }
307 };
308
309 /* OID utilities */
310
311 void oid_oidcpy(int *t, int *s)
312 {
313     while ((*(t++) = *(s++)) > -1);
314 }
315
316 void oid_oidcat(int *t, int *s)
317 {
318     while (*t > -1)
319         t++;
320     while ((*(t++) = *(s++)) > -1);
321 }
322
323 int oid_oidcmp(int *o1, int *o2)
324 {
325     while (*o1 == *o2 && *o1 > -1)
326     {
327         o1++;
328         o2++;
329     }
330     if (*o1 == *o2)
331         return 0;
332     else if (*o1 > *o2)
333         return 1;
334     else
335         return -1;
336 }
337
338 int oid_oidlen(int *o)
339 {
340     int len = 0;
341
342     while (*(o++) >= 0)
343         len++;
344     return len;
345 }
346
347
348 static int match_prefix(int *look, int *prefix)
349 {
350     int len;
351
352     for (len = 0; *look == *prefix; look++, prefix++, len++);
353     if (*prefix < 0) /* did we reach the end of the prefix? */
354         return len;
355     return 0;
356 }
357
358 void oid_transfer (struct oident *oident)
359 {
360     while (*oident->oidsuffix >= 0)
361     {
362         oid_addent (oident->oidsuffix, oident->proto,
363                     oident->oclass,
364                     oident->desc, oident->value);
365         oident++;
366     }
367 }
368
369 void oid_init (void)
370 {
371     if (oid_init_flag == 0)
372     {
373         /* oid_transfer is thread safe, so there's nothing wrong in having
374            two threads calling it simultaniously. On the other hand
375            no thread may exit oid_init before all OID's bave been
376            transferred - which is why checked is set after oid_transfer... 
377         */
378         nmem_mutex_create (&oid_mutex);
379         nmem_mutex_enter (oid_mutex);
380         if (!oid_nmem)
381             oid_nmem = nmem_create ();
382         nmem_mutex_leave (oid_mutex);
383         oid_transfer (standard_oids);
384         oid_init_flag = 1;
385     }
386 }
387
388 void oid_exit (void)
389 {
390     if (oid_init_flag)
391     {
392         oid_init_flag = 0;
393         nmem_mutex_destroy (&oid_mutex);
394         nmem_destroy (oid_nmem);
395         oid_nmem = 0;
396     }
397 }
398
399 static struct oident *oid_getentbyoid_x(int *o)
400 {
401     enum oid_proto proto;
402     int prelen;
403     struct oident_list *ol;
404     
405     /* determine protocol type */
406     if ((prelen = match_prefix(o, z3950_prefix)) != 0)
407         proto = PROTO_Z3950;
408     else if ((prelen = match_prefix(o, sr_prefix)) != 0)
409         proto = PROTO_SR;
410     else
411         proto = PROTO_GENERAL;
412     for (ol = oident_table; ol; ol = ol->next)
413     {
414         struct oident *p = &ol->oident;
415         if (p->proto == proto && !oid_oidcmp(o + prelen, p->oidsuffix))
416             return p;
417         if (p->proto == PROTO_GENERAL && !oid_oidcmp (o, p->oidsuffix))
418             return p;
419     }
420     return 0;
421 }
422
423 /*
424  * To query, fill out proto, class, and value of the ent parameter.
425  */
426 int *oid_ent_to_oid(struct oident *ent, int *ret)
427 {
428     struct oident_list *ol;
429     
430     oid_init ();
431     for (ol = oident_table; ol; ol = ol->next)
432     {
433         struct oident *p = &ol->oident;
434         if (ent->value == p->value &&
435             (p->proto == PROTO_GENERAL || (ent->proto == p->proto &&  
436             (ent->oclass == p->oclass || ent->oclass == CLASS_GENERAL))))
437         {
438             if (p->proto == PROTO_Z3950)
439                 oid_oidcpy(ret, z3950_prefix);
440             else if (p->proto == PROTO_SR)
441                 oid_oidcpy(ret, sr_prefix);
442             else
443                 ret[0] = -1;
444             oid_oidcat(ret, p->oidsuffix);
445             ent->desc = p->desc;
446             return ret;
447         }
448     }
449     ret[0] = -1;
450     return 0;
451 }
452
453 /*
454  * To query, fill out proto, class, and value of the ent parameter.
455  */
456 int *oid_getoidbyent(struct oident *ent)
457 {
458     static int ret[OID_SIZE];
459
460     return oid_ent_to_oid (ent, ret);
461 }
462
463 struct oident *oid_addent (int *oid, enum oid_proto proto,
464                            enum oid_class oclass,
465                            const char *desc, int value)
466 {
467     struct oident *oident = 0;
468
469     nmem_mutex_enter (oid_mutex);
470     if (!oident)
471     {
472         char desc_str[200];
473         struct oident_list *oident_list;
474         oident_list = (struct oident_list *)
475             nmem_malloc (oid_nmem, sizeof(*oident_list));
476         oident = &oident_list->oident;
477         oident->proto = proto;
478         oident->oclass = oclass;
479
480         if (!desc)
481         {
482             int i;
483
484             sprintf (desc_str, "%d", *oid);
485             for (i = 1; i < 12 && oid[i] >= 0; i++)
486                 sprintf (desc_str+strlen(desc_str), ".%d", oid[i]);
487             desc = desc_str;
488         }
489         oident->desc = nmem_strdup (oid_nmem, desc);
490         if (value == VAL_DYNAMIC)
491             oident->value = (enum oid_value) (++oid_value_dynamic);
492         else
493             oident->value = (enum oid_value) value;
494         oid_oidcpy (oident->oidsuffix, oid);
495         oident_list->next = oident_table;
496         oident_table = oident_list;
497     }
498     nmem_mutex_leave (oid_mutex);
499     return oident;
500 }
501
502 struct oident *oid_getentbyoid(int *oid)
503 {
504     struct oident *oident;
505
506     if (!oid)
507         return 0;
508     oid_init ();
509     oident = oid_getentbyoid_x (oid);
510     if (!oident)
511         oident = oid_addent (oid, PROTO_GENERAL, CLASS_GENERAL,
512                              NULL, VAL_DYNAMIC);
513     return oident;
514 }
515
516 static oid_value oid_getval_raw(const char *name)
517 {
518     int val = 0, i = 0, oid[OID_SIZE];
519     struct oident *oident;
520     
521     while (isdigit (*name))
522     {
523         val = val*10 + (*name - '0');
524         name++;
525         if (*name == '.')
526         {
527             if (i < OID_SIZE-1)
528                 oid[i++] = val;
529             val = 0;
530             name++;
531         }
532     }
533     oid[i] = val;
534     oid[i+1] = -1;
535     oident = oid_getentbyoid_x (oid);
536     if (!oident)
537         oident = oid_addent (oid, PROTO_GENERAL, CLASS_GENERAL, NULL,
538                          VAL_DYNAMIC);
539     return oident->value;
540 }
541
542 oid_value oid_getvalbyname(const char *name)
543 {
544     struct oident_list *ol;
545
546     oid_init ();
547     if (isdigit (*name))
548         return oid_getval_raw (name);
549     for (ol = oident_table; ol; ol = ol->next)
550         if (!yaz_matchstr(ol->oident.desc, name))
551         {
552             return ol->oident.value;
553         }
554     return VAL_NONE;
555 }
556
557 void oid_setprivateoids(oident *list)
558 {
559     oid_transfer (list);
560 }
561
562 void oid_trav (void (*func)(struct oident *oidinfo, void *vp), void *vp)
563 {
564     struct oident_list *ol;
565
566     oid_init ();
567     for (ol = oident_table; ol; ol = ol->next)
568         (*func)(&ol->oident, vp);
569 }