X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Fzoom-c.c;h=3ada8d1ca85c65b858cbf73f527fcf28fc0da9b2;hb=fadf07ca8b5d84ed21b83e63bfec438666e11587;hp=320a9258ac94d5bf909b7f53e30e21ad7759e2ad;hpb=55ca7cdb58b098d348054917296c0fe2c9cb1580;p=yaz-moved-to-github.git diff --git a/src/zoom-c.c b/src/zoom-c.c index 320a925..3ada8d1 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.127 2007-04-30 08:29:07 adam Exp $ + * $Id: zoom-c.c,v 1.140 2007-08-15 17:53:11 mike Exp $ */ /** * \file zoom-c.c @@ -28,6 +28,7 @@ #include #include #include +#include static int log_api = 0; static int log_details = 0; @@ -47,9 +48,9 @@ static char *cql2pqf(ZOOM_connection c, const char *cql); * This wrapper is just for logging failed lookups. It would be nicer * if it could cause failure when a lookup fails, but that's hard. */ -static int *zoom_yaz_str_to_z3950oid(ZOOM_connection c, +static Odr_oid *zoom_yaz_str_to_z3950oid(ZOOM_connection c, int oid_class, const char *str) { - int *res = yaz_string_to_oid_odr(yaz_oid_std(), oid_class, 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", @@ -364,6 +365,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); @@ -445,24 +453,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"); @@ -523,6 +529,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) { @@ -530,6 +538,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) { @@ -538,6 +548,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); @@ -728,6 +764,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); } @@ -1187,7 +1226,7 @@ static void otherInfo_attach(ZOOM_connection c, Z_APDU *a, ODR out) for (i = 0; i<200; i++) { size_t len; - int *oid; + Odr_oid *oid; Z_OtherInformation **oi; char buf[80]; const char *val; @@ -1278,15 +1317,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); @@ -1310,7 +1342,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.127 $"); + version = odr_strdup(c->odr_out, "$Revision: 1.140 $"); if (strlen(version) > 10) /* check for unexpanded CVS strings */ version[strlen(version)-2] = '\0'; ireq->implementationVersion = @@ -1319,52 +1351,29 @@ 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) @@ -1658,9 +1667,11 @@ static zoom_ret ZOOM_connection_send_search(ZOOM_connection c) static void response_default_diag(ZOOM_connection c, Z_DefaultDiagFormat *r) { - int oclass; + char oid_name_buf[OID_STR_MAX]; + const char *oid_name; char *addinfo = 0; + oid_name = yaz_oid_to_string_buf(r->diagnosticSetId, 0, oid_name_buf); switch (r->which) { case Z_DefaultDiagFormat_v2Addinfo: @@ -1672,10 +1683,7 @@ static void response_default_diag(ZOOM_connection c, Z_DefaultDiagFormat *r) } xfree(c->addinfo); c->addinfo = 0; - set_dset_error(c, *r->condition, - yaz_oid_to_string(yaz_oid_std(), - r->diagnosticSetId, &oclass), - addinfo, 0); + set_dset_error(c, *r->condition, oid_name, addinfo, 0); } static void response_diag(ZOOM_connection c, Z_DiagRec *p) @@ -1881,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) @@ -1995,7 +2003,7 @@ ZOOM_API(const char *) if (!strcmp(type, "render")) { Z_External *r = (Z_External *) npr->u.databaseRecord; - const int *oid = r->direct_reference; + const Odr_oid *oid = r->direct_reference; /* render bibliographic record .. */ if (r->which == Z_External_OPAC) @@ -2043,7 +2051,7 @@ ZOOM_API(const char *) else if (!strcmp(type, "xml")) { Z_External *r = (Z_External *) npr->u.databaseRecord; - const int *oid = r->direct_reference; + const Odr_oid *oid = r->direct_reference; /* render bibliographic record .. */ if (r->which == Z_External_OPAC) @@ -2683,6 +2691,19 @@ ZOOM_API(ZOOM_scanset) { yaz_log(log_api, "%p ZOOM_connection_scan1 q=%p CQL '%s'", c, q, q->query_string); + /* + * ### This is wrong: if ZOOM_query_cql2rpn() was used, then + * the query already been translated to PQF, so we'd be in the + * previous branch. We only get here if the client submitted + * CQL to be interepreted by the server using + * ZOOM_query_cql(), in which case we should send it as-is. + * We can't do that in Z39.50 as the ScanRequest APDU has no + * slot in which to place the CQL, but we could and should do + * it for SRU connections. At present, we can't do that + * because there is no slot in the ZOOM_scanset structure to + * save the CQL so that it can be sent when the ZOOM_TASK_SCAN + * fires. + */ start = freeme = cql2pqf(c, q->query_string); if (start == 0) return 0; @@ -2879,14 +2900,12 @@ ZOOM_API(void) ZOOM_options_set(scan->options, key, val); } -static Z_APDU *create_es_package(ZOOM_package p, const int *oid) +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); Z_ExtendedServicesRequest *req = apdu->u.extendedServicesRequest; - *req->function = Z_ExtendedServicesRequest_create; - str = ZOOM_options_get(p->options, "package-name"); if (str && *str) req->packageName = odr_strdup(p->odr_out, str); @@ -2901,11 +2920,24 @@ static Z_APDU *create_es_package(ZOOM_package p, const int *oid) if (str) { if (!strcmp (str, "create")) - *req->function = 1; + *req->function = Z_ExtendedServicesRequest_create; if (!strcmp (str, "delete")) - *req->function = 2; + *req->function = Z_ExtendedServicesRequest_delete; if (!strcmp (str, "modify")) - *req->function = 3; + *req->function = Z_ExtendedServicesRequest_modify; + } + + str = ZOOM_options_get(p->options, "waitAction"); + if (str) + { + if (!strcmp (str, "wait")) + *req->waitAction = Z_ExtendedServicesRequest_wait; + if (!strcmp (str, "waitIfPossible")) + *req->waitAction = Z_ExtendedServicesRequest_waitIfPossible; + if (!strcmp (str, "dontWait")) + *req->waitAction = Z_ExtendedServicesRequest_dontWait; + if (!strcmp (str, "dontReturnPackage")) + *req->waitAction = Z_ExtendedServicesRequest_dontReturnPackage; } return apdu; } @@ -3106,9 +3138,18 @@ 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"); + const char *version = ZOOM_options_get(p->options, "updateVersion"); + + const char *correlationInfo_note = + ZOOM_options_get(p->options, "correlationInfo.note"); + const char *correlationInfo_id = + ZOOM_options_get(p->options, "correlationInfo.id"); int action_no = -1; - int *syntax_oid = 0; + Odr_oid *syntax_oid = 0; + const Odr_oid *package_oid = yaz_oid_extserv_database_update; + if (!version) + version = "3"; if (!syntax_str) syntax_str = "xml"; if (!record_buf) @@ -3129,8 +3170,27 @@ static Z_APDU *create_update_package(ZOOM_package p) if (num_db > 0) first_db = db[0]; - if (!action) - action = "specialUpdate"; + switch(*version) + { + case '1': + package_oid = yaz_oid_extserv_database_update_first_version; + /* old update does not support specialUpdate */ + if (!action) + action = "recordInsert"; + break; + case '2': + if (!action) + action = "specialUpdate"; + package_oid = yaz_oid_extserv_database_update_second_version; + break; + case '3': + if (!action) + action = "specialUpdate"; + package_oid = yaz_oid_extserv_database_update; + break; + default: + return 0; + } if (!strcmp(action, "recordInsert")) action_no = Z_IUOriginPartToKeep_recordInsert; @@ -3145,19 +3205,19 @@ static Z_APDU *create_update_package(ZOOM_package p) else return 0; - apdu = create_es_package(p, yaz_oid_extserv_database_update); + apdu = create_es_package(p, package_oid); if (apdu) { Z_IUOriginPartToKeep *toKeep; Z_IUSuppliedRecords *notToKeep; Z_External *r = (Z_External *) odr_malloc(p->odr_out, sizeof(*r)); + const char *elementSetName = + ZOOM_options_get(p->options, "elementSetName"); apdu->u.extendedServicesRequest->taskSpecificParameters = r; - - r->direct_reference = odr_oiddup(p->odr_out, - yaz_oid_extserv_database_update); + r->direct_reference = odr_oiddup(p->odr_out, package_oid); r->descriptor = 0; r->which = Z_External_update; r->indirect_reference = 0; @@ -3173,7 +3233,11 @@ static Z_APDU *create_update_package(ZOOM_package p) toKeep->databaseName = odr_strdup(p->odr_out, first_db); toKeep->schema = 0; + toKeep->elementSetName = 0; + if (elementSetName) + toKeep->elementSetName = odr_strdup(p->odr_out, elementSetName); + toKeep->actionQualifier = 0; toKeep->action = odr_intdup(p->odr_out, action_no); @@ -3203,7 +3267,18 @@ static Z_APDU *create_update_package(ZOOM_package p) else notToKeep->elements[0]->u.opaque = 0; notToKeep->elements[0]->supplementalId = 0; - notToKeep->elements[0]->correlationInfo = 0; + if (correlationInfo_note || correlationInfo_id) + { + Z_IUCorrelationInfo *ci; + ci = notToKeep->elements[0]->correlationInfo = + odr_malloc(p->odr_out, sizeof(*ci)); + ci->note = correlationInfo_note ? + odr_strdup(p->odr_out, correlationInfo_note) : 0; + ci->id = correlationInfo_id ? + odr_intdup(p->odr_out, atoi(correlationInfo_id)) : 0; + } + else + notToKeep->elements[0]->correlationInfo = 0; notToKeep->elements[0]->record = z_ext_record_oid(p->odr_out, syntax_oid, record_buf, strlen(record_buf)); @@ -3478,7 +3553,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); @@ -3495,7 +3570,7 @@ static void recv_apdu(ZOOM_connection c, Z_APDU *apdu) switch(apdu->which) { case Z_APDU_initResponse: - yaz_log(log_api, "%p recv_apd: Received Init response", c); + yaz_log(log_api, "%p recv_apdu: Received Init response", c); initrs = apdu->u.initResponse; ZOOM_connection_option_set(c, "serverImplementationId", initrs->implementationId ? @@ -3716,14 +3791,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; @@ -3758,7 +3834,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); @@ -3812,11 +3888,19 @@ static int do_read(ZOOM_connection c) { int x; int err = odr_geterrorx(c->odr_in, &x); - char msg[60]; + char msg[100]; const char *element = odr_getelement(c->odr_in); - sprintf(msg, "ODR code %d:%d element=%-20s", - err, x, element ? element : ""); + yaz_snprintf(msg, sizeof(msg), + "ODR code %d:%d element=%s offset=%d", + err, x, element ? element : "", + odr_offset(c->odr_in)); set_ZOOM_error(c, ZOOM_ERROR_DECODE, msg); + if (log_api) + { + FILE *ber_file = yaz_log_file(); + if (ber_file) + odr_dumpBER(ber_file, c->buf_in, r); + } do_close(c); } else if (gdu->which == Z_GDU_Z3950) @@ -4055,6 +4139,8 @@ static void ZOOM_connection_do_io(ZOOM_connection c, int mask) if (c->cs->io_pending & CS_WANT_READ) mask += ZOOM_SELECT_READ; ZOOM_connection_set_mask(c, mask); + event = ZOOM_Event_create(ZOOM_EVENT_NONE); + ZOOM_connection_put_event(c, event); } else if (ret == 0) { @@ -4108,7 +4194,7 @@ ZOOM_API(int) static void cql2pqf_wrbuf_puts(const char *buf, void *client_data) { - WRBUF wrbuf = client_data; + WRBUF wrbuf = (WRBUF) client_data; wrbuf_puts(wrbuf, buf); }