Deal with recordPacking, recordXMLEscaping
authorAdam Dickmeiss <adam@indexdata.dk>
Wed, 4 Sep 2013 07:32:08 +0000 (09:32 +0200)
committerAdam Dickmeiss <adam@indexdata.dk>
Wed, 4 Sep 2013 07:32:08 +0000 (09:32 +0200)
Dealing with those is complicated due to our desire for
interoperability with both SRU 1.X and SRU 2.0.

client/client.c
src/srw.c
src/srwutil.c

index 64de44b..638d16e 100644 (file)
@@ -83,6 +83,7 @@ static file_history_t file_history = 0;
 
 static char sru_method[10] = "soap";
 static char sru_version[10] = "1.2";
+static char sru_recordPacking[10] = "";
 static char *codeset = 0;               /* character set for output */
 static int hex_dump = 0;
 static char *dump_file_prefix = 0;
@@ -1473,6 +1474,8 @@ static int send_SRW_searchRequest(const char *arg)
         printf("Only CQL and PQF supported in SRW\n");
         return 0;
     }
+    if (*sru_recordPacking)
+        sr->u.request->recordPacking = sru_recordPacking;
     sru_maximumRecords = 0;
     sr->u.request->maximumRecords = odr_intdup(out, 0);
     sr->u.request->facetList = facet_list;
@@ -2822,7 +2825,8 @@ static int cmd_sru(const char *arg)
     }
     else
     {
-        int r = sscanf(arg, "%9s %9s", sru_method, sru_version);
+        int r = sscanf(arg, "%9s %9s %9s", sru_method, sru_version,
+            sru_recordPacking);
         if (r >= 1)
         {
             if (!yaz_matchstr(sru_method, "post"))
@@ -3165,6 +3169,8 @@ static int send_SRW_presentRequest(const char *arg)
         return 0;
     if (!parse_show_args(arg, setstring, &setno, &nos))
         return 0;
+    if (*sru_recordPacking)
+        sr->u.request->recordPacking = sru_recordPacking;
     sr->u.request->startRecord = odr_intdup(out, setno);
     sru_maximumRecords = nos;
     sr->u.request->maximumRecords = odr_intdup(out, nos);
index 2cc0c7d..456151d 100644 (file)
--- a/src/srw.c
+++ b/src/srw.c
@@ -755,6 +755,8 @@ int yaz_srw_codec(ODR o, void * vptr, Z_SRW_PDU **handler_data,
         {
             xmlNodePtr ptr = method->children;
             Z_SRW_searchRetrieveRequest *req;
+            char *recordPacking = 0;
+            char *recordXMLEscaping = 0;
 
             (*p)->which = Z_SRW_searchRetrieve_request;
             req = (*p)->u.request = (Z_SRW_searchRetrieveRequest *)
@@ -797,7 +799,10 @@ int yaz_srw_codec(ODR o, void * vptr, Z_SRW_PDU **handler_data,
                                            &req->maximumRecords))
                     ;
                 else if (match_xsd_string(ptr, "recordPacking", o,
-                                          &req->recordPacking))
+                                          &recordPacking))
+                    ;
+                else if (match_xsd_string(ptr, "recordXMLEscaping", o,
+                                          &recordXMLEscaping))
                     ;
                 else if (match_xsd_string(ptr, "recordSchema", o,
                                           &req->recordSchema))
@@ -822,6 +827,15 @@ int yaz_srw_codec(ODR o, void * vptr, Z_SRW_PDU **handler_data,
                 /* should put proper diagnostic here */
                 return -1;
             }
+            if (!strcmp((*p)->srw_version, "2.0"))
+            {
+                req->recordPacking = recordXMLEscaping;
+                req->packing = recordPacking;
+            }
+            else
+            {
+                req->recordPacking = recordPacking;
+            }
         }
         else if (!xmlStrcmp(method->name, BAD_CAST "searchRetrieveResponse"))
         {
@@ -1064,7 +1078,13 @@ int yaz_srw_codec(ODR o, void * vptr, Z_SRW_PDU **handler_data,
             }
             add_xsd_integer(ptr, "startRecord", req->startRecord);
             add_xsd_integer(ptr, "maximumRecords", req->maximumRecords);
-            add_xsd_string(ptr, "recordPacking", req->recordPacking);
+            if (version2)
+            {
+                add_xsd_string(ptr, "recordXMLEscaping", req->recordPacking);
+                add_xsd_string(ptr, "recordPacking", req->packing);
+            }
+            else
+                add_xsd_string(ptr, "recordPacking", req->recordPacking);
             add_xsd_string(ptr, "recordSchema", req->recordSchema);
             add_xsd_string(ptr, "recordXPath", req->recordXPath);
             add_xsd_integer(ptr, "resultSetTTL", req->resultSetTTL);
@@ -1122,7 +1142,13 @@ int yaz_srw_codec(ODR o, void * vptr, Z_SRW_PDU **handler_data,
 
             if (!version2)
                 add_xsd_string(ptr, "version", (*p)->srw_version);
-            add_xsd_string(ptr, "recordPacking", req->recordPacking);
+            if (version2)
+            {
+                add_xsd_string(ptr, "recordXMLEscaping", req->recordPacking);
+                add_xsd_string(ptr, "recordPacking", req->packing);
+            }
+            else
+                add_xsd_string(ptr, "recordPacking", req->recordPacking);
             add_xsd_string(ptr, "stylesheet", req->stylesheet);
             add_xsd_string(ptr, "database", req->database);
         }
index 37d8f9e..2cf49c3 100644 (file)
@@ -760,6 +760,7 @@ Z_SRW_PDU *yaz_srw_get_pdu(ODR o, int which, const char *version)
         sr->u.request->maximumRecords = 0;
         sr->u.request->recordSchema = 0;
         sr->u.request->recordPacking = 0;
+        sr->u.request->packing = 0;
         sr->u.request->recordXPath = 0;
         sr->u.request->database = 0;
         sr->u.request->resultSetTTL = 0;
@@ -785,6 +786,7 @@ Z_SRW_PDU *yaz_srw_get_pdu(ODR o, int which, const char *version)
         sr->u.explain_request = (Z_SRW_explainRequest *)
             odr_malloc(o, sizeof(*sr->u.explain_request));
         sr->u.explain_request->recordPacking = 0;
+        sr->u.explain_request->packing = 0;
         sr->u.explain_request->database = 0;
         sr->u.explain_request->stylesheet = 0;
         break;
@@ -928,8 +930,16 @@ static int yaz_get_sru_parms(const Z_SRW_PDU *srw_pdu, ODR encode,
                                srw_pdu->u.request->maximumRecords);
         yaz_add_name_value_str(encode, name, value, &i, "recordSchema",
                                srw_pdu->u.request->recordSchema);
-        yaz_add_name_value_str(encode, name, value, &i, "recordPacking",
-                               srw_pdu->u.request->recordPacking);
+        if (version2)
+        {
+            yaz_add_name_value_str(encode, name, value, &i, "recordXMLEscaping",
+                                   srw_pdu->u.request->recordPacking);
+            yaz_add_name_value_str(encode, name, value, &i, "recordPacking",
+                                   srw_pdu->u.request->packing);
+        }
+        else
+            yaz_add_name_value_str(encode, name, value, &i, "recordPacking",
+                                   srw_pdu->u.request->recordPacking);
         yaz_add_name_value_str(encode, name, value, &i, "recordXPath",
                                srw_pdu->u.request->recordXPath);
         yaz_add_name_value_str(encode, name, value, &i, "stylesheet",
@@ -939,6 +949,17 @@ static int yaz_get_sru_parms(const Z_SRW_PDU *srw_pdu, ODR encode,
         break;
     case Z_SRW_explain_request:
         value[i++] = "explain";
+
+        if (version2)
+        {
+            yaz_add_name_value_str(encode, name, value, &i, "recordXMLEscaping",
+                                   srw_pdu->u.explain_request->recordPacking);
+            yaz_add_name_value_str(encode, name, value, &i, "recordPacking",
+                                   srw_pdu->u.explain_request->packing);
+        }
+        else
+            yaz_add_name_value_str(encode, name, value, &i, "recordPacking",
+                                   srw_pdu->u.explain_request->recordPacking);
         yaz_add_name_value_str(encode, name, value, &i, "stylesheet",
                                srw_pdu->u.explain_request->stylesheet);
         break;