2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
6 * This file is part of InspIRCd. InspIRCd is free software: you can
7 * redistribute it and/or modify it under the terms of the GNU General Public
8 * License as published by the Free Software Foundation, version 2.
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "exitcodes.h"
24 bool ModuleManager::Load(const std::string& modname, bool defer)
26 /* Don't allow people to specify paths for modules, it doesn't work as expected */
27 if (modname.find('/') != std::string::npos)
29 LastModuleError = "You can't load modules with a path: " + modname;
33 const std::string filename = ExpandModName(modname);
34 const std::string moduleFile = ServerInstance->Config->Paths.PrependModule(filename);
36 if (!FileSystem::FileExists(moduleFile))
38 LastModuleError = "Module file could not be found: " + filename;
39 ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, LastModuleError);
43 if (Modules.find(filename) != Modules.end())
45 LastModuleError = "Module " + filename + " is already loaded, cannot load a module twice!";
46 ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, LastModuleError);
50 Module* newmod = NULL;
51 DLLManager* newhandle = new DLLManager(moduleFile.c_str());
52 ServiceList newservices;
54 this->NewServices = &newservices;
58 newmod = newhandle->CallInit();
59 this->NewServices = NULL;
63 newmod->ModuleSourceFile = filename;
64 newmod->ModuleDLLManager = newhandle;
65 Modules[filename] = newmod;
66 std::string version = newhandle->GetVersion();
68 version.assign("unknown");
71 ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, "New module introduced: %s (Module version %s)",
72 filename.c_str(), version.c_str());
76 ConfigStatus confstatus;
79 AddServices(newservices);
81 newmod->ReadConfig(confstatus);
83 Version v = newmod->GetVersion();
84 ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, "New module introduced: %s (Module version %s)%s",
85 filename.c_str(), version.c_str(), (!(v.Flags & VF_VENDOR) ? " [3rd Party]" : " [Vendor]"));
90 LastModuleError = "Unable to load " + filename + ": " + newhandle->LastError();
91 ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, LastModuleError);
96 catch (CoreException& modexcept)
98 this->NewServices = NULL;
100 // failure in module constructor
103 DoSafeUnload(newmod);
104 ServerInstance->GlobalCulls.AddItem(newhandle);
108 LastModuleError = "Unable to load " + filename + ": " + modexcept.GetReason();
109 ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, LastModuleError);
116 FOREACH_MOD(OnLoadModule, (newmod));
118 ServerInstance->ISupport.Build();
122 /* We must load the modules AFTER initializing the socket engine, now */
123 void ModuleManager::LoadCoreModules(std::map<std::string, ServiceList>& servicemap)
125 std::cout << "Loading core modules " << std::flush;
127 std::vector<std::string> files;
128 if (!FileSystem::GetFileList(ServerInstance->Config->Paths.Module, files, "core_*.so"))
130 std::cout << "failed!" << std::endl;
131 ServerInstance->Exit(EXIT_STATUS_MODULE);
134 for (std::vector<std::string>::const_iterator iter = files.begin(); iter != files.end(); ++iter)
136 std::cout << "." << std::flush;
138 const std::string& name = *iter;
139 this->NewServices = &servicemap[name];
141 if (!Load(name, true))
143 ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, this->LastError());
144 std::cout << std::endl << "[" << con_red << "*" << con_reset << "] " << this->LastError() << std::endl << std::endl;
145 ServerInstance->Exit(EXIT_STATUS_MODULE);
149 std::cout << std::endl;