/*
- * Copyright (c) 1995-2004, Index Data
+ * Copyright (C) 1995-2007, Index Data ApS
* See the file LICENSE for details.
*
- * $Id: oid.c,v 1.4 2004-10-15 00:19:00 adam Exp $
+ * $Id: oid.c,v 1.13 2007-01-03 08:42:15 adam Exp $
*/
/**
{PROTO_Z3950, CLASS_TAGSET, VAL_CIMI1, {14,6,-1},
"CIMI-tagset"},
{PROTO_Z3950, CLASS_TAGSET, VAL_THESAURUS, {14,1000,81,1,-1},
- "thesaurus-tagset"}, /* What is this Satan-spawn doing here? */
+ "thesaurus-tagset"}, /* What is this Satan-spawn doing here? */
{PROTO_Z3950, CLASS_TAGSET, VAL_EXPLAIN, {14,1000,81,2,-1},
"Explain-tagset"},
{PROTO_Z3950, CLASS_TAGSET, VAL_ZTHES, {14,8,-1},
"Zthes-tagset"},
{PROTO_Z3950, CLASS_NEGOT, VAL_CHARNEG3, {15,3,-1},
"CharSetandLanguageNegotiation-3"},
+ {PROTO_Z3950, CLASS_NEGOT, VAL_CHARNEG4, {15,4,-1},
+ "CharSetandLanguageNegotiation-4"},
{PROTO_Z3950, CLASS_NEGOT, VAL_ID_CHARSET, {15,1000,81,1,-1},
"ID-Charset" },
{PROTO_Z3950, CLASS_USERINFO,VAL_CQL, {16, 2, -1},
"CQL"},
- {PROTO_GENERAL, CLASS_GENERAL, VAL_UCS2, {1,0,10646,1,0,2,-1},
+ {PROTO_GENERAL, CLASS_GENERAL, VAL_UCS2, {1,0,10646,1,0,2,-1},
"UCS-2"},
- {PROTO_GENERAL, CLASS_GENERAL, VAL_UCS4, {1,0,10646,1,0,4,-1},
+ {PROTO_GENERAL, CLASS_GENERAL, VAL_UCS4, {1,0,10646,1,0,4,-1},
"UCS-4"},
- {PROTO_GENERAL, CLASS_GENERAL, VAL_UTF16, {1,0,10646,1,0,5,-1},
+ {PROTO_GENERAL, CLASS_GENERAL, VAL_UTF16, {1,0,10646,1,0,5,-1},
"UTF-16"},
- {PROTO_GENERAL, CLASS_GENERAL, VAL_UTF8, {1,0,10646,1,0,8,-1},
+ {PROTO_GENERAL, CLASS_GENERAL, VAL_UTF8, {1,0,10646,1,0,8,-1},
"UTF-8"},
- {PROTO_Z3950, CLASS_USERINFO,VAL_OCLCUI, {10, 1000, 17, 1, -1},
+ {PROTO_Z3950, CLASS_USERINFO,VAL_OCLCUI, {10, 1000, 17, 1, -1},
"OCLC-userInfo"},
- {PROTO_NOP, CLASS_NOP, VAL_NOP, {-1}, 0 }
+ {PROTO_Z3950, CLASS_EXTSERV, VAL_XMLES, {9,1000,105,4,-1},
+ "XML-ES"},
+ {PROTO_NOP, CLASS_NOP, VAL_NOP, {-1}, 0 }
};
/* OID utilities */
{
while (*oidentp->oidsuffix >= 0)
{
- oid_addent (oidentp->oidsuffix, oidentp->proto,
- oidentp->oclass,
- oidentp->desc, oidentp->value);
- oidentp++;
+ oid_addent (oidentp->oidsuffix, oidentp->proto,
+ oidentp->oclass,
+ oidentp->desc, oidentp->value);
+ oidentp++;
}
}
{
if (oid_init_flag == 0)
{
- /* oid_transfer is thread safe, so there's nothing wrong in having
- two threads calling it simultaniously. On the other hand
- no thread may exit oid_init before all OID's bave been
- transferred - which is why checked is set after oid_transfer...
- */
- nmem_mutex_create (&oid_mutex);
- nmem_mutex_enter (oid_mutex);
- if (!oid_nmem)
- oid_nmem = nmem_create ();
- nmem_mutex_leave (oid_mutex);
- oid_transfer (standard_oids);
- oid_init_flag = 1;
+ /* oid_transfer is thread safe, so there's nothing wrong in having
+ two threads calling it simultaniously. On the other hand
+ no thread may exit oid_init before all OID's bave been
+ transferred - which is why checked is set after oid_transfer...
+ */
+ nmem_mutex_create (&oid_mutex);
+ nmem_mutex_enter (oid_mutex);
+ if (!oid_nmem)
+ oid_nmem = nmem_create ();
+ nmem_mutex_leave (oid_mutex);
+ oid_transfer (standard_oids);
+ oid_init_flag = 1;
}
}
proto = PROTO_GENERAL;
for (ol = oident_table; ol; ol = ol->next)
{
- struct oident *p = &ol->oident;
+ struct oident *p = &ol->oident;
if (p->proto == proto && !oid_oidcmp(o + prelen, p->oidsuffix))
return p;
- if (p->proto == PROTO_GENERAL && !oid_oidcmp (o, p->oidsuffix))
- return p;
+ if (p->proto == PROTO_GENERAL && !oid_oidcmp (o, p->oidsuffix))
+ return p;
}
return 0;
}
oid_init ();
for (ol = oident_table; ol; ol = ol->next)
{
- struct oident *p = &ol->oident;
+ struct oident *p = &ol->oident;
if (ent->value == p->value &&
(p->proto == PROTO_GENERAL || (ent->proto == p->proto &&
- (ent->oclass == p->oclass || ent->oclass == CLASS_GENERAL))))
- {
- if (p->proto == PROTO_Z3950)
- oid_oidcpy(ret, z3950_prefix);
- else if (p->proto == PROTO_SR)
- oid_oidcpy(ret, sr_prefix);
- else
- ret[0] = -1;
- oid_oidcat(ret, p->oidsuffix);
- ent->desc = p->desc;
- return ret;
- }
+ (ent->oclass == p->oclass || ent->oclass == CLASS_GENERAL))))
+ {
+ if (p->proto == PROTO_Z3950)
+ oid_oidcpy(ret, z3950_prefix);
+ else if (p->proto == PROTO_SR)
+ oid_oidcpy(ret, sr_prefix);
+ else
+ ret[0] = -1;
+ oid_oidcat(ret, p->oidsuffix);
+ ent->desc = p->desc;
+ return ret;
+ }
}
ret[0] = -1;
return 0;
}
struct oident *oid_addent (int *oid, enum oid_proto proto,
- enum oid_class oclass,
- const char *desc, int value)
+ enum oid_class oclass,
+ const char *desc, int value)
{
struct oident *oident = 0;
nmem_mutex_enter (oid_mutex);
if (!oident)
{
- char desc_str[200];
- struct oident_list *oident_list;
- oident_list = (struct oident_list *)
- nmem_malloc (oid_nmem, sizeof(*oident_list));
- oident = &oident_list->oident;
- oident->proto = proto;
- oident->oclass = oclass;
-
- if (!desc)
- {
- int i;
-
- sprintf (desc_str, "%d", *oid);
- for (i = 1; i < 12 && oid[i] >= 0; i++)
- sprintf (desc_str+strlen(desc_str), ".%d", oid[i]);
- desc = desc_str;
- }
- oident->desc = nmem_strdup (oid_nmem, desc);
- if (value == VAL_DYNAMIC)
- oident->value = (enum oid_value) (++oid_value_dynamic);
- else
- oident->value = (enum oid_value) value;
- oid_oidcpy (oident->oidsuffix, oid);
- oident_list->next = oident_table;
- oident_table = oident_list;
+ struct oident_list *oident_list;
+ oident_list = (struct oident_list *)
+ nmem_malloc (oid_nmem, sizeof(*oident_list));
+ oident = &oident_list->oident;
+ oident->proto = proto;
+ oident->oclass = oclass;
+
+ if (!desc)
+ {
+ char desc_str[OID_STR_MAX];
+ int i;
+
+ *desc_str = '\0';
+ if (*oid >= 0)
+ {
+ sprintf (desc_str, "%d", *oid);
+ for (i = 1; i < OID_SIZE && oid[i] >= 0; i++)
+ sprintf (desc_str+strlen(desc_str), ".%d", oid[i]);
+ }
+ oident->desc = nmem_strdup(oid_nmem, desc_str);
+ }
+ else
+ oident->desc = nmem_strdup(oid_nmem, desc);
+ if (value == VAL_DYNAMIC)
+ oident->value = (enum oid_value) (++oid_value_dynamic);
+ else
+ oident->value = (enum oid_value) value;
+ oid_oidcpy (oident->oidsuffix, oid);
+ oident_list->next = oident_table;
+ oident_table = oident_list;
}
nmem_mutex_leave (oid_mutex);
return oident;
struct oident *oident;
if (!oid)
- return 0;
+ return 0;
oid_init ();
oident = oid_getentbyoid_x (oid);
if (!oident)
- oident = oid_addent (oid, PROTO_GENERAL, CLASS_GENERAL,
- NULL, VAL_DYNAMIC);
+ oident = oid_addent (oid, PROTO_GENERAL, CLASS_GENERAL,
+ NULL, VAL_DYNAMIC);
return oident;
}
int val = 0, i = 0, oid[OID_SIZE];
struct oident *oident;
- while (isdigit (*name))
+ while (isdigit (*(const unsigned char *) name))
{
val = val*10 + (*name - '0');
name++;
{
if (i < OID_SIZE-1)
oid[i++] = val;
- val = 0;
+ val = 0;
name++;
}
}
oident = oid_getentbyoid_x (oid);
if (!oident)
oident = oid_addent (oid, PROTO_GENERAL, CLASS_GENERAL, NULL,
- VAL_DYNAMIC);
+ VAL_DYNAMIC);
return oident->value;
}
struct oident_list *ol;
oid_init ();
- if (isdigit (*name))
+ if (isdigit (*(const unsigned char *) name))
return oid_getval_raw (name);
for (ol = oident_table; ol; ol = ol->next)
- if (!yaz_matchstr(ol->oident.desc, name))
- {
- return ol->oident.value;
- }
+ if (!yaz_matchstr(ol->oident.desc, name))
+ {
+ return ol->oident.value;
+ }
return VAL_NONE;
}
(*func)(&ol->oident, vp);
}
-int *oid_name_to_oid(oid_class oclass, const char *name, int *oid) {
+int *oid_name_to_oid(oid_class oclass, const char *name, int *oid)
+{
struct oident ent;
/* Translate syntax to oid_val */
return oid_ent_to_oid(&ent, oid);
}
-char *oid_to_dotstring(const int *oid, char *oidbuf) {
+char *oid_to_dotstring(const int *oid, char *oidbuf)
+{
char tmpbuf[20];
int i;
oidbuf[0] = '\0';
- for (i = 0; oid[i] != -1; i++) {
- sprintf(tmpbuf, "%d", oid[i]);
- if (i > 0) strcat(oidbuf, ".");
- strcat(oidbuf, tmpbuf);
+ for (i = 0; oid[i] != -1 && i < OID_SIZE; i++)
+ {
+ sprintf(tmpbuf, "%d", oid[i]);
+ if (i > 0)
+ strcat(oidbuf, ".");
+ strcat(oidbuf, tmpbuf);
}
-
return oidbuf;
}
-char *oid_name_to_dotstring(oid_class oclass, const char *name, char *oidbuf) {
+char *oid_name_to_dotstring(oid_class oclass, const char *name, char *oidbuf)
+{
int oid[OID_SIZE];
(void) oid_name_to_oid(oclass, name, oid);
return oid_to_dotstring(oid, oidbuf);
}
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
+