X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Fzoom-c.c;h=a37e14a925d39076ab471df54267b1543556cf86;hb=ccd8958b42e2d3d6aee55dd1201d56eb7a278b56;hp=19947c39fd48789ffbfa46f0d0f1d9fe88d5d938;hpb=23794062255aca1313eaff359edb7b73a5f1a742;p=yaz-moved-to-github.git diff --git a/src/zoom-c.c b/src/zoom-c.c index 19947c3..a37e14a 100644 --- a/src/zoom-c.c +++ b/src/zoom-c.c @@ -1,8 +1,8 @@ /* - * Copyright (c) 2000-2003, Index Data + * Copyright (c) 2000-2004, Index Data * See the file LICENSE for details. * - * $Id: zoom-c.c,v 1.8 2003-11-26 16:22:35 mike Exp $ + * $Id: zoom-c.c,v 1.20 2004-01-22 11:20:54 adam Exp $ * * ZOOM layer for C, connections, result sets, queries. */ @@ -889,16 +889,19 @@ static zoom_ret send_APDU (ZOOM_connection c, Z_APDU *a) static zoom_ret ZOOM_connection_send_init (ZOOM_connection c) { - const char *impid, *impname, *impver; Z_APDU *apdu = zget_APDU(c->odr_out, Z_APDU_initRequest); Z_InitRequest *ireq = apdu->u.initRequest; Z_IdAuthentication *auth = (Z_IdAuthentication *) odr_malloc(c->odr_out, sizeof(*auth)); const char *auth_groupId = ZOOM_options_get (c->options, "group"); const char *auth_userId = ZOOM_options_get (c->options, "user"); - const char *auth_password = ZOOM_options_get (c->options, "pass"); + const char *auth_password = ZOOM_options_get (c->options, "password"); char *version; + /* support the pass for backwards compatibility */ + if (!auth_password) + auth_password = ZOOM_options_get (c->options, "pass"); + ODR_MASK_SET(ireq->options, Z_Options_search); ODR_MASK_SET(ireq->options, Z_Options_present); ODR_MASK_SET(ireq->options, Z_Options_scan); @@ -919,12 +922,12 @@ static zoom_ret ZOOM_connection_send_init (ZOOM_connection c) ZOOM_options_get(c->options, "implementationName"), odr_prepend(c->odr_out, "ZOOM-C", ireq->implementationName)); - version = odr_strdup(c->odr_out, "$Revision: 1.8 $"); + version = odr_strdup(c->odr_out, "$Revision: 1.20 $"); if (strlen(version) > 10) /* check for unexpanded CVS strings */ version[strlen(version)-2] = '\0'; ireq->implementationVersion = odr_prepend(c->odr_out, ZOOM_options_get(c->options, "implementationVersion"), - odr_prepend(c->odr_out, &version[10], ireq->implementationVersion)); + odr_prepend(c->odr_out, &version[11], ireq->implementationVersion)); *ireq->maximumRecordSize = ZOOM_options_get_int (c->options, "maximumRecordSize", 1024*1024); @@ -1005,7 +1008,7 @@ static zoom_ret send_srw (ZOOM_connection c, Z_SRW_PDU *sr) { char ctype[50]; Z_SOAP_Handler h[2] = { - {"http://www.loc.gov/zing/srw/v1.0/", 0, (Z_SOAP_fun) yaz_srw_codec}, + {"http://www.loc.gov/zing/srw/", 0, (Z_SOAP_fun) yaz_srw_codec}, {0, 0, 0} }; ODR o = odr_createmem(ODR_ENCODE); @@ -1360,6 +1363,62 @@ ZOOM_record_destroy (ZOOM_record rec) xfree (rec); } +static const char *marc_iconv_return(ZOOM_record rec, int marc_type, + int *len, + const char *buf, int sz, + const char *record_charset) +{ + char to[40]; + char from[40]; + yaz_iconv_t cd = 0; + yaz_marc_t mt = yaz_marc_create(); + + *from = '\0'; + strcpy(to, "UTF-8"); + if (record_charset && *record_charset) + { + /* Use "from,to" or just "from" */ + const char *cp =strchr(record_charset, ','); + int clen = strlen(record_charset); + if (cp && cp[1]) + { + strncpy( to, cp+1, sizeof(to)-1); + to[sizeof(to)-1] = '\0'; + clen = cp - record_charset; + } + if (clen > sizeof(from)-1) + clen = sizeof(from)-1; + + if (clen) + strncpy(from, record_charset, clen); + from[clen] = '\0'; + } + + if (*from && *to) + { + cd = yaz_iconv_open(to, from); + yaz_marc_iconv(mt, cd); + } + + yaz_marc_xml(mt, marc_type); + if (!rec->wrbuf_marc) + rec->wrbuf_marc = wrbuf_alloc(); + wrbuf_rewind (rec->wrbuf_marc); + if (yaz_marc_decode_wrbuf (mt, buf, sz, rec->wrbuf_marc) > 0) + { + yaz_marc_destroy(mt); + if (cd) + yaz_iconv_close(cd); + if (len) + *len = wrbuf_len(rec->wrbuf_marc); + return wrbuf_buf(rec->wrbuf_marc); + } + yaz_marc_destroy(mt); + if (cd) + yaz_iconv_close(cd); + return 0; +} + static const char *record_iconv_return(ZOOM_record rec, int *len, const char *buf, int sz, const char *record_charset) @@ -1430,6 +1489,7 @@ ZOOM_record_get (ZOOM_record rec, const char *type_spec, int *len) { char type[40]; char charset[40]; + char xpath[512]; const char *cp; int i; Z_NamePlusRecord *npr; @@ -1452,7 +1512,7 @@ ZOOM_record_get (ZOOM_record rec, const char *type_spec, int *len) } type[i] = '\0'; charset[0] = '\0'; - if (type_spec[i] == ';') + while (type_spec[i] == ';') { i++; while (type_spec[i] == ' ') @@ -1468,8 +1528,16 @@ ZOOM_record_get (ZOOM_record rec, const char *type_spec, int *len) } charset[i] = '\0'; } - } - + else if (!strncmp(type_spec+i, "xpath=", 6)) + { + cp = type_spec+i+6; + for (i = 0; cp[i] && i < sizeof(xpath)-1; i++) + xpath[i] = cp[i]; + xpath[i] = '\0'; + } + while (type_spec[i] == ' ') + i++; + } if (!strcmp (type, "database")) { if (len) @@ -1515,7 +1583,7 @@ ZOOM_record_get (ZOOM_record rec, const char *type_spec, int *len) charset); else if (r->which == Z_External_octet) { - yaz_marc_t mt; + const char *ret_buf; switch (ent->value) { case VAL_SOIF: @@ -1526,23 +1594,13 @@ ZOOM_record_get (ZOOM_record rec, const char *type_spec, int *len) case VAL_APPLICATION_XML: break; default: - if (!rec->wrbuf_marc) - rec->wrbuf_marc = wrbuf_alloc(); - - mt = yaz_marc_create(); - wrbuf_rewind (rec->wrbuf_marc); - if (yaz_marc_decode_wrbuf ( - mt, (const char *) r->u.octet_aligned->buf, - r->u.octet_aligned->len, - rec->wrbuf_marc) > 0) - { - yaz_marc_destroy(mt); - return record_iconv_return(rec, len, - wrbuf_buf(rec->wrbuf_marc), - wrbuf_len(rec->wrbuf_marc), - charset); - } - yaz_marc_destroy(mt); + ret_buf = marc_iconv_return( + rec, YAZ_MARC_LINE, len, + (const char *) r->u.octet_aligned->buf, + r->u.octet_aligned->len, + charset); + if (ret_buf) + return ret_buf; } return record_iconv_return(rec, len, (const char *) r->u.octet_aligned->buf, @@ -1583,7 +1641,7 @@ ZOOM_record_get (ZOOM_record rec, const char *type_spec, int *len) charset); else if (r->which == Z_External_octet) { - yaz_marc_t mt; + const char *ret_buf; int marc_decode_type = YAZ_MARC_MARCXML; if (!strcmp(type, "oai")) @@ -1598,24 +1656,13 @@ ZOOM_record_get (ZOOM_record rec, const char *type_spec, int *len) case VAL_APPLICATION_XML: break; default: - if (!rec->wrbuf_marc) - rec->wrbuf_marc = wrbuf_alloc(); - wrbuf_rewind (rec->wrbuf_marc); - mt = yaz_marc_create(); - - yaz_marc_xml(mt, YAZ_MARC_MARCXML); - if (yaz_marc_decode_wrbuf ( - mt, (const char *) r->u.octet_aligned->buf, - r->u.octet_aligned->len, - rec->wrbuf_marc) > 0) - { - yaz_marc_destroy(mt); - return record_iconv_return(rec, len, - wrbuf_buf(rec->wrbuf_marc), - wrbuf_len(rec->wrbuf_marc), - charset); - } - yaz_marc_destroy(mt); + ret_buf = marc_iconv_return( + rec, marc_decode_type, len, + (const char *) r->u.octet_aligned->buf, + r->u.octet_aligned->len, + charset); + if (ret_buf) + return ret_buf; } return record_iconv_return(rec, len, (const char *) r->u.octet_aligned->buf, @@ -2177,7 +2224,7 @@ ZOOM_scanset_display_term (ZOOM_scanset scan, size_t pos, if (t->displayTerm) { - term = (const char *) t->term->u.general->buf; + term = t->displayTerm; *len = strlen(term); } else if (t->term->which == Z_Term_general) @@ -2406,7 +2453,8 @@ static Z_APDU *create_update_package(ZOOM_package p) int num_db; char **db = set_DatabaseNames(p->connection, p->options, &num_db); const char *action = ZOOM_options_get(p->options, "action"); - const char *recordId = ZOOM_options_get(p->options, "recordId"); + const char *recordIdOpaque = ZOOM_options_get(p->options, "recordIdOpaque"); + const char *recordIdNumber = ZOOM_options_get(p->options, "recordIdNumber"); const char *record_buf = ZOOM_options_get(p->options, "record"); const char *syntax_str = ZOOM_options_get(p->options, "syntax"); int syntax_oid = VAL_NONE; @@ -2482,14 +2530,21 @@ static Z_APDU *create_update_package(ZOOM_package p) notToKeep->elements[0] = (Z_IUSuppliedRecords_elem *) odr_malloc(p->odr_out, sizeof(**notToKeep->elements)); notToKeep->elements[0]->which = Z_IUSuppliedRecords_elem_opaque; - if (recordId) + if (recordIdOpaque) { notToKeep->elements[0]->u.opaque = (Odr_oct *) odr_malloc (p->odr_out, sizeof(Odr_oct)); - notToKeep->elements[0]->u.opaque->size = strlen(recordId); - notToKeep->elements[0]->u.opaque->len = strlen(recordId); + notToKeep->elements[0]->u.opaque->size = + notToKeep->elements[0]->u.opaque->len = strlen(recordIdOpaque); notToKeep->elements[0]->u.opaque->buf = - odr_strdup(p->odr_out, recordId); + odr_strdup(p->odr_out, recordIdOpaque); + } + else if (recordIdNumber) + { + notToKeep->elements[0]->which = Z_IUSuppliedRecords_elem_number; + + notToKeep->elements[0]->u.number = + odr_intdup(p->odr_out, atoi(recordIdNumber)); } else notToKeep->elements[0]->u.opaque = 0; @@ -2917,9 +2972,9 @@ static void handle_http(ZOOM_connection c, Z_HTTP_Response *hres) if (content_type && !yaz_strcmp_del("text/xml", content_type, "; ")) { Z_SOAP *soap_package = 0; - ODR o = odr_createmem(ODR_DECODE); + ODR o = c->odr_in; Z_SOAP_Handler soap_handlers[2] = { - {"http://www.loc.gov/zing/srw/v1.0/", 0, + {"http://www.loc.gov/zing/srw/", 0, (Z_SOAP_fun) yaz_srw_codec}, {0, 0, 0} }; @@ -2944,7 +2999,6 @@ static void handle_http(ZOOM_connection c, Z_HTTP_Response *hres) } else ret = -1; - odr_destroy(o); } if (ret) {