1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2007 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
14 #include "configreader.h"
25 DLLManager::DLLManager(InspIRCd* ServerInstance, const char *fname)
29 if (!strstr(fname,".so"))
31 err = "This doesn't look like a module file to me...";
35 this->staticname[0] = '\0';
36 for (int j = 0; modsyms[j].name; j++)
38 if (!strcmp(modsyms[j].name,fname))
40 strlcpy(this->staticname,fname,1020);
45 err = "Module is not statically compiled into the ircd";
47 h = dlopen(fname, RTLD_NOW|RTLD_LOCAL);
50 err = (char*)dlerror();
56 DLLManager::~DLLManager()
59 // close the library if it isn't null
69 bool DLLManager::GetSymbol(initfunc* &v, const char *sym_name)
71 for (int j = 0; modsyms[j].name; j++)
73 if (!strcmp(this->staticname,modsyms[j].name))
80 err = "Module symbol missing from the core";
86 bool DLLManager::GetSymbol(void** v, const char* sym_name)
88 // try extract a symbol from the library
89 // get any error message is there is any
93 dlerror(); // clear value
94 *v = dlsym(h, sym_name);
95 err = (char*)dlerror();
112 DLLFactoryBase::DLLFactoryBase(InspIRCd* Instance, const char* fname, const char* symbol) : DLLManager(Instance, fname)
114 // try get the factory function if there is no error yet
120 if (!GetSymbol( factory_func, symbol ? symbol : "init_module"))
122 if (!GetSymbol( (void **)&factory_func, symbol ? symbol : "init_module"))
125 throw ModuleException("Missing init_module() entrypoint!");
130 DLLFactoryBase::~DLLFactoryBase()