Start work on contentProxy support
authorAdam Dickmeiss <adam@indexdata.dk>
Mon, 25 Jul 2011 14:40:35 +0000 (16:40 +0200)
committerAdam Dickmeiss <adam@indexdata.dk>
Mon, 25 Jul 2011 14:40:35 +0000 (16:40 +0200)
New setting in Torus/record contentConnector specifies a connector
to be used for contentProxy. If this is defined (non-zero length)
then content proxy rewrite is performed on generated-url from urlRecipe.
The rewritten server is specified by attribute 'server' in element
contentProxy in zoom filter configureation.

etc/config-zoom.xml
src/filter_zoom.cpp
xml/schema/filter_zoom.rnc
xml/schema/filter_zoom.rng
xml/schema/filter_zoom.xsd

index 659fa94..531963f 100644 (file)
@@ -24,6 +24,7 @@
            <transform>tmarc.xsl</transform>
            <urlRecipe>http://sever.com?title=${md-title[\s+/+/g]}</urlRecipe>
            <zurl>localhost:9999/db01</zurl>
+           <contentConnector>connectorfile</contentConnector>
          </record>
          <record>
            <piggyback>1</piggyback>
@@ -73,6 +74,7 @@
           <attr type="1" value="12"/>
         </qual>
       </cclmap>
+      <contentProxy server="proxy.indexdata.com"/>
     </filter>
   </filters>
   <routes>  
index e9fd0db..7476417 100644 (file)
@@ -63,6 +63,7 @@ namespace metaproxy_1 {
             std::string record_encoding;
             std::string transform_xsl_fname;
             std::string urlRecipe;
+            std::string contentConnector;
             bool use_turbomarc;
             bool piggyback;
             CCL_bibset ccl_bibset;
@@ -140,6 +141,7 @@ namespace metaproxy_1 {
             std::map<std::string,std::string> fieldmap;
             std::string xsldir;
             std::string file_path;
+            std::string content_proxy_server;
             CCL_bibset bibset;
             std::string element_transform;
             std::string element_raw;
@@ -387,6 +389,11 @@ yf::Zoom::SearchablePtr yf::Zoom::Impl::parse_torus_record(const xmlNode *ptr)
         {
             s->cfSubDb = mp::xml::get_text(ptr);
         }  
+        else if (!strcmp((const char *) ptr->name,
+                         "contentConnector"))
+        {
+            s->contentConnector = mp::xml::get_text(ptr);
+        }  
         else if (!strcmp((const char *) ptr->name, "udb"))
         {
             s->udb = mp::xml::get_text(ptr);
@@ -553,6 +560,19 @@ void yf::Zoom::Impl::configure(const xmlNode *ptr, bool test_only,
             if (cql_field.length())
                 fieldmap[cql_field] = ccl_field;
         }
+        else if (!strcmp((const char *) ptr->name, "contentProxy"))
+        {
+            const struct _xmlAttr *attr;
+            for (attr = ptr->properties; attr; attr = attr->next)
+            {
+                if (!strcmp((const char *) attr->name, "server"))
+                    content_proxy_server = mp::xml::get_text(attr->children);
+                else
+                    throw mp::filter::FilterException(
+                        "Bad attribute " + std::string((const char *)
+                                                       attr->name));
+            }
+        }
         else
         {
             throw mp::filter::FilterException
@@ -936,6 +956,20 @@ Z_Records *yf::Zoom::Frontend::get_records(Odr_int start,
                     xmlDoc *doc = xmlParseMemory(rec_buf, rec_len);
                     std::string res = 
                         mp::xml::url_recipe_handle(doc, b->sptr->urlRecipe);
+                    if (res.length() && b->sptr->contentConnector.length())
+                    {
+                        yaz_log(YLOG_LOG, "contentConnector: %s",
+                                b->sptr->contentConnector.c_str());
+                        size_t off = res.find_first_of("://");
+                        if (off != std::string::npos)
+                        {
+                            char tmp[1024];
+                            long id = 12345;
+                            sprintf(tmp, "%ld.%s/",
+                                    id, m_p->content_proxy_server.c_str());
+                            res.insert(off + 3, tmp);
+                        }
+                    }
                     if (res.length())
                     {
                         xmlNode *ptr = xmlDocGetRootElement(doc);
index 75494bb..ab03ddc 100644 (file)
@@ -32,7 +32,8 @@ filter_zoom =
         element mp:zurl { xsd:string },
         element mp:cfAuth { xsd:string }?,
         element mp:cfProxy { xsd:string }?,
-        element mp:cfSubDb { xsd:string }?
+        element mp:cfSubDb { xsd:string }?,
+        element mp:contentConnector { xsd:string }?
       }*
     }?
   }?,
@@ -48,6 +49,10 @@ filter_zoom =
         attribute value { xsd:string }
       }+
     }*
+  }?,
+  element mp:contentProxy {
+    attribute server { xsd:string }
   }?
 
 
+
index 16f04d1..981f5b9 100644 (file)
                     <data type="string"/>
                   </element>
                 </optional>
+                <optional>
+                  <element name="mp:contentConnector">
+                    <data type="string"/>
+                  </element>
+                </optional>
               </element>
             </zeroOrMore>
           </element>
         </zeroOrMore>
       </element>
     </optional>
+    <optional>
+      <element name="mp:contentProxy">
+        <attribute name="server">
+          <data type="string"/>
+        </attribute>
+      </element>
+    </optional>
   </define>
 </grammar>
index fe9c5a6..17ea392 100644 (file)
@@ -8,6 +8,7 @@
       <xs:element minOccurs="0" ref="mp:torus"/>
       <xs:element minOccurs="0" maxOccurs="unbounded" ref="mp:fieldmap"/>
       <xs:element minOccurs="0" ref="mp:cclmap"/>
+      <xs:element minOccurs="0" ref="mp:contentProxy"/>
     </xs:sequence>
   </xs:group>
   <xs:element name="torus">
@@ -51,6 +52,7 @@
         <xs:element minOccurs="0" ref="mp:cfAuth"/>
         <xs:element minOccurs="0" ref="mp:cfProxy"/>
         <xs:element minOccurs="0" ref="mp:cfSubDb"/>
+        <xs:element minOccurs="0" ref="mp:contentConnector"/>
       </xs:sequence>
     </xs:complexType>
   </xs:element>
@@ -74,6 +76,7 @@
   <xs:element name="cfAuth" type="xs:string"/>
   <xs:element name="cfProxy" type="xs:string"/>
   <xs:element name="cfSubDb" type="xs:string"/>
+  <xs:element name="contentConnector" type="xs:string"/>
   <xs:element name="fieldmap">
     <xs:complexType>
       <xs:attribute name="cql" use="required" type="xs:string"/>
       <xs:attribute name="value" use="required" type="xs:string"/>
     </xs:complexType>
   </xs:element>
+  <xs:element name="contentProxy">
+    <xs:complexType>
+      <xs:attribute name="server" use="required" type="xs:string"/>
+    </xs:complexType>
+  </xs:element>
   <xs:attributeGroup name="filter_zoom">
     <xs:attribute name="type" use="required">
       <xs:simpleType>