1 /* $Id: modules.cpp,v 1.1 2005-05-30 20:09:21 adam Exp $
2 Copyright (c) 1998-2005, Index Data.
4 This file is part of the yaz-proxy.
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
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
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
28 #include <yazproxy/module.h>
30 class Yaz_ProxyModule {
31 friend class Proxy_Msg;
33 void *m_dl_handle; /* dlopen/close handle */
34 Yaz_ProxyModule_entry *m_entry;
35 Yaz_ProxyModule *m_next;
36 void *m_user_handle; /* user handle */
38 Yaz_ProxyModule(void *dl_handle, Yaz_ProxyModule_entry *ent,
39 Yaz_ProxyModule *next);
42 Yaz_ProxyModule *get_next() { return m_next; };
43 int is_module(const char *name);
44 int authenticate(const char *target_name, void *element_ptr,
45 const char *user, const char *group, const char *password);
48 int Yaz_ProxyModule::is_module(const char *name)
50 if (!name || !strcmp(m_entry->module_name, name))
55 Yaz_ProxyModule::Yaz_ProxyModule(void *dl_handle, Yaz_ProxyModule_entry *ent,
56 Yaz_ProxyModule *next)
58 m_dl_handle = dl_handle;
62 if (m_entry->int_version == 0)
64 struct Yaz_ProxyModule_int0 *int0 =
65 reinterpret_cast<Yaz_ProxyModule_int0 *>(m_entry->fl);
67 m_user_handle = (*int0->init)();
71 Yaz_ProxyModule::~Yaz_ProxyModule()
73 if (m_entry->int_version == 0)
75 struct Yaz_ProxyModule_int0 *int0 =
76 reinterpret_cast<Yaz_ProxyModule_int0 *>(m_entry->fl);
78 (*int0->destroy)(m_user_handle);
85 int Yaz_ProxyModule::authenticate(const char *name,
87 const char *user, const char *group,
90 if (m_entry->int_version == 0)
92 struct Yaz_ProxyModule_int0 *int0 =
93 reinterpret_cast<Yaz_ProxyModule_int0 *>(m_entry->fl);
95 if (!int0->authenticate)
96 return YAZPROXY_RET_NOT_ME;
97 return (*int0->authenticate)(m_user_handle, name, element_ptr,
98 user, group, password);
100 return YAZPROXY_RET_NOT_ME;
103 Yaz_ProxyModules::Yaz_ProxyModules()
109 Yaz_ProxyModules::~Yaz_ProxyModules()
114 void Yaz_ProxyModules::unload_modules()
116 Yaz_ProxyModule *m = m_list;
119 Yaz_ProxyModule *m_next = m->get_next();
127 int Yaz_ProxyModules::authenticate(const char *module_name,
128 const char *target_name, void *element_ptr,
131 const char *password)
133 int ret = YAZPROXY_RET_NOT_ME;
134 Yaz_ProxyModule *m = m_list;
135 for (; m; m = m->get_next())
137 if (m->is_module(module_name))
139 ret = m->authenticate(target_name, element_ptr,
140 user, group, password);
141 if (ret != YAZPROXY_RET_NOT_ME)
148 int Yaz_ProxyModules::add_module(const char *fname)
151 void *dl_handle = dlopen(fname, RTLD_NOW|RTLD_GLOBAL);
154 Yaz_ProxyModule_entry *fl_ptr = 0;
155 fl_ptr = reinterpret_cast<Yaz_ProxyModule_entry *>
156 (dlsym(dl_handle, "yazproxy_module"));
159 Yaz_ProxyModule *m = new Yaz_ProxyModule(dl_handle,