Handle Z39.50 Options better
authorAdam Dickmeiss <adam@indexdata.dk>
Tue, 25 Oct 2005 15:19:39 +0000 (15:19 +0000)
committerAdam Dickmeiss <adam@indexdata.dk>
Tue, 25 Oct 2005 15:19:39 +0000 (15:19 +0000)
src/filter_backend_test.cpp
src/filter_virt_db.cpp

index f4f0b16..0a050ff 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: filter_backend_test.cpp,v 1.1 2005-10-25 11:48:30 adam Exp $
+/* $Id: filter_backend_test.cpp,v 1.2 2005-10-25 15:19:39 adam Exp $
    Copyright (c) 2005, Index Data.
 
 %LICENSE%
@@ -64,9 +64,9 @@ void yf::Backend_test::process(Package &package) const
             
             int i;
             static const int masks[] = {
-                Z_Options_search, Z_Options_present, 0 
+                Z_Options_search, Z_Options_present, -1 
             };
-            for (i = 0; masks[i]; i++)
+            for (i = 0; masks[i] != -1; i++)
                 if (ODR_MASK_GET(req->options, masks[i]))
                     ODR_MASK_SET(resp->options, masks[i]);
             if (m_p->m_support_named_result_sets)
@@ -76,6 +76,18 @@ void yf::Backend_test::process(Package &package) const
                 else
                     m_p->m_support_named_result_sets = false;
             }
+            static const int versions[] = {
+                Z_ProtocolVersion_1,
+                Z_ProtocolVersion_2,
+                Z_ProtocolVersion_3,
+                -1
+            };
+            for (i = 0; versions[i] != -1; i++)
+                if (ODR_MASK_GET(req->protocolVersion, versions[i]))
+                    ODR_MASK_SET(resp->protocolVersion, versions[i]);
+                else
+                    break;
+
         }
         else if (apdu_req->which == Z_APDU_searchRequest)
         { 
index 1902d61..4c34f00 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: filter_virt_db.cpp,v 1.3 2005-10-25 11:48:30 adam Exp $
+/* $Id: filter_virt_db.cpp,v 1.4 2005-10-25 15:19:39 adam Exp $
    Copyright (c) 2005, Index Data.
 
 %LICENSE%
@@ -137,10 +137,13 @@ void yf::Virt_db::Rep::present(Package &package, Z_APDU *apdu, bool &move_later)
             Z_APDU *apdu = zget_APDU(odr, Z_APDU_close);
             
             *apdu->u.close->closeReason = Z_Close_protocolError;
+            apdu->u.close->diagnosticInformation =
+                odr_strdup(odr, "no session for present request");
             
             package.response() = apdu;
             package.session().close();
             odr_destroy(odr);
+            assert(false);
             return;
         }
         if (it->second.m_use_vhost)
@@ -351,12 +354,24 @@ void yf::Virt_db::Rep::init(Package &package, Z_APDU *apdu, bool &move_later)
         
         int i;
         static const int masks[] = {
-            Z_Options_search, Z_Options_present, Z_Options_namedResultSets, 0 
+            Z_Options_search, Z_Options_present, Z_Options_namedResultSets, -1 
         };
-        for (i = 0; masks[i]; i++)
+        for (i = 0; masks[i] != -1; i++)
             if (ODR_MASK_GET(req->options, masks[i]))
                 ODR_MASK_SET(resp->options, masks[i]);
         
+        static const int versions[] = {
+            Z_ProtocolVersion_1,
+            Z_ProtocolVersion_2,
+            Z_ProtocolVersion_3,
+            -1
+        };
+        for (i = 0; versions[i] != -1; i++)
+            if (ODR_MASK_GET(req->protocolVersion, versions[i]))
+                ODR_MASK_SET(resp->protocolVersion, versions[i]);
+            else
+                break;
+
         package.response() = apdu;
         
         odr_destroy(odr);
@@ -404,6 +419,9 @@ void yf::Virt_db::process(Package &package) const
             Z_APDU *apdu = zget_APDU(odr, Z_APDU_close);
             
             *apdu->u.close->closeReason = Z_Close_protocolError;
+
+            apdu->u.close->diagnosticInformation =
+                odr_strdup(odr, "unsupported APDU in filter_virt_db");
             
             package.response() = apdu;
             package.session().close();