Use rand rather than mkstemp for session
[metaproxy-moved-to-github.git] / src / filter_zoom.cpp
index f2b8f54..1c2ff9a 100644 (file)
@@ -17,6 +17,10 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */
 
 #include "config.hpp"
+
+#include <stdlib.h>
+#include <sys/types.h>
+#include <fcntl.h>
 #include "filter_zoom.hpp"
 #include <yaz/zoom.h>
 #include <yaz/yaz-version.h>
@@ -365,6 +369,8 @@ yf::Zoom::Impl::Impl() :
     apdu_log(false), element_transform("pz2") , element_raw("raw")
 {
     bibset = ccl_qual_mk();
+
+    srand(time(0));
 }
 
 yf::Zoom::Impl::~Impl()
@@ -521,7 +527,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.";
+    content_tmp_file = "/tmp/cf.XXXXXX.p";
     if (path && *path)
     {
         file_path = path;
@@ -831,13 +837,23 @@ yf::Zoom::BackendPtr yf::Zoom::Frontend::get_backend_from_databases(
     }
     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);
-        
+        int suffixlen;
+        char *xx = strstr(fname, "XXXXXX");
+        if (xx)
+            suffixlen = strlen(xx) - 6;
+        else
+        {
+            suffixlen = 0;
+            xx = fname + strlen(fname);
+            strcat(fname, "XXXXXX");
+        }
+        char tmp_char = xx[6];
+        sprintf(xx, "%06d", ((unsigned) rand()) % 1000000);
+        xx[6] = tmp_char;
+
+        int fd = creat(fname, 0666);
         if (fd == -1)
         {
             yaz_log(YLOG_WARN|YLOG_ERRNO, "create %s", fname);
@@ -848,7 +864,7 @@ yf::Zoom::BackendPtr yf::Zoom::Frontend::get_backend_from_databases(
             BackendPtr backend_null;
             return backend_null;
         }
-        b->content_session_id.assign(fname + (strlen(fname) - 6));
+        b->content_session_id.assign(xx, 6);
         WRBUF w = wrbuf_alloc();
         wrbuf_puts(w, "#content_proxy\n");
         wrbuf_printf(w, "connector: %s\n", b->sptr->contentConnector.c_str());
@@ -866,7 +882,6 @@ yf::Zoom::BackendPtr yf::Zoom::Frontend::get_backend_from_databases(
         yaz_log(YLOG_LOG, "file %s created\n", fname);
         xfree(fname);
     }
-    
 
     std::string url;
     if (sptr->sru.length())