2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2017-2019 Sadie Powell <sadie@witchery.services>
5 * Copyright (C) 2014 Attila Molnar <attilamolnar@hush.com>
6 * Copyright (C) 2012 Robby <robby@chatbelgie.be>
7 * Copyright (C) 2012 ChrisTX <xpipe@hotmail.de>
8 * Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
9 * Copyright (C) 2009 Uli Schlachter <psychon@inspircd.org>
10 * Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net>
11 * Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
12 * Copyright (C) 2006, 2010 Craig Edwards <brain@inspircd.org>
14 * This file is part of InspIRCd. InspIRCd is free software: you can
15 * redistribute it and/or modify it under the terms of the GNU General Public
16 * License as published by the Free Software Foundation, version 2.
18 * This program is distributed in the hope that it will be useful, but WITHOUT
19 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
20 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <http://www.gnu.org/licenses/>.
33 #define dlopen(path, state) (void*)LoadLibraryA(path)
34 #define dlsym(handle, export) (void*)GetProcAddress((HMODULE)handle, export)
35 #define dlclose(handle) FreeLibrary((HMODULE)handle)
38 DLLManager::DLLManager(const char *fname)
40 if (!strstr(fname,".so"))
42 err = "This doesn't look like a module file to me...";
47 h = dlopen(fname, RTLD_NOW|RTLD_LOCAL);
54 DLLManager::~DLLManager()
56 /* close the library */
61 Module* DLLManager::CallInit()
69 vptr = GetSymbol(MODULE_INIT_STR);
76 void* DLLManager::GetSymbol(const char* name)
78 return h ? dlsym(h, name) : NULL;
81 std::string DLLManager::GetVersion()
83 const char* srcver = static_cast<const char*>(GetSymbol("inspircd_src_version"));
84 return srcver ? srcver : "";
87 void DLLManager::RetrieveLastError()
91 DWORD dwErrorCode = GetLastError();
92 if (FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, dwErrorCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)errmsg, _countof(errmsg), NULL) == 0)
93 sprintf_s(errmsg, _countof(errmsg), "Error code: %u", dwErrorCode);
94 SetLastError(ERROR_SUCCESS);
97 const char* errmsg = dlerror();
98 err = errmsg ? errmsg : "Unknown error";
101 std::string::size_type p;
102 while ((p = err.find_last_of("\r\n")) != std::string::npos)