Reformat: delete trailing whitespace
[metaproxy-moved-to-github.git] / src / filter_bounce.cpp
1 /* This file is part of Metaproxy.
2    Copyright (C) 2005-2012 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 "filter_bounce.hpp"
20 #include <metaproxy/package.hpp>
21 #include <metaproxy/util.hpp>
22 #include "gduutil.hpp"
23
24 #include <yaz/zgdu.h>
25
26 #include <sstream>
27
28 namespace mp = metaproxy_1;
29 namespace yf = mp::filter;
30
31 namespace metaproxy_1 {
32     namespace filter {
33         class Bounce::Rep {
34             friend class Bounce;
35             bool bounce;
36         };
37     }
38 }
39
40 yf::Bounce::Bounce() : m_p(new Rep)
41 {
42     m_p->bounce = true;
43 }
44
45 yf::Bounce::~Bounce()
46 {  // must have a destructor because of boost::scoped_ptr
47 }
48
49 void yf::Bounce::process(mp::Package &package) const
50 {
51     if (! m_p->bounce )
52     {
53         package.move();
54         return;
55     }
56     package.session().close();
57
58     Z_GDU *zgdu = package.request().get();
59
60     if (!zgdu)
61         return;
62
63     //std::string message("BOUNCE ");
64     std::ostringstream message;
65     message << "BOUNCE " << *zgdu;
66
67     metaproxy_1::odr odr;
68
69     if (zgdu->which == Z_GDU_Z3950)
70     {
71         Z_APDU *apdu_res = 0;
72         apdu_res = odr.create_close(zgdu->u.z3950,
73                                     Z_Close_systemProblem,
74                                     message.str().c_str());
75         package.response() = apdu_res;
76     }
77     else if (zgdu->which == Z_GDU_HTTP_Request)
78     {
79         Z_GDU *zgdu_res = 0;
80         zgdu_res
81             = odr.create_HTTP_Response(package.session(),
82                                        zgdu->u.HTTP_Request, 400);
83
84         package.response() = zgdu_res;
85     }
86     else if (zgdu->which == Z_GDU_HTTP_Response)
87     {
88     }
89
90
91     return;
92 }
93
94 void mp::filter::Bounce::configure(const xmlNode * ptr, bool test_only,
95                                    const char *path)
96 {
97     mp::xml::check_empty(ptr);
98 }
99
100 static mp::filter::Base* filter_creator()
101 {
102     return new mp::filter::Bounce;
103 }
104
105 extern "C" {
106     struct metaproxy_1_filter_struct metaproxy_1_filter_bounce = {
107         0,
108         "bounce",
109         filter_creator
110     };
111 }
112
113
114 /*
115  * Local variables:
116  * c-basic-offset: 4
117  * c-file-style: "Stroustrup"
118  * indent-tabs-mode: nil
119  * End:
120  * vim: shiftwidth=4 tabstop=8 expandtab
121  */
122