1 /* $Id: modules.cpp,v 1.7 2006-03-30 10:32:16 adam Exp $
2 Copyright (c) 1998-2006, Index Data.
4 This file is part of the yazproxy.
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
29 #include <yazproxy/module.h>
31 class Yaz_ProxyModule {
32 friend class Proxy_Msg;
34 void *m_dl_handle; /* dlopen/close handle */
35 Yaz_ProxyModule_entry *m_entry;
36 Yaz_ProxyModule *m_next;
37 void *m_user_handle; /* user handle */
39 Yaz_ProxyModule(void *dl_handle, Yaz_ProxyModule_entry *ent,
40 Yaz_ProxyModule *next);
43 Yaz_ProxyModule *get_next() { return m_next; };
44 int is_module(const char *name);
45 int authenticate(const char *target_name, void *element_ptr,
46 const char *user, const char *group, const char *password,
50 int Yaz_ProxyModule::is_module(const char *name)
52 if (!name || !strcmp(m_entry->module_name, name))
57 Yaz_ProxyModule::Yaz_ProxyModule(void *dl_handle, Yaz_ProxyModule_entry *ent,
58 Yaz_ProxyModule *next)
60 m_dl_handle = dl_handle;
64 if (m_entry->int_version == 0)
66 struct Yaz_ProxyModule_int0 *int0 =
67 reinterpret_cast<Yaz_ProxyModule_int0 *>(m_entry->fl);
69 m_user_handle = (*int0->init)();
73 Yaz_ProxyModule::~Yaz_ProxyModule()
75 if (m_entry->int_version == 0)
77 struct Yaz_ProxyModule_int0 *int0 =
78 reinterpret_cast<Yaz_ProxyModule_int0 *>(m_entry->fl);
80 (*int0->destroy)(m_user_handle);
87 int Yaz_ProxyModule::authenticate(const char *name,
89 const char *user, const char *group,
93 if (m_entry->int_version == 0)
95 struct Yaz_ProxyModule_int0 *int0 =
96 reinterpret_cast<Yaz_ProxyModule_int0 *>(m_entry->fl);
98 if (!int0->authenticate)
99 return YAZPROXY_RET_NOT_ME;
100 return (*int0->authenticate)(m_user_handle, name, element_ptr,
101 user, group, password, peer_IP);
103 return YAZPROXY_RET_NOT_ME;
106 Yaz_ProxyModules::Yaz_ProxyModules()
113 Yaz_ProxyModules::~Yaz_ProxyModules()
118 void Yaz_ProxyModules::unload_modules()
120 Yaz_ProxyModule *m = m_list;
123 Yaz_ProxyModule *m_next = m->get_next();
132 int Yaz_ProxyModules::authenticate(const char *module_name,
133 const char *target_name, void *element_ptr,
136 const char *password,
139 int ret = YAZPROXY_RET_NOT_ME;
140 Yaz_ProxyModule *m = m_list;
141 for (; m; m = m->get_next())
143 if (m->is_module(module_name))
145 ret = m->authenticate(target_name, element_ptr,
146 user, group, password,
148 if (ret != YAZPROXY_RET_NOT_ME)
155 int Yaz_ProxyModules::add_module(const char *fname)
158 void *dl_handle = dlopen(fname, RTLD_NOW|RTLD_GLOBAL);
161 Yaz_ProxyModule_entry *fl_ptr = 0;
162 fl_ptr = reinterpret_cast<Yaz_ProxyModule_entry *>
163 (dlsym(dl_handle, "yazproxy_module"));
166 Yaz_ProxyModule *m = new Yaz_ProxyModule(dl_handle,
172 yaz_log(YLOG_LOG, "Loaded module %s OK", fname);
177 yaz_log(YLOG_WARN, "Failed loading module %s - missing symbols",
185 yaz_log(YLOG_WARN, "Failed loading module %s", fname);
189 yaz_log(YLOG_WARN, "Failed loading module %s - no module support", fname);
197 * indent-tabs-mode: nil
199 * vim: shiftwidth=4 tabstop=8 expandtab