Version 1.8.8
[metaproxy-moved-to-github.git] / src / filter_zoom.cpp
index 755b17e..4948ca5 100644 (file)
@@ -83,6 +83,7 @@ namespace metaproxy_1 {
             std::string extraArgs;
             std::string rpn2cql_fname;
             std::string retry_on_failure;
+            std::map<std::string, std::string> cf_param;
             bool use_turbomarc;
             bool piggyback;
             CCL_bibset ccl_bibset;
@@ -93,7 +94,6 @@ namespace metaproxy_1 {
         class Zoom::Backend : boost::noncopyable {
             friend class Impl;
             friend class Frontend;
-            std::string zurl;
             mp::wrbuf m_apdu_wrbuf;
             ZOOM_connection m_connection;
             ZOOM_resultset m_resultset;
@@ -716,6 +716,11 @@ yf::Zoom::SearchablePtr yf::Zoom::Impl::parse_torus_record(const xmlNode *ptr)
         {
             s->retry_on_failure = mp::xml::get_text(ptr);
         }
+        else if (strlen((const char *) ptr->name) > 3 &&
+                 !memcmp((const char *) ptr->name, "cf_", 3))
+        {
+            s->cf_param[(const char *) ptr->name + 3] = mp::xml::get_text(ptr);
+        }
     }
     return s;
 }
@@ -1140,8 +1145,6 @@ yf::Zoom::BackendPtr yf::Zoom::Frontend::get_backend_from_databases(
     else
         torus_db = database;
 
-    std::string authentication;
-    std::string content_authentication;
     std::string content_proxy;
     std::string realm = session_realm;
     if (realm.length() == 0)
@@ -1161,11 +1164,11 @@ yf::Zoom::BackendPtr yf::Zoom::Frontend::get_backend_from_databases(
     if (input_args.length())
         no_parms = yaz_uri_to_array(input_args.c_str(),
                                     odr, &names, &values);
-    // adding 10 because we'll be adding other URL args
+    // adding 20 because we'll be adding other URL args
     const char **out_names = (const char **)
-        odr_malloc(odr, (10 + no_parms) * sizeof(*out_names));
+        odr_malloc(odr, (20 + no_parms) * sizeof(*out_names));
     const char **out_values = (const char **)
-        odr_malloc(odr, (10 + no_parms) * sizeof(*out_values));
+        odr_malloc(odr, (20 + no_parms) * sizeof(*out_values));
 
     // may be changed if it's a content connection
     std::string torus_url = m_p->torus_searchable_url;
@@ -1256,19 +1259,6 @@ yf::Zoom::BackendPtr yf::Zoom::Frontend::get_backend_from_databases(
         return m_backend;
     }
 
-    if (param_user)
-    {
-        authentication = std::string(param_user);
-        if (param_password)
-            authentication += "/" + std::string(param_password);
-    }
-    if (param_content_user)
-    {
-        content_authentication = std::string(param_content_user);
-        if (param_content_password)
-            content_authentication += "/" + std::string(param_content_password);
-    }
-
     if (torus_db.compare("IR-Explain---1") == 0)
         return explain_search(package, database, error, addinfo, odr, torus_url,
                               torus_db, realm);
@@ -1470,11 +1460,20 @@ yf::Zoom::BackendPtr yf::Zoom::Frontend::get_backend_from_databases(
                                         maximumRecords > 0 */
     b->set_option("piggyback", sptr->piggyback ? "1" : "0");
 
-    if (content_authentication.length() == 0)
-        content_authentication = sptr->contentAuthentication;
-
-    if (authentication.length() == 0)
-        authentication = sptr->authentication;
+    std::string authentication = sptr->authentication;
+    if (param_user)
+    {
+        authentication = std::string(param_user);
+        if (param_password)
+            authentication += "/" + std::string(param_password);
+    }
+    std::string content_authentication = sptr->contentAuthentication;
+    if (param_content_user)
+    {
+        content_authentication = std::string(param_content_user);
+        if (param_content_password)
+            content_authentication += "/" + std::string(param_content_password);
+    }
 
     if (proxy.length() == 0)
         proxy = sptr->cfProxy;
@@ -1484,7 +1483,17 @@ yf::Zoom::BackendPtr yf::Zoom::Frontend::get_backend_from_databases(
     {
         // A CF target
         b->set_option("user", sptr->cfAuth);
-        if (authentication.length())
+        if (param_user)
+        {
+            out_names[no_out_args] = "user";
+            out_values[no_out_args++] = odr_strdup(odr, param_user);
+            if (param_password)
+            {
+                out_names[no_out_args] = "password";
+                out_values[no_out_args++] = odr_strdup(odr, param_password);
+            }
+        }
+        else if (authentication.length())
         {
             size_t found = authentication.find('/');
             if (found != std::string::npos)
@@ -1522,6 +1531,20 @@ yf::Zoom::BackendPtr yf::Zoom::Frontend::get_backend_from_databases(
             out_names[no_out_args] = "nocproxy";
             out_values[no_out_args++] = odr_strdup(odr, param_nocproxy);
         }
+        std::map<std::string,std::string>::const_iterator it;
+        for (it = sptr->cf_param.begin(); it != sptr->cf_param.end(); it++)
+        {
+            int i;
+            const char *n = it->first.c_str();
+            for (i = 0; i < no_out_args; i++)
+                if (!strcmp(n, out_names[i]))
+                    break;
+            if (i == no_out_args)
+            {
+                out_names[no_out_args] = odr_strdup(odr, n);
+                out_values[no_out_args++] = odr_strdup(odr, it->second.c_str());
+            }
+        }
     }
     else
     {
@@ -2391,12 +2414,8 @@ next_proxy:
             case CCL_ERR_TRUNC_NOT_LEFT:
             case CCL_ERR_TRUNC_NOT_RIGHT:
             case CCL_ERR_TRUNC_NOT_BOTH:
-#ifdef CCL_ERR_TRUNC_NOT_EMBED
             case CCL_ERR_TRUNC_NOT_EMBED:
-#endif
-#ifdef CCL_ERR_TRUNC_NOT_SINGLE
             case CCL_ERR_TRUNC_NOT_SINGLE:
-#endif
                 error = YAZ_BIB1_UNSUPP_SEARCH;
                 break;
             }