1 /* This file is part of Metaproxy.
2 Copyright (C) 2005-2008 Index Data
4 Metaproxy is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
9 Metaproxy is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 /* $Id: filter_cql_to_rpn.cpp,v 1.8 2008-02-20 15:07:51 adam Exp $
19 Copyright (c) 2005-2007, Index Data.
21 See the LICENSE file for details
28 #include "package.hpp"
30 #include "filter_cql_to_rpn.hpp"
32 #include <yazpp/z-query.h>
34 #include <yazpp/cql2rpn.h>
36 #include <yaz/diagbib1.h>
40 namespace mp = metaproxy_1;
41 namespace yf = metaproxy_1::filter;
43 namespace metaproxy_1 {
45 class CQLtoRPN::Impl {
49 void process(metaproxy_1::Package & package);
50 void configure(const xmlNode * ptr);
52 yazpp_1::Yaz_cql2rpn m_cql2rpn;
58 // define Pimpl wrapper forwarding to Impl
60 yf::CQLtoRPN::CQLtoRPN() : m_p(new Impl)
64 yf::CQLtoRPN::~CQLtoRPN()
65 { // must have a destructor because of boost::scoped_ptr
68 void yf::CQLtoRPN::configure(const xmlNode *xmlnode, bool test_only)
70 m_p->configure(xmlnode);
73 void yf::CQLtoRPN::process(mp::Package &package) const
75 m_p->process(package);
79 // define Implementation stuff
81 yf::CQLtoRPN::Impl::Impl()
85 yf::CQLtoRPN::Impl::~Impl()
89 void yf::CQLtoRPN::Impl::configure(const xmlNode *xmlnode)
93 <filter type="cql_rpn">
94 <conversion file="pqf.properties"/>
99 for (xmlnode = xmlnode->children; xmlnode; xmlnode = xmlnode->next)
101 if (xmlnode->type != XML_ELEMENT_NODE)
103 if (!strcmp((const char *) xmlnode->name, "conversion"))
105 const struct _xmlAttr *attr;
106 for (attr = xmlnode->properties; attr; attr = attr->next)
108 if (!strcmp((const char *) attr->name, "file"))
109 fname = mp::xml::get_text(attr);
111 throw mp::filter::FilterException(
112 "Bad attribute " + std::string((const char *)
118 throw mp::filter::FilterException("Bad element "
119 + std::string((const char *)
123 if (fname.length() == 0)
125 throw mp::filter::FilterException("Missing conversion configuration "
126 "for filter cql_rpn");
130 if (!m_cql2rpn.parse_spec_file(fname.c_str(), &error))
132 throw mp::filter::FilterException("Bad or missing "
133 "CQL to RPN configuration "
138 void yf::CQLtoRPN::Impl::process(mp::Package &package)
140 Z_GDU *gdu = package.request().get();
142 if (gdu && gdu->which == Z_GDU_Z3950 && gdu->u.z3950->which ==
143 Z_APDU_searchRequest)
145 Z_APDU *apdu_req = gdu->u.z3950;
146 Z_SearchRequest *sr = gdu->u.z3950->u.searchRequest;
147 if (sr->query && sr->query->which == Z_Query_type_104 &&
148 sr->query->u.type_104->which == Z_External_CQL)
151 Z_RPNQuery *rpnquery = 0;
154 int r = m_cql2rpn.query_transform(sr->query->u.type_104->u.cql,
160 odr.create_searchResponse(
162 YAZ_BIB1_TEMPORARY_SYSTEM_ERROR,
163 "Missing CQL to RPN configuration");
164 package.response() = f_apdu;
169 int error_code = yaz_diag_srw_to_bib1(r);
172 odr.create_searchResponse(apdu_req, error_code, addinfo);
173 package.response() = f_apdu;
179 sr->query->which = Z_Query_type_1;
180 sr->query->u.type_1 = rpnquery;
181 package.request() = gdu;
189 static mp::filter::Base* filter_creator()
191 return new mp::filter::CQLtoRPN;
195 struct metaproxy_1_filter_struct metaproxy_1_filter_cql_to_rpn = {
205 * indent-tabs-mode: nil
206 * c-file-style: "stroustrup"
208 * vim: shiftwidth=4 tabstop=8 expandtab