From: Adam Dickmeiss Date: Thu, 12 Apr 2007 20:47:27 +0000 (+0000) Subject: Added function yaz_oid_add which adds custom OID entry to database. X-Git-Tag: YAZ.3.0.0~61 X-Git-Url: http://lists.indexdata.dk/?a=commitdiff_plain;h=be821514c869d68186361b5aab6bbfd1aa60e087;p=yaz-moved-to-github.git Added function yaz_oid_add which adds custom OID entry to database. Re-implemented 'register_oid' for yaz-client. --- diff --git a/client/client.c b/client/client.c index 59a70c2..b091b31 100644 --- a/client/client.c +++ b/client/client.c @@ -2,7 +2,7 @@ * Copyright (C) 1995-2007, Index Data ApS * See the file LICENSE for details. * - * $Id: client.c,v 1.332 2007-04-12 13:52:57 adam Exp $ + * $Id: client.c,v 1.333 2007-04-12 20:47:27 adam Exp $ */ /** \file client.c * \brief yaz-client program @@ -3607,7 +3607,6 @@ int cmd_set_marcdump(const char* arg) return 1; } -#if 0 /* this command takes 3 arge {name class oid} */ @@ -3634,12 +3633,10 @@ int cmd_register_oid(const char* args) { {0,(enum oid_class) 0} }; char oname_str[101], oclass_str[101], oid_str[101]; - char* name; int i; - oid_class oidclass = CLASS_GENERAL; - int val = 0, oid[OID_SIZE]; - struct oident * new_oident=NULL; - + int oidclass = CLASS_GENERAL; + int oid[OID_SIZE]; + if (sscanf (args, "%100[^ ] %100[^ ] %100s", oname_str,oclass_str, oid_str) < 1) { printf("Error in register command \n"); @@ -3659,35 +3656,15 @@ int cmd_register_oid(const char* args) { return 0; } - i = 0; - name = oid_str; - val = 0; - - while (isdigit (*(unsigned char *) name)) - { - val = val*10 + (*name - '0'); - name++; - if (*name == '.') - { - if (i < OID_SIZE-1) - oid[i++] = val; - val = 0; - name++; - } - } - oid[i] = val; - oid[i+1] = -1; - - new_oident = oid_addent (oid, PROTO_GENERAL, oidclass, oname_str, - VAL_DYNAMIC); - if(strcmp(new_oident->desc,oname_str)) + oid_dotstring_to_oid(oid_str, oid); + + if (yaz_oid_add(yaz_oid_std(), oidclass, oname_str, oid)) { - fprintf(stderr,"oid is already named as %s, registration failed\n", - new_oident->desc); + printf("oid %s already exists, registration failed\n", + oname_str); } return 1; } -#endif int cmd_push_command(const char* arg) { @@ -4421,9 +4398,7 @@ static struct { {"set_auto_wait", cmd_set_auto_wait," on|off",complete_auto_reconnect,1,NULL}, {"set_otherinfo", cmd_set_otherinfo," ",NULL,0,NULL}, {"sleep", cmd_sleep,"",NULL,0,NULL}, -#if 0 {"register_oid", cmd_register_oid," ",NULL,0,NULL}, -#endif {"push_command", cmd_push_command,"",command_generator,0,NULL}, {"register_tab", cmd_register_tab," ",command_generator,0,NULL}, {"cclparse", cmd_cclparse,"",NULL,0,NULL}, diff --git a/include/yaz/oid_db.h b/include/yaz/oid_db.h index 094a1f4..0903b23 100644 --- a/include/yaz/oid_db.h +++ b/include/yaz/oid_db.h @@ -24,7 +24,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -/* $Id: oid_db.h,v 1.1 2007-04-12 13:52:57 adam Exp $ */ +/* $Id: oid_db.h,v 1.2 2007-04-12 20:47:27 adam Exp $ */ /** * \file oid_db.h @@ -40,7 +40,7 @@ YAZ_BEGIN_CDECL /** \brief OID database */ -typedef struct yaz_oid_entry *yaz_oid_db_t; +typedef struct yaz_oid_db *yaz_oid_db_t; /** \brief returns standard OID database \retval OID database handle @@ -124,6 +124,18 @@ YAZ_EXPORT void yaz_oid_trav(yaz_oid_db_t oid_db, YAZ_EXPORT int yaz_oid_is_iso2709(const int *oid); +/** \brief adds new OID entry to database + \param oid_db database + \param oclass OID class + \param name name of OID + \param new_oid OID value (raw OID) + \retval 0 OID added + \retval -1 OID name+oclass already exists +*/ +YAZ_EXPORT +int yaz_oid_add(yaz_oid_db_t oid_db, int oclass, const char *name, + const int *new_oid); + #define OID_STR_BIB1 "Bib-1" #define OID_STR_DIAG1 "Diag-1" #define OID_STR_USMARC "USmarc" diff --git a/include/yaz/oid_util.h b/include/yaz/oid_util.h index d0b85b6..3dafc0d 100644 --- a/include/yaz/oid_util.h +++ b/include/yaz/oid_util.h @@ -24,7 +24,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -/* $Id: oid_util.h,v 1.1 2007-04-12 13:52:57 adam Exp $ */ +/* $Id: oid_util.h,v 1.2 2007-04-12 20:47:27 adam Exp $ */ /** * \file oid_util.h @@ -79,7 +79,9 @@ YAZ_EXPORT void oid_oidcpy(int *t, const int *s); YAZ_EXPORT void oid_oidcat(int *t, const int *s); YAZ_EXPORT int oid_oidcmp(const int *o1, const int *o2); YAZ_EXPORT int oid_oidlen(const int *o); -YAZ_EXPORT char *oid_to_dotstring(const int *oid, char *oidbuf); +YAZ_EXPORT char *oid_oid_to_dotstring(const int *oid, char *oidbuf); +YAZ_EXPORT int oid_dotstring_to_oid(const char *name, int *oid); + YAZ_END_CDECL #endif diff --git a/src/odr_util.c b/src/odr_util.c index c50ac55..c28c586 100644 --- a/src/odr_util.c +++ b/src/odr_util.c @@ -2,7 +2,7 @@ * Copyright (C) 1995-2007, Index Data ApS * See the file LICENSE for details. * - * $Id: odr_util.c,v 1.11 2007-04-12 13:52:57 adam Exp $ + * $Id: odr_util.c,v 1.12 2007-04-12 20:47:28 adam Exp $ */ /** * \file odr_util.c @@ -63,20 +63,13 @@ Odr_oid *odr_oiddup(ODR odr, const Odr_oid *o) Odr_oid *odr_getoidbystr_nmem(NMEM nmem, const char *str) { - int num = 1, i = 0; - const char *p = str; - Odr_oid *ret; + int oid[OID_SIZE]; + int *ret; - if (!isdigit(*(const unsigned char *) str)) + if (oid_dotstring_to_oid(str, oid)) return 0; - while ((p = strchr(p, '.'))) - num++, p++; - ret = (int *)nmem_malloc(nmem, sizeof(*ret)*(num + 1)); - p = str; - do - ret[i++] = atoi(p); - while ((p = strchr(p, '.')) && *++p); - ret[i] = -1; + ret = (int *)nmem_malloc(nmem, sizeof(*ret)*(oid_oidlen(oid) + 1)); + oid_oidcpy(ret, oid); return ret; } diff --git a/src/oid_db.c b/src/oid_db.c index 1c5448b..f809530 100644 --- a/src/oid_db.c +++ b/src/oid_db.c @@ -2,7 +2,7 @@ * Copyright (C) 1995-2007, Index Data ApS * See the file LICENSE for details. * - * $Id: oid_db.c,v 1.1 2007-04-12 13:52:57 adam Exp $ + * $Id: oid_db.c,v 1.2 2007-04-12 20:47:28 adam Exp $ */ /** @@ -23,19 +23,19 @@ struct yaz_oid_entry { int oclass; - int oid[10]; + int oid[OID_SIZE]; char *name; }; #define Z3950_PREFIX 1, 2, 840, 10003 -static struct yaz_oid_entry standard_oids[] = +static struct yaz_oid_entry standard_list[] = { /* General definitions */ {CLASS_TRANSYN, {2, 1, 1,-1}, "BER" }, {CLASS_TRANSYN, {1, 0, 2709, 1, 1,-1}, "ISO2709"}, {CLASS_GENERAL, {1, 0, 10161, 2, 1,-1}, OID_STR_ILL_1 }, - {CLASS_ABSYN, {2, 1,-1}, "Z-APDU"}, + {CLASS_ABSYN, {2, 1,-1}, "Z-APDU"}, {CLASS_APPCTX, {1, 1,-1}, "Z-BASIC"}, {CLASS_ATTSET, {Z3950_PREFIX, 3, 1,-1}, "Bib-1"}, {CLASS_ATTSET, {Z3950_PREFIX, 3, 2,-1}, "Exp-1"}, @@ -58,254 +58,153 @@ static struct yaz_oid_entry standard_oids[] = {CLASS_ATTSET, {Z3950_PREFIX, 3, 18,-1}, "Bib-2"}, {CLASS_ATTSET, {Z3950_PREFIX, 3, 19,-1}, "ZeeRex"}, /* New applications should use Zthes-1 instead of this Satan-spawn */ - {CLASS_ATTSET, {Z3950_PREFIX, 3,1000, 81,1,-1}, - "Thesaurus-attset"}, - {CLASS_ATTSET, {Z3950_PREFIX, 3,1000, 81,2,-1}, - "IDXPATH"}, - {CLASS_ATTSET, {Z3950_PREFIX, 3,1000, 81,3,-1}, - "EXTLITE"}, - {CLASS_DIAGSET, {Z3950_PREFIX, 4, 1,-1}, - OID_STR_BIB1}, - {CLASS_DIAGSET, {Z3950_PREFIX, 4, 2,-1}, - OID_STR_DIAG1}, - {CLASS_DIAGSET, {Z3950_PREFIX, 4, 3,-1}, - "Diag-ES"}, - {CLASS_DIAGSET, {Z3950_PREFIX, 4, 3,-1}, - "Diag-General"}, - {CLASS_RECSYN, {Z3950_PREFIX, 5, 1,-1}, - "Unimarc"}, - {CLASS_RECSYN, {Z3950_PREFIX, 5, 2,-1}, - "Intermarc"}, - {CLASS_RECSYN, {Z3950_PREFIX, 5, 3,-1}, - "CCF"}, - {CLASS_RECSYN, {Z3950_PREFIX, 5, 10,-1}, - OID_STR_USMARC}, + {CLASS_ATTSET, {Z3950_PREFIX, 3,1000, 81,1,-1}, "Thesaurus-attset"}, + {CLASS_ATTSET, {Z3950_PREFIX, 3,1000, 81,2,-1}, "IDXPATH"}, + {CLASS_ATTSET, {Z3950_PREFIX, 3,1000, 81,3,-1}, "EXTLITE"}, + {CLASS_DIAGSET, {Z3950_PREFIX, 4, 1,-1}, OID_STR_BIB1}, + {CLASS_DIAGSET, {Z3950_PREFIX, 4, 2,-1}, OID_STR_DIAG1}, + {CLASS_DIAGSET, {Z3950_PREFIX, 4, 3,-1}, "Diag-ES"}, + {CLASS_DIAGSET, {Z3950_PREFIX, 4, 3,-1}, "Diag-General"}, + {CLASS_RECSYN, {Z3950_PREFIX, 5, 1,-1}, "Unimarc"}, + {CLASS_RECSYN, {Z3950_PREFIX, 5, 2,-1}, "Intermarc"}, + {CLASS_RECSYN, {Z3950_PREFIX, 5, 3,-1}, "CCF"}, + {CLASS_RECSYN, {Z3950_PREFIX, 5, 10,-1}, OID_STR_USMARC}, /* MARC21 is just an alias for the original USmarc */ - {CLASS_RECSYN, {Z3950_PREFIX, 5, 10,-1}, - "MARC21"}, - {CLASS_RECSYN, {Z3950_PREFIX, 5, 11,-1}, - "UKmarc"}, - {CLASS_RECSYN, {Z3950_PREFIX, 5, 12,-1}, - "Normarc"}, - {CLASS_RECSYN, {Z3950_PREFIX, 5, 13,-1}, - "Librismarc"}, - {CLASS_RECSYN, {Z3950_PREFIX, 5, 14,-1}, - "Danmarc"}, - {CLASS_RECSYN, {Z3950_PREFIX, 5, 15,-1}, - "Finmarc"}, - {CLASS_RECSYN, {Z3950_PREFIX, 5, 16,-1}, - "MAB"}, - {CLASS_RECSYN, {Z3950_PREFIX, 5, 17,-1}, - "Canmarc"}, - {CLASS_RECSYN, {Z3950_PREFIX, 5, 18,-1}, - "SBN"}, - {CLASS_RECSYN, {Z3950_PREFIX, 5, 19,-1}, - "Picamarc"}, - {CLASS_RECSYN, {Z3950_PREFIX, 5, 20,-1}, - "Ausmarc"}, - {CLASS_RECSYN, {Z3950_PREFIX, 5, 21,-1}, - "Ibermarc"}, - {CLASS_RECSYN, {Z3950_PREFIX, 5, 22,-1}, - "Carmarc"}, - {CLASS_RECSYN, {Z3950_PREFIX, 5, 23,-1}, - "Malmarc"}, - {CLASS_RECSYN, {Z3950_PREFIX, 5, 24,-1}, - "JPmarc"}, - {CLASS_RECSYN, {Z3950_PREFIX, 5, 25,-1}, - "SWEmarc"}, - {CLASS_RECSYN, {Z3950_PREFIX, 5, 26,-1}, - "SIGLEmarc"}, - {CLASS_RECSYN, {Z3950_PREFIX, 5, 27,-1}, - "ISDSmarc"}, - {CLASS_RECSYN, {Z3950_PREFIX, 5, 28,-1}, - "RUSmarc"}, - {CLASS_RECSYN, {Z3950_PREFIX, 5, 29,-1}, - "Hunmarc"}, - {CLASS_RECSYN, {Z3950_PREFIX, 5, 30,-1}, - "NACSIS-CATP"}, - {CLASS_RECSYN, {Z3950_PREFIX, 5, 31,-1}, - "FINMARC2000"}, - {CLASS_RECSYN, {Z3950_PREFIX, 5, 32,-1}, - "MARC21-fin"}, - {CLASS_RECSYN, {Z3950_PREFIX, 5, 100,-1}, - OID_STR_EXPLAIN}, - {CLASS_RECSYN, {Z3950_PREFIX, 5, 101,-1}, - OID_STR_SUTRS}, - {CLASS_RECSYN, {Z3950_PREFIX, 5, 102,-1}, - OID_STR_OPAC}, - {CLASS_RECSYN, {Z3950_PREFIX, 5, 103,-1}, - OID_STR_SUMMARY}, - {CLASS_RECSYN, {Z3950_PREFIX, 5, 104,-1}, - "GRS-0"}, - {CLASS_RECSYN, {Z3950_PREFIX, 5, 105,-1}, - OID_STR_GRS1 }, - {CLASS_RECSYN, {Z3950_PREFIX, 5, 106,-1}, - OID_STR_EXTENDED}, - {CLASS_RECSYN, {Z3950_PREFIX, 5, 107,-1}, - "Fragment"}, - {CLASS_RECSYN, {Z3950_PREFIX, 5, 109,1,-1}, - "pdf"}, - {CLASS_RECSYN, {Z3950_PREFIX, 5, 109,2,-1}, - OID_STR_POSTSCRIPT}, - {CLASS_RECSYN, {Z3950_PREFIX, 5, 109,3,-1}, - OID_STR_HTML}, - {CLASS_RECSYN, {Z3950_PREFIX, 5, 109,4,-1}, - "tiff"}, - {CLASS_RECSYN, {Z3950_PREFIX, 5, 109,5,-1}, - "gif"}, - {CLASS_RECSYN, {Z3950_PREFIX, 5, 109,6,-1}, - "jpeg"}, - {CLASS_RECSYN, {Z3950_PREFIX, 5, 109,7,-1}, - "png"}, - {CLASS_RECSYN, {Z3950_PREFIX, 5, 109,8,-1}, - "mpeg"}, - {CLASS_RECSYN, {Z3950_PREFIX, 5, 109,9,-1}, - "sgml"}, - - {CLASS_RECSYN, {Z3950_PREFIX, 5, 110,1,-1}, - "tiff-b"}, - {CLASS_RECSYN, {Z3950_PREFIX, 5, 110,2,-1}, - "wav"}, + {CLASS_RECSYN, {Z3950_PREFIX, 5, 10,-1}, "MARC21"}, + {CLASS_RECSYN, {Z3950_PREFIX, 5, 11,-1}, "UKmarc"}, + {CLASS_RECSYN, {Z3950_PREFIX, 5, 12,-1}, "Normarc"}, + {CLASS_RECSYN, {Z3950_PREFIX, 5, 13,-1}, "Librismarc"}, + {CLASS_RECSYN, {Z3950_PREFIX, 5, 14,-1}, "Danmarc"}, + {CLASS_RECSYN, {Z3950_PREFIX, 5, 15,-1}, "Finmarc"}, + {CLASS_RECSYN, {Z3950_PREFIX, 5, 16,-1}, "MAB"}, + {CLASS_RECSYN, {Z3950_PREFIX, 5, 17,-1}, "Canmarc"}, + {CLASS_RECSYN, {Z3950_PREFIX, 5, 18,-1}, "SBN"}, + {CLASS_RECSYN, {Z3950_PREFIX, 5, 19,-1}, "Picamarc"}, + {CLASS_RECSYN, {Z3950_PREFIX, 5, 20,-1}, "Ausmarc"}, + {CLASS_RECSYN, {Z3950_PREFIX, 5, 21,-1}, "Ibermarc"}, + {CLASS_RECSYN, {Z3950_PREFIX, 5, 22,-1}, "Carmarc"}, + {CLASS_RECSYN, {Z3950_PREFIX, 5, 23,-1}, "Malmarc"}, + {CLASS_RECSYN, {Z3950_PREFIX, 5, 24,-1}, "JPmarc"}, + {CLASS_RECSYN, {Z3950_PREFIX, 5, 25,-1}, "SWEmarc"}, + {CLASS_RECSYN, {Z3950_PREFIX, 5, 26,-1}, "SIGLEmarc"}, + {CLASS_RECSYN, {Z3950_PREFIX, 5, 27,-1}, "ISDSmarc"}, + {CLASS_RECSYN, {Z3950_PREFIX, 5, 28,-1}, "RUSmarc"}, + {CLASS_RECSYN, {Z3950_PREFIX, 5, 29,-1}, "Hunmarc"}, + {CLASS_RECSYN, {Z3950_PREFIX, 5, 30,-1}, "NACSIS-CATP"}, + {CLASS_RECSYN, {Z3950_PREFIX, 5, 31,-1}, "FINMARC2000"}, + {CLASS_RECSYN, {Z3950_PREFIX, 5, 32,-1}, "MARC21-fin"}, + {CLASS_RECSYN, {Z3950_PREFIX, 5, 100,-1}, OID_STR_EXPLAIN}, + {CLASS_RECSYN, {Z3950_PREFIX, 5, 101,-1}, OID_STR_SUTRS}, + {CLASS_RECSYN, {Z3950_PREFIX, 5, 102,-1}, OID_STR_OPAC}, + {CLASS_RECSYN, {Z3950_PREFIX, 5, 103,-1}, OID_STR_SUMMARY}, + {CLASS_RECSYN, {Z3950_PREFIX, 5, 104,-1}, "GRS-0"}, + {CLASS_RECSYN, {Z3950_PREFIX, 5, 105,-1}, OID_STR_GRS1 }, + {CLASS_RECSYN, {Z3950_PREFIX, 5, 106,-1}, OID_STR_EXTENDED}, + {CLASS_RECSYN, {Z3950_PREFIX, 5, 107,-1}, "Fragment"}, + {CLASS_RECSYN, {Z3950_PREFIX, 5, 109,1,-1}, "pdf"}, + {CLASS_RECSYN, {Z3950_PREFIX, 5, 109,2,-1}, OID_STR_POSTSCRIPT}, + {CLASS_RECSYN, {Z3950_PREFIX, 5, 109,3,-1}, OID_STR_HTML}, + {CLASS_RECSYN, {Z3950_PREFIX, 5, 109,4,-1}, "tiff"}, + {CLASS_RECSYN, {Z3950_PREFIX, 5, 109,5,-1}, "gif"}, + {CLASS_RECSYN, {Z3950_PREFIX, 5, 109,6,-1}, "jpeg"}, + {CLASS_RECSYN, {Z3950_PREFIX, 5, 109,7,-1}, "png"}, + {CLASS_RECSYN, {Z3950_PREFIX, 5, 109,8,-1}, "mpeg"}, + {CLASS_RECSYN, {Z3950_PREFIX, 5, 109,9,-1}, "sgml"}, + {CLASS_RECSYN, {Z3950_PREFIX, 5, 110,1,-1}, "tiff-b"}, + {CLASS_RECSYN, {Z3950_PREFIX, 5, 110,2,-1}, "wav"}, + {CLASS_RECSYN, {Z3950_PREFIX, 5, 111,-1}, "SQL-RS"}, + {CLASS_RECSYN, {Z3950_PREFIX, 5, 1000, 81, 2,-1}, OID_STR_SOIF}, + {CLASS_RECSYN, {Z3950_PREFIX, 5, 109, 10,-1}, OID_STR_XML }, + {CLASS_RECSYN, {Z3950_PREFIX, 5, 109, 10,-1}, "application-XML"}, + {CLASS_RECSYN, {Z3950_PREFIX, 5, 109, 11,-1}, OID_STR_APPLICATION_XML }, + {CLASS_RESFORM, {Z3950_PREFIX, 7, 1,-1}, "Resource-1"}, + {CLASS_RESFORM, {Z3950_PREFIX, 7, 2,-1}, "Resource-2"}, + {CLASS_RESFORM, {Z3950_PREFIX, 7, 1000, 81, 1,-1}, "UNIverse-Resource-Report"}, + {CLASS_ACCFORM, {Z3950_PREFIX, 8, 1,-1}, "Prompt-1"}, + {CLASS_ACCFORM, {Z3950_PREFIX, 8, 2,-1}, "Des-1"}, + {CLASS_ACCFORM, {Z3950_PREFIX, 8, 3,-1}, "Krb-1"}, + {CLASS_EXTSERV, {Z3950_PREFIX, 9, 1,-1}, "Pers. set"}, + {CLASS_EXTSERV, {Z3950_PREFIX, 9, 2,-1}, "Pers. query"}, + {CLASS_EXTSERV, {Z3950_PREFIX, 9, 3,-1}, "Per'd query"}, + {CLASS_EXTSERV, {Z3950_PREFIX, 9, 4,-1}, OID_STR_ITEMORDER }, + {CLASS_EXTSERV, {Z3950_PREFIX, 9, 5,-1}, "DB. Update (first version)"}, + {CLASS_EXTSERV, {Z3950_PREFIX, 9, 5,1,-1}, "DB. Update (second version)"}, + {CLASS_EXTSERV, {Z3950_PREFIX, 9, 5, 1, 1,-1}, OID_STR_EXT_UPDATE}, + {CLASS_EXTSERV, {Z3950_PREFIX, 9, 6,-1}, "exp. spec."}, + {CLASS_EXTSERV, {Z3950_PREFIX, 9, 7,-1}, "exp. inv."}, + {CLASS_EXTSERV, {Z3950_PREFIX, 9, 1000, 81, 1,-1}, OID_STR_ADMIN}, + {CLASS_USERINFO, {Z3950_PREFIX, 10, 1,-1}, "searchResult-1"}, + {CLASS_USERINFO, {Z3950_PREFIX, 10, 2,-1}, "CharSetandLanguageNegotiation"}, + {CLASS_USERINFO, {Z3950_PREFIX, 10, 3,-1}, OID_STR_USERINFO_1}, + {CLASS_USERINFO, {Z3950_PREFIX, 10, 4,-1}, "MultipleSearchTerms-1"}, + {CLASS_USERINFO, {Z3950_PREFIX, 10, 5,-1}, "MultipleSearchTerms-2"}, + {CLASS_USERINFO, {Z3950_PREFIX, 10, 6,-1}, "DateTime"}, + {CLASS_USERINFO, {Z3950_PREFIX, 10, 1000, 81, 1,-1}, OID_STR_PROXY}, + {CLASS_USERINFO, {Z3950_PREFIX, 10, 1000, 81, 2,-1}, OID_STR_COOKIE}, + {CLASS_USERINFO, {Z3950_PREFIX, 10, 1000, 81, 3,-1}, OID_STR_CLIENT_IP }, + {CLASS_ELEMSPEC, {1, 2, 840, 1003, 11, 1,-1}, "Espec-1"}, + {CLASS_VARSET, {Z3950_PREFIX, 12, 1,-1}, "Variant-1"}, + {CLASS_SCHEMA, {Z3950_PREFIX, 13, 1,-1}, "WAIS-schema"}, + {CLASS_SCHEMA, {Z3950_PREFIX, 13, 2,-1}, "GILS-schema"}, + {CLASS_SCHEMA, {Z3950_PREFIX, 13, 3,-1}, "Collections-schema"}, + {CLASS_SCHEMA, {Z3950_PREFIX, 13, 4,-1}, "Geo-schema"}, + {CLASS_SCHEMA, {Z3950_PREFIX, 13, 5,-1}, "CIMI-schema"}, + {CLASS_SCHEMA, {Z3950_PREFIX, 13, 6,-1}, "Update ES"}, + {CLASS_SCHEMA, {Z3950_PREFIX, 13, 7,-1}, "Holdings"}, + {CLASS_SCHEMA, {Z3950_PREFIX, 13, 8,-1}, "Zthes"}, + {CLASS_SCHEMA, {Z3950_PREFIX, 13, 1000, 81, 1,-1}, "thesaurus-schema"}, + {CLASS_SCHEMA, {Z3950_PREFIX, 13, 1000, 81, 2,-1}, "Explain-schema"}, + {CLASS_TAGSET, {Z3950_PREFIX, 14, 1,-1}, "TagsetM"}, + {CLASS_TAGSET, {Z3950_PREFIX, 14, 2,-1}, "TagsetG"}, + {CLASS_TAGSET, {Z3950_PREFIX, 14, 3,-1}, "STAS-tagset"}, + {CLASS_TAGSET, {Z3950_PREFIX, 14, 4,-1}, "GILS-tagset"}, + {CLASS_TAGSET, {Z3950_PREFIX, 14, 5,-1}, "Collections-tagset"}, + {CLASS_TAGSET, {Z3950_PREFIX, 14, 6,-1}, "CIMI-tagset"}, + {CLASS_TAGSET, {Z3950_PREFIX, 14, 1000, 81, 1,-1}, "thesaurus-tagset"}, + {CLASS_TAGSET, {Z3950_PREFIX, 14, 1000, 81, 2,-1}, "Explain-tagset"}, + {CLASS_TAGSET, {Z3950_PREFIX, 14, 8,-1}, "Zthes-tagset"}, + {CLASS_NEGOT, {Z3950_PREFIX, 15, 3,-1}, OID_STR_CHARNEG_3 }, + {CLASS_NEGOT, {Z3950_PREFIX, 15, 4,-1}, OID_STR_CHARNEG_4 }, + {CLASS_NEGOT, {Z3950_PREFIX, 15, 1000, 81, 1, -1}, OID_STR_ID_CHARSET }, + {CLASS_USERINFO, {1, 2, 840, 1003, 16, 2, -1}, "CQL"}, + {CLASS_GENERAL, {1,0,10646,1,0,2,-1}, "UCS-2"}, + {CLASS_GENERAL, {1,0,10646,1,0,4,-1}, "UCS-4"}, + {CLASS_GENERAL, {1,0,10646,1,0,5,-1}, "UTF-16"}, + {CLASS_GENERAL, {1,0,10646,1,0,8,-1}, "UTF-8"}, + {CLASS_USERINFO, {Z3950_PREFIX, 10, 1000, 17, 1, -1}, "OCLC-userInfo"}, + {CLASS_EXTSERV, {Z3950_PREFIX, 9, 1000,105,4,-1}, OID_STR_XMLES }, + {CLASS_NOP, {-1}, 0} +}; - {CLASS_RECSYN, {Z3950_PREFIX, 5, 111,-1}, - "SQL-RS"}, - {CLASS_RECSYN, {Z3950_PREFIX, 5, 1000, 81, 2,-1}, - OID_STR_SOIF}, - {CLASS_RECSYN, {Z3950_PREFIX, 5, 109, 10,-1}, - OID_STR_XML }, - {CLASS_RECSYN, {Z3950_PREFIX, 5, 109, 10,-1}, - "application-XML"}, - {CLASS_RECSYN, {Z3950_PREFIX, 5, 109, 11,-1}, - OID_STR_APPLICATION_XML }, - {CLASS_RESFORM, {Z3950_PREFIX, 7, 1,-1}, - "Resource-1"}, - {CLASS_RESFORM, {Z3950_PREFIX, 7, 2,-1}, - "Resource-2"}, - {CLASS_RESFORM, {Z3950_PREFIX, 7, 1000, 81, 1,-1}, - "UNIverse-Resource-Report"}, +struct yaz_oid_db { + struct yaz_oid_entry *entries; + struct yaz_oid_db *next; + int xmalloced; +}; - {CLASS_ACCFORM, {Z3950_PREFIX, 8, 1,-1}, - "Prompt-1"}, - {CLASS_ACCFORM, {Z3950_PREFIX, 8, 2,-1}, - "Des-1"}, - {CLASS_ACCFORM, {Z3950_PREFIX, 8, 3,-1}, - "Krb-1"}, - {CLASS_EXTSERV, {Z3950_PREFIX, 9, 1,-1}, - "Pers. set"}, - {CLASS_EXTSERV, {Z3950_PREFIX, 9, 2,-1}, - "Pers. query"}, - {CLASS_EXTSERV, {Z3950_PREFIX, 9, 3,-1}, - "Per'd query"}, - {CLASS_EXTSERV, {Z3950_PREFIX, 9, 4,-1}, - OID_STR_ITEMORDER }, - {CLASS_EXTSERV, {Z3950_PREFIX, 9, 5,-1}, - "DB. Update (first version)"}, - {CLASS_EXTSERV, {Z3950_PREFIX, 9, 5,1,-1}, - "DB. Update (second version)"}, - {CLASS_EXTSERV, {Z3950_PREFIX, 9, 5, 1, 1,-1}, - OID_STR_EXT_UPDATE}, - {CLASS_EXTSERV, {Z3950_PREFIX, 9, 6,-1}, - "exp. spec."}, - {CLASS_EXTSERV, {Z3950_PREFIX, 9, 7,-1}, - "exp. inv."}, - {CLASS_EXTSERV, {Z3950_PREFIX, 9, 1000, 81, 1,-1}, - OID_STR_ADMIN}, - {CLASS_USERINFO, {Z3950_PREFIX, 10, 1,-1}, - "searchResult-1"}, - {CLASS_USERINFO, {Z3950_PREFIX, 10, 2,-1}, - "CharSetandLanguageNegotiation"}, - {CLASS_USERINFO, {Z3950_PREFIX, 10, 3,-1}, - OID_STR_USERINFO_1}, - {CLASS_USERINFO, {Z3950_PREFIX, 10, 4,-1}, - "MultipleSearchTerms-1"}, - {CLASS_USERINFO, {Z3950_PREFIX, 10, 5,-1}, - "MultipleSearchTerms-2"}, - {CLASS_USERINFO, {Z3950_PREFIX, 10, 6,-1}, - "DateTime"}, - {CLASS_USERINFO, {Z3950_PREFIX, 10, 1000, 81, 1,-1}, - OID_STR_PROXY}, - {CLASS_USERINFO, {Z3950_PREFIX, 10, 1000, 81, 2,-1}, - OID_STR_COOKIE}, - {CLASS_USERINFO, {Z3950_PREFIX, 10, 1000, 81, 3,-1}, - OID_STR_CLIENT_IP }, - {CLASS_ELEMSPEC, {1, 2, 840, 1003, 11, 1,-1}, - "Espec-1"}, - {CLASS_VARSET, {Z3950_PREFIX, 12, 1,-1}, - "Variant-1"}, - {CLASS_SCHEMA, {Z3950_PREFIX, 13, 1,-1}, - "WAIS-schema"}, - {CLASS_SCHEMA, {Z3950_PREFIX, 13, 2,-1}, - "GILS-schema"}, - {CLASS_SCHEMA, {Z3950_PREFIX, 13, 3,-1}, - "Collections-schema"}, - {CLASS_SCHEMA, {Z3950_PREFIX, 13, 4,-1}, - "Geo-schema"}, - {CLASS_SCHEMA, {Z3950_PREFIX, 13, 5,-1}, - "CIMI-schema"}, - {CLASS_SCHEMA, {Z3950_PREFIX, 13, 6,-1}, - "Update ES"}, - {CLASS_SCHEMA, {Z3950_PREFIX, 13, 7,-1}, - "Holdings"}, - {CLASS_SCHEMA, {Z3950_PREFIX, 13, 8,-1}, - "Zthes"}, - {CLASS_SCHEMA, {Z3950_PREFIX, 13, 1000, 81, 1,-1}, - "thesaurus-schema"}, - {CLASS_SCHEMA, {Z3950_PREFIX, 13, 1000, 81, 2,-1}, - "Explain-schema"}, - {CLASS_TAGSET, {Z3950_PREFIX, 14, 1,-1}, - "TagsetM"}, - {CLASS_TAGSET, {Z3950_PREFIX, 14, 2,-1}, - "TagsetG"}, - {CLASS_TAGSET, {Z3950_PREFIX, 14, 3,-1}, - "STAS-tagset"}, - {CLASS_TAGSET, {Z3950_PREFIX, 14, 4,-1}, - "GILS-tagset"}, - {CLASS_TAGSET, {Z3950_PREFIX, 14, 5,-1}, - "Collections-tagset"}, - {CLASS_TAGSET, {Z3950_PREFIX, 14, 6,-1}, - "CIMI-tagset"}, - {CLASS_TAGSET, {Z3950_PREFIX, 14, 1000, 81, 1,-1}, - "thesaurus-tagset"}, - {CLASS_TAGSET, {Z3950_PREFIX, 14, 1000, 81, 2,-1}, - "Explain-tagset"}, - {CLASS_TAGSET, {Z3950_PREFIX, 14, 8,-1}, - "Zthes-tagset"}, - {CLASS_NEGOT, {Z3950_PREFIX, 15, 3,-1}, - OID_STR_CHARNEG_3 }, - {CLASS_NEGOT, {Z3950_PREFIX, 15, 4,-1}, - OID_STR_CHARNEG_4 }, - {CLASS_NEGOT, {Z3950_PREFIX, 15, 1000, 81,1,-1}, - OID_STR_ID_CHARSET }, - {CLASS_USERINFO, {1, 2, 840, 1003, 16, 2, -1}, - "CQL"}, - {CLASS_GENERAL, {1,0,10646,1,0,2,-1}, - "UCS-2"}, - {CLASS_GENERAL, {1,0,10646,1,0,4,-1}, - "UCS-4"}, - {CLASS_GENERAL, {1,0,10646,1,0,5,-1}, - "UTF-16"}, - {CLASS_GENERAL, {1,0,10646,1,0,8,-1}, - "UTF-8"}, - {CLASS_USERINFO, {Z3950_PREFIX, 10, 1000, 17, 1, -1}, - "OCLC-userInfo"}, - {CLASS_EXTSERV, {Z3950_PREFIX, 9, 1000,105,4,-1}, - OID_STR_XMLES }, - {CLASS_NOP, {-1}, 0} +struct yaz_oid_db standard_db_l = { + standard_list, 0, 0 }; +yaz_oid_db_t standard_db = &standard_db_l; + yaz_oid_db_t yaz_oid_std(void) { - return standard_oids; + return standard_db; } -const int *yaz_string_to_oid(yaz_oid_db_t oid_list, +const int *yaz_string_to_oid(yaz_oid_db_t oid_db, int oclass, const char *name) { - for (; oid_list->name; oid_list++) + for (; oid_db; oid_db = oid_db->next) { - if (!yaz_matchstr(oid_list->name, name) - && (oclass == CLASS_GENERAL || oclass == oid_list->oclass)) - return oid_list->oid; + struct yaz_oid_entry *e = oid_db->entries; + for (; e->name; e++) + { + if (!yaz_matchstr(e->name, name) + && (oclass == CLASS_GENERAL || oclass == e->oclass)) + return e->oid; + } } return 0; } @@ -325,18 +224,22 @@ int *yaz_string_to_oid_odr(yaz_oid_db_t oid_list, return yaz_string_to_oid_nmem(oid_list, oclass, name, odr_getmem(o)); } -const char *yaz_oid_to_string(yaz_oid_db_t oid_list, +const char *yaz_oid_to_string(yaz_oid_db_t oid_db, const int *oid, int *oclass) { if (!oid) return 0; - for (; oid_list->name; oid_list++) + for (; oid_db; oid_db = oid_db->next) { - if (!oid_oidcmp(oid_list->oid, oid)) + struct yaz_oid_entry *e = oid_db->entries; + for (; e->name; e++) { - if (oclass) - *oclass = oid_list->oclass; - return oid_list->name; + if (!oid_oidcmp(e->oid, oid)) + { + if (oclass) + *oclass = e->oclass; + return e->name; + } } } return 0; @@ -344,12 +247,12 @@ const char *yaz_oid_to_string(yaz_oid_db_t oid_list, const char *yaz_oid_to_string_buf(const int *oid, int *oclass, char *buf) { - const char *p = yaz_oid_to_string(standard_oids, oid, oclass); + const char *p = yaz_oid_to_string(standard_db, oid, oclass); if (p) return p; if (oclass) *oclass = CLASS_GENERAL; - return oid_to_dotstring(oid, buf); + return oid_oid_to_dotstring(oid, buf); } int yaz_oid_is_iso2709(const int *oid) @@ -361,13 +264,72 @@ int yaz_oid_is_iso2709(const int *oid) return 0; } -void yaz_oid_trav(yaz_oid_db_t oid_list, +int yaz_oid_add(yaz_oid_db_t oid_db, int oclass, const char *name, + const int *new_oid) +{ + const int *oid = yaz_string_to_oid(oid_db, oclass, name); + if (!oid) + { + struct yaz_oid_entry *ent; + + while (oid_db->next) + oid_db = oid_db->next; + oid_db->next = xmalloc(sizeof(*oid_db->next)); + oid_db = oid_db->next; + + oid_db->next = 0; + oid_db->xmalloced = 1; + oid_db->entries = ent = xmalloc(2 * sizeof(*ent)); + ent[0].oclass = oclass; + oid_oidcpy(ent[0].oid, new_oid); + ent[0].name = xstrdup(name); + ent[1].oclass = CLASS_NOP; + ent[1].oid[0] = -1; + ent[1].name = 0; + return 0; + } + return -1; +} + +yaz_oid_db_t yaz_oid_db_new(void) +{ + yaz_oid_db_t p = xmalloc(sizeof(*p)); + p->entries = 0; + p->next = 0; + p->xmalloced = 1; + return p; +} + +void yaz_oid_db_destroy(yaz_oid_db_t oid_db) +{ + while (oid_db) + { + yaz_oid_db_t p = oid_db; + + oid_db = oid_db->next; + if (p->xmalloced) + { + struct yaz_oid_entry *e = p->entries; + for (; e->name; e++) + xfree (e->name); + xfree(p->entries); + xfree(p); + } + } +} + +void yaz_oid_trav(yaz_oid_db_t oid_db, void (*func)(const int *oid, int oclass, const char *name, void *client_data), void *client_data) { - for (; oid_list->name; oid_list++) - func(oid_list->oid, oid_list->oclass, oid_list->name, client_data); + for (; oid_db; oid_db = oid_db->next) + { + struct yaz_oid_entry *e = oid_db->entries; + + for (; e->name; e++) + func(e->oid, e->oclass, e->name, client_data); + } } diff --git a/src/oid_util.c b/src/oid_util.c index fc62f51..7523158 100644 --- a/src/oid_util.c +++ b/src/oid_util.c @@ -2,7 +2,7 @@ * Copyright (C) 1995-2007, Index Data ApS * See the file LICENSE for details. * - * $Id: oid_util.c,v 1.1 2007-04-12 13:52:57 adam Exp $ + * $Id: oid_util.c,v 1.2 2007-04-12 20:47:28 adam Exp $ */ /** @@ -58,7 +58,7 @@ int oid_oidlen(const int *o) } -char *oid_to_dotstring(const int *oid, char *oidbuf) +char *oid_oid_to_dotstring(const int *oid, char *oidbuf) { char tmpbuf[20]; int i; @@ -74,6 +74,27 @@ char *oid_to_dotstring(const int *oid, char *oidbuf) return oidbuf; } +int oid_dotstring_to_oid(const char *name, int *oid) +{ + int i = 0; + int val = 0; + while (isdigit (*(unsigned char *) name)) + { + val = val*10 + (*name - '0'); + name++; + if (*name == '.') + { + if (i < OID_SIZE-1) + oid[i++] = val; + val = 0; + name++; + } + } + oid[i] = val; + oid[i+1] = -1; + return 0; +} + /* * Local variables: * c-basic-offset: 4 diff --git a/src/retrieval.c b/src/retrieval.c index 7f0b17d..4ee7ad1 100644 --- a/src/retrieval.c +++ b/src/retrieval.c @@ -2,7 +2,7 @@ * Copyright (C) 2005-2007, Index Data ApS * See the file LICENSE for details. * - * $Id: retrieval.c,v 1.18 2007-04-12 13:52:57 adam Exp $ + * $Id: retrieval.c,v 1.19 2007-04-12 20:47:28 adam Exp $ */ /** * \file retrieval.c @@ -344,7 +344,7 @@ int yaz_retrieval_request(yaz_retrieval_t p, if (!syntax_matches && syntax) { char buf[OID_STR_MAX]; - wrbuf_printf(p->wr_error, "%s", oid_to_dotstring(syntax, buf)); + wrbuf_printf(p->wr_error, "%s", oid_oid_to_dotstring(syntax, buf)); return 2; } if (schema) diff --git a/src/seshigh.c b/src/seshigh.c index 5b2ecf6..8ac8a69 100644 --- a/src/seshigh.c +++ b/src/seshigh.c @@ -2,7 +2,7 @@ * Copyright (C) 1995-2007, Index Data ApS * See the file LICENSE for details. * - * $Id: seshigh.c,v 1.113 2007-04-12 13:52:57 adam Exp $ + * $Id: seshigh.c,v 1.114 2007-04-12 20:47:28 adam Exp $ */ /** * \file seshigh.c @@ -625,7 +625,7 @@ static int retrieve_fetch(association *assoc, bend_fetch_rr *rr) if (input_syntax_raw) { char oidbuf[OID_STR_MAX]; - oid_to_dotstring(input_syntax_raw, oidbuf); + oid_oid_to_dotstring(input_syntax_raw, oidbuf); rr->errstring = odr_strdup(rr->stream, oidbuf); } return -1; @@ -2344,7 +2344,7 @@ static Z_APDU *process_initRequest(association *assoc, request *reqb) assoc->init->implementation_name, odr_prepend(assoc->encode, "GFS", resp->implementationName)); - version = odr_strdup(assoc->encode, "$Revision: 1.113 $"); + version = odr_strdup(assoc->encode, "$Revision: 1.114 $"); if (strlen(version) > 10) /* check for unexpanded CVS strings */ version[strlen(version)-2] = '\0'; resp->implementationVersion = odr_prepend(assoc->encode,