backend_test_cpp. Removed p2.cpp.
test_session1
test_session2
test_filter_z3950_client
+test_filter_backend_test
test_filter_virt_db
-## $Id: Makefile.am,v 1.24 2005-10-25 11:48:30 adam Exp $
+## $Id: Makefile.am,v 1.25 2005-10-25 21:32:01 adam Exp $
MAINTAINERCLEANFILES = Makefile.in config.in config.hpp
filter_log.cpp filter_log.hpp \
filter_virt_db.cpp filter_virt_db.hpp \
filter_z3950_client.cpp filter_z3950_client.hpp \
- filter_backend_test.cpp filter_backend_test.hpp
+ filter_backend_test.cpp filter_backend_test.hpp \
+ test_util.cpp test_util.hpp
# Rules for programs..
test_filter_frontend_net \
test_filter_log \
test_filter_z3950_client \
+ test_filter_backend_test \
test_filter_virt_db
TESTS=$(check_PROGRAMS)
test_filter_frontend_net_SOURCES = test_filter_frontend_net.cpp
test_filter_log_SOURCES = test_filter_log.cpp
test_filter_z3950_client_SOURCES = test_filter_z3950_client.cpp
+test_filter_backend_test_SOURCES = test_filter_backend_test.cpp
test_filter_virt_db_SOURCES = test_filter_virt_db.cpp
TESTLDADD = $(LDADD) -lboost_unit_test_framework
test_filter_frontend_net_LDADD = $(TESTLDADD)
test_filter_log_LDADD = $(TESTLDADD)
test_filter_z3950_client_LDADD = $(TESTLDADD)
+test_filter_backend_test_LDADD = $(TESTLDADD)
test_filter_virt_db_LDADD = $(TESTLDADD)
# doxygen target
-/* $Id: filter_backend_test.cpp,v 1.3 2005-10-25 16:01:36 adam Exp $
+/* $Id: filter_backend_test.cpp,v 1.4 2005-10-25 21:32:01 adam Exp $
Copyright (c) 2005, Index Data.
%LICENSE%
namespace yp2 {
namespace filter {
+ class Session_info {
+ int dummy;
+ };
class Backend_test::Rep {
friend class Backend_test;
private:
bool m_support_named_result_sets;
+
+ session_map<Session_info> m_sessions;
};
}
}
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)
+
+ if (apdu_req->which != Z_APDU_initRequest &&
+ !m_p->m_sessions.active(package.session()))
+ {
+ apdu_res = zget_APDU(odr, Z_APDU_close);
+ *apdu_res->u.close->closeReason = Z_Close_protocolError;
+ apdu_res->u.close->diagnosticInformation =
+ odr_strdup(odr, "no init for filter_backend_test");
+
+ package.session().close();
+ }
+ else if (apdu_req->which == Z_APDU_initRequest)
{
apdu_res = zget_APDU(odr, Z_APDU_initResponse);
Z_InitRequest *req = apdu_req->u.initRequest;
else
break;
+ Session_info info;
+ m_p->m_sessions.create(info, package.session());
}
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"))
{
package.response() = apdu_res;
odr_destroy(odr);
}
+ if (package.session().is_closed())
+ m_p->m_sessions.release(package.session());
}
-/* $Id: filter_virt_db.cpp,v 1.5 2005-10-25 16:00:58 adam Exp $
+/* $Id: filter_virt_db.cpp,v 1.6 2005-10-25 21:32:01 adam Exp $
Copyright (c) 2005, Index Data.
%LICENSE%
{
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);
+ m_sessions.erase(package.session());
}
void yf::Virt_db::Rep::present(Package &package, Z_APDU *apdu, bool &move_later){
-/* $Id: filter_z3950_client.cpp,v 1.4 2005-10-25 16:01:14 adam Exp $
+/* $Id: filter_z3950_client.cpp,v 1.5 2005-10-25 21:32:01 adam Exp $
Copyright (c) 2005, Index Data.
%LICENSE%
#include "config.hpp"
+#include <map>
#include "filter.hpp"
#include "router.hpp"
#include "package.hpp"
class Z3950Client::Assoc : public yazpp_1::Z_Assoc{
friend class Pimpl;
public:
- Assoc(yp2::Session id, yazpp_1::SocketManager *socket_manager,
+ Assoc(yazpp_1::SocketManager *socket_manager,
yazpp_1::IPDU_Observable *PDU_Observable,
std::string host);
~Assoc();
yazpp_1::IPDU_Observable *the_PDU_Observable,
int fd);
private:
- yp2::Session m_session_id;
+ // yp2::Session m_session_id;
yazpp_1::SocketManager *m_socket_manager;
yazpp_1::IPDU_Observable *m_PDU_Observable;
Package *m_package;
class Z3950Client::Pimpl {
public:
boost::mutex m_mutex;
- std::list<Z3950Client::Assoc *> m_clients;
+ std::map<yp2::Session,Z3950Client::Assoc *> m_clients;
Z3950Client::Assoc *get_assoc(Package &package);
void send_and_receive(Package &package,
yf::Z3950Client::Assoc *c);
}
-yf::Z3950Client::Assoc::Assoc(yp2::Session id,
- yazpp_1::SocketManager *socket_manager,
+yf::Z3950Client::Assoc::Assoc(yazpp_1::SocketManager *socket_manager,
yazpp_1::IPDU_Observable *PDU_Observable,
std::string host)
- : Z_Assoc(PDU_Observable), m_session_id(id),
+ : Z_Assoc(PDU_Observable),
m_socket_manager(socket_manager), m_PDU_Observable(PDU_Observable),
m_package(0), m_waiting(false), m_connected(false),
m_host(host)
// only one thread messes with the clients list at a time
boost::mutex::scoped_lock lock(m_mutex);
- std::list<yf::Z3950Client::Assoc *>::iterator it;
-
- for (it = m_clients.begin(); it != m_clients.end(); it++)
- {
- if ((*it)->m_session_id == package.session())
- break;
- }
+ std::map<yp2::Session,yf::Z3950Client::Assoc *>::iterator it;
+
+ it = m_clients.find(package.session());
if (it != m_clients.end())
- return *it;
+ return it->second;
// only deal with Z39.50
Z_GDU *gdu = package.request().get();
yazpp_1::SocketManager *sm = new yazpp_1::SocketManager;
yazpp_1::PDU_Assoc *pdu_as = new yazpp_1::PDU_Assoc(sm);
- yf::Z3950Client::Assoc *as = new yf::Z3950Client::Assoc(package.session(),
- sm, pdu_as,
- vhost);
- m_clients.push_back(as);
+ yf::Z3950Client::Assoc *as = new yf::Z3950Client::Assoc(sm, pdu_as, vhost);
+ m_clients[package.session()] = as;
return as;
}
if (package.session().is_closed())
{
boost::mutex::scoped_lock lock(m_mutex);
- std::list<yf::Z3950Client::Assoc *>::iterator it;
+ std::map<yp2::Session,yf::Z3950Client::Assoc *>::iterator it;
- for (it = m_clients.begin(); it != m_clients.end(); it++)
- {
- if ((*it)->m_session_id == package.session())
- break;
- }
+ it = m_clients.find(package.session());
if (it != m_clients.end())
{
// the Z_Assoc and PDU_Assoc must be destroyed before
// the socket manager.. so pull that out.. first..
- yazpp_1::SocketManager *s = (*it)->m_socket_manager;
- delete *it; // destroy Z_Assoc
+ yazpp_1::SocketManager *s = it->second->m_socket_manager;
+ delete it->second; // destroy Z_Assoc
delete s; // then manager
m_clients.erase(it);
}
+++ /dev/null
-/* $Id: p2.cpp,v 1.5 2005-10-15 14:09:09 adam Exp $
- Copyright (c) 2005, Index Data.
-
-%LICENSE%
- */
-/* $Id: p2.cpp,v 1.5 2005-10-15 14:09:09 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 <pthread.h>
-#include <stdlib.h>
-#include <yaz/log.h>
-#include <yaz/diagbib1.h>
-#include <yaz/options.h>
-
-#include "config.hpp"
-#include <yaz++/socket-manager.h>
-#include "p2_config.h"
-#include "p2_frontend.h"
-#include "p2_xmlerror.h"
-#include "p2_modules.h"
-
-using namespace yazpp_1;
-
-extern P2_ModuleEntry *p2_backend_dummy;
-
-/*
- frontend result set map
- resultset -> db,query
-
- backend result set map
- db,query -> resultset, target
- resultset, target
-*/
-class P2_Frontend;
-
-P2_Config *P2_Server::lockConfig()
-{
- pthread_mutex_lock(&m_mutex_config);
- return m_config;
-}
-
-void P2_Server::unlockConfig()
-{
- pthread_mutex_unlock(&m_mutex_config);
-}
-
-P2_Server::P2_Server(IPDU_Observable *the_PDU_Observable,
- yp2::ThreadPoolSocketObserver *my_thread,
- P2_Config *config,
- P2_ModuleFactory *modules)
- : Z_Assoc(the_PDU_Observable)
-{
- m_my_thread = my_thread;
- m_modules = modules;
- m_config = config;
-
- pthread_mutex_init(&m_mutex_config, 0);
-
- yaz_log(YLOG_LOG, "Construct P2_Server=%p", this);
-}
-
-IPDU_Observer *P2_Server::sessionNotify(IPDU_Observable
- *the_PDU_Observable, int fd)
-{
- P2_Frontend *my = new P2_Frontend(the_PDU_Observable, m_my_thread, this);
- yaz_log(YLOG_LOG, "New session %s", the_PDU_Observable->getpeername());
- return my;
-}
-
-P2_Server::~P2_Server()
-{
- yaz_log(YLOG_LOG, "Destroy P2_server=%p", this);
- pthread_mutex_destroy(&m_mutex_config);
-}
-
-void P2_Server::recv_GDU(Z_GDU *apdu, int len)
-{
-}
-
-void P2_Server::failNotify()
-{
-}
-
-void P2_Server::timeoutNotify()
-{
-}
-
-void P2_Server::connectNotify()
-{
-}
-
-int main(int argc, char **argv)
-{
- p2_xmlerror_setup();
-
- P2_Config config;
-
- if (!config.parse_options(argc, argv))
- {
- yaz_log(YLOG_FATAL, "Configuration incorrect. Exiting");
- exit(1);
- }
-
- SocketManager mySocketManager;
-
- PDU_Assoc *my_PDU_Assoc = 0;
-
- yp2::ThreadPoolSocketObserver my_thread(&mySocketManager,
- config.m_no_threads);
-
- my_PDU_Assoc = new PDU_Assoc(&mySocketManager);
-
- P2_ModuleFactory modules;
-
- modules.add(p2_backend_dummy);
-
- std::list<P2_ConfigModule *>::const_iterator it;
- for (it = config.m_modules.begin(); it != config.m_modules.end(); it++)
- modules.add((*it)->m_fname.c_str());
-
- P2_Server z(my_PDU_Assoc, &my_thread, &config, &modules);
- z.server(config.m_listen_address.c_str());
-
- while (mySocketManager.processEvent() > 0)
- ;
- return 0;
-}
-/*
- * Local variables:
- * c-basic-offset: 4
- * indent-tabs-mode: nil
- * c-file-style: "stroustrup"
- * End:
- * vim: shiftwidth=4 tabstop=8 expandtab
- */
-
-/* $Id: session.hpp,v 1.9 2005-10-25 11:48:30 adam Exp $
+/* $Id: session.hpp,v 1.10 2005-10-25 21:32:01 adam Exp $
Copyright (c) 2005, Index Data.
%LICENSE%
#define SESSION_HPP
//#include <stdexcept>
-
+#include <map>
#include <boost/thread/mutex.hpp>
namespace yp2 {
static unsigned long int m_global_id;
};
+
+ template <class T> class session_map {
+ public:
+ void create(T &t, const yp2::Session &s) {
+ boost::mutex::scoped_lock lock(m_mutex);
+ m_map[s] = t;
+ };
+ void release(const yp2::Session &s) {
+ boost::mutex::scoped_lock lock(m_mutex);
+
+ m_map.erase(s);
+ };
+ bool active(const yp2::Session &s) {
+ typename std::map<yp2::Session,T>::const_iterator it;
+ it = m_map.find(s);
+ return it == m_map.end() ? false : true;
+ }
+ private:
+ boost::mutex m_mutex;
+ std::map<yp2::Session,T>m_map;
+ };
}
-/* $Id: test_filter_virt_db.cpp,v 1.3 2005-10-25 16:01:36 adam Exp $
+/* $Id: test_filter_virt_db.cpp,v 1.4 2005-10-25 21:32:01 adam Exp $
Copyright (c) 2005, Index Data.
%LICENSE%
#include <iostream>
#include <stdexcept>
+#include "test_util.hpp"
#include "filter_virt_db.hpp"
#include "filter_backend_test.hpp"
#include "filter_log.hpp"
}
static void search(yp2::Package &pack, yp2::Router &router,
- const char *pqf_query, const char *db,
+ const std::string &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;
+ yp2::util::pqf(odr, apdu, query);
+
+ apdu->u.searchRequest->resultSetName = odr_strdup(odr, setname);
apdu->u.searchRequest->num_databaseNames = 1;
apdu->u.searchRequest->databaseNames = (char**)
--- /dev/null
+/* $Id: test_util.cpp,v 1.1 2005-10-25 21:32:01 adam Exp $
+ Copyright (c) 2005, Index Data.
+
+%LICENSE%
+ */
+
+#include "config.hpp"
+
+#include <yaz/pquery.h>
+#include "test_util.hpp"
+
+bool yp2::util::pqf(ODR odr, Z_APDU *apdu, const std::string &q) {
+ YAZ_PQF_Parser pqf_parser = yaz_pqf_create();
+
+ Z_RPNQuery *rpn = yaz_pqf_parse(pqf_parser, odr, q.c_str());
+ if (!rpn)
+ {
+ yaz_pqf_destroy(pqf_parser);
+ return false;
+ }
+ yaz_pqf_destroy(pqf_parser);
+ Z_Query *query = (Z_Query *) odr_malloc(odr, sizeof(Z_Query));
+ query->which = Z_Query_type_1;
+ query->u.type_1 = rpn;
+
+ apdu->u.searchRequest->query = query;
+ return true;
+}
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * c-file-style: "stroustrup"
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
--- /dev/null
+/* $Id: test_util.hpp,v 1.1 2005-10-25 21:32:01 adam Exp $
+ Copyright (c) 2005, Index Data.
+
+%LICENSE%
+ */
+
+#ifndef TEST_UTIL_HPP
+#define TEST_UTIL_HPP
+
+#include <yaz/z-core.h>
+#include <string>
+namespace yp2 {
+ struct util {
+ static bool pqf(ODR odr, Z_APDU *apdu, const std::string &q);
+ };
+}
+#endif
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * c-file-style: "stroustrup"
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */