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 ServerInstance->Log(DEBUG,"Loading core-compiled module '%s'",fname);
37 for (int j = 0; modsyms[j].name; j++)
39 ServerInstance->Log(DEBUG,"Check %s",modsyms[j].name);
40 if (!strcmp(modsyms[j].name,fname))
42 ServerInstance->Log(DEBUG,"Found %s",fname);
43 strlcpy(this->staticname,fname,1020);
48 err = "Module is not statically compiled into the ircd";
50 h = dlopen(fname, RTLD_NOW|RTLD_LOCAL);
53 err = (char*)dlerror();
54 ServerInstance->Log(DEBUG,"dlerror '%s' occured!", err);
58 ServerInstance->Log(DEBUG,"Finished loading '%s': %0x", fname, h);
62 DLLManager::~DLLManager()
65 // close the library if it isn't null
75 bool DLLManager::GetSymbol(initfunc* &v, const char *sym_name)
77 for (int j = 0; modsyms[j].name; j++)
79 if (!strcmp(this->staticname,modsyms[j].name))
86 err = "Module symbol missing from the core";
92 bool DLLManager::GetSymbol(void** v, const char* sym_name)
94 // try extract a symbol from the library
95 // get any error message is there is any
99 dlerror(); // clear value
100 *v = dlsym(h, sym_name);
101 err = (char*)dlerror();
118 DLLFactoryBase::DLLFactoryBase(InspIRCd* Instance, const char* fname, const char* symbol) : DLLManager(Instance, fname)
120 // try get the factory function if there is no error yet
126 if (!GetSymbol( factory_func, symbol ? symbol : "init_module"))
128 if (!GetSymbol( (void **)&factory_func, symbol ? symbol : "init_module"))
131 throw ModuleException("Missing init_module() entrypoint!");
136 DLLFactoryBase::~DLLFactoryBase()