]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/dynamic.cpp
Fix module unmapping with culled Module objects
[user/henk/code/inspircd.git] / src / dynamic.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
6  * See: http://wiki.inspircd.org/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(const char *fname)
21 {
22         if (!strstr(fname,".so"))
23         {
24                 err = "This doesn't look like a module file to me...";
25                 h = NULL;
26                 return;
27         }
28
29         h = dlopen(fname, RTLD_NOW|RTLD_LOCAL);
30         if (!h)
31         {
32                 err = dlerror();
33         }
34 }
35
36 DLLManager::~DLLManager()
37 {
38         /* close the library */
39         if (h)
40                 dlclose(h);
41 }
42
43 union init_t {
44         void* vptr;
45         Module* (*fptr)();
46 };
47
48 Module* DLLManager::callInit()
49 {
50         if (!h)
51                 return NULL;
52
53         init_t initfn;
54         initfn.vptr = dlsym(h, MODULE_INIT_STR);
55         if (!initfn.vptr)
56         {
57                 err = dlerror();
58                 return NULL;
59         }
60
61         return (*initfn.fptr)();
62 }