X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Fsrwutil.c;h=560976be9216899bd53cf693a995135d3ea428e3;hb=6d678c5970ec665607e3d1ddbd8809a14bccabdf;hp=7be74bfef995c5e2827def3611fe84512afb9eb2;hpb=8170d48cb0b650f3d8ec35e3ad1e5fe0046eeecc;p=yaz-moved-to-github.git diff --git a/src/srwutil.c b/src/srwutil.c index 7be74bf..560976b 100644 --- a/src/srwutil.c +++ b/src/srwutil.c @@ -2,7 +2,7 @@ * Copyright (C) 1995-2006, Index Data ApS * See the file LICENSE for details. * - * $Id: srwutil.c,v 1.47 2006-08-18 06:30:05 adam Exp $ + * $Id: srwutil.c,v 1.53 2006-10-27 11:22:09 adam Exp $ */ /** * \file srwutil.c @@ -80,7 +80,7 @@ static void yaz_array_to_uri_ex(char **path, ODR o, char **name, char **value, void yaz_array_to_uri(char **path, ODR o, char **name, char **value) { - return yaz_array_to_uri_ex(path, o, name, value, 0); + yaz_array_to_uri_ex(path, o, name, value, 0); } int yaz_uri_array(const char *path, ODR o, char ***name, char ***val) @@ -328,6 +328,36 @@ void yaz_add_srw_diagnostic(ODR o, Z_SRW_diagnostic **d, yaz_add_srw_diagnostic_uri(o, d, num, uri, 0, addinfo); } + +void yaz_add_sru_update_diagnostic(ODR o, Z_SRW_diagnostic **d, + int *num, int code, const char *addinfo) +{ + char uri[40]; + + sprintf(uri, "info:srw/diagnostic/12/%d", code); + yaz_add_srw_diagnostic_uri(o, d, num, uri, 0, addinfo); +} + + +static void grab_charset(ODR o, const char *content_type, char **charset) +{ + if (charset) + { + const char *charset_p = 0; + if (content_type && (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 = (char*) odr_malloc(o, i+1); + memcpy(*charset, charset_p, i); + (*charset)[i] = '\0'; + } + } +} + int yaz_srw_decode(Z_HTTP_Request *hreq, Z_SRW_PDU **srw_pdu, Z_SOAP **soap_package, ODR decode, char **charset) { @@ -343,7 +373,6 @@ int yaz_srw_decode(Z_HTTP_Request *hreq, Z_SRW_PDU **srw_pdu, char *db = "Default"; const char *p0 = hreq->path, *p1; int ret = -1; - const char *charset_p = 0; static Z_SOAP_Handler soap_handlers[4] = { #if YAZ_HAVE_XML2 @@ -369,17 +398,8 @@ int yaz_srw_decode(Z_HTTP_Request *hreq, Z_SRW_PDU **srw_pdu, db[p1 - p0] = '\0'; } - if (charset && (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 = (char*) odr_malloc(decode, i+1); - memcpy(*charset, charset_p, i); - (*charset)[i] = '\0'; - } + grab_charset(decode, content_type, charset); + ret = z_soap_codec(decode, soap_package, &hreq->content_buf, &hreq->content_len, soap_handlers); @@ -411,10 +431,10 @@ int yaz_srw_decode(Z_HTTP_Request *hreq, Z_SRW_PDU **srw_pdu, return 2; } -static int yaz_sru_integer_decode(ODR odr, const char *pname, +static int yaz_sru_decode_integer(ODR odr, const char *pname, const char *valstr, int **valp, - Z_SRW_diagnostic **diag, int *num_diag) - + Z_SRW_diagnostic **diag, int *num_diag, + int min_value) { int ival; if (!valstr) @@ -425,9 +445,16 @@ static int yaz_sru_integer_decode(ODR odr, const char *pname, YAZ_SRW_UNSUPP_PARAMETER_VALUE, pname); return 0; } + if (min_value >= 0 && ival < min_value) + { + yaz_add_srw_diagnostic(odr, diag, num_diag, + YAZ_SRW_UNSUPP_PARAMETER_VALUE, pname); + return 0; + } *valp = odr_intdup(odr, ival); return 1; } + /** http://www.loc.gov/z3950/agency/zing/srw/service.html */ @@ -443,20 +470,18 @@ int yaz_sru_decode(Z_HTTP_Request *hreq, Z_SRW_PDU **srw_pdu, }; #endif const char *content_type = z_HTTP_header_lookup(hreq->headers, - "Content-Type"); + "Content-Type"); + /* - SRU GET: allow any content type. + SRU GET: ignore content type. SRU POST: we support "application/x-www-form-urlencoded"; not "multipart/form-data" . */ - if (!strcmp(hreq->method, "GET") - || - (!strcmp(hreq->method, "POST") - && content_type && - !yaz_strcmp_del("application/x-www-form-urlencoded", - content_type, "; ") - ) - ) + if (!strcmp(hreq->method, "GET") + || + (!strcmp(hreq->method, "POST") && content_type && + !yaz_strcmp_del("application/x-www-form-urlencoded", + content_type, "; "))) { char *db = "Default"; const char *p0 = hreq->path, *p1; @@ -483,8 +508,10 @@ int yaz_sru_decode(Z_HTTP_Request *hreq, Z_SRW_PDU **srw_pdu, char **uri_name; char **uri_val; - if (charset) - *charset = 0; + grab_charset(decode, content_type, charset); + if (charset && *charset == 0 && !strcmp(hreq->method, "GET")) + *charset = "UTF-8"; + if (*p0 == '/') p0++; p1 = strchr(p0, '?'); @@ -599,13 +626,13 @@ int yaz_sru_decode(Z_HTTP_Request *hreq, Z_SRW_PDU **srw_pdu, sr->u.request->recordPacking = recordPacking; sr->u.request->stylesheet = stylesheet; - yaz_sru_integer_decode(decode, "maximumRecords", maximumRecords, + yaz_sru_decode_integer(decode, "maximumRecords", maximumRecords, &sr->u.request->maximumRecords, - diag, num_diag); - - yaz_sru_integer_decode(decode, "startRecord", startRecord, + diag, num_diag, 0); + + yaz_sru_decode_integer(decode, "startRecord", startRecord, &sr->u.request->startRecord, - diag, num_diag); + diag, num_diag, 1); sr->u.request->database = db; @@ -677,15 +704,15 @@ int yaz_sru_decode(Z_HTTP_Request *hreq, Z_SRW_PDU **srw_pdu, YAZ_SRW_MANDATORY_PARAMETER_NOT_SUPPLIED, "scanClause"); sr->u.scan_request->database = db; - yaz_sru_integer_decode(decode, "maximumTerms", + yaz_sru_decode_integer(decode, "maximumTerms", maximumTerms, &sr->u.scan_request->maximumTerms, - diag, num_diag); - - yaz_sru_integer_decode(decode, "responsePosition", + diag, num_diag, 0); + + yaz_sru_decode_integer(decode, "responsePosition", responsePosition, &sr->u.scan_request->responsePosition, - diag, num_diag); + diag, num_diag, 0); sr->u.scan_request->stylesheet = stylesheet;