2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2013, 2015, 2019-2020 Sadie Powell <sadie@witchery.services>
5 * Copyright (C) 2013 Adam <Adam@anope.org>
6 * Copyright (C) 2012-2013, 2015 Attila Molnar <attilamolnar@hush.com>
7 * Copyright (C) 2012 Robby <robby@chatbelgie.be>
8 * Copyright (C) 2012 ChrisTX <xpipe@hotmail.de>
9 * Copyright (C) 2010 Craig Edwards <brain@inspircd.org>
10 * Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
12 * This file is part of InspIRCd. InspIRCd is free software: you can
13 * redistribute it and/or modify it under the terms of the GNU General Public
14 * License as published by the Free Software Foundation, version 2.
16 * This program is distributed in the hope that it will be useful, but WITHOUT
17 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <http://www.gnu.org/licenses/>.
27 #include "exitcodes.h"
30 bool ModuleManager::Load(const std::string& modname, bool defer)
32 /* Don't allow people to specify paths for modules, it doesn't work as expected */
33 if (modname.find('/') != std::string::npos)
35 LastModuleError = "You can't load modules with a path: " + modname;
39 const std::string filename = ExpandModName(modname);
40 const std::string moduleFile = ServerInstance->Config->Paths.PrependModule(filename);
42 if (!FileSystem::FileExists(moduleFile))
44 LastModuleError = "Module file could not be found: " + filename;
45 ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, LastModuleError);
49 if (Modules.find(filename) != Modules.end())
51 LastModuleError = "Module " + filename + " is already loaded, cannot load a module twice!";
52 ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, LastModuleError);
56 Module* newmod = NULL;
57 DLLManager* newhandle = new DLLManager(moduleFile.c_str());
58 ServiceList newservices;
60 this->NewServices = &newservices;
64 newmod = newhandle->CallInit();
65 this->NewServices = NULL;
69 newmod->ModuleSourceFile = filename;
70 newmod->ModuleDLLManager = newhandle;
71 Modules[filename] = newmod;
72 const char* version = newhandle->GetVersion();
77 ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, "New module introduced: %s (Module version %s)",
78 filename.c_str(), version);
82 ConfigStatus confstatus;
85 AddServices(newservices);
87 newmod->ReadConfig(confstatus);
89 Version v = newmod->GetVersion();
90 ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, "New module introduced: %s (Module version %s)%s",
91 filename.c_str(), version, (!(v.Flags & VF_VENDOR) ? " [3rd Party]" : " [Vendor]"));
96 LastModuleError = "Unable to load " + filename + ": " + newhandle->LastError();
97 ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, LastModuleError);
102 catch (CoreException& modexcept)
104 this->NewServices = NULL;
106 // failure in module constructor
109 DoSafeUnload(newmod);
110 ServerInstance->GlobalCulls.AddItem(newhandle);
114 LastModuleError = "Unable to load " + filename + ": " + modexcept.GetReason();
115 ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, LastModuleError);
122 FOREACH_MOD(OnLoadModule, (newmod));
124 ServerInstance->ISupport.Build();
128 /* We must load the modules AFTER initializing the socket engine, now */
129 void ModuleManager::LoadCoreModules(std::map<std::string, ServiceList>& servicemap)
131 std::cout << "Loading core modules " << std::flush;
133 std::vector<std::string> files;
134 if (!FileSystem::GetFileList(ServerInstance->Config->Paths.Module, files, "core_*.so"))
136 std::cout << "failed!" << std::endl;
137 ServerInstance->Exit(EXIT_STATUS_MODULE);
140 for (std::vector<std::string>::const_iterator iter = files.begin(); iter != files.end(); ++iter)
142 std::cout << "." << std::flush;
144 const std::string& name = *iter;
145 this->NewServices = &servicemap[name];
147 if (!Load(name, true))
149 ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, this->LastError());
150 std::cout << std::endl << "[" << con_red << "*" << con_reset << "] " << this->LastError() << std::endl << std::endl;
151 ServerInstance->Exit(EXIT_STATUS_MODULE);
155 std::cout << std::endl;