X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Fsrw.c;h=8e3196bf275babd63c0fe274bcac93ad025eb460;hb=0d16731ebba3c4988791de9d770eccff725f5bda;hp=69df44ac154bb624128ec3debb54d5ab862073d4;hpb=98a78d8028fa4835369006de527353d7e33f1ef9;p=yaz-moved-to-github.git diff --git a/src/srw.c b/src/srw.c index 69df44a..8e3196b 100644 --- a/src/srw.c +++ b/src/srw.c @@ -1,5 +1,5 @@ /* This file is part of the YAZ toolkit. - * Copyright (C) 1995-2011 Index Data + * Copyright (C) 1995-2012 Index Data * See the file LICENSE for details. */ /** @@ -164,11 +164,12 @@ static int match_xsd_XML_n2(xmlNodePtr ptr, const char *elem, ODR o, } if (no_root_nodes != 1 && fixup_root) { + /* does not appear to be an XML document. Make it so */ xmlBufferAddHead(buf, (const xmlChar *) "", -1); xmlBufferAdd(buf, (const xmlChar *) "", -1); } - *val = (char *) odr_malloc(o, buf->use+1); - memcpy (*val, buf->content, buf->use); + *val = (char *) odr_malloc(o, buf->use + 1); + memcpy(*val, buf->content, buf->use); (*val)[buf->use] = '\0'; if (len) @@ -223,7 +224,7 @@ char *yaz_negotiate_sru_version(char *input_ver) if (!strcmp(input_ver, "1.1")) return "1.1"; - return "1.2"; /* our latest supported version */ + return "1.2"; /* our latest supported version */ } static int yaz_srw_record(ODR o, xmlNodePtr pptr, Z_SRW_record *rec, @@ -235,9 +236,7 @@ static int yaz_srw_record(ODR o, xmlNodePtr pptr, Z_SRW_record *rec, Z_SRW_extra_record ex; char *spack = 0; - int pack = Z_SRW_recordPacking_string; xmlNodePtr ptr; - xmlNodePtr data_ptr = 0; rec->recordSchema = 0; rec->recordData_buf = 0; rec->recordData_len = 0; @@ -255,20 +254,33 @@ static int yaz_srw_record(ODR o, xmlNodePtr pptr, Z_SRW_record *rec, &rec->recordSchema)) ; else if (match_xsd_string(ptr, "recordPacking", o, &spack)) - { - if (spack) - pack = yaz_srw_str_to_pack(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 (match_element(ptr, "recordData")) { - /* save position of Data until after the loop - then we will know the packing (hopefully), and - unpacking is done once - */ - data_ptr = ptr; + /* we assume XML packing, if any element nodes exist below + recordData. Unfortunately, in SRU 2.0 recordPacking + means something different */ + xmlNode *p = ptr->children; + for (; p; p = p->next) + if (p->type == XML_ELEMENT_NODE) + break; + if (p) + { + 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( + 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, @@ -278,27 +290,6 @@ static int yaz_srw_record(ODR o, xmlNodePtr pptr, Z_SRW_record *rec, match_xsd_string(ptr, "recordIdentifier", o, &ex.recordIdentifier); } - if (data_ptr) - { - switch(pack) - { - case Z_SRW_recordPacking_XML: - match_xsd_XML_n2(data_ptr, "recordData", o, - &rec->recordData_buf, &rec->recordData_len, 1); - break; - case Z_SRW_recordPacking_URL: - /* just store it as a string. - leave it to the backend to collect the document */ - match_xsd_string_n(data_ptr, "recordData", o, - &rec->recordData_buf, &rec->recordData_len); - break; - case Z_SRW_recordPacking_string: - match_xsd_string_n(data_ptr, "recordData", o, - &rec->recordData_buf, &rec->recordData_len); - break; - } - } - rec->recordPacking = pack; if (ex.extraRecordData_buf || ex.recordIdentifier) { *extra = (Z_SRW_extra_record *) @@ -315,7 +306,7 @@ 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); - switch(pack) + switch (pack) { case Z_SRW_recordPacking_string: add_xsd_string_n(ptr, "recordData", rec->recordData_buf, @@ -532,8 +523,11 @@ 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")) { - facet_list_field_set(o, facet_list, yaz_sru_proxy_decode_facet_field(o, node), num_facets); + if (match_element(node, "facet")) + { + facet_list_field_set( + o, facet_list, + yaz_sru_proxy_decode_facet_field(o, node), num_facets); num_facets++; } } @@ -837,6 +831,7 @@ int yaz_srw_codec(ODR o, void * vptr, Z_SRW_PDU **handler_data, res->num_diagnostics = 0; res->nextRecordPosition = 0; res->facetList = 0; + res->suggestions = 0; for (; ptr; ptr = ptr->next) { @@ -1036,7 +1031,7 @@ int yaz_srw_codec(ODR o, void * vptr, Z_SRW_PDU **handler_data, if ((*p)->srw_version) add_xsd_string(ptr, "version", (*p)->srw_version); - switch(req->query_type) + switch (req->query_type) { case Z_SRW_query_type_cql: add_xsd_string(ptr, "query", req->query.cql); @@ -1054,7 +1049,7 @@ int yaz_srw_codec(ODR o, void * vptr, Z_SRW_PDU **handler_data, add_xsd_string(ptr, "recordSchema", req->recordSchema); add_xsd_string(ptr, "recordXPath", req->recordXPath); add_xsd_integer(ptr, "resultSetTTL", req->resultSetTTL); - switch(req->sort_type) + switch (req->sort_type) { case Z_SRW_sort_type_none: break; @@ -1139,7 +1134,7 @@ 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); - switch(req->query_type) + switch (req->query_type) { case Z_SRW_query_type_cql: add_xsd_string(ptr, "scanClause", req->scanClause.cql); @@ -1235,12 +1230,13 @@ int yaz_ucp_codec(ODR o, void * vptr, Z_SRW_PDU **handler_data, ; else if (match_xsd_string(ptr, "action", o, &oper)){ - if ( oper ){ - if ( !strcmp(oper, "info:srw/action/1/delete")) + if (oper) + { + if (!strcmp(oper, "info:srw/action/1/delete")) req->operation = "delete"; else if (!strcmp(oper,"info:srw/action/1/replace" )) req->operation = "replace"; - else if ( !strcmp( oper, "info:srw/action/1/create")) + else if (!strcmp(oper, "info:srw/action/1/create")) req->operation = "insert"; } } @@ -1328,7 +1324,6 @@ int yaz_ucp_codec(ODR o, void * vptr, Z_SRW_PDU **handler_data, Z_SRW_PDU **p = handler_data; xmlNsPtr ns_ucp, ns_srw; - if ((*p)->which == Z_SRW_update_request) { Z_SRW_updateRequest *req = (*p)->u.update_request; @@ -1401,7 +1396,6 @@ int yaz_ucp_codec(ODR o, void * vptr, Z_SRW_PDU **handler_data, } else return -1; - } return 0; }