2 * Copyright (C) 1995-2007, Index Data ApS
3 * See the file LICENSE for details.
5 * $Id: oid_db.c,v 1.5 2007-04-16 21:53:09 adam Exp $
19 #include <yaz/yaz-util.h>
21 #include <yaz/oid_util.h>
22 #include <yaz/oid_db.h>
25 struct yaz_oid_entry *entries;
26 struct yaz_oid_db *next;
30 struct yaz_oid_db standard_db_l = {
31 yaz_oid_standard_entries, 0, 0
33 yaz_oid_db_t standard_db = &standard_db_l;
35 yaz_oid_db_t yaz_oid_std(void)
40 const int *yaz_string_to_oid(yaz_oid_db_t oid_db,
41 int oclass, const char *name)
43 for (; oid_db; oid_db = oid_db->next)
45 struct yaz_oid_entry *e;
46 if (oclass != CLASS_GENERAL)
48 for (e = oid_db->entries; e->name; e++)
50 if (!yaz_matchstr(e->name, name) && oclass == e->oclass)
54 for (e = oid_db->entries; e->name; e++)
56 if (!yaz_matchstr(e->name, name))
63 int *yaz_string_to_oid_nmem(yaz_oid_db_t oid_list,
64 int oclass, const char *name, NMEM nmem)
66 const int *oid = yaz_string_to_oid(oid_list, oclass, name);
68 return odr_oiddup_nmem(nmem, oid);
69 return odr_getoidbystr_nmem(nmem, name);
72 int *yaz_string_to_oid_odr(yaz_oid_db_t oid_list,
73 int oclass, const char *name, ODR o)
75 return yaz_string_to_oid_nmem(oid_list, oclass, name, odr_getmem(o));
78 const char *yaz_oid_to_string(yaz_oid_db_t oid_db,
79 const int *oid, int *oclass)
83 for (; oid_db; oid_db = oid_db->next)
85 struct yaz_oid_entry *e = oid_db->entries;
88 if (!oid_oidcmp(e->oid, oid))
99 const char *yaz_oid_to_string_buf(const int *oid, int *oclass, char *buf)
101 const char *p = yaz_oid_to_string(standard_db, oid, oclass);
105 *oclass = CLASS_GENERAL;
106 return oid_oid_to_dotstring(oid, buf);
109 int yaz_oid_is_iso2709(const int *oid)
111 if (oid_oidlen(oid) == 6 && oid[0] == 1 && oid[1] == 2
112 && oid[2] == 840 && oid[3] == 10003 && oid[4] == 5
113 && oid[5] <= 29 && oid[5] != 16)
118 int yaz_oid_add(yaz_oid_db_t oid_db, int oclass, const char *name,
121 const int *oid = yaz_string_to_oid(oid_db, oclass, name);
124 struct yaz_oid_entry *ent;
128 oid_db = oid_db->next;
129 oid_db->next = xmalloc(sizeof(*oid_db->next));
130 oid_db = oid_db->next;
133 oid_db->xmalloced = 1;
134 oid_db->entries = ent = xmalloc(2 * sizeof(*ent));
136 alloc_oid = xmalloc(sizeof(*alloc_oid) * (oid_oidlen(new_oid)+1));
137 oid_oidcpy(alloc_oid, new_oid);
138 ent[0].oid = alloc_oid;
139 ent[0].name = xstrdup(name);
140 ent[0].oclass = oclass;
144 ent[1].oclass = CLASS_NOP;
150 yaz_oid_db_t yaz_oid_db_new(void)
152 yaz_oid_db_t p = xmalloc(sizeof(*p));
159 void yaz_oid_db_destroy(yaz_oid_db_t oid_db)
163 yaz_oid_db_t p = oid_db;
165 oid_db = oid_db->next;
168 struct yaz_oid_entry *e = p->entries;
177 void yaz_oid_trav(yaz_oid_db_t oid_db,
178 void (*func)(const int *oid,
179 int oclass, const char *name,
183 for (; oid_db; oid_db = oid_db->next)
185 struct yaz_oid_entry *e = oid_db->entries;
188 func(e->oid, e->oclass, e->name, client_data);
195 * indent-tabs-mode: nil
197 * vim: shiftwidth=4 tabstop=8 expandtab