Indent
[metaproxy-moved-to-github.git] / src / filter_bounce.cpp
1 /* $Id: filter_bounce.cpp,v 1.3 2007-03-20 07:17:40 adam Exp $
2    Copyright (c) 2005-2007, Index Data.
3
4    See the LICENSE file for details
5  */
6
7 #include "filter_bounce.hpp"
8 #include "package.hpp"
9 #include "util.hpp"
10 #include "gduutil.hpp"
11
12 #include <yaz/zgdu.h>
13
14 #include <sstream>
15
16 //#include "config.hpp"
17 //#include "filter.hpp"
18
19 //#include <boost/thread/mutex.hpp>
20
21
22
23
24
25 namespace mp = metaproxy_1;
26 namespace yf = mp::filter;
27
28 namespace metaproxy_1 {
29     namespace filter {
30         class Bounce::Rep {
31             friend class Bounce;
32             bool bounce;
33         };
34     }
35 }
36
37 yf::Bounce::Bounce() : m_p(new Rep)
38 {
39     m_p->bounce = true;
40 }
41
42 yf::Bounce::~Bounce()
43 {  // must have a destructor because of boost::scoped_ptr
44 }
45
46 void yf::Bounce::process(mp::Package &package) const
47 {
48     if (! m_p->bounce )
49     {
50         package.move();
51         return;
52     }
53     package.session().close();
54     
55     Z_GDU *zgdu = package.request().get();
56     
57     if (!zgdu)
58         return;
59     
60     //std::string message("BOUNCE ");
61     std::ostringstream message;    
62     message << "BOUNCE " << *zgdu;
63     
64     metaproxy_1::odr odr; 
65     
66     if (zgdu->which == Z_GDU_Z3950)
67     {
68         Z_APDU *apdu_res = 0;
69         apdu_res = odr.create_close(zgdu->u.z3950,
70                                     Z_Close_systemProblem,
71                                     message.str().c_str());
72         package.response() = apdu_res;
73     }
74     else if (zgdu->which == Z_GDU_HTTP_Request)
75     {
76         Z_GDU *zgdu_res = 0;
77         zgdu_res 
78             = odr.create_HTTP_Response(package.session(), 
79                                        zgdu->u.HTTP_Request, 400);
80         
81         package.response() = zgdu_res;
82     }
83     else if (zgdu->which == Z_GDU_HTTP_Response)
84     {
85     }
86     
87
88     return;
89 }
90
91 static mp::filter::Base* filter_creator()
92 {
93     return new mp::filter::Bounce;
94 }
95
96 extern "C" {
97     struct metaproxy_1_filter_struct metaproxy_1_filter_bounce = {
98         0,
99         "bounce",
100         filter_creator
101     };
102 }
103
104
105 /*
106  * Local variables:
107  * c-basic-offset: 4
108  * indent-tabs-mode: nil
109  * c-file-style: "stroustrup"
110  * End:
111  * vim: shiftwidth=4 tabstop=8 expandtab
112  */