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