GPL v2.
[metaproxy-moved-to-github.git] / src / filter_bounce.cpp
1 /* $Id: filter_bounce.cpp,v 1.4 2007-05-09 21:23:09 adam Exp $
2    Copyright (c) 2005-2007, Index Data.
3
4 This file is part of Metaproxy.
5
6 Metaproxy is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2, or (at your option) any later
9 version.
10
11 Metaproxy is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with Metaproxy; see the file LICENSE.  If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
19 02111-1307, USA.
20  */
21
22 #include "filter_bounce.hpp"
23 #include "package.hpp"
24 #include "util.hpp"
25 #include "gduutil.hpp"
26
27 #include <yaz/zgdu.h>
28
29 #include <sstream>
30
31 //#include "config.hpp"
32 //#include "filter.hpp"
33
34 //#include <boost/thread/mutex.hpp>
35
36
37
38
39
40 namespace mp = metaproxy_1;
41 namespace yf = mp::filter;
42
43 namespace metaproxy_1 {
44     namespace filter {
45         class Bounce::Rep {
46             friend class Bounce;
47             bool bounce;
48         };
49     }
50 }
51
52 yf::Bounce::Bounce() : m_p(new Rep)
53 {
54     m_p->bounce = true;
55 }
56
57 yf::Bounce::~Bounce()
58 {  // must have a destructor because of boost::scoped_ptr
59 }
60
61 void yf::Bounce::process(mp::Package &package) const
62 {
63     if (! m_p->bounce )
64     {
65         package.move();
66         return;
67     }
68     package.session().close();
69     
70     Z_GDU *zgdu = package.request().get();
71     
72     if (!zgdu)
73         return;
74     
75     //std::string message("BOUNCE ");
76     std::ostringstream message;    
77     message << "BOUNCE " << *zgdu;
78     
79     metaproxy_1::odr odr; 
80     
81     if (zgdu->which == Z_GDU_Z3950)
82     {
83         Z_APDU *apdu_res = 0;
84         apdu_res = odr.create_close(zgdu->u.z3950,
85                                     Z_Close_systemProblem,
86                                     message.str().c_str());
87         package.response() = apdu_res;
88     }
89     else if (zgdu->which == Z_GDU_HTTP_Request)
90     {
91         Z_GDU *zgdu_res = 0;
92         zgdu_res 
93             = odr.create_HTTP_Response(package.session(), 
94                                        zgdu->u.HTTP_Request, 400);
95         
96         package.response() = zgdu_res;
97     }
98     else if (zgdu->which == Z_GDU_HTTP_Response)
99     {
100     }
101     
102
103     return;
104 }
105
106 static mp::filter::Base* filter_creator()
107 {
108     return new mp::filter::Bounce;
109 }
110
111 extern "C" {
112     struct metaproxy_1_filter_struct metaproxy_1_filter_bounce = {
113         0,
114         "bounce",
115         filter_creator
116     };
117 }
118
119
120 /*
121  * Local variables:
122  * c-basic-offset: 4
123  * indent-tabs-mode: nil
124  * c-file-style: "stroustrup"
125  * End:
126  * vim: shiftwidth=4 tabstop=8 expandtab
127  */