Added a simple loadable example-module, with its own
authorHeikki Levanto <heikki@indexdata.dk>
Tue, 16 Dec 2008 13:30:12 +0000 (14:30 +0100)
committerHeikki Levanto <heikki@indexdata.dk>
Tue, 16 Dec 2008 13:30:12 +0000 (14:30 +0100)
Makefile etc.

.gitignore
example-module/Makefile [new file with mode: 0644]
example-module/README [new file with mode: 0644]
example-module/config.xml [new file with mode: 0644]
example-module/filter_myfilter.cpp [new file with mode: 0644]

index 4c93b60..b5c2aba 100644 (file)
@@ -14,3 +14,4 @@ lib
 bin
 ChangeLog
 build-stamp
+*~
diff --git a/example-module/Makefile b/example-module/Makefile
new file mode 100644 (file)
index 0000000..b966052
--- /dev/null
@@ -0,0 +1,9 @@
+CONFIG=../../yazpp/yazpp-config
+SO=metaproxy_filter_myfilter.so
+$(SO): filter_myfilter.cpp
+       $(CXX) -shared -nostdlib `$(CONFIG) --cflags` -I ../src $< -o $(SO) ../src/.libs/libmetaproxy.so
+
+clean:
+       rm $(SO)
+run: $(SO)
+       ../src/metaproxy -c config.xml
diff --git a/example-module/README b/example-module/README
new file mode 100644 (file)
index 0000000..430d82d
--- /dev/null
@@ -0,0 +1,12 @@
+This is a very simplified example of a loadable metaproxy module
+
+There is a simple makefile, that does not depend (very much) on the
+main metaproxy stuff.
+
+You can run the server with 
+
+   make run
+
+Then connect to it with a yaz-client localhost:9000. The module sees the 
+init request, and rejects it with a system error.
+
diff --git a/example-module/config.xml b/example-module/config.xml
new file mode 100644 (file)
index 0000000..2b562e3
--- /dev/null
@@ -0,0 +1,21 @@
+<?xml version="1.0"?>
+<metaproxy xmlns="http://indexdata.com/metaproxy" version="1.0">
+  <dlpath>.</dlpath>
+  <start route="start"/>
+  <filters>
+    <filter id="frontend" type="frontend_net">
+      <port>@:9000</port>
+    </filter>
+  </filters>
+  <routes>  
+    <route id="start">
+      <filter refid="frontend"/>
+      <filter type="log"><category user-access="true" apdu="true" /></filter>
+      <filter type="myfilter">
+        <logmsg>hello</logmsg>
+      </filter>
+      <filter type="bounce"/>
+    </route>
+  </routes>
+</metaproxy>
+
diff --git a/example-module/filter_myfilter.cpp b/example-module/filter_myfilter.cpp
new file mode 100644 (file)
index 0000000..4c8f82d
--- /dev/null
@@ -0,0 +1,110 @@
+/* This file is part of Metaproxy.
+   Copyright (C) 2008 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 <yaz/log.h>
+#include <yaz/diagbib1.h>
+
+#include "config.hpp"
+#include "filter.hpp"
+#include "package.hpp"
+#include "util.hpp"
+
+namespace mp = metaproxy_1;
+
+namespace metaproxy_1 {
+    namespace filter {
+        class Filter_myfilter: public mp::filter::Base {
+        public:
+            void process(mp::Package & package) const;
+            void configure(const xmlNode *ptr, bool test_only);
+        };
+    }
+}
+
+void mp::filter::Filter_myfilter::process(mp::Package & package) const
+{   // See src/filter_backend_test.cpp for a more comprehensive 
+    // example of a dummy Z-server
+    Z_GDU *gdu = package.request().get();
+    Z_APDU *apdu_res = 0;
+    mp::odr odr;
+
+    if (!gdu || gdu->which != Z_GDU_Z3950)
+    {
+        yaz_log(YLOG_LOG, "myfilter::process: Not a Z39.50 packet");
+        package.move(); // Send on to other filters
+        return;
+    }
+    Z_APDU *apdu_req = gdu->u.z3950;
+    if (apdu_req->which == Z_APDU_initRequest) 
+    {
+        yaz_log(YLOG_LOG, "myfilter::process: Init request");
+        apdu_res= odr.create_initResponse( apdu_req,  
+              YAZ_BIB1_PERMANENT_SYSTEM_ERROR, "Not implemented!");
+        package.response() = apdu_res;
+    }
+    else 
+    {
+        yaz_log(YLOG_LOG, "myfilter::process: Unknown request type");
+        package.move(); // Send on to other filters
+    }
+}
+
+void mp::filter::Filter_myfilter::configure(const xmlNode *ptr, bool test_only)
+{
+    yaz_log(YLOG_LOG, "myfilter::configure");
+    for (ptr = ptr->children; ptr; ptr = ptr->next) 
+    {
+        if (ptr->type != XML_ELEMENT_NODE)
+            continue;
+        if (!strcmp((const char *) ptr->name, "logmsg"))
+        {
+            std::string msg = mp::xml::get_text(ptr);
+            yaz_log(YLOG_LOG, "myfilter::configure: %s", msg.c_str() );
+
+        }
+        else 
+        {
+            throw mp::filter::FilterException("Bad element "
+                      + std::string((const char *) ptr->name));
+        }
+    }
+
+
+}
+
+static mp::filter::Base* filter_creator()
+{
+    return new mp::filter::Filter_myfilter;
+}
+
+extern "C" {
+    struct metaproxy_1_filter_struct metaproxy_1_filter_myfilter = {
+        0,
+        "myfilter",
+        filter_creator
+    };
+}
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * c-file-style: "stroustrup"
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */