]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/dynamic.cpp
Remove more unnecessary header traffic
[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 "dynamic.h"
16 #ifndef WIN32
17 #include <dlfcn.h>
18 #endif
19
20 DLLManager::DLLManager(InspIRCd* ServerInstance, const char *fname)
21 {
22         err = NULL;
23
24         if (!strstr(fname,".so"))
25         {
26                 err = "This doesn't look like a module file to me...";
27                 return;
28         }
29
30         h = dlopen(fname, RTLD_NOW|RTLD_LOCAL);
31         if (!h)
32         {
33                 err = (char*)dlerror();
34                 return;
35         }
36 }
37
38 DLLManager::~DLLManager()
39 {
40         /* close the library */
41         if (h)
42                 dlclose(h);
43 }
44
45
46
47 bool DLLManager::GetSymbol(void** v, const char* sym_name)
48 {
49         /*
50          * try extract a symbol from the library
51          * get any error message is there is any
52          */
53         
54         if (h)
55         {
56                 dlerror(); // clear value
57                 *v = dlsym(h, sym_name);
58                 err = (char*)dlerror();
59                 if (!*v || err)
60                         return false;
61         }
62         
63         /* succeeded :) */
64         return true;
65 }
66
67 DLLFactoryBase::DLLFactoryBase(InspIRCd* Instance, const char* fname, const char* symbol) : DLLManager(Instance, fname)
68 {
69         /* try get the factory function if there is no error yet */
70         factory_func = 0;
71         
72         if (!LastError())
73         {
74                 if (!GetSymbol( (void **)&factory_func, symbol ? symbol : "init_module"))
75                 {
76                         throw ModuleException("Missing init_module() entrypoint!");
77                 }
78         }
79 }
80
81 DLLFactoryBase::~DLLFactoryBase()
82 {
83 }
84