X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=src%2Fzoom-c.c;h=fa6e729720d7edb7d14f61af23bb1193805eff57;hp=1f0cd79709297ba86c9754d0d470a2ab05abe7be;hb=1e49cc7bdcdeb5cb9e7b2e709c5322acccec90df;hpb=55649442b6db726cae33bf4ee92ad447995c930f diff --git a/src/zoom-c.c b/src/zoom-c.c index 1f0cd79..fa6e729 100644 --- a/src/zoom-c.c +++ b/src/zoom-c.c @@ -2,7 +2,7 @@ * Copyright (C) 1995-2007, Index Data ApS * See the file LICENSE for details. * - * $Id: zoom-c.c,v 1.116 2007-03-12 08:27:44 adam Exp $ + * $Id: zoom-c.c,v 1.131 2007-05-23 11:54:47 adam Exp $ */ /** * \file zoom-c.c @@ -26,8 +26,8 @@ #include #include #include - -#define TASK_FIX 1 +#include +#include static int log_api = 0; static int log_details = 0; @@ -48,8 +48,9 @@ static char *cql2pqf(ZOOM_connection c, const char *cql); * if it could cause failure when a lookup fails, but that's hard. */ static Odr_oid *zoom_yaz_str_to_z3950oid(ZOOM_connection c, - int oid_class, const char *str) { - Odr_oid *res = yaz_str_to_z3950oid(c->odr_out, oid_class, str); + int oid_class, const char *str) { + Odr_oid *res = yaz_string_to_oid_odr(yaz_oid_std(), oid_class, str, + c->odr_out); if (res == 0) yaz_log(YLOG_WARN, "%p OID lookup (%d, '%s') failed", c, (int) oid_class, str); @@ -168,9 +169,7 @@ static void set_dset_error(ZOOM_connection c, int error, c, c->host_port ? c->host_port : "<>", dset, error, addinfo ? addinfo : "", addinfo2 ? addinfo2 : ""); -#if TASK_FIX ZOOM_connection_remove_tasks(c); -#endif } } @@ -365,6 +364,13 @@ ZOOM_API(ZOOM_connection) c->client_IP = 0; c->tasks = 0; + c->user = 0; + c->group = 0; + c->password = 0; + + c->maximum_record_size = 0; + c->preferred_message_size = 0; + c->odr_in = odr_createmem(ODR_DECODE); c->odr_out = odr_createmem(ODR_ENCODE); @@ -397,7 +403,7 @@ static char **set_DatabaseNames(ZOOM_connection con, ZOOM_options options, } if (!cp) cp = "Default"; - nmem_strsplit(odr->mem, "+", cp, &databaseNames, num); + nmem_strsplit(odr_getmem(odr), "+", cp, &databaseNames, num); return databaseNames; } @@ -446,24 +452,22 @@ ZOOM_API(void) } yaz_log(log_details, "%p ZOOM_connection_connect connect", c); xfree(c->proxy); + c->proxy = 0; val = ZOOM_options_get(c->options, "proxy"); if (val && *val) { yaz_log(log_details, "%p ZOOM_connection_connect proxy=%s", c, val); c->proxy = xstrdup(val); } - else - c->proxy = 0; xfree(c->charset); + c->charset = 0; val = ZOOM_options_get(c->options, "charset"); if (val && *val) { yaz_log(log_details, "%p ZOOM_connection_connect charset=%s", c, val); c->charset = xstrdup(val); } - else - c->charset = 0; xfree(c->lang); val = ZOOM_options_get(c->options, "lang"); @@ -524,6 +528,8 @@ ZOOM_API(void) ZOOM_options_set(c->options, "host", c->host_port); + xfree(c->cookie_out); + c->cookie_out = 0; val = ZOOM_options_get(c->options, "cookie"); if (val && *val) { @@ -531,6 +537,8 @@ ZOOM_API(void) c->cookie_out = xstrdup(val); } + xfree(c->client_IP); + c->client_IP = 0; val = ZOOM_options_get(c->options, "clientIP"); if (val && *val) { @@ -539,6 +547,32 @@ ZOOM_API(void) c->client_IP = xstrdup(val); } + xfree(c->group); + c->group = 0; + val = ZOOM_options_get(c->options, "group"); + if (val && *val) + c->group = xstrdup(val); + + xfree(c->user); + c->user = 0; + val = ZOOM_options_get(c->options, "user"); + if (val && *val) + c->user = xstrdup(val); + + xfree(c->password); + c->password = 0; + val = ZOOM_options_get(c->options, "password"); + if (!val) + val = ZOOM_options_get(c->options, "pass"); + + if (val && *val) + c->password = xstrdup(val); + + c->maximum_record_size = + ZOOM_options_get_int(c->options, "maximumRecordSize", 1024*1024); + c->preferred_message_size = + ZOOM_options_get_int(c->options, "preferredMessageSize", 1024*1024); + c->async = ZOOM_options_get_bool(c->options, "async", 0); yaz_log(log_details, "%p ZOOM_connection_connect async=%d", c, c->async); @@ -587,7 +621,7 @@ ZOOM_API(int) s->query_string = odr_strdup(s->odr, str); s->z_query = (Z_Query *) odr_malloc(s->odr, sizeof(*s->z_query)); s->z_query->which = Z_Query_type_1; - s->z_query->u.type_1 = p_query_rpn(s->odr, PROTO_Z3950, str); + s->z_query->u.type_1 = p_query_rpn(s->odr, str); if (!s->z_query->u.type_1) { yaz_log(log_details, "%p ZOOM_query_prefix str=%s failed", s, str); @@ -678,8 +712,8 @@ ZOOM_API(int) WRBUF wr = wrbuf_alloc(); ccl_pquery(wr, rpn); ccl_rpn_delete(rpn); - ret = ZOOM_query_prefix(s, wrbuf_buf(wr)); - wrbuf_free(wr, 1); + ret = ZOOM_query_prefix(s, wrbuf_cstr(wr)); + wrbuf_destroy(wr); } ccl_qual_rm(&bibset); return ret; @@ -729,6 +763,9 @@ ZOOM_API(void) xfree(c->cookie_out); xfree(c->cookie_in); xfree(c->client_IP); + xfree(c->user); + xfree(c->group); + xfree(c->password); xfree(c); } @@ -765,6 +802,7 @@ ZOOM_resultset ZOOM_resultset_create(void) r->next = 0; r->databaseNames = 0; r->num_databaseNames = 0; + r->rpn_iconv = 0; return r; } @@ -795,6 +833,13 @@ ZOOM_API(ZOOM_resultset) r->query = q; r->options = ZOOM_options_create_with_parent(c->options); + + { + const char *cp = ZOOM_options_get(r->options, "rpnCharset"); + if (cp) + r->rpn_iconv = yaz_iconv_open(cp, "UTF-8"); + } + start = ZOOM_options_get_int(r->options, "start", 0); count = ZOOM_options_get_int(r->options, "count", 0); @@ -820,6 +865,8 @@ ZOOM_API(ZOOM_resultset) r->next = c->resultsets; c->resultsets = r; + + if (c->host_port && c->proto == PROTO_HTTP) { if (!c->cs) @@ -857,14 +904,9 @@ ZOOM_API(ZOOM_resultset) return r; } -/* - * This is the old result-set sorting API, which is maintained only - * for the sake of binary compatibility. There is no reason ever to - * use this rather than ZOOM_resultset_sort1(). - */ ZOOM_API(void) ZOOM_resultset_sort(ZOOM_resultset r, - const char *sort_type, const char *sort_spec) + const char *sort_type, const char *sort_spec) { (void) ZOOM_resultset_sort1(r, sort_type, sort_spec); } @@ -927,11 +969,11 @@ ZOOM_API(void) for (rc = r->record_hash[i]; rc; rc = rc->next) { if (rc->rec.wrbuf_marc) - wrbuf_free(rc->rec.wrbuf_marc, 1); + wrbuf_destroy(rc->rec.wrbuf_marc); if (rc->rec.wrbuf_iconv) - wrbuf_free(rc->rec.wrbuf_iconv, 1); + wrbuf_destroy(rc->rec.wrbuf_iconv); if (rc->rec.wrbuf_opac) - wrbuf_free(rc->rec.wrbuf_opac, 1); + wrbuf_destroy(rc->rec.wrbuf_opac); } r->record_hash[i] = 0; } @@ -971,6 +1013,8 @@ static void resultset_destroy(ZOOM_resultset r) } ZOOM_query_destroy(r->query); ZOOM_options_destroy(r->options); + if (r->rpn_iconv) + yaz_iconv_close(r->rpn_iconv); odr_destroy(r->odr); xfree(r->setname); xfree(r->schema); @@ -1181,11 +1225,11 @@ static void otherInfo_attach(ZOOM_connection c, Z_APDU *a, ODR out) for (i = 0; i<200; i++) { size_t len; + Odr_oid *oid; Z_OtherInformation **oi; char buf[80]; const char *val; const char *cp; - int oidval; sprintf(buf, "otherInfo%d", i); val = ZOOM_options_get(c->options, buf); @@ -1199,12 +1243,14 @@ static void otherInfo_attach(ZOOM_connection c, Z_APDU *a, ODR out) len = sizeof(buf)-1; memcpy(buf, val, len); buf[len] = '\0'; - oidval = oid_getvalbyname(buf); - if (oidval == VAL_NONE) + + oid = yaz_string_to_oid_odr(yaz_oid_std(), CLASS_USERINFO, + buf, out); + if (!oid) continue; yaz_oi_APDU(a, &oi); - yaz_oi_set_string_oidval(oi, out, oidval, 1, cp+1); + yaz_oi_set_string_oid(oi, out, oid, 1, cp+1); } } @@ -1215,13 +1261,15 @@ static int encode_APDU(ZOOM_connection c, Z_APDU *a, ODR out) { Z_OtherInformation **oi; yaz_oi_APDU(a, &oi); - yaz_oi_set_string_oidval(oi, out, VAL_COOKIE, 1, c->cookie_out); + yaz_oi_set_string_oid(oi, out, yaz_oid_userinfo_cookie, + 1, c->cookie_out); } if (c->client_IP) { Z_OtherInformation **oi; yaz_oi_APDU(a, &oi); - yaz_oi_set_string_oidval(oi, out, VAL_CLIENT_IP, 1, c->client_IP); + yaz_oi_set_string_oid(oi, out, yaz_oid_userinfo_client_ip, + 1, c->client_IP); } otherInfo_attach(c, a, out); if (!z_APDU(out, &a, 0, 0)) @@ -1268,15 +1316,8 @@ static zoom_ret ZOOM_connection_send_init(ZOOM_connection c) 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, "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); @@ -1300,7 +1341,7 @@ static zoom_ret ZOOM_connection_send_init(ZOOM_connection c) odr_prepend(c->odr_out, "ZOOM-C", ireq->implementationName)); - version = odr_strdup(c->odr_out, "$Revision: 1.116 $"); + version = odr_strdup(c->odr_out, "$Revision: 1.131 $"); if (strlen(version) > 10) /* check for unexpanded CVS strings */ version[strlen(version)-2] = '\0'; ireq->implementationVersion = @@ -1309,57 +1350,36 @@ static zoom_ret ZOOM_connection_send_init(ZOOM_connection c) odr_prepend(c->odr_out, &version[11], ireq->implementationVersion)); - *ireq->maximumRecordSize = - ZOOM_options_get_int(c->options, "maximumRecordSize", 1024*1024); - *ireq->preferredMessageSize = - ZOOM_options_get_int(c->options, "preferredMessageSize", 1024*1024); + *ireq->maximumRecordSize = c->maximum_record_size; + *ireq->preferredMessageSize = c->preferred_message_size; - if (auth_groupId || auth_password) + if (c->group || c->password) { Z_IdPass *pass = (Z_IdPass *) odr_malloc(c->odr_out, sizeof(*pass)); - int i = 0; pass->groupId = 0; - if (auth_groupId && *auth_groupId) - { - pass->groupId = (char *) - odr_malloc(c->odr_out, strlen(auth_groupId)+1); - strcpy(pass->groupId, auth_groupId); - i++; - } + if (c->group) + pass->groupId = odr_strdup(c->odr_out, c->group); pass->userId = 0; - if (auth_userId && *auth_userId) - { - pass->userId = (char *) - odr_malloc(c->odr_out, strlen(auth_userId)+1); - strcpy(pass->userId, auth_userId); - i++; - } + if (c->user) + pass->userId = odr_strdup(c->odr_out, c->user); pass->password = 0; - if (auth_password && *auth_password) - { - pass->password = (char *) - odr_malloc(c->odr_out, strlen(auth_password)+1); - strcpy(pass->password, auth_password); - i++; - } - if (i) - { - auth->which = Z_IdAuthentication_idPass; - auth->u.idPass = pass; - ireq->idAuthentication = auth; - } + if (c->password) + pass->password = odr_strdup(c->odr_out, c->password); + auth->which = Z_IdAuthentication_idPass; + auth->u.idPass = pass; + ireq->idAuthentication = auth; } - else if (auth_userId) + else if (c->user) { auth->which = Z_IdAuthentication_open; - auth->u.open = (char *) - odr_malloc(c->odr_out, strlen(auth_userId)+1); - strcpy(auth->u.open, auth_userId); + auth->u.open = odr_strdup(c->odr_out, c->user); ireq->idAuthentication = auth; } if (c->proxy) - yaz_oi_set_string_oidval(&ireq->otherInfo, c->odr_out, - VAL_PROXY, 1, c->host_port); + { + yaz_oi_set_string_oid(&ireq->otherInfo, c->odr_out, + yaz_oid_userinfo_proxy, 1, c->host_port); + } if (c->charset || c->lang) { Z_OtherInformation **oi; @@ -1549,7 +1569,13 @@ static zoom_ret ZOOM_connection_send_search(ZOOM_connection c) set_ZOOM_error(c, ZOOM_ERROR_INVALID_QUERY, 0); return zoom_complete; } - + if (r->query->z_query->which == Z_Query_type_1 && r->rpn_iconv) + { + search_req->query = yaz_copy_Z_Query(r->query->z_query, c->odr_out); + + yaz_query_charset_convert_rpnquery(search_req->query->u.type_1, + c->odr_out, r->rpn_iconv); + } search_req->databaseNames = r->databaseNames; search_req->num_databaseNames = r->num_databaseNames; @@ -1640,7 +1666,7 @@ static zoom_ret ZOOM_connection_send_search(ZOOM_connection c) static void response_default_diag(ZOOM_connection c, Z_DefaultDiagFormat *r) { - int oclass; + oid_class oclass; char *addinfo = 0; switch (r->which) @@ -1655,7 +1681,8 @@ static void response_default_diag(ZOOM_connection c, Z_DefaultDiagFormat *r) xfree(c->addinfo); c->addinfo = 0; set_dset_error(c, *r->condition, - yaz_z3950oid_to_str(r->diagnosticSetId, &oclass), + yaz_oid_to_string(yaz_oid_std(), + r->diagnosticSetId, &oclass), addinfo, 0); } @@ -1730,11 +1757,11 @@ ZOOM_API(void) if (!rec) return; if (rec->wrbuf_marc) - wrbuf_free(rec->wrbuf_marc, 1); + wrbuf_destroy(rec->wrbuf_marc); if (rec->wrbuf_iconv) - wrbuf_free(rec->wrbuf_iconv, 1); + wrbuf_destroy(rec->wrbuf_iconv); if (rec->wrbuf_opac) - wrbuf_free(rec->wrbuf_opac, 1); + wrbuf_destroy(rec->wrbuf_opac); odr_destroy(rec->odr); xfree(rec); } @@ -1787,7 +1814,7 @@ static const char *marc_iconv_return(ZOOM_record rec, int marc_type, yaz_iconv_close(cd); if (len) *len = wrbuf_len(rec->wrbuf_marc); - return wrbuf_buf(rec->wrbuf_marc); + return wrbuf_cstr(rec->wrbuf_marc); } yaz_marc_destroy(mt); if (cd) @@ -1805,6 +1832,7 @@ static const char *record_iconv_return(ZOOM_record rec, int *len, *from = '\0'; strcpy(to, "UTF-8"); + if (record_charset && *record_charset) { /* Use "from,to" or just "from" */ @@ -1826,32 +1854,15 @@ static const char *record_iconv_return(ZOOM_record rec, int *len, if (*from && *to && (cd = yaz_iconv_open(to, from))) { - char outbuf[12]; - size_t inbytesleft = sz; - const char *inp = buf; - if (!rec->wrbuf_iconv) rec->wrbuf_iconv = wrbuf_alloc(); wrbuf_rewind(rec->wrbuf_iconv); - while (inbytesleft) - { - size_t outbytesleft = sizeof(outbuf); - char *outp = outbuf; - size_t r = yaz_iconv(cd, (char**) &inp, - &inbytesleft, - &outp, &outbytesleft); - if (r == (size_t) (-1)) - { - int e = yaz_iconv_error(cd); - if (e != YAZ_ICONV_E2BIG) - break; - } - wrbuf_write(rec->wrbuf_iconv, outbuf, outp - outbuf); - } - wrbuf_puts(rec->wrbuf_iconv, ""); - buf = wrbuf_buf(rec->wrbuf_iconv); + wrbuf_iconv_write(rec->wrbuf_iconv, cd, buf, sz); + wrbuf_iconv_reset(rec->wrbuf_iconv, cd); + + buf = wrbuf_cstr(rec->wrbuf_iconv); sz = wrbuf_len(rec->wrbuf_iconv); yaz_iconv_close(cd); } @@ -1878,7 +1889,7 @@ ZOOM_API(int) if (diag_rec->which == Z_DiagRec_defaultFormat) { Z_DefaultDiagFormat *ddf = diag_rec->u.defaultFormat; - int oclass; + oid_class oclass; error = *ddf->condition; switch (ddf->which) @@ -1891,7 +1902,9 @@ ZOOM_API(int) break; } if (diagset) - *diagset = yaz_z3950oid_to_str(ddf->diagnosticSetId, &oclass); + *diagset = + yaz_oid_to_string(yaz_oid_std(), + ddf->diagnosticSetId, &oclass); } else { @@ -1975,9 +1988,7 @@ ZOOM_API(const char *) if (npr->which == Z_NamePlusRecord_databaseRecord) { Z_External *r = (Z_External *) npr->u.databaseRecord; - oident *ent = oid_getentbyoid(r->direct_reference); - if (ent) - desc = ent->desc; + desc = yaz_oid_to_string(yaz_oid_std(), r->direct_reference, 0); } if (!desc) desc = "none"; @@ -1992,7 +2003,7 @@ ZOOM_API(const char *) if (!strcmp(type, "render")) { Z_External *r = (Z_External *) npr->u.databaseRecord; - oident *ent = oid_getentbyoid(r->direct_reference); + const Odr_oid *oid = r->direct_reference; /* render bibliographic record .. */ if (r->which == Z_External_OPAC) @@ -2000,7 +2011,7 @@ ZOOM_API(const char *) r = r->u.opac->bibliographicRecord; if (!r) return 0; - ent = oid_getentbyoid(r->direct_reference); + oid = r->direct_reference; } if (r->which == Z_External_sutrs) return record_iconv_return(rec, len, @@ -2009,18 +2020,9 @@ ZOOM_API(const char *) charset); else if (r->which == Z_External_octet) { - const char *ret_buf; - switch (ent->value) + if (yaz_oid_is_iso2709(oid)) { - case VAL_SOIF: - case VAL_HTML: - case VAL_SUTRS: - break; - case VAL_TEXT_XML: - case VAL_APPLICATION_XML: - break; - default: - ret_buf = marc_iconv_return( + const char *ret_buf = marc_iconv_return( rec, YAZ_MARC_LINE, len, (const char *) r->u.octet_aligned->buf, r->u.octet_aligned->len, @@ -2049,7 +2051,7 @@ ZOOM_API(const char *) else if (!strcmp(type, "xml")) { Z_External *r = (Z_External *) npr->u.databaseRecord; - oident *ent = oid_getentbyoid(r->direct_reference); + const Odr_oid *oid = r->direct_reference; /* render bibliographic record .. */ if (r->which == Z_External_OPAC) @@ -2057,7 +2059,7 @@ ZOOM_API(const char *) r = r->u.opac->bibliographicRecord; if (!r) return 0; - ent = oid_getentbyoid(r->direct_reference); + oid = r->direct_reference; } if (r->which == Z_External_sutrs) @@ -2067,20 +2069,10 @@ ZOOM_API(const char *) charset); else if (r->which == Z_External_octet) { - const char *ret_buf; int marc_decode_type = YAZ_MARC_MARCXML; - - switch (ent->value) + if (yaz_oid_is_iso2709(oid)) { - case VAL_SOIF: - case VAL_HTML: - case VAL_SUTRS: - break; - case VAL_TEXT_XML: - case VAL_APPLICATION_XML: - break; - default: - ret_buf = marc_iconv_return( + const char *ret_buf = marc_iconv_return( rec, marc_decode_type, len, (const char *) r->u.octet_aligned->buf, r->u.octet_aligned->len, @@ -2297,7 +2289,7 @@ static void handle_records(ZOOM_connection c, Z_Records *sr, resultset, *start, *count); /* transfer our response to search_nmem .. we need it later */ - nmem_transfer(resultset->odr->mem, nmem); + nmem_transfer(odr_getmem(resultset->odr), nmem); nmem_destroy(nmem); if (present_phase && p->num_records == 0) { @@ -2476,7 +2468,7 @@ static int scan_response(ZOOM_connection c, Z_ScanResponse *res) if (res->entries && res->entries->nonsurrogateDiagnostics) response_diag(c, res->entries->nonsurrogateDiagnostics[0]); scan->scan_response = res; - nmem_transfer(scan->odr->mem, nmem); + nmem_transfer(odr_getmem(scan->odr), nmem); if (res->stepSize) ZOOM_options_set_int(scan->options, "stepSize", *res->stepSize); if (res->positionOfTerm) @@ -2720,6 +2712,20 @@ ZOOM_API(ZOOM_scanset) p_query_scan(scan->odr, PROTO_Z3950, &scan->attributeSet, start); xfree(freeme); + { + const char *cp = ZOOM_options_get(scan->options, "rpnCharset"); + if (cp) + { + yaz_iconv_t cd = yaz_iconv_open(cp, "UTF-8"); + if (cd) + { + yaz_query_charset_convert_apt(scan->termListAndStartPoint, + scan->odr, cd); + } + } + } + + scan->databaseNames = set_DatabaseNames(c, c->options, &scan->num_databaseNames, scan->odr); @@ -2881,7 +2887,7 @@ ZOOM_API(void) ZOOM_options_set(scan->options, key, val); } -static Z_APDU *create_es_package(ZOOM_package p, int type) +static Z_APDU *create_es_package(ZOOM_package p, const Odr_oid *oid) { const char *str; Z_APDU *apdu = zget_APDU(p->odr_out, Z_APDU_extendedServicesRequest); @@ -2891,14 +2897,13 @@ static Z_APDU *create_es_package(ZOOM_package p, int type) str = ZOOM_options_get(p->options, "package-name"); if (str && *str) - req->packageName = nmem_strdup(p->odr_out->mem, str); + req->packageName = odr_strdup(p->odr_out, str); str = ZOOM_options_get(p->options, "user-id"); if (str) - req->userId = nmem_strdup(p->odr_out->mem, str); + req->userId = odr_strdup(p->odr_out, str); - req->packageType = yaz_oidval_to_z3950oid(p->odr_out, CLASS_EXTSERV, - type); + req->packageType = odr_oiddup(p->odr_out, oid); str = ZOOM_options_get(p->options, "function"); if (str) @@ -2942,16 +2947,11 @@ static Z_External *encode_ill_request(ZOOM_package p) } else { - oident oid; int illRequest_size = 0; char *illRequest_buf = odr_getbuf(out, &illRequest_size, 0); - oid.proto = PROTO_GENERAL; - oid.oclass = CLASS_GENERAL; - oid.value = VAL_ISO_ILL_1; - r = (Z_External *) odr_malloc(out, sizeof(*r)); - r->direct_reference = odr_oiddup(out,oid_getoidbyent(&oid)); + r->direct_reference = odr_oiddup(out, yaz_oid_general_isoill_1); r->indirect_reference = 0; r->descriptor = 0; r->which = Z_External_single; @@ -2982,15 +2982,15 @@ static Z_ItemOrder *encode_item_order(ZOOM_package p) str = ZOOM_options_get(p->options, "contact-name"); req->u.esRequest->toKeep->contact->name = str ? - nmem_strdup(p->odr_out->mem, str) : 0; + odr_strdup(p->odr_out, str) : 0; str = ZOOM_options_get(p->options, "contact-phone"); req->u.esRequest->toKeep->contact->phone = str ? - nmem_strdup(p->odr_out->mem, str) : 0; + odr_strdup(p->odr_out, str) : 0; str = ZOOM_options_get(p->options, "contact-email"); req->u.esRequest->toKeep->contact->email = str ? - nmem_strdup(p->odr_out->mem, str) : 0; + odr_strdup(p->odr_out, str) : 0; req->u.esRequest->toKeep->addlBilling = 0; @@ -3010,7 +3010,7 @@ static Z_ItemOrder *encode_item_order(ZOOM_package p) odr_malloc(p->odr_out, sizeof(Z_IOResultSetItem)); req->u.esRequest->notToKeep->resultSetItem->resultSetId = - nmem_strdup(p->odr_out->mem, str); + odr_strdup(p->odr_out, str); req->u.esRequest->notToKeep->resultSetItem->item = (int *) odr_malloc(p->odr_out, sizeof(int)); @@ -3021,8 +3021,10 @@ static Z_ItemOrder *encode_item_order(ZOOM_package p) str = ZOOM_options_get(p->options, "doc"); if (str) + { req->u.esRequest->notToKeep->itemRequest = - z_ext_record(p->odr_out, VAL_TEXT_XML, str, strlen(str)); + z_ext_record_xml(p->odr_out, str, strlen(str)); + } else req->u.esRequest->notToKeep->itemRequest = encode_ill_request(p); @@ -3033,7 +3035,7 @@ Z_APDU *create_admin_package(ZOOM_package p, int type, Z_ESAdminOriginPartToKeep **toKeepP, Z_ESAdminOriginPartNotToKeep **notToKeepP) { - Z_APDU *apdu = create_es_package(p, VAL_ADMINSERVICE); + Z_APDU *apdu = create_es_package(p, yaz_oid_extserv_admin); if (apdu) { Z_ESAdminOriginPartToKeep *toKeep; @@ -3046,9 +3048,7 @@ Z_APDU *create_admin_package(ZOOM_package p, int type, if (num_db > 0) first_db = db[0]; - r->direct_reference = - yaz_oidval_to_z3950oid(p->odr_out, CLASS_EXTSERV, - VAL_ADMINSERVICE); + r->direct_reference = odr_oiddup(p->odr_out, yaz_oid_extserv_admin); r->descriptor = 0; r->indirect_reference = 0; r->which = Z_External_ESAdmin; @@ -3083,7 +3083,7 @@ Z_APDU *create_admin_package(ZOOM_package p, int type, static Z_APDU *create_xmlupdate_package(ZOOM_package p) { - Z_APDU *apdu = create_es_package(p, VAL_XMLES); + Z_APDU *apdu = create_es_package(p, yaz_oid_extserv_xml_es); Z_ExtendedServicesRequest *req = apdu->u.extendedServicesRequest; Z_External *ext = (Z_External *) odr_malloc(p->odr_out, sizeof(*ext)); const char *doc = ZOOM_options_get(p->options, "doc"); @@ -3114,19 +3114,26 @@ static Z_APDU *create_update_package(ZOOM_package p) 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; int action_no = -1; - - if (syntax_str) - syntax_oid = oid_getvalbyname(syntax_str); + Odr_oid *syntax_oid = 0; + + if (!syntax_str) + syntax_str = "xml"; if (!record_buf) { record_buf = "void"; - syntax_oid = VAL_SUTRS; + syntax_str = "SUTRS"; } - if (syntax_oid == VAL_NONE) - syntax_oid = VAL_TEXT_XML; - + + if (syntax_str) + { + syntax_oid = yaz_string_to_oid_odr(yaz_oid_std(), + CLASS_RECSYN, syntax_str, + p->odr_out); + } + if (!syntax_oid) + return 0; + if (num_db > 0) first_db = db[0]; @@ -3146,7 +3153,7 @@ static Z_APDU *create_update_package(ZOOM_package p) else return 0; - apdu = create_es_package(p, VAL_DBUPDATE); + apdu = create_es_package(p, yaz_oid_extserv_database_update); if (apdu) { Z_IUOriginPartToKeep *toKeep; @@ -3155,10 +3162,10 @@ static Z_APDU *create_update_package(ZOOM_package p) odr_malloc(p->odr_out, sizeof(*r)); apdu->u.extendedServicesRequest->taskSpecificParameters = r; + - r->direct_reference = - yaz_oidval_to_z3950oid(p->odr_out, CLASS_EXTSERV, - VAL_DBUPDATE); + r->direct_reference = odr_oiddup(p->odr_out, + yaz_oid_extserv_database_update); r->descriptor = 0; r->which = Z_External_update; r->indirect_reference = 0; @@ -3206,8 +3213,8 @@ static Z_APDU *create_update_package(ZOOM_package p) notToKeep->elements[0]->supplementalId = 0; notToKeep->elements[0]->correlationInfo = 0; notToKeep->elements[0]->record = - z_ext_record(p->odr_out, syntax_oid, - record_buf, strlen(record_buf)); + z_ext_record_oid(p->odr_out, syntax_oid, + record_buf, strlen(record_buf)); } if (0 && apdu) { @@ -3232,14 +3239,13 @@ ZOOM_API(void) p->buf_out = 0; if (!strcmp(type, "itemorder")) { - apdu = create_es_package(p, VAL_ITEMORDER); + apdu = create_es_package(p, yaz_oid_extserv_item_order); if (apdu) { Z_External *r = (Z_External *) odr_malloc(p->odr_out, sizeof(*r)); - r->direct_reference = - yaz_oidval_to_z3950oid(p->odr_out, CLASS_EXTSERV, - VAL_ITEMORDER); + r->direct_reference = + odr_oiddup(p->odr_out, yaz_oid_extserv_item_order); r->descriptor = 0; r->which = Z_External_itemOrder; r->indirect_reference = 0; @@ -3480,7 +3486,7 @@ static void interpret_otherinformation_field(ZOOM_connection c, static void set_init_option(const char *name, void *clientData) { - ZOOM_connection c = clientData; + ZOOM_connection c = (ZOOM_connection) clientData; char buf[80]; sprintf(buf, "init_opt_%.70s", name); @@ -3534,8 +3540,8 @@ static void recv_apdu(ZOOM_connection c, Z_APDU *apdu) else { char *cookie = - yaz_oi_get_string_oidval(&apdu->u.initResponse->otherInfo, - VAL_COOKIE, 1, 0); + yaz_oi_get_string_oid(&apdu->u.initResponse->otherInfo, + yaz_oid_userinfo_cookie, 1, 0); xfree(c->cookie_in); c->cookie_in = 0; if (cookie) @@ -3683,7 +3689,7 @@ static void handle_srw_response(ZOOM_connection c, odr_malloc(c->odr_in, sizeof(Z_External)); npr->u.databaseRecord->descriptor = 0; npr->u.databaseRecord->direct_reference = - yaz_oidval_to_z3950oid(c->odr_in, CLASS_RECSYN, VAL_TEXT_XML); + odr_oiddup(c->odr_in, yaz_oid_recsyn_xml); npr->u.databaseRecord->which = Z_External_octet; npr->u.databaseRecord->u.octet_aligned = (Odr_oct *) @@ -3709,7 +3715,7 @@ static void handle_srw_response(ZOOM_connection c, } } nmem = odr_extract_mem(c->odr_in); - nmem_transfer(resultset->odr->mem, nmem); + nmem_transfer(odr_getmem(resultset->odr), nmem); nmem_destroy(nmem); } #endif @@ -3718,14 +3724,15 @@ static void handle_srw_response(ZOOM_connection c, static void handle_http(ZOOM_connection c, Z_HTTP_Response *hres) { int ret = -1; - const char *content_type = z_HTTP_header_lookup(hres->headers, - "Content-Type"); + const char *addinfo = 0; const char *connection_head = z_HTTP_header_lookup(hres->headers, "Connection"); ZOOM_connection_set_mask(c, 0); yaz_log(log_details, "%p handle_http", c); - - if (content_type && !yaz_strcmp_del("text/xml", content_type, "; ")) + + if (!yaz_srw_check_content_type(hres)) + addinfo = "content-type"; + else { Z_SOAP *soap_package = 0; ODR o = c->odr_in; @@ -3760,7 +3767,7 @@ static void handle_http(ZOOM_connection c, Z_HTTP_Response *hres) if (hres->code != 200) set_HTTP_error(c, hres->code, 0, 0); else - set_ZOOM_error(c, ZOOM_ERROR_DECODE, 0); + set_ZOOM_error(c, ZOOM_ERROR_DECODE, addinfo); do_close(c); } ZOOM_connection_remove_task(c); @@ -4108,6 +4115,12 @@ ZOOM_API(int) } +static void cql2pqf_wrbuf_puts(const char *buf, void *client_data) +{ + WRBUF wrbuf = (WRBUF) client_data; + wrbuf_puts(wrbuf, buf); +} + /* * Returns an xmalloc()d string containing RPN that corresponds to the * CQL passed in. On error, sets the Connection object's error state @@ -4118,10 +4131,9 @@ static char *cql2pqf(ZOOM_connection c, const char *cql) { CQL_parser parser; int error; - struct cql_node *node; const char *cqlfile; - static cql_transform_t trans; - char pqfbuf[512]; + cql_transform_t trans; + char *result = 0; parser = cql_parser_create(); if ((error = cql_parser_string(parser, cql)) != 0) { @@ -4130,42 +4142,40 @@ static char *cql2pqf(ZOOM_connection c, const char *cql) return 0; } - node = cql_parser_result(parser); - /* ### Do not call cql_parser_destroy() yet: it destroys `node'! */ - cqlfile = ZOOM_connection_option_get(c, "cqlfile"); - if (cqlfile == 0) { - cql_parser_destroy(parser); - cql_node_destroy(node); + if (cqlfile == 0) + { set_ZOOM_error(c, ZOOM_ERROR_CQL_TRANSFORM, "no CQL transform file"); - return 0; } - - if ((trans = cql_transform_open_fname(cqlfile)) == 0) { + else if ((trans = cql_transform_open_fname(cqlfile)) == 0) + { char buf[512]; - cql_parser_destroy(parser); - cql_node_destroy(node); sprintf(buf, "can't open CQL transform file '%.200s': %.200s", cqlfile, strerror(errno)); set_ZOOM_error(c, ZOOM_ERROR_CQL_TRANSFORM, buf); - return 0; } - - error = cql_transform_buf(trans, node, pqfbuf, sizeof pqfbuf); - cql_parser_destroy(parser); - cql_node_destroy(node); - if (error != 0) { - char buf[512]; - const char *addinfo; - error = cql_transform_error(trans, &addinfo); + else + { + WRBUF wrbuf_result = wrbuf_alloc(); + error = cql_transform(trans, cql_parser_result(parser), + cql2pqf_wrbuf_puts, wrbuf_result); + if (error != 0) { + char buf[512]; + const char *addinfo; + error = cql_transform_error(trans, &addinfo); + sprintf(buf, "%.200s (addinfo=%.200s)", + cql_strerror(error), addinfo); + set_ZOOM_error(c, ZOOM_ERROR_CQL_TRANSFORM, buf); + } + else + { + result = xstrdup(wrbuf_cstr(wrbuf_result)); + } cql_transform_close(trans); - sprintf(buf, "%.200s (addinfo=%.200s)", cql_strerror(error), addinfo); - set_ZOOM_error(c, ZOOM_ERROR_CQL_TRANSFORM, buf); - return 0; + wrbuf_destroy(wrbuf_result); } - - cql_transform_close(trans); - return xstrdup(pqfbuf); + cql_parser_destroy(parser); + return result; } ZOOM_API(int) ZOOM_connection_fire_event_timeout(ZOOM_connection c)