Avoid one condition variable in msg-thread impl
[yazproxy-moved-to-github.git] / src / mod_sample.cpp
1 /* $Id: mod_sample.cpp,v 1.5 2005-06-25 15:58:33 adam Exp $
2    Copyright (c) 1998-2005, Index Data.
3
4 This file is part of the yaz-proxy.
5
6 YAZ proxy 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 YAZ proxy 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 YAZ proxy; 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 <string.h>
23 #include <stdio.h>
24 #include <unistd.h>
25
26 #include <yazproxy/module.h>
27
28 #if HAVE_XSLT
29 #include <libxml/parser.h>
30 #include <libxml/tree.h>
31 #include <libxml/xinclude.h>
32 #include <libxslt/xsltutils.h>
33 #include <libxslt/transform.h>
34 #endif
35
36 void *my_init(void)
37 {
38     return 0;  // no private data for handler
39 }
40
41 void my_destroy(void *p)
42 {
43     // private data destroy
44 }
45
46 int my_authenticate(void *user_handle,
47                     const char *target_name,
48                     void *element_ptr,
49                     const char *user, const char *group, const char *password,
50                     const char *peer_IP)
51 {
52     // see if we have an "args" attribute
53     const char *args = 0;
54 #if HAVE_XSLT
55     xmlNodePtr ptr = (xmlNodePtr) element_ptr;
56     struct _xmlAttr *attr;
57     
58     for (attr = ptr->properties; attr; attr = attr->next)
59     {
60         if (!strcmp((const char *) attr->name, "args") &&
61             attr->children && attr->children->type == XML_TEXT_NODE)
62             args = (const char *) attr->children->content;
63     }
64 #endif
65     // args holds args (or NULL if  none is provided)
66
67     sleep(2);
68     fprintf(stderr, "my_authenticate: target=%s user=%s group=%s args=%s IP=%s"
69             "\n",
70             target_name ? target_name : "none", 
71             user ? user : "none", group ? group : "none",
72             args ? args : "none",
73             peer_IP);
74     // authentication handler
75     if (!user && !group && !password)
76         return YAZPROXY_RET_OK;   // OK if anonymous
77     if (user && !strcmp(user, "guest")
78         && password && !strcmp(password, "guest"))  // or guest guest
79         return YAZPROXY_RET_OK;
80     return YAZPROXY_RET_PERM;  // fail otherwise
81 }
82
83 Yaz_ProxyModule_int0 interface0 = {
84     my_init,
85     my_destroy,
86     my_authenticate
87 };
88
89 Yaz_ProxyModule_entry yazproxy_module = {
90     0,                            // interface version
91     "sample",                     // name
92     "Sample Module for YAZ Proxy",// description
93     &interface0
94 };
95 /*
96  * Local variables:
97  * c-basic-offset: 4
98  * indent-tabs-mode: nil
99  * End:
100  * vim: shiftwidth=4 tabstop=8 expandtab
101  */
102