X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Fseshigh.c;h=34fe0b072943806d8b1051d0a02e8f9102411884;hb=8811f4c9c5a84976b696349b5dc4d7ae0faf66b6;hp=7a8a7aaeee424769e405cb53142312405cccd07a;hpb=c82bbc07fb53f78aab88bb4121629daeef42ed2a;p=yaz-moved-to-github.git diff --git a/src/seshigh.c b/src/seshigh.c index 7a8a7aa..34fe0b0 100644 --- a/src/seshigh.c +++ b/src/seshigh.c @@ -1,8 +1,8 @@ /* - * Copyright (c) 1995-2003, Index Data + * Copyright (c) 1995-2004, Index Data * See the file LICENSE for details. * - * $Id: seshigh.c,v 1.13 2004-01-05 09:34:42 adam Exp $ + * $Id: seshigh.c,v 1.19 2004-01-27 12:15:12 adam Exp $ */ /* @@ -564,12 +564,8 @@ static void srw_bend_search(association *assoc, request *req, { 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; + yaz_add_srw_diagnostic(assoc->encode, &srw_res->diagnostics, + &srw_res->num_diagnostics, 1, 0); return; } } @@ -635,9 +631,8 @@ static void srw_bend_search(association *assoc, request *req, 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; + yaz_mk_std_diagnostic(assoc->encode, + srw_res->diagnostics, srw_error, 0); return; } @@ -665,13 +660,11 @@ static void srw_bend_search(association *assoc, request *req, 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, - yaz_diag_bib1_to_srw (rr.errcode)); - srw_res->diagnostics[0].details = rr.errstring; + yaz_mk_std_diagnostic(assoc->encode, srw_res->diagnostics, + yaz_diag_bib1_to_srw (rr.errcode), + rr.errstring); yaz_log(LOG_DEBUG, "srw_bend_search returned SRW error %d", *srw_res->diagnostics[0].code); - } else { @@ -717,10 +710,11 @@ static void srw_bend_search(association *assoc, request *req, srw_res->diagnostics = (Z_SRW_diagnostic *) odr_malloc(assoc->encode, sizeof(*srw_res->diagnostics)); - srw_res->diagnostics[0].code = - odr_intdup(assoc->encode, - yaz_diag_bib1_to_srw (errcode)); - srw_res->diagnostics[0].details = rr.errstring; + + yaz_mk_std_diagnostic(assoc->encode, + srw_res->diagnostics, + yaz_diag_bib1_to_srw (errcode), + rr.errstring); break; } if (srw_res->records[j].recordData_buf) @@ -779,17 +773,36 @@ static void process_http_request(association *assoc, request *req) { Z_HTTP_Request *hreq = req->gdu_request->u.HTTP_Request; ODR o = assoc->encode; - int r; + int r = 2; /* 2=NOT TAKEN, 1=TAKEN, 0=SOAP TAKEN */ Z_SRW_PDU *sr = 0; Z_SOAP *soap_package = 0; Z_GDU *p = 0; char *charset = 0; - Z_HTTP_Response *hres; + Z_HTTP_Response *hres = 0; int keepalive = 1; + char *stylesheet = 0; + Z_SRW_diagnostic *diagnostic = 0; + int num_diagnostic = 0; - r = yaz_srw_decode(hreq, &sr, &soap_package, assoc->decode, &charset); + if (!strcmp(hreq->path, "/test")) + { + p = z_get_HTTP_Response(o, 200); + hres = p->u.HTTP_Response; + hres->content_buf = "1234567890\n"; + hres->content_len = strlen(hres->content_buf); + r = 1; + } + if (r == 2) + { + r = yaz_srw_decode(hreq, &sr, &soap_package, assoc->decode, &charset); + yaz_log(LOG_DEBUG, "yaz_srw_decode returned %d", r); + } if (r == 2) /* not taken */ - r = yaz_sru_decode(hreq, &sr, &soap_package, assoc->decode, &charset); + { + r = yaz_sru_decode(hreq, &sr, &soap_package, assoc->decode, &charset, + &diagnostic, &num_diagnostic); + yaz_log(LOG_DEBUG, "yaz_sru_decode returned %d", r); + } if (r == 0) /* decode SRW/SRU OK .. */ { int http_code = 200; @@ -797,20 +810,51 @@ static void process_http_request(association *assoc, request *req) { Z_SRW_PDU *res = yaz_srw_get(assoc->encode, Z_SRW_searchRetrieve_response); - - srw_bend_search(assoc, req, sr->u.request, res->u.response, - &http_code); + + stylesheet = sr->u.request->stylesheet; + if (num_diagnostic) + { + res->u.response->diagnostics = diagnostic; + res->u.response->num_diagnostics = num_diagnostic; + } + else + { + srw_bend_search(assoc, req, sr->u.request, res->u.response, + &http_code); + } if (http_code == 200) soap_package->u.generic->p = res; } else if (sr->which == Z_SRW_explain_request) { Z_SRW_PDU *res = yaz_srw_get(o, Z_SRW_explain_response); - srw_bend_explain(assoc, req, sr->u.explain_request, + stylesheet = sr->u.explain_request->stylesheet; + if (num_diagnostic) + { + res->u.explain_response->diagnostics = diagnostic; + res->u.explain_response->num_diagnostics = num_diagnostic; + } + srw_bend_explain(assoc, req, sr->u.explain_request, res->u.explain_response, &http_code); if (http_code == 200) soap_package->u.generic->p = res; } + else if (sr->which == Z_SRW_scan_request) + { + Z_SRW_PDU *res = yaz_srw_get(o, Z_SRW_scan_response); + stylesheet = sr->u.scan_request->stylesheet; + if (num_diagnostic) + { + res->u.scan_response->diagnostics = diagnostic; + res->u.scan_response->num_diagnostics = num_diagnostic; + } + yaz_add_srw_diagnostic(o, + &res->u.scan_response->diagnostics, + &res->u.scan_response->num_diagnostics, + 4, "scan"); + if (http_code == 200) + soap_package->u.generic->p = res; + } else { http_code = 500; @@ -832,9 +876,9 @@ static void process_http_request(association *assoc, request *req) int ret; p = z_get_HTTP_Response(o, 200); hres = p->u.HTTP_Response; - ret = z_soap_codec_enc(assoc->encode, &soap_package, - &hres->content_buf, &hres->content_len, - soap_handlers, charset); + ret = z_soap_codec_enc_xsl(assoc->encode, &soap_package, + &hres->content_buf, &hres->content_len, + soap_handlers, charset, stylesheet); hres->code = http_code; strcpy(ctype, "text/xml"); @@ -848,7 +892,8 @@ static void process_http_request(association *assoc, request *req) else p = z_get_HTTP_Response(o, http_code); } - else + + if (p == 0) p = z_get_HTTP_Response(o, 500); hres = p->u.HTTP_Response; if (!strcmp(hreq->version, "1.0")) @@ -1145,7 +1190,8 @@ static Z_APDU *process_initRequest(association *assoc, request *reqb) { Z_CharSetandLanguageNegotiation *negotiation = yaz_get_charneg_record (req->otherInfo); - if (negotiation->which == Z_CharSetandLanguageNegotiation_proposal) + if (negotiation && + negotiation->which == Z_CharSetandLanguageNegotiation_proposal) assoc->init->charneg_request = negotiation; } @@ -1239,7 +1285,7 @@ static Z_APDU *process_initRequest(association *assoc, request *reqb) if (ODR_MASK_GET(req->protocolVersion, Z_ProtocolVersion_1)) { ODR_MASK_SET(resp->protocolVersion, Z_ProtocolVersion_1); - assoc->version = 2; /* 1 & 2 are equivalent */ + assoc->version = 1; /* 1 & 2 are equivalent */ } if (ODR_MASK_GET(req->protocolVersion, Z_ProtocolVersion_2)) { @@ -1271,7 +1317,7 @@ static Z_APDU *process_initRequest(association *assoc, request *reqb) assoc->init->implementation_name, odr_prepend(assoc->encode, "GFS", resp->implementationName)); - version = odr_strdup(assoc->encode, "$Revision: 1.13 $"); + version = odr_strdup(assoc->encode, "$Revision: 1.19 $"); if (strlen(version) > 10) /* check for unexpanded CVS strings */ version[strlen(version)-2] = '\0'; resp->implementationVersion = odr_prepend(assoc->encode, @@ -1515,7 +1561,8 @@ static Z_Records *pack_records(association *a, char *setname, int start, this_length = odr_total(a->encode) - total_length - dumped_records; yaz_log(LOG_DEBUG, " fetched record, len=%d, total=%d dumped=%d", this_length, total_length, dumped_records); - if (this_length + total_length > a->preferredMessageSize) + if (a->preferredMessageSize > 0 && + this_length + total_length > a->preferredMessageSize) { /* record is small enough, really */ if (this_length <= a->preferredMessageSize && recno > start)