New filter sd_remove
authorAdam Dickmeiss <adam@indexdata.dk>
Tue, 14 May 2013 13:21:39 +0000 (15:21 +0200)
committerAdam Dickmeiss <adam@indexdata.dk>
Tue, 14 May 2013 13:21:58 +0000 (15:21 +0200)
which removes surrogate diagnostics.

etc/config1.xml
src/Makefile.am
src/factory_static.cpp
src/filter_sd_remove.cpp [new file with mode: 0644]
src/filter_sd_remove.hpp [new file with mode: 0644]
xml/schema/Makefile.am
xml/schema/filter_sd_remove.rnc [new file with mode: 0644]
xml/schema/metaproxy.rnc

index dd91ae4..43b3e27 100644 (file)
@@ -22,6 +22,7 @@
       <filter type="log">
         <message>log</message>
       </filter>
+      <filter type="sd_remove"/>
       <filter refid="backend"/>
       <filter type="bounce"/>
     </route>
index e47daa8..53bc72a 100644 (file)
@@ -34,7 +34,8 @@ filter_src = \
        filter_z3950_client.cpp filter_z3950_client.hpp \
        filter_zeerex_explain.cpp  filter_zeerex_explain.hpp \
        filter_zoom.cpp filter_zoom.hpp \
-       filter_frontend_net.cpp filter_frontend_net.hpp
+       filter_frontend_net.cpp filter_frontend_net.hpp \
+       filter_sd_remove.cpp filter_sd_remove.hpp
 
 lib_LTLIBRARIES = libmetaproxy.la
 libmetaproxy_la_LDFLAGS = -version-info 4:0:0 -export-dynamic
index b3f6370..fcd039c 100644 (file)
@@ -44,6 +44,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 #include "filter_multi.hpp"
 #include "filter_query_rewrite.hpp"
 #include "filter_record_transform.hpp"
+#include "filter_sd_remove.hpp"
 #include "filter_session_shared.hpp"
 #include "filter_sort.hpp"
 #include "filter_sru_to_z3950.hpp"
