Bump year in copyright msg in source
[metaproxy-moved-to-github.git] / example-module / filter_myfilter.cpp
1 /* This file is part of Metaproxy.
2    Copyright (C) 2005-2009 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 "config.hpp"
23 #include "filter.hpp"
24 #include "package.hpp"
25 #include "util.hpp"
26
27 namespace mp = metaproxy_1;
28
29 namespace metaproxy_1 {
30     namespace filter {
31         class Filter_myfilter: public mp::filter::Base {
32         public:
33             void process(mp::Package & package) const;
34             void configure(const xmlNode *ptr, bool test_only);
35         };
36     }
37 }
38
39 void mp::filter::Filter_myfilter::process(mp::Package & package) const
40 {   // See src/filter_backend_test.cpp for a more comprehensive 
41     // example of a dummy Z-server
42     Z_GDU *gdu = package.request().get();
43     Z_APDU *apdu_res = 0;
44     mp::odr odr;
45
46     if (!gdu || gdu->which != Z_GDU_Z3950)
47     {
48         yaz_log(YLOG_LOG, "myfilter::process: Not a Z39.50 packet");
49         package.move(); // Send on to other filters
50         return;
51     }
52     Z_APDU *apdu_req = gdu->u.z3950;
53     if (apdu_req->which == Z_APDU_initRequest) 
54     {
55         yaz_log(YLOG_LOG, "myfilter::process: Init request");
56         apdu_res= odr.create_initResponse( apdu_req,  
57               YAZ_BIB1_PERMANENT_SYSTEM_ERROR, "Not implemented!");
58         package.response() = apdu_res;
59     }
60     else 
61     {
62         yaz_log(YLOG_LOG, "myfilter::process: Unknown request type");
63         package.move(); // Send on to other filters
64     }
65 }
66
67 void mp::filter::Filter_myfilter::configure(const xmlNode *ptr, bool test_only)
68 {
69     yaz_log(YLOG_LOG, "myfilter::configure");
70     for (ptr = ptr->children; ptr; ptr = ptr->next) 
71     {
72         if (ptr->type != XML_ELEMENT_NODE)
73             continue;
74         if (!strcmp((const char *) ptr->name, "logmsg"))
75         {
76             std::string msg = mp::xml::get_text(ptr);
77             yaz_log(YLOG_LOG, "myfilter::configure: %s", msg.c_str() );
78
79         }
80         else 
81         {
82             throw mp::filter::FilterException("Bad element "
83                       + std::string((const char *) ptr->name));
84         }
85     }
86
87
88 }
89
90 static mp::filter::Base* filter_creator()
91 {
92     return new mp::filter::Filter_myfilter;
93 }
94
95 extern "C" {
96     struct metaproxy_1_filter_struct metaproxy_1_filter_myfilter = {
97         0,
98         "myfilter",
99         filter_creator
100     };
101 }
102
103 /*
104  * Local variables:
105  * c-basic-offset: 4
106  * c-file-style: "Stroustrup"
107  * indent-tabs-mode: nil
108  * End:
109  * vim: shiftwidth=4 tabstop=8 expandtab
110  */
111