2 * Copyright (c) 1995-2003, Index Data
3 * See the file LICENSE for details.
5 * $Id: oid.c,v 1.60 2003-04-03 21:01:28 mike Exp $
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.
22 #include <yaz/yaz-util.h>
24 static int z3950_prefix[] = { 1, 2, 840, 10003, -1 };
25 static int sr_prefix[] = { 1, 0, 10163, -1 };
29 struct oident_list *next;
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;
41 static oident standard_oids[] =
43 /* General definitions */
44 {PROTO_GENERAL, CLASS_TRANSYN, VAL_BER, {2,1,1,-1},
46 {PROTO_GENERAL, CLASS_TRANSYN, VAL_ISO2709, {1,0,2709,1,1,-1},
48 {PROTO_GENERAL, CLASS_GENERAL, VAL_ISO_ILL_1, {1,0,10161,2,1,-1},
50 /* Z39.50v3 definitions */
51 {PROTO_Z3950, CLASS_ABSYN, VAL_APDU, {2,1,-1},
53 {PROTO_Z3950, CLASS_APPCTX, VAL_BASIC_CTX, {1,1,-1},
55 {PROTO_Z3950, CLASS_ATTSET, VAL_BIB1, {3,1,-1},
57 {PROTO_Z3950, CLASS_ATTSET, VAL_EXP1, {3,2,-1},
59 {PROTO_Z3950, CLASS_ATTSET, VAL_EXT1, {3,3,-1},
61 {PROTO_Z3950, CLASS_ATTSET, VAL_CCL1, {3,4,-1},
63 {PROTO_Z3950, CLASS_ATTSET, VAL_GILS, {3,5,-1},
65 {PROTO_Z3950, CLASS_ATTSET, VAL_GILS, {3,5,-1},
67 {PROTO_Z3950, CLASS_ATTSET, VAL_STAS, {3,6,-1},
69 {PROTO_Z3950, CLASS_ATTSET, VAL_COLLECT1, {3,7,-1},
70 "Collections-attset"},
71 {PROTO_Z3950, CLASS_ATTSET, VAL_CIMI1, {3,8,-1},
73 {PROTO_Z3950, CLASS_ATTSET, VAL_GEO, {3,9,-1},
76 {PROTO_Z3950, CLASS_ATTSET, VAL_ZBIG, {3,10,-1},
78 {PROTO_Z3950, CLASS_ATTSET, VAL_UTIL, {3,11,-1},
80 {PROTO_Z3950, CLASS_ATTSET, VAL_XD1, {3,12,-1},
82 {PROTO_Z3950, CLASS_ATTSET, VAL_ZTHES, {3,13,-1},
84 {PROTO_Z3950, CLASS_ATTSET, VAL_FIN1, {3,14,-1},
86 {PROTO_Z3950, CLASS_ATTSET, VAL_DAN1, {3,15,-1},
88 {PROTO_Z3950, CLASS_ATTSET, VAL_HOLDINGS, {3,16,-1},
90 {PROTO_Z3950, CLASS_ATTSET, VAL_USMARC, {3,17,-1},
92 {PROTO_Z3950, CLASS_ATTSET, VAL_BIB2, {3,18,-1},
94 {PROTO_Z3950, CLASS_ATTSET, VAL_ZEEREX, {3,19,-1},
96 #if 0 /* This is the spawn of Satan. Use Zthes-1 instead */
97 {PROTO_Z3950, CLASS_ATTSET, VAL_THESAURUS, {3,1000,81,1,-1},
100 {PROTO_Z3950, CLASS_ATTSET, VAL_IDXPATH, {3,1000,81,2,-1},
102 {PROTO_Z3950, CLASS_DIAGSET, VAL_BIB1, {4,1,-1},
104 {PROTO_Z3950, CLASS_DIAGSET, VAL_DIAG1, {4,2,-1},
106 {PROTO_Z3950, CLASS_DIAGSET, VAL_DIAG_ES, {4,3,-1},
108 {PROTO_Z3950, CLASS_DIAGSET, VAL_DIAG_GENERAL, {4,3,-1},
110 {PROTO_Z3950, CLASS_RECSYN, VAL_UNIMARC, {5,1,-1},
112 {PROTO_Z3950, CLASS_RECSYN, VAL_INTERMARC, {5,2,-1},
114 {PROTO_Z3950, CLASS_RECSYN, VAL_CCF, {5,3,-1},
116 {PROTO_Z3950, CLASS_RECSYN, VAL_USMARC, {5,10,-1},
118 {PROTO_Z3950, CLASS_RECSYN, VAL_UKMARC, {5,11,-1},
120 {PROTO_Z3950, CLASS_RECSYN, VAL_NORMARC, {5,12,-1},
122 {PROTO_Z3950, CLASS_RECSYN, VAL_LIBRISMARC, {5,13,-1},
124 {PROTO_Z3950, CLASS_RECSYN, VAL_DANMARC, {5,14,-1},
126 {PROTO_Z3950, CLASS_RECSYN, VAL_FINMARC, {5,15,-1},
128 {PROTO_Z3950, CLASS_RECSYN, VAL_MAB, {5,16,-1},
130 {PROTO_Z3950, CLASS_RECSYN, VAL_CANMARC, {5,17,-1},
132 {PROTO_Z3950, CLASS_RECSYN, VAL_SBN, {5,18,-1},
134 {PROTO_Z3950, CLASS_RECSYN, VAL_PICAMARC, {5,19,-1},
136 {PROTO_Z3950, CLASS_RECSYN, VAL_AUSMARC, {5,20,-1},
138 {PROTO_Z3950, CLASS_RECSYN, VAL_IBERMARC, {5,21,-1},
140 {PROTO_Z3950, CLASS_RECSYN, VAL_CATMARC, {5,22,-1},
142 {PROTO_Z3950, CLASS_RECSYN, VAL_MALMARC, {5,23,-1},
144 {PROTO_Z3950, CLASS_RECSYN, VAL_JPMARC, {5,24,-1},
146 {PROTO_Z3950, CLASS_RECSYN, VAL_SWEMARC, {5,25,-1},
148 {PROTO_Z3950, CLASS_RECSYN, VAL_SIGLEMARC, {5,26,-1},
150 {PROTO_Z3950, CLASS_RECSYN, VAL_ISDSMARC, {5,27,-1},
152 {PROTO_Z3950, CLASS_RECSYN, VAL_RUSMARC, {5,28,-1},
154 {PROTO_Z3950, CLASS_RECSYN, VAL_HUNMARC, {5,29,-1},
156 {PROTO_Z3950, CLASS_RECSYN, VAL_EXPLAIN, {5,100,-1},
158 {PROTO_Z3950, CLASS_RECSYN, VAL_SUTRS, {5,101,-1},
160 {PROTO_Z3950, CLASS_RECSYN, VAL_OPAC, {5,102,-1},
162 {PROTO_Z3950, CLASS_RECSYN, VAL_SUMMARY, {5,103,-1},
164 {PROTO_Z3950, CLASS_RECSYN, VAL_GRS0, {5,104,-1},
166 {PROTO_Z3950, CLASS_RECSYN, VAL_GRS1, {5,105,-1},
168 {PROTO_Z3950, CLASS_RECSYN, VAL_EXTENDED, {5,106,-1},
170 {PROTO_Z3950, CLASS_RECSYN, VAL_FRAGMENT, {5,107,-1},
172 {PROTO_Z3950, CLASS_RECSYN, VAL_PDF, {5,109,1,-1},
174 {PROTO_Z3950, CLASS_RECSYN, VAL_POSTSCRIPT, {5,109,2,-1},
176 {PROTO_Z3950, CLASS_RECSYN, VAL_HTML, {5,109,3,-1},
178 {PROTO_Z3950, CLASS_RECSYN, VAL_TIFF, {5,109,4,-1},
180 {PROTO_Z3950, CLASS_RECSYN, VAL_GIF, {5,109,5,-1},
182 {PROTO_Z3950, CLASS_RECSYN, VAL_JPEG, {5,109,6,-1},
184 {PROTO_Z3950, CLASS_RECSYN, VAL_PNG, {5,109,7,-1},
186 {PROTO_Z3950, CLASS_RECSYN, VAL_MPEG, {5,109,8,-1},
188 {PROTO_Z3950, CLASS_RECSYN, VAL_SGML, {5,109,9,-1},
191 {PROTO_Z3950, CLASS_RECSYN, VAL_TIFFB, {5,110,1,-1},
193 {PROTO_Z3950, CLASS_RECSYN, VAL_WAV, {5,110,2,-1},
196 {PROTO_Z3950, CLASS_RECSYN, VAL_SQLRS, {5,111,-1},
198 {PROTO_Z3950, CLASS_RECSYN, VAL_SOIF, {5,1000,81,2,-1},
200 {PROTO_Z3950, CLASS_RECSYN, VAL_TEXT_XML, {5,109,10,-1},
202 {PROTO_Z3950, CLASS_RECSYN, VAL_TEXT_XML, {5,109,10,-1},
204 {PROTO_Z3950, CLASS_RECSYN, VAL_APPLICATION_XML, {5,109,11,-1},
206 {PROTO_Z3950, CLASS_RESFORM, VAL_RESOURCE1, {7,1,-1},
208 {PROTO_Z3950, CLASS_RESFORM, VAL_RESOURCE2, {7,2,-1},
210 {PROTO_Z3950, CLASS_RESFORM, VAL_UNIVERSE_REPORT, {7,1000,81,1,-1},
211 "UNIverse-Resource-Report"},
213 {PROTO_Z3950, CLASS_ACCFORM, VAL_PROMPT1, {8,1,-1},
215 {PROTO_Z3950, CLASS_ACCFORM, VAL_DES1, {8,2,-1},
217 {PROTO_Z3950, CLASS_ACCFORM, VAL_KRB1, {8,3,-1},
219 {PROTO_Z3950, CLASS_EXTSERV, VAL_PRESSET, {9,1,-1},
221 {PROTO_Z3950, CLASS_EXTSERV, VAL_PQUERY, {9,2,-1},
223 {PROTO_Z3950, CLASS_EXTSERV, VAL_PCQUERY, {9,3,-1},
225 {PROTO_Z3950, CLASS_EXTSERV, VAL_ITEMORDER, {9,4,-1},
227 {PROTO_Z3950, CLASS_EXTSERV, VAL_DBUPDATE0, {9,5,1,-1},
228 "DB. Update (old version)"},
229 {PROTO_Z3950, CLASS_EXTSERV, VAL_DBUPDATE, {9,5,1,1,-1},
231 {PROTO_Z3950, CLASS_EXTSERV, VAL_EXPORTSPEC, {9,6,-1},
233 {PROTO_Z3950, CLASS_EXTSERV, VAL_EXPORTINV, {9,7,-1},
235 {PROTO_Z3950, CLASS_EXTSERV, VAL_ADMINSERVICE, {9,81,1,-1},
237 {PROTO_Z3950, CLASS_USERINFO,VAL_SEARCHRES1, {10,1,-1},
239 {PROTO_Z3950, CLASS_USERINFO,VAL_CHARLANG, {10,2,-1},
240 "CharSetandLanguageNegotiation"},
241 {PROTO_Z3950, CLASS_USERINFO,VAL_USERINFO1, {10,3,-1},
243 {PROTO_Z3950, CLASS_USERINFO,VAL_MULTISRCH1, {10,4,-1},
244 "MultipleSearchTerms-1"},
245 {PROTO_Z3950, CLASS_USERINFO,VAL_MULTISRCH2, {10,5,-1},
246 "MultipleSearchTerms-2"},
247 {PROTO_Z3950, CLASS_USERINFO,VAL_DATETIME, {10,6,-1},
249 {PROTO_Z3950, CLASS_USERINFO,VAL_PROXY, {10,1000,81,1,-1},
251 {PROTO_Z3950, CLASS_USERINFO,VAL_COOKIE, {10,1000,81,2,-1},
253 {PROTO_Z3950, CLASS_USERINFO,VAL_CLIENT_IP, {10,1000,81,3,-1},
255 {PROTO_Z3950, CLASS_ELEMSPEC,VAL_ESPEC1, {11,1,-1},
257 {PROTO_Z3950, CLASS_VARSET, VAL_VAR1, {12,1,-1},
259 {PROTO_Z3950, CLASS_SCHEMA, VAL_WAIS, {13,1,-1},
261 {PROTO_Z3950, CLASS_SCHEMA, VAL_GILS, {13,2,-1},
263 {PROTO_Z3950, CLASS_SCHEMA, VAL_COLLECT1, {13,3,-1},
264 "Collections-schema"},
265 {PROTO_Z3950, CLASS_SCHEMA, VAL_GEO, {13,4,-1},
267 {PROTO_Z3950, CLASS_SCHEMA, VAL_CIMI1, {13,5,-1},
269 {PROTO_Z3950, CLASS_SCHEMA, VAL_UPDATEES, {13,6,-1},
271 {PROTO_Z3950, CLASS_SCHEMA, VAL_HOLDINGS, {13,7,-1},
273 {PROTO_Z3950, CLASS_SCHEMA, VAL_ZTHES, {13,8,-1},
275 {PROTO_Z3950, CLASS_SCHEMA, VAL_THESAURUS, {13,1000,81,1,-1},
277 {PROTO_Z3950, CLASS_SCHEMA, VAL_EXPLAIN, {13,1000,81,2,-1},
279 {PROTO_Z3950, CLASS_TAGSET, VAL_SETM, {14,1,-1},
281 {PROTO_Z3950, CLASS_TAGSET, VAL_SETG, {14,2,-1},
283 {PROTO_Z3950, CLASS_TAGSET, VAL_STAS, {14,3,-1},
285 {PROTO_Z3950, CLASS_TAGSET, VAL_GILS, {14,4,-1},
287 {PROTO_Z3950, CLASS_TAGSET, VAL_COLLECT1, {14,5,-1},
288 "Collections-tagset"},
289 {PROTO_Z3950, CLASS_TAGSET, VAL_CIMI1, {14,6,-1},
291 {PROTO_Z3950, CLASS_TAGSET, VAL_THESAURUS, {14,1000,81,1,-1},
292 "thesaurus-tagset"}, /* What is this Satan-spawn doing here? */
293 {PROTO_Z3950, CLASS_TAGSET, VAL_EXPLAIN, {14,1000,81,2,-1},
295 {PROTO_Z3950, CLASS_TAGSET, VAL_ZTHES, {14,8,-1},
297 {PROTO_Z3950, CLASS_NEGOT, VAL_CHARNEG3, {15,3,-1},
298 "CharSetandLanguageNegotiation-3"},
299 {PROTO_Z3950, CLASS_USERINFO,VAL_CQL, {16, 2, -1},
301 {PROTO_GENERAL, CLASS_GENERAL, VAL_UCS2, {1,0,10646,1,0,2,-1},
303 {PROTO_GENERAL, CLASS_GENERAL, VAL_UCS4, {1,0,10646,1,0,4,-1},
305 {PROTO_GENERAL, CLASS_GENERAL, VAL_UTF16, {1,0,10646,1,0,5,-1},
307 {PROTO_GENERAL, CLASS_GENERAL, VAL_UTF8, {1,0,10646,1,0,8,-1},
309 {PROTO_NOP, CLASS_NOP, VAL_NOP, {-1}, 0 }
314 void oid_oidcpy(int *t, int *s)
316 while ((*(t++) = *(s++)) > -1);
319 void oid_oidcat(int *t, int *s)
323 while ((*(t++) = *(s++)) > -1);
326 int oid_oidcmp(int *o1, int *o2)
328 while (*o1 == *o2 && *o1 > -1)
341 int oid_oidlen(int *o)
351 static int match_prefix(int *look, int *prefix)
355 for (len = 0; *look == *prefix; look++, prefix++, len++);
356 if (*prefix < 0) /* did we reach the end of the prefix? */
361 void oid_transfer (struct oident *oident)
363 while (*oident->oidsuffix >= 0)
365 oid_addent (oident->oidsuffix, oident->proto,
367 oident->desc, oident->value);
374 if (oid_init_flag == 0)
376 /* oid_transfer is thread safe, so there's nothing wrong in having
377 two threads calling it simultaniously. On the other hand
378 no thread may exit oid_init before all OID's bave been
379 transferred - which is why checked is set after oid_transfer...
381 nmem_mutex_create (&oid_mutex);
382 nmem_mutex_enter (oid_mutex);
384 oid_nmem = nmem_create ();
385 nmem_mutex_leave (oid_mutex);
386 oid_transfer (standard_oids);
396 nmem_mutex_destroy (&oid_mutex);
397 nmem_destroy (oid_nmem);
402 static struct oident *oid_getentbyoid_x(int *o)
404 enum oid_proto proto;
406 struct oident_list *ol;
408 /* determine protocol type */
409 if ((prelen = match_prefix(o, z3950_prefix)) != 0)
411 else if ((prelen = match_prefix(o, sr_prefix)) != 0)
414 proto = PROTO_GENERAL;
415 for (ol = oident_table; ol; ol = ol->next)
417 struct oident *p = &ol->oident;
418 if (p->proto == proto && !oid_oidcmp(o + prelen, p->oidsuffix))
420 if (p->proto == PROTO_GENERAL && !oid_oidcmp (o, p->oidsuffix))
427 * To query, fill out proto, class, and value of the ent parameter.
429 int *oid_ent_to_oid(struct oident *ent, int *ret)
431 struct oident_list *ol;
434 for (ol = oident_table; ol; ol = ol->next)
436 struct oident *p = &ol->oident;
437 if (ent->value == p->value &&
438 (p->proto == PROTO_GENERAL || (ent->proto == p->proto &&
439 (ent->oclass == p->oclass || ent->oclass == CLASS_GENERAL))))
441 if (p->proto == PROTO_Z3950)
442 oid_oidcpy(ret, z3950_prefix);
443 else if (p->proto == PROTO_SR)
444 oid_oidcpy(ret, sr_prefix);
447 oid_oidcat(ret, p->oidsuffix);
457 * To query, fill out proto, class, and value of the ent parameter.
459 int *oid_getoidbyent(struct oident *ent)
461 static int ret[OID_SIZE];
463 return oid_ent_to_oid (ent, ret);
466 struct oident *oid_addent (int *oid, enum oid_proto proto,
467 enum oid_class oclass,
468 const char *desc, int value)
470 struct oident *oident = 0;
472 nmem_mutex_enter (oid_mutex);
476 struct oident_list *oident_list;
477 oident_list = (struct oident_list *)
478 nmem_malloc (oid_nmem, sizeof(*oident_list));
479 oident = &oident_list->oident;
480 oident->proto = proto;
481 oident->oclass = oclass;
487 sprintf (desc_str, "%d", *oid);
488 for (i = 1; i < 12 && oid[i] >= 0; i++)
489 sprintf (desc_str+strlen(desc_str), ".%d", oid[i]);
492 oident->desc = nmem_strdup (oid_nmem, desc);
493 if (value == VAL_DYNAMIC)
494 oident->value = (enum oid_value) (++oid_value_dynamic);
496 oident->value = (enum oid_value) value;
497 oid_oidcpy (oident->oidsuffix, oid);
498 oident_list->next = oident_table;
499 oident_table = oident_list;
501 nmem_mutex_leave (oid_mutex);
505 struct oident *oid_getentbyoid(int *oid)
507 struct oident *oident;
512 oident = oid_getentbyoid_x (oid);
514 oident = oid_addent (oid, PROTO_GENERAL, CLASS_GENERAL,
519 static oid_value oid_getval_raw(const char *name)
521 int val = 0, i = 0, oid[OID_SIZE];
522 struct oident *oident;
524 while (isdigit (*name))
526 val = val*10 + (*name - '0');
538 oident = oid_getentbyoid_x (oid);
540 oident = oid_addent (oid, PROTO_GENERAL, CLASS_GENERAL, NULL,
542 return oident->value;
545 oid_value oid_getvalbyname(const char *name)
547 struct oident_list *ol;
551 return oid_getval_raw (name);
552 for (ol = oident_table; ol; ol = ol->next)
553 if (!yaz_matchstr(ol->oident.desc, name))
555 return ol->oident.value;
560 void oid_setprivateoids(oident *list)
565 void oid_trav (void (*func)(struct oident *oidinfo, void *vp), void *vp)
567 struct oident_list *ol;
570 for (ol = oident_table; ol; ol = ol->next)
571 (*func)(&ol->oident, vp);