X-Git-Url: http://jsfdemo.indexdata.com/?a=blobdiff_plain;f=src%2Fsrw.c;h=33452e26ef79e616f972f76d0597514e2239cc99;hb=c5ebd327a29b3ec88eedbea53f9a0f6cda164de7;hp=d4fbfc6f1da0b2397c85833754e2491f6108ca53;hpb=951bf68e90a1f19fc5103c408b136bdb4242e67b;p=yaz-moved-to-github.git diff --git a/src/srw.c b/src/srw.c index d4fbfc6..33452e2 100644 --- a/src/srw.c +++ b/src/srw.c @@ -18,7 +18,7 @@ #include #include #include - +#include #include "sru-p.h" static void add_XML_n(xmlNodePtr ptr, const char *elem, char *val, int len, @@ -68,7 +68,7 @@ xmlNodePtr add_xsd_string(xmlNodePtr ptr, const char *elem, const char *val) return add_xsd_string_ns(ptr, elem, val, 0); } -static void add_xsd_integer(xmlNodePtr ptr, const char *elem, +void add_xsd_integer(xmlNodePtr ptr, const char *elem, const Odr_int *val) { if (val) @@ -79,7 +79,7 @@ static void add_xsd_integer(xmlNodePtr ptr, const char *elem, } } -static int match_element(xmlNodePtr ptr, const char *elem) +int yaz_match_xsd_element(xmlNodePtr ptr, const char *elem) { if (ptr->type == XML_ELEMENT_NODE && !xmlStrcmp(ptr->name, BAD_CAST elem)) { @@ -90,13 +90,13 @@ static int match_element(xmlNodePtr ptr, const char *elem) #define CHECK_TYPE 0 -static int match_xsd_string_n(xmlNodePtr ptr, const char *elem, ODR o, - char **val, int *len) +int yaz_match_xsd_string_n(xmlNodePtr ptr, const char *elem, ODR o, + char **val, int *len) { #if CHECK_TYPE struct _xmlAttr *attr; #endif - if (!match_element(ptr, elem)) + if (!yaz_match_xsd_element(ptr, elem)) return 0; #if CHECK_TYPE for (attr = ptr->properties; attr; attr = attr->next) @@ -127,19 +127,18 @@ static int match_xsd_string_n(xmlNodePtr ptr, const char *elem, ODR o, } -static int match_xsd_string(xmlNodePtr ptr, const char *elem, ODR o, - char **val) +int yaz_match_xsd_string(xmlNodePtr ptr, const char *elem, ODR o, char **val) { - return match_xsd_string_n(ptr, elem, o, val, 0); + return yaz_match_xsd_string_n(ptr, elem, o, val, 0); } -static int match_xsd_XML_n2(xmlNodePtr ptr, const char *elem, ODR o, - char **val, int *len, int fixup_root) +static int yaz_match_xsd_XML_n2(xmlNodePtr ptr, const char *elem, ODR o, + char **val, int *len, int fixup_root) { xmlBufferPtr buf; int no_root_nodes = 0; - if (!match_element(ptr, elem)) + if (!yaz_match_xsd_element(ptr, elem)) return 0; buf = xmlBufferCreate(); @@ -180,19 +179,19 @@ static int match_xsd_XML_n2(xmlNodePtr ptr, const char *elem, ODR o, return 1; } -static int match_xsd_XML_n(xmlNodePtr ptr, const char *elem, ODR o, +static int yaz_match_xsd_XML_n(xmlNodePtr ptr, const char *elem, ODR o, char **val, int *len) { - return match_xsd_XML_n2(ptr, elem, o, val, len, 0); + return yaz_match_xsd_XML_n2(ptr, elem, o, val, len, 0); } -static int match_xsd_integer(xmlNodePtr ptr, const char *elem, ODR o, - Odr_int **val) +int yaz_match_xsd_integer(xmlNodePtr ptr, const char *elem, ODR o, + Odr_int **val) { #if CHECK_TYPE struct _xmlAttr *attr; #endif - if (!match_element(ptr, elem)) + if (!yaz_match_xsd_element(ptr, elem)) return 0; #if CHECK_TYPE for (attr = ptr->properties; attr; attr = attr->next) @@ -220,16 +219,19 @@ static int match_xsd_integer(xmlNodePtr ptr, const char *elem, ODR o, char *yaz_negotiate_sru_version(char *input_ver) { if (!input_ver) - input_ver = "1.1"; - + return "2.0"; if (!strcmp(input_ver, "1.1")) return "1.1"; - return "1.2"; /* our latest supported version */ + if (!strncmp(input_ver, "1.", 2)) + return "1.2"; + if (!strncmp(input_ver, "2.", 2)) + return "2.0"; + return 0; } static int yaz_srw_record(ODR o, xmlNodePtr pptr, Z_SRW_record *rec, Z_SRW_extra_record **extra, - void *client_data, const char *ns) + void *client_data, int version2) { if (o->direction == ODR_DECODE) { @@ -237,6 +239,9 @@ static int yaz_srw_record(ODR o, xmlNodePtr pptr, Z_SRW_record *rec, char *spack = 0; xmlNodePtr ptr; +#ifdef Z_SRW_packed + rec->packing = 0; +#endif rec->recordSchema = 0; rec->recordData_buf = 0; rec->recordData_len = 0; @@ -250,15 +255,15 @@ static int yaz_srw_record(ODR o, xmlNodePtr pptr, Z_SRW_record *rec, for (ptr = pptr->children; ptr; ptr = ptr->next) { - if (match_xsd_string(ptr, "recordSchema", o, - &rec->recordSchema)) + if (yaz_match_xsd_string(ptr, "recordSchema", o, + &rec->recordSchema)) ; - else if (match_xsd_string(ptr, "recordPacking", o, &spack)) + else if (yaz_match_xsd_string(ptr, "recordPacking", o, &spack)) ; /* can't rely on it: in SRU 2.0 it's different semantics */ - else if (match_xsd_integer(ptr, "recordPosition", o, - &rec->recordPosition)) + else if (yaz_match_xsd_integer(ptr, "recordPosition", o, + &rec->recordPosition)) ; - else if (match_element(ptr, "recordData")) + else if (yaz_match_xsd_element(ptr, "recordData")) { /* we assume XML packing, if any element nodes exist below recordData. Unfortunately, in SRU 2.0 recordPacking @@ -269,26 +274,26 @@ static int yaz_srw_record(ODR o, xmlNodePtr pptr, Z_SRW_record *rec, break; if (p) { - match_xsd_XML_n2( + yaz_match_xsd_XML_n2( ptr, "recordData", o, &rec->recordData_buf, &rec->recordData_len, 1); rec->recordPacking = Z_SRW_recordPacking_XML; } else { - match_xsd_string_n( + yaz_match_xsd_string_n( ptr, "recordData", o, &rec->recordData_buf, &rec->recordData_len); rec->recordPacking = Z_SRW_recordPacking_string; } } - else if (match_xsd_XML_n(ptr, "extraRecordData", o, - &ex.extraRecordData_buf, - &ex.extraRecordData_len) ) + else if (yaz_match_xsd_XML_n(ptr, "extraRecordData", o, + &ex.extraRecordData_buf, + &ex.extraRecordData_len) ) ; else - match_xsd_string(ptr, "recordIdentifier", o, - &ex.recordIdentifier); + yaz_match_xsd_string(ptr, "recordIdentifier", o, + &ex.recordIdentifier); } if (ex.extraRecordData_buf || ex.recordIdentifier) { @@ -305,7 +310,12 @@ static int yaz_srw_record(ODR o, xmlNodePtr pptr, Z_SRW_record *rec, add_xsd_string(ptr, "recordSchema", rec->recordSchema); if (spack) - add_xsd_string(ptr, "recordPacking", spack); + { + if (version2) + add_xsd_string(ptr, "recordXMLEscaping", spack); + else + add_xsd_string(ptr, "recordPacking", spack); + } switch (pack) { case Z_SRW_recordPacking_string: @@ -339,7 +349,7 @@ static int yaz_srw_record(ODR o, xmlNodePtr pptr, Z_SRW_record *rec, static int yaz_srw_records(ODR o, xmlNodePtr pptr, Z_SRW_record **recs, Z_SRW_extra_record ***extra, - int *num, void *client_data, const char *ns) + int *num, void *client_data, int version2) { if (o->direction == ODR_DECODE) { @@ -361,7 +371,7 @@ static int yaz_srw_records(ODR o, xmlNodePtr pptr, Z_SRW_record **recs, if (ptr->type == XML_ELEMENT_NODE && !xmlStrcmp(ptr->name, BAD_CAST "record")) { - yaz_srw_record(o, ptr, *recs + i, *extra + i, client_data, ns); + yaz_srw_record(o, ptr, *recs + i, *extra + i, client_data, 0); i++; } } @@ -374,7 +384,7 @@ static int yaz_srw_records(ODR o, xmlNodePtr pptr, Z_SRW_record **recs, xmlNodePtr rptr = xmlNewChild(pptr, 0, BAD_CAST "record", 0); yaz_srw_record(o, rptr, (*recs)+i, (*extra ? *extra + i : 0), - client_data, ns); + client_data, version2); } } return 0; @@ -391,11 +401,12 @@ static int yaz_srw_version(ODR o, xmlNodePtr pptr, Z_SRW_recordVersion *rec, for (ptr = pptr->children; ptr; ptr = ptr->next) { - if (match_xsd_string(ptr, "versionType", o, - &rec->versionType)) + if (yaz_match_xsd_string(ptr, "versionType", o, + &rec->versionType)) ; else - match_xsd_string(ptr, "versionValue", o, &rec->versionValue); + yaz_match_xsd_string(ptr, "versionValue", o, + &rec->versionValue); } } else if (o->direction == ODR_ENCODE) @@ -484,14 +495,14 @@ static Z_FacetField *yaz_sru_proxy_decode_facet_field(ODR odr, xmlNodePtr ptr) list = yaz_use_attribute_create(odr, name); for (node = ptr->children; node; node = node->next) { - if (match_element(node, "facetvalue")) + if (yaz_match_xsd_element(node, "facetvalue")) num_terms++; } facet_field = facet_field_create(odr, list, num_terms); index = 0; for (node = ptr->children; node; node = node->next) { - if (match_element(node, "facetvalue")) + if (yaz_match_xsd_element(node, "facetvalue")) { facet_field_term_set(odr, facet_field, yaz_sru_proxy_get_facet_term_count(odr, node), @@ -509,7 +520,7 @@ static int yaz_sru_proxy_decode_facets(ODR o, xmlNodePtr root, for (ptr = root->children; ptr; ptr = ptr->next) { - if (match_element(ptr, "facets")) + if (yaz_match_xsd_element(ptr, "facets")) { xmlNodePtr node; Z_FacetList *facet_list; @@ -523,7 +534,7 @@ static int yaz_sru_proxy_decode_facets(ODR o, xmlNodePtr root, num_facets = 0; for (node = ptr->children; node; node= node->next) { - if (match_element(node, "facet")) + if (yaz_match_xsd_element(node, "facet")) { facet_list_field_set( o, facet_list, @@ -573,14 +584,14 @@ static int yaz_srw_decode_diagnostics(ODR o, xmlNodePtr pptr, (*recs)[i].message = 0; for (rptr = ptr->children; rptr; rptr = rptr->next) { - if (match_xsd_string(rptr, "uri", o, - &(*recs)[i].uri)) + if (yaz_match_xsd_string(rptr, "uri", o, &(*recs)[i].uri)) ; - else if (match_xsd_string(rptr, "details", o, - &(*recs)[i].details)) + else if (yaz_match_xsd_string(rptr, "details", o, + &(*recs)[i].details)) ; else - match_xsd_string(rptr, "message", o, &(*recs)[i].message); + yaz_match_xsd_string(rptr, "message", o, + &(*recs)[i].message); } i++; } @@ -666,16 +677,16 @@ static int yaz_srw_term(ODR o, xmlNodePtr pptr, Z_SRW_scanTerm *term, term->whereInList = 0; for (ptr = pptr->children; ptr; ptr = ptr->next) { - if (match_xsd_string(ptr, "value", o, &term->value)) + if (yaz_match_xsd_string(ptr, "value", o, &term->value)) ; - else if (match_xsd_integer(ptr, "numberOfRecords", o, - &term->numberOfRecords)) + else if (yaz_match_xsd_integer(ptr, "numberOfRecords", o, + &term->numberOfRecords)) ; - else if (match_xsd_string(ptr, "displayTerm", o, - &term->displayTerm)) + else if (yaz_match_xsd_string(ptr, "displayTerm", o, + &term->displayTerm)) ; else - match_xsd_string(ptr, "whereInList", o, &term->whereInList); + yaz_match_xsd_string(ptr, "whereInList", o, &term->whereInList); } } else if (o->direction == ODR_ENCODE) @@ -743,24 +754,28 @@ int yaz_srw_codec(ODR o, void * vptr, Z_SRW_PDU **handler_data, if (method->type != XML_ELEMENT_NODE) return -1; - *p = yaz_srw_get_core_v_1_1(o); + *p = yaz_srw_get_core_v_2_0(o); if (!xmlStrcmp(method->name, BAD_CAST "searchRetrieveRequest")) { xmlNodePtr ptr = method->children; Z_SRW_searchRetrieveRequest *req; + char *recordPacking = 0; + char *recordXMLEscaping = 0; + const char *facetLimit = 0; (*p)->which = Z_SRW_searchRetrieve_request; req = (*p)->u.request = (Z_SRW_searchRetrieveRequest *) odr_malloc(o, sizeof(*req)); - req->query_type = Z_SRW_query_type_cql; - req->query.cql = 0; + req->queryType = "cql"; + req->query = 0; req->sort_type = Z_SRW_sort_type_none; req->sort.none = 0; req->startRecord = 0; req->maximumRecords = 0; req->recordSchema = 0; req->recordPacking = 0; + req->packing = 0; req->recordXPath = 0; req->resultSetTTL = 0; req->stylesheet = 0; @@ -768,50 +783,69 @@ int yaz_srw_codec(ODR o, void * vptr, Z_SRW_PDU **handler_data, for (; ptr; ptr = ptr->next) { - if (match_xsd_string(ptr, "version", o, + if (yaz_match_xsd_string(ptr, "version", o, &(*p)->srw_version)) ; - else if (match_xsd_string(ptr, "query", o, - &req->query.cql)) - req->query_type = Z_SRW_query_type_cql; - else if (match_xsd_string(ptr, "pQuery", o, - &req->query.pqf)) - req->query_type = Z_SRW_query_type_pqf; - else if (match_xsd_string(ptr, "xQuery", o, - &req->query.xcql)) - req->query_type = Z_SRW_query_type_xcql; - else if (match_xsd_integer(ptr, "startRecord", o, + else if (yaz_match_xsd_string(ptr, "queryType", o, + &req->queryType)) + ; + else if (yaz_match_xsd_string(ptr, "query", o, + &req->query)) + ; + else if (yaz_match_xsd_string(ptr, "pQuery", o, + &req->query)) + req->queryType = "pqf"; + else if (yaz_match_xsd_string(ptr, "xQuery", o, + &req->query)) + req->queryType = "xcql"; + else if (yaz_match_xsd_integer(ptr, "startRecord", o, &req->startRecord)) ; - else if (match_xsd_integer(ptr, "maximumRecords", o, + else if (yaz_match_xsd_integer(ptr, "maximumRecords", o, &req->maximumRecords)) ; - else if (match_xsd_string(ptr, "recordPacking", o, - &req->recordPacking)) + else if (yaz_match_xsd_string(ptr, "recordPacking", o, + &recordPacking)) + ; + else if (yaz_match_xsd_string(ptr, "recordXMLEscaping", o, + &recordXMLEscaping)) ; - else if (match_xsd_string(ptr, "recordSchema", o, + else if (yaz_match_xsd_string(ptr, "recordSchema", o, &req->recordSchema)) ; - else if (match_xsd_string(ptr, "recordXPath", o, + else if (yaz_match_xsd_string(ptr, "recordXPath", o, &req->recordXPath)) ; - else if (match_xsd_integer(ptr, "resultSetTTL", o, + else if (yaz_match_xsd_integer(ptr, "resultSetTTL", o, &req->resultSetTTL)) ; - else if (match_xsd_string(ptr, "sortKeys", o, + else if (yaz_match_xsd_string(ptr, "sortKeys", o, &req->sort.sortKeys)) req->sort_type = Z_SRW_sort_type_sort; - else if (match_xsd_string(ptr, "stylesheet", o, + else if (yaz_match_xsd_string(ptr, "stylesheet", o, &req->stylesheet)) ; - else - match_xsd_string(ptr, "database", o, &req->database); + else if (yaz_match_xsd_string(ptr, "database", o, &req->database)) + ; + else if (yaz_match_xsd_string(ptr, "facetLimit", o, + (char**) &facetLimit)) + ; } - if (!req->query.cql && !req->query.pqf && !req->query.xcql) + if (!req->query) { /* should put proper diagnostic here */ return -1; } + if (!strcmp((*p)->srw_version, "2.0")) + { + req->recordPacking = recordXMLEscaping; + req->packing = recordPacking; + } + else + { + req->recordPacking = recordPacking; + } + yaz_sru_facet_request(o, &req->facetList, &facetLimit); } else if (!xmlStrcmp(method->name, BAD_CAST "searchRetrieveResponse")) { @@ -823,6 +857,7 @@ int yaz_srw_codec(ODR o, void * vptr, Z_SRW_PDU **handler_data, odr_malloc(o, sizeof(*res)); res->numberOfRecords = 0; + res->resultCountPrecision = 0; res->resultSetId = 0; res->resultSetIdleTime = 0; res->records = 0; @@ -835,35 +870,43 @@ int yaz_srw_codec(ODR o, void * vptr, Z_SRW_PDU **handler_data, for (; ptr; ptr = ptr->next) { - if (match_xsd_string(ptr, "version", o, + if (yaz_match_xsd_string(ptr, "version", o, &(*p)->srw_version)) ; - else if (match_xsd_XML_n(ptr, "extraResponseData", o, + else if (yaz_match_xsd_XML_n(ptr, "extraResponseData", o, &(*p)->extraResponseData_buf, &(*p)->extraResponseData_len)) ; - else if (match_xsd_integer(ptr, "numberOfRecords", o, + else if (yaz_match_xsd_integer(ptr, "numberOfRecords", o, &res->numberOfRecords)) ; - else if (match_xsd_string(ptr, "resultSetId", o, + else if (yaz_match_xsd_string(ptr, "resultCountPrecision", o, + &res->resultCountPrecision)) + ; + else if (yaz_match_xsd_string(ptr, "resultSetId", o, &res->resultSetId)) ; - else if (match_xsd_integer(ptr, "resultSetIdleTime", o, + else if (yaz_match_xsd_integer(ptr, "resultSetIdleTime", o, &res->resultSetIdleTime)) ; - else if (match_element(ptr, "records")) + else if (yaz_match_xsd_integer(ptr, "resultSetTTL", o, + &res->resultSetIdleTime)) + ; + else if (yaz_match_xsd_element(ptr, "records")) yaz_srw_records(o, ptr, &res->records, &res->extra_records, - &res->num_records, client_data, ns); - else if (match_xsd_integer(ptr, "nextRecordPosition", o, + &res->num_records, client_data, 0); + else if (yaz_match_xsd_integer(ptr, "nextRecordPosition", o, &res->nextRecordPosition)) ; - else if (match_element(ptr, "diagnostics")) + else if (yaz_match_xsd_element(ptr, "diagnostics")) yaz_srw_diagnostics(o, ptr, &res->diagnostics, &res->num_diagnostics, client_data, ns); - else if (match_element(ptr, "facet_analysis")) + else if (yaz_match_xsd_element(ptr, "facet_analysis")) yaz_sru_proxy_decode_facets(o, ptr, &res->facetList); + else if (yaz_match_xsd_element(ptr, "facetedResults")) + yaz_sru_facet_response(o, &res->facetList, ptr); } } else if (!xmlStrcmp(method->name, BAD_CAST "explainRequest")) @@ -875,25 +918,26 @@ int yaz_srw_codec(ODR o, void * vptr, Z_SRW_PDU **handler_data, req = (*p)->u.explain_request = (Z_SRW_explainRequest *) odr_malloc(o, sizeof(*req)); req->recordPacking = 0; + req->packing = 0; req->database = 0; req->stylesheet = 0; for (; ptr; ptr = ptr->next) { - if (match_xsd_string(ptr, "version", o, + if (yaz_match_xsd_string(ptr, "version", o, &(*p)->srw_version)) ; - else if (match_xsd_XML_n(ptr, "extraResponseData", o, + else if (yaz_match_xsd_XML_n(ptr, "extraResponseData", o, &(*p)->extraResponseData_buf, &(*p)->extraResponseData_len)) ; - else if (match_xsd_string(ptr, "stylesheet", o, + else if (yaz_match_xsd_string(ptr, "stylesheet", o, &req->stylesheet)) ; - else if (match_xsd_string(ptr, "recordPacking", o, + else if (yaz_match_xsd_string(ptr, "recordPacking", o, &req->recordPacking)) ; else - match_xsd_string(ptr, "database", o, &req->database); + yaz_match_xsd_string(ptr, "database", o, &req->database); } } else if (!xmlStrcmp(method->name, BAD_CAST "explainResponse")) @@ -913,17 +957,17 @@ int yaz_srw_codec(ODR o, void * vptr, Z_SRW_PDU **handler_data, for (; ptr; ptr = ptr->next) { - if (match_xsd_string(ptr, "version", o, + if (yaz_match_xsd_string(ptr, "version", o, &(*p)->srw_version)) ; - else if (match_xsd_XML_n(ptr, "extraResponseData", o, + else if (yaz_match_xsd_XML_n(ptr, "extraResponseData", o, &(*p)->extraResponseData_buf, &(*p)->extraResponseData_len)) ; - else if (match_element(ptr, "record")) + else if (yaz_match_xsd_element(ptr, "record")) yaz_srw_record(o, ptr, &res->record, &res->extra_record, - client_data, ns); - else if (match_element(ptr, "diagnostics")) + client_data, 0); + else if (yaz_match_xsd_element(ptr, "diagnostics")) yaz_srw_diagnostics(o, ptr, &res->diagnostics, &res->num_diagnostics, client_data, ns); @@ -938,8 +982,8 @@ int yaz_srw_codec(ODR o, void * vptr, Z_SRW_PDU **handler_data, (*p)->which = Z_SRW_scan_request; req = (*p)->u.scan_request = (Z_SRW_scanRequest *) odr_malloc(o, sizeof(*req)); - req->query_type = Z_SRW_query_type_cql; - req->scanClause.cql = 0; + req->queryType = "cql"; + req->scanClause = 0; req->responsePosition = 0; req->maximumTerms = 0; req->stylesheet = 0; @@ -947,32 +991,32 @@ int yaz_srw_codec(ODR o, void * vptr, Z_SRW_PDU **handler_data, for (; ptr; ptr = ptr->next) { - if (match_xsd_string(ptr, "version", o, + if (yaz_match_xsd_string(ptr, "version", o, &(*p)->srw_version)) ; - else if (match_xsd_XML_n(ptr, "extraResponseData", o, + else if (yaz_match_xsd_XML_n(ptr, "extraResponseData", o, &(*p)->extraResponseData_buf, &(*p)->extraResponseData_len)) ; - else if (match_xsd_string(ptr, "scanClause", o, - &req->scanClause.cql)) + else if (yaz_match_xsd_string(ptr, "scanClause", o, + &req->scanClause)) ; - else if (match_xsd_string(ptr, "pScanClause", o, - &req->scanClause.pqf)) + else if (yaz_match_xsd_string(ptr, "pScanClause", o, + &req->scanClause)) { - req->query_type = Z_SRW_query_type_pqf; + req->queryType = "pqf"; } - else if (match_xsd_integer(ptr, "responsePosition", o, + else if (yaz_match_xsd_integer(ptr, "responsePosition", o, &req->responsePosition)) ; - else if (match_xsd_integer(ptr, "maximumTerms", o, + else if (yaz_match_xsd_integer(ptr, "maximumTerms", o, &req->maximumTerms)) ; - else if (match_xsd_string(ptr, "stylesheet", o, + else if (yaz_match_xsd_string(ptr, "stylesheet", o, &req->stylesheet)) ; else - match_xsd_string(ptr, "database", o, &req->database); + yaz_match_xsd_string(ptr, "database", o, &req->database); } } else if (!xmlStrcmp(method->name, BAD_CAST "scanResponse")) @@ -990,18 +1034,18 @@ int yaz_srw_codec(ODR o, void * vptr, Z_SRW_PDU **handler_data, for (; ptr; ptr = ptr->next) { - if (match_xsd_string(ptr, "version", o, + if (yaz_match_xsd_string(ptr, "version", o, &(*p)->srw_version)) ; - else if (match_xsd_XML_n(ptr, "extraResponseData", o, + else if (yaz_match_xsd_XML_n(ptr, "extraResponseData", o, &(*p)->extraResponseData_buf, &(*p)->extraResponseData_len)) ; - else if (match_element(ptr, "terms")) + else if (yaz_match_xsd_element(ptr, "terms")) yaz_srw_terms(o, ptr, &res->terms, &res->num_terms, client_data, ns); - else if (match_element(ptr, "diagnostics")) + else if (yaz_match_xsd_element(ptr, "diagnostics")) yaz_srw_diagnostics(o, ptr, &res->diagnostics, &res->num_diagnostics, client_data, ns); @@ -1021,31 +1065,43 @@ int yaz_srw_codec(ODR o, void * vptr, Z_SRW_PDU **handler_data, Z_SRW_PDU **p = handler_data; xmlNsPtr ns_srw; xmlNodePtr ptr = 0; - + int version2 = !(*p)->srw_version || + strcmp((*p)->srw_version, "2.") > 0; if ((*p)->which == Z_SRW_searchRetrieve_request) { Z_SRW_searchRetrieveRequest *req = (*p)->u.request; + const char *queryType = req->queryType; + if (version2) + ns = "http://docs.oasis-open.org/ns/search-ws/sruRequest"; ptr = xmlNewChild(pptr, 0, BAD_CAST "searchRetrieveRequest", 0); ns_srw = xmlNewNs(ptr, BAD_CAST ns, BAD_CAST "zs"); xmlSetNs(ptr, ns_srw); - if ((*p)->srw_version) - add_xsd_string(ptr, "version", (*p)->srw_version); - switch (req->query_type) + add_xsd_string(ptr, "version", (*p)->srw_version); + if (version2) { - case Z_SRW_query_type_cql: - add_xsd_string(ptr, "query", req->query.cql); - break; - case Z_SRW_query_type_xcql: - add_xsd_string(ptr, "xQuery", req->query.xcql); - break; - case Z_SRW_query_type_pqf: - add_xsd_string(ptr, "pQuery", req->query.pqf); - break; + if (queryType) + add_xsd_string(ptr, "queryType", queryType); + add_xsd_string(ptr, "query", req->query); + } + else + { + if (!queryType || !strcmp(queryType, "cql")) + add_xsd_string(ptr, "query", req->query); + else if (!strcmp(queryType, "xcql")) + add_xsd_string(ptr, "xQuery", req->query); + else if (!strcmp(queryType, "pqf")) + add_xsd_string(ptr, "pQuery", req->query); } add_xsd_integer(ptr, "startRecord", req->startRecord); add_xsd_integer(ptr, "maximumRecords", req->maximumRecords); - add_xsd_string(ptr, "recordPacking", req->recordPacking); + if (version2) + { + add_xsd_string(ptr, "recordXMLEscaping", req->recordPacking); + add_xsd_string(ptr, "recordPacking", req->packing); + } + else + add_xsd_string(ptr, "recordPacking", req->recordPacking); add_xsd_string(ptr, "recordSchema", req->recordSchema); add_xsd_string(ptr, "recordXPath", req->recordXPath); add_xsd_integer(ptr, "resultSetTTL", req->resultSetTTL); @@ -1062,25 +1118,33 @@ int yaz_srw_codec(ODR o, void * vptr, Z_SRW_PDU **handler_data, } add_xsd_string(ptr, "stylesheet", req->stylesheet); add_xsd_string(ptr, "database", req->database); + { + const char *limit = 0; + yaz_sru_facet_request(o, &req->facetList, &limit); + add_xsd_string(ptr, "facetLimit", limit); + } } else if ((*p)->which == Z_SRW_searchRetrieve_response) { Z_SRW_searchRetrieveResponse *res = (*p)->u.response; + if (version2) + ns = "http://docs.oasis-open.org/ns/search-ws/sruResponse"; ptr = xmlNewChild(pptr, 0, BAD_CAST "searchRetrieveResponse", 0); ns_srw = xmlNewNs(ptr, BAD_CAST ns, BAD_CAST "zs"); xmlSetNs(ptr, ns_srw); - if ((*p)->srw_version) - add_xsd_string(ptr, "version", (*p)->srw_version); + add_xsd_string(ptr, "version", (*p)->srw_version); add_xsd_integer(ptr, "numberOfRecords", res->numberOfRecords); add_xsd_string(ptr, "resultSetId", res->resultSetId); - add_xsd_integer(ptr, "resultSetIdleTime", res->resultSetIdleTime); + add_xsd_integer(ptr, + version2 ? "resultSetTTL" : "resultSetIdleTime" , + res->resultSetIdleTime); if (res->num_records) { xmlNodePtr rptr = xmlNewChild(ptr, 0, BAD_CAST "records", 0); yaz_srw_records(o, rptr, &res->records, &res->extra_records, &res->num_records, - client_data, ns); + client_data, version2); } add_xsd_integer(ptr, "nextRecordPosition", res->nextRecordPosition); @@ -1091,6 +1155,10 @@ int yaz_srw_codec(ODR o, void * vptr, Z_SRW_PDU **handler_data, yaz_srw_diagnostics(o, rptr, &res->diagnostics, &res->num_diagnostics, client_data, ns); } + if (res->resultCountPrecision) + add_xsd_string(ptr, "resultCountPrecision", + res->resultCountPrecision); + yaz_sru_facet_response(o, &res->facetList, ptr); } else if ((*p)->which == Z_SRW_explain_request) { @@ -1100,7 +1168,13 @@ int yaz_srw_codec(ODR o, void * vptr, Z_SRW_PDU **handler_data, xmlSetNs(ptr, ns_srw); add_xsd_string(ptr, "version", (*p)->srw_version); - add_xsd_string(ptr, "recordPacking", req->recordPacking); + if (version2) + { + add_xsd_string(ptr, "recordXMLEscaping", req->recordPacking); + add_xsd_string(ptr, "recordPacking", req->packing); + } + else + add_xsd_string(ptr, "recordPacking", req->recordPacking); add_xsd_string(ptr, "stylesheet", req->stylesheet); add_xsd_string(ptr, "database", req->database); } @@ -1116,7 +1190,7 @@ int yaz_srw_codec(ODR o, void * vptr, Z_SRW_PDU **handler_data, { xmlNodePtr ptr1 = xmlNewChild(ptr, 0, BAD_CAST "record", 0); yaz_srw_record(o, ptr1, &res->record, &res->extra_record, - client_data, ns); + client_data, version2); } if (res->num_diagnostics) { @@ -1129,19 +1203,27 @@ int yaz_srw_codec(ODR o, void * vptr, Z_SRW_PDU **handler_data, else if ((*p)->which == Z_SRW_scan_request) { Z_SRW_scanRequest *req = (*p)->u.scan_request; + const char *queryType = req->queryType; + if (version2) + ns = "http://docs.oasis-open.org/ns/search-ws/scan"; ptr = xmlNewChild(pptr, 0, BAD_CAST "scanRequest", 0); ns_srw = xmlNewNs(ptr, BAD_CAST ns, BAD_CAST "zs"); xmlSetNs(ptr, ns_srw); add_xsd_string(ptr, "version", (*p)->srw_version); - switch (req->query_type) + + if (version2) { - case Z_SRW_query_type_cql: - add_xsd_string(ptr, "scanClause", req->scanClause.cql); - break; - case Z_SRW_query_type_pqf: - add_xsd_string(ptr, "pScanClause", req->scanClause.pqf); - break; + if (queryType && strcmp(queryType, "cql")) + add_xsd_string(ptr, "queryType", queryType); + add_xsd_string(ptr, "scanClause", req->scanClause); + } + else + { + if (!queryType || !strcmp(queryType, "cql")) + add_xsd_string(ptr, "scanClause", req->scanClause); + else if (!strcmp(queryType, "pqf")) + add_xsd_string(ptr, "pScanClause", req->scanClause); } add_xsd_integer(ptr, "responsePosition", req->responsePosition); add_xsd_integer(ptr, "maximumTerms", req->maximumTerms); @@ -1151,12 +1233,13 @@ int yaz_srw_codec(ODR o, void * vptr, Z_SRW_PDU **handler_data, else if ((*p)->which == Z_SRW_scan_response) { Z_SRW_scanResponse *res = (*p)->u.scan_response; + if (version2) + ns = "http://docs.oasis-open.org/ns/search-ws/scan"; ptr = xmlNewChild(pptr, 0, BAD_CAST "scanResponse", 0); ns_srw = xmlNewNs(ptr, BAD_CAST ns, BAD_CAST "zs"); xmlSetNs(ptr, ns_srw); add_xsd_string(ptr, "version", (*p)->srw_version); - if (res->num_terms) { xmlNodePtr rptr = xmlNewChild(ptr, 0, BAD_CAST "terms", 0); @@ -1201,7 +1284,7 @@ int yaz_ucp_codec(ODR o, void * vptr, Z_SRW_PDU **handler_data, if (method->type != XML_ELEMENT_NODE) return -1; - *p = yaz_srw_get_core_v_1_1(o); + *p = yaz_srw_get_core_v_2_0(o); if (!xmlStrcmp(method->name, BAD_CAST "updateRequest")) { @@ -1225,10 +1308,10 @@ int yaz_ucp_codec(ODR o, void * vptr, Z_SRW_PDU **handler_data, for (; ptr; ptr = ptr->next) { - if (match_xsd_string(ptr, "version", o, + if (yaz_match_xsd_string(ptr, "version", o, &(*p)->srw_version)) ; - else if (match_xsd_string(ptr, "action", o, + else if (yaz_match_xsd_string(ptr, "action", o, &oper)){ if (oper) { @@ -1240,24 +1323,24 @@ int yaz_ucp_codec(ODR o, void * vptr, Z_SRW_PDU **handler_data, req->operation = "insert"; } } - else if (match_xsd_string(ptr, "recordIdentifier", o, + else if (yaz_match_xsd_string(ptr, "recordIdentifier", o, &req->recordId)) ; - else if (match_element(ptr, "recordVersions" ) ) + else if (yaz_match_xsd_element(ptr, "recordVersions" ) ) yaz_srw_versions( o, ptr, &req->recordVersions, &req->num_recordVersions, client_data, ns_ucp_str); - else if (match_element(ptr, "record")) + else if (yaz_match_xsd_element(ptr, "record")) { req->record = yaz_srw_get_record(o); yaz_srw_record(o, ptr, req->record, &req->extra_record, - client_data, ns_ucp_str); + client_data, 0); } - else if (match_xsd_string(ptr, "stylesheet", o, + else if (yaz_match_xsd_string(ptr, "stylesheet", o, &req->stylesheet)) ; else - match_xsd_string(ptr, "database", o, &req->database); + yaz_match_xsd_string(ptr, "database", o, &req->database); } } else if (!xmlStrcmp(method->name, BAD_CAST "updateResponse")) @@ -1282,26 +1365,26 @@ int yaz_ucp_codec(ODR o, void * vptr, Z_SRW_PDU **handler_data, for (; ptr; ptr = ptr->next) { - if (match_xsd_string(ptr, "version", o, + if (yaz_match_xsd_string(ptr, "version", o, &(*p)->srw_version)) ; - else if (match_xsd_string(ptr, "operationStatus", o, + else if (yaz_match_xsd_string(ptr, "operationStatus", o, &res->operationStatus )) ; - else if (match_xsd_string(ptr, "recordIdentifier", o, + else if (yaz_match_xsd_string(ptr, "recordIdentifier", o, &res->recordId)) ; - else if (match_element(ptr, "recordVersions" )) + else if (yaz_match_xsd_element(ptr, "recordVersions" )) yaz_srw_versions(o, ptr, &res->recordVersions, &res->num_recordVersions, client_data, ns_ucp_str); - else if (match_element(ptr, "record")) + else if (yaz_match_xsd_element(ptr, "record")) { res->record = yaz_srw_get_record(o); yaz_srw_record(o, ptr, res->record, &res->extra_record, - client_data, ns_ucp_str); + client_data, 0); } - else if (match_element(ptr, "diagnostics")) + else if (yaz_match_xsd_element(ptr, "diagnostics")) yaz_srw_diagnostics(o, ptr, &res->diagnostics, &res->num_diagnostics, client_data, ns_ucp_str); @@ -1344,7 +1427,7 @@ int yaz_ucp_codec(ODR o, void * vptr, Z_SRW_PDU **handler_data, xmlNodePtr rptr = xmlNewChild(ptr, 0, BAD_CAST "record", 0); xmlSetNs(rptr, ns_srw); yaz_srw_record(o, rptr, req->record, &req->extra_record, - client_data, ns_ucp_str); + client_data, 0); } if (req->extraRequestData_len) { @@ -1376,7 +1459,7 @@ int yaz_ucp_codec(ODR o, void * vptr, Z_SRW_PDU **handler_data, xmlNodePtr rptr = xmlNewChild(ptr, 0, BAD_CAST "record", 0); xmlSetNs(rptr, ns_srw); yaz_srw_record(o, rptr, res->record, &res->extra_record, - client_data, ns_ucp_str); + client_data, 0); } if (res->num_diagnostics) {