-## $Id: Makefile.am,v 1.38 2005-12-10 09:59:10 adam Exp $
+## $Id: Makefile.am,v 1.39 2006-01-04 11:19:04 adam Exp $
MAINTAINERCLEANFILES = Makefile.in config.in config.hpp
filter_backend_test.cpp filter_backend_test.hpp \
filter_session_shared.cpp filter_session_shared.hpp \
filter_template.cpp filter_template.hpp \
+ factory_static.cpp factory_static.hpp \
pipe.cpp pipe.hpp \
util.cpp util.hpp
-/* $Id: ex_filter_frontend_net.cpp,v 1.19 2005-12-09 11:27:59 adam Exp $
+/* $Id: ex_filter_frontend_net.cpp,v 1.20 2006-01-04 11:19:04 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("gils", "indexdata.dk/gils");
- filter_virt_db.add_map_db2vhost("Default", "localhost:9100/Default");
- router.append(filter_virt_db);
+ filter_virt_db.add_map_db2vhost("Default", "localhost:9999/Default");
+ filter_virt_db.add_map_db2vhost("2", "localhost:9999/2");
+ // router.append(filter_virt_db);
-// yp2::filter::Session_shared filter_session_shared;
-// router.append(filter_session_shared);
+ yp2::filter::SessionShared filter_session_shared;
+ //router.append(filter_session_shared);
yp2::filter::Log filter_log_back("BACK");
router.append(filter_log_back);
-/* $Id: ex_router_flexml.cpp,v 1.2 2005-10-31 11:59:08 marc Exp $
+/* $Id: ex_router_flexml.cpp,v 1.3 2006-01-04 11:19:04 adam Exp $
Copyright (c) 2005, Index Data.
%LICENSE%
int main(int argc, char **argv)
{
try
- {
-
+ {
+
std::string xmlconf = "<?xml version=\"1.0\"?>\n"
"<yp2 xmlns=\"http://indexdata.dk/yp2/config/1\">\n"
"<start route=\"start\"/>\n"
--- /dev/null
+/* $Id: factory_static.cpp,v 1.1 2006-01-04 11:19:04 adam Exp $
+ Copyright (c) 2005, Index Data.
+
+%LICENSE%
+
+*/
+
+#include <iostream>
+#include <stdexcept>
+
+#include "factory_static.hpp"
+
+#include "config.hpp"
+#include "filter.hpp"
+#include "package.hpp"
+
+#include "filter_factory.hpp"
+
+#include "filter_backend_test.hpp"
+#include "filter_frontend_net.hpp"
+#include "filter_log.hpp"
+#include "filter_session_shared.hpp"
+#include "filter_template.hpp"
+#include "filter_virt_db.hpp"
+#include "filter_z3950_client.hpp"
+
+yp2::FactoryStatic::FactoryStatic(yp2::FilterFactory &factory)
+{
+ const struct yp2_filter_struct *buildins[] = {
+ &yp2_filter_backend_test,
+ &yp2_filter_frontend_net,
+ &yp2_filter_log,
+ &yp2_filter_session_shared,
+ &yp2_filter_template,
+ &yp2_filter_virt_db,
+ &yp2_filter_z3950_client,
+ 0
+ };
+ int i;
+
+ for (i = 0; buildins[i]; i++)
+ factory.add_creator(buildins[i]->type, buildins[i]->creator);
+}
+
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * c-file-style: "stroustrup"
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
--- /dev/null
+/* $Id: factory_static.hpp,v 1.1 2006-01-04 11:19:04 adam Exp $
+ Copyright (c) 2005, Index Data.
+
+%LICENSE%
+ */
+
+#ifndef FACTORY_STATIC_HPP
+#define FACTORY_STATIC_HPP
+
+#include "filter_factory.hpp"
+
+namespace yp2 {
+ class FactoryStatic {
+ public:
+ FactoryStatic(yp2::FilterFactory &factory);
+ };
+}
+
+#endif
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * c-file-style: "stroustrup"
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
-/* $Id: filter.hpp,v 1.10 2005-12-10 09:59:10 adam Exp $
+/* $Id: filter.hpp,v 1.11 2006-01-04 11:19:04 adam Exp $
Copyright (c) 2005, Index Data.
%LICENSE%
struct yp2_filter_struct {
int ver;
+ const char *type;
yp2::filter::Base* (*creator)();
};
-/* $Id: filter_backend_test.cpp,v 1.10 2005-11-10 23:10:42 adam Exp $
+/* $Id: filter_backend_test.cpp,v 1.11 2006-01-04 11:19:04 adam Exp $
Copyright (c) 2005, Index Data.
%LICENSE%
m_p->m_sessions.release(package.session());
}
+static yp2::filter::Base* filter_creator()
+{
+ return new yp2::filter::Backend_test;
+}
+
+extern "C" {
+ const struct yp2_filter_struct yp2_filter_backend_test = {
+ 0,
+ "backend_test",
+ filter_creator
+ };
+}
+
/*
* Local variables:
-/* $Id: filter_backend_test.hpp,v 1.5 2005-11-10 23:10:42 adam Exp $
+/* $Id: filter_backend_test.hpp,v 1.6 2006-01-04 11:19:04 adam Exp $
Copyright (c) 2005, Index Data.
%LICENSE%
}
}
+extern "C" {
+ extern const struct yp2_filter_struct yp2_filter_backend_test;
+}
+
#endif
/*
* Local variables:
-/* $Id: filter_dl.cpp,v 1.1 2005-12-10 09:59:10 adam Exp $
+/* $Id: filter_dl.cpp,v 1.2 2006-01-04 11:19:04 adam Exp $
Copyright (c) 2005, Index Data.
%LICENSE%
}
extern "C" {
- struct yp2_filter_struct yp2_filter_dl = {
+ const struct yp2_filter_struct yp2_filter_dl = {
0,
+ "dl",
filter_creator
};
}
-/* $Id: filter_frontend_net.cpp,v 1.9 2005-11-07 21:57:10 adam Exp $
+/* $Id: filter_frontend_net.cpp,v 1.10 2006-01-04 11:19:04 adam Exp $
Copyright (c) 2005, Index Data.
%LICENSE%
return m_listen_duration;
}
+static yp2::filter::Base* filter_creator()
+{
+ return new yp2::filter::FrontendNet;
+}
+
+extern "C" {
+ const struct yp2_filter_struct yp2_filter_frontend_net = {
+ 0,
+ "frontend_net",
+ filter_creator
+ };
+}
+
/*
* Local variables:
* c-basic-offset: 4
-/* $Id: filter_frontend_net.hpp,v 1.8 2005-11-07 12:31:43 adam Exp $
+/* $Id: filter_frontend_net.hpp,v 1.9 2006-01-04 11:19:04 adam Exp $
Copyright (c) 2005, Index Data.
%LICENSE%
}
}
+extern "C" {
+ extern const struct yp2_filter_struct yp2_filter_frontend_net;
+}
#endif
/*
-/* $Id: filter_log.cpp,v 1.9 2005-12-11 17:23:05 adam Exp $
+/* $Id: filter_log.cpp,v 1.10 2006-01-04 11:19:04 adam Exp $
Copyright (c) 2005, Index Data.
%LICENSE%
}
}
+static yp2::filter::Base* filter_creator()
+{
+ return new yp2::filter::Log;
+}
+
+extern "C" {
+ const struct yp2_filter_struct yp2_filter_log = {
+ 0,
+ "log",
+ filter_creator
+ };
+}
+
+
/*
* Local variables:
* c-basic-offset: 4
-/* $Id: filter_log.hpp,v 1.10 2005-12-11 17:23:05 adam Exp $
+/* $Id: filter_log.hpp,v 1.11 2006-01-04 11:19:04 adam Exp $
Copyright (c) 2005, Index Data.
%LICENSE%
}
}
+extern "C" {
+ extern const struct yp2_filter_struct yp2_filter_log;
+}
+
#endif
/*
* Local variables:
-/* $Id: filter_session_shared.cpp,v 1.2 2005-12-02 11:05:08 adam Exp $
+/* $Id: filter_session_shared.cpp,v 1.3 2006-01-04 11:19:04 adam Exp $
Copyright (c) 2005, Index Data.
%LICENSE%
namespace yp2 {
namespace filter {
- class Session_shared::Rep {
- friend class Session_shared;
+ class SessionShared::Rep {
+ friend class SessionShared;
void handle_init(Z_InitRequest *req, Package &package);
void handle_search(Z_SearchRequest *req, Package &package);
public:
- typedef boost::shared_ptr<Session_shared::List> SharedList;
+ typedef boost::shared_ptr<SessionShared::List> SharedList;
- typedef std::map<Session_shared::InitKey,SharedList> InitListMap;
+ typedef std::map<SessionShared::InitKey,SharedList> InitListMap;
InitListMap m_init_list_map;
typedef std::map<Session,SharedList> SessionListMap;
SessionListMap m_session_list_map;
};
- class Session_shared::InitKey {
- friend class Session_shared;
- friend class Session_shared::Rep;
+ class SessionShared::InitKey {
+ friend class SessionShared;
+ friend class SessionShared::Rep;
std::string m_vhost;
std::string m_open;
std::string m_user;
std::string m_group;
std::string m_password;
public:
- bool operator < (const Session_shared::InitKey &k) const;
+ bool operator < (const SessionShared::InitKey &k) const;
};
- class Session_shared::List {
+ class SessionShared::List {
public:
yazpp_1::GDU m_init_response; // init response for backend
Session m_session; // session for backend
using namespace yp2;
-bool yf::Session_shared::InitKey::operator < (const Session_shared::InitKey
+bool yf::SessionShared::InitKey::operator < (const SessionShared::InitKey
&k) const
{
if (m_vhost < k.m_vhost)
return false;
}
-yf::Session_shared::Session_shared() : m_p(new Rep)
+yf::SessionShared::SessionShared() : m_p(new Rep)
{
}
-yf::Session_shared::~Session_shared()
+yf::SessionShared::~SessionShared()
{
}
-void yf::Session_shared::Rep::handle_search(Z_SearchRequest *req,
+void yf::SessionShared::Rep::handle_search(Z_SearchRequest *req,
Package &package)
{
yaz_log(YLOG_LOG, "Got search");
package.response() = search_package.response();
}
-void yf::Session_shared::Rep::handle_init(Z_InitRequest *req, Package &package)
+void yf::SessionShared::Rep::handle_init(Z_InitRequest *req, Package &package)
{
yaz_log(YLOG_LOG, "Got init");
- Session_shared::InitKey key;
+ SessionShared::InitKey key;
const char *vhost =
yaz_oi_get_string_oidval(&req->otherInfo, VAL_PROXY, 1, 0);
if (vhost)
yaz_log(YLOG_LOG, "New KEY");
// building new package with original init and new session
- SharedList l(new Session_shared::List); // new session for backend
+ SharedList l(new SessionShared::List); // new session for backend
Package init_package(l->m_session, package.origin());
init_package.copy_filter(package);
}
}
-void yf::Session_shared::process(Package &package) const
+void yf::SessionShared::process(Package &package) const
{
// don't tell the backend if the "fronent" filter closes..
// we want to keep them alive
package.move(); // Not Z39.50 or not Init
}
+static yp2::filter::Base* filter_creator()
+{
+ return new yp2::filter::SessionShared;
+}
+
+extern "C" {
+ const struct yp2_filter_struct yp2_filter_session_shared = {
+ 0,
+ "session_shared",
+ filter_creator
+ };
+}
+
+
/*
* Local variables:
-/* $Id: filter_session_shared.hpp,v 1.1 2005-11-14 23:35:22 adam Exp $
+/* $Id: filter_session_shared.hpp,v 1.2 2006-01-04 11:19:04 adam Exp $
Copyright (c) 2005, Index Data.
%LICENSE%
namespace yp2 {
namespace filter {
- class Session_shared : public Base {
+ class SessionShared : public Base {
class Rep;
class InitKey;
class List;
public:
- ~Session_shared();
- Session_shared();
+ ~SessionShared();
+ SessionShared();
void process(yp2::Package & package) const;
private:
boost::scoped_ptr<Rep> m_p;
}
}
+extern "C" {
+ extern const struct yp2_filter_struct yp2_filter_session_shared;
+}
+
#endif
/*
* Local variables:
-/* $Id: filter_template.cpp,v 1.2 2005-12-11 17:20:18 adam Exp $
+/* $Id: filter_template.cpp,v 1.3 2006-01-04 11:19:04 adam Exp $
Copyright (c) 2005, Index Data.
%LICENSE%
package.move();
}
+static yp2::filter::Base* filter_creator()
+{
+ return new yp2::filter::Template;
+}
+
+extern "C" {
+ const struct yp2_filter_struct yp2_filter_template = {
+ 0,
+ "template",
+ filter_creator
+ };
+}
+
/*
* Local variables:
-/* $Id: filter_template.hpp,v 1.2 2005-12-11 17:20:18 adam Exp $
+/* $Id: filter_template.hpp,v 1.3 2006-01-04 11:19:04 adam Exp $
Copyright (c) 2005, Index Data.
%LICENSE%
}
}
+extern "C" {
+ extern const struct yp2_filter_struct yp2_filter_template;
+}
+
#endif
/*
* Local variables:
-/* $Id: filter_virt_db.cpp,v 1.15 2005-12-19 08:42:59 adam Exp $
+/* $Id: filter_virt_db.cpp,v 1.16 2006-01-04 11:19:04 adam Exp $
Copyright (c) 2005, Index Data.
%LICENSE%
#include "package.hpp"
#include <boost/thread/mutex.hpp>
+#include <boost/thread/condition.hpp>
#include "util.hpp"
#include "filter_virt_db.hpp"
Virt_db_map();
std::string m_vhost;
};
+ struct Frontend {
+ Frontend();
+ ~Frontend();
+ yp2::Session m_session;
+ bool m_use_vhost;
+ bool m_in_use;
+ std::map<std::string,Virt_db_set> m_sets;
+ void search(Package &package, Z_APDU *apdu,
+ const std::map<std::string, Virt_db_map> &maps);
+ void present(Package &package, Z_APDU *apdu);
+ void close(Package &package);
+ typedef std::map<std::string,Virt_db_set>::iterator Sets_it;
+ };
class Virt_db::Rep {
friend class Virt_db;
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);
+
+ Frontend *get_frontend(Package &package);
+ void release_frontend(Package &package);
private:
boost::mutex m_sessions_mutex;
std::map<yp2::Session,Virt_db_session>m_sessions;
typedef std::map<yp2::Session,Virt_db_session>::iterator Ses_it;
typedef std::map<std::string,Virt_db_set>::iterator Sets_it;
+
+ boost::mutex m_mutex;
+ boost::condition m_cond_session_ready;
+ std::map<yp2::Session,Frontend *> m_clients;
};
}
}
using namespace yp2;
+yf::Frontend::Frontend()
+{
+ m_use_vhost = false;
+}
+
+void yf::Frontend::close(Package &package)
+{
+ Sets_it sit = m_sets.begin();
+ for (; sit != m_sets.end(); sit++)
+ {
+ sit->second.m_backend_session.close();
+ Package close_package(sit->second.m_backend_session, package.origin());
+ close_package.copy_filter(package);
+
+ close_package.move();
+ }
+}
+
+yf::Frontend::~Frontend()
+{
+}
+
+yf::Frontend *yf::Virt_db::Rep::get_frontend(Package &package)
+{
+ boost::mutex::scoped_lock lock(m_mutex);
+
+ std::map<yp2::Session,yf::Frontend *>::iterator it;
+
+ while(true)
+ {
+ it = m_clients.find(package.session());
+ if (it == m_clients.end())
+ break;
+
+ if (!it->second->m_in_use)
+ {
+ it->second->m_in_use = true;
+ return it->second;
+ }
+ m_cond_session_ready.wait(lock);
+ }
+ Frontend *f = new Frontend;
+ m_clients[package.session()] = f;
+ f->m_in_use = true;
+ return f;
+}
+
+
+void yf::Virt_db::Rep::release_frontend(Package &package)
+{
+ boost::mutex::scoped_lock lock(m_mutex);
+ std::map<yp2::Session,yf::Frontend *>::iterator it;
+
+ it = m_clients.find(package.session());
+ if (it != m_clients.end())
+ {
+ if (package.session().is_closed())
+ {
+ std::cout << "Closing IT\n";
+ it->second->close(package);
+ delete it->second;
+ m_clients.erase(it);
+ }
+ else
+ {
+ it->second->m_in_use = false;
+ }
+ m_cond_session_ready.notify_all();
+ }
+}
+
yf::Virt_db_set::Virt_db_set(yp2::Session &id, std::string setname,
std::string vhost, bool named_result_sets)
: m_backend_session(id), m_backend_setname(setname), m_vhost(vhost),
delete id;
}
+void yf::Frontend::present(Package &package, Z_APDU *apdu)
+{
+ Session *id = 0;
+ Z_PresentRequest *req = apdu->u.presentRequest;
+ std::string resultSetId = req->resultSetId;
+ yp2::odr odr;
+
+ Sets_it sets_it = m_sets.find(resultSetId);
+ if (sets_it == m_sets.end())
+ {
+ 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,
+ resultSetId.c_str());
+ package.response() = apdu;
+
+ return;
+ }
+ id = new yp2::Session(sets_it->second.m_backend_session);
+
+ // 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);
+
+ present_package.move();
+
+ if (present_package.session().is_closed())
+ {
+ 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_RESULT_SET_NO_LONGER_EXISTS_UNILATERALLY_DELETED_BY_,
+ resultSetId.c_str());
+ package.response() = apdu;
+
+ m_sets.erase(resultSetId);
+ }
+ else
+ {
+ package.response() = present_package.response();
+ }
+ delete id;
+}
+
void yf::Virt_db::Rep::search(Package &package, Z_APDU *apdu, bool &move_later)
{
Z_SearchRequest *req = apdu->u.searchRequest;
support_named_result_sets);
}
+void yf::Frontend::search(Package &package, Z_APDU *apdu,
+ const std::map<std::string, Virt_db_map> &maps)
+{
+ Z_SearchRequest *req = apdu->u.searchRequest;
+ std::string vhost;
+ std::string database;
+ std::string resultSetId = req->resultSetName;
+ bool support_named_result_sets = false; // whether backend supports it
+ yp2::odr odr;
+
+ if (req->num_databaseNames != 1)
+ { // exactly one database must be specified
+ 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_TOO_MANY_DATABASES_SPECIFIED, 0);
+ package.response() = apdu;
+
+ return;
+ }
+ database = req->databaseNames[0];
+ std::map<std::string, Virt_db_map>::const_iterator map_it;
+ map_it = maps.find(database);
+ if (map_it == maps.end())
+ { // no map for database: return diagnostic
+ 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_DOES_NOT_EXIST, database.c_str());
+ package.response() = apdu;
+
+ return;
+ }
+ if (*req->replaceIndicator == 0)
+ {
+ Sets_it sets_it = m_sets.find(req->resultSetName);
+ if (sets_it != m_sets.end())
+ {
+ 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;
+
+ return;
+ }
+ }
+ m_sets.erase(req->resultSetName);
+ vhost = map_it->second.m_vhost;
+ // we might look for an existing session with same vhost
+ Session id;
+ const char *vhost_cstr = vhost.c_str();
+ if (true)
+ { // sending init to backend
+ Package init_package(id, package.origin());
+ init_package.copy_filter(package);
+
+ Z_APDU *init_apdu = zget_APDU(odr, Z_APDU_initRequest);
+
+ yaz_oi_set_string_oidval(&init_apdu->u.initRequest->otherInfo, odr,
+ VAL_PROXY, 1, vhost_cstr);
+
+ init_package.request() = init_apdu;
+
+ init_package.move(); // sending init
+
+ if (init_package.session().is_closed())
+ {
+ 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;
+ }
+ 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
+ {
+ 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;
+
+ return;
+ }
+ }
+ // sending search to backend
+ Package search_package(id, package.origin());
+
+ search_package.copy_filter(package);
+ const char *sep = strchr(vhost_cstr, '/');
+ if (sep)
+ req->databaseNames[0] = odr_strdup(odr, sep+1);
+
+ *req->replaceIndicator = 1;
+
+ std::string backend_resultSetId = "default";
+ req->resultSetName = odr_strdup(odr, backend_resultSetId.c_str());
+ search_package.request() = yazpp_1::GDU(apdu);
+
+ search_package.move();
+
+ if (search_package.session().is_closed())
+ {
+ 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;
+
+ return;
+ }
+ package.response() = search_package.response();
+
+ m_sets[resultSetId] =
+ 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)
{
release_session(package);
else
{
m_sessions[package.session()] = Virt_db_session(package.session(), true);
- move_later = true;
+ package.move();
}
}
m_p->m_maps[db] = Virt_db_map(vhost);
}
+#if 0
+void yf::Virt_db::process(Package &package) const
+{
+ yf::Frontend *f = m_p->get_frontend(package);
+ if (f)
+ {
+ Z_GDU *gdu = package.request().get();
+ if (!gdu || gdu->which != Z_GDU_Z3950 || f->m_use_vhost)
+ package.move();
+ else
+ {
+ Z_APDU *apdu = gdu->u.z3950;
+ if (apdu->which == Z_APDU_initRequest)
+ {
+ Z_InitRequest *req = apdu->u.initRequest;
+
+ const char *vhost =
+ yaz_oi_get_string_oidval(&req->otherInfo, VAL_PROXY, 1, 0);
+ if (!vhost)
+ {
+ yp2::odr odr;
+ Z_APDU *apdu = zget_APDU(odr, Z_APDU_initResponse);
+ Z_InitResponse *resp = apdu->u.initResponse;
+
+ int i;
+ static const int masks[] = {
+ Z_Options_search, Z_Options_present, Z_Options_namedResultSets, -1
+ };
+ for (i = 0; masks[i] != -1; i++)
+ if (ODR_MASK_GET(req->options, masks[i]))
+ ODR_MASK_SET(resp->options, masks[i]);
+
+ static const int versions[] = {
+ Z_ProtocolVersion_1,
+ Z_ProtocolVersion_2,
+ Z_ProtocolVersion_3,
+ -1
+ };
+ for (i = 0; versions[i] != -1; i++)
+ if (ODR_MASK_GET(req->protocolVersion, versions[i]))
+ ODR_MASK_SET(resp->protocolVersion, versions[i]);
+ else
+ break;
+
+ package.response() = apdu;
+ }
+ else
+ {
+ f->m_use_vhost = true;
+ package.move();
+ }
+ }
+ else if (apdu->which == Z_APDU_searchRequest)
+ {
+ f->search(package, apdu, m_p->m_maps);
+ }
+ else if (apdu->which == Z_APDU_presentRequest)
+ {
+ f->present(package, apdu);
+ }
+ else
+ {
+ yp2::odr odr;
+
+ package.response() = odr.create_close(
+ Z_Close_protocolError,
+ "unsupported APDU in filter_virt_db");
+
+ package.session().close();
+ }
+ }
+ }
+ m_p->release_frontend(package);
+}
+
+#else
void yf::Virt_db::process(Package &package) const
{
Z_GDU *gdu = package.request().get();
package.move();
}
}
+#endif
+
+
+static yp2::filter::Base* filter_creator()
+{
+ return new yp2::filter::Virt_db;
+}
+
+extern "C" {
+ const struct yp2_filter_struct yp2_filter_virt_db = {
+ 0,
+ "virt_db",
+ filter_creator
+ };
+}
/*
-/* $Id: filter_virt_db.hpp,v 1.4 2005-10-31 09:40:18 marc Exp $
+/* $Id: filter_virt_db.hpp,v 1.5 2006-01-04 11:19:04 adam Exp $
Copyright (c) 2005, Index Data.
%LICENSE%
}
}
+extern "C" {
+ extern const struct yp2_filter_struct yp2_filter_virt_db;
+}
+
#endif
/*
* Local variables:
-/* $Id: filter_z3950_client.cpp,v 1.13 2006-01-03 15:34:10 adam Exp $
+/* $Id: filter_z3950_client.cpp,v 1.14 2006-01-04 11:19:04 adam Exp $
Copyright (c) 2005, Index Data.
%LICENSE%
}
+static yp2::filter::Base* filter_creator()
+{
+ return new yp2::filter::Z3950Client;
+}
+
+extern "C" {
+ const struct yp2_filter_struct yp2_filter_z3950_client = {
+ 0,
+ "z3950_client",
+ filter_creator
+ };
+}
+
/*
* Local variables:
* c-basic-offset: 4
-/* $Id: filter_z3950_client.hpp,v 1.5 2005-11-10 23:10:42 adam Exp $
+/* $Id: filter_z3950_client.hpp,v 1.6 2006-01-04 11:19:04 adam Exp $
Copyright (c) 2005, Index Data.
%LICENSE%
}
}
+extern "C" {
+ extern const struct yp2_filter_struct yp2_filter_z3950_client;
+}
+
#endif
/*
* Local variables:
-/* $Id: package.cpp,v 1.1 2005-11-11 15:00:25 adam Exp $
+/* $Id: package.cpp,v 1.2 2006-01-04 11:19:04 adam Exp $
Copyright (c) 2005, Index Data.
%LICENSE%
}
-unsigned int yp2::Package::data() const
+int yp2::Package::data() const
{
return m_data;
}
-unsigned int & yp2::Package::data()
+int & yp2::Package::data()
{
return m_data;
}
-
-yp2::Package & yp2::Package::data(const unsigned int & data)
+yp2::Package & yp2::Package::data(const int & data)
{
m_data = data;
return *this;
-/* $Id: package.hpp,v 1.10 2005-11-11 15:00:25 adam Exp $
+/* $Id: package.hpp,v 1.11 2006-01-04 11:19:04 adam Exp $
Copyright (c) 2005, Index Data.
%LICENSE%
yp2::Session & session();
/// get function - right val in assignment
- unsigned int data() const;
+ int data() const;
-
/// set function - left val in assignment
- unsigned int & data();
+ int & data();
/// set function - can be chained
- Package & data(const unsigned int & data);
+ Package & data(const int & data);
/// get function - right val in assignment
Origin origin() const;
const filter::Base *m_filter;
const Router *m_router;
- unsigned int m_data;
+ int m_data;
yazpp_1::GDU m_request_gdu;
yazpp_1::GDU m_response_gdu;
-/* $Id: router_flexml.cpp,v 1.6 2005-12-08 22:32:57 adam Exp $
+/* $Id: router_flexml.cpp,v 1.7 2006-01-04 11:19:04 adam Exp $
Copyright (c) 2005, Index Data.
%LICENSE%
#include "config.hpp"
#include "router_flexml.hpp"
+#include "filter_factory.hpp"
+#include "factory_static.hpp"
#include <iostream>
#include <map>
const xmlNode* jump_to_next(const xmlNode* node, int xml_node_type);
const xmlNode* jump_to_children(const xmlNode* node, int xml_node_type);
+ FilterFactory m_factory;
};
}
filter_nr++;
std::cout << "processing /yp2/filters/filter["
<< filter_nr << "]" << std::endl;
+
+ const struct _xmlAttr *attr;
+ std::string id_value;
+ std::string type_value;
+ for (attr = node2->properties; attr; attr = attr->next)
+ {
+ std::string name = std::string((const char *) attr->name);
+ std::string value;
+
+ if (attr->children && attr->children->type == XML_TEXT_NODE)
+ value = std::string((const char *)attr->children->content);
+
+ if (name == "id")
+ id_value = value;
+ else if (name == "type")
+ type_value = value;
+ else
+ throw XMLError("Error. Only attribute id or type allowed in filter element. Got " + name);
+
+ std::cout << "attr " << name << "=" << value << "\n";
+
+ //const xmlNode *val;
+ }
+
+ yp2::filter::Base* filter_base = m_factory.create(type_value);
+
node2 = jump_to_next(node2, XML_ELEMENT_NODE);
}
yp2::RouterFleXML::RouterFleXML(std::string xmlconf)
: m_p(new Rep)
{
+ {
+ yp2::FactoryStatic fs(m_p->m_factory);
+ }
+
LIBXML_TEST_VERSION;
xmlDocPtr doc = xmlParseMemory(xmlconf.c_str(),
-/* $Id: test_router_flexml.cpp,v 1.7 2005-12-08 22:32:58 adam Exp $
+/* $Id: test_router_flexml.cpp,v 1.8 2006-01-04 11:19:04 adam Exp $
Copyright (c) 2005, Index Data.
%LICENSE%
#include "filter.hpp"
#include "router_flexml.hpp"
+#include "filter_factory.hpp"
#define BOOST_AUTO_TEST_MAIN
#include <boost/test/auto_unit_test.hpp>
"<yp2 xmlns=\"http://indexdata.dk/yp2/config/1\">\n"
" <start route=\"start\"/>\n"
" <filters>\n"
- " <filter id=\"front_default\" type=\"frontend-net\">\n"
+ " <filter id=\"front_default\" type=\"frontend_net\">\n"
" <port>210</port>\n"
" </filter>\n"
" <filter id=\"log_cout\" type=\"log\">\n"
"</yp2>\n";
yp2::RouterFleXML rflexml(xmlconf);
}
+ catch ( yp2::RouterFleXML::XMLError &e) {
+ std::cout << "XMLError: " << e.what() << "\n";
+ BOOST_CHECK (false);
+ }
+ catch ( yp2::FilterFactoryException &e) {
+ std::cout << "FilterFactoryException: " << e.what() << "\n";
+ BOOST_CHECK (false);
+ }
catch ( ... ) {
BOOST_CHECK (false);
}
"<y:yp2 xmlns:y=\"http://indexdata.dk/yp2/config/1\">\n"
" <start route=\"start\"/>\n"
" <filters>\n"
- " <filter id=\"front_default\" type=\"frontend-net\">\n"
+ " <filter id=\"front_default\" type=\"frontend_net\">\n"
" <port>210</port>\n";
yp2::RouterFleXML rflexml(xmlconf_invalid);
"<y:yp2 xmlns:y=\"http://indexdata.dk/yp2/config/1\">\n"
" <y:start route=\"start\"/>\n"
" <y:filters>\n"
- " <y:filter id=\"front_default\" type=\"frontend-net\">\n"
+ " <y:filter id=\"front_default\" type=\"frontend_net\">\n"
" <port>210</port>\n"
" </y:filter>\n"
" <y:filter id=\"log_cout\" type=\"log\">\n"