More functional virt_db filter. Removed p2_* source
authorAdam Dickmeiss <adam@indexdata.dk>
Tue, 25 Oct 2005 11:48:30 +0000 (11:48 +0000)
committerAdam Dickmeiss <adam@indexdata.dk>
Tue, 25 Oct 2005 11:48:30 +0000 (11:48 +0000)
20 files changed:
src/Makefile.am
src/filter_backend_test.cpp [new file with mode: 0644]
src/filter_backend_test.hpp [new file with mode: 0644]
src/filter_log.cpp
src/filter_log.hpp
src/filter_virt_db.cpp
src/p2_backend.h [deleted file]
src/p2_backend_dummy.cpp [deleted file]
src/p2_config.cpp [deleted file]
src/p2_config.h [deleted file]
src/p2_frontend.cpp [deleted file]
src/p2_frontend.h [deleted file]
src/p2_modules.cpp [deleted file]
src/p2_modules.h [deleted file]
src/p2_msg.cpp [deleted file]
src/p2_xmlerror.cpp [deleted file]
src/p2_xmlerror.h [deleted file]
src/session.hpp
src/test_filter_log.cpp
src/test_filter_virt_db.cpp

index 76c620a..021dc3d 100644 (file)
@@ -1,4 +1,4 @@
-## $Id: Makefile.am,v 1.23 2005-10-24 14:33:30 adam Exp $
+## $Id: Makefile.am,v 1.24 2005-10-25 11:48:30 adam Exp $
 
 MAINTAINERCLEANFILES = Makefile.in config.in config.hpp
 
@@ -15,7 +15,8 @@ libyp2_la_SOURCES = \
        filter_frontend_net.cpp filter_frontend_net.hpp \
        filter_log.cpp filter_log.hpp \
        filter_virt_db.cpp filter_virt_db.hpp \
-       filter_z3950_client.cpp filter_z3950_client.hpp
+       filter_z3950_client.cpp filter_z3950_client.hpp \
+       filter_backend_test.cpp filter_backend_test.hpp
 
 # Rules for programs..
 
diff --git a/src/filter_backend_test.cpp b/src/filter_backend_test.cpp
new file mode 100644 (file)
index 0000000..f4f0b16
--- /dev/null
@@ -0,0 +1,124 @@
+/* $Id: filter_backend_test.cpp,v 1.1 2005-10-25 11:48:30 adam Exp $
+   Copyright (c) 2005, Index Data.
+
+%LICENSE%
+ */
+
+#include "config.hpp"
+
+#include "filter.hpp"
+#include "router.hpp"
+#include "package.hpp"
+
+#include <boost/thread/mutex.hpp>
+
+#include "filter_backend_test.hpp"
+
+#include <yaz/zgdu.h>
+#include <yaz/log.h>
+#include <yaz/otherinfo.h>
+#include <yaz/diagbib1.h>
+
+#include <list>
+#include <map>
+#include <iostream>
+
+namespace yf = yp2::filter;
+
+namespace yp2 {
+    namespace filter {
+        class Backend_test::Rep {
+            friend class Backend_test;
+            
+        private:
+            bool m_support_named_result_sets;
+        };
+    }
+}
+
+yf::Backend_test::Backend_test() {
+    m_p = new Backend_test::Rep;
+    m_p->m_support_named_result_sets = false;
+}
+
+yf::Backend_test::~Backend_test() {
+    delete m_p;
+}
+
+void yf::Backend_test::process(Package &package) const
+{
+    Z_GDU *gdu = package.request().get();
+
+    if (!gdu || gdu->which != Z_GDU_Z3950)
+        package.move();
+    else
+    {
+        Z_APDU *apdu_req = gdu->u.z3950;
+        Z_APDU *apdu_res = 0;
+        ODR odr = odr_createmem(ODR_ENCODE);
+        if (apdu_req->which == Z_APDU_initRequest)
+        {
+            apdu_res = zget_APDU(odr, Z_APDU_initResponse);
+            Z_InitRequest *req = apdu_req->u.initRequest;
+            Z_InitResponse *resp = apdu_res->u.initResponse;
+            
+            int i;
+            static const int masks[] = {
+                Z_Options_search, Z_Options_present, 0 
+            };
+            for (i = 0; masks[i]; i++)
+                if (ODR_MASK_GET(req->options, masks[i]))
+                    ODR_MASK_SET(resp->options, masks[i]);
+            if (m_p->m_support_named_result_sets)
+            {
+                if (ODR_MASK_GET(req->options, Z_Options_namedResultSets))
+                    ODR_MASK_SET(resp->options, Z_Options_namedResultSets);
+                else
+                    m_p->m_support_named_result_sets = false;
+            }
+        }
+        else if (apdu_req->which == Z_APDU_searchRequest)
+        { 
+            apdu_res = zget_APDU(odr, Z_APDU_searchResponse);
+            Z_SearchRequest *req = apdu_req->u.searchRequest;
+            Z_SearchResponse *resp = apdu_res->u.searchResponse;
+
+            if (!m_p->m_support_named_result_sets && 
+                strcmp(req->resultSetName, "default"))
+            {
+                Z_Records *rec = (Z_Records *)
+                    odr_malloc(odr, sizeof(Z_Records));
+                resp->records = rec;
+                rec->which = Z_Records_NSD;
+                rec->u.nonSurrogateDiagnostic =
+                    zget_DefaultDiagFormat(
+                        odr, YAZ_BIB1_RESULT_SET_NAMING_UNSUPP, 0);
+            }
+            else
+                *resp->resultCount = 42;
+        }
+        else if (apdu_req->which == Z_APDU_presentRequest)
+        { 
+            apdu_res = zget_APDU(odr, Z_APDU_presentResponse);
+        }
+        else
+        {
+            apdu_res = zget_APDU(odr, Z_APDU_close);            
+            *apdu_res->u.close->closeReason = Z_Close_protocolError;
+            package.session().close();
+        }
+        if (apdu_res)
+            package.response() = apdu_res;
+        odr_destroy(odr);
+    }
+}
+
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * c-file-style: "stroustrup"
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
diff --git a/src/filter_backend_test.hpp b/src/filter_backend_test.hpp
new file mode 100644 (file)
index 0000000..da10262
--- /dev/null
@@ -0,0 +1,37 @@
+/* $Id: filter_backend_test.hpp,v 1.1 2005-10-25 11:48:30 adam Exp $
+   Copyright (c) 2005, Index Data.
+
+%LICENSE%
+ */
+
+#ifndef FILTER_BACKEND_TEST_HPP
+#define FILTER_BACKEND_TEST_HPP
+
+#include <stdexcept>
+#include <list>
+
+#include "filter.hpp"
+
+namespace yp2 {
+    namespace filter {
+        class Backend_test : public Base {
+            class Rep;
+        public:
+            ~Backend_test();
+            Backend_test();
+            void process(yp2::Package & package) const;
+        private:
+            Rep *m_p;
+        };
+    }
+}
+
+#endif
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * c-file-style: "stroustrup"
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
index 232fd7a..2cc54a4 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: filter_log.cpp,v 1.5 2005-10-19 22:45:59 marc Exp $
+/* $Id: filter_log.cpp,v 1.6 2005-10-25 11:48:30 adam Exp $
    Copyright (c) 2005, Index Data.
 
 %LICENSE%
@@ -33,19 +33,18 @@ void yp2::filter::Log::process(Package &package) const {
     // scope for locking Ostream 
     { 
         boost::mutex::scoped_lock scoped_lock(m_log_mutex);
-        std::cout << receive_time << " ";
-        std::cout << "request id=" << package.session().id();
+        std::cout << receive_time << " " << m_msg;
+        std::cout << " request id=" << package.session().id();
         std::cout << " close=" 
                   << (package.session().is_closed() ? "yes" : "no")
                   << "\n";
-    }
-    
-    gdu = package.request().get();
-    if (gdu)
-    {
-       ODR odr = odr_createmem(ODR_PRINT);
-       z_GDU(odr, &gdu, 0, 0);
-       odr_destroy(odr);
+        gdu = package.request().get();
+        if (gdu)
+        {
+            ODR odr = odr_createmem(ODR_PRINT);
+            z_GDU(odr, &gdu, 0, 0);
+            odr_destroy(odr);
+        }
     }
 
     // unlocked during move
@@ -60,8 +59,8 @@ void yp2::filter::Log::process(Package &package) const {
     // scope for locking Ostream 
     { 
         boost::mutex::scoped_lock scoped_lock(m_log_mutex);
-        std::cout << send_time << " ";
-        std::cout << "response id=" << package.session().id();
+        std::cout << send_time << " " << m_msg;
+        std::cout << " response id=" << package.session().id();
         std::cout << " close=" 
                   << (package.session().is_closed() ? "yes " : "no ")
                   << "duration=" << duration      
@@ -80,6 +79,11 @@ void yp2::filter::Log::process(Package &package) const {
     }
 }
 
+void yp2::filter::Log::set_prefix(const std::string &msg)
+{
+    m_msg = msg;
+}
+
 // defining and initializing static members
 boost::mutex yp2::filter::Log::m_log_mutex;
 
index 60d1425..c8d3f85 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: filter_log.hpp,v 1.5 2005-10-19 22:45:59 marc Exp $
+/* $Id: filter_log.hpp,v 1.6 2005-10-25 11:48:30 adam Exp $
    Copyright (c) 2005, Index Data.
 
 %LICENSE%
@@ -20,10 +20,12 @@ namespace yp2 {
         class Log : public Base {
         public:
             Log();
-            void process(yp2::Package & package) const;       
+            void process(yp2::Package & package) const;
+            void set_prefix(const std::string &msg);
         private:
             /// static mutex to lock Ostream during logging operation
             static boost::mutex m_log_mutex;
+            std::string m_msg;
         };
     }
 }
index 2a86b79..1902d61 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: filter_virt_db.cpp,v 1.2 2005-10-24 21:01:53 adam Exp $
+/* $Id: filter_virt_db.cpp,v 1.3 2005-10-25 11:48:30 adam Exp $
    Copyright (c) 2005, Index Data.
 
 %LICENSE%
@@ -28,8 +28,9 @@ namespace yf = yp2::filter;
 namespace yp2 {
     namespace filter {
         struct Virt_db_set {
-            Virt_db_set(yp2::Session &id, Z_InternationalString *setname,
+            Virt_db_set(yp2::Session &id, std::string setname,
                         std::string vhost);
+            Virt_db_set();
             ~Virt_db_set();
 
             yp2::Session m_session;
@@ -38,9 +39,10 @@ namespace yp2 {
         };
         struct Virt_db_session {
             Virt_db_session(yp2::Session &id, bool use_vhost);
+            Virt_db_session();
             yp2::Session m_session;
             bool m_use_vhost;
-            std::list<Virt_db_set> m_sets;
+            std::map<std::string,Virt_db_set> m_sets;
         };
         struct Virt_db_map {
             Virt_db_map(std::string vhost);
@@ -53,20 +55,30 @@ namespace yp2 {
             void release_session(Package &package);
             void init(Package &package, Z_APDU *apdu, bool &move_later);
             void search(Package &package, Z_APDU *apdu, bool &move_later);
+            void present(Package &package, Z_APDU *apdu, bool &move_later);
         private:
             boost::mutex m_sessions_mutex;
-            std::list<Virt_db_session>m_sessions;
+            std::map<yp2::Session,Virt_db_session>m_sessions;
             std::map<std::string, Virt_db_map>m_maps;
+
+            typedef std::map<yp2::Session,Virt_db_session>::iterator Ses_it;
+            typedef std::map<std::string,Virt_db_set>::iterator Sets_it;
         };
     }
 }
 
-yf::Virt_db_set::Virt_db_set(yp2::Session &id, Z_InternationalString *setname,
+yf::Virt_db_set::Virt_db_set(yp2::Session &id, std::string setname,
                              std::string vhost)
     :   m_session(id), m_setname(setname), m_vhost(vhost)
 {
 }
 
+
+yf::Virt_db_set::Virt_db_set()
+{
+}
+
+
 yf::Virt_db_set::~Virt_db_set()
 {
 }
@@ -80,6 +92,12 @@ yf::Virt_db_map::Virt_db_map()
 {
 }
 
+yf::Virt_db_session::Virt_db_session()
+    : m_use_vhost(false)
+{
+
+}
+
 yf::Virt_db_session::Virt_db_session(yp2::Session &id,
                                      bool use_vhost) :
     m_session(id) , m_use_vhost(use_vhost)
@@ -97,20 +115,75 @@ yf::Virt_db::~Virt_db() {
 
 void yf::Virt_db::Rep::release_session(Package &package)
 {
-    if (package.session().is_closed()) 
+    boost::mutex::scoped_lock lock(m_sessions_mutex);
+    
+    Ses_it it = m_sessions.find(package.session());
+    
+    if (it != m_sessions.end())
+        m_sessions.erase(it);
+}
+
+void yf::Virt_db::Rep::present(Package &package, Z_APDU *apdu, bool &move_later){
+    Session *id = 0;
+    Z_PresentRequest *req = apdu->u.presentRequest;
     {
         boost::mutex::scoped_lock lock(m_sessions_mutex);
         
-        std::list<Virt_db_session>::iterator it;
-        for (it = m_sessions.begin(); it != m_sessions.end(); it++)
+        Ses_it it = m_sessions.find(package.session());
+        if (it == m_sessions.end())
         {
-            if (package.session() == (*it).m_session)
-                break;
+            ODR odr = odr_createmem(ODR_ENCODE);
+            
+            Z_APDU *apdu = zget_APDU(odr, Z_APDU_close);
+            
+            *apdu->u.close->closeReason = Z_Close_protocolError;
+            
+            package.response() = apdu;
+            package.session().close();
+            odr_destroy(odr);
+            return;
         }
-        if (it == m_sessions.end())
+        if (it->second.m_use_vhost)
+        {
+            move_later = true;
             return;
-        m_sessions.erase(it);
+        }
+        Sets_it sets_it = it->second.m_sets.find(req->resultSetId);
+        if (sets_it == it->second.m_sets.end())
+        {
+            ODR odr = odr_createmem(ODR_ENCODE);
+            Z_APDU *apdu = zget_APDU(odr, Z_APDU_presentResponse);
+            
+            Z_Records *rec = (Z_Records *) odr_malloc(odr, sizeof(Z_Records));
+            apdu->u.presentResponse->records = rec;
+            rec->which = Z_Records_NSD;
+            rec->u.nonSurrogateDiagnostic =
+                zget_DefaultDiagFormat(
+                    odr,
+                    YAZ_BIB1_SPECIFIED_RESULT_SET_DOES_NOT_EXIST,
+                    req->resultSetId);
+            package.response() = apdu;
+            odr_destroy(odr);
+            return;
+        }
+        id = new yp2::Session(it->second.m_session);
     }
+    ODR odr = odr_createmem(ODR_ENCODE);
+    
+    // sending present to backend
+    Package present_package(*id, package.origin());
+    present_package.copy_filter(package);
+    
+    req->resultSetId = odr_strdup(odr, "default");
+    present_package.request() = yazpp_1::GDU(apdu);
+    
+    odr_destroy(odr);
+    
+    present_package.move();
+
+    package.response() = present_package.response();
+    // must check for a closed present session..
+    delete id;
 }
 
 void yf::Virt_db::Rep::search(Package &package, Z_APDU *apdu, bool &move_later)
@@ -121,20 +194,22 @@ void yf::Virt_db::Rep::search(Package &package, Z_APDU *apdu, bool &move_later)
     Session *id = 0;
     {
         boost::mutex::scoped_lock lock(m_sessions_mutex);
-        
-        std::list<Virt_db_session>::iterator it;
-        for (it = m_sessions.begin(); it != m_sessions.end(); it++)
-        {
-            if (package.session() == (*it).m_session)
-                break;
-        }
+
+        Ses_it it = m_sessions.find(package.session());
         if (it == m_sessions.end())
         {
-            // error should be returned
-            move_later = true;
+            ODR odr = odr_createmem(ODR_ENCODE);
+            
+            Z_APDU *apdu = zget_APDU(odr, Z_APDU_close);
+            
+            *apdu->u.close->closeReason = Z_Close_protocolError;
+            
+            package.response() = apdu;
+            package.session().close();
+            odr_destroy(odr);
             return;
         }
-        if ((*it).m_use_vhost)
+        if (it->second.m_use_vhost)
         {
             move_later = true;
             return;
@@ -174,9 +249,33 @@ void yf::Virt_db::Rep::search(Package &package, Z_APDU *apdu, bool &move_later)
             odr_destroy(odr);
             return;
         }
+        if (*req->replaceIndicator == 0)
+        {
+            Sets_it sets_it = it->second.m_sets.find(req->resultSetName);
+            if (sets_it != it->second.m_sets.end())
+            {
+                ODR odr = odr_createmem(ODR_ENCODE);
+                Z_APDU *apdu = zget_APDU(odr, Z_APDU_searchResponse);
+                
+                Z_Records *rec = (Z_Records *) odr_malloc(odr, sizeof(Z_Records));
+                apdu->u.searchResponse->records = rec;
+                rec->which = Z_Records_NSD;
+                rec->u.nonSurrogateDiagnostic =
+                    zget_DefaultDiagFormat(
+                        odr,
+                        YAZ_BIB1_RESULT_SET_EXISTS_AND_REPLACE_INDICATOR_OFF,
+                        0);
+                package.response() = apdu;
+                
+                odr_destroy(odr);
+                return;
+            }
+        }
         vhost = map_it->second.m_vhost;
         id = new Session;
-        (*it).m_sets.push_back(Virt_db_set(*id, req->resultSetName, vhost));
+
+        it->second.m_sets[req->resultSetName] =
+            Virt_db_set(*id, req->resultSetName, vhost);
     }
     const char *vhost_cstr = vhost.c_str();
     if (true)
@@ -193,7 +292,7 @@ void yf::Virt_db::Rep::search(Package &package, Z_APDU *apdu, bool &move_later)
         init_package.request() = init_apdu;
         odr_destroy(odr);
 
-        init_package.move();  // send init 
+        init_package.move();  // sending init 
 
         if (init_package.session().is_closed())
         {
@@ -214,12 +313,15 @@ void yf::Virt_db::Rep::search(Package &package, Z_APDU *apdu, bool &move_later)
     }
     // sending search to backend
     Package search_package(*id, package.origin());
+
     search_package.copy_filter(package);
     const char *sep = strchr(vhost_cstr, '/');
     ODR odr = odr_createmem(ODR_ENCODE);
     if (sep)
         req->databaseNames[0] = odr_strdup(odr, sep+1);
-    
+
+    *req->replaceIndicator = 1;
+    req->resultSetName = odr_strdup(odr, "default");
     search_package.request() = yazpp_1::GDU(apdu);
     
     odr_destroy(odr);
@@ -227,20 +329,14 @@ void yf::Virt_db::Rep::search(Package &package, Z_APDU *apdu, bool &move_later)
     search_package.move();
 
     package.response() = search_package.response();
+    // must check for a closed search session..
+    delete id;
 }
 
 void yf::Virt_db::Rep::init(Package &package, Z_APDU *apdu, bool &move_later)
 {
+    release_session(package);
     boost::mutex::scoped_lock lock(m_sessions_mutex);
-    std::list<Virt_db_session>::iterator it;
-
-    for (it = m_sessions.begin(); it != m_sessions.end(); it++)
-    {
-        if (package.session() == (*it).m_session)
-            break;
-    }
-    if (it != m_sessions.end())
-        m_sessions.erase(it);
 
     Z_InitRequest *req = apdu->u.initRequest;
     
@@ -255,7 +351,7 @@ 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, 0 
+            Z_Options_search, Z_Options_present, Z_Options_namedResultSets, 0 
         };
         for (i = 0; masks[i]; i++)
             if (ODR_MASK_GET(req->options, masks[i]))
@@ -265,11 +361,11 @@ void yf::Virt_db::Rep::init(Package &package, Z_APDU *apdu, bool &move_later)
         
         odr_destroy(odr);
 
-        m_sessions.push_back(Virt_db_session(package.session(), false));
+        m_sessions[package.session()] = Virt_db_session(package.session(), false);
     }
     else
     {
-        m_sessions.push_back(Virt_db_session(package.session(), true));
+        m_sessions[package.session()] = Virt_db_session(package.session(), true);
         move_later = true;
     }
 }
@@ -297,6 +393,10 @@ void yf::Virt_db::process(Package &package) const
         {
             m_p->search(package, apdu, move_later);
         }
+        else if (apdu->which == Z_APDU_presentRequest)
+        {
+            m_p->present(package, apdu, move_later);
+        }
         else
         {
             ODR odr = odr_createmem(ODR_ENCODE);
@@ -312,7 +412,8 @@ void yf::Virt_db::process(Package &package) const
         if (move_later)
             package.move();
     }
-    m_p->release_session(package);
+    if (package.session().is_closed())
+        m_p->release_session(package);
 }
 
 
diff --git a/src/p2_backend.h b/src/p2_backend.h
deleted file mode 100644 (file)
index b5864b3..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-
-#ifndef P2_BACKEND_H
-#define P2_BACKEND_H
-
-#include <yaz++/z-query.h>
-
-class IP2_BackendSet {
-public:
-    virtual ~IP2_BackendSet();
-    virtual int get(int start, int number) = 0;
-};
-
-class IP2_Backend {
- public:
-    virtual ~IP2_Backend();
-    virtual int search(yazpp_1::Yaz_Z_Query *q, IP2_BackendSet **rset, int *hits) = 0;
-};
-
-struct P2_ModuleInterface0 {
-    IP2_Backend *(*create)(const char *address);
-};
-    
-struct P2_ModuleEntry {
-    int version;
-    const char *name;
-    const char *description;
-    void *interface_ptr;
-};
-
-    
-#endif
diff --git a/src/p2_backend_dummy.cpp b/src/p2_backend_dummy.cpp
deleted file mode 100644 (file)
index 0b0bbdd..0000000
+++ /dev/null
@@ -1,74 +0,0 @@
-#include "config.hpp"
-#include <yaz/log.h>
-#include "p2_backend.h"
-
-class P2_BackendSetDummy : public IP2_BackendSet {
-public:
-    P2_BackendSetDummy();
-    ~P2_BackendSetDummy();
-    int get(int start, int number);
-};
-
-class P2_BackendDummy : public IP2_Backend {
-public:
-    P2_BackendDummy(const char *address);
-    ~P2_BackendDummy();
-    int search(yazpp_1::Yaz_Z_Query *q, IP2_BackendSet **rset, int *hits);
-};
-
-P2_BackendDummy::P2_BackendDummy(const char *address)
-{
-    yaz_log(YLOG_LOG, "P2_backendDummy %p create", this);
-}
-
-P2_BackendDummy::~P2_BackendDummy()
-{
-    yaz_log(YLOG_LOG, "P2_backendDummy %p destroy", this);
-}
-
-int P2_BackendDummy::search(yazpp_1::Yaz_Z_Query *q, IP2_BackendSet **rset,
-                           int *hits)
-{
-    yaz_log(YLOG_LOG, "P2_backendDummy %p search", this);
-
-    P2_BackendSetDummy *s = new P2_BackendSetDummy();
-
-    *rset = s;
-    *hits = 42;
-    return 0;
-}
-
-int P2_BackendSetDummy::get(int start, int number)
-{
-    yaz_log(YLOG_LOG, "P2_backendSetDummy %p get", this);
-    return 0;
-}
-
-P2_BackendSetDummy::P2_BackendSetDummy()
-{
-    yaz_log(YLOG_LOG, "P2_backendSetDummy %p create", this);
-
-}
-
-P2_BackendSetDummy::~P2_BackendSetDummy()
-{
-    yaz_log(YLOG_LOG, "P2_backendSetDummy %p destroy", this);
-}
-
-static IP2_Backend *dummy_create(const char *address)
-{
-    return new P2_BackendDummy(address);
-}
-
-P2_ModuleInterface0 int0 = {
-    dummy_create
-};
-
-P2_ModuleEntry p2_module_entry = {
-    0,
-    "dummy",
-    "Dummy Backend",
-    (void *) &int0
-};
-
-P2_ModuleEntry *p2_backend_dummy = &p2_module_entry;
diff --git a/src/p2_config.cpp b/src/p2_config.cpp
deleted file mode 100644 (file)
index 7bea420..0000000
+++ /dev/null
@@ -1,384 +0,0 @@
-/* $Id: p2_config.cpp,v 1.2 2005-10-07 09:21:41 marc Exp $
-   Copyright (c) 1998-2005, Index Data.
-
-This file is part of the yaz-proxy.
-
-YAZ proxy 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
-Software Foundation; either version 2, or (at your option) any later
-version.
-
-YAZ proxy is distributed in the hope that it will be useful, but WITHOUT ANY
-WARRANTY; without even the implied warranty of MERCHANTABILITY or
-FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-for more details.
-
-You should have received a copy of the GNU General Public License
-along with YAZ proxy; see the file LICENSE.  If not, write to the
-Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
-02111-1307, USA.
- */
-
-#include <stdlib.h>
-#include <string.h>
-#include <yaz/log.h>
-#include <yaz/options.h>
-#include <yaz/diagbib1.h>
-#include "p2_config.h"
-#include "config.hpp"
-
-#if HAVE_XSLT
-#include <libxml/parser.h>
-#include <libxml/tree.h>
-#include <libxml/xinclude.h>
-#include <libxslt/xsltutils.h>
-#include <libxslt/transform.h>
-#endif
-
-#include <iostream>
-
-using namespace std;
-
-class P2_Config::Rep {
-    
-public:
-    Rep();
-    ~Rep();
-public:
-#if HAVE_XSLT
-    xmlDocPtr m_docPtr;
-    xmlNodePtr m_proxyPtr;
-#endif
-};
-
-P2_Config::Rep::Rep()
-{
-#if HAVE_XSLT
-    m_docPtr = 0;
-    m_proxyPtr = 0;
-#endif
-}
-
-P2_Config::Rep::~Rep()
-{
-#if HAVE_XSLT
-    if (m_docPtr)
-        xmlFreeDoc(m_docPtr);
-#endif
-}
-    
-P2_Config::P2_Config()
-{
-    m_max_clients = 500;
-    m_client_idletime = 600;
-    m_debug_mode = 0;
-    m_no_limit_files = 0;
-    m_no_threads = 20;
-    m_target_idletime = 600;
-
-    m_rep = new Rep();
-}
-
-bool P2_Config::parse_options(int argc, char **argv)
-{
-    char *arg;
-    int ret;
-    bool show_config = false;
-    while ((ret = options("o:a:t:v:c:u:i:m:l:T:p:n:h:XS",
-                          argv, argc, &arg)) != -2)
-    {
-        switch (ret)
-        {
-        case 0:
-            if (m_listen_address.length())
-            {
-                yaz_log(YLOG_FATAL, "Multiple listener address given");
-                return false;
-            }
-            m_listen_address = arg;
-            break;
-        case 'a':
-            m_apdu_log = arg;
-            break;
-        case 'c':
-            if (m_xml_fname.length())
-            {
-                yaz_log(YLOG_FATAL, "Multiple -c options given");
-                return false;
-            }
-            if (!read_xml_config(arg))
-            {
-                return false;
-            }
-            m_xml_fname = arg;
-            break;
-        case 'i':
-            m_client_idletime = atoi(arg);
-            break;
-        case 'l':
-            m_log_file = arg;
-            break;
-        case 'm':
-            m_max_clients = atoi(arg);
-            break;
-        case 'n':
-            m_no_limit_files = atoi(arg);
-            break;
-        case 'h':
-            m_no_threads = atoi(arg);
-            break;
-        case 'o':
-            m_optimize_flags = arg;
-            break;
-        case 'p':
-            if (m_pid_fname.length())
-            {
-                yaz_log(YLOG_LOG, "Multiple -p options given");
-                return false;
-            }
-            m_pid_fname = arg;
-            break;
-        case 't':
-            if (m_default_target.length())
-            {
-                yaz_log(YLOG_LOG, "Multiple -t options given");
-                return false;
-            }
-            m_default_target = arg;
-            break;
-        case 'T':
-            m_target_idletime = atoi(arg);
-            break;
-        case 'u':
-            if (m_uid.length())
-            {
-                yaz_log(YLOG_FATAL, "-u specified more than once");
-                return false;
-            }
-            m_uid = arg;
-            break;
-        case 'v':
-            yaz_log_init_level(yaz_log_mask_str(arg));
-            break;
-        case 'X':
-            m_debug_mode = 1;
-            break;
-        case 'S':
-            show_config = true;
-            break;
-        default:
-            yaz_log(YLOG_FATAL, "Bad option %s", arg);
-            return false;
-        }
-    } 
-    if (m_log_file.length())
-        yaz_log_init_file(m_log_file.c_str());
-    if (show_config)
-        print();
-    return true;
-}
-
-bool P2_Config::parse_xml_text(void *xml_ptr, bool &val)
-{
-    string v;
-    if (!parse_xml_text(xml_ptr, v))
-        return false;
-    if (v.length() == 1 && v[0] == '1')
-        val = true;
-    else
-        val = false;
-    return true;
-}
-
-bool P2_Config::parse_xml_text(void *xml_ptr, string &val)
-{
-    xmlNodePtr ptr = (xmlNodePtr) xml_ptr;
-    bool found = false;
-    string v;
-    for(ptr = ptr->children; ptr; ptr = ptr->next)
-        if (ptr->type == XML_TEXT_NODE)
-        {
-            xmlChar *t = ptr->content;
-            if (t)
-            {
-                v += (const char *) t;
-                found = true;
-            }
-        }
-    if (found)
-        val = v;
-    return found;
-}
-
-void P2_Config::parse_xml_element_target(void *xml_ptr,
-                                         P2_ConfigTarget *t)
-{
-    xmlNodePtr ptr = (xmlNodePtr) xml_ptr;
-
-    for (ptr = ptr->children; ptr; ptr = ptr->next)
-    {
-        if (ptr->type != XML_ELEMENT_NODE)
-            continue;
-        if (!strcmp((const char *) ptr->name, "url"))
-        {
-            parse_xml_text(ptr, t->m_target_address);
-        }
-        else if (!strcmp((const char *) ptr->name, "database"))
-        {
-            parse_xml_text(ptr, t->m_target_database);
-        }
-        else
-        {
-            yaz_log(YLOG_WARN, "Unknown element '%s' inside target",
-                    (const char *) ptr->name);
-            m_errors++;
-        }
-    }
-}
-
-void P2_Config::parse_xml_element_proxy(void *xml_ptr)
-{
-    xmlNodePtr ptr = (xmlNodePtr) xml_ptr;
-
-    for (ptr = ptr->children; ptr; ptr = ptr->next)
-    {
-        if (ptr->type != XML_ELEMENT_NODE)
-            continue;
-        if (!strcmp((const char *) ptr->name, "target"))
-        {
-            P2_ConfigTarget *t = new P2_ConfigTarget();
-
-            struct _xmlAttr *attr;
-            for (attr = ptr->properties; attr; attr = attr->next)
-                if (!strcmp((const char *) attr->name, "name")
-                    || !strcmp((const char *) attr->name, "host"))
-                {
-                    parse_xml_text(attr, t->m_virt_address);
-                }
-                else if (!strcmp((const char *) attr->name, "database"))
-                {
-                    parse_xml_text(attr, t->m_virt_database);
-                }
-                else if (!strcmp((const char *) attr->name, "default"))
-                {
-                    parse_xml_text(attr, t->m_default);
-                }
-                else if (!strcmp((const char *) attr->name, "type"))
-                {
-                    parse_xml_text(attr, t->m_type);
-                }
-                else
-                {
-                    yaz_log(YLOG_WARN, "Unknown attribute '%s' for "
-                            "element proxy",
-                            (const char *) attr->name);
-                    m_errors++;
-                }
-            parse_xml_element_target(ptr, t);
-            m_target_list.push_back(t);
-        }
-        else if (!strcmp((const char *) ptr->name, "max-clients"))
-        {
-            string v;
-            if (parse_xml_text(ptr, v))
-                m_max_clients = atoi(v.c_str());
-        }
-        else if (!strcmp((const char *) ptr->name, "module"))
-        {
-            P2_ConfigModule *t = new P2_ConfigModule();
-
-            string v;
-            if (parse_xml_text(ptr, v))
-            {
-                t->m_fname = v;
-                m_modules.push_back(t);
-            }
-        }
-        else
-        {
-            yaz_log(YLOG_WARN, "Unknown element '%s' inside proxy", ptr->name);
-            m_errors++;
-        }
-    }
-}
-
-void P2_Config::print()
-{
-    cout << "max_clients=" << m_max_clients << endl;
-    list<P2_ConfigTarget *>::const_iterator it;
-    
-    for (it = m_target_list.begin(); it != m_target_list.end(); it++)
-    {
-        cout << "type=" << (*it)->m_type << " ";
-        cout << "v-address=" << (*it)->m_virt_address << " ";
-        cout << "v-db=" << (*it)->m_virt_database << " ";
-        cout << "t-address=" << (*it)->m_target_address << " ";
-        cout << "t-db=" << (*it)->m_target_database << " ";
-        cout << "default=" << (*it)->m_default << endl;
-    }
-}
-
-bool P2_Config::read_xml_config(const char *fname)
-{
-    xmlDocPtr ndoc = xmlParseFile(fname);
-
-    if (!ndoc)
-    {
-        yaz_log(YLOG_WARN, "Config file %s not found or parse error", fname);
-        return false;
-    }
-    int noSubstitutions = xmlXIncludeProcess(ndoc);
-    if (noSubstitutions == -1)
-        yaz_log(YLOG_WARN, "XInclude processing failed on config %s", fname);
-
-    xmlNodePtr proxyPtr = xmlDocGetRootElement(ndoc);
-    if (!proxyPtr || proxyPtr->type != XML_ELEMENT_NODE ||
-        strcmp((const char *) proxyPtr->name, "proxy"))
-    {
-        yaz_log(YLOG_WARN, "No proxy element in %s", fname);
-        xmlFreeDoc(ndoc);
-        return false;
-    }
-    m_rep->m_proxyPtr = proxyPtr;
-    
-    // OK: release previous and make it the current one.
-    if (m_rep->m_docPtr)
-        xmlFreeDoc(m_rep->m_docPtr);
-    m_rep->m_docPtr = ndoc;
-
-    m_errors = 0;
-    parse_xml_element_proxy(proxyPtr);
-    if (m_errors && !m_debug_mode)
-        return false;
-    return true;
-}
-
-P2_Config::~P2_Config()
-{
-    delete m_rep;
-}
-
-P2_ConfigTarget::P2_ConfigTarget()
-{
-    m_default = false;
-}
-
-P2_ConfigTarget *P2_Config::find_target(string db)
-{
-    list<P2_ConfigTarget *>::const_iterator it;
-    for (it = m_target_list.begin(); it != m_target_list.end(); it++)
-    {
-        if ((*it)->m_virt_database == db)
-            return (*it);
-    }
-    return 0;
-}
-
-
-/*
- * Local variables:
- * c-basic-offset: 4
- * indent-tabs-mode: nil
- * End:
- * vim: shiftwidth=4 tabstop=8 expandtab
- */
diff --git a/src/p2_config.h b/src/p2_config.h
deleted file mode 100644 (file)
index 161e6e9..0000000
+++ /dev/null
@@ -1,90 +0,0 @@
-/* $Id: p2_config.h,v 1.1 2005-10-06 09:37:25 marc Exp $
-   Copyright (c) 1998-2005, Index Data.
-
-This file is part of the yaz-proxy.
-
-YAZ proxy 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
-Software Foundation; either version 2, or (at your option) any later
-version.
-
-YAZ proxy is distributed in the hope that it will be useful, but WITHOUT ANY
-WARRANTY; without even the implied warranty of MERCHANTABILITY or
-FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-for more details.
-
-You should have received a copy of the GNU General Public License
-along with YAZ proxy; see the file LICENSE.  If not, write to the
-Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
-02111-1307, USA.
- */
-
-#ifndef P2_CONFIG_INCLUDED
-#define P2_CONFIG_INCLUDED
-
-#include <string>
-#include <list>
-
-class P2_ConfigTarget {
- public:
-    P2_ConfigTarget();
-    std::string m_virt_address;
-    std::string m_virt_database;
-    std::string m_target_address;
-    std::string m_target_database;
-    std::string m_type;
-    bool m_default;
-};
-
-class P2_ConfigModule {
- public:
-    std::string m_fname;
-};
-
-class P2_Config {
-    class Rep;
- public:
-    P2_Config::P2_Config();
-    P2_Config::~P2_Config();
-    bool P2_Config::parse_options(int argc, char **argv);
-    P2_ConfigTarget *find_target(std::string db);
-    void print();
- private:
-    bool read_xml_config(const char *fname);
-    void parse_xml_element_proxy(void *xml_ptr);
-    void parse_xml_element_target(void *xml_ptr,
-                                            P2_ConfigTarget *t);
-    bool parse_xml_text(void *xml_ptr, std::string &val);
-    bool parse_xml_text(void *xml_ptr, bool &val);
- public:
-    std::string m_apdu_log;
-    std::string m_default_target;
-    std::string m_listen_address;
-    std::string m_log_file;
-    std::string m_optimize_flags;
-    std::string m_pid_fname;
-    std::string m_uid;
-    std::string m_xml_fname;
-
-    int m_max_clients;
-    int m_client_idletime;
-    int m_debug_mode;
-    int m_no_limit_files;
-    int m_no_threads;
-    int m_target_idletime;
-
-    std::list<P2_ConfigTarget *> m_target_list;
-    std::list<P2_ConfigModule *> m_modules;
- private:
-    Rep *m_rep;
-    int m_errors;
-};
-
-#endif
-/*
- * Local variables:
- * c-basic-offset: 4
- * indent-tabs-mode: nil
- * End:
- * vim: shiftwidth=4 tabstop=8 expandtab
- */
diff --git a/src/p2_frontend.cpp b/src/p2_frontend.cpp
deleted file mode 100644 (file)
index e43b54d..0000000
+++ /dev/null
@@ -1,97 +0,0 @@
-/* $Id: p2_frontend.cpp,v 1.4 2005-10-14 10:27:18 adam Exp $
-   Copyright (c) 1998-2005, Index Data.
-
-This file is part of the yaz-proxy.
-
-YAZ proxy 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
-Software Foundation; either version 2, or (at your option) any later
-version.
-
-YAZ proxy is distributed in the hope that it will be useful, but WITHOUT ANY
-WARRANTY; without even the implied warranty of MERCHANTABILITY or
-FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-for more details.
-
-You should have received a copy of the GNU General Public License
-along with YAZ proxy; see the file LICENSE.  If not, write to the
-Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
-02111-1307, USA.
- */
-
-#include "config.hpp"
-#include <yaz/log.h>
-#include <yaz/diagbib1.h>
-#include "p2_frontend.h"
-
-using namespace yazpp_1;
-using namespace std;
-
-P2_Frontend::P2_Frontend(IPDU_Observable *the_PDU_Observable,
-                         yp2::ThreadPoolSocketObserver 
-                         *my_thread, P2_Server *server)
-    :  Z_Assoc(the_PDU_Observable)
-{
-    m_my_thread = my_thread;
-    m_server = server;
-    m_no_requests = 0;
-    m_delete_flag = 0;
-    yaz_log(YLOG_LOG, "Construct P2_Frontend=%p", this);
-}
-
-
-IPDU_Observer *P2_Frontend::sessionNotify(IPDU_Observable
-                                          *the_PDU_Observable, int fd)
-{
-    return 0;
-}
-
-P2_Frontend::~P2_Frontend()
-{
-    yaz_log(YLOG_LOG, "Destroy P2_Frontend=%p", this);
-
-    list<P2_FrontResultSet *>::iterator it;
-    
-    for (it = m_resultSets.begin(); it != m_resultSets.end(); it++)
-    {
-        delete *it;
-        *it = 0;
-    }
-}
-
-void P2_Frontend::recv_GDU(Z_GDU *z_pdu, int len)
-{
-    GDU *gdu = new GDU(z_pdu);
-
-    P2_Msg *m = new P2_Msg(gdu, this, m_server);
-    m_no_requests++;
-    m_my_thread->put(m);  
-}
-
-void P2_Frontend::failNotify()
-{
-    m_delete_flag = 1;
-    if (m_no_requests == 0)
-        delete this;
-    
-}
-
-void P2_Frontend::timeoutNotify()
-{
-    m_delete_flag = 1;
-    if (m_no_requests == 0)
-        delete this;
-}
-
-void P2_Frontend::connectNotify()
-{
-
-}
-
-/*
- * Local variables:
- * c-basic-offset: 4
- * indent-tabs-mode: nil
- * End:
- * vim: shiftwidth=4 tabstop=8 expandtab
- */
diff --git a/src/p2_frontend.h b/src/p2_frontend.h
deleted file mode 100644 (file)
index adae8b2..0000000
+++ /dev/null
@@ -1,164 +0,0 @@
-/* $Id: p2_frontend.h,v 1.5 2005-10-14 10:27:18 adam Exp $
-   Copyright (c) 1998-2005, Index Data.
-
-This file is part of the yaz-proxy.
-
-YAZ proxy 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
-Software Foundation; either version 2, or (at your option) any later
-version.
-
-YAZ proxy is distributed in the hope that it will be useful, but WITHOUT ANY
-WARRANTY; without even the implied warranty of MERCHANTABILITY or
-FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-for more details.
-
-You should have received a copy of the GNU General Public License
-along with YAZ proxy; see the file LICENSE.  If not, write to the
-Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
-02111-1307, USA.
- */
-
-#ifndef P2_FRONTEND_H
-#define P2_FRONTEND_H
-
-#include <list>
-#include <vector>
-#include <string>
-
-#include "thread_pool_observer.hpp"
-#include <yaz++/z-assoc.h>
-#include <yaz++/pdu-assoc.h>
-#include <yaz++/gdu.h>
-#include <yaz++/gduqueue.h>
-#include <yaz++/z-query.h>
-
-class P2_Frontend;
-class P2_Server;
-class P2_Config;
-class P2_ConfigTarget;
-class P2_ModuleFactory;
-
-class IP2_BackendSet;
-
-class P2_BackendResultSet {
- public:
-    P2_BackendResultSet();
-    ~P2_BackendResultSet();
-    yazpp_1::Yaz_Z_Query m_query;
-    std::list<std::string> m_db_list;
-    int m_hit_count;
-    IP2_BackendSet *m_int;
-    // record cache here 
-};
-
-class IP2_Backend;
-
-class P2_Backend {
- public:
-    P2_Backend(P2_ConfigTarget *cfg, IP2_Backend *backend_interface);
-    ~P2_Backend();
- public:
-    std::list<P2_BackendResultSet *>m_resultSets;
-    P2_ConfigTarget *m_configTarget;
-    bool m_busy;
-    IP2_Backend *m_int;
-};
-
-class P2_Server : public yazpp_1::Z_Assoc {
-public:
-    ~P2_Server();
-    P2_Server(yazpp_1::IPDU_Observable *the_PDU_Observable,
-              yp2::ThreadPoolSocketObserver *m_my_thread,
-              P2_Config *config,
-              P2_ModuleFactory *modules);
-    P2_Config *lockConfig();
-    void unlockConfig();
-    std::list<P2_Backend *>m_backend_list;
-    P2_ModuleFactory *m_modules;
-private:
-    yazpp_1::IPDU_Observer* sessionNotify(
-        yazpp_1::IPDU_Observable *the_PDU_Observable,
-        int fd);
-    void recv_GDU(Z_GDU *apdu, int len);
-
-    void failNotify();
-    void timeoutNotify();
-    void connectNotify();
-private:
-    P2_Config *m_config;
-    yp2::ThreadPoolSocketObserver *m_my_thread;
-    pthread_mutex_t m_mutex_config;
-};
-
-class P2_FrontResultSet {
-public:
-    P2_FrontResultSet(const char *id);
-    ~P2_FrontResultSet();
-    void setQuery(Z_Query *z_query);
-    void setDatabases(char **db, int num);
-    std::string m_resultSetId;
-    std::vector<std::string> m_db_list;
-    yazpp_1::Yaz_Z_Query m_query;
-};
-
-class P2_Msg : public yp2::IThreadPoolMsg {
-public:
-    int m_close_flag;
-    yazpp_1::GDU *m_gdu;
-    yazpp_1::GDU *m_output;
-    P2_Frontend *m_front;
-    P2_Server *m_server;
-    yp2::IThreadPoolMsg *handle();
-    void result();
-    P2_Msg(yazpp_1::GDU *gdu, P2_Frontend *front, P2_Server *server);
-    virtual ~P2_Msg();
- private:
-
-    Z_APDU *frontend_search_resultset(Z_APDU *z_gdu, ODR odr,
-                                      P2_FrontResultSet **rset);
-    Z_APDU *frontend_present_resultset(Z_APDU *z_gdu, ODR odr,
-                                       P2_FrontResultSet **rset);
-    Z_APDU *frontend_search_apdu(Z_APDU *z_gdu, ODR odr);
-    Z_APDU *frontend_present_apdu(Z_APDU *z_gdu, ODR odr);
-    P2_Backend *select_backend(std::string db,
-                               yazpp_1::Yaz_Z_Query *query,
-                               P2_BackendResultSet **bset);
-    P2_Backend *create_backend(std::string db);
-};
-
-class P2_Frontend : public yazpp_1::Z_Assoc {
- public:
-    ~P2_Frontend();
-    P2_Frontend(yazpp_1::IPDU_Observable *the_PDU_Observable,
-                yp2::ThreadPoolSocketObserver *m_my_thread, P2_Server *server);
-    IPDU_Observer* sessionNotify(yazpp_1::IPDU_Observable *the_PDU_Observable,
-                                 int fd);
-    
-    void recv_GDU(Z_GDU *apdu, int len);
-    
-    void failNotify();
-    void timeoutNotify();
-    void connectNotify();
-
-    int m_no_requests;
-    int m_delete_flag;
-    std::list<P2_FrontResultSet *> m_resultSets;
-    
- private:
-    yazpp_1::GDUQueue m_in_queue;
-    yp2::ThreadPoolSocketObserver *m_my_thread;
-    P2_Server *m_server;
- private:
-    bool P2_Frontend::search(Z_GDU *z_gdu);
-    bool P2_Frontend::handle_init(Z_GDU *z_gdu);
-};
-
-#endif
-/*
- * Local variables:
- * c-basic-offset: 4
- * indent-tabs-mode: nil
- * End:
- * vim: shiftwidth=4 tabstop=8 expandtab
- */
diff --git a/src/p2_modules.cpp b/src/p2_modules.cpp
deleted file mode 100644 (file)
index fd1849c..0000000
+++ /dev/null
@@ -1,78 +0,0 @@
-
-#include "config.hpp"
-#include <dlfcn.h>
-
-#include "p2_modules.h"
-
-class P2_ModuleDLEntry {
-public:
-    void *m_dl_handle;
-    P2_ModuleEntry *m_entry;
-    P2_ModuleDLEntry();
-    ~P2_ModuleDLEntry();
-};
-
-P2_ModuleDLEntry::P2_ModuleDLEntry()
-{
-    m_dl_handle = 0;
-    m_entry = 0;
-}
-    
-P2_ModuleDLEntry::~P2_ModuleDLEntry()
-{
-    if (m_dl_handle)
-       dlclose(m_dl_handle);
-}
-    
-P2_ModuleFactory::P2_ModuleFactory()
-{
-}
-
-P2_ModuleFactory::~P2_ModuleFactory()
-{
-}
-
-bool P2_ModuleFactory::add(P2_ModuleEntry *entry)
-{
-    P2_ModuleDLEntry *m = new P2_ModuleDLEntry();
-    m->m_entry = entry;
-    m_modules.push_back(m);
-    return true;
-}
-
-bool P2_ModuleFactory::add(const char *fname)
-{
-    void *dl_handle = dlopen(fname, RTLD_NOW|RTLD_GLOBAL);
-    if (!dl_handle)
-       return false;
-
-    P2_ModuleEntry *entry =
-       reinterpret_cast<P2_ModuleEntry *> 
-       (dlsym(dl_handle, "p2_module_entry"));
-    if (!entry)
-    {
-       dlclose(dl_handle);
-       return false;
-    }
-    P2_ModuleDLEntry *m = new P2_ModuleDLEntry();
-    m->m_dl_handle = dl_handle;
-    m->m_entry = entry;
-    m_modules.push_back(m);
-    return true;
-}
-
-void *P2_ModuleFactory::get_interface(const char *name, int version)
-{
-    std::list<P2_ModuleDLEntry *>::const_iterator it;
-    for (it = m_modules.begin();  it != m_modules.end(); it++)
-    {
-       P2_ModuleDLEntry *ent = *it;
-       if (!strcmp(ent->m_entry->name, name) &&
-           ent->m_entry->version == version)
-       {
-           return ent->m_entry->interface_ptr;
-       }
-    }
-    return 0;
-}
-
diff --git a/src/p2_modules.h b/src/p2_modules.h
deleted file mode 100644 (file)
index c3f0e1b..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-
-#ifndef P2_MODULES_H
-#define P2_MODULES_H
-
-#include "p2_backend.h"
-
-#include <list>
-
-class P2_ModuleDLEntry ;
-class P2_ModuleFactory {
- public:
-    P2_ModuleFactory();
-    ~P2_ModuleFactory();
-    bool add(const char *fname);
-    bool add(P2_ModuleEntry *entry);
-    void *get_interface(const char *name, int version);
- private:
-    std::list <P2_ModuleDLEntry *>m_modules;
-};
-
-#endif
diff --git a/src/p2_msg.cpp b/src/p2_msg.cpp
deleted file mode 100644 (file)
index a0c50e1..0000000
+++ /dev/null
@@ -1,388 +0,0 @@
-/* $Id: p2_msg.cpp,v 1.4 2005-10-14 10:27:18 adam Exp $
-   Copyright (c) 1998-2005, Index Data.
-
-This file is part of the yaz-proxy.
-
-YAZ proxy 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
-Software Foundation; either version 2, or (at your option) any later
-version.
-
-YAZ proxy is distributed in the hope that it will be useful, but WITHOUT ANY
-WARRANTY; without even the implied warranty of MERCHANTABILITY or
-FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-for more details.
-
-You should have received a copy of the GNU General Public License
-along with YAZ proxy; see the file LICENSE.  If not, write to the
-Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
-02111-1307, USA.
- */
-
-#include "config.hpp"
-#include <yaz/log.h>
-#include <yaz/diagbib1.h>
-#include "p2_backend.h"
-#include "p2_frontend.h"
-#include "p2_config.h"
-#include "p2_modules.h"
-
-using namespace yazpp_1;
-using namespace std;
-
-IP2_BackendSet::~IP2_BackendSet()
-{
-}
-
-IP2_Backend::~IP2_Backend()
-{
-
-}
-
-P2_Backend::P2_Backend(P2_ConfigTarget *cfg, IP2_Backend *backend_int)
-{
-    m_configTarget = new P2_ConfigTarget;
-    *m_configTarget = *cfg;
-    m_busy = false;
-    m_int = backend_int;
-}
-
-P2_Backend::~P2_Backend()
-{
-    delete m_configTarget;
-}
-
-P2_BackendResultSet::P2_BackendResultSet()
-{
-    m_int = 0;
-}
-
-P2_BackendResultSet::~P2_BackendResultSet()
-{
-    delete m_int;
-}
-
-P2_Backend *P2_Msg::select_backend(string db,
-                                   Yaz_Z_Query *query,
-                                   P2_BackendResultSet **bset)
-{
-    P2_Config *cfg = m_server->lockConfig();
-
-    // see if some target has done this query before
-
-    *bset = 0;
-    P2_Backend *backend = 0;
-
-    list<P2_Backend *>::const_iterator it;
-    for (it = m_server->m_backend_list.begin(); 
-         it != m_server->m_backend_list.end(); it++)
-    {
-        if ((*it)->m_busy)
-            continue;
-
-        if (db != (*it)->m_configTarget->m_virt_database)
-            continue;
-        backend = *it;
-
-        if (query)
-        {
-            list<P2_BackendResultSet *>::const_iterator is;
-            for (is  = (*it)->m_resultSets.begin(); 
-                 is != (*it)->m_resultSets.end(); is++)
-            {
-                if (query->match(&(*is)->m_query))
-                {
-                    *bset = *is;
-                    break;
-                }
-            }
-        }
-        if (bset)
-            break;
-    }
-    if (!backend)
-    {
-        P2_ConfigTarget *target_cfg = cfg->find_target(db);
-
-        if (!target_cfg)
-        {
-            yaz_log(YLOG_WARN, "No backend for database %s",
-                    db.c_str());
-        }
-        else
-        {
-            P2_ModuleInterface0 *int0 =
-            reinterpret_cast<P2_ModuleInterface0 *>
-                (m_server->m_modules->get_interface(target_cfg->m_type.c_str(),
-                                                    0));
-            IP2_Backend *bint = 0;
-
-            if (int0)
-                bint = int0->create(target_cfg->m_target_address.c_str());
-
-            if (bint)
-                backend = new P2_Backend(target_cfg, bint);
-
-            if (backend)
-                m_server->m_backend_list.push_back(backend);
-        }
-    }
-    if (backend)
-        backend->m_busy = true;
-    m_server->unlockConfig();
-    return backend;
-}
-
-void P2_FrontResultSet::setQuery(Z_Query *z_query)
-{
-    m_query.set_Z_Query(z_query);
-}
-
-void P2_FrontResultSet::setDatabases(char **db, int num)
-{
-    m_db_list.clear();
-
-    int i;
-    for (i = 0; i<num; i++)
-        m_db_list.push_back(db[i]);
-}
-
-P2_FrontResultSet::P2_FrontResultSet(const char *id)
-{
-    m_resultSetId = id;
-}
-
-
-P2_FrontResultSet::~P2_FrontResultSet()
-{
-}
-
-P2_Msg::P2_Msg(GDU *gdu, P2_Frontend *front, P2_Server *server)
-{
-    m_front = front;
-    m_server = server;
-    m_output = 0;
-    m_gdu = gdu;
-    m_close_flag = 0;
-}
-
-P2_Msg::~P2_Msg()
-{
-    delete m_output;
-    delete m_gdu;
-}
-
-Z_APDU *P2_Msg::frontend_search_resultset(Z_APDU *z_gdu, ODR odr,
-                                          P2_FrontResultSet **rset)
-{
-    Z_SearchRequest *req = z_gdu->u.searchRequest;
-    list<P2_FrontResultSet *>::iterator it;
-    P2_FrontResultSet *s = 0;
-
-    string id = req->resultSetName;
-    for (it = m_front->m_resultSets.begin(); it != m_front->m_resultSets.end(); it++)
-    {
-       if ((*it)->m_resultSetId == id)
-        {
-            s = *it;
-           break;
-        }
-    }
-    if (s)
-    {
-       // result set already exists
-        *rset = s;
-       if (req->replaceIndicator && *req->replaceIndicator)
-       {  // replace indicator true
-           s->setQuery(req->query);
-           s->setDatabases(req->databaseNames, req->num_databaseNames);
-           return 0;
-       }
-       Z_APDU *apdu = zget_APDU(odr, Z_APDU_searchResponse);
-       Z_Records *rec = (Z_Records *) odr_malloc(odr, sizeof(Z_Records));
-       apdu->u.searchResponse->records = rec;
-       rec->which = Z_Records_NSD;
-       rec->u.nonSurrogateDiagnostic =
-           zget_DefaultDiagFormat(
-               odr, YAZ_BIB1_RESULT_SET_EXISTS_AND_REPLACE_INDICATOR_OFF,
-               req->resultSetName);
-       
-       return apdu;
-    }
-    // does not exist 
-    s = new P2_FrontResultSet(req->resultSetName);
-    s->setQuery(req->query);
-    s->setDatabases(req->databaseNames, req->num_databaseNames);
-    m_front->m_resultSets.push_back(s);
-    *rset = s;
-    return 0;
-}
-
-Z_APDU *P2_Msg::frontend_search_apdu(Z_APDU *request_apdu, ODR odr)
-{
-    P2_FrontResultSet *rset;
-    Z_APDU *response_apdu = frontend_search_resultset(request_apdu, odr,
-                                                      &rset);
-    if (response_apdu)
-        return response_apdu;
-
-    // no immediate error (yet) 
-    size_t i;
-    for (i = 0; i<rset->m_db_list.size(); i++)
-    {
-        string db = rset->m_db_list[i];
-        P2_BackendResultSet *bset;
-        P2_Backend *b = select_backend(db, &rset->m_query, &bset);
-        if (!b)
-        {
-            Z_APDU *apdu = zget_APDU(odr, Z_APDU_searchResponse);
-            Z_Records *rec = (Z_Records *) odr_malloc(odr, sizeof(Z_Records));
-            apdu->u.searchResponse->records = rec;
-            rec->which = Z_Records_NSD;
-            rec->u.nonSurrogateDiagnostic =
-                zget_DefaultDiagFormat(
-                    odr, YAZ_BIB1_DATABASE_UNAVAILABLE, db.c_str());
-            return apdu;
-        }
-        if (!bset)
-        {   // new set 
-            bset = new P2_BackendResultSet();
-
-            bset->m_query.set_Z_Query(request_apdu->u.searchRequest->query);
-            bset->m_db_list.push_back(db);
-
-            b->m_int->search(&bset->m_query, &bset->m_int, &bset->m_hit_count);
-            b->m_resultSets.push_back(bset);
-        }
-        else
-        {
-            bset->m_int->get(1, 1);
-        }
-        response_apdu = zget_APDU(odr, Z_APDU_searchResponse);
-        *response_apdu->u.searchResponse->resultCount = bset->m_hit_count;
-        b->m_busy = false;
-    }
-    if (!response_apdu)
-    {
-        Z_APDU *apdu = zget_APDU(odr, Z_APDU_searchResponse);
-        Z_Records *rec = (Z_Records *) odr_malloc(odr, sizeof(Z_Records));
-        apdu->u.searchResponse->records = rec;
-            rec->which = Z_Records_NSD;
-            rec->u.nonSurrogateDiagnostic =
-                zget_DefaultDiagFormat(odr, YAZ_BIB1_UNSUPP_SEARCH, 0);
-            return apdu;
-    }
-    return response_apdu;
-}
-
-Z_APDU *P2_Msg::frontend_present_resultset(Z_APDU *z_gdu, ODR odr,
-                                           P2_FrontResultSet **rset)
-{
-    Z_PresentRequest *req = z_gdu->u.presentRequest;
-    list<P2_FrontResultSet *>::iterator it;
-    P2_FrontResultSet *s = 0;
-
-    string id = req->resultSetId;
-    for (it = m_front->m_resultSets.begin(); it != m_front->m_resultSets.end(); it++)
-    {
-       if ((*it)->m_resultSetId == id)
-        {
-            s = *it;
-           break;
-        }
-    }
-    *rset = s;
-    if (s)
-       return 0;  // fine result set exists 
-
-    Z_APDU *apdu = zget_APDU(odr, Z_APDU_presentResponse);
-    
-    Z_Records *rec = (Z_Records *) odr_malloc(odr, sizeof(Z_Records));
-    apdu->u.presentResponse->records = rec;
-    rec->which = Z_Records_NSD;
-    rec->u.nonSurrogateDiagnostic =
-       zget_DefaultDiagFormat(
-           odr,
-           YAZ_BIB1_SPECIFIED_RESULT_SET_DOES_NOT_EXIST,
-           req->resultSetId);
-    return apdu;
-}
-
-Z_APDU *P2_Msg::frontend_present_apdu(Z_APDU *request_apdu, ODR odr)
-{
-    P2_FrontResultSet *rset;
-    Z_APDU *response_apdu = frontend_present_resultset(request_apdu, odr,
-                                                       &rset);
-    if (response_apdu)
-        return response_apdu;
-    return zget_APDU(odr, Z_APDU_presentResponse);
-}
-    
-yp2::IThreadPoolMsg *P2_Msg::handle()
-{
-    ODR odr = odr_createmem(ODR_ENCODE);
-    yaz_log(YLOG_LOG, "P2_Msg:handle begin");
-    Z_GDU *request_gdu = m_gdu->get();
-
-    if (request_gdu->which == Z_GDU_Z3950)
-    {
-       Z_APDU *request_apdu = request_gdu->u.z3950;
-        Z_APDU *response_apdu = 0;
-        switch(request_apdu->which)
-        {
-        case Z_APDU_initRequest:
-            response_apdu = zget_APDU(odr, Z_APDU_initResponse);
-            ODR_MASK_SET(response_apdu->u.initResponse->options, Z_Options_triggerResourceCtrl);
-            ODR_MASK_SET(response_apdu->u.initResponse->options, Z_Options_search);
-            ODR_MASK_SET(response_apdu->u.initResponse->options, Z_Options_present);
-           ODR_MASK_SET(response_apdu->u.initResponse->options, Z_Options_namedResultSets);
-            break;
-        case Z_APDU_searchRequest:
-            response_apdu = frontend_search_apdu(request_apdu, odr);
-            break;
-       case Z_APDU_presentRequest:
-           response_apdu = frontend_present_apdu(request_apdu, odr);
-            break;
-        case Z_APDU_triggerResourceControlRequest:
-            break;
-        default:
-            response_apdu = zget_APDU(odr, Z_APDU_close);
-            m_close_flag = 1;
-            break;
-        }
-        if (response_apdu)
-            m_output = new GDU(response_apdu);
-    }
-    yaz_log(YLOG_LOG, "P2_Msg:handle end");
-    odr_destroy(odr);
-    return this;
-}
-
-void P2_Msg::result()
-{
-    m_front->m_no_requests--;
-    if (!m_front->m_delete_flag)
-    {
-        if (m_output)
-        {
-            int len;
-            m_front->send_GDU(m_output->get(), &len);
-        }
-        if (m_close_flag)
-        {
-            m_front->close();
-            m_front->m_delete_flag = 1;
-        }
-    }
-    if (m_front->m_delete_flag && m_front->m_no_requests == 0)
-        delete m_front;
-    delete this;
-}
-
-/*
- * Local variables:
- * c-basic-offset: 4
- * indent-tabs-mode: nil
- * End:
- * vim: shiftwidth=4 tabstop=8 expandtab
- */
diff --git a/src/p2_xmlerror.cpp b/src/p2_xmlerror.cpp
deleted file mode 100644 (file)
index a04c4e2..0000000
+++ /dev/null
@@ -1,71 +0,0 @@
-/* $Id: p2_xmlerror.cpp,v 1.2 2005-10-08 23:29:32 adam Exp $
-   Copyright (c) 1998-2005, Index Data.
-
-This file is part of the yaz-proxy.
-
-YAZ proxy 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
-Software Foundation; either version 2, or (at your option) any later
-version.
-
-YAZ proxy is distributed in the hope that it will be useful, but WITHOUT ANY
-WARRANTY; without even the implied warranty of MERCHANTABILITY or
-FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-for more details.
-
-You should have received a copy of the GNU General Public License
-along with YAZ proxy; see the file LICENSE.  If not, write to the
-Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
-02111-1307, USA.
- */
-
-#include "config.hpp"
-#include <stdio.h>
-#include <string.h>
-#include <yaz/log.h>
-
-#include "p2_xmlerror.h"
-
-#if HAVE_XSLT
-#include <libxml/parser.h>
-#include <libxslt/xsltutils.h>
-#endif
-
-#if HAVE_XSLT
-static void p2_xml_error_handler(void *ctx, const char *fmt, ...)
-{
-    char buf[1024];
-    size_t sz;
-
-    va_list ap;
-    va_start(ap, fmt);
-
-#ifdef WIN32
-    vsprintf(buf, fmt, ap);
-#else
-    vsnprintf(buf, sizeof(buf), fmt, ap);
-#endif
-    sz = strlen(buf);
-    if (sz > 0 && buf[sz-1] == '\n')
-        buf[sz-1] = '\0';
-        
-    yaz_log(YLOG_WARN, "%s: %s", (char*) ctx, buf);
-
-    va_end (ap);
-}
-#endif
-
-void p2_xmlerror_setup()
-{
-#if HAVE_XSLT
-    xmlSetGenericErrorFunc((void *) "XML", p2_xml_error_handler);
-    xsltSetGenericErrorFunc((void *) "XSLT", p2_xml_error_handler);
-#endif
-}
-/*
- * Local variables:
- * c-basic-offset: 4
- * indent-tabs-mode: nil
- * End:
- * vim: shiftwidth=4 tabstop=8 expandtab
- */
diff --git a/src/p2_xmlerror.h b/src/p2_xmlerror.h
deleted file mode 100644 (file)
index f8eb1e5..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-/* $Id: p2_xmlerror.h,v 1.1 2005-10-06 09:37:25 marc Exp $
-   Copyright (c) 1998-2005, Index Data.
-
-This file is part of the yaz-proxy.
-
-YAZ proxy 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
-Software Foundation; either version 2, or (at your option) any later
-version.
-
-YAZ proxy is distributed in the hope that it will be useful, but WITHOUT ANY
-WARRANTY; without even the implied warranty of MERCHANTABILITY or
-FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-for more details.
-
-You should have received a copy of the GNU General Public License
-along with YAZ proxy; see the file LICENSE.  If not, write to the
-Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
-02111-1307, USA.
- */
-
-#ifndef P2_XMLERROR_H
-#define P2_XMLERROR_H
-
-void p2_xmlerror_setup();
-
-#endif
-
-/*
- * Local variables:
- * c-basic-offset: 4
- * indent-tabs-mode: nil
- * End:
- * vim: shiftwidth=4 tabstop=8 expandtab
- */
index 2ca4931..148749d 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: session.hpp,v 1.8 2005-10-16 16:05:18 adam Exp $
+/* $Id: session.hpp,v 1.9 2005-10-25 11:48:30 adam Exp $
    Copyright (c) 2005, Index Data.
 
 %LICENSE%
@@ -29,7 +29,7 @@ namespace yp2 {
         /// copy session including old id
         Session(const Session &s) : m_id(s.m_id), m_close(s.m_close) {};
         
-        Session& operator=(const Session &s) {
+        Session& operator=(const Session &s) { 
             if (this != &s)
             {
                 m_id = s.m_id;
@@ -37,6 +37,10 @@ namespace yp2 {
             }
             return *this;
         }
+
+        bool operator<(const Session &s) const {
+            return m_id < s.m_id ? true : false;
+        }
         
         unsigned long id() const {
             return m_id;
@@ -51,7 +55,7 @@ namespace yp2 {
             m_close = true;
         };
 
-        bool operator == (Session &ses) {
+        bool operator == (Session &ses) const {
             return ses.m_id == m_id;
         }
     private:
index 154cbd7..0c2e6d8 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: test_filter_log.cpp,v 1.1 2005-10-19 22:45:59 marc Exp $
+/* $Id: test_filter_log.cpp,v 1.2 2005-10-25 11:48:30 adam Exp $
    Copyright (c) 2005, Index Data.
 
 %LICENSE%
@@ -49,9 +49,7 @@ BOOST_AUTO_TEST_CASE( test_filter_log_1 )
 {
     try 
     {
-        {
-            yp2::filter::Log lf;
-        }
+        yp2::filter::Log lf;
     }
     catch ( ... ) {
         BOOST_CHECK (false);
@@ -62,37 +60,35 @@ BOOST_AUTO_TEST_CASE( test_filter_log_2 )
 {
     try 
     {
-        {
-           yp2::RouterChain router;
-
-            yp2::filter::Log lf;
-            FilterBounceInit bf;
-
-           router.rule(lf);
-           router.rule(bf);
-
-            // Create package with Z39.50 init request in it
-           yp2::Package pack;
-
-            ODR odr = odr_createmem(ODR_ENCODE);
-            Z_APDU *apdu = zget_APDU(odr, Z_APDU_initRequest);
-            
-            pack.request() = apdu;
-            odr_destroy(odr);
-           // Done creating query. 
-
-            // Put it in router
-           pack.router(router).move(); 
-
-            // Inspect that we got Z39.50 init response
-            yazpp_1::GDU *gdu = &pack.response();
-
-            Z_GDU *z_gdu = gdu->get();
-            BOOST_CHECK(z_gdu);
-            if (z_gdu) {
-                BOOST_CHECK_EQUAL(z_gdu->which, Z_GDU_Z3950);
-                BOOST_CHECK_EQUAL(z_gdu->u.z3950->which, Z_APDU_initResponse);
-            }
+        yp2::RouterChain router;
+        
+        yp2::filter::Log lf;
+        FilterBounceInit bf;
+        
+        router.rule(lf);
+        router.rule(bf);
+        
+        // Create package with Z39.50 init request in it
+        yp2::Package pack;
+        
+        ODR odr = odr_createmem(ODR_ENCODE);
+        Z_APDU *apdu = zget_APDU(odr, Z_APDU_initRequest);
+        
+        pack.request() = apdu;
+        odr_destroy(odr);
+        // Done creating query. 
+        
+        // Put it in router
+        pack.router(router).move(); 
+        
+        // Inspect that we got Z39.50 init response
+        yazpp_1::GDU *gdu = &pack.response();
+        
+        Z_GDU *z_gdu = gdu->get();
+        BOOST_CHECK(z_gdu);
+        if (z_gdu) {
+            BOOST_CHECK_EQUAL(z_gdu->which, Z_GDU_Z3950);
+            BOOST_CHECK_EQUAL(z_gdu->u.z3950->which, Z_APDU_initResponse);
         }
     }
     catch ( ... ) {
index 72aa647..f62bb40 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: test_filter_virt_db.cpp,v 1.1 2005-10-24 14:33:30 adam Exp $
+/* $Id: test_filter_virt_db.cpp,v 1.2 2005-10-25 11:48:30 adam Exp $
    Copyright (c) 2005, Index Data.
 
 %LICENSE%
@@ -9,6 +9,8 @@
 #include <stdexcept>
 
 #include "filter_virt_db.hpp"
+#include "filter_backend_test.hpp"
+#include "filter_log.hpp"
 
 #include "router.hpp"
 #include "session.hpp"
@@ -18,6 +20,7 @@
 #include <boost/test/auto_unit_test.hpp>
 
 #include <yaz/zgdu.h>
+#include <yaz/pquery.h>
 #include <yaz/otherinfo.h>
 using namespace boost::unit_test;
 
@@ -44,6 +47,8 @@ BOOST_AUTO_TEST_CASE( test_filter_virt_db_2 )
         router.rule(vdb);
         
         // Create package with Z39.50 init request in it
+        // Since there is not vhost given, the virt will make its
+        // own init response (regardless of backend)
         yp2::Package pack;
         
         ODR odr = odr_createmem(ODR_ENCODE);
@@ -74,6 +79,183 @@ BOOST_AUTO_TEST_CASE( test_filter_virt_db_2 )
     }
 }
 
+
+static void init(yp2::Package &pack, yp2::Router &router)
+{
+    // Create package with Z39.50 init request in it
+    ODR odr = odr_createmem(ODR_ENCODE);
+    Z_APDU *apdu = zget_APDU(odr, Z_APDU_initRequest);
+    
+    BOOST_CHECK(apdu);
+    if (!apdu)
+        return;
+    
+    pack.request() = apdu;
+    odr_destroy(odr);
+    
+    // Put it in router
+    pack.router(router).move(); 
+    
+    // Inspect that we got Z39.50 init response
+    yazpp_1::GDU *gdu = &pack.response();
+    
+    BOOST_CHECK(!pack.session().is_closed()); 
+    
+    Z_GDU *z_gdu = gdu->get();
+    BOOST_CHECK(z_gdu);
+    if (!z_gdu)
+        return;
+    BOOST_CHECK_EQUAL(z_gdu->which, Z_GDU_Z3950);
+    BOOST_CHECK_EQUAL(z_gdu->u.z3950->which, Z_APDU_initResponse);
+}
+                 
+static void search(yp2::Package &pack, yp2::Router &router,
+                   const char *pqf_query, const char *db,
+                   const char *setname)
+{
+    // Create package with Z39.50 search request in it
+            
+    ODR odr = odr_createmem(ODR_ENCODE);
+    Z_APDU *apdu = zget_APDU(odr, Z_APDU_searchRequest);
+    
+    YAZ_PQF_Parser pqf_parser = yaz_pqf_create();
+    
+    Z_RPNQuery *rpn = yaz_pqf_parse(pqf_parser, odr, pqf_query);
+    BOOST_CHECK(rpn);
+    if (!rpn)
+        return;
+    Z_Query query;
+    query.which = Z_Query_type_1;
+    query.u.type_1 = rpn;
+    
+    apdu->u.searchRequest->resultSetName = odr_strdup(odr, setname);
+
+    apdu->u.searchRequest->query = &query;
+    
+    apdu->u.searchRequest->num_databaseNames = 1;
+    apdu->u.searchRequest->databaseNames = (char**)
+        odr_malloc(odr, sizeof(char *));
+    apdu->u.searchRequest->databaseNames[0] = odr_strdup(odr, db);
+    
+    BOOST_CHECK(apdu);
+    if (!apdu)
+        return;
+    
+    pack.request() = apdu;
+    
+    odr_destroy(odr);
+    
+    Z_GDU *gdu_test = pack.request().get();
+    BOOST_CHECK(gdu_test);
+    
+    // Put it in router
+    pack.router(router).move(); 
+    
+    // Inspect that we got Z39.50 search response
+    yazpp_1::GDU *gdu = &pack.response();
+    
+    BOOST_CHECK(!pack.session().is_closed()); 
+    
+    Z_GDU *z_gdu = gdu->get();
+    BOOST_CHECK(z_gdu);
+    if (!z_gdu)
+        return;
+    BOOST_CHECK_EQUAL(z_gdu->which, Z_GDU_Z3950);
+    BOOST_CHECK_EQUAL(z_gdu->u.z3950->which, Z_APDU_searchResponse);
+}
+
+static void present(yp2::Package &pack, yp2::Router &router,
+                    int start, int number,
+                    const char *setname)
+{
+    // Create package with Z39.50 present request in it
+            
+    ODR odr = odr_createmem(ODR_ENCODE);
+    Z_APDU *apdu = zget_APDU(odr, Z_APDU_presentRequest);
+    
+    apdu->u.presentRequest->resultSetId  = odr_strdup(odr, setname);
+    *apdu->u.presentRequest->resultSetStartPoint = start;
+    *apdu->u.presentRequest->numberOfRecordsRequested = number;
+
+    BOOST_CHECK(apdu);
+    if (!apdu)
+        return;
+    
+    pack.request() = apdu;
+    
+    odr_destroy(odr);
+    
+    Z_GDU *gdu_test = pack.request().get();
+    BOOST_CHECK(gdu_test);
+    
+    // Put it in router
+    pack.router(router).move(); 
+    
+    // Inspect that we got Z39.50 present response
+    yazpp_1::GDU *gdu = &pack.response();
+    
+    BOOST_CHECK(!pack.session().is_closed()); 
+    
+    Z_GDU *z_gdu = gdu->get();
+    BOOST_CHECK(z_gdu);
+    if (!z_gdu)
+        return;
+    BOOST_CHECK_EQUAL(z_gdu->which, Z_GDU_Z3950);
+    BOOST_CHECK_EQUAL(z_gdu->u.z3950->which, Z_APDU_presentResponse);
+}
+
+BOOST_AUTO_TEST_CASE( test_filter_virt_db_3 )
+{
+    try 
+    {
+        yp2::RouterChain router;
+
+#if 0
+        yp2::filter::Log filter_log1;
+        filter_log1.set_prefix("FRONT");
+        router.rule(filter_log1);
+#endif
+   
+        yp2::filter::Virt_db vdb;        
+        router.rule(vdb);
+        vdb.add_map_db2vhost("Default", "localhost:210");
+#if 0
+        yp2::filter::Log filter_log2;
+        filter_log2.set_prefix("BACK");
+        router.rule(filter_log2);
+#endif
+        yp2::filter::Backend_test btest;
+        router.rule(btest);
+
+        yp2::Session session1;
+        yp2::Origin origin1;
+        
+        {
+            yp2::Package pack(session1, origin1);
+            init(pack, router);
+        }
+        {
+            // search for database for which there is no map
+            yp2::Package pack(session1, origin1);
+            search(pack, router, "computer", "bad_database", "default");
+        }
+        {
+            // search for database for which there a map
+            yp2::Package pack(session1, origin1);
+            search(pack, router, "other", "Default", "default");
+        }
+        {
+            // present from last search
+            yp2::Package pack(session1, origin1);
+            present(pack, router, 1, 2, "default");
+        }
+    }
+    catch ( ... ) {
+        BOOST_CHECK (false);
+    }
+}
+
+
 /*
  * Local variables:
  * c-basic-offset: 4