Happy new year
[metaproxy-moved-to-github.git] / src / filter_multi.cpp
index 33367e7..53912ee 100644 (file)
@@ -1,5 +1,5 @@
 /* This file is part of Metaproxy.
-   Copyright (C) 2005-2009 Index Data
+   Copyright (C) 2005-2011 Index Data
 
 Metaproxy is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free
@@ -20,15 +20,15 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
 #include "config.hpp"
 
-#include "filter.hpp"
-#include "package.hpp"
+#include <metaproxy/filter.hpp>
+#include <metaproxy/package.hpp>
 
 #include <boost/thread/thread.hpp>
 #include <boost/thread/mutex.hpp>
 #include <boost/thread/condition.hpp>
 #include <boost/shared_ptr.hpp>
 
-#include "util.hpp"
+#include <metaproxy/util.hpp>
 #include "filter_multi.hpp"
 
 #include <yaz/zgdu.h>
@@ -417,6 +417,8 @@ void yf::Multi::Frontend::init(mp::Package &package, Z_GDU *gdu)
         mp::util::set_vhost_otherinfo(&init_apdu->u.initRequest->otherInfo,
                                        odr, vhost_one);
 
+        init_apdu->u.initRequest->idAuthentication = req->idAuthentication;
+
         Z_InitRequest *req = init_apdu->u.initRequest;
         
         ODR_MASK_SET(req->options, Z_Options_search);
@@ -461,8 +463,6 @@ void yf::Multi::Frontend::init(mp::Package &package, Z_GDU *gdu)
             bit = m_backend_list.erase(bit);
             continue;
         }
-        no_succeeded++;
-
         Z_GDU *gdu = p->response().get();
         if (gdu && gdu->which == Z_GDU_Z3950 && gdu->u.z3950->which ==
             Z_APDU_initResponse)
@@ -481,28 +481,30 @@ void yf::Multi::Frontend::init(mp::Package &package, Z_GDU *gdu)
             for (i = 0; i <= Z_ProtocolVersion_3; i++)
                 if (!ODR_MASK_GET(b_resp->protocolVersion, i))
                     ODR_MASK_CLEAR(f_resp->protocolVersion, i);
-            // reject if any of the backends reject
-            if (!*b_resp->result)
-                *f_resp->result = 0;
+            if (*b_resp->result)
+                no_succeeded++;
+            else
+                no_failed++;
         }
         else
-        {
-            // if any target does not return init return that (close or
-            // similar )
-            package.response() = p->response();
-            return;
-        }
+            no_failed++;
         bit++;
     }
     if (m_p->m_hide_unavailable)
     {
         if (no_succeeded == 0)
+        {
+            *f_resp->result = 0;
             package.session().close();
+        }
     }
     else
     {
         if (no_failed)
+        {
+            *f_resp->result = 0;
             package.session().close();
+        }
     }
     package.response() = f_apdu;
 }
@@ -766,6 +768,14 @@ void yf::Multi::Frontend::present(mp::Package &package, Z_APDU *apdu_req)
         f_resp->records = z_records_diag;
         *f_resp->presentStatus = Z_PresentStatus_failure;
     }
+    else if (number < 0 || (size_t) number > jobs.size())
+    {
+        f_apdu = 
+            odr.create_presentResponse(
+                apdu_req,
+                YAZ_BIB1_PRESENT_REQUEST_OUT_OF_RANGE,
+                0);
+    }
     else
     {
         f_resp->records = (Z_Records *) odr_malloc(odr, sizeof(Z_Records));
@@ -976,7 +986,7 @@ void yf::Multi::Frontend::scan2(mp::Package &package, Z_APDU *apdu_req)
                     {
                         ScanTermInfo my;
 
-                        int *occur = ent->u.termInfo->globalOccurrences;
+                        Odr_int *occur = ent->u.termInfo->globalOccurrences;
                         my.m_count = occur ? *occur : 0;
 
                         if (ent->u.termInfo->term->which == Z_Term_general)
@@ -1017,7 +1027,7 @@ void yf::Multi::Frontend::scan2(mp::Package &package, Z_APDU *apdu_req)
                     {
                         ScanTermInfo my;
 
-                        int *occur = ent->u.termInfo->globalOccurrences;
+                        Odr_int *occur = ent->u.termInfo->globalOccurrences;
                         my.m_count = occur ? *occur : 0;
 
                         if (ent->u.termInfo->term->which == Z_Term_general)