1 /* $Id: filter_cql_to_rpn.cpp,v 1.5 2007-01-16 09:04:54 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"
15 #include <yazpp/z-query.h>
17 #include <yazpp/cql2rpn.h>
19 #include <yaz/diagbib1.h>
23 namespace mp = metaproxy_1;
24 namespace yf = metaproxy_1::filter;
26 namespace metaproxy_1 {
28 class CQLtoRPN::Impl {
32 void process(metaproxy_1::Package & package);
33 void configure(const xmlNode * ptr);
35 yazpp_1::Yaz_cql2rpn m_cql2rpn;
41 // define Pimpl wrapper forwarding to Impl
43 yf::CQLtoRPN::CQLtoRPN() : m_p(new Impl)
47 yf::CQLtoRPN::~CQLtoRPN()
48 { // must have a destructor because of boost::scoped_ptr
51 void yf::CQLtoRPN::configure(const xmlNode *xmlnode)
53 m_p->configure(xmlnode);
56 void yf::CQLtoRPN::process(mp::Package &package) const
58 m_p->process(package);
62 // define Implementation stuff
64 yf::CQLtoRPN::Impl::Impl()
68 yf::CQLtoRPN::Impl::~Impl()
72 void yf::CQLtoRPN::Impl::configure(const xmlNode *xmlnode)
76 <filter type="cql_rpn">
77 <conversion file="pqf.properties"/>
82 for (xmlnode = xmlnode->children; xmlnode; xmlnode = xmlnode->next)
84 if (xmlnode->type != XML_ELEMENT_NODE)
86 if (!strcmp((const char *) xmlnode->name, "conversion"))
88 const struct _xmlAttr *attr;
89 for (attr = xmlnode->properties; attr; attr = attr->next)
91 if (!strcmp((const char *) attr->name, "file"))
92 fname = mp::xml::get_text(attr);
94 throw mp::filter::FilterException(
95 "Bad attribute " + std::string((const char *)
101 throw mp::filter::FilterException("Bad element "
102 + std::string((const char *)
106 if (fname.length() == 0)
108 throw mp::filter::FilterException("Missing conversion configuration "
109 "for filter cql_rpn");
113 if (!m_cql2rpn.parse_spec_file(fname.c_str(), &error))
115 throw mp::filter::FilterException("Bad or missing "
116 "CQL to RPN configuration "
121 void yf::CQLtoRPN::Impl::process(mp::Package &package)
123 Z_GDU *gdu = package.request().get();
125 if (gdu && gdu->which == Z_GDU_Z3950 && gdu->u.z3950->which ==
126 Z_APDU_searchRequest)
128 Z_APDU *apdu_req = gdu->u.z3950;
129 Z_SearchRequest *sr = gdu->u.z3950->u.searchRequest;
130 if (sr->query && sr->query->which == Z_Query_type_104 &&
131 sr->query->u.type_104->which == Z_External_CQL)
134 Z_RPNQuery *rpnquery = 0;
137 int r = m_cql2rpn.query_transform(sr->query->u.type_104->u.cql,
143 odr.create_searchResponse(
145 YAZ_BIB1_TEMPORARY_SYSTEM_ERROR,
146 "Missing CQL to RPN configuration");
147 package.response() = f_apdu;
152 int error_code = yaz_diag_srw_to_bib1(r);
155 odr.create_searchResponse(apdu_req, error_code, addinfo);
156 package.response() = f_apdu;
162 sr->query->which = Z_Query_type_1;
163 sr->query->u.type_1 = rpnquery;
164 package.request() = gdu;
172 static mp::filter::Base* filter_creator()
174 return new mp::filter::CQLtoRPN;
178 struct metaproxy_1_filter_struct metaproxy_1_filter_cql_to_rpn = {
188 * indent-tabs-mode: nil
189 * c-file-style: "stroustrup"
191 * vim: shiftwidth=4 tabstop=8 expandtab