Always supply operation and version for SRU 2.0
authorAdam Dickmeiss <adam@indexdata.dk>
Fri, 6 Sep 2013 13:25:43 +0000 (15:25 +0200)
committerAdam Dickmeiss <adam@indexdata.dk>
Fri, 6 Sep 2013 13:25:43 +0000 (15:25 +0200)
While not required by the standard it does improve compatibility.

src/srw.c
src/srwutil.c

index 97cb05d..4013458 100644 (file)
--- a/src/srw.c
+++ b/src/srw.c
@@ -1070,9 +1070,7 @@ 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);
 
-            if (!version2)
-                add_xsd_string(ptr, "version", (*p)->srw_version);
-
+            add_xsd_string(ptr, "version", (*p)->srw_version);
             if (version2)
             {
                 if (queryType)
@@ -1123,8 +1121,7 @@ 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);
 
-            if (!version2)
-                add_xsd_string(ptr, "version", (*p)->srw_version);
+            add_xsd_string(ptr, "version", (*p)->srw_version);
             add_xsd_integer(ptr, "numberOfRecords", res->numberOfRecords);
             add_xsd_string(ptr, "resultSetId", res->resultSetId);
             add_xsd_integer(ptr,
@@ -1157,8 +1154,7 @@ 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);
 
-            if (!version2)
-                add_xsd_string(ptr, "version", (*p)->srw_version);
+            add_xsd_string(ptr, "version", (*p)->srw_version);
             if (version2)
             {
                 add_xsd_string(ptr, "recordXMLEscaping", req->recordPacking);
@@ -1201,8 +1197,7 @@ 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);
 
-            if (!version2)
-                add_xsd_string(ptr, "version", (*p)->srw_version);
+            add_xsd_string(ptr, "version", (*p)->srw_version);
 
             if (version2)
             {
@@ -1231,9 +1226,7 @@ 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);
 
-            if (!version2)
-                add_xsd_string(ptr, "version", (*p)->srw_version);
-
+            add_xsd_string(ptr, "version", (*p)->srw_version);
             if (res->num_terms)
             {
                 xmlNodePtr rptr = xmlNewChild(ptr, 0, BAD_CAST "terms", 0);
index 4f403a5..c18ca64 100644 (file)
@@ -488,8 +488,13 @@ int yaz_sru_decode(Z_HTTP_Request *hreq, Z_SRW_PDU **srw_pdu,
                 }
             }
         }
-        if (!operation && query)
-            operation = "searchRetrieve";
+        if (!operation)
+        {
+            if (query)
+                operation = "searchRetrieve";
+            else if (scanClause)
+                operation = "scan";
+        }
         version = yaz_negotiate_sru_version(version);
 
         if (!version)
@@ -884,19 +889,19 @@ static int yaz_get_sru_parms(const Z_SRW_PDU *srw_pdu, ODR encode,
     int version2 = strcmp(srw_pdu->srw_version, "2.") > 0;
     int i = 0;
     char *queryType;
-    if (!version2)
-        yaz_add_name_value_str(encode, name, value, &i, "version", srw_pdu->srw_version);
+    yaz_add_name_value_str(encode, name, value, &i, "version",
+                           srw_pdu->srw_version);
     name[i] = "operation";
     switch (srw_pdu->which)
     {
     case Z_SRW_searchRetrieve_request:
-        if (!version2)
-            value[i++] = "searchRetrieve";
+        value[i++] = "searchRetrieve";
         queryType = srw_pdu->u.request->queryType;
         if (version2)
         {
-            yaz_add_name_value_str(encode, name, value, &i, "queryType",
-                                   queryType);
+            if (queryType && strcmp(queryType, "cql"))
+                yaz_add_name_value_str(encode, name, value, &i, "queryType",
+                                       queryType);
             yaz_add_name_value_str(encode, name, value, &i, "query",
                                    srw_pdu->u.request->query);
         }