1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) 1995-2008 Index Data
3 * See the file LICENSE for details.
18 #include <yaz/yaz-util.h>
20 #include <yaz/oid_util.h>
21 #include <yaz/oid_db.h>
24 struct yaz_oid_entry *entries;
25 struct yaz_oid_db *next;
29 struct yaz_oid_db standard_db_l = {
30 yaz_oid_standard_entries, 0, 0
32 yaz_oid_db_t standard_db = &standard_db_l;
34 yaz_oid_db_t yaz_oid_std(void)
39 const Odr_oid *yaz_string_to_oid(yaz_oid_db_t oid_db,
40 oid_class oclass, const char *name)
42 for (; oid_db; oid_db = oid_db->next)
44 struct yaz_oid_entry *e;
45 if (oclass != CLASS_GENERAL)
47 for (e = oid_db->entries; e->name; e++)
49 if (!yaz_matchstr(e->name, name) && oclass == e->oclass)
53 for (e = oid_db->entries; e->name; e++)
55 if (!yaz_matchstr(e->name, name))
62 Odr_oid *yaz_string_to_oid_nmem(yaz_oid_db_t oid_list,
63 oid_class oclass, const char *name, NMEM nmem)
65 const Odr_oid *oid = yaz_string_to_oid(oid_list, oclass, name);
67 return odr_oiddup_nmem(nmem, oid);
68 return odr_getoidbystr_nmem(nmem, name);
71 Odr_oid *yaz_string_to_oid_odr(yaz_oid_db_t oid_list,
72 oid_class oclass, const char *name, ODR o)
74 return yaz_string_to_oid_nmem(oid_list, oclass, name, odr_getmem(o));
77 const char *yaz_oid_to_string(yaz_oid_db_t oid_db,
78 const Odr_oid *oid, oid_class *oclass)
82 for (; oid_db; oid_db = oid_db->next)
84 struct yaz_oid_entry *e = oid_db->entries;
87 if (!oid_oidcmp(e->oid, oid))
98 const char *yaz_oid_to_string_buf(const Odr_oid *oid, oid_class *oclass, char *buf)
100 const char *p = yaz_oid_to_string(standard_db, oid, oclass);
104 *oclass = CLASS_GENERAL;
105 return oid_oid_to_dotstring(oid, buf);
109 char *oid_name_to_dotstring(oid_class oclass, const char *name, char *oid_buf)
111 const Odr_oid *oid = yaz_string_to_oid(yaz_oid_std(), oclass, name);
113 return oid_oid_to_dotstring(oid, oid_buf);
118 int yaz_oid_is_iso2709(const Odr_oid *oid)
120 if (oid_oidlen(oid) == 6 && oid[0] == 1 && oid[1] == 2
121 && oid[2] == 840 && oid[3] == 10003 && oid[4] == 5
122 && oid[5] <= 29 && oid[5] != 16)
127 int yaz_oid_add(yaz_oid_db_t oid_db, oid_class oclass, const char *name,
128 const Odr_oid *new_oid)
130 const Odr_oid *oid = yaz_string_to_oid(oid_db, oclass, name);
133 struct yaz_oid_entry *ent;
137 oid_db = oid_db->next;
138 oid_db->next = (struct yaz_oid_db *) xmalloc(sizeof(*oid_db->next));
139 oid_db = oid_db->next;
142 oid_db->xmalloced = 1;
143 oid_db->entries = ent = (struct yaz_oid_entry *) xmalloc(2 * sizeof(*ent));
145 alloc_oid = (Odr_oid *)
146 xmalloc(sizeof(*alloc_oid) * (oid_oidlen(new_oid)+1));
147 oid_oidcpy(alloc_oid, new_oid);
148 ent[0].oid = alloc_oid;
149 ent[0].name = xstrdup(name);
150 ent[0].oclass = oclass;
154 ent[1].oclass = CLASS_NOP;
160 yaz_oid_db_t yaz_oid_db_new(void)
162 yaz_oid_db_t p = (yaz_oid_db_t) xmalloc(sizeof(*p));
169 void yaz_oid_db_destroy(yaz_oid_db_t oid_db)
173 yaz_oid_db_t p = oid_db;
175 oid_db = oid_db->next;
178 struct yaz_oid_entry *e = p->entries;
187 void yaz_oid_trav(yaz_oid_db_t oid_db,
188 void (*func)(const Odr_oid *oid,
189 oid_class oclass, const char *name,
193 for (; oid_db; oid_db = oid_db->next)
195 struct yaz_oid_entry *e = oid_db->entries;
198 func(e->oid, e->oclass, e->name, client_data);
205 * indent-tabs-mode: nil
207 * vim: shiftwidth=4 tabstop=8 expandtab