X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=src%2Fsrwutil.c;h=e1c9546d7d2c8330046141634d254b41019a263a;hp=4eb9573fca0d2047cdd1e4a46491d3d671254c5a;hb=176adcd5ec7f2340fb6f0f625a727498db9c04c4;hpb=2caef65db3a7a290fd2fff36910bc19e70a880a3 diff --git a/src/srwutil.c b/src/srwutil.c index 4eb9573..e1c9546 100644 --- a/src/srwutil.c +++ b/src/srwutil.c @@ -141,13 +141,6 @@ static void yaz_srw_decodeauth(Z_SRW_PDU *sr, Z_HTTP_Request *hreq, } } -void yaz_uri_val_int(const char *path, const char *name, ODR o, Odr_int **intp) -{ - const char *v = yaz_uri_val(path, name, o); - if (v) - *intp = odr_intdup(o, atoi(v)); -} - void yaz_mk_srw_diagnostic(ODR o, Z_SRW_diagnostic *d, const char *uri, const char *message, const char *details) @@ -241,14 +234,21 @@ static void grab_charset(ODR o, const char *content_type, char **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 j = 0, i = 0; + int sep = 0; + charset_p += 10; /* skip ; charset= */ + if (charset_p[i] == '"' || charset_p[i] == '\'') + sep = charset_p[i++]; + *charset = odr_strdup(o, charset_p); + while (charset_p[i] && charset_p[i] != sep) + { + if (!sep && strchr("; \n\r", charset_p[i])) + break; + if (charset_p[i] == '\\' && charset_p[i+1]) + i++; + (*charset)[j++] = charset_p[i++]; + } + (*charset)[j] = '\0'; } } } @@ -286,7 +286,6 @@ int yaz_srw_decode(Z_HTTP_Request *hreq, Z_SRW_PDU **srw_pdu, p1 = p0 + strlen(p0); if (p1 != p0) db = yaz_decode_sru_dbpath_odr(decode, p0, p1 - p0); - grab_charset(decode, content_type, charset); ret = z_soap_codec(decode, soap_package, &hreq->content_buf, &hreq->content_len, @@ -397,6 +396,9 @@ int yaz_sru_decode(Z_HTTP_Request *hreq, Z_SRW_PDU **srw_pdu, char *startRecord = 0; char *maximumTerms = 0; char *responsePosition = 0; + const char *facetLimit = 0; + const char *facetStart = 0; + const char *facetSort = 0; Z_SRW_extra_arg *extra_args = 0; #endif char **uri_name; @@ -468,6 +470,12 @@ int yaz_sru_decode(Z_HTTP_Request *hreq, Z_SRW_PDU **srw_pdu, maximumTerms = v; else if (!strcmp(n, "responsePosition")) responsePosition = v; + else if (!strcmp(n, "facetLimit")) + facetLimit = v; + else if (!strcmp(n, "facetStart")) + facetStart = v; + else if (!strcmp(n, "facetSort")) + facetSort = v; else if (!strcmp(n, "extraRequestData")) ; /* ignoring extraRequestData */ else if (n[0] == 'x' && n[1] == '-') @@ -488,8 +496,13 @@ int yaz_sru_decode(Z_HTTP_Request *hreq, Z_SRW_PDU **srw_pdu, } } } - if (!operation && query) - operation = "searchRetrieve"; + if (!operation) + { + if (query) + operation = "searchRetrieve"; + else if (scanClause) + operation = "scan"; + } version = yaz_negotiate_sru_version(version); if (!version) @@ -547,6 +560,8 @@ int yaz_sru_decode(Z_HTTP_Request *hreq, Z_SRW_PDU **srw_pdu, sr->u.request->recordPacking = recordXMLEscaping; sr->u.request->packing = recordPacking; sr->u.request->stylesheet = stylesheet; + yaz_sru_facet_request(decode , &sr->u.request->facetList, + &facetLimit, &facetStart, &facetSort); yaz_sru_decode_integer(decode, "maximumRecords", maximumRecords, &sr->u.request->maximumRecords, @@ -773,6 +788,7 @@ Z_SRW_PDU *yaz_srw_get_pdu(ODR o, int which, const char *version) sr->u.response = (Z_SRW_searchRetrieveResponse *) odr_malloc(o, sizeof(*sr->u.response)); sr->u.response->numberOfRecords = 0; + sr->u.response->resultCountPrecision = 0; sr->u.response->resultSetId = 0; sr->u.response->resultSetIdleTime = 0; sr->u.response->records = 0; @@ -883,19 +899,19 @@ static int yaz_get_sru_parms(const Z_SRW_PDU *srw_pdu, ODR encode, int version2 = strcmp(srw_pdu->srw_version, "2.") > 0; int i = 0; char *queryType; - if (!version2) - yaz_add_name_value_str(encode, name, value, &i, "version", srw_pdu->srw_version); + yaz_add_name_value_str(encode, name, value, &i, "version", + srw_pdu->srw_version); name[i] = "operation"; switch (srw_pdu->which) { case Z_SRW_searchRetrieve_request: - if (!version2) - value[i++] = "searchRetrieve"; + value[i++] = "searchRetrieve"; queryType = srw_pdu->u.request->queryType; if (version2) { - yaz_add_name_value_str(encode, name, value, &i, "queryType", - queryType); + if (queryType && strcmp(queryType, "cql")) + yaz_add_name_value_str(encode, name, value, &i, "queryType", + queryType); yaz_add_name_value_str(encode, name, value, &i, "query", srw_pdu->u.request->query); } @@ -948,6 +964,19 @@ static int yaz_get_sru_parms(const Z_SRW_PDU *srw_pdu, ODR encode, srw_pdu->u.request->stylesheet); yaz_add_name_value_int(encode, name, value, &i, "resultSetTTL", srw_pdu->u.request->resultSetTTL); + { + const char *facetLimit = 0; + const char *facetStart = 0; + const char *facetSort = 0; + yaz_sru_facet_request(encode, &srw_pdu->u.request->facetList, + &facetLimit, &facetStart, &facetSort); + yaz_add_name_value_str(encode, name, value, &i, "facetLimit", + (char *) facetLimit); + yaz_add_name_value_str(encode, name, value, &i, "facetStart", + (char *) facetStart); + yaz_add_name_value_str(encode, name, value, &i, "facetSort", + (char *) facetSort); + } break; case Z_SRW_explain_request: value[i++] = "explain"; @@ -1036,7 +1065,6 @@ int yaz_sru_get_encode(Z_HTTP_Request *hreq, Z_SRW_PDU *srw_pdu, odr_malloc(encode, strlen(hreq->path) + strlen(uri_args) + 4); sprintf(path, "%s?%s", hreq->path, uri_args); - yaz_log(YLOG_DEBUG, "SRU HTTP Get Request %s", path); hreq->path = path; z_HTTP_header_add_content_type(encode, &hreq->headers, @@ -1084,7 +1112,7 @@ int yaz_sru_soap_encode(Z_HTTP_Request *hreq, Z_SRW_PDU *srw_pdu, srw_pdu->username, srw_pdu->password); z_HTTP_header_add_content_type(odr, &hreq->headers, - "text/xml", charset); + "text/xml", 0 /* no charset in MIME */); z_HTTP_header_add(odr, &hreq->headers, "SOAPAction", "\"\""); @@ -1153,6 +1181,9 @@ void yaz_encode_sru_extra(Z_SRW_PDU *sr, ODR odr, const char *extra_args) Z_SRW_extra_arg **ea = &sr->extra_args; yaz_uri_to_array(extra_args, odr, &name, &val); + /** append rather than override */ + while (*ea) + ea = &(*ea)->next; while (*name) { *ea = (Z_SRW_extra_arg *) odr_malloc(odr, sizeof(**ea));