Filter virt_db relays close APDU if received
authorAdam Dickmeiss <adam@indexdata.dk>
Tue, 12 Apr 2011 12:00:35 +0000 (14:00 +0200)
committerAdam Dickmeiss <adam@indexdata.dk>
Tue, 12 Apr 2011 12:01:57 +0000 (14:01 +0200)
Filter virt_db now relays close APDU . Previously, it would just
close the session and throw away the close APDU.

src/filter_virt_db.cpp

index 243f8d7..8d68ceb 100644 (file)
@@ -79,6 +79,7 @@ namespace metaproxy_1 {
             void search(Package &package, Z_APDU *apdu);
             void present(Package &package, Z_APDU *apdu);
             void scan(Package &package, Z_APDU *apdu);
+            int relay_apdu(Package &package, Z_APDU *apdu);
 
             void close(Package &package);
             typedef std::map<std::string,VirtualDB::Set>::iterator Sets_it;
@@ -603,6 +604,27 @@ void yf::VirtualDB::Frontend::present(mp::Package &package, Z_APDU *apdu_req)
     delete id;
 }
 
+int yf::VirtualDB::Frontend::relay_apdu(mp::Package &package, Z_APDU *apdu_req)
+{
+    int no = 0;
+    std::list<BackendPtr>::const_iterator map_it;
+    map_it = m_backend_list.begin();
+    for (; map_it != m_backend_list.end(); map_it++)
+    {
+        BackendPtr b = *map_it;
+        
+        Package relay_package(b->m_backend_session, package.origin());
+        relay_package.copy_filter(package);
+
+        relay_package.request() = yazpp_1::GDU(apdu_req);
+
+        relay_package.move(b->m_route);
+        package.response() = relay_package.response();
+        no++;
+    }
+    return no;
+}
+
 void yf::VirtualDB::Frontend::scan(mp::Package &package, Z_APDU *apdu_req)
 {
     Z_ScanRequest *req = apdu_req->u.scanRequest;
@@ -775,7 +797,15 @@ void yf::VirtualDB::process(mp::Package &package) const
         }
         else if (apdu->which == Z_APDU_close)
         {
-            package.session().close();
+            if (f->relay_apdu(package, apdu) == 0)
+            {
+                mp::odr odr;
+                
+                package.response() = odr.create_close(
+                    apdu, Z_Close_finished, "virt_db");
+                
+                package.session().close();
+            }
         }
         else
         {