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