Fixed bug in inetd code. The server listened on tcp:@:9999 even
[yaz-moved-to-github.git] / util / oid.c
1 /*
2  * Copyright (c) 1995-1997, Index Data
3  * See the file LICENSE for details.
4  * Sebastian Hammer, Adam Dickmeiss
5  *
6  * $Log: oid.c,v $
7  * Revision 1.24  1997-09-29 13:19:00  adam
8  * Added function, oid_ent_to_oid, to replace the function
9  * oid_getoidbyent, which is not thread safe.
10  *
11  * Revision 1.23  1997/09/09 10:10:19  adam
12  * Another MSV5.0 port. Changed projects to include proper
13  * library/include paths.
14  * Server starts server in test-mode when no options are given.
15  *
16  * Revision 1.22  1997/08/29 13:34:58  quinn
17  * Added thesaurus oids
18  *
19  * Revision 1.21  1997/08/19 08:46:05  quinn
20  * Added Thesaurus OID
21  *
22  * Revision 1.20  1997/07/28 12:34:43  adam
23  * Added new OID entries (RVDM).
24  *
25  * Revision 1.19  1997/05/02 08:39:41  quinn
26  * Support for private OID table added. Thanks to Ronald van der Meer
27  *
28  * Revision 1.18  1997/04/30 08:52:12  quinn
29  * Null
30  *
31  * Revision 1.17  1996/10/10  12:35:23  quinn
32  * Added Update extended service.
33  *
34  * Revision 1.16  1996/10/09  15:55:02  quinn
35  * Added SearchInfoReport
36  *
37  * Revision 1.15  1996/10/07  15:29:43  quinn
38  * Added SOIF support
39  *
40  * Revision 1.14  1996/02/20  17:58:28  adam
41  * Added const to oid_getvalbyname.
42  *
43  * Revision 1.13  1996/02/20  16:37:33  quinn
44  * Using yaz_matchstr in oid_getvalbyname
45  *
46  * Revision 1.12  1996/01/02  08:57:53  quinn
47  * Changed enums in the ASN.1 .h files to #defines. Changed oident.class to oclass
48  *
49  * Revision 1.11  1995/12/13  16:03:35  quinn
50  * *** empty log message ***
51  *
52  * Revision 1.10  1995/11/28  09:30:44  quinn
53  * Work.
54  *
55  * Revision 1.9  1995/11/13  09:27:53  quinn
56  * Fiddling with the variant stuff.
57  *
58  * Revision 1.8  1995/10/12  10:34:56  quinn
59  * Added Espec-1.
60  *
61  * Revision 1.7  1995/10/10  16:27:12  quinn
62  * *** empty log message ***
63  *
64  * Revision 1.6  1995/09/29  17:12:35  quinn
65  * Smallish
66  *
67  * Revision 1.5  1995/09/29  17:01:51  quinn
68  * More Windows work
69  *
70  * Revision 1.4  1995/09/27  15:03:03  quinn
71  * Modified function heads & prototypes.
72  *
73  * Revision 1.3  1995/09/12  11:32:06  quinn
74  * Added a looker-upper by name.
75  *
76  * Revision 1.2  1995/08/21  09:11:16  quinn
77  * Smallish fixes to suppport new formats.
78  *
79  * Revision 1.1  1995/05/29  08:17:13  quinn
80  * iMoved oid to util to support comstack.
81  *
82  * Revision 1.5  1995/05/22  11:30:16  quinn
83  * Adding Z39.50-1992 stuff to proto.c. Adding zget.c
84  *
85  * Revision 1.4  1995/05/16  08:50:22  quinn
86  * License, documentation, and memory fixes
87  *
88  * Revision 1.3  1995/04/11  11:52:02  quinn
89  * Fixed possible buf in proto.c
90  *
91  * Revision 1.2  1995/03/29  15:39:38  quinn
92  * Adding some resource control elements, and a null-check to getentbyoid
93  *
94  * Revision 1.1  1995/03/27  08:32:12  quinn
95  * Added OID database
96  *
97  *
98  */
99
100 /*
101  * More or less protocol-transparent OID database.
102  * We could (and should?) extend this so that the user app can add new
103  * entries to the list at initialization.
104  */
105
106 #include <stdlib.h>
107 #include <oid.h>
108 #include <yaz-util.h>
109
110 static int z3950_prefix[] = { 1, 2, 840, 10003, -1 };
111 static int sr_prefix[]    = { 1, 0, 10163, -1 };
112
113 static oident *extoids = NULL;
114
115 /*
116  * OID database
117  */
118 static oident oids[] =
119 {
120     /* General definitions */
121     {PROTO_GENERAL, CLASS_TRANSYN, VAL_BER,       {2,1,1,-1},  "BER"         },
122     {PROTO_GENERAL, CLASS_TRANSYN, VAL_ISO2709,   {1,0,2709,1,1,-1},"ISO2709"},
123
124     /* Z39.50v3 definitions */
125     {PROTO_Z3950,   CLASS_ABSYN,   VAL_APDU,      {2,1,-1},    "Z-APDU"      },
126
127     {PROTO_Z3950,   CLASS_APPCTX,  VAL_BASIC_CTX, {1,1,-1},    "Z-BASIC"     },
128
129     {PROTO_Z3950,   CLASS_ATTSET,  VAL_BIB1,      {3,1,-1},    "Bib-1"       },
130     {PROTO_Z3950,   CLASS_ATTSET,  VAL_EXP1,      {3,2,-1},    "Exp-1"       },
131     {PROTO_Z3950,   CLASS_ATTSET,  VAL_EXT1,      {3,3,-1},    "Ext-1"       },
132     {PROTO_Z3950,   CLASS_ATTSET,  VAL_CCL1,      {3,4,-1},    "CCL-1"       },
133     {PROTO_Z3950,   CLASS_ATTSET,  VAL_GILS,      {3,5,-1},    "GILS-attset" },
134     {PROTO_Z3950,   CLASS_ATTSET,  VAL_STAS,      {3,6,-1},    "STAS-attset" },
135     {PROTO_Z3950,   CLASS_ATTSET,  VAL_COLLECT1,  {3,7,-1},    "Collections-attset"},
136     {PROTO_Z3950,   CLASS_ATTSET,  VAL_CIMI1,     {3,8,-1},    "CIMI-attset"},
137     {PROTO_Z3950,   CLASS_ATTSET,  VAL_GEO,       {3,9,-1},    "Geo-attset"},
138     {PROTO_Z3950,   CLASS_ATTSET,  VAL_THESAURUS, {3,1000,81,1,-1},"Thesaurus-attset"},
139
140     {PROTO_Z3950,   CLASS_DIAGSET, VAL_BIB1,      {4,1,-1},    "Bib-1"       },
141     {PROTO_Z3950,   CLASS_DIAGSET, VAL_DIAG1,     {4,2,-1},    "Diag-1"      },
142
143     {PROTO_Z3950,   CLASS_RECSYN,  VAL_UNIMARC,   {5,1,-1},    "Unimarc"     },
144     {PROTO_Z3950,   CLASS_RECSYN,  VAL_INTERMARC, {5,2,-1},    "Intermarc"   },
145     {PROTO_Z3950,   CLASS_RECSYN,  VAL_CCF,       {5,3,-1},    "CCF"         },
146     {PROTO_Z3950,   CLASS_RECSYN,  VAL_USMARC,    {5,10,-1},   "USmarc"      },
147     {PROTO_Z3950,   CLASS_RECSYN,  VAL_UKMARC,    {5,11,-1},   "UKmarc"      },
148     {PROTO_Z3950,   CLASS_RECSYN,  VAL_NORMARC,   {5,12,-1},   "Normarc"     },
149     {PROTO_Z3950,   CLASS_RECSYN,  VAL_LIBRISMARC,{5,13,-1},   "Librismarc"  },
150     {PROTO_Z3950,   CLASS_RECSYN,  VAL_DANMARC,   {5,14,-1},   "Danmarc"     },
151     {PROTO_Z3950,   CLASS_RECSYN,  VAL_FINMARC,   {5,15,-1},   "Finmarc"     },
152     {PROTO_Z3950,   CLASS_RECSYN,  VAL_MAB,       {5,16,-1},   "MAB"         },
153     {PROTO_Z3950,   CLASS_RECSYN,  VAL_CANMARC,   {5,17,-1},   "Canmarc"     },
154     {PROTO_Z3950,   CLASS_RECSYN,  VAL_SBN,       {5,18,-1},   "SBN"         },
155     {PROTO_Z3950,   CLASS_RECSYN,  VAL_PICAMARC,  {5,19,-1},   "Picamarc"    },
156     {PROTO_Z3950,   CLASS_RECSYN,  VAL_AUSMARC,   {5,20,-1},   "Ausmarc"     },
157     {PROTO_Z3950,   CLASS_RECSYN,  VAL_IBERMARC,  {5,21,-1},   "Ibermarc"    },
158     {PROTO_Z3950,   CLASS_RECSYN,  VAL_CATMARC,   {5,22,-1},   "Carmarc"     },
159     {PROTO_Z3950,   CLASS_RECSYN,  VAL_MALMARC,   {5,23,-1},   "Malmarc"     },
160     {PROTO_Z3950,   CLASS_RECSYN,  VAL_EXPLAIN,   {5,100,-1},  "Explain"     },
161     {PROTO_Z3950,   CLASS_RECSYN,  VAL_SUTRS,     {5,101,-1},  "SUTRS"       },
162     {PROTO_Z3950,   CLASS_RECSYN,  VAL_OPAC,      {5,102,-1},  "OPAC"        },
163     {PROTO_Z3950,   CLASS_RECSYN,  VAL_SUMMARY,   {5,103,-1},  "Summary"     },
164     {PROTO_Z3950,   CLASS_RECSYN,  VAL_GRS0,      {5,104,-1},  "GRS-0"       },
165     {PROTO_Z3950,   CLASS_RECSYN,  VAL_GRS1,      {5,105,-1},  "GRS-1"       },
166     {PROTO_Z3950,   CLASS_RECSYN,  VAL_EXTENDED,  {5,106,-1},  "Extended"    },
167     {PROTO_Z3950,   CLASS_RECSYN,  VAL_FRAGMENT,  {5,107,-1},  "Fragment"    },
168 #if 0
169     {PROTO_Z3950,   CLASS_RECSYN,  VAL_ID_SGML,   {5,1000,81,1,-1},"ID-SGML" },
170 #endif
171     {PROTO_Z3950,   CLASS_RECSYN,  VAL_SOIF,      {5,1000,81,2,-1},"SOIF" },
172
173     {PROTO_Z3950,   CLASS_RESFORM, VAL_RESOURCE1, {7,1,-1},    "Resource-1"  },
174     {PROTO_Z3950,   CLASS_RESFORM, VAL_RESOURCE2, {7,2,-1},    "Resource-2"  },
175
176     {PROTO_Z3950,   CLASS_ACCFORM, VAL_PROMPT1,   {8,1,-1},    "Prompt-1"    },
177     {PROTO_Z3950,   CLASS_ACCFORM, VAL_DES1,      {8,2,-1},    "Des-1"       },
178     {PROTO_Z3950,   CLASS_ACCFORM, VAL_KRB1,      {8,3,-1},    "Krb-1"       },
179
180     {PROTO_Z3950,   CLASS_EXTSERV, VAL_PRESSET,   {9,1,-1},    "Pers. set"   },
181     {PROTO_Z3950,   CLASS_EXTSERV, VAL_PQUERY,    {9,2,-1},    "Pers. query" },
182     {PROTO_Z3950,   CLASS_EXTSERV, VAL_PCQUERY,   {9,3,-1},    "Per'd query" },
183     {PROTO_Z3950,   CLASS_EXTSERV, VAL_ITEMORDER, {9,4,-1},    "Item order"  },
184     {PROTO_Z3950,   CLASS_EXTSERV, VAL_DBUPDATE,  {9,5,-1},    "DB. Update"  },
185     {PROTO_Z3950,   CLASS_EXTSERV, VAL_EXPORTSPEC,{9,6,-1},    "exp. spec."  },
186     {PROTO_Z3950,   CLASS_EXTSERV, VAL_EXPORTINV, {9,7,-1},    "exp. inv."   },
187
188     {PROTO_Z3950,   CLASS_USERINFO,VAL_SEARCHRES1,{10,1,-1},  "searchResult-1"},
189
190     {PROTO_Z3950,   CLASS_ELEMSPEC,VAL_ESPEC1,    {11,1,-1},   "Espec-1"     },
191
192     {PROTO_Z3950,   CLASS_VARSET,  VAL_VAR1,      {12,1,-1},   "Variant-1"   },
193
194     {PROTO_Z3950,   CLASS_SCHEMA,  VAL_WAIS,      {13,1,-1},   "WAIS-schema" },
195     {PROTO_Z3950,   CLASS_SCHEMA,  VAL_GILS,      {13,2,-1},   "GILS-schema" },
196     {PROTO_Z3950,   CLASS_SCHEMA,  VAL_COLLECT1,  {13,3,-1},   "Collections-schema" },
197     {PROTO_Z3950,   CLASS_SCHEMA,  VAL_GEO,       {13,4,-1},   "Geo-schema" },
198     {PROTO_Z3950,   CLASS_SCHEMA,  VAL_CIMI1,     {13,5,-1},   "CIMI-schema" },
199
200     {PROTO_Z3950,   CLASS_TAGSET,  VAL_SETM,      {14,1,-1},   "TagsetM"     },
201     {PROTO_Z3950,   CLASS_TAGSET,  VAL_SETG,      {14,2,-1},   "TagsetG"     },
202     {PROTO_Z3950,   CLASS_TAGSET,  VAL_STAS,      {14,3,-1},   "STAS-tagset" },
203     {PROTO_Z3950,   CLASS_TAGSET,  VAL_GILS,      {14,4,-1},   "GILS-tagset" },
204     {PROTO_Z3950,   CLASS_TAGSET,  VAL_COLLECT1,  {14,5,-1},   "Collections-tagset"},
205     {PROTO_Z3950,   CLASS_TAGSET,  VAL_CIMI1,     {14,6,-1},   "CIMI-tagset" },
206     {PROTO_Z3950,   CLASS_TAGSET,  VAL_THESAURUS, {14,1000,81,1,-1}, "thesaurus-tagset"},
207
208     /* SR definitions. Note that some of them aren't defined by the
209         standard (yet), but are borrowed from Z3950v3 */
210     {PROTO_SR,      CLASS_ABSYN,   VAL_APDU,      {2,1,-1},    "SR-APDU"     },
211
212     {PROTO_SR,      CLASS_APPCTX,  VAL_BASIC_CTX, {1,1,-1},    "SR-BASIC"    },
213
214     {PROTO_SR,      CLASS_ATTSET,  VAL_BIB1,      {3,1,-1},    "Bib-1"       },
215     {PROTO_SR,      CLASS_ATTSET,  VAL_EXP1,      {3,2,-1},    "Exp-1"       },
216     {PROTO_SR,      CLASS_ATTSET,  VAL_EXT1,      {3,3,-1},    "Ext-1"       },
217     {PROTO_SR,      CLASS_ATTSET,  VAL_CCL1,      {3,4,-1},    "CCL-1"       },
218     {PROTO_SR,      CLASS_ATTSET,  VAL_GILS,      {3,5,-1},    "GILS"        },
219     {PROTO_SR,      CLASS_ATTSET,  VAL_STAS,      {3,6,-1},    "STAS",       },
220     {PROTO_SR,      CLASS_ATTSET,  VAL_COLLECT1,  {3,7,-1},    "Collections-attset"},
221     {PROTO_SR,      CLASS_ATTSET,  VAL_CIMI1,     {3,8,-1},    "CIMI-attset"},
222     {PROTO_SR,      CLASS_ATTSET,  VAL_GEO,       {3,9,-1},    "Geo-attset"},
223
224     {PROTO_SR,      CLASS_DIAGSET, VAL_BIB1,      {4,1,-1},    "Bib-1"       },
225     {PROTO_SR,      CLASS_DIAGSET, VAL_DIAG1,     {4,2,-1},    "Diag-1"      },
226
227     {PROTO_SR,      CLASS_RECSYN,  VAL_UNIMARC,   {5,1,-1},    "Unimarc"     },
228     {PROTO_SR,      CLASS_RECSYN,  VAL_INTERMARC, {5,2,-1},    "Intermarc"   },
229     {PROTO_SR,      CLASS_RECSYN,  VAL_CCF,       {5,3,-1},     "CCF"        },
230     {PROTO_SR,      CLASS_RECSYN,  VAL_USMARC,    {5,10,-1},   "USmarc"      },
231     {PROTO_SR,      CLASS_RECSYN,  VAL_UKMARC,    {5,11,-1},   "UKmarc"      },
232     {PROTO_SR,      CLASS_RECSYN,  VAL_NORMARC,   {5,12,-1},   "Normarc"     },
233     {PROTO_SR,      CLASS_RECSYN,  VAL_LIBRISMARC,{5,13,-1},   "Librismarc"  },
234     {PROTO_SR,      CLASS_RECSYN,  VAL_DANMARC,   {5,14,-1},   "Danmarc"     },
235     {PROTO_SR,      CLASS_RECSYN,  VAL_FINMARC,   {5,15,-1},   "Finmarc"     },
236     {PROTO_SR,      CLASS_RECSYN,  VAL_MAB,       {5,16,-1},   "MAB"         },
237     {PROTO_SR,      CLASS_RECSYN,  VAL_CANMARC,   {5,17,-1},   "Canmarc"     },
238     {PROTO_SR,      CLASS_RECSYN,  VAL_MAB,       {5,16,-1},   "MAB"         },
239     {PROTO_SR,      CLASS_RECSYN,  VAL_CANMARC,   {5,17,-1},   "Canmarc"     },
240     {PROTO_SR,      CLASS_RECSYN,  VAL_SBN,       {5,18,-1},   "SBN"         },
241     {PROTO_SR,      CLASS_RECSYN,  VAL_PICAMARC,  {5,19,-1},   "Picamarc"    },
242     {PROTO_SR,      CLASS_RECSYN,  VAL_AUSMARC,   {5,20,-1},   "Ausmarc"     },
243     {PROTO_SR,      CLASS_RECSYN,  VAL_IBERMARC,  {5,21,-1},   "Ibermarc"    },
244     {PROTO_SR,      CLASS_RECSYN,  VAL_CATMARC,   {5,22,-1},   "Catmarc"     },
245     {PROTO_SR,      CLASS_RECSYN,  VAL_MALMARC,   {5,23,-1},   "Malmarc"     },
246     {PROTO_SR,      CLASS_RECSYN,  VAL_EXPLAIN,   {5,100,-1},  "Explain"     },
247     {PROTO_SR,      CLASS_RECSYN,  VAL_SUTRS,     {5,101,-1},  "SUTRS"       },
248     {PROTO_SR,      CLASS_RECSYN,  VAL_OPAC,      {5,102,-1},  "OPAC"        },
249     {PROTO_SR,      CLASS_RECSYN,  VAL_SUMMARY,   {5,103,-1},  "Summary"     },
250     {PROTO_SR,      CLASS_RECSYN,  VAL_GRS0,      {5,104,-1},  "GRS-0"       },
251     {PROTO_SR,      CLASS_RECSYN,  VAL_GRS1,      {5,105,-1},  "GRS-1"       },
252     {PROTO_SR,      CLASS_RECSYN,  VAL_EXTENDED,  {5,106,-1},  "Extended"    },
253     {PROTO_SR,      CLASS_RECSYN,  VAL_FRAGMENT,  {5,107,-1},  "Fragment"    },
254
255     {PROTO_SR,      CLASS_RESFORM, VAL_RESOURCE1, {7,1,-1},    "Resource-1"  },
256     {PROTO_SR,      CLASS_RESFORM, VAL_RESOURCE2, {7,2,-1},    "Resource-2"  },
257
258     {PROTO_SR,      CLASS_ACCFORM, VAL_PROMPT1,   {8,1,-1},    "Prompt-1"    },
259     {PROTO_SR,      CLASS_ACCFORM, VAL_DES1,      {8,2,-1},    "Des-1"       },
260     {PROTO_SR,      CLASS_ACCFORM, VAL_KRB1,      {8,3,-1},    "Krb-1"       },
261
262     {PROTO_SR,      CLASS_EXTSERV, VAL_PRESSET,   {9,1,-1},    "Pers. set"   },
263     {PROTO_SR,      CLASS_EXTSERV, VAL_PQUERY,    {9,2,-1},    "Pers. query" },
264     {PROTO_SR,      CLASS_EXTSERV, VAL_PCQUERY,   {9,3,-1},    "Per'd query" },
265     {PROTO_SR,      CLASS_EXTSERV, VAL_ITEMORDER, {9,4,-1},    "Item order"  },
266     {PROTO_SR,      CLASS_EXTSERV, VAL_DBUPDATE,  {9,5,-1},    "DB. Update"  },
267     {PROTO_SR,      CLASS_EXTSERV, VAL_EXPORTSPEC,{9,6,-1},    "exp. spec."  },
268     {PROTO_SR,      CLASS_EXTSERV, VAL_EXPORTINV, {9,7,-1},    "exp. inv."   },
269
270     {PROTO_SR,      CLASS_ELEMSPEC,VAL_ESPEC1,    {11,1,-1},   "Espec-1"     },
271
272     {PROTO_SR,      CLASS_VARSET,  VAL_VAR1,      {12,1,-1},   "Variant-1"   },
273
274     {PROTO_SR,      CLASS_SCHEMA,  VAL_WAIS,      {13,1,-1},   "WAIS-schema" },
275     {PROTO_SR,      CLASS_SCHEMA,  VAL_GILS,      {13,2,-1},   "GILS-schema" },
276     {PROTO_SR,      CLASS_SCHEMA,  VAL_COLLECT1,  {13,3,-1},   "Collections-schema" },
277     {PROTO_SR,      CLASS_SCHEMA,  VAL_GEO,       {13,4,-1},   "Geo-schema" },
278     {PROTO_SR,      CLASS_SCHEMA,  VAL_CIMI1,     {13,5,-1},   "CIMI-schema" },
279     {PROTO_Z3950,   CLASS_SCHEMA,  VAL_THESAURUS, {13,1000,81,1,-1}, "thesaurus-schema"},
280
281     {PROTO_SR,      CLASS_TAGSET,  VAL_SETM,      {14,1,-1},   "TagsetM"     },
282     {PROTO_SR,      CLASS_TAGSET,  VAL_SETG,      {14,2,-1},   "TagsetG"     },
283
284     {PROTO_SR,      CLASS_TAGSET,  VAL_STAS,      {14,3,-1},   "STAS-tagset" },
285     {PROTO_SR,      CLASS_TAGSET,  VAL_GILS,      {14,4,-1},   "GILS-tagset" },
286     {PROTO_SR,      CLASS_TAGSET,  VAL_COLLECT1,  {14,5,-1},   "Collections-tagset"},
287     {PROTO_SR,      CLASS_TAGSET,  VAL_CIMI1,     {14,6,-1},   "CIMI-tagset" },
288
289     {0,             0,             0,             {-1},        0          }
290 };
291
292 /* OID utilities */
293
294 void oid_oidcpy(int *t, int *s)
295 {
296     while ((*(t++) = *(s++)) > -1);
297 }
298
299 void oid_oidcat(int *t, int *s)
300 {
301     while (*t > -1)
302         t++;
303     while ((*(t++) = *(s++)) > -1);
304 }
305
306 int oid_oidcmp(int *o1, int *o2)
307 {
308     while (*o1 == *o2 && *o1 > -1)
309     {
310         o1++;
311         o2++;
312     }
313     if (*o1 == *o2)
314         return 0;
315     else if (*o1 > *o2)
316         return 1;
317     else
318         return -1;
319 }
320
321 int oid_oidlen(int *o)
322 {
323     int len = 0;
324
325     while (*(o++) >= 0)
326         len++;
327     return len;
328 }
329
330
331 static int match_prefix(int *look, int *prefix)
332 {
333     int len;
334
335     for (len = 0; *look == *prefix; look++, prefix++, len++);
336     if (*prefix < 0) /* did we reach the end of the prefix? */
337         return len;
338     return 0;
339 }
340
341 struct oident *oid_getentbyoid(int *o)
342 {
343     enum oid_proto proto;
344     int prelen;
345     oident *p;
346
347     /* determine protocol type */
348     if (!o)
349         return 0;
350     if ((prelen = match_prefix(o, z3950_prefix)) != 0)
351         proto = PROTO_Z3950;
352     else if ((prelen = match_prefix(o, sr_prefix)) != 0)
353         proto = PROTO_SR;
354     else
355         proto = PROTO_GENERAL;
356     for (p = oids; *p->oidsuffix >= 0; p++)
357         if (p->proto == proto && !oid_oidcmp(o + prelen, p->oidsuffix))
358             return p;
359     if (extoids != NULL)
360         for (p = extoids; *p->oidsuffix >= 0; p++)
361             if (p->proto == proto && !oid_oidcmp(o + prelen, p->oidsuffix))
362                 return p;
363     return 0;
364 }
365
366
367 /*
368  * To query, fill out proto, class, and value of the ent parameter.
369  */
370 int *oid_ent_to_oid(struct oident *ent, int *ret)
371 {
372     struct oident *p;
373
374     for (p = oids; *p->oidsuffix >= 0; p++)
375         if (ent->proto == p->proto &&
376             ent->oclass == p->oclass &&
377             ent->value == p->value)
378         {
379             if (ent->proto == PROTO_Z3950)
380                 oid_oidcpy(ret, z3950_prefix);
381             else if (ent->proto == PROTO_SR)
382                 oid_oidcpy(ret, sr_prefix);
383             else
384                 ret[0] = -1;
385             oid_oidcat(ret, p->oidsuffix);
386             return ret;
387         }
388     if (extoids != NULL)
389         for (p = extoids; *p->oidsuffix >= 0; p++)
390            if (ent->proto == p->proto &&
391                 ent->oclass == p->oclass &&
392                 ent->value == p->value)
393             {
394                 if (ent->proto == PROTO_Z3950)
395                     oid_oidcpy(ret, z3950_prefix);
396                 else if (ent->proto == PROTO_SR)
397                     oid_oidcpy(ret, sr_prefix);
398                 else
399                     ret[0] = -1;
400                 oid_oidcat(ret, p->oidsuffix);
401                 return ret;
402             }
403     return 0;
404 }
405 /*
406  * To query, fill out proto, class, and value of the ent parameter.
407  */
408 int *oid_getoidbyent(struct oident *ent)
409 {
410     static int ret[OID_SIZE];
411
412     return oid_ent_to_oid (ent, ret);
413 }
414
415 oid_value oid_getvalbyname(const char *name)
416 {
417     struct oident *p;
418
419     for (p = oids; *p->oidsuffix >= 0; p++)
420         if (!yaz_matchstr(p->desc, name))
421             return p->value;
422     if (extoids != NULL)
423         for (p = extoids; *p->oidsuffix >= 0; p++)
424             if (!yaz_matchstr(p->desc, name))
425                 return p->value;
426     return VAL_NONE;
427 }
428
429 void oid_setprivateoids(oident *list)
430 {
431     extoids = list;
432 }