From 964ec58fa0d8664752262cef2f2707f10b16ba9c Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Fri, 15 Nov 2013 11:20:25 +0100 Subject: [PATCH] Rename cql_rpn source --- src/Makefile.am | 2 +- src/factory_static.cpp | 2 +- src/filter_cql_rpn.cpp | 212 +++++++++++++++++++++++++++++++++++++++++++++ src/filter_cql_rpn.hpp | 56 ++++++++++++ src/filter_cql_to_rpn.cpp | 212 --------------------------------------------- src/filter_cql_to_rpn.hpp | 56 ------------ win/makefile | 2 +- 7 files changed, 271 insertions(+), 271 deletions(-) create mode 100644 src/filter_cql_rpn.cpp create mode 100644 src/filter_cql_rpn.hpp delete mode 100644 src/filter_cql_to_rpn.cpp delete mode 100644 src/filter_cql_to_rpn.hpp diff --git a/src/Makefile.am b/src/Makefile.am index f4edb3c..6e314c0 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -16,7 +16,7 @@ filter_src = \ filter_backend_test.cpp filter_backend_test.hpp \ filter_bounce.cpp filter_bounce.hpp \ filter_cgi.cpp filter_cgi.hpp \ - filter_cql_to_rpn.cpp filter_cql_to_rpn.hpp \ + filter_cql_rpn.cpp filter_cql_rpn.hpp \ filter_frontend_net.cpp filter_frontend_net.hpp \ filter_http_client.cpp filter_http_client.hpp \ filter_http_file.cpp filter_http_file.hpp \ diff --git a/src/factory_static.cpp b/src/factory_static.cpp index 9f3bbcf..867aeb2 100644 --- a/src/factory_static.cpp +++ b/src/factory_static.cpp @@ -33,7 +33,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #ifndef WIN32 #include "filter_cgi.hpp" #endif -#include "filter_cql_to_rpn.hpp" +#include "filter_cql_rpn.hpp" #include "filter_frontend_net.hpp" #include "filter_http_client.hpp" #include "filter_http_file.hpp" diff --git a/src/filter_cql_rpn.cpp b/src/filter_cql_rpn.cpp new file mode 100644 index 0000000..af093ae --- /dev/null +++ b/src/filter_cql_rpn.cpp @@ -0,0 +1,212 @@ +/* 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 +#include + +#include "filter_cql_rpn.hpp" + +#include +#include +#include +#include +#include +#include +#include + +namespace mp = metaproxy_1; +namespace yf = metaproxy_1::filter; + +namespace metaproxy_1 { + namespace filter { + class CQLtoRPN::Impl { + public: + Impl(); + ~Impl(); + void process(metaproxy_1::Package & package); + void configure(const xmlNode *ptr, const char *path); + private: + yazpp_1::Yaz_cql2rpn m_cql2rpn; + }; + } +} + + +// define Pimpl wrapper forwarding to Impl + +yf::CQLtoRPN::CQLtoRPN() : m_p(new Impl) +{ +} + +yf::CQLtoRPN::~CQLtoRPN() +{ // must have a destructor because of boost::scoped_ptr +} + +void yf::CQLtoRPN::configure(const xmlNode *xmlnode, bool test_only, + const char *path) +{ + m_p->configure(xmlnode, path); +} + +void yf::CQLtoRPN::process(mp::Package &package) const +{ + m_p->process(package); +} + + +// define Implementation stuff + +yf::CQLtoRPN::Impl::Impl() +{ +} + +yf::CQLtoRPN::Impl::~Impl() +{ +} + +void yf::CQLtoRPN::Impl::configure(const xmlNode *xmlnode, const char *path) +{ + + /* + + + + */ + + std::string fname; + for (xmlnode = xmlnode->children; xmlnode; xmlnode = xmlnode->next) + { + if (xmlnode->type != XML_ELEMENT_NODE) + continue; + if (!strcmp((const char *) xmlnode->name, "conversion")) + { + const struct _xmlAttr *attr; + for (attr = xmlnode->properties; attr; attr = attr->next) + { + if (!strcmp((const char *) attr->name, "file")) + fname = mp::xml::get_text(attr); + else + throw mp::filter::FilterException( + "Bad attribute " + std::string((const char *) + attr->name)); + } + } + else + { + throw mp::filter::FilterException("Bad element " + + std::string((const char *) + xmlnode->name)); + } + } + if (fname.length() == 0) + { + throw mp::filter::FilterException("Missing conversion configuration " + "for filter cql_rpn"); + } + + + char fullpath[1024]; + if (!yaz_filepath_resolve(fname.c_str(), path, 0, fullpath)) + { + throw mp::filter::FilterException("Could not open " + fname); + } + int error = 0; + if (!m_cql2rpn.parse_spec_file(fullpath, &error)) + { + throw mp::filter::FilterException("Bad or missing " + "CQL to RPN configuration " + + fname); + } +} + +void yf::CQLtoRPN::Impl::process(mp::Package &package) +{ + Z_GDU *gdu = package.request().get(); + + if (gdu && gdu->which == Z_GDU_Z3950 && gdu->u.z3950->which == + Z_APDU_searchRequest) + { + Z_APDU *apdu_req = gdu->u.z3950; + Z_SearchRequest *sr = gdu->u.z3950->u.searchRequest; + if (sr->query && sr->query->which == Z_Query_type_104 && + sr->query->u.type_104->which == Z_External_CQL) + { + char *addinfo = 0; + Z_RPNQuery *rpnquery = 0; + mp::odr odr; + + int r = m_cql2rpn.query_transform(sr->query->u.type_104->u.cql, + &rpnquery, odr, + &addinfo); + if (r == -3) + { + Z_APDU *f_apdu = + odr.create_searchResponse( + apdu_req, + YAZ_BIB1_PERMANENT_SYSTEM_ERROR, + "cql_rpn: missing CQL to RPN configuration"); + package.response() = f_apdu; + return; + } + else if (r) + { + int error_code = yaz_diag_srw_to_bib1(r); + + Z_APDU *f_apdu = + odr.create_searchResponse(apdu_req, error_code, addinfo); + package.response() = f_apdu; + return; + } + else + { // conversion OK + + sr->query->which = Z_Query_type_1; + sr->query->u.type_1 = rpnquery; + package.request() = gdu; + } + } + } + package.move(); +} + + +static mp::filter::Base* filter_creator() +{ + return new mp::filter::CQLtoRPN; +} + +extern "C" { + struct metaproxy_1_filter_struct metaproxy_1_filter_cql_rpn = { + 0, + "cql_rpn", + filter_creator + }; +} + +/* + * Local variables: + * c-basic-offset: 4 + * c-file-style: "Stroustrup" + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ + diff --git a/src/filter_cql_rpn.hpp b/src/filter_cql_rpn.hpp new file mode 100644 index 0000000..a4f369a --- /dev/null +++ b/src/filter_cql_rpn.hpp @@ -0,0 +1,56 @@ +/* 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 FILTER_CQL_RPN_HPP +#define FILTER_CQL_RPN_HPP + +#include +#include + +#include + +namespace metaproxy_1 { + namespace filter { + class CQLtoRPN : public Base { + class Impl; + boost::scoped_ptr m_p; + public: + CQLtoRPN(); + ~CQLtoRPN(); + void process(metaproxy_1::Package & package) const; + void configure(const xmlNode * ptr, bool test_only, + const char *path); + private: + }; + } +} + +extern "C" { + extern struct metaproxy_1_filter_struct metaproxy_1_filter_cql_rpn; +} + +#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/src/filter_cql_to_rpn.cpp b/src/filter_cql_to_rpn.cpp deleted file mode 100644 index 322eb46..0000000 --- a/src/filter_cql_to_rpn.cpp +++ /dev/null @@ -1,212 +0,0 @@ -/* 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 -#include - -#include "filter_cql_to_rpn.hpp" - -#include -#include -#include -#include -#include -#include -#include - -namespace mp = metaproxy_1; -namespace yf = metaproxy_1::filter; - -namespace metaproxy_1 { - namespace filter { - class CQLtoRPN::Impl { - public: - Impl(); - ~Impl(); - void process(metaproxy_1::Package & package); - void configure(const xmlNode *ptr, const char *path); - private: - yazpp_1::Yaz_cql2rpn m_cql2rpn; - }; - } -} - - -// define Pimpl wrapper forwarding to Impl - -yf::CQLtoRPN::CQLtoRPN() : m_p(new Impl) -{ -} - -yf::CQLtoRPN::~CQLtoRPN() -{ // must have a destructor because of boost::scoped_ptr -} - -void yf::CQLtoRPN::configure(const xmlNode *xmlnode, bool test_only, - const char *path) -{ - m_p->configure(xmlnode, path); -} - -void yf::CQLtoRPN::process(mp::Package &package) const -{ - m_p->process(package); -} - - -// define Implementation stuff - -yf::CQLtoRPN::Impl::Impl() -{ -} - -yf::CQLtoRPN::Impl::~Impl() -{ -} - -void yf::CQLtoRPN::Impl::configure(const xmlNode *xmlnode, const char *path) -{ - - /* - - - - */ - - std::string fname; - for (xmlnode = xmlnode->children; xmlnode; xmlnode = xmlnode->next) - { - if (xmlnode->type != XML_ELEMENT_NODE) - continue; - if (!strcmp((const char *) xmlnode->name, "conversion")) - { - const struct _xmlAttr *attr; - for (attr = xmlnode->properties; attr; attr = attr->next) - { - if (!strcmp((const char *) attr->name, "file")) - fname = mp::xml::get_text(attr); - else - throw mp::filter::FilterException( - "Bad attribute " + std::string((const char *) - attr->name)); - } - } - else - { - throw mp::filter::FilterException("Bad element " - + std::string((const char *) - xmlnode->name)); - } - } - if (fname.length() == 0) - { - throw mp::filter::FilterException("Missing conversion configuration " - "for filter cql_rpn"); - } - - - char fullpath[1024]; - if (!yaz_filepath_resolve(fname.c_str(), path, 0, fullpath)) - { - throw mp::filter::FilterException("Could not open " + fname); - } - int error = 0; - if (!m_cql2rpn.parse_spec_file(fullpath, &error)) - { - throw mp::filter::FilterException("Bad or missing " - "CQL to RPN configuration " - + fname); - } -} - -void yf::CQLtoRPN::Impl::process(mp::Package &package) -{ - Z_GDU *gdu = package.request().get(); - - if (gdu && gdu->which == Z_GDU_Z3950 && gdu->u.z3950->which == - Z_APDU_searchRequest) - { - Z_APDU *apdu_req = gdu->u.z3950; - Z_SearchRequest *sr = gdu->u.z3950->u.searchRequest; - if (sr->query && sr->query->which == Z_Query_type_104 && - sr->query->u.type_104->which == Z_External_CQL) - { - char *addinfo = 0; - Z_RPNQuery *rpnquery = 0; - mp::odr odr; - - int r = m_cql2rpn.query_transform(sr->query->u.type_104->u.cql, - &rpnquery, odr, - &addinfo); - if (r == -3) - { - Z_APDU *f_apdu = - odr.create_searchResponse( - apdu_req, - YAZ_BIB1_PERMANENT_SYSTEM_ERROR, - "cql_rpn: missing CQL to RPN configuration"); - package.response() = f_apdu; - return; - } - else if (r) - { - int error_code = yaz_diag_srw_to_bib1(r); - - Z_APDU *f_apdu = - odr.create_searchResponse(apdu_req, error_code, addinfo); - package.response() = f_apdu; - return; - } - else - { // conversion OK - - sr->query->which = Z_Query_type_1; - sr->query->u.type_1 = rpnquery; - package.request() = gdu; - } - } - } - package.move(); -} - - -static mp::filter::Base* filter_creator() -{ - return new mp::filter::CQLtoRPN; -} - -extern "C" { - struct metaproxy_1_filter_struct metaproxy_1_filter_cql_rpn = { - 0, - "cql_rpn", - filter_creator - }; -} - -/* - * Local variables: - * c-basic-offset: 4 - * c-file-style: "Stroustrup" - * indent-tabs-mode: nil - * End: - * vim: shiftwidth=4 tabstop=8 expandtab - */ - diff --git a/src/filter_cql_to_rpn.hpp b/src/filter_cql_to_rpn.hpp deleted file mode 100644 index a61724a..0000000 --- a/src/filter_cql_to_rpn.hpp +++ /dev/null @@ -1,56 +0,0 @@ -/* 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 FILTER_CQL_TO_RPN_HPP -#define FILTER_CQL_TO_RPN_HPP - -#include -#include - -#include - -namespace metaproxy_1 { - namespace filter { - class CQLtoRPN : public Base { - class Impl; - boost::scoped_ptr m_p; - public: - CQLtoRPN(); - ~CQLtoRPN(); - void process(metaproxy_1::Package & package) const; - void configure(const xmlNode * ptr, bool test_only, - const char *path); - private: - }; - } -} - -extern "C" { - extern struct metaproxy_1_filter_struct metaproxy_1_filter_cql_rpn; -} - -#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/win/makefile b/win/makefile index e78b8c7..18ce38b 100644 --- a/win/makefile +++ b/win/makefile @@ -217,7 +217,7 @@ PROJECT_DLL_OBJS = \ $(OBJDIR)\filter_auth_simple.obj \ $(OBJDIR)\filter_backend_test.obj \ $(OBJDIR)\filter_bounce.obj \ - $(OBJDIR)\filter_cql_to_rpn.obj \ + $(OBJDIR)\filter_cql_rpn.obj \ $(OBJDIR)\filter_frontend_net.obj \ $(OBJDIR)\filter_http_client.obj \ $(OBJDIR)\filter_http_file.obj \ -- 1.7.10.4