From: Adam Dickmeiss Date: Wed, 9 Jul 2014 11:49:29 +0000 (+0200) Subject: echoedSearchRetrieveRequest support YAZ-776 X-Git-Tag: v5.3.0~5 X-Git-Url: http://jsfdemo.indexdata.com/cgi-bin?a=commitdiff_plain;h=d7f1bc4eb6c5d8e0d2eba2f040eb9c359eca9e45;p=yaz-moved-to-github.git echoedSearchRetrieveRequest support YAZ-776 --- diff --git a/include/yaz/srw.h b/include/yaz/srw.h index 164155f..2c7cc01 100644 --- a/include/yaz/srw.h +++ b/include/yaz/srw.h @@ -212,7 +212,12 @@ typedef struct { char *srw_version; char *username; /* From HTTP header or request */ char *password; /* From HTTP header or request */ - Z_SRW_extra_arg *extra_args; /* extraRequestData SRU GET/POST */ + + /* 1. SRU extraRequestData x-name=value for requests encoding */ + /* 2. SRU extraRequestData x-name=value for requests decoding */ + /* 3. SRU echoed data for response encoding */ + Z_SRW_extra_arg *extra_args; + char *extraResponseData_buf; int extraResponseData_len; } Z_SRW_PDU; @@ -225,6 +230,7 @@ YAZ_EXPORT int yaz_ucp_codec(ODR o, void * pptr, void *client_data, const char *ns); YAZ_EXPORT Z_SRW_PDU *yaz_srw_get_core_v_2_0(ODR o); YAZ_EXPORT Z_SRW_PDU *yaz_srw_get_pdu(ODR o, int which, const char *version); +YAZ_EXPORT Z_SRW_PDU *yaz_srw_get_pdu_e(ODR o, int which, Z_SRW_PDU *req); YAZ_EXPORT Z_SRW_PDU *yaz_srw_get(ODR o, int which); YAZ_EXPORT Z_SRW_recordVersion *yaz_srw_get_record_versions(ODR o, int num); YAZ_EXPORT Z_SRW_extra_record *yaz_srw_get_extra_record(ODR o); diff --git a/src/seshigh.c b/src/seshigh.c index 1949eb9..4c9f4f6 100644 --- a/src/seshigh.c +++ b/src/seshigh.c @@ -1862,8 +1862,8 @@ static void process_http_request(association *assoc, request *req) if (sr->which == Z_SRW_searchRetrieve_request) { Z_SRW_PDU *res = - yaz_srw_get_pdu(assoc->encode, Z_SRW_searchRetrieve_response, - sr->srw_version); + yaz_srw_get_pdu_e(assoc->encode, Z_SRW_searchRetrieve_response, + sr); stylesheet = sr->u.request->stylesheet; if (num_diagnostic) { diff --git a/src/srw.c b/src/srw.c index f156921..431696b 100644 --- a/src/srw.c +++ b/src/srw.c @@ -985,6 +985,16 @@ 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); + + } if (res->num_diagnostics) { xmlNodePtr rptr = xmlNewChild(ptr, 0, BAD_CAST "diagnostics", diff --git a/src/srwutil.c b/src/srwutil.c index 81e1010..ef27e45 100644 --- a/src/srwutil.c +++ b/src/srwutil.c @@ -20,6 +20,34 @@ #define MAX_SRU_PARAMETERS 30 +static Z_SRW_extra_arg **append_extra_arg(ODR odr, Z_SRW_extra_arg **l, + const char *n, const char *v) +{ + if (n && v && *v != '\0') + { + while (*l) + l = &(*l)->next; + *l = (Z_SRW_extra_arg *) odr_malloc(odr, sizeof(**l)); + (*l)->name = odr_strdup(odr, n); + (*l)->value = odr_strdup(odr, v); + (*l)->next = 0; + l = &(*l)->next; + } + return l; +} + +static Z_SRW_extra_arg **append_extra_arg_int(ODR odr, Z_SRW_extra_arg **l, + const char *n, Odr_int *v) +{ + if (v) + { + char str[32]; + sprintf(str, ODR_INT_PRINTF, *v); + l = append_extra_arg(odr, l, n, str); + } + return l; +} + static char *yaz_decode_sru_dbpath_odr(ODR n, const char *uri, size_t len) { return odr_strdupn(n, uri, len); @@ -453,13 +481,7 @@ int yaz_sru_decode(Z_HTTP_Request *hreq, Z_SRW_PDU **srw_pdu, ; /* ignoring extraRequestData */ else if (n[0] == 'x' && n[1] == '-') { - Z_SRW_extra_arg **l = &extra_args; - while (*l) - l = &(*l)->next; - *l = (Z_SRW_extra_arg *) odr_malloc(decode, sizeof(**l)); - (*l)->name = odr_strdup(decode, n); - (*l)->value = odr_strdup(decode, v); - (*l)->next = 0; + append_extra_arg(decode, &extra_args, n, v); } else { @@ -732,6 +754,42 @@ Z_SRW_PDU *yaz_srw_get(ODR o, int which) return yaz_srw_get_pdu(o, which, "2.0"); } +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); + 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); + l = append_extra_arg(o, l, "query", req->u.request->query); + l = append_extra_arg_int(o, l, "startRecord", + req->u.request->startRecord); + l = append_extra_arg_int(o, l, "maximumRecords", + req->u.request->maximumRecords); + if (version2) + { + l = append_extra_arg(o, l, "recordXMLEscaping", + req->u.request->recordPacking); + l = append_extra_arg(o, l, "recordPacking", + req->u.request->packing); + } + else + l = append_extra_arg(o, l, "recordPacking", + req->u.request->recordPacking); + l = append_extra_arg(o, l, "recordSchema", + req->u.request->recordSchema); + if (req->u.request->sort_type == Z_SRW_sort_type_sort) + l = append_extra_arg(o, l, "sortKeys", + req->u.request->sort.sortKeys); + } + return res; +} + 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); @@ -1160,19 +1218,12 @@ 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)); - (*ea)->name = *name; - (*ea)->value = *val; - ea = &(*ea)->next; + ea = append_extra_arg(odr, ea, *name, *val); val++; name++; } - *ea = 0; } }