1 /* $Id: filter_cql_to_rpn.cpp,v 1.4 2007-01-16 08:49:05 marc Exp $
2 Copyright (c) 2005-2006, Index Data.
4 See the LICENSE file for details
11 #include "package.hpp"
13 #include "filter_cql_to_rpn.hpp"
19 #include <yaz/otherinfo.h>
20 #include <yaz/diagbib1.h>
22 #include <yazpp/z-query.h>
23 #include <yazpp/cql2rpn.h>
26 namespace mp = metaproxy_1;
27 namespace yf = metaproxy_1::filter;
29 namespace metaproxy_1 {
31 class CQLtoRPN::Impl {
35 void process(metaproxy_1::Package & package);
36 void configure(const xmlNode * ptr);
38 yazpp_1::Yaz_cql2rpn m_cql2rpn;
44 // define Pimpl wrapper forwarding to Impl
46 yf::CQLtoRPN::CQLtoRPN() : m_p(new Impl)
50 yf::CQLtoRPN::~CQLtoRPN()
51 { // must have a destructor because of boost::scoped_ptr
54 void yf::CQLtoRPN::configure(const xmlNode *xmlnode)
56 m_p->configure(xmlnode);
59 void yf::CQLtoRPN::process(mp::Package &package) const
61 m_p->process(package);
65 // define Implementation stuff
67 yf::CQLtoRPN::Impl::Impl()
71 yf::CQLtoRPN::Impl::~Impl()
75 void yf::CQLtoRPN::Impl::configure(const xmlNode *xmlnode)
79 <filter type="cql_rpn">
80 <conversion file="pqf.properties"/>
85 for (xmlnode = xmlnode->children; xmlnode; xmlnode = xmlnode->next)
87 if (xmlnode->type != XML_ELEMENT_NODE)
89 if (!strcmp((const char *) xmlnode->name, "conversion"))
91 const struct _xmlAttr *attr;
92 for (attr = xmlnode->properties; attr; attr = attr->next)
94 if (!strcmp((const char *) attr->name, "file"))
95 fname = mp::xml::get_text(attr);
97 throw mp::filter::FilterException(
98 "Bad attribute " + std::string((const char *)
104 throw mp::filter::FilterException("Bad element "
105 + std::string((const char *)
109 if (fname.length() == 0)
111 throw mp::filter::FilterException("Missing conversion spec for "
116 if (!m_cql2rpn.parse_spec_file(fname.c_str(), &error))
118 throw mp::filter::FilterException("Bad or missing CQL to RPN spec "
123 void yf::CQLtoRPN::Impl::process(mp::Package &package)
125 Z_GDU *gdu = package.request().get();
127 if (gdu && gdu->which == Z_GDU_Z3950 && gdu->u.z3950->which ==
128 Z_APDU_searchRequest)
130 Z_APDU *apdu_req = gdu->u.z3950;
131 Z_SearchRequest *sr = gdu->u.z3950->u.searchRequest;
132 if (sr->query && sr->query->which == Z_Query_type_104 &&
133 sr->query->u.type_104->which == Z_External_CQL)
136 Z_RPNQuery *rpnquery = 0;
139 int r = m_cql2rpn.query_transform(sr->query->u.type_104->u.cql,
144 yaz_log(YLOG_LOG, "No CQL to RPN table");
146 odr.create_searchResponse(
148 YAZ_BIB1_TEMPORARY_SYSTEM_ERROR,
149 "Missing CQL to RPN spec");
150 package.response() = f_apdu;
155 int error_code = yaz_diag_srw_to_bib1(r);
157 yaz_log(YLOG_LOG, "CQL Conversion error %d", r);
159 odr.create_searchResponse(apdu_req, error_code, addinfo);
160 package.response() = f_apdu;
166 sr->query->which = Z_Query_type_1;
167 sr->query->u.type_1 = rpnquery;
168 package.request() = gdu;
176 static mp::filter::Base* filter_creator()
178 return new mp::filter::CQLtoRPN;
182 struct metaproxy_1_filter_struct metaproxy_1_filter_cql_to_rpn = {
192 * indent-tabs-mode: nil
193 * c-file-style: "stroustrup"
195 * vim: shiftwidth=4 tabstop=8 expandtab