Decode SRU 2.0 responses
authorAdam Dickmeiss <adam@indexdata.dk>
Wed, 8 Aug 2012 12:53:22 +0000 (14:53 +0200)
committerAdam Dickmeiss <adam@indexdata.dk>
Wed, 8 Aug 2012 12:57:22 +0000 (14:57 +0200)
The official namespace for responses, according to
http://docs.oasis-open.org/search-ws/searchRetrieve/v1.0/cs01/schemas/sruResponse.xsd
appears to be http://docs.oasis-open.org/ns/search-ws/sruResponse .
nature.com's server, however, usee namespace
http://docs.oasis-open.org/ns/search-ws/sru-2-0-response
For this reason we are now using a glob-expr to match up the namespace.
ZOOM C and yaz-client updated.
Perhaps SRU 1.2 uses same namespace, I don't know. I can not find
a single real example showing the "real" namespace in the documentation
from OASIS. The namespace for requests is different from responses, but
this is not added to YAZ yet, when we don't encode them yet.

client/client.c
include/yaz/srw.h
src/soap.c
src/zoom-sru.c

index 5af4e26..d8e78b9 100644 (file)
@@ -4458,8 +4458,9 @@ static void http_response(Z_HTTP_Response *hres)
         {
             Z_SOAP *soap_package = 0;
             ODR o = odr_createmem(ODR_DECODE);
-            Z_SOAP_Handler soap_handlers[3] = {
+            Z_SOAP_Handler soap_handlers[4] = {
                 {YAZ_XMLNS_SRU_v1_1, 0, (Z_SOAP_fun) yaz_srw_codec},
+                {YAZ_XMLNS_SRU_v2_response, 0, (Z_SOAP_fun) yaz_srw_codec},
                 {YAZ_XMLNS_UPDATE_v0_9, 0, (Z_SOAP_fun) yaz_ucp_codec},
                 {0, 0, 0}
             };
index cf08af4..8a67ca0 100644 (file)
@@ -335,6 +335,7 @@ void yaz_encode_sru_extra(Z_SRW_PDU *sr, ODR odr, const char *extra_args);
 #define YAZ_XMLNS_SRU_v1_1 "http://www.loc.gov/zing/srw/"
 #define YAZ_XMLNS_DIAG_v1_1 "http://www.loc.gov/zing/srw/diagnostic/"
 #define YAZ_XMLNS_UPDATE_v0_9 "http://www.loc.gov/zing/srw/update/"
+#define YAZ_XMLNS_SRU_v2_response "http://docs.oasis-open.org/ns/search-ws/sru*esponse"
 
 YAZ_EXPORT
 int yaz_srw_check_content_type(Z_HTTP_Response *hres);
index 5e58a49..0f564b0 100644 (file)
@@ -14,6 +14,7 @@
 #endif
 
 #include <yaz/soap.h>
+#include <yaz/match_glob.h>
 
 #if YAZ_HAVE_XML2
 #include <libxml/parser.h>
@@ -56,7 +57,7 @@ int z_soap_codec_enc_xsl(ODR o, Z_SOAP **pp,
         /* check for SRU root node match */
         
         for (i = 0; handlers[i].ns; i++)
-            if (!xmlStrcmp(ptr->ns->href, BAD_CAST handlers[i].ns))
+            if (yaz_match_glob(handlers[i].ns, (const char *)ptr->ns->href))
                 break;
         if (handlers[i].ns)
         {
@@ -66,7 +67,7 @@ int z_soap_codec_enc_xsl(ODR o, Z_SOAP **pp,
             p_top_tmp.children = ptr;
             ret = (*handlers[i].f)(o, &p_top_tmp, &handler_data,
                                    handlers[i].client_data,
-                                   handlers[i].ns);
+                                   (const char *)ptr->ns->href);
             
             if (ret || !handler_data)
                 z_soap_error(o, p, "SOAP-ENV:Client",
@@ -182,15 +183,19 @@ int z_soap_codec_enc_xsl(ODR o, Z_SOAP **pp,
         }
         else
         {
+            const char *ns = (const char *) ptr->ns->href;
             for (i = 0; handlers[i].ns; i++)
-                if (!xmlStrcmp(ptr->ns->href, BAD_CAST handlers[i].ns))
+            {
+                fprintf(stderr, "checking globns=%s ns=%s\n",
+                         handlers[i].ns, ns);
+                if (yaz_match_glob(handlers[i].ns, ns))
                     break;
+            }
             if (handlers[i].ns)
             {
                 void *handler_data = 0;
                 ret = (*handlers[i].f)(o, pptr, &handler_data,
-                                       handlers[i].client_data,
-                                       handlers[i].ns);
+                                       handlers[i].client_data, ns);
                 if (ret || !handler_data)
                     z_soap_error(o, p, "SOAP-ENV:Client",
                                  "SOAP Handler returned error", 0);
@@ -207,8 +212,7 @@ int z_soap_codec_enc_xsl(ODR o, Z_SOAP **pp,
             else
             {
                 ret = z_soap_error(o, p, "SOAP-ENV:Client", 
-                                   "No handler for NS",
-                                   (const char *)ptr->ns->href);
+                                   "No handler for NS", ns);
             }
         }
         xmlFreeDoc(doc);
index c38cee6..04aff43 100644 (file)
@@ -425,15 +425,15 @@ int ZOOM_handle_sru(ZOOM_connection c, Z_HTTP_Response *hres,
     {
         Z_SOAP *soap_package = 0;
         ODR o = c->odr_in;
-        Z_SOAP_Handler soap_handlers[2] = {
+        Z_SOAP_Handler soap_handlers[3] = {
             {YAZ_XMLNS_SRU_v1_1, 0, (Z_SOAP_fun) yaz_srw_codec},
+            {YAZ_XMLNS_SRU_v2_response, 0, (Z_SOAP_fun) yaz_srw_codec},
             {0, 0, 0}
         };
         ret = z_soap_codec(o, &soap_package,
                            &hres->content_buf, &hres->content_len,
                            soap_handlers);
-        if (!ret && soap_package->which == Z_SOAP_generic &&
-            soap_package->u.generic->no == 0)
+        if (!ret && soap_package->which == Z_SOAP_generic)
         {
             Z_SRW_PDU *sr = (Z_SRW_PDU*) soap_package->u.generic->p;