2 * Copyright (C) 1995-2007, Index Data ApS
3 * See the file LICENSE for details.
5 * $Id: oid_db.c,v 1.7 2007-05-06 20:12:20 adam Exp $
20 #include <yaz/yaz-util.h>
22 #include <yaz/oid_util.h>
23 #include <yaz/oid_db.h>
26 struct yaz_oid_entry *entries;
27 struct yaz_oid_db *next;
31 struct yaz_oid_db standard_db_l = {
32 yaz_oid_standard_entries, 0, 0
34 yaz_oid_db_t standard_db = &standard_db_l;
36 yaz_oid_db_t yaz_oid_std(void)
41 const int *yaz_string_to_oid(yaz_oid_db_t oid_db,
42 int oclass, const char *name)
44 for (; oid_db; oid_db = oid_db->next)
46 struct yaz_oid_entry *e;
47 if (oclass != CLASS_GENERAL)
49 for (e = oid_db->entries; e->name; e++)
51 if (!yaz_matchstr(e->name, name) && oclass == e->oclass)
55 for (e = oid_db->entries; e->name; e++)
57 if (!yaz_matchstr(e->name, name))
64 int *yaz_string_to_oid_nmem(yaz_oid_db_t oid_list,
65 int oclass, const char *name, NMEM nmem)
67 const int *oid = yaz_string_to_oid(oid_list, oclass, name);
69 return odr_oiddup_nmem(nmem, oid);
70 return odr_getoidbystr_nmem(nmem, name);
73 int *yaz_string_to_oid_odr(yaz_oid_db_t oid_list,
74 int oclass, const char *name, ODR o)
76 return yaz_string_to_oid_nmem(oid_list, oclass, name, odr_getmem(o));
79 const char *yaz_oid_to_string(yaz_oid_db_t oid_db,
80 const int *oid, int *oclass)
84 for (; oid_db; oid_db = oid_db->next)
86 struct yaz_oid_entry *e = oid_db->entries;
89 if (!oid_oidcmp(e->oid, oid))
100 const char *yaz_oid_to_string_buf(const int *oid, int *oclass, char *buf)
102 const char *p = yaz_oid_to_string(standard_db, oid, oclass);
106 *oclass = CLASS_GENERAL;
107 return oid_oid_to_dotstring(oid, buf);
110 int yaz_oid_is_iso2709(const int *oid)
112 if (oid_oidlen(oid) == 6 && oid[0] == 1 && oid[1] == 2
113 && oid[2] == 840 && oid[3] == 10003 && oid[4] == 5
114 && oid[5] <= 29 && oid[5] != 16)
119 int yaz_oid_add(yaz_oid_db_t oid_db, int oclass, const char *name,
122 const int *oid = yaz_string_to_oid(oid_db, oclass, name);
125 struct yaz_oid_entry *ent;
129 oid_db = oid_db->next;
130 oid_db->next = (struct yaz_oid_db *) xmalloc(sizeof(*oid_db->next));
131 oid_db = oid_db->next;
134 oid_db->xmalloced = 1;
135 oid_db->entries = ent = (struct yaz_oid_entry *) xmalloc(2 * sizeof(*ent));
138 xmalloc(sizeof(*alloc_oid) * (oid_oidlen(new_oid)+1));
139 oid_oidcpy(alloc_oid, new_oid);
140 ent[0].oid = alloc_oid;
141 ent[0].name = xstrdup(name);
142 ent[0].oclass = oclass;
146 ent[1].oclass = CLASS_NOP;
152 yaz_oid_db_t yaz_oid_db_new(void)
154 yaz_oid_db_t p = (yaz_oid_db_t) xmalloc(sizeof(*p));
161 void yaz_oid_db_destroy(yaz_oid_db_t oid_db)
165 yaz_oid_db_t p = oid_db;
167 oid_db = oid_db->next;
170 struct yaz_oid_entry *e = p->entries;
179 void yaz_oid_trav(yaz_oid_db_t oid_db,
180 void (*func)(const int *oid,
181 int oclass, const char *name,
185 for (; oid_db; oid_db = oid_db->next)
187 struct yaz_oid_entry *e = oid_db->entries;
190 func(e->oid, e->oclass, e->name, client_data);
197 * indent-tabs-mode: nil
199 * vim: shiftwidth=4 tabstop=8 expandtab