1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
7 * <brain@chatspike.net>
8 * <Craig@chatspike.net>
10 * Written by Craig Edwards, Craig McLure, and others.
11 * This program is free but copyrighted software; see
12 * the file COPYING for details.
14 * ---------------------------------------------------
19 #include "configreader.h"
30 DLLManager::DLLManager(InspIRCd* ServerInstance, const char *fname)
34 if (!strstr(fname,".so"))
36 err = "This doesn't look like a module file to me...";
40 this->staticname[0] = '\0';
41 ServerInstance->Log(DEBUG,"Loading core-compiled module '%s'",fname);
42 for (int j = 0; modsyms[j].name; j++)
44 ServerInstance->Log(DEBUG,"Check %s",modsyms[j].name);
45 if (!strcmp(modsyms[j].name,fname))
47 ServerInstance->Log(DEBUG,"Found %s",fname);
48 strlcpy(this->staticname,fname,1020);
53 err = "Module is not statically compiled into the ircd";
55 h = dlopen(fname, RTLD_NOW|RTLD_LOCAL);
58 err = (char*)dlerror();
59 ServerInstance->Log(DEBUG,"dlerror '%s' occured!", err);
63 ServerInstance->Log(DEBUG,"Finished loading '%s': %0x", fname, h);
67 DLLManager::~DLLManager()
70 // close the library if it isn't null
80 bool DLLManager::GetSymbol(initfunc* &v, const char *sym_name)
82 for (int j = 0; modsyms[j].name; j++)
84 if (!strcmp(this->staticname,modsyms[j].name))
91 err = "Module symbol missing from the core";
97 bool DLLManager::GetSymbol(void** v, const char* sym_name)
99 // try extract a symbol from the library
100 // get any error message is there is any
104 dlerror(); // clear value
105 *v = dlsym(h, sym_name);
106 err = (char*)dlerror();
123 DLLFactoryBase::DLLFactoryBase(InspIRCd* Instance, const char* fname, const char* symbol) : DLLManager(Instance, fname)
125 // try get the factory function if there is no error yet
131 if (!GetSymbol( factory_func, symbol ? symbol : "init_module"))
133 if (!GetSymbol( (void **)&factory_func, symbol ? symbol : "init_module"))
136 throw ModuleException("Missing init_module() entrypoint!");
141 DLLFactoryBase::~DLLFactoryBase()