X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Ffilter_cql_to_rpn.cpp;h=322eb4628b43a36e865cd9170b66697f36108e80;hb=9181e947fbaaaaed1cbf53f38f13b56bc762366c;hp=10894030aa9f9f6a2b7de448355c5d5df3ed4173;hpb=a998c1e468af7f5f14e3db68d258780fe7e1a0bd;p=metaproxy-moved-to-github.git diff --git a/src/filter_cql_to_rpn.cpp b/src/filter_cql_to_rpn.cpp index 1089403..322eb46 100644 --- a/src/filter_cql_to_rpn.cpp +++ b/src/filter_cql_to_rpn.cpp @@ -1,35 +1,36 @@ -/* $Id: filter_cql_to_rpn.cpp,v 1.3 2007-01-15 15:07:59 marc Exp $ - Copyright (c) 2005-2006, Index Data. +/* This file is part of Metaproxy. + Copyright (C) 2005-2013 Index Data - See the LICENSE file for details - */ +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. -#include "config.hpp" +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 "filter.hpp" -#include "package.hpp" +#include "config.hpp" +#include -#include -#include -#include -#include -#include -#include +#include +#include -#include "util.hpp" #include "filter_cql_to_rpn.hpp" -#include +#include #include +#include #include -#include #include #include -#include -#include -#include -#include -#include +#include namespace mp = metaproxy_1; namespace yf = metaproxy_1::filter; @@ -37,12 +38,11 @@ namespace yf = metaproxy_1::filter; namespace metaproxy_1 { namespace filter { class CQLtoRPN::Impl { - //friend class CQLtoRPN; public: Impl(); ~Impl(); void process(metaproxy_1::Package & package); - void configure(const xmlNode * ptr); + void configure(const xmlNode *ptr, const char *path); private: yazpp_1::Yaz_cql2rpn m_cql2rpn; }; @@ -51,7 +51,7 @@ namespace metaproxy_1 { // define Pimpl wrapper forwarding to Impl - + yf::CQLtoRPN::CQLtoRPN() : m_p(new Impl) { } @@ -60,9 +60,10 @@ yf::CQLtoRPN::~CQLtoRPN() { // must have a destructor because of boost::scoped_ptr } -void yf::CQLtoRPN::configure(const xmlNode *xmlnode) +void yf::CQLtoRPN::configure(const xmlNode *xmlnode, bool test_only, + const char *path) { - m_p->configure(xmlnode); + m_p->configure(xmlnode, path); } void yf::CQLtoRPN::process(mp::Package &package) const @@ -78,10 +79,10 @@ yf::CQLtoRPN::Impl::Impl() } yf::CQLtoRPN::Impl::~Impl() -{ +{ } -void yf::CQLtoRPN::Impl::configure(const xmlNode *xmlnode) +void yf::CQLtoRPN::Impl::configure(const xmlNode *xmlnode, const char *path) { /* @@ -89,7 +90,7 @@ void yf::CQLtoRPN::Impl::configure(const xmlNode *xmlnode) */ - + std::string fname; for (xmlnode = xmlnode->children; xmlnode; xmlnode = xmlnode->next) { @@ -110,21 +111,28 @@ void yf::CQLtoRPN::Impl::configure(const xmlNode *xmlnode) } else { - throw mp::filter::FilterException("Bad element " + throw mp::filter::FilterException("Bad element " + std::string((const char *) xmlnode->name)); } } if (fname.length() == 0) { - throw mp::filter::FilterException("Missing conversion spec for " - "filter cql_rpn"); + 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(fname.c_str(), &error)) + if (!m_cql2rpn.parse_spec_file(fullpath, &error)) { - throw mp::filter::FilterException("Bad or missing CQL to RPN spec " + throw mp::filter::FilterException("Bad or missing " + "CQL to RPN configuration " + fname); } } @@ -144,18 +152,17 @@ void yf::CQLtoRPN::Impl::process(mp::Package &package) 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) { - yaz_log(YLOG_LOG, "No CQL to RPN table"); - Z_APDU *f_apdu = + Z_APDU *f_apdu = odr.create_searchResponse( - apdu_req, - YAZ_BIB1_TEMPORARY_SYSTEM_ERROR, - "Missing CQL to RPN spec"); + apdu_req, + YAZ_BIB1_PERMANENT_SYSTEM_ERROR, + "cql_rpn: missing CQL to RPN configuration"); package.response() = f_apdu; return; } @@ -163,15 +170,14 @@ void yf::CQLtoRPN::Impl::process(mp::Package &package) { int error_code = yaz_diag_srw_to_bib1(r); - yaz_log(YLOG_LOG, "CQL Conversion error %d", r); - Z_APDU *f_apdu = + 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; @@ -182,130 +188,13 @@ void yf::CQLtoRPN::Impl::process(mp::Package &package) } -// yf::CQLtoRPN::Rep::Rep() -// { - -// } - -// yf::CQLtoRPN::CQLtoRPN() : m_p(new CQLtoRPN::Rep) -// { -// } - -// yf::CQLtoRPN::~CQLtoRPN() -// { - -// } - -// void yf::CQLtoRPN::process(mp::Package &package) const -// { -// 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_p->cql2rpn.query_transform(sr->query->u.type_104->u.cql, -// &rpnquery, odr, -// &addinfo); -// if (r == -3) -// { -// yaz_log(YLOG_LOG, "No CQL to RPN table"); -// Z_APDU *f_apdu = -// odr.create_searchResponse( -// apdu_req, -// YAZ_BIB1_TEMPORARY_SYSTEM_ERROR, -// "Missing CQL to RPN spec"); -// package.response() = f_apdu; -// return; -// } -// else if (r) -// { -// int error_code = yaz_diag_srw_to_bib1(r); - -// yaz_log(YLOG_LOG, "CQL Conversion error %d", 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(); -// } - -// void yf::CQLtoRPN::configure(const xmlNode *ptr) -// { - -// /* -// -// -// -// */ - -// std::string fname; -// for (ptr = ptr->children; ptr; ptr = ptr->next) -// { -// if (ptr->type != XML_ELEMENT_NODE) -// continue; -// if (!strcmp((const char *) ptr->name, "conversion")) -// { -// const struct _xmlAttr *attr; -// for (attr = ptr->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 *) -// ptr->name)); -// } -// } -// if (fname.length() == 0) -// { -// throw mp::filter::FilterException("Missing conversion spec for " -// "filter cql_rpn"); -// } - -// int error = 0; -// if (!m_p->cql2rpn.parse_spec_file(fname.c_str(), &error)) -// { -// throw mp::filter::FilterException("Bad or missing CQL to RPN spec " -// + fname); -// } -// } - - - - static mp::filter::Base* filter_creator() { return new mp::filter::CQLtoRPN; } extern "C" { - struct metaproxy_1_filter_struct metaproxy_1_filter_cql_to_rpn = { + struct metaproxy_1_filter_struct metaproxy_1_filter_cql_rpn = { 0, "cql_rpn", filter_creator @@ -315,8 +204,9 @@ extern "C" { /* * Local variables: * c-basic-offset: 4 + * c-file-style: "Stroustrup" * indent-tabs-mode: nil - * c-file-style: "stroustrup" * End: * vim: shiftwidth=4 tabstop=8 expandtab */ +