Int casts (Odr_int stuff)
[metaproxy-moved-to-github.git] / src / filter_zoom.cpp
index 17065a0..2c70e94 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>
@@ -49,7 +53,8 @@ namespace yf = mp::filter;
 
 namespace metaproxy_1 {
     namespace filter {
-        struct Zoom::Searchable : boost::noncopyable {
+        class Zoom::Searchable : boost::noncopyable {
+          public:
             std::string authentication;
             std::string cfAuth;
             std::string cfProxy;
@@ -365,6 +370,8 @@ yf::Zoom::Impl::Impl() :
     apdu_log(false), element_transform("pz2") , element_raw("raw")
 {
     bibset = ccl_qual_mk();
+
+    srand((unsigned int) time(0));
 }
 
 yf::Zoom::Impl::~Impl()
@@ -732,6 +739,10 @@ yf::Zoom::BackendPtr yf::Zoom::Frontend::get_backend_from_databases(
     if (m_p->apdu_log) 
         b->set_option("apdulog", "1");
 
+    if (sptr->piggyback)
+        b->set_option("count", "10");
+    b->set_option("piggyback", sptr->piggyback ? "1" : "0");
+
     std::string authentication = sptr->authentication;
     std::string proxy = sptr->cfProxy;
         
@@ -833,17 +844,17 @@ yf::Zoom::BackendPtr yf::Zoom::Frontend::get_backend_from_databases(
     {
         char *fname = (char *) xmalloc(m_p->content_tmp_file.length() + 8);
         strcpy(fname, m_p->content_tmp_file.c_str());
-        int suffixlen;
         char *xx = strstr(fname, "XXXXXX");
-        if (xx)
-            suffixlen = strlen(xx) - 6;
-        else
+        if (!xx)
         {
-            suffixlen = 0;
             xx = fname + strlen(fname);
             strcat(fname, "XXXXXX");
         }
-        int fd = mkstemps(fname, suffixlen);
+        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);
@@ -917,7 +928,7 @@ Z_Records *yf::Zoom::Frontend::get_records(Odr_int start,
         number_to_present = 10000;
     
     ZOOM_record *recs = (ZOOM_record *)
-        odr_malloc(odr, number_to_present * sizeof(*recs));
+        odr_malloc(odr, (size_t) number_to_present * sizeof(*recs));
 
     char oid_name_str[OID_STR_MAX];
     const char *syntax_name = 0;
@@ -966,7 +977,7 @@ Z_Records *yf::Zoom::Frontend::get_records(Odr_int start,
 
     b->present(start, number_to_present, recs, error, addinfo, odr);
 
-    Odr_int i = 0;
+    int i = 0;
     if (!*error)
     {
         for (i = 0; i < number_to_present; i++)