Merge branch 'master' of ssh://git.indexdata.com/home/git/pub/metaproxy
authorMike Taylor <mike@indexdata.com>
Wed, 20 Jul 2011 16:17:16 +0000 (17:17 +0100)
committerMike Taylor <mike@indexdata.com>
Wed, 20 Jul 2011 16:17:16 +0000 (17:17 +0100)
etc/config-zoom.xml
src/filter_zoom.cpp
src/router_flexml.cpp
src/test_xmlutil.cpp
src/url_recipe.cpp

index 20246c1..659fa94 100644 (file)
          <record>
            <piggyback>1</piggyback>
            <queryEncoding>UTF-8</queryEncoding>
+           <udb>jstor-local</udb>
+           <cclmap_term>s=al</cclmap_term>
+           <cclmap_ti>1=title s=pw t=l,r</cclmap_ti>
+           <sru>get</sru>
+           <transform>dc.xsl</transform>
+           <zurl>dfr.jstor.org/sru</zurl>
+         </record>
+         <record>
+           <piggyback>1</piggyback>
+           <queryEncoding>UTF-8</queryEncoding>
            <udb>cf-local</udb>
            <cclmap_term>1=1016 s=al</cclmap_term>
            <cclmap_ti>1=4 s=pw t=l,r</cclmap_ti>
       <fieldmap cql="dc.subject" ccl="su"/>
       <fieldmap cql="bath.isbn" ccl="isbn"/>
       <fieldmap cql="bath.issn" ccl="issn"/>
-      <fieldmap cql="bash.isbn" ccl="isbn"/><!-- ### deprecated erroneous synonym -->
-      <fieldmap cql="bash.issn" ccl="issn"/><!-- ### deprecated erroneous synonym -->
       <fieldmap cql="dc.date" ccl="date"/>
-      <!-- 
-          I got some of the following CCL qualifier names from
-          http://catalog.pburglib.org/polaris/Help/PWbasicsearch6.html
-          These are marked with the comment POLARIS.
-          The others, I just made up.
-          (Mike, Wed Jun 15 22:50:18 BST 2011)
-       -->
-      <fieldmap cql="rec.identifier" ccl="ocn"/><!-- POLARIS -->
-      <fieldmap cql="net.path" ccl="db"/>
-      <fieldmap cql="dc.language" ccl="la"/><!-- POLARIS -->
-      <fieldmap cql="dc.format" ccl="tom"/><!-- POLARIS -->
-      <fieldmap cql="id.fullText" ccl="fullText"/>
-      <fieldmap cql="id.peerReviewed" ccl="peerReviewed"/>
-      <fieldmap cql="dc.description" ccl="desc"/>
-      <fieldmap cql="dc.source" ccl="src"/>
-      <fieldmap cql="dc.publisher" ccl="pub"/><!-- POLARIS -->
-      <fieldmap cql="id.seriesTitle" ccl="series-ti"/>
-
       <cclmap>
         <qual name="ocn">
           <attr type="1" value="12"/>
         <message>F</message>
       </filter>
       <filter type="sru_z3950"/>
-      <filter type="record_transform">
-        <retrievalinfo   xmlns="http://indexdata.com/yaz" version="1.0">
-          <retrieval syntax="xml" name="usi">
-            <backend syntax="xml" name="pz2">
-              <xslt stylesheet="pz22usi.xsl"/>
-            </backend>
-          </retrieval>
-          <retrieval syntax="xml"/>
-          <retrieval syntax="json"/>
-          <retrieval syntax="usmarc"/>
-        </retrievalinfo>
-      </filter>
       <filter type="session_shared"/>
       <filter type="log">
         <message>B</message>
index eb9f64b..76992fa 100644 (file)
@@ -537,6 +537,7 @@ yf::Zoom::BackendPtr yf::Zoom::Frontend::get_backend_from_databases(
     if (m_backend && m_backend->m_frontend_database == database)
         return m_backend;
 
+    const char *sru_proxy = 0;
     std::string db_args;
     std::string torus_db;
     size_t db_arg_pos = database.find(',');
@@ -635,19 +636,34 @@ yf::Zoom::BackendPtr yf::Zoom::Frontend::get_backend_from_databases(
     {
         // A CF target
         b->set_option("user", sptr->cfAuth.c_str());
-        if (authentication.length() && db_args.length() == 0)
+        if (db_args.length() == 0)
         {
-            // no database (auth) args specified already.. and the
-            // Torus authentication has it.. Generate the args that CF
-            // understands..
-            size_t found = authentication.find('/');
-            if (found != std::string::npos)
+            if (authentication.length())
+            {
+                // no database (auth) args specified already.. and the
+                // Torus authentication has it.. Generate the args that CF
+                // understands..
+                size_t found = authentication.find('/');
+                if (found != std::string::npos)
+                {
+                    db_args += "user=" + mp::util::uri_encode(authentication.substr(0, found))
+                        + "&password=" + mp::util::uri_encode(authentication.substr(found+1));
+                }
+                else
+                    db_args += "user=" + mp::util::uri_encode(authentication);
+            }
+            if (sptr->cfProxy.length())
             {
-                db_args += "user=" + mp::util::uri_encode(authentication.substr(0, found))
-                    + "&password=" + mp::util::uri_encode(authentication.substr(found+1));
+                if (db_args.length())
+                    db_args += "&";
+                db_args += "proxy=" + mp::util::uri_encode(sptr->cfProxy);
             }
-            else
-                db_args += "user=" + mp::util::uri_encode(authentication);
+        }
+        if (sptr->cfSubDb.length())
+        {
+            if (db_args.length())
+                db_args += "&";
+            db_args += "subdatabase=" + mp::util::uri_encode(sptr->cfSubDb);
         }
     }
     else
@@ -671,6 +687,8 @@ yf::Zoom::BackendPtr yf::Zoom::Frontend::get_backend_from_databases(
                     param_user = value;
                 else if (!strcmp(name, "password"))
                     param_password = value;
+                else if (!strcmp(name, "proxy"))
+                    sru_proxy = value;
                 else
                 {
                     BackendPtr notfound;
@@ -699,18 +717,9 @@ yf::Zoom::BackendPtr yf::Zoom::Frontend::get_backend_from_databases(
                 b->set_option("user", authentication.c_str());
         }
     }
-    if (sptr->cfProxy.length())
-    {
-        if (db_args.length())
-            db_args += "&";
-        db_args += "proxy=" + mp::util::uri_encode(sptr->cfProxy);
-    }
-    if (sptr->cfSubDb.length())
-    {
-        if (db_args.length())
-            db_args += "&";
-        db_args += "subdatabase=" + mp::util::uri_encode(sptr->cfSubDb);
-    }
+
+    if (sru_proxy)
+        b->set_option("proxy", sru_proxy);
 
     std::string url;
     if (sptr->sru.length())
index 0a019eb..7aca757 100644 (file)
@@ -67,9 +67,9 @@ namespace metaproxy_1 {
                                   const char *file_include_path);
 
         void parse_xml_filters(xmlDocPtr doc, const xmlNode *node,
-            bool test_only);
+                               bool test_only, const char *file_include_path);
         void parse_xml_routes(xmlDocPtr doc, const xmlNode *node,
-            bool test_only);
+                              bool test_only, const char *file_include_path);
 
         bool m_xinclude;
     private:
@@ -91,7 +91,8 @@ namespace metaproxy_1 {
 
 void mp::RouterFleXML::Rep::parse_xml_filters(xmlDocPtr doc,
                                               const xmlNode *node,
-                                              bool test_only)
+                                              bool test_only,
+                                              const char *file_include_path)
 {
     unsigned int filter_nr = 0;
     while(node && mp::xml::check_element_mp(node, "filter"))
@@ -140,7 +141,8 @@ void mp::RouterFleXML::Rep::parse_xml_filters(xmlDocPtr doc,
 
 void mp::RouterFleXML::Rep::parse_xml_routes(xmlDocPtr doc,
                                              const xmlNode *node,
-                                             bool test_only)
+                                             bool test_only,
+                                             const char *file_include_path)
 {
     mp::xml::check_element_mp(node, "route");
 
@@ -288,7 +290,7 @@ void mp::RouterFleXML::Rep::parse_xml_config_dom(xmlDocPtr doc,
     {
         parse_xml_filters(doc, mp::xml::jump_to_children(node,
                                                          XML_ELEMENT_NODE),
-            test_only);
+                          test_only, file_include_path);
                       
         node = mp::xml::jump_to_next(node, XML_ELEMENT_NODE);
     }
@@ -296,7 +298,7 @@ void mp::RouterFleXML::Rep::parse_xml_config_dom(xmlDocPtr doc,
     mp::xml::check_element_mp(node, "routes");
     
     parse_xml_routes(doc, mp::xml::jump_to_children(node, XML_ELEMENT_NODE),
-        test_only);
+                     test_only, file_include_path);
 
     node = mp::xml::jump_to_next(node, XML_ELEMENT_NODE);
     if (node)
index 13065a1..ae9b571 100644 (file)
@@ -99,8 +99,13 @@ BOOST_AUTO_TEST_CASE( url_recipe )
             xmlFreeDoc(doc);
         }
     }
+    catch ( std::runtime_error &e) {
+        std::cout << "std::runtime error: " << e.what() << std::endl;
+        BOOST_CHECK(false);
+    }
     catch ( ... ) {
-        BOOST_CHECK (false);
+        std::cout << "unknown exception" << std::endl;
+        BOOST_CHECK(false);
     }
 }
 
index 8076928..7a8f28f 100644 (file)
@@ -117,15 +117,19 @@ std::string mp_xml::url_recipe_handle(xmlDoc *doc, std::string recipe)
                             break;
                         }
                 }
-            boost::regex::flag_type b_mode = boost::regex::perl;
-            if (mode.find_first_of('i') != std::string::npos)
-                b_mode |= boost::regex::icase;
-            boost::regex e(pattern, b_mode);
-
-            boost::match_flag_type match_mode = boost::format_first_only;
-            if (mode.find_first_of('g') != std::string::npos)
-                match_mode = boost::format_all;
-            result += regex_replace(text, e, replacement, match_mode);
+            if (pattern.length() == 0)
+                result += text;
+            else
+            {
+                boost::regex::flag_type b_mode = boost::regex::perl;
+                if (mode.find_first_of('i') != std::string::npos)
+                    b_mode |= boost::regex::icase;
+                boost::regex e(pattern, b_mode);
+                boost::match_flag_type match_mode = boost::format_first_only;
+                if (mode.find_first_of('g') != std::string::npos)
+                    match_mode = boost::format_all;
+                result += regex_replace(text, e, replacement, match_mode);
+            }
         }
     }
     return result;