Put proper reference IDs in response PDUs properly.
[metaproxy-moved-to-github.git] / src / filter_auth_simple.cpp
1 /* $Id: filter_auth_simple.cpp,v 1.2 2006-01-13 15:09:35 adam Exp $
2    Copyright (c) 2005, Index Data.
3
4 %LICENSE%
5  */
6
7 #include "config.hpp"
8
9 #include "filter.hpp"
10 #include "package.hpp"
11
12 #include <boost/thread/mutex.hpp>
13
14 #include "util.hpp"
15 #include "filter_auth_simple.hpp"
16
17 #include <yaz/zgdu.h>
18
19 namespace yf = yp2::filter;
20
21 namespace yp2 {
22     namespace filter {
23         class AuthSimple::Rep {
24             friend class AuthSimple;
25             int dummy; // private data
26         };
27     }
28 }
29
30 yf::AuthSimple::AuthSimple() : m_p(new Rep)
31 {
32     m_p->dummy = 1;
33 }
34
35 yf::AuthSimple::~AuthSimple()
36 {  // must have a destructor because of boost::scoped_ptr
37 }
38
39 void yf::AuthSimple::process(yp2::Package &package) const
40 {
41     Z_GDU *gdu = package.request().get();
42
43     if (gdu && gdu->which == Z_GDU_Z3950 && gdu->u.z3950->which ==
44         Z_APDU_initRequest)
45     {
46         // we have a Z39.50 init request
47         Z_InitRequest *init = gdu->u.z3950->u.initRequest;
48
49         // for now reject if we don't supply _some_ auth
50         if (!init->idAuthentication)
51         {
52             yp2::odr odr;
53             Z_APDU *apdu = odr.create_initResponse(gdu->u.z3950, 0, 0);
54             
55             apdu->u.initResponse->implementationName = "YP2/YAZ";
56             *apdu->u.initResponse->result = 0; // reject
57             
58             package.response() = apdu;
59
60             package.session().close();
61             return;
62         }
63         // if we get here access is granted..
64
65         // should authentication be altered of deleted?
66         // that could be configurable..
67     }
68     package.move();  // pass on package
69 }
70
71 void yp2::filter::AuthSimple::configure(const xmlNode * ptr)
72 {
73     // Read XML config.. Put config info in m_p..
74     m_p->dummy = 1;  
75 }
76
77 static yp2::filter::Base* filter_creator()
78 {
79     return new yp2::filter::AuthSimple;
80 }
81
82 extern "C" {
83     struct yp2_filter_struct yp2_filter_auth_simple = {
84         0,
85         "auth_simple",
86         filter_creator
87     };
88 }
89
90
91 /*
92  * Local variables:
93  * c-basic-offset: 4
94  * indent-tabs-mode: nil
95  * c-file-style: "stroustrup"
96  * End:
97  * vim: shiftwidth=4 tabstop=8 expandtab
98  */