Allow Content-Type application/sru+xml YAZ-840
[yaz-moved-to-github.git] / src / srwutil.c
index 0f6d71c..1de920d 100644 (file)
@@ -97,6 +97,8 @@ int yaz_srw_check_content_type(Z_HTTP_Response *hres)
             return 1;
         if (!yaz_strcmp_del("application/xml", content_type, "; "))
             return 1;
+        if (!yaz_strcmp_del("application/sru+xml", content_type, "; "))
+            return 1;
     }
     return 0;
 }
@@ -416,7 +418,7 @@ int yaz_sru_decode(Z_HTTP_Request *hreq, Z_SRW_PDU **srw_pdu,
             p1 = p0 + strlen(p0);
         if (p1 != p0)
             db = yaz_decode_sru_dbpath_odr(decode, p0, p1 - p0);
-        if (!strcmp(hreq->method, "POST"))
+        if (!strcmp(hreq->method, "POST") && hreq->content_buf)
             p1 = hreq->content_buf;
         yaz_uri_to_array(p1, decode, &uri_name, &uri_val);
 #if YAZ_HAVE_XML2
@@ -756,15 +758,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 +792,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 +819,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 *)