zoom: Honor extraArgs, strip # in zurl
[metaproxy-moved-to-github.git] / src / filter_zoom.cpp
index 264fa5a..9de8e6b 100644 (file)
@@ -76,6 +76,7 @@ namespace metaproxy_1 {
             std::string urlRecipe;
             std::string contentConnector;
             std::string sortStrategy;
+            std::string extraArgs;
             std::string rpn2cql_fname;
             bool use_turbomarc;
             bool piggyback;
@@ -292,6 +293,7 @@ yf::Zoom::Backend::Backend()
     enable_cproxy = true;
     enable_explain = false;
     explain_doc = 0;
+    cqlt = 0;
 }
 
 yf::Zoom::Backend::~Backend()
@@ -358,8 +360,12 @@ void yf::Zoom::Backend::connect(std::string zurl,
                                 int *error, char **addinfo,
                                 ODR odr)
 {
+    size_t h = zurl.find_first_of('#');
+    if (h != std::string::npos)
+        zurl.erase(h);
     ZOOM_connection_connect(m_connection, zurl.length() ? zurl.c_str() : 0, 0);
     get_zoom_error(error, addinfo, odr);
+    
 }
 
 void yf::Zoom::Backend::search(ZOOM_query q, Odr_int *hits,
@@ -602,6 +608,11 @@ yf::Zoom::SearchablePtr yf::Zoom::Impl::parse_torus_record(const xmlNode *ptr)
         {
             s->sortStrategy = mp::xml::get_text(ptr);
         }
+        else if (!strcmp((const char *) ptr->name,
+                          "extraArgs"))
+        {
+            s->extraArgs = mp::xml::get_text(ptr);
+        }
         else if (!strcmp((const char *) ptr->name, "rpn2cql"))
             s->rpn2cql_fname = mp::xml::get_text(ptr);
     }
@@ -1325,6 +1336,9 @@ yf::Zoom::BackendPtr yf::Zoom::Frontend::get_backend_from_databases(
     if (sptr->query_encoding.length())
         b->set_option("rpnCharset", sptr->query_encoding);
 
+    if (sptr->extraArgs.length())
+        b->set_option("extraArgs", sptr->extraArgs);
+
     b->set_option("timeout", m_p->zoom_timeout.c_str());
     
     if (m_p->apdu_log) 
@@ -2481,11 +2495,13 @@ void yf::Zoom::Frontend::auth(mp::Package &package, Z_InitRequest *req,
     yaz_log(YLOG_LOG, "IP=%s", ip.c_str());
 
     std::string torus_query;
+    int failure_code;
 
     if (user.length() && password.length())
     {
         torus_query = "userName==\"" + escape_cql_term(user) +
             "\" and password==\"" + escape_cql_term(password) + "\"";
+        failure_code = YAZ_BIB1_INIT_AC_BAD_USERID_AND_OR_PASSWORD;
     }
     else
     {  
@@ -2497,6 +2513,7 @@ void yf::Zoom::Frontend::auth(mp::Package &package, Z_InitRequest *req,
         torus_query = "ip encloses/net.ipaddress \"";
         torus_query += escape_cql_term(std::string(ip_cstr));
         torus_query += "\"";
+        failure_code = YAZ_BIB1_INIT_AC_BLOCKED_NETWORK_ADDRESS;
     }
 
     std::string dummy_db;
@@ -2505,7 +2522,8 @@ void yf::Zoom::Frontend::auth(mp::Package &package, Z_InitRequest *req,
                                      torus_query, dummy_realm, m_p->proxy);
     if (!doc)
     {
-        *error = YAZ_BIB1_UNSPECIFIED_ERROR;
+        // something fundamental broken in lookup.
+        *error = YAZ_BIB1_TEMPORARY_SYSTEM_ERROR;
         *addinfo = odr_strdup(odr, "Torus server unavailable or "
                               "incorrectly configured");
         return;
@@ -2541,7 +2559,7 @@ void yf::Zoom::Frontend::auth(mp::Package &package, Z_InitRequest *req,
     }
     if (!ptr)
     {
-        *error = YAZ_BIB1_INIT_AC_BAD_USERID_AND_OR_PASSWORD;
+        *error = failure_code;
         return;
     }
     session_realm = mp::xml::get_text(ptr);