Windows: use Boost 1.59, msvc 14.0
[metaproxy-moved-to-github.git] / example-module / filter_myfilter.cpp
1 /* This file is part of Metaproxy.
2    Copyright (C) Index Data
3
4 Metaproxy is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
7 version.
8
9 Metaproxy is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17 */
18
19 #include <yaz/log.h>
20 #include <yaz/diagbib1.h>
21
22 #include <metaproxy/filter.hpp>
23 #include <metaproxy/package.hpp>
24 #include <metaproxy/util.hpp>
25
26 namespace mp = metaproxy_1;
27
28 namespace metaproxy_1 {
29     namespace filter {
30         class Filter_myfilter: public mp::filter::Base {
31         public:
32             void process(mp::Package & package) const;
33             void configure(const xmlNode *ptr, bool test_only, const char *path);
34         };
35     }
36 }
37
38 void mp::filter::Filter_myfilter::process(mp::Package & package) const
39 {   // See src/filter_backend_test.cpp for a more comprehensive
40     // example of a dummy Z-server
41     Z_GDU *gdu = package.request().get();
42     Z_APDU *apdu_res = 0;
43     mp::odr odr;
44
45     if (!gdu || gdu->which != Z_GDU_Z3950)
46     {
47         yaz_log(YLOG_LOG, "myfilter::process: Not a Z39.50 packet");
48         package.move(); // Send on to other filters
49         return;
50     }
51     Z_APDU *apdu_req = gdu->u.z3950;
52     if (apdu_req->which == Z_APDU_initRequest)
53     {
54         yaz_log(YLOG_LOG, "myfilter::process: Init request");
55         apdu_res= odr.create_initResponse( apdu_req,
56               YAZ_BIB1_PERMANENT_SYSTEM_ERROR, "Not implemented!");
57         package.response() = apdu_res;
58     }
59     else
60     {
61         yaz_log(YLOG_LOG, "myfilter::process: Unknown request type");
62         package.move(); // Send on to other filters
63     }
64 }
65
66 void mp::filter::Filter_myfilter::configure(const xmlNode *ptr, bool test_only, const char *path)
67 {
68     yaz_log(YLOG_LOG, "myfilter::configure called with test_only %d and %s", test_only, path);
69     for (ptr = ptr->children; ptr; ptr = ptr->next)
70     {
71         if (ptr->type != XML_ELEMENT_NODE)
72             continue;
73         if (!strcmp((const char *) ptr->name, "logmsg"))
74         {
75             std::string msg = mp::xml::get_text(ptr);
76             yaz_log(YLOG_LOG, "myfilter::configure: %s", msg.c_str() );
77
78         }
79         else
80         {
81             throw mp::filter::FilterException("Bad element "
82                       + std::string((const char *) ptr->name));
83         }
84     }
85
86
87 }
88
89 static mp::filter::Base* filter_creator()
90 {
91     return new mp::filter::Filter_myfilter;
92 }
93
94 extern "C" {
95     struct metaproxy_1_filter_struct metaproxy_1_filter_myfilter = {
96         0,
97         "myfilter",
98         filter_creator
99     };
100 }
101
102 /*
103  * Local variables:
104  * c-basic-offset: 4
105  * c-file-style: "Stroustrup"
106  * indent-tabs-mode: nil
107  * End:
108  * vim: shiftwidth=4 tabstop=8 expandtab
109  */
110