Year 2007.
[metaproxy-moved-to-github.git] / src / filter_cql_to_rpn.cpp
index fccf623..a0988f5 100644 (file)
-/* $Id: filter_cql_to_rpn.cpp,v 1.2 2007-01-12 10:17:23 adam Exp $
-   Copyright (c) 2005-2006, Index Data.
+/* $Id: filter_cql_to_rpn.cpp,v 1.6 2007-01-25 14:05:54 adam Exp $
+   Copyright (c) 2005-2007, Index Data.
 
    See the LICENSE file for details
  */
 
 #include "config.hpp"
+#include "util.hpp"
 
 #include "filter.hpp"
 #include "package.hpp"
 
-#include <boost/thread/mutex.hpp>
-#include <boost/thread/condition.hpp>
-#include <boost/thread/thread.hpp>
-#include <boost/thread/xtime.hpp>
-#include <boost/shared_ptr.hpp>
-#include <boost/format.hpp>
-
-#include "util.hpp"
 #include "filter_cql_to_rpn.hpp"
 
-#include <yaz/log.h>
+#include <yazpp/z-query.h>
 #include <yaz/cql.h>
+#include <yazpp/cql2rpn.h>
 #include <yaz/zgdu.h>
-#include <yaz/otherinfo.h>
 #include <yaz/diagbib1.h>
 #include <yaz/srw.h>
-#include <yazpp/z-query.h>
-#include <yazpp/cql2rpn.h>
-#include <map>
-#include <iostream>
-#include <time.h>
+
 
 namespace mp = metaproxy_1;
 namespace yf = metaproxy_1::filter;
 
 namespace metaproxy_1 {
     namespace filter {
-        class CQL_to_RPN::Rep {
-            friend class CQL_to_RPN;
-
-            Rep();
-
-            yazpp_1::Yaz_cql2rpn cql2rpn;
+        class CQLtoRPN::Impl {
+        public:
+            Impl();
+            ~Impl();
+            void process(metaproxy_1::Package & package);
+            void configure(const xmlNode * ptr);
+        private:
+            yazpp_1::Yaz_cql2rpn m_cql2rpn;
         };
     }
 }
 
-yf::CQL_to_RPN::Rep::Rep()
+
+// define Pimpl wrapper forwarding to Impl
+yf::CQLtoRPN::CQLtoRPN() : m_p(new Impl)
 {
+}
 
+yf::CQLtoRPN::~CQLtoRPN()
+{  // must have a destructor because of boost::scoped_ptr
 }
 
-yf::CQL_to_RPN::CQL_to_RPN() : m_p(new CQL_to_RPN::Rep)
+void yf::CQLtoRPN::configure(const xmlNode *xmlnode)
 {
+    m_p->configure(xmlnode);
 }
 
-yf::CQL_to_RPN::~CQL_to_RPN()
+void yf::CQLtoRPN::process(mp::Package &package) const
 {
+    m_p->process(package);
+}
+
+
+// define Implementation stuff
+
+yf::CQLtoRPN::Impl::Impl()
+{
+}
 
+yf::CQLtoRPN::Impl::~Impl()
+{ 
 }
 
-void yf::CQL_to_RPN::process(mp::Package &package) const
+void yf::CQLtoRPN::Impl::configure(const xmlNode *xmlnode)
+{
+
+    /*
+      <filter type="cql_rpn">
+      <conversion file="pqf.properties"/>
+      </filter>
+    */
+    
+    std::string fname;
+    for (xmlnode = xmlnode->children; xmlnode; xmlnode = xmlnode->next)
+    {
+        if (xmlnode->type != XML_ELEMENT_NODE)
+            continue;
+        if (!strcmp((const char *) xmlnode->name, "conversion"))
+        {
+            const struct _xmlAttr *attr;
+            for (attr = xmlnode->properties; attr; attr = attr->next)
+            {
+                if (!strcmp((const char *) attr->name, "file"))
+                    fname = mp::xml::get_text(attr);
+                else
+                    throw mp::filter::FilterException(
+                        "Bad attribute " + std::string((const char *)
+                                                       attr->name));
+            }
+        }
+        else
+        {
+            throw mp::filter::FilterException("Bad element " 
+                                               + std::string((const char *)
+                                                             xmlnode->name));
+        }
+    }
+    if (fname.length() == 0)
+    {
+        throw mp::filter::FilterException("Missing conversion configuration "
+                                          "for filter cql_rpn");
+    }
+
+    int error = 0;
+    if (!m_cql2rpn.parse_spec_file(fname.c_str(), &error))
+    {
+        throw mp::filter::FilterException("Bad or missing "
+                                          "CQL to RPN configuration "
+                                          + fname);
+    }
+}
+
+void yf::CQLtoRPN::Impl::process(mp::Package &package)
 {
     Z_GDU *gdu = package.request().get();
 
@@ -76,17 +134,16 @@ void yf::CQL_to_RPN::process(mp::Package &package) const
             Z_RPNQuery *rpnquery = 0;
             mp::odr odr;
             
-            int r = m_p->cql2rpn.query_transform(sr->query->u.type_104->u.cql,
+            int r = m_cql2rpn.query_transform(sr->query->u.type_104->u.cql,
                                                  &rpnquery, odr,
                                                  &addinfo);
             if (r == -3)
             {
-                yaz_log(YLOG_LOG, "No CQL to RPN table");
                 Z_APDU *f_apdu = 
                     odr.create_searchResponse(
                         apdu_req, 
                         YAZ_BIB1_TEMPORARY_SYSTEM_ERROR,
-                        "Missing CQL to RPN spec");
+                        "Missing CQL to RPN configuration");
                 package.response() = f_apdu;
                 return;
             }
@@ -94,7 +151,6 @@ void yf::CQL_to_RPN::process(mp::Package &package) const
             {
                 int error_code = yaz_diag_srw_to_bib1(r);
 
-                yaz_log(YLOG_LOG, "CQL Conversion error %d", r);
                 Z_APDU *f_apdu = 
                     odr.create_searchResponse(apdu_req, error_code, addinfo);
                 package.response() = f_apdu;
@@ -112,63 +168,16 @@ void yf::CQL_to_RPN::process(mp::Package &package) const
     package.move();
 }
 
-void yf::CQL_to_RPN::configure(const xmlNode *ptr)
-{
-
-    /*
-      <filter type="cql_to_rpn">
-      <conversion file="pqf.properties"/>
-      </filter>
-    */
-    
-    std::string fname;
-    for (ptr = ptr->children; ptr; ptr = ptr->next)
-    {
-        if (ptr->type != XML_ELEMENT_NODE)
-            continue;
-        if (!strcmp((const char *) ptr->name, "conversion"))
-        {
-            const struct _xmlAttr *attr;
-            for (attr = ptr->properties; attr; attr = attr->next)
-            {
-                if (!strcmp((const char *) attr->name, "file"))
-                    fname = mp::xml::get_text(attr);
-                else
-                    throw mp::filter::FilterException(
-                        "Bad attribute " + std::string((const char *)
-                                                       attr->name));
-            }
-        }
-        else
-        {
-            throw mp::filter::FilterException("Bad element " 
-                                               + std::string((const char *)
-                                                             ptr->name));
-        }
-    }
-    if (fname.length() == 0)
-    {
-        throw mp::filter::FilterException("Missing conversion spec for "
-                                          "filter cql_to_rpn");
-    }
-
-    int error = 0;
-    if (!m_p->cql2rpn.parse_spec_file(fname.c_str(), &error))
-    {
-        throw mp::filter::FilterException("Bad or missing CQL to RPN spec "
-                                          + fname);
-    }
-}
 
 static mp::filter::Base* filter_creator()
 {
-    return new mp::filter::CQL_to_RPN;
+    return new mp::filter::CQLtoRPN;
 }
 
 extern "C" {
     struct metaproxy_1_filter_struct metaproxy_1_filter_cql_to_rpn = {
         0,
-        "cql_to_rpn",
+        "cql_rpn",
         filter_creator
     };
 }