From: Heikki Levanto Date: Wed, 12 Jun 2013 13:31:08 +0000 (+0200) Subject: Merge remote-tracking branch 'origin/master' into rewrite-filter X-Git-Tag: v1.3.59~57^2~8 X-Git-Url: http://sru.miketaylor.org.uk/?a=commitdiff_plain;h=a370d3def5758d5f2d1d7113a27871655fc7cec5;hp=df9b11da1202e8af0eb10633a44405e45c94800e;p=metaproxy-moved-to-github.git Merge remote-tracking branch 'origin/master' into rewrite-filter --- diff --git a/configure.ac b/configure.ac index 6f870a0..ada1153 100644 --- a/configure.ac +++ b/configure.ac @@ -45,11 +45,11 @@ if test -z "$YAZPPLIB"; then AC_MSG_ERROR([YAZ++ development libraries missing]) fi CPPFLAGS="$YAZPPINC $CPPFLAGS" -AC_MSG_CHECKING([if YAZ is version 4.2.50 or later]) +AC_MSG_CHECKING([if YAZ is version 4.2.59 or later]) AC_COMPILE_IFELSE( [AC_LANG_PROGRAM([[#include ]], [[ -#if YAZ_VERSIONL < 0x40232 +#if YAZ_VERSIONL < 0x4023B #error too old #endif ]])], diff --git a/debian/control b/debian/control index be118e0..1756ecb 100644 --- a/debian/control +++ b/debian/control @@ -4,7 +4,7 @@ Standards-Version: 3.6.2 Maintainer: Adam Dickmeiss Priority: extra Build-Depends: debhelper (>= 5), - libyaz4-dev (>= 4.2.50), + libyaz4-dev (>= 4.2.59), libyazpp5-dev (>= 1.4.1), libxslt1-dev, libboost-dev, diff --git a/include/metaproxy/Makefile.am b/include/metaproxy/Makefile.am index 0f38914..9c80072 100644 --- a/include/metaproxy/Makefile.am +++ b/include/metaproxy/Makefile.am @@ -2,5 +2,6 @@ ## Copyright (C) 2005-2013 Index Data pkginclude_HEADERS= filter.hpp origin.hpp package.hpp \ - router.hpp session.hpp util.hpp xmlutil.hpp router_chain.hpp + router.hpp router_chain.hpp router_xml.hpp \ + session.hpp util.hpp xmlutil.hpp diff --git a/include/metaproxy/router_xml.hpp b/include/metaproxy/router_xml.hpp new file mode 100644 index 0000000..2792ba7 --- /dev/null +++ b/include/metaproxy/router_xml.hpp @@ -0,0 +1,60 @@ +/* This file is part of Metaproxy. + Copyright (C) 2005-2013 Index Data + +Metaproxy 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. + +Metaproxy 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 this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef ROUTER_XML_HPP +#define ROUTER_XML_HPP + +#include + +#include +#include + +namespace metaproxy_1 +{ + class RouterXML : public metaproxy_1::Router + { + class Rep; + class Route; + class Pos; + public: + RouterXML(xmlDocPtr doc, + bool test_only, const char *file_include_path); + RouterXML(std::string xmlconf, + bool test_only); + + ~RouterXML(); + + virtual RoutePos *createpos() const; + void start(); + void stop(); + private: + boost::scoped_ptr m_p; + }; + +}; +#endif + +/* + * Local variables: + * c-basic-offset: 4 + * c-file-style: "Stroustrup" + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ + diff --git a/metaproxy.spec b/metaproxy.spec index 5a7bf29..80e42a3 100644 --- a/metaproxy.spec +++ b/metaproxy.spec @@ -9,7 +9,7 @@ Vendor: Index Data ApS Source: metaproxy-%{version}.tar.gz BuildRoot: %{_tmppath}/%{name}-%{version}-root Prefix: %{_prefix} /etc/metaproxy -BuildRequires: pkgconfig, libyaz4-devel >= 4.2.50, libyazpp5-devel >= 1.4.1 +BuildRequires: pkgconfig, libyaz4-devel >= 4.2.59, libyazpp5-devel >= 1.4.1 BuildRequires: libxslt-devel, boost-devel Conflicts: cf-engine <= 2.12.5 Packager: Adam Dickmeiss diff --git a/src/Makefile.am b/src/Makefile.am index 42bb6b3..92f526e 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -12,8 +12,6 @@ AM_CPPFLAGS = -I$(top_srcdir)/include $(USEMARCONINC) bin_SCRIPTS = metaproxy-config filter_src = \ - factory_filter.cpp factory_filter.hpp \ - factory_static.cpp factory_static.hpp \ filter_auth_simple.cpp filter_auth_simple.hpp \ filter_backend_test.cpp filter_backend_test.hpp \ filter_bounce.cpp filter_bounce.hpp \ @@ -39,13 +37,14 @@ filter_src = \ filter_virt_db.cpp filter_virt_db.hpp \ filter_z3950_client.cpp filter_z3950_client.hpp \ filter_zeerex_explain.cpp filter_zeerex_explain.hpp \ - filter_zoom.cpp filter_zoom.hpp \ - router_flexml.hpp router_flexml.cpp + filter_zoom.cpp filter_zoom.hpp lib_LTLIBRARIES = libmetaproxy.la libmetaproxy_la_LDFLAGS = -version-info 4:0:0 -export-dynamic libmetaproxy_la_SOURCES = \ + factory_filter.cpp factory_filter.hpp \ + factory_static.cpp factory_static.hpp \ filter.cpp \ gduutil.cpp gduutil.hpp \ origin.cpp \ @@ -60,6 +59,8 @@ libmetaproxy_la_SOURCES = \ util.cpp \ html_parser.hpp html_parser.cpp \ router_chain.cpp \ + router_flexml.hpp router_flexml.cpp \ + router_xml.cpp \ xmlutil.cpp libmetaproxy_la_LIBADD = $(YAZPPLALIB) \ diff --git a/src/factory_filter.cpp b/src/factory_filter.cpp index 7ea6d3a..3915202 100644 --- a/src/factory_filter.cpp +++ b/src/factory_filter.cpp @@ -101,15 +101,6 @@ mp::filter::Base* mp::FactoryFilter::create(std::string fi) return (it->second()); } -bool mp::FactoryFilter::have_dl_support() -{ -#if HAVE_DLFCN_H - return true; -#else - return false; -#endif -} - bool mp::FactoryFilter::add_creator_dl(const std::string &fi, const std::string &path) { diff --git a/src/factory_filter.hpp b/src/factory_filter.hpp index 0b54e14..5498d75 100644 --- a/src/factory_filter.hpp +++ b/src/factory_filter.hpp @@ -50,8 +50,6 @@ namespace metaproxy_1 { bool add_creator_dl(const std::string &fi, const std::string &path); - bool have_dl_support(); - class NotFound : public std::runtime_error { public: NotFound(const std::string msg); diff --git a/src/factory_static.cpp b/src/factory_static.cpp index c3adc54..26078b3 100644 --- a/src/factory_static.cpp +++ b/src/factory_static.cpp @@ -61,6 +61,7 @@ namespace mp = metaproxy_1; mp::FactoryStatic::FactoryStatic() { #ifdef HAVE_DLFCN_H +#else struct metaproxy_1_filter_struct *buildins[] = { &metaproxy_1_filter_auth_simple, &metaproxy_1_filter_backend_test, diff --git a/src/filter_http_client.cpp b/src/filter_http_client.cpp index 74a1aa8..6cb9633 100644 --- a/src/filter_http_client.cpp +++ b/src/filter_http_client.cpp @@ -71,11 +71,16 @@ void yf::HTTPClient::Rep::proxy(mp::Package &package) Z_GDU *res_gdu = 0; mp::odr o; yaz_url_t yaz_url = yaz_url_create(); - std::string uri; + const char *http_proxy = + z_HTTP_header_remove(&hreq->headers, "X-Metaproxy-Proxy"); + + if (!http_proxy) + http_proxy = proxy_host.c_str(); - if (proxy_host.length()) - yaz_url_set_proxy(yaz_url, proxy_host.c_str()); + if (*http_proxy) + yaz_url_set_proxy(yaz_url, http_proxy); + std::string uri; if (hreq->path[0] == '/') { if (default_host.length()) @@ -92,14 +97,7 @@ void yf::HTTPClient::Rep::proxy(mp::Package &package) if (http_response) { res_gdu = o.create_HTTP_Response(package.session(), hreq, 200); - Z_HTTP_Header **hp = &http_response->headers; - while (*hp) - { - if (!yaz_matchstr((*hp)->name, "Transfer-Encoding")) - *hp = (*hp)->next; - else - hp = &(*hp)->next; - } + z_HTTP_header_remove(&http_response->headers, "Transfer-Encoding"); res_gdu->u.HTTP_Response = http_response; } else diff --git a/src/filter_sru_to_z3950.cpp b/src/filter_sru_to_z3950.cpp index 5704479..ff15d8e 100644 --- a/src/filter_sru_to_z3950.cpp +++ b/src/filter_sru_to_z3950.cpp @@ -93,7 +93,8 @@ namespace metaproxy_1 { mp::odr &odr_en, Z_SRW_PDU *sru_pdu_res, Z_SRW_searchRetrieveRequest const *sr_req, - std::string zurl + std::string zurl, + std::string db_append ) const; bool z3950_present_request( @@ -224,6 +225,7 @@ void yf::SRUtoZ3950::Impl::sru(mp::Package &package, Z_GDU *zgdu_req) bool enable_package_log = false; std::string zurl; + std::string dbargs; Z_SRW_extra_arg *arg; for ( arg = sru_pdu_req->extra_args; arg; arg = arg->next) @@ -247,6 +249,15 @@ void yf::SRUtoZ3950::Impl::sru(mp::Package &package, Z_GDU *zgdu_req) package.log_enable(); } } + else if (!strncmp(arg->name, "x-client-", 9) && arg->value) + { + if (dbargs.length()) + dbargs += '&'; + dbargs += mp_util::uri_encode(arg->name + 9); + dbargs += '='; + dbargs += mp_util::uri_encode(arg->value); + } + assert(sru_pdu_req); // filter acts as sink for SRU explain requests @@ -272,7 +283,7 @@ void yf::SRUtoZ3950::Impl::sru(mp::Package &package, Z_GDU *zgdu_req) zurl, sru_pdu_res, sru_pdu_req)) { ok = z3950_search_request(package, odr_en, - sru_pdu_res, sr_req, zurl); + sru_pdu_res, sr_req, zurl, dbargs); if (ok && sru_pdu_res->u.response->numberOfRecords @@ -549,7 +560,8 @@ bool yf::SRUtoZ3950::Impl::z3950_search_request(mp::Package &package, Z_SRW_PDU *sru_pdu_res, Z_SRW_searchRetrieveRequest const *sr_req, - std::string zurl) const + std::string zurl, + std::string dbappend) const { assert(sru_pdu_res->u.response); @@ -568,16 +580,22 @@ bool yf::SRUtoZ3950::Impl::z3950_search_request(mp::Package &package, &z_searchRequest->num_databaseNames, &z_searchRequest->databaseNames)) { - z_searchRequest->num_databaseNames = 1; - z_searchRequest->databaseNames = (char**) - odr_malloc(odr_en, sizeof(char *)); + std::string db; if (sr_req->database) - z_searchRequest->databaseNames[0] - = odr_strdup(odr_en, const_cast(sr_req->database)); + db = sr_req->database; else - z_searchRequest->databaseNames[0] - = odr_strdup(odr_en, "Default"); + db = "Default"; + + if (dbappend.length()) + { + db += ","; + db += dbappend; + } + z_searchRequest->num_databaseNames = 1; + z_searchRequest->databaseNames = (char**) + odr_malloc(odr_en, sizeof(char *)); + z_searchRequest->databaseNames[0] = odr_strdup(odr_en, db.c_str()); } Z_Query *z_query = (Z_Query *) odr_malloc(odr_en, sizeof(Z_Query)); diff --git a/src/metaproxy_prog.cpp b/src/metaproxy_prog.cpp index bfa1b77..a4ec7f0 100644 --- a/src/metaproxy_prog.cpp +++ b/src/metaproxy_prog.cpp @@ -30,8 +30,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include #include #include -#include "router_flexml.hpp" -#include "factory_static.hpp" +#include #if HAVE_UNISTD_H #include @@ -45,7 +44,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA namespace mp = metaproxy_1; -mp::RouterFleXML *routerp = 0; +mp::RouterXML *routerp = 0; static void set_log_prefix(void) { @@ -84,7 +83,7 @@ static void work_common(void *data) signal(SIGTERM, sig_term_handler); signal(SIGUSR1, sig_usr1_handler); #endif - routerp = (mp::RouterFleXML*) data; + routerp = (mp::RouterXML*) data; routerp->start(); mp::Package pack; @@ -247,9 +246,8 @@ static int sc_main( wrbuf_puts(base_path, "."); ret = 0; try { - mp::FactoryStatic factory; - mp::RouterFleXML *router = - new mp::RouterFleXML(doc, factory, test_config, wrbuf_cstr(base_path)); + mp::RouterXML *router = + new mp::RouterXML(doc, test_config, wrbuf_cstr(base_path)); if (!test_config) { diff --git a/src/router_xml.cpp b/src/router_xml.cpp new file mode 100644 index 0000000..9abba65 --- /dev/null +++ b/src/router_xml.cpp @@ -0,0 +1,92 @@ +/* This file is part of Metaproxy. + Copyright (C) 2005-2013 Index Data + +Metaproxy 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. + +Metaproxy 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 this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include "config.hpp" +#include +#include "router_flexml.hpp" +#include "factory_static.hpp" + +namespace mp = metaproxy_1; + +namespace metaproxy_1 { + class RouterXML::Rep { + public: + Rep(xmlDocPtr, bool, const char *); + Rep(std::string, bool); + ~Rep(); + FactoryStatic m_factory; + boost::scoped_ptr m_flexml; + }; +} + +mp::RouterXML::Rep::Rep(xmlDocPtr doc, bool test_only, + const char *include_path) + : m_factory(), + m_flexml(new RouterFleXML(doc, m_factory, test_only, include_path)) +{ +} + +mp::RouterXML::Rep::Rep(std::string xmlconf, bool test_only) + : m_factory(), + m_flexml(new RouterFleXML(xmlconf, m_factory, test_only)) +{ +} + +mp::RouterXML::Rep::~Rep() +{ +} + +mp::RouterXML::RouterXML(xmlDocPtr doc, + bool test_only, const char *file_include_path) + : m_p(new Rep(doc, test_only, file_include_path)) +{ +} + +mp::RouterXML::RouterXML(std::string xmlconf, bool test_only) + : m_p(new Rep(xmlconf, test_only)) +{ +} + +mp::RouterXML::~RouterXML() +{ +} + +mp::RoutePos *mp::RouterXML::createpos() const +{ + return m_p->m_flexml->createpos(); +} + +void mp::RouterXML::start() +{ + m_p->m_flexml->start(); +} + +void mp::RouterXML::stop() +{ + m_p->m_flexml->stop(); +} + +/* + * Local variables: + * c-basic-offset: 4 + * c-file-style: "Stroustrup" + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ + diff --git a/win/makefile b/win/makefile index 3f9575d..5f1a546 100644 --- a/win/makefile +++ b/win/makefile @@ -245,6 +245,7 @@ PROJECT_DLL_OBJS = \ $(OBJDIR)\plainfile.obj \ $(OBJDIR)\router_chain.obj \ $(OBJDIR)\router_flexml.obj \ + $(OBJDIR)\router_xml.obj \ $(OBJDIR)\session.obj \ $(OBJDIR)\sru_util.obj \ $(OBJDIR)\thread_pool_observer.obj \