zoom: add facililty to dump APDUs.
[metaproxy-moved-to-github.git] / src / filter_zoom.cpp
index 6591a6e..f2b8f54 100644 (file)
@@ -145,6 +145,7 @@ namespace metaproxy_1 {
             std::string file_path;
             std::string content_proxy_server;
             std::string content_tmp_file;
+            bool apdu_log;
             CCL_bibset bibset;
             std::string element_transform;
             std::string element_raw;
@@ -198,7 +199,8 @@ void yf::Zoom::Backend::get_zoom_error(int *error, char **addinfo,
 {
     const char *msg = 0;
     const char *zoom_addinfo = 0;
-    *error = ZOOM_connection_error(m_connection, &msg, &zoom_addinfo);
+    const char *dset = 0;
+    *error = ZOOM_connection_error_x(m_connection, &msg, &zoom_addinfo, &dset);
     if (*error)
     {
         if (*error >= ZOOM_ERROR_CONNECT)
@@ -218,6 +220,8 @@ void yf::Zoom::Backend::get_zoom_error(int *error, char **addinfo,
         }
         else
         {
+            if (dset && !strcmp(dset, "info:srw/diagnostic/1"))
+                *error = yaz_diag_srw_to_bib1(*error);
             *addinfo = (char *) odr_malloc(
                 odr, 20 + (zoom_addinfo ? strlen(zoom_addinfo) : 0));
             **addinfo = '\0';
@@ -357,7 +361,8 @@ void yf::Zoom::Impl::release_frontend(mp::Package &package)
     }
 }
 
-yf::Zoom::Impl::Impl() : element_transform("pz2") , element_raw("raw")
+yf::Zoom::Impl::Impl() :
+    apdu_log(false), element_transform("pz2") , element_raw("raw")
 {
     bibset = ccl_qual_mk();
 }
@@ -584,6 +589,19 @@ void yf::Zoom::Impl::configure(const xmlNode *ptr, bool test_only,
                                                        attr->name));
             }
         }
+        else if (!strcmp((const char *) ptr->name, "log"))
+        { 
+            const struct _xmlAttr *attr;
+            for (attr = ptr->properties; attr; attr = attr->next)
+            {
+                if (!strcmp((const char *) attr->name, "apdu"))
+                    apdu_log = mp::xml::get_bool(attr->children, false);
+                else
+                    throw mp::filter::FilterException(
+                        "Bad attribute " + std::string((const char *)
+                                                       attr->name));
+            }
+        }
         else
         {
             throw mp::filter::FilterException
@@ -710,7 +728,9 @@ yf::Zoom::BackendPtr yf::Zoom::Frontend::get_backend_from_databases(
         b->set_option("rpnCharset", sptr->query_encoding);
 
     b->set_option("timeout", "40");
-
+    
+    if (m_p->apdu_log) 
+        b->set_option("apdulog", "1");
 
     std::string authentication = sptr->authentication;
     std::string proxy = sptr->cfProxy;
@@ -1252,6 +1272,13 @@ static void sort_via_cql(WRBUF cql_sortby, const char *sru_sortkeys)
     nmem_destroy(nmem);
 }
 
+#if YAZ_VERSIONL < 0x40206
+static void wrbuf_vp_puts(const char *buf, void *client_data)
+{
+    WRBUF b = (WRBUF) client_data;
+    wrbuf_puts(b, buf);
+}
+#endif
 
 void yf::Zoom::Frontend::handle_search(mp::Package &package)
 {