1 /* $Id: filter_cql_to_rpn.cpp,v 1.7 2007-05-09 21:23:09 adam Exp $
2 Copyright (c) 2005-2007, Index Data.
4 This file is part of Metaproxy.
6 Metaproxy is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2, or (at your option) any later
11 Metaproxy is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with Metaproxy; see the file LICENSE. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
21 /* $Id: filter_cql_to_rpn.cpp,v 1.7 2007-05-09 21:23:09 adam Exp $
22 Copyright (c) 2005-2007, Index Data.
24 See the LICENSE file for details
31 #include "package.hpp"
33 #include "filter_cql_to_rpn.hpp"
35 #include <yazpp/z-query.h>
37 #include <yazpp/cql2rpn.h>
39 #include <yaz/diagbib1.h>
43 namespace mp = metaproxy_1;
44 namespace yf = metaproxy_1::filter;
46 namespace metaproxy_1 {
48 class CQLtoRPN::Impl {
52 void process(metaproxy_1::Package & package);
53 void configure(const xmlNode * ptr);
55 yazpp_1::Yaz_cql2rpn m_cql2rpn;
61 // define Pimpl wrapper forwarding to Impl
63 yf::CQLtoRPN::CQLtoRPN() : m_p(new Impl)
67 yf::CQLtoRPN::~CQLtoRPN()
68 { // must have a destructor because of boost::scoped_ptr
71 void yf::CQLtoRPN::configure(const xmlNode *xmlnode)
73 m_p->configure(xmlnode);
76 void yf::CQLtoRPN::process(mp::Package &package) const
78 m_p->process(package);
82 // define Implementation stuff
84 yf::CQLtoRPN::Impl::Impl()
88 yf::CQLtoRPN::Impl::~Impl()
92 void yf::CQLtoRPN::Impl::configure(const xmlNode *xmlnode)
96 <filter type="cql_rpn">
97 <conversion file="pqf.properties"/>
102 for (xmlnode = xmlnode->children; xmlnode; xmlnode = xmlnode->next)
104 if (xmlnode->type != XML_ELEMENT_NODE)
106 if (!strcmp((const char *) xmlnode->name, "conversion"))
108 const struct _xmlAttr *attr;
109 for (attr = xmlnode->properties; attr; attr = attr->next)
111 if (!strcmp((const char *) attr->name, "file"))
112 fname = mp::xml::get_text(attr);
114 throw mp::filter::FilterException(
115 "Bad attribute " + std::string((const char *)
121 throw mp::filter::FilterException("Bad element "
122 + std::string((const char *)
126 if (fname.length() == 0)
128 throw mp::filter::FilterException("Missing conversion configuration "
129 "for filter cql_rpn");
133 if (!m_cql2rpn.parse_spec_file(fname.c_str(), &error))
135 throw mp::filter::FilterException("Bad or missing "
136 "CQL to RPN configuration "
141 void yf::CQLtoRPN::Impl::process(mp::Package &package)
143 Z_GDU *gdu = package.request().get();
145 if (gdu && gdu->which == Z_GDU_Z3950 && gdu->u.z3950->which ==
146 Z_APDU_searchRequest)
148 Z_APDU *apdu_req = gdu->u.z3950;
149 Z_SearchRequest *sr = gdu->u.z3950->u.searchRequest;
150 if (sr->query && sr->query->which == Z_Query_type_104 &&
151 sr->query->u.type_104->which == Z_External_CQL)
154 Z_RPNQuery *rpnquery = 0;
157 int r = m_cql2rpn.query_transform(sr->query->u.type_104->u.cql,
163 odr.create_searchResponse(
165 YAZ_BIB1_TEMPORARY_SYSTEM_ERROR,
166 "Missing CQL to RPN configuration");
167 package.response() = f_apdu;
172 int error_code = yaz_diag_srw_to_bib1(r);
175 odr.create_searchResponse(apdu_req, error_code, addinfo);
176 package.response() = f_apdu;
182 sr->query->which = Z_Query_type_1;
183 sr->query->u.type_1 = rpnquery;
184 package.request() = gdu;
192 static mp::filter::Base* filter_creator()
194 return new mp::filter::CQLtoRPN;
198 struct metaproxy_1_filter_struct metaproxy_1_filter_cql_to_rpn = {
208 * indent-tabs-mode: nil
209 * c-file-style: "stroustrup"
211 * vim: shiftwidth=4 tabstop=8 expandtab