1 /* $Id: modules.cpp,v 1.2 2005-06-10 22:53:43 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
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);
49 int Yaz_ProxyModule::is_module(const char *name)
51 if (!name || !strcmp(m_entry->module_name, name))
56 Yaz_ProxyModule::Yaz_ProxyModule(void *dl_handle, Yaz_ProxyModule_entry *ent,
57 Yaz_ProxyModule *next)
59 m_dl_handle = dl_handle;
63 if (m_entry->int_version == 0)
65 struct Yaz_ProxyModule_int0 *int0 =
66 reinterpret_cast<Yaz_ProxyModule_int0 *>(m_entry->fl);
68 m_user_handle = (*int0->init)();
72 Yaz_ProxyModule::~Yaz_ProxyModule()
74 if (m_entry->int_version == 0)
76 struct Yaz_ProxyModule_int0 *int0 =
77 reinterpret_cast<Yaz_ProxyModule_int0 *>(m_entry->fl);
79 (*int0->destroy)(m_user_handle);
86 int Yaz_ProxyModule::authenticate(const char *name,
88 const char *user, const char *group,
91 if (m_entry->int_version == 0)
93 struct Yaz_ProxyModule_int0 *int0 =
94 reinterpret_cast<Yaz_ProxyModule_int0 *>(m_entry->fl);
96 if (!int0->authenticate)
97 return YAZPROXY_RET_NOT_ME;
98 return (*int0->authenticate)(m_user_handle, name, element_ptr,
99 user, group, password);
101 return YAZPROXY_RET_NOT_ME;
104 Yaz_ProxyModules::Yaz_ProxyModules()
111 Yaz_ProxyModules::~Yaz_ProxyModules()
116 void Yaz_ProxyModules::unload_modules()
118 Yaz_ProxyModule *m = m_list;
121 Yaz_ProxyModule *m_next = m->get_next();
130 int Yaz_ProxyModules::authenticate(const char *module_name,
131 const char *target_name, void *element_ptr,
134 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);
144 if (ret != YAZPROXY_RET_NOT_ME)
151 int Yaz_ProxyModules::add_module(const char *fname)
154 void *dl_handle = dlopen(fname, RTLD_NOW|RTLD_GLOBAL);
157 Yaz_ProxyModule_entry *fl_ptr = 0;
158 fl_ptr = reinterpret_cast<Yaz_ProxyModule_entry *>
159 (dlsym(dl_handle, "yazproxy_module"));
162 Yaz_ProxyModule *m = new Yaz_ProxyModule(dl_handle,
168 yaz_log(YLOG_LOG, "Loaded module no_open=%d", m_no_open);