1 /* This file is part of YAZ proxy
2 Copyright (C) 1998-2011 Index Data
4 YAZ proxy is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
9 YAZ proxy is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 #include <yazproxy/module.h>
28 class Yaz_ProxyModule {
29 friend class Proxy_Msg;
31 void *m_dl_handle; /* dlopen/close handle */
32 Yaz_ProxyModule_entry *m_entry;
33 Yaz_ProxyModule *m_next;
34 void *m_user_handle; /* user handle */
36 Yaz_ProxyModule(void *dl_handle, Yaz_ProxyModule_entry *ent,
37 Yaz_ProxyModule *next);
40 Yaz_ProxyModule *get_next() { return m_next; };
41 int is_module(const char *name);
42 int authenticate(const char *target_name, void *element_ptr,
43 const char *user, const char *group, const char *password,
47 int Yaz_ProxyModule::is_module(const char *name)
49 if (!name || !strcmp(m_entry->module_name, name))
54 Yaz_ProxyModule::Yaz_ProxyModule(void *dl_handle, Yaz_ProxyModule_entry *ent,
55 Yaz_ProxyModule *next)
57 m_dl_handle = dl_handle;
61 if (m_entry->int_version == 0)
63 struct Yaz_ProxyModule_int0 *int0 =
64 reinterpret_cast<Yaz_ProxyModule_int0 *>(m_entry->fl);
66 m_user_handle = (*int0->init)();
70 Yaz_ProxyModule::~Yaz_ProxyModule()
72 if (m_entry->int_version == 0)
74 struct Yaz_ProxyModule_int0 *int0 =
75 reinterpret_cast<Yaz_ProxyModule_int0 *>(m_entry->fl);
77 (*int0->destroy)(m_user_handle);
84 int Yaz_ProxyModule::authenticate(const char *name,
86 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, peer_IP);
100 return YAZPROXY_RET_NOT_ME;
103 Yaz_ProxyModules::Yaz_ProxyModules()
110 Yaz_ProxyModules::~Yaz_ProxyModules()
115 void Yaz_ProxyModules::unload_modules()
117 Yaz_ProxyModule *m = m_list;
120 Yaz_ProxyModule *m_next = m->get_next();
129 int Yaz_ProxyModules::authenticate(const char *module_name,
130 const char *target_name, void *element_ptr,
133 const char *password,
136 int ret = YAZPROXY_RET_NOT_ME;
137 Yaz_ProxyModule *m = m_list;
138 for (; m; m = m->get_next())
140 if (m->is_module(module_name))
142 ret = m->authenticate(target_name, element_ptr,
143 user, group, password,
145 if (ret != YAZPROXY_RET_NOT_ME)
152 int Yaz_ProxyModules::add_module(const char *fname)
155 void *dl_handle = dlopen(fname, RTLD_NOW|RTLD_GLOBAL);
158 Yaz_ProxyModule_entry *fl_ptr = 0;
159 fl_ptr = reinterpret_cast<Yaz_ProxyModule_entry *>
160 (dlsym(dl_handle, "yazproxy_module"));
163 Yaz_ProxyModule *m = new Yaz_ProxyModule(dl_handle,
169 yaz_log(YLOG_LOG, "Loaded module %s OK", fname);
174 yaz_log(YLOG_WARN, "Failed loading module %s - missing symbols",
182 yaz_log(YLOG_WARN, "Failed loading module %s", fname);
186 yaz_log(YLOG_WARN, "Failed loading module %s - no module support", fname);
194 * c-file-style: "Stroustrup"
195 * indent-tabs-mode: nil
197 * vim: shiftwidth=4 tabstop=8 expandtab