metaproxy  1.21.0
Public Member Functions | Private Attributes | List of all members
metaproxy_1::filter::CQLtoRPN::Impl Class Reference
Collaboration diagram for metaproxy_1::filter::CQLtoRPN::Impl:
Collaboration graph

Public Member Functions

 Impl ()
 
 ~Impl ()
 
void process (metaproxy_1::Package &package)
 
void configure (const xmlNode *ptr, const char *path)
 

Private Attributes

yazpp_1::Yaz_cql2rpn m_cql2rpn
 
bool reverse
 

Detailed Description

Definition at line 41 of file filter_cql_rpn.cpp.

Constructor & Destructor Documentation

◆ Impl()

mp::filter::CQLtoRPN::Impl::Impl ( )

Definition at line 79 of file filter_cql_rpn.cpp.

79  : reverse(false)
80 {
81 }

◆ ~Impl()

mp::filter::CQLtoRPN::Impl::~Impl ( )

Definition at line 83 of file filter_cql_rpn.cpp.

84 {
85 }

Member Function Documentation

◆ configure()

void mp::filter::CQLtoRPN::Impl::configure ( const xmlNode *  ptr,
const char *  path 
)

Definition at line 87 of file filter_cql_rpn.cpp.

88 {
89 
90  /*
91  <filter type="cql_rpn">
92  <conversion file="pqf.properties"/>
93  </filter>
94  */
95 
96  std::string fname;
97  for (xmlnode = xmlnode->children; xmlnode; xmlnode = xmlnode->next)
98  {
99  if (xmlnode->type != XML_ELEMENT_NODE)
100  continue;
101  if (!strcmp((const char *) xmlnode->name, "conversion"))
102  {
103  const struct _xmlAttr *attr;
104  for (attr = xmlnode->properties; attr; attr = attr->next)
105  {
106  if (!strcmp((const char *) attr->name, "file"))
107  fname = mp::xml::get_text(attr);
108  else if (!strcmp((const char *) attr->name, "reverse"))
109  {
110  reverse = mp::xml::get_bool(attr->children, 0);
111  }
112  else
113  throw mp::filter::FilterException(
114  "Bad attribute " + std::string((const char *)
115  attr->name));
116  }
117  }
118  else
119  {
120  throw mp::filter::FilterException("Bad element "
121  + std::string((const char *)
122  xmlnode->name));
123  }
124  }
125  if (fname.length() == 0)
126  {
127  throw mp::filter::FilterException("Missing conversion configuration "
128  "for filter cql_rpn");
129  }
130 
131 
132  char fullpath[1024];
133  if (!yaz_filepath_resolve(fname.c_str(), path, 0, fullpath))
134  {
135  throw mp::filter::FilterException("Could not open " + fname);
136  }
137  int error = 0;
138  if (!m_cql2rpn.parse_spec_file(fullpath, &error))
139  {
140  throw mp::filter::FilterException("Bad or missing "
141  "CQL to RPN configuration "
142  + fname);
143  }
144 }

◆ process()

void mp::filter::CQLtoRPN::Impl::process ( metaproxy_1::Package &  package)

Definition at line 146 of file filter_cql_rpn.cpp.

147 {
148  Z_GDU *gdu = package.request().get();
149 
150  if (gdu && gdu->which == Z_GDU_Z3950 && gdu->u.z3950->which ==
151  Z_APDU_searchRequest)
152  {
153  Z_APDU *apdu_req = gdu->u.z3950;
154  Z_SearchRequest *sr = gdu->u.z3950->u.searchRequest;
155  if (reverse && sr->query && sr->query->which == Z_Query_type_1)
156  {
157  char *addinfo = 0;
158  mp::odr odr;
159  WRBUF cql = wrbuf_alloc();
160 
161  int r = m_cql2rpn.rpn2cql_transform(sr->query->u.type_1, cql,
162  odr, &addinfo);
163  if (r)
164  {
165  Z_APDU *f_apdu =
166  odr.create_searchResponse(apdu_req, r, addinfo);
167  package.response() = f_apdu;
168  return;
169  }
170  else
171  {
172  Z_External *ext = (Z_External *)
173  odr_malloc(odr, sizeof(*ext));
174  ext->direct_reference = odr_oiddup(odr,
175  yaz_oid_userinfo_cql);
176  ext->indirect_reference = 0;
177  ext->descriptor = 0;
178  ext->which = Z_External_CQL;
179  ext->u.cql = odr_strdup(odr, wrbuf_cstr(cql));
180 
181  sr->query->which = Z_Query_type_104;
182  sr->query->u.type_104 = ext;
183 
184  package.request() = gdu;
185  }
186  wrbuf_destroy(cql);
187  }
188  if (!reverse && sr->query && sr->query->which == Z_Query_type_104 &&
189  sr->query->u.type_104->which == Z_External_CQL)
190  {
191  char *addinfo = 0;
192  Z_RPNQuery *rpnquery = 0;
193  mp::odr odr;
194 
195  int r = m_cql2rpn.query_transform(sr->query->u.type_104->u.cql,
196  &rpnquery, odr,
197  &addinfo);
198  if (r == -3)
199  {
200  Z_APDU *f_apdu =
201  odr.create_searchResponse(
202  apdu_req,
203  YAZ_BIB1_PERMANENT_SYSTEM_ERROR,
204  "cql_rpn: missing CQL to RPN configuration");
205  package.response() = f_apdu;
206  return;
207  }
208  else if (r)
209  {
210  int error_code = yaz_diag_srw_to_bib1(r);
211 
212  Z_APDU *f_apdu =
213  odr.create_searchResponse(apdu_req, error_code, addinfo);
214  package.response() = f_apdu;
215  return;
216  }
217  else
218  { // conversion OK
219 
220  sr->query->which = Z_Query_type_1;
221  sr->query->u.type_1 = rpnquery;
222  package.request() = gdu;
223  }
224  }
225  }
226  package.move();
227 }

Member Data Documentation

◆ m_cql2rpn

yazpp_1::Yaz_cql2rpn metaproxy_1::filter::CQLtoRPN::Impl::m_cql2rpn
private

Definition at line 48 of file filter_cql_rpn.cpp.

◆ reverse

bool metaproxy_1::filter::CQLtoRPN::Impl::reverse
private

Definition at line 49 of file filter_cql_rpn.cpp.


The documentation for this class was generated from the following file: