]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/dynamic.cpp
Add options:maxtargets that was somehow omitted, fixes bug #400 (Reported by DarkStorm)
[user/henk/code/inspircd.git] / src / dynamic.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2007 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include "inspircd.h"
15 #include "configreader.h"
16 #include "dynamic.h"
17 #ifndef WIN32
18 #include <dlfcn.h>
19 #endif
20
21 DLLManager::DLLManager(InspIRCd* ServerInstance, const char *fname)
22 {
23         err = NULL;
24
25         if (!strstr(fname,".so"))
26         {
27                 err = "This doesn't look like a module file to me...";
28                 return;
29         }
30
31         h = dlopen(fname, RTLD_NOW|RTLD_LOCAL);
32         if (!h)
33         {
34                 err = (char*)dlerror();
35                 return;
36         }
37 }
38
39 DLLManager::~DLLManager()
40 {
41         /* close the library */
42         if (h)
43                 dlclose(h);
44 }
45
46
47
48 bool DLLManager::GetSymbol(void** v, const char* sym_name)
49 {
50         /*
51          * try extract a symbol from the library
52          * get any error message is there is any
53          */
54         
55         if (h)
56         {
57                 dlerror(); // clear value
58                 *v = dlsym(h, sym_name);
59                 err = (char*)dlerror();
60                 if (!*v || err)
61                         return false;
62         }
63         
64         /* succeeded :) */
65         return true;
66 }
67
68 DLLFactoryBase::DLLFactoryBase(InspIRCd* Instance, const char* fname, const char* symbol) : DLLManager(Instance, fname)
69 {
70         /* try get the factory function if there is no error yet */
71         factory_func = 0;
72         
73         if (!LastError())
74         {
75                 if (!GetSymbol( (void **)&factory_func, symbol ? symbol : "init_module"))
76                 {
77                         throw ModuleException("Missing init_module() entrypoint!");
78                 }
79         }
80 }
81
82 DLLFactoryBase::~DLLFactoryBase()
83 {
84 }
85