<!-- the Z39.50/HTTP frontend -->
<port>210</port>
</filter>
- <filter id="log_cout" type="log"> <!-- apply logging always -->
- <logfile>mylog.log</logfile>
+ <filter id="log_out" type="log"> <!-- apply logging always -->
+ <logfile>out.log</logfile>
+ </filter>
+ <filter id="log_cerr" type="log"> <!-- apply logging always -->
+ <logfile>std::cerr</logfile>
</filter>
</filters>
<routes>
<route id="start">
- <filter refid="gftr"/>
+ <filter refid="log_cout"/>
<filter type="cond"> <!-- conditional -->
<if test="port=210 and db=public" route="A"/>
<if test="port=210 and db=other" route="B"/>
<default route="C3"/>
</switch>
</filter>
+ <filter refid="log_out"/>
+ <filter refid="log_cerr"/>
<filter type="log"> <!-- apply logging always -->
<logfile>mylog.log</logfile>
</filter>
request-type Init,Search,HTTP,...
origin IP of origin
port Port
+
+
+mother object filter-dom-hash
+ deletes pointers to contexts and filters on program exit
+hash filter-type -> hash-filter-id -> Context
+ -> filter-binary-pointer
+
+moher object router pointer hash
+
+created in mother thread, read only structures.
+
+Context* filter.configure(dom );
+
+
+
+process(Context con)
+
+where each filter can have is own context class
+
+yp2::filter::Log::Context : public Context
+
+
+Filters are constructed with a FilterFactory class which exposes a
+method
+
+Filter* createFilter(std::string type)
+
+ .. which returns a filter
+instance. (The interface pointer that is). The FilterFactory may later
+offer function
+ loadModule(std::string filename);
+or even
+ loadModules(std::string filenamemask);
+
+
+
-->
<!-- observation: the logic could be controlled by a XSLT! -->
-## $Id: Makefile.am,v 1.28 2005-10-26 14:12:00 marc Exp $
+## $Id: Makefile.am,v 1.29 2005-10-26 18:53:49 adam Exp $
MAINTAINERCLEANFILES = Makefile.in config.in config.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 \
- test_util.cpp test_util.hpp
+ util.cpp util.hpp
# Rules for programs..
test_filter_z3950_client \
test_filter_backend_test \
test_filter_virt_db \
+ test_ses_map \
test_router_flexml
TESTS=$(check_PROGRAMS)
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
+test_ses_map_SOURCES = test_ses_map.cpp
test_router_flexml_SOURCES = test_router_flexml.cpp
-
TESTLDADD = $(LDADD) -lboost_unit_test_framework
test_filter1_LDADD = $(TESTLDADD)
test_filter_z3950_client_LDADD = $(TESTLDADD)
test_filter_backend_test_LDADD = $(TESTLDADD)
test_filter_virt_db_LDADD = $(TESTLDADD)
+test_ses_map_LDADD = $(TESTLDADD)
test_router_flexml_LDADD = $(TESTLDADD)
# doxygen target
-/* $Id: ex_filter_frontend_net.cpp,v 1.13 2005-10-26 10:55:26 marc Exp $
+/* $Id: ex_filter_frontend_net.cpp,v 1.14 2005-10-26 18:53:49 adam Exp $
Copyright (c) 2005, Index Data.
%LICENSE%
// put Virt db filter in router
yp2::filter::Virt_db filter_virt_db;
filter_virt_db.add_map_db2vhost("Default", "indexdata.dk/gils");
- filter_virt_db.add_map_db2vhost("Local", "localhost:9999/Default");
+ filter_virt_db.add_map_db2vhost("Local", "localhost:9100/Default");
router.append(filter_virt_db);
-/* $Id: filter_backend_test.cpp,v 1.4 2005-10-25 21:32:01 adam Exp $
+/* $Id: filter_backend_test.cpp,v 1.5 2005-10-26 18:53:49 adam Exp $
Copyright (c) 2005, Index Data.
%LICENSE%
ODR odr = odr_createmem(ODR_ENCODE);
if (apdu_req->which != Z_APDU_initRequest &&
- !m_p->m_sessions.active(package.session()))
+ !m_p->m_sessions.exist(package.session()))
{
apdu_res = zget_APDU(odr, Z_APDU_close);
*apdu_res->u.close->closeReason = Z_Close_protocolError;
-/* $Id: filter_virt_db.cpp,v 1.8 2005-10-25 23:04:06 adam Exp $
+/* $Id: filter_virt_db.cpp,v 1.9 2005-10-26 18:53:49 adam Exp $
Copyright (c) 2005, Index Data.
%LICENSE%
namespace filter {
struct Virt_db_set {
Virt_db_set(yp2::Session &id, std::string setname,
- std::string vhost);
+ std::string vhost, bool named_result_sets);
Virt_db_set();
~Virt_db_set();
yp2::Session m_backend_session;
std::string m_backend_setname;
std::string m_vhost;
+ bool m_named_result_sets;
};
struct Virt_db_session {
Virt_db_session(yp2::Session &id, bool use_vhost);
}
yf::Virt_db_set::Virt_db_set(yp2::Session &id, std::string setname,
- std::string vhost)
- : m_backend_session(id), m_backend_setname(setname), m_vhost(vhost)
+ std::string vhost, bool named_result_sets)
+ : m_backend_session(id), m_backend_setname(setname), m_vhost(vhost),
+ m_named_result_sets(named_result_sets)
{
}
std::string vhost;
std::string database;
std::string resultSetId = req->resultSetName;
+ bool support_named_result_sets = false; // whether backend supports it
{
boost::mutex::scoped_lock lock(m_sessions_mutex);
odr_destroy(odr);
}
+ Z_GDU *gdu = init_package.response().get();
+ // we hope to get an init response
+ if (gdu && gdu->which == Z_GDU_Z3950 && gdu->u.z3950->which ==
+ Z_APDU_initResponse)
+ {
+ if (ODR_MASK_GET(gdu->u.z3950->u.initResponse->options,
+ Z_Options_namedResultSets))
+ support_named_result_sets = true;
+ }
+ else
+ {
+ 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_DATABASE_UNAVAILABLE, database.c_str());
+ package.response() = apdu;
+
+ odr_destroy(odr);
+ return;
+ }
}
// sending search to backend
Package search_package(id, package.origin());
Ses_it it = m_sessions.find(package.session());
if (it != m_sessions.end())
it->second.m_sets[resultSetId] =
- Virt_db_set(id, backend_resultSetId, vhost);
+ Virt_db_set(id, backend_resultSetId, vhost,
+ support_named_result_sets);
}
void yf::Virt_db::Rep::init(Package &package, Z_APDU *apdu, bool &move_later)
-/* $Id: session.hpp,v 1.10 2005-10-25 21:32:01 adam Exp $
+/* $Id: session.hpp,v 1.11 2005-10-26 18:53:49 adam Exp $
Copyright (c) 2005, Index Data.
%LICENSE%
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;
+ boost::mutex::scoped_lock lock(m_map_mutex);
+ m_map[s] = SessionItem(t);
};
void release(const yp2::Session &s) {
- boost::mutex::scoped_lock lock(m_mutex);
+ boost::mutex::scoped_lock lock(m_map_mutex);
m_map.erase(s);
};
- bool active(const yp2::Session &s) {
- typename std::map<yp2::Session,T>::const_iterator it;
+#if 0
+ T &get_session_data(const yp2::Session &s) {
+ boost::mutex::scoped_lock lock(m_map_mutex);
+
+ typename std::map<yp2::Session,SessionItem>::const_iterator it;
+ it = m_map.find(s);
+ if (it == m_map.end())
+ return 0;
+ boost::mutx::scoped_lock *scoped_ptr =
+ new boost::mutex::scoped_lock(it->second->m_item_mutex);
+ };
+#endif
+ bool exist(const yp2::Session &s) {
+ typename std::map<yp2::Session,SessionItem>::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;
+ class SessionItem {
+ public:
+ SessionItem() {};
+ SessionItem(T &t) : m_t(t) {};
+ SessionItem &operator =(const SessionItem &s) {
+ if (this != &s) {
+ m_t = s.m_t;
+ }
+ return *this;
+ };
+ SessionItem(const SessionItem &s) {
+ m_t = s.m_t;
+ };
+ T m_t;
+ boost::mutex m_item_mutex;
+ };
+ private:
+ boost::mutex m_map_mutex;
+ std::map<yp2::Session,SessionItem>m_map;
};
}
-/* $Id: test_filter_backend_test.cpp,v 1.3 2005-10-26 10:55:26 marc Exp $
+/* $Id: test_filter_backend_test.cpp,v 1.4 2005-10-26 18:53:49 adam Exp $
Copyright (c) 2005, Index Data.
%LICENSE%
#include <iostream>
#include <stdexcept>
-#include "test_util.hpp"
+#include "util.hpp"
#include "filter_backend_test.hpp"
#include "filter_log.hpp"
-/* $Id: test_filter_virt_db.cpp,v 1.6 2005-10-26 10:55:26 marc Exp $
+/* $Id: test_filter_virt_db.cpp,v 1.7 2005-10-26 18:53:49 adam Exp $
Copyright (c) 2005, Index Data.
%LICENSE%
#include <iostream>
#include <stdexcept>
-#include "test_util.hpp"
+#include "util.hpp"
#include "filter_virt_db.hpp"
#include "filter_backend_test.hpp"
#include "filter_log.hpp"
--- /dev/null
+/* $Id: test_ses_map.cpp,v 1.1 2005-10-26 18:53:49 adam Exp $
+ Copyright (c) 2005, Index Data.
+
+%LICENSE%
+ */
+
+#include "config.hpp"
+#include <iostream>
+#include <stdexcept>
+
+#include "router.hpp"
+#include "session.hpp"
+#include "package.hpp"
+
+#include <map>
+
+#include <boost/thread.hpp>
+#include <boost/shared_ptr.hpp>
+#define BOOST_AUTO_TEST_MAIN
+#include <boost/test/auto_unit_test.hpp>
+
+#include <yaz/zgdu.h>
+#include <yaz/pquery.h>
+#include <yaz/otherinfo.h>
+using namespace boost::unit_test;
+
+
+namespace yp2 {
+ class SesMap;
+
+
+ class SesMap {
+ class Wrap {
+ public:
+ Wrap(const double &t) : m_t(t) { };
+ double m_t;
+ boost::mutex m_mutex;
+ };
+ private:
+ boost::mutex m_map_mutex;
+ public:
+ void create(SesMap &sm, const yp2::Session &s, double &t) {
+ boost::mutex::scoped_lock lock(m_map_mutex);
+
+ boost::shared_ptr<Wrap> w_ptr(new Wrap(t));
+ m_map_ptr[s] = w_ptr;
+ }
+ std::map<yp2::Session,boost::shared_ptr<Wrap> >m_map_ptr;
+ };
+}
+
+
+BOOST_AUTO_TEST_CASE( test_ses_map_1 )
+{
+ try
+ {
+ yp2::SesMap ses_map;
+ }
+ catch ( ... ) {
+ BOOST_CHECK (false);
+ }
+}
+
+
+/*
+ * 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.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
- */
--- /dev/null
+/* $Id: util.cpp,v 1.1 2005-10-26 18:53:49 adam Exp $
+ Copyright (c) 2005, Index Data.
+
+%LICENSE%
+ */
+
+#include "config.hpp"
+
+#include <yaz/pquery.h>
+#include "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: util.hpp,v 1.1 2005-10-26 18:53:49 adam Exp $
+ Copyright (c) 2005, Index Data.
+
+%LICENSE%
+ */
+
+#ifndef YP2_UTIL_HPP
+#define YP2_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
+ */