X-Git-Url: http://jsfdemo.indexdata.com/?a=blobdiff_plain;f=src%2Fsrw.c;h=2cc0c7d458001b4ec7fd90f0d20768ba4a0e1071;hb=799ea46466fc7433ce75d7c66d796b5a0997f59c;hp=7a3440f1b50edfd3b0123ddb6d9d6c720bb6be30;hpb=5242cb5a8634bfa38b9333ff7f903e718ac6e292;p=yaz-moved-to-github.git diff --git a/src/srw.c b/src/srw.c index 7a3440f..2cc0c7d 100644 --- a/src/srw.c +++ b/src/srw.c @@ -1,5 +1,5 @@ /* This file is part of the YAZ toolkit. - * Copyright (C) 1995-2012 Index Data + * Copyright (C) 1995-2013 Index Data * See the file LICENSE for details. */ /** @@ -220,16 +220,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) { if (o->direction == ODR_DECODE) { @@ -237,6 +240,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; @@ -339,7 +345,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) { if (o->direction == ODR_DECODE) { @@ -361,7 +367,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); i++; } } @@ -374,7 +380,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); } } return 0; @@ -469,7 +475,7 @@ Z_FacetTerm *yaz_sru_proxy_get_facet_term_count(ODR odr, xmlNodePtr node) facet_term = facet_term_create_cstr(odr, wrbuf_cstr(wrbuf), freq); wrbuf_destroy(wrbuf); return facet_term; -}; +} static Z_FacetField *yaz_sru_proxy_decode_facet_field(ODR odr, xmlNodePtr ptr) { @@ -743,7 +749,7 @@ 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")) { @@ -753,14 +759,15 @@ int yaz_srw_codec(ODR o, void * vptr, Z_SRW_PDU **handler_data, (*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; @@ -771,15 +778,18 @@ int yaz_srw_codec(ODR o, void * vptr, Z_SRW_PDU **handler_data, if (match_xsd_string(ptr, "version", o, &(*p)->srw_version)) ; + else if (match_xsd_string(ptr, "queryType", o, + &req->queryType)) + ; else if (match_xsd_string(ptr, "query", o, - &req->query.cql)) - req->query_type = Z_SRW_query_type_cql; + &req->query)) + ; else if (match_xsd_string(ptr, "pQuery", o, - &req->query.pqf)) - req->query_type = Z_SRW_query_type_pqf; + &req->query)) + req->queryType = "pqf"; else if (match_xsd_string(ptr, "xQuery", o, - &req->query.xcql)) - req->query_type = Z_SRW_query_type_xcql; + &req->query)) + req->queryType = "xcql"; else if (match_xsd_integer(ptr, "startRecord", o, &req->startRecord)) ; @@ -807,7 +817,7 @@ int yaz_srw_codec(ODR o, void * vptr, Z_SRW_PDU **handler_data, else match_xsd_string(ptr, "database", o, &req->database); } - if (!req->query.cql && !req->query.pqf && !req->query.xcql) + if (!req->query) { /* should put proper diagnostic here */ return -1; @@ -854,7 +864,7 @@ int yaz_srw_codec(ODR o, void * vptr, Z_SRW_PDU **handler_data, else if (match_element(ptr, "records")) yaz_srw_records(o, ptr, &res->records, &res->extra_records, - &res->num_records, client_data, ns); + &res->num_records, client_data); else if (match_xsd_integer(ptr, "nextRecordPosition", o, &res->nextRecordPosition)) ; @@ -875,6 +885,7 @@ 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) @@ -922,7 +933,7 @@ int yaz_srw_codec(ODR o, void * vptr, Z_SRW_PDU **handler_data, ; else if (match_element(ptr, "record")) yaz_srw_record(o, ptr, &res->record, &res->extra_record, - client_data, ns); + client_data); else if (match_element(ptr, "diagnostics")) yaz_srw_diagnostics(o, ptr, &res->diagnostics, &res->num_diagnostics, @@ -938,8 +949,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; @@ -955,12 +966,12 @@ int yaz_srw_codec(ODR o, void * vptr, Z_SRW_PDU **handler_data, &(*p)->extraResponseData_len)) ; else if (match_xsd_string(ptr, "scanClause", o, - &req->scanClause.cql)) + &req->scanClause)) ; else if (match_xsd_string(ptr, "pScanClause", o, - &req->scanClause.pqf)) + &req->scanClause)) { - req->query_type = Z_SRW_query_type_pqf; + req->queryType = "pqf"; } else if (match_xsd_integer(ptr, "responsePosition", o, &req->responsePosition)) @@ -1021,27 +1032,35 @@ 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) + if (!version2) add_xsd_string(ptr, "version", (*p)->srw_version); - switch (req->query_type) + + 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); @@ -1066,11 +1085,13 @@ int yaz_srw_codec(ODR o, void * vptr, Z_SRW_PDU **handler_data, 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) + if (!version2) add_xsd_string(ptr, "version", (*p)->srw_version); add_xsd_integer(ptr, "numberOfRecords", res->numberOfRecords); add_xsd_string(ptr, "resultSetId", res->resultSetId); @@ -1080,7 +1101,7 @@ int yaz_srw_codec(ODR o, void * vptr, Z_SRW_PDU **handler_data, 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); } add_xsd_integer(ptr, "nextRecordPosition", res->nextRecordPosition); @@ -1099,7 +1120,8 @@ int yaz_srw_codec(ODR o, void * vptr, Z_SRW_PDU **handler_data, ns_srw = xmlNewNs(ptr, BAD_CAST ns, BAD_CAST "zs"); xmlSetNs(ptr, ns_srw); - add_xsd_string(ptr, "version", (*p)->srw_version); + if (!version2) + add_xsd_string(ptr, "version", (*p)->srw_version); add_xsd_string(ptr, "recordPacking", req->recordPacking); add_xsd_string(ptr, "stylesheet", req->stylesheet); add_xsd_string(ptr, "database", req->database); @@ -1116,7 +1138,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); } if (res->num_diagnostics) { @@ -1129,19 +1151,28 @@ 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) + add_xsd_string(ptr, "version", (*p)->srw_version); + + if (strcmp((*p)->srw_version, "2.") > 0) { - 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,11 +1182,14 @@ 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 (!version2) + add_xsd_string(ptr, "version", (*p)->srw_version); if (res->num_terms) { @@ -1201,7 +1235,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")) { @@ -1251,7 +1285,7 @@ int yaz_ucp_codec(ODR o, void * vptr, Z_SRW_PDU **handler_data, { req->record = yaz_srw_get_record(o); yaz_srw_record(o, ptr, req->record, &req->extra_record, - client_data, ns_ucp_str); + client_data); } else if (match_xsd_string(ptr, "stylesheet", o, &req->stylesheet)) @@ -1299,7 +1333,7 @@ int yaz_ucp_codec(ODR o, void * vptr, Z_SRW_PDU **handler_data, { res->record = yaz_srw_get_record(o); yaz_srw_record(o, ptr, res->record, &res->extra_record, - client_data, ns_ucp_str); + client_data); } else if (match_element(ptr, "diagnostics")) yaz_srw_diagnostics(o, ptr, &res->diagnostics, @@ -1344,7 +1378,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); } if (req->extraRequestData_len) { @@ -1376,7 +1410,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); } if (res->num_diagnostics) {