@@ -57,7 +58,7 @@ namespace mp = metaproxy_1;
 
 mp::FactoryStatic::FactoryStatic()
 {
-#ifdef WIN32
+#ifdef HAVE_DLFCN_H
     struct metaproxy_1_filter_struct *buildins[] = {
         &metaproxy_1_filter_auth_simple,
         &metaproxy_1_filter_backend_test,
@@ -76,6 +77,7 @@ mp::FactoryStatic::FactoryStatic()
         &metaproxy_1_filter_multi,
         &metaproxy_1_filter_query_rewrite,
         &metaproxy_1_filter_record_transform,
+        &metaproxy_1_filter_sd_remove,
         &metaproxy_1_filter_session_shared,
         &metaproxy_1_filter_sort,
         &metaproxy_1_filter_sru_to_z3950,
diff --git a/src/filter_sd_remove.cpp b/src/filter_sd_remove.cpp
new file mode 100644 (file)
index 0000000..d7e75ea
--- /dev/null
@@ -0,0 +1,145 @@
+/* This file is part of Metaproxy.
+   Copyright (C) 2005-2013 Index Data
+
+Metaproxy is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 2, or (at your option) any later
+version.
+
+Metaproxy is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+*/
+
+#include "config.hpp"
+#include "filter_sd_remove.hpp"
+#include <metaproxy/package.hpp>
+#include <metaproxy/util.hpp>
+#include <yaz/zgdu.h>
+#include <metaproxy/filter.hpp>
+#include <yaz/querytowrbuf.h>
+
+namespace metaproxy_1 {
+    namespace filter {
+        class SD_Remove : public Base {
+        public:
+            SD_Remove();
+            ~SD_Remove();
+            void process(metaproxy_1::Package & package) const;
+            void configure(const xmlNode * ptr, bool test_only,
+                           const char *path);
+        };
+    }
+}
+
+namespace mp = metaproxy_1;
+namespace yf = mp::filter;
+
+yf::SD_Remove::SD_Remove()
+{
+}
+
+yf::SD_Remove::~SD_Remove()
+{
+}
+
+void yf::SD_Remove::configure(const xmlNode *xmlnode, bool test_only,
+                             const char *path)
+{
+    if (xmlnode)
+    {
+        xmlNode *ptr;
+        for (ptr = xmlnode->children; ptr; ptr = ptr->next)
+        {
+            if (ptr->type == XML_ELEMENT_NODE)
+                throw mp::filter::FilterException("Bad element "
+                                                  + std::string((const char *)
+                                                                ptr->name));
+        }
+    }
+}
+
+void yf::SD_Remove::process(mp::Package &package) const
+{
+    package.move();
+
+    Z_GDU *gdu_res = package.response().get();
+    if (gdu_res && gdu_res->which == Z_GDU_Z3950)
+    {
+        Z_NamePlusRecordList *records = 0;
+        Z_APDU *apdu = gdu_res->u.z3950;
+        if (apdu->which == Z_APDU_presentResponse)
+        {
+            Z_PresentResponse * pr_res = apdu->u.presentResponse;
+            if (pr_res->numberOfRecordsReturned
+                && *(pr_res->numberOfRecordsReturned) > 0
+                && pr_res->records
+                && pr_res->records->which == Z_Records_DBOSD)
+            {
+                records = pr_res->records->u.databaseOrSurDiagnostics;
+            }
+        }
+        if (apdu->which == Z_APDU_searchResponse)
+        {
+            Z_SearchResponse *sr_res = apdu->u.searchResponse;
+            if (
+                sr_res->numberOfRecordsReturned
+                && *(sr_res->numberOfRecordsReturned) > 0
+                && sr_res->records
+                && sr_res->records->which == Z_Records_DBOSD)
+            {
+                records = sr_res->records->u.databaseOrSurDiagnostics;
+            }
+        }
+        if (records)
+        {
+            mp::odr odr_en(ODR_ENCODE);
+            int i;
+            for (i = 0; i < records->num_records; i++)
+            {
+                Z_NamePlusRecord *npr = records->records[i];
+                if (npr->which == Z_NamePlusRecord_surrogateDiagnostic)
+                {
+                    WRBUF w = wrbuf_alloc();
+                    wrbuf_diags(w, 1, &npr->u.surrogateDiagnostic);
+                    npr->which = Z_NamePlusRecord_databaseRecord;
+                    npr->u.databaseRecord = z_ext_record_sutrs(odr_en,
+                                                               wrbuf_buf(w),
+                                                               wrbuf_len(w));
+                    wrbuf_destroy(w);
+                }
+            }
+            package.response() = gdu_res;
+        }
+    }
+}
+
+
+static mp::filter::Base* filter_creator()
+{
+    return new mp::filter::SD_Remove;
+}
+
+extern "C" {
+    struct metaproxy_1_filter_struct metaproxy_1_filter_sd_remove = {
+        0,
+        "sd_remove",
+        filter_creator
+    };
+}
+
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * c-file-style: "Stroustrup"
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
+
diff --git a/src/filter_sd_remove.hpp b/src/filter_sd_remove.hpp
new file mode 100644 (file)
index 0000000..21cd2b0
--- /dev/null
@@ -0,0 +1,35 @@
+/* This file is part of Metaproxy.
+   Copyright (C) 2005-2013 Index Data
+
+Metaproxy is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 2, or (at your option) any later
+version.
+
+Metaproxy is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+*/
+
+#ifndef FILTER_SD_REMOVE_HPP
+#define FILTER_SD_REMOVE_HPP
+
+extern "C" {
+    extern struct metaproxy_1_filter_struct metaproxy_1_filter_sd_remove;
+}
+
+#endif
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * c-file-style: "Stroustrup"
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
+
index 632b4a2..a605b48 100644 (file)
@@ -18,6 +18,7 @@ filter_log.rnc \
 filter_multi.rnc \
 filter_query_rewrite.rnc \
 filter_record_transform.rnc \
+filter_sd_remove.rnc \
 filter_session_shared.rnc \
 filter_sort.rnc \
 filter_sru_z3950.rnc \
diff --git a/xml/schema/filter_sd_remove.rnc b/xml/schema/filter_sd_remove.rnc
new file mode 100644 (file)
index 0000000..00ff23f
--- /dev/null
@@ -0,0 +1,9 @@
+# Metaproxy XML config file schema
+
+namespace mp = "http://indexdata.com/metaproxy"
+
+filter_sd_remove =
+  attribute type { "sd_remove" },
+  attribute id { xsd:NCName }?,
+  attribute name { xsd:NCName }?
+
index 8063d89..e4ff7ef 100644 (file)
@@ -37,6 +37,7 @@ include "filter_log.rnc"
 include "filter_multi.rnc"
 include "filter_query_rewrite.rnc"
 include "filter_record_transform.rnc"
+include "filter_sd_remove.rnc"
 include "filter_session_shared.rnc"
 include "filter_sort.rnc"
 include "filter_sru_z3950.rnc"
@@ -87,6 +88,7 @@ filter =
     | filter_multi
     | filter_query_rewrite
     | filter_record_transform
+    | filter_sd_remove
     | filter_session_shared
     | filter_sort
     | filter_sru_z3950