Bump version to 1.1.0
[yazproxy-moved-to-github.git] / src / mod_sample.cpp
1 /* $Id: mod_sample.cpp,v 1.2 2005-02-21 14:27:32 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
25 #include <yazproxy/module.h>
26
27 #if HAVE_XSLT
28 #include <libxml/parser.h>
29 #include <libxml/tree.h>
30 #include <libxml/xinclude.h>
31 #include <libxslt/xsltutils.h>
32 #include <libxslt/transform.h>
33 #endif
34
35 void *my_init(void)
36 {
37     return 0;  // no private data for handler
38 }
39
40 void my_destroy(void *p)
41 {
42     // private data destroy
43 }
44
45 int my_authenticate(void *user_handle,
46                     const char *target_name,
47                     void *element_ptr,
48                     const char *user, const char *group, const char *password)
49 {
50     // see if we have an "args" attribute
51     const char *args = 0;
52 #if HAVE_XSLT
53     xmlNodePtr ptr = (xmlNodePtr) element_ptr;
54     struct _xmlAttr *attr;
55     
56     for (attr = ptr->properties; attr; attr = attr->next)
57     {
58         if (!strcmp((const char *) attr->name, "args") &&
59             attr->children && attr->children->type == XML_TEXT_NODE)
60             args = (const char *) attr->children->content;
61     }
62 #endif
63     // args holds args (or NULL if  none is provided)
64
65     fprintf(stderr, "my_authenticate: target=%s user=%s group=%s args=%s\n",
66             target_name ? target_name : "none", 
67             user ? user : "none", group ? group : "none",
68             args ? args : "none");
69     // authentication handler
70     if (!user && !group && !password)
71         return YAZPROXY_RET_OK;   // OK if anonymous
72     if (user && !strcmp(user, "guest")
73         && password && !strcmp(password, "guest"))  // or guest guest
74         return YAZPROXY_RET_OK;
75     return YAZPROXY_RET_PERM;  // fail otherwise
76 }
77
78 Yaz_ProxyModule_int0 interface0 = {
79     my_init,
80     my_destroy,
81     my_authenticate
82 };
83
84 Yaz_ProxyModule_entry yazproxy_module = {
85     0,                            // interface version
86     "sample",                     // name
87     "Sample Module for YAZ Proxy",// description
88     &interface0
89 };