X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=server%2Fseshigh.c;h=e8c643997b5c063b0d3b48084b8ff2e46560b5be;hb=1e5554fc59c8cad2105b2a8cf095d13315dc6ed1;hp=bb2775414213c9f7a2eb64a73fb3ba8d7da32b88;hpb=5f9dfb9266ab741d41a636249a39a254e4fb7211;p=yaz-moved-to-github.git diff --git a/server/seshigh.c b/server/seshigh.c index bb27754..e8c6439 100644 --- a/server/seshigh.c +++ b/server/seshigh.c @@ -2,7 +2,7 @@ * Copyright (c) 1995-2003, Index Data * See the file LICENSE for details. * - * $Id: seshigh.c,v 1.146 2003-02-23 14:26:57 adam Exp $ + * $Id: seshigh.c,v 1.148 2003-03-11 11:09:17 adam Exp $ */ /* @@ -100,6 +100,7 @@ association *create_association(IOCHAN channel, COMSTACK link) if (!(anew = (association *)xmalloc(sizeof(*anew)))) return 0; anew->init = 0; + anew->version = 0; anew->client_chan = channel; anew->client_link = link; anew->cs_get_mask = 0; @@ -444,6 +445,8 @@ static void assoc_init_reset(association *assoc) static int srw_bend_init(association *assoc) { + const char *encoding = "UTF-8"; + Z_External *ce; bend_initresult *binitres; statserv_options_block *cb = statserv_getcontrol(); @@ -451,7 +454,10 @@ static int srw_bend_init(association *assoc) assoc->maximumRecordSize = 3000000; assoc->preferredMessageSize = 3000000; - +#if 1 + ce = yaz_set_proposal_charneg(assoc->decode, &encoding, 1, 0, 0, 1); + assoc->init->charneg_request = ce->u.charNeg3; +#endif if (!(binitres = (*cb->bend_init)(assoc->init))) { yaz_log(LOG_WARN, "Bad response from backend."); @@ -506,7 +512,10 @@ static int srw_bend_fetch(association *assoc, int pos, rr.errcode = 0; rr.errstring = 0; rr.surrogate_flag = 0; - + + if (!assoc->init->bend_fetch) + return 1; + (*assoc->init->bend_fetch)(assoc->backend, &rr); if (rr.len >= 0) @@ -531,8 +540,21 @@ static void srw_bend_search(association *assoc, request *req, yaz_log(LOG_LOG, "Got SRW SearchRetrieveRequest"); if (!assoc->init) - srw_bend_init(assoc); - + { + if (!srw_bend_init(assoc)) + { + srw_error = 3; /* assume Authentication error */ + + srw_res->num_diagnostics = 1; + srw_res->diagnostics = (Z_SRW_diagnostic *) + odr_malloc(assoc->encode, sizeof(*srw_res->diagnostics)); + srw_res->diagnostics[0].code = + odr_intdup(assoc->encode, srw_error); + srw_res->diagnostics[0].details = 0; + return; + } + } + rr.setname = "default"; rr.replace_set = 1; rr.num_bases = 1; @@ -582,9 +604,12 @@ static void srw_bend_search(association *assoc, request *req, else srw_error = 11; - if (srw_req->sort_type != Z_SRW_sort_type_none) + if (!srw_error && srw_req->sort_type != Z_SRW_sort_type_none) srw_error = 80; + if (!srw_error && !assoc->init->bend_search) + srw_error = 1; + if (srw_error) { srw_res->num_diagnostics = 1; @@ -595,7 +620,6 @@ static void srw_bend_search(association *assoc, request *req, srw_res->diagnostics[0].details = 0; return; } - rr.stream = assoc->encode; rr.decode = assoc->decode; @@ -643,7 +667,7 @@ static void srw_bend_search(association *assoc, request *req, int errcode; srw_res->records[j].recordData_buf = 0; errcode = srw_bend_fetch(assoc, i+start, srw_req, - srw_res->records + j); + srw_res->records + j); if (errcode) { srw_res->num_diagnostics = 1; @@ -773,6 +797,8 @@ static void process_http_request(association *assoc, request *req) Z_SOAP *soap_package = 0; int ret = -1; int http_code = 500; + const char *charset_p = 0; + char *charset = 0; static Z_SOAP_Handler soap_handlers[2] = { #if HAVE_XML2 @@ -781,6 +807,18 @@ static void process_http_request(association *assoc, request *req) #endif {0, 0, 0} }; + if ((charset_p = strstr(content_type, "; charset="))) + { + int i = 0; + charset_p += 10; + while (i < 20 && charset_p[i] && + !strchr("; \n\r", charset_p[i])) + i++; + charset = odr_malloc(assoc->encode, i+1); + memcpy(charset, charset_p, i); + charset[i] = '\0'; + yaz_log(LOG_LOG, "SOAP encoding %s", charset); + } ret = z_soap_codec(assoc->decode, &soap_package, &hreq->content_buf, &hreq->content_len, soap_handlers); @@ -826,11 +864,19 @@ static void process_http_request(association *assoc, request *req) #endif p = z_get_HTTP_Response(o, 200); hres = p->u.HTTP_Response; - ret = z_soap_codec(assoc->encode, &soap_package, - &hres->content_buf, &hres->content_len, - soap_handlers); + ret = z_soap_codec_enc(assoc->encode, &soap_package, + &hres->content_buf, &hres->content_len, + soap_handlers, charset); hres->code = http_code; - z_HTTP_header_add(o, &hres->headers, "Content-Type", "text/xml"); + if (!charset) + z_HTTP_header_add(o, &hres->headers, "Content-Type", "text/xml"); + else + { + char ctype[60]; + strcpy(ctype, "text/xml; charset="); + strcat(ctype, charset); + z_HTTP_header_add(o, &hres->headers, "Content-Type", ctype); + } } if (!p) /* still no response ? */ p = z_get_HTTP_Response(o, 500);