zoom: create temp for contentProxy
authorAdam Dickmeiss <adam@indexdata.dk>
Tue, 26 Jul 2011 13:05:21 +0000 (15:05 +0200)
committerAdam Dickmeiss <adam@indexdata.dk>
Tue, 26 Jul 2011 13:05:21 +0000 (15:05 +0200)
The temporary file name is configable by tmp_file attribute of element
contentProxy of the zoom filter.

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

index 531963f..a61addc 100644 (file)
           <attr type="1" value="12"/>
         </qual>
       </cclmap>
-      <contentProxy server="proxy.indexdata.com"/>
+      <contentProxy
+         server="proxy.indexdata.com"
+         tmp_file="/tmp/mp_content_proxy."
+      />
     </filter>
   </filters>
   <routes>  
index 7476417..dc7d574 100644 (file)
@@ -79,6 +79,7 @@ namespace metaproxy_1 {
             std::string m_frontend_database;
             SearchablePtr sptr;
             xsltStylesheetPtr xsp;
+            std::string content_session_id;
         public:
             Backend(SearchablePtr sptr);
             ~Backend();
@@ -142,6 +143,7 @@ namespace metaproxy_1 {
             std::string xsldir;
             std::string file_path;
             std::string content_proxy_server;
+            std::string content_tmp_file;
             CCL_bibset bibset;
             std::string element_transform;
             std::string element_raw;
@@ -508,6 +510,7 @@ void yf::Zoom::Impl::configure_local_records(const xmlNode *ptr, bool test_only)
 void yf::Zoom::Impl::configure(const xmlNode *ptr, bool test_only,
                                const char *path)
 {
+    content_tmp_file = "/tmp/mp_content_proxy.";
     if (path && *path)
     {
         file_path = path;
@@ -567,6 +570,8 @@ void yf::Zoom::Impl::configure(const xmlNode *ptr, bool test_only,
             {
                 if (!strcmp((const char *) attr->name, "server"))
                     content_proxy_server = mp::xml::get_text(attr->children);
+                else if (!strcmp((const char *) attr->name, "tmp_file"))
+                    content_tmp_file = mp::xml::get_text(attr->children);
                 else
                     throw mp::filter::FilterException(
                         "Bad attribute " + std::string((const char *)
@@ -790,6 +795,36 @@ yf::Zoom::BackendPtr yf::Zoom::Frontend::get_backend_from_databases(
 
     if (sru_proxy)
         b->set_option("proxy", sru_proxy);
+    
+    if (b->sptr->contentConnector.length())
+    {
+        int fd;
+        
+        char *fname = (char *) xmalloc(m_p->content_tmp_file.length() + 8);
+        strcpy(fname, m_p->content_tmp_file.c_str());
+        strcat(fname, "XXXXXX");
+        fd = mkstemp(fname);
+        
+        if (fd == -1)
+        {
+            yaz_log(YLOG_WARN|YLOG_ERRNO, "create %s", fname);
+            *error = YAZ_BIB1_TEMPORARY_SYSTEM_ERROR;
+            *addinfo = (char *)  odr_malloc(odr, 40 + strlen(fname));
+            sprintf(*addinfo, "Could not create %s", fname);
+
+            xfree(fname);
+            BackendPtr backend_null;
+            return backend_null;
+        }
+        b->content_session_id.assign(fname + (strlen(fname) - 6));
+        char buf[1024];
+        sprintf(buf, "#content_proxy\n");
+        write(fd, buf, strlen(buf));
+        close(fd);
+        yaz_log(YLOG_LOG, "file %s created\n", fname);
+        xfree(fname);
+    }
+    
 
     std::string url;
     if (sptr->sru.length())
@@ -956,17 +991,16 @@ 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())
+                    if (res.length() && b->content_session_id.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());
+                            sprintf(tmp, "%s.%s/",
+                                    b->content_session_id.c_str(),
+                                    m_p->content_proxy_server.c_str());
                             res.insert(off + 3, tmp);
                         }
                     }
index ab03ddc..40ff2ca 100644 (file)
@@ -51,7 +51,8 @@ filter_zoom =
     }*
   }?,
   element mp:contentProxy {
-    attribute server { xsd:string }
+    attribute server { xsd:string }?,
+    attribute tmp_file { xsd:string }?
   }?
 
 
index 981f5b9..bffc0cc 100644 (file)
     </optional>
     <optional>
       <element name="mp:contentProxy">
-        <attribute name="server">
-          <data type="string"/>
-        </attribute>
+        <optional>
+          <attribute name="server">
+            <data type="string"/>
+          </attribute>
+        </optional>
+        <optional>
+          <attribute name="tmp_file">
+            <data type="string"/>
+          </attribute>
+        </optional>
       </element>
     </optional>
   </define>
index 17ea392..13ec017 100644 (file)
   </xs:element>
   <xs:element name="contentProxy">
     <xs:complexType>
-      <xs:attribute name="server" use="required" type="xs:string"/>
+      <xs:attribute name="server" type="xs:string"/>
+      <xs:attribute name="tmp_file" type="xs:string"/>
     </xs:complexType>
   </xs:element>
   <xs:attributeGroup name="filter_zoom">