Implemented plugin facility. First use is authentication from
[yazproxy-moved-to-github.git] / src / mod_sample.cpp
1 /* $Id: mod_sample.cpp,v 1.1 2005-02-11 15:19:08 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 void *my_init(void)
28 {
29     return 0;  // no private data for handler
30 }
31
32 void my_destroy(void *p)
33 {
34     // private data destroy
35 }
36
37 int my_authenticate(void *p, const char *user, const char *group,
38                     const char *password)
39 {
40     fprintf(stderr, "my_authenticate: user=%s group=%s\n",
41             user ? user : "none", group ? group : "none");
42     // authentication handler
43     if (!user && !group && !password)
44         return YAZPROXY_RET_OK;   // OK if anonymous
45     if (user && !strcmp(user, "guest")
46         && password && !strcmp(password, "guest"))  // or guest guest
47         return YAZPROXY_RET_OK;
48     return YAZPROXY_RET_PERM;  // fail otherwise
49 }
50
51 Yaz_ProxyModule_int0 interface0 = {
52     my_init,
53     my_destroy,
54     my_authenticate
55 };
56
57 Yaz_ProxyModule_entry yazproxy_module = {
58     0,                            // interface version
59     "sample",                     // name
60     "Sample Module for YAZ Proxy",// description
61     &interface0
62 };
63