]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/dynamic.cpp
Fix pending invites not being removed when a channel was deleted or had its TS lowered
[user/henk/code/inspircd.git] / src / dynamic.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
5  *   Copyright (C) 2007 Oliver Lupton <oliverlupton@gmail.com>
6  *   Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net>
7  *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
8  *   Copyright (C) 2003, 2006 Craig Edwards <craigedwards@brainbox.cc>
9  *
10  * This file is part of InspIRCd.  InspIRCd is free software: you can
11  * redistribute it and/or modify it under the terms of the GNU General Public
12  * License as published by the Free Software Foundation, version 2.
13  *
14  * This program is distributed in the hope that it will be useful, but WITHOUT
15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
17  * details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  */
22
23
24 #include "inspircd.h"
25 #include "dynamic.h"
26 #ifndef WIN32
27 #include <dlfcn.h>
28 #endif
29
30 DLLManager::DLLManager(const char *fname)
31 {
32         if (!strstr(fname,".so"))
33         {
34                 err = "This doesn't look like a module file to me...";
35                 h = NULL;
36                 return;
37         }
38
39         h = dlopen(fname, RTLD_NOW|RTLD_LOCAL);
40         if (!h)
41         {
42                 err = dlerror();
43         }
44 }
45
46 DLLManager::~DLLManager()
47 {
48         /* close the library */
49         if (h)
50                 dlclose(h);
51 }
52
53 union init_t {
54         void* vptr;
55         Module* (*fptr)();
56 };
57
58 Module* DLLManager::CallInit()
59 {
60         if (!h)
61                 return NULL;
62
63         init_t initfn;
64         initfn.vptr = dlsym(h, MODULE_INIT_STR);
65         if (!initfn.vptr)
66         {
67                 err = dlerror();
68                 return NULL;
69         }
70
71         return (*initfn.fptr)();
72 }
73
74 std::string DLLManager::GetVersion()
75 {
76         if (!h)
77                 return "";
78
79         const char* srcver = (char*)dlsym(h, "inspircd_src_version");
80         if (srcver)
81                 return srcver;
82         return "Unversioned module";
83 }