X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=zutil%2Fzoom-c.c;h=aa81c141f828122e374502daefb1770a79ce7514;hb=9ef544523c1dc964401a8227dd784add479900fd;hp=72e73544c23de7217c0655cf5fed7da960f16277;hpb=e12377e7ea8e58cf447492b5cb9887b839a78700;p=yaz-moved-to-github.git diff --git a/zutil/zoom-c.c b/zutil/zoom-c.c index 72e7354..aa81c14 100644 --- a/zutil/zoom-c.c +++ b/zutil/zoom-c.c @@ -2,7 +2,7 @@ * Copyright (c) 2000-2003, Index Data * See the file LICENSE for details. * - * $Id: zoom-c.c,v 1.25 2003-02-19 15:22:11 adam Exp $ + * $Id: zoom-c.c,v 1.30 2003-04-17 19:43:41 adam Exp $ * * ZOOM layer for C, connections, result sets, queries. */ @@ -388,6 +388,7 @@ ZOOM_query_create(void) s->z_query = 0; s->sort_spec = 0; s->odr = odr_createmem (ODR_ENCODE); + s->query_string = 0; return s; } @@ -410,6 +411,7 @@ ZOOM_query_destroy(ZOOM_query s) ZOOM_API(int) ZOOM_query_prefix(ZOOM_query s, const char *str) { + 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); @@ -423,16 +425,19 @@ ZOOM_query_cql(ZOOM_query s, const char *str) { Z_External *ext; + s->query_string = odr_strdup(s->odr, str); + ext = (Z_External *) odr_malloc(s->odr, sizeof(*ext)); ext->direct_reference = odr_getoidbystr(s->odr, "1.2.840.10003.16.2"); ext->indirect_reference = 0; ext->descriptor = 0; ext->which = Z_External_CQL; - ext->u.cql = odr_strdup(s->odr, str); + ext->u.cql = s->query_string; s->z_query = (Z_Query *) odr_malloc (s->odr, sizeof(*s->z_query)); s->z_query->which = Z_Query_type_104; s->z_query->u.type_104 = ext; + return 0; } @@ -499,8 +504,7 @@ ZOOM_resultset ZOOM_resultset_create () r->count = 0; r->record_cache = 0; r->r_sort_spec = 0; - r->z_query = 0; - r->search = 0; + r->query = 0; r->connection = 0; r->next = 0; return r; @@ -527,8 +531,7 @@ ZOOM_connection_search(ZOOM_connection c, ZOOM_query q) const char *cp; r->r_sort_spec = q->sort_spec; - r->z_query = q->z_query; - r->search = q; + r->query = q; r->options = ZOOM_options_create_with_parent(c->options); @@ -547,7 +550,7 @@ ZOOM_connection_search(ZOOM_connection c, ZOOM_query q) r->next = c->resultsets; c->resultsets = r; - if (c->host_port && c->proto == PROTO_SRW) + if (c->host_port && c->proto == PROTO_HTTP) { if (!c->cs) { @@ -605,7 +608,7 @@ ZOOM_resultset_destroy(ZOOM_resultset r) rp = &(*rp)->next; } } - ZOOM_query_destroy (r->search); + ZOOM_query_destroy (r->query); ZOOM_options_destroy (r->options); odr_destroy (r->odr); xfree (r->setname); @@ -642,7 +645,7 @@ static void ZOOM_resultset_retrieve (ZOOM_resultset r, if (!c) return; - if (c->host_port && c->proto == PROTO_SRW) + if (c->host_port && c->proto == PROTO_HTTP) { if (!c->cs) { @@ -709,29 +712,23 @@ static zoom_ret do_connect (ZOOM_connection c) yaz_log (LOG_DEBUG, "do_connect host=%s", effective_host); assert (!c->cs); + c->cs = cs_create_host (effective_host, 0, &add); - if (memcmp(c->host_port, "http:", 5) == 0) + if (c->cs && c->cs->protocol == PROTO_HTTP) { #if HAVE_XML2 - const char *path; - c->proto = PROTO_SRW; - effective_host = c->host_port + 5; - if (*effective_host == '/') - effective_host++; - if (*effective_host == '/') - effective_host++; - if (!(path = strchr(effective_host, '/'))) - path = "/"; + const char *path = 0; + + c->proto = PROTO_HTTP; + cs_get_host_args(c->host_port, &path); xfree(c->path); c->path = xstrdup(path); #else - c->state = STATE_IDLE; set_ZOOM_error(c, ZOOM_ERROR_UNSUPPORTED_PROTOCOL, "SRW"); + do_close(c); return zoom_complete; #endif } - c->cs = cs_create_host (effective_host, 0, &add); - if (c->cs) { int ret = cs_connect (c->cs, add); @@ -976,8 +973,9 @@ static zoom_ret ZOOM_connection_send_init (ZOOM_connection c) } #if HAVE_XML2 -static zoom_ret send_srw (ZOOM_connection c, Z_SRW_searchRetrieve *sr) +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}, {0, 0, 0} @@ -990,8 +988,15 @@ static zoom_ret send_srw (ZOOM_connection c, Z_SRW_searchRetrieve *sr) gdu = z_get_HTTP_Request(c->odr_out); gdu->u.HTTP_Request->path = c->path; + + strcpy(ctype, "text/xml"); + if (c->charset && strlen(c->charset) < 20) + { + strcat(ctype, "; charset="); + strcat(ctype, c->charset); + } z_HTTP_header_add(c->odr_out, &gdu->u.HTTP_Request->headers, - "Content-Type", "text/xml"); + "Content-Type", ctype); z_HTTP_header_add(c->odr_out, &gdu->u.HTTP_Request->headers, "SOAPAction", "\"\""); p->which = Z_SOAP_generic; @@ -1001,9 +1006,10 @@ static zoom_ret send_srw (ZOOM_connection c, Z_SRW_searchRetrieve *sr) p->u.generic->p = sr; p->ns = "http://schemas.xmlsoap.org/soap/envelope/"; - ret = z_soap_codec(o, &p, - &gdu->u.HTTP_Request->content_buf, - &gdu->u.HTTP_Request->content_len, h); + ret = z_soap_codec_enc(o, &p, + &gdu->u.HTTP_Request->content_buf, + &gdu->u.HTTP_Request->content_len, h, + c->charset); if (!z_GDU(c->odr_out, &gdu, 0, 0)) return zoom_complete; @@ -1023,7 +1029,8 @@ static zoom_ret ZOOM_connection_srw_send_search(ZOOM_connection c) { int i; ZOOM_resultset resultset = 0; - Z_SRW_searchRetrieve *sr = 0; + Z_SRW_PDU *sr = 0; + const char *recordPacking = 0; if (c->error) /* don't continue on error */ return zoom_complete; @@ -1056,18 +1063,22 @@ static zoom_ret ZOOM_connection_srw_send_search(ZOOM_connection c) if (i == resultset->count) return zoom_complete; } - assert(resultset->z_query); + assert(resultset->query); sr = yaz_srw_get(c->odr_out, Z_SRW_searchRetrieve_request); - if (resultset->z_query->which == Z_Query_type_104 - && resultset->z_query->u.type_104->which == Z_External_CQL) - sr->u.request->query = resultset->z_query->u.type_104->u.cql; - else if (resultset->z_query->which == Z_Query_type_1 && - resultset->z_query->u.type_1) + if (resultset->query->z_query->which == Z_Query_type_104 + && resultset->query->z_query->u.type_104->which == Z_External_CQL) { - set_ZOOM_error(c, ZOOM_ERROR_UNSUPPORTED_QUERY, 0); - return zoom_complete; + + sr->u.request->query_type = Z_SRW_query_type_cql; + sr->u.request->query.cql =resultset->query->z_query->u.type_104->u.cql; + } + else if (resultset->query->z_query->which == Z_Query_type_1 && + resultset->query->z_query->u.type_1) + { + sr->u.request->query_type = Z_SRW_query_type_pqf; + sr->u.request->query.pqf = resultset->query->query_string; } else { @@ -1078,7 +1089,11 @@ static zoom_ret ZOOM_connection_srw_send_search(ZOOM_connection c) sr->u.request->maximumRecords = odr_intdup (c->odr_out, resultset->count); sr->u.request->recordSchema = resultset->schema; - + recordPacking = ZOOM_resultset_option_get (resultset, "recordPacking"); + + if (recordPacking) + sr->u.request->recordPacking = odr_strdup(c->odr_out, recordPacking); + return send_srw(c, sr); } #else @@ -1118,10 +1133,10 @@ static zoom_ret ZOOM_connection_send_search (ZOOM_connection c) mediumSetElementSetName = elementSetName; assert (r); - assert (r->z_query); + assert (r->query); /* prepare query for the search request */ - search_req->query = r->z_query; + search_req->query = r->query->z_query; search_req->databaseNames = set_DatabaseNames (c, r->options, &search_req->num_databaseNames); @@ -1428,6 +1443,11 @@ ZOOM_record_get (ZOOM_record rec, const char *type, int *len) if (len) *len = 5; return "GRS-1"; } + else if (r->which == Z_External_OPAC) + { + if (len) *len = 4; + return "OPAC"; + } return 0; } else if (!strcmp (type, "raw")) @@ -2217,13 +2237,13 @@ static int ZOOM_connection_exec_task (ZOOM_connection c) switch (task->which) { case ZOOM_TASK_SEARCH: - if (c->proto == PROTO_SRW) + if (c->proto == PROTO_HTTP) ret = ZOOM_connection_srw_send_search(c); else ret = ZOOM_connection_send_search(c); break; case ZOOM_TASK_RETRIEVE: - if (c->proto == PROTO_SRW) + if (c->proto == PROTO_HTTP) ret = ZOOM_connection_srw_send_search(c); else ret = send_present (c); @@ -2484,7 +2504,7 @@ static void handle_http(ZOOM_connection c, Z_HTTP_Response *hres) if (!ret && soap_package->which == Z_SOAP_generic && soap_package->u.generic->no == 0) { - Z_SRW_searchRetrieve *sr = soap_package->u.generic->p; + Z_SRW_PDU *sr = soap_package->u.generic->p; if (sr->which == Z_SRW_searchRetrieve_response) handle_srw_response(c, sr->u.response); else