From: Adam Dickmeiss Date: Thu, 10 Jul 2014 13:19:38 +0000 (+0200) Subject: echo extra args as well YAZ-776 X-Git-Tag: v5.3.0~3 X-Git-Url: http://jsfdemo.indexdata.com/cgi-bin?a=commitdiff_plain;h=20fefe985756693f69f2fedef8deaeb686034b8d;p=yaz-moved-to-github.git echo extra args as well YAZ-776 --- diff --git a/src/srw.c b/src/srw.c index f7f2107..31c1418 100644 --- a/src/srw.c +++ b/src/srw.c @@ -554,6 +554,30 @@ static int yaz_srw_terms(ODR o, xmlNodePtr pptr, Z_SRW_scanTerm **terms, return 0; } +static void encode_echoed_args(xmlNodePtr ptr, Z_SRW_PDU *p, const char *name) +{ + Z_SRW_extra_arg *ea = p->extra_args; + if (ea) + { + xmlNode *p1 = xmlNewChild(ptr, 0, BAD_CAST name, 0); + xmlNode *p2 = 0; + for (; ea; ea = ea->next) + { + if (ea->name && ea->name[0] == 'x' && ea->name[1] == '-') + { + /* not really according to XSD as of July 2014 */ + if (!p2) + p2 = xmlNewChild(p1, 0, + BAD_CAST "extraRequestData", 0); + /* skip +2: "x-" in element */ + add_xsd_string(p2, ea->name + 2, ea->value); + } + else + add_xsd_string(p1, ea->name, ea->value); + } + } +} + int yaz_srw_codec(ODR o, void * vptr, Z_SRW_PDU **handler_data, void *client_data, const char *ns) { @@ -985,16 +1009,7 @@ int yaz_srw_codec(ODR o, void * vptr, Z_SRW_PDU **handler_data, } add_xsd_integer(ptr, "nextRecordPosition", res->nextRecordPosition); - if ((*p)->extra_args) - { - xmlNode *p1 = - xmlNewChild(ptr, 0, BAD_CAST "echoedSearchRetrieveRequest", - 0); - Z_SRW_extra_arg *ea = (*p)->extra_args; - for (; ea; ea = ea->next) - add_xsd_string(p1, ea->name, ea->value); - - } + encode_echoed_args(ptr, *p, "echoedSearchRetrieveRequest"); if (res->num_diagnostics) { xmlNodePtr rptr = xmlNewChild(ptr, 0, BAD_CAST "diagnostics", @@ -1053,14 +1068,7 @@ int yaz_srw_codec(ODR o, void * vptr, Z_SRW_PDU **handler_data, yaz_srw_record(o, ptr1, &res->record, &res->extra_record, client_data, version2); } - if ((*p)->extra_args) - { - xmlNode *p1 = - xmlNewChild(ptr, 0, BAD_CAST "echoedExplainRequest", 0); - Z_SRW_extra_arg *ea = (*p)->extra_args; - for (; ea; ea = ea->next) - add_xsd_string(p1, ea->name, ea->value); - } + encode_echoed_args(ptr, *p, "echoedExplainRequest"); if (res->num_diagnostics) { xmlNodePtr rptr = xmlNewChild(ptr, 0, BAD_CAST "diagnostics", diff --git a/src/srwutil.c b/src/srwutil.c index 0f6d71c..723ffc3 100644 --- a/src/srwutil.c +++ b/src/srwutil.c @@ -756,15 +756,16 @@ Z_SRW_PDU *yaz_srw_get(ODR o, int which) return yaz_srw_get_pdu(o, which, "2.0"); } +/* http://docs.oasis-open.org/search-ws/searchRetrieve/v1.0/os/schemas/sruResponse.xsd */ Z_SRW_PDU *yaz_srw_get_pdu_e(ODR o, int which, Z_SRW_PDU *req) { int version2 = !req->srw_version || strcmp(req->srw_version, "2.") > 0; Z_SRW_PDU *res = yaz_srw_get_pdu(o, which, req->srw_version); + Z_SRW_extra_arg **l = &res->extra_args, *ea; + l = append_extra_arg(o, l, "version", req->srw_version); if (req->which == Z_SRW_searchRetrieve_request && which == Z_SRW_searchRetrieve_response) { - Z_SRW_extra_arg **l = &res->extra_args; - l = append_extra_arg(o, l, "version", req->srw_version); if (req->u.request->queryType && strcmp(req->u.request->queryType, "cql")) l = append_extra_arg(o, l, "queryType", req->u.request->queryType); @@ -789,16 +790,25 @@ Z_SRW_PDU *yaz_srw_get_pdu_e(ODR o, int which, Z_SRW_PDU *req) l = append_extra_arg(o, l, "sortKeys", req->u.request->sort.sortKeys); l = append_extra_arg(o, l, "stylesheet", req->u.request->stylesheet); - } if (req->which == Z_SRW_explain_request && which == Z_SRW_explain_response) { - Z_SRW_extra_arg **l = &res->extra_args; - l = append_extra_arg(o, l, "version", req->srw_version); + if (version2) + { + l = append_extra_arg(o, l, "recordXMLEscaping", + req->u.explain_request->recordPacking); + l = append_extra_arg(o, l, "recordPacking", + req->u.explain_request->packing); + } + else + l = append_extra_arg(o, l, "recordPacking", + req->u.explain_request->recordPacking); l = append_extra_arg(o, l, "stylesheet", req->u.explain_request->stylesheet); } + for (ea = req->extra_args; ea; ea = ea->next) + l = append_extra_arg(o, l, ea->name, ea->value); return res; } @@ -807,7 +817,7 @@ Z_SRW_PDU *yaz_srw_get_pdu(ODR o, int which, const char *version) Z_SRW_PDU *sr = yaz_srw_get_core_ver(o, version); sr->which = which; - switch(which) + switch (which) { case Z_SRW_searchRetrieve_request: sr->u.request = (Z_SRW_searchRetrieveRequest *)