X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=src%2Fzoom-c.c;h=4d55399e8f9c9f9e17f02930abdadeafc4adda60;hp=27ebfa80f876e3b3db87aaa3947aec776a6eb2f1;hb=fe507b6b15788a3a8e58063d9dae52532a5229a5;hpb=3cdfbd27dfc8dd15619f127ae78bf0f71b27dd6d diff --git a/src/zoom-c.c b/src/zoom-c.c index 27ebfa8..4d55399 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.125 2007-04-16 21:53:09 adam Exp $ + * $Id: zoom-c.c,v 1.129 2007-05-06 20:12:20 adam Exp $ */ /** * \file zoom-c.c @@ -26,6 +26,8 @@ #include #include #include +#include +#include static int log_api = 0; static int log_details = 0; @@ -362,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); @@ -443,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"); @@ -521,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) { @@ -528,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) { @@ -536,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); @@ -726,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); } @@ -762,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; } @@ -792,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); @@ -817,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) @@ -858,7 +908,7 @@ ZOOM_API(void) ZOOM_resultset_sort(ZOOM_resultset r, const char *sort_type, const char *sort_spec) { - (void) ZOOM_resultset_sort(r, sort_type, sort_spec); + (void) ZOOM_resultset_sort1(r, sort_type, sort_spec); } ZOOM_API(int) @@ -963,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); @@ -1264,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); @@ -1296,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.125 $"); + version = odr_strdup(c->odr_out, "$Revision: 1.129 $"); if (strlen(version) > 10) /* check for unexpanded CVS strings */ version[strlen(version)-2] = '\0'; ireq->implementationVersion = @@ -1305,52 +1350,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) @@ -1547,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; @@ -2684,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); @@ -3444,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); @@ -4074,7 +4116,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); }