1 /* $Id: filter_cql_to_rpn.cpp,v 1.2 2007-01-12 10:17:23 adam Exp $
2 Copyright (c) 2005-2006, Index Data.
4 See the LICENSE file for details
10 #include "package.hpp"
12 #include <boost/thread/mutex.hpp>
13 #include <boost/thread/condition.hpp>
14 #include <boost/thread/thread.hpp>
15 #include <boost/thread/xtime.hpp>
16 #include <boost/shared_ptr.hpp>
17 #include <boost/format.hpp>
20 #include "filter_cql_to_rpn.hpp"
25 #include <yaz/otherinfo.h>
26 #include <yaz/diagbib1.h>
28 #include <yazpp/z-query.h>
29 #include <yazpp/cql2rpn.h>
34 namespace mp = metaproxy_1;
35 namespace yf = metaproxy_1::filter;
37 namespace metaproxy_1 {
39 class CQL_to_RPN::Rep {
40 friend class CQL_to_RPN;
44 yazpp_1::Yaz_cql2rpn cql2rpn;
49 yf::CQL_to_RPN::Rep::Rep()
54 yf::CQL_to_RPN::CQL_to_RPN() : m_p(new CQL_to_RPN::Rep)
58 yf::CQL_to_RPN::~CQL_to_RPN()
63 void yf::CQL_to_RPN::process(mp::Package &package) const
65 Z_GDU *gdu = package.request().get();
67 if (gdu && gdu->which == Z_GDU_Z3950 && gdu->u.z3950->which ==
70 Z_APDU *apdu_req = gdu->u.z3950;
71 Z_SearchRequest *sr = gdu->u.z3950->u.searchRequest;
72 if (sr->query && sr->query->which == Z_Query_type_104 &&
73 sr->query->u.type_104->which == Z_External_CQL)
76 Z_RPNQuery *rpnquery = 0;
79 int r = m_p->cql2rpn.query_transform(sr->query->u.type_104->u.cql,
84 yaz_log(YLOG_LOG, "No CQL to RPN table");
86 odr.create_searchResponse(
88 YAZ_BIB1_TEMPORARY_SYSTEM_ERROR,
89 "Missing CQL to RPN spec");
90 package.response() = f_apdu;
95 int error_code = yaz_diag_srw_to_bib1(r);
97 yaz_log(YLOG_LOG, "CQL Conversion error %d", r);
99 odr.create_searchResponse(apdu_req, error_code, addinfo);
100 package.response() = f_apdu;
106 sr->query->which = Z_Query_type_1;
107 sr->query->u.type_1 = rpnquery;
108 package.request() = gdu;
115 void yf::CQL_to_RPN::configure(const xmlNode *ptr)
119 <filter type="cql_to_rpn">
120 <conversion file="pqf.properties"/>
125 for (ptr = ptr->children; ptr; ptr = ptr->next)
127 if (ptr->type != XML_ELEMENT_NODE)
129 if (!strcmp((const char *) ptr->name, "conversion"))
131 const struct _xmlAttr *attr;
132 for (attr = ptr->properties; attr; attr = attr->next)
134 if (!strcmp((const char *) attr->name, "file"))
135 fname = mp::xml::get_text(attr);
137 throw mp::filter::FilterException(
138 "Bad attribute " + std::string((const char *)
144 throw mp::filter::FilterException("Bad element "
145 + std::string((const char *)
149 if (fname.length() == 0)
151 throw mp::filter::FilterException("Missing conversion spec for "
152 "filter cql_to_rpn");
156 if (!m_p->cql2rpn.parse_spec_file(fname.c_str(), &error))
158 throw mp::filter::FilterException("Bad or missing CQL to RPN spec "
163 static mp::filter::Base* filter_creator()
165 return new mp::filter::CQL_to_RPN;
169 struct metaproxy_1_filter_struct metaproxy_1_filter_cql_to_rpn = {
179 * indent-tabs-mode: nil
180 * c-file-style: "stroustrup"
182 * vim: shiftwidth=4 tabstop=8 expandtab