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"
30 bool ModuleManager::Load(const std::string& filename, bool defer)
32 /* Don't allow people to specify paths for modules, it doesn't work as expected */
33 if (filename.find('/') != std::string::npos)
36 const std::string moduleFile = ServerInstance->Config->Paths.PrependModule(filename);
38 if (!FileSystem::FileExists(moduleFile))
40 LastModuleError = "Module file could not be found: " + filename;
41 ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, LastModuleError);
45 if (Modules.find(filename) != Modules.end())
47 LastModuleError = "Module " + filename + " is already loaded, cannot load a module twice!";
48 ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, LastModuleError);
52 Module* newmod = NULL;
53 DLLManager* newhandle = new DLLManager(moduleFile.c_str());
54 ServiceList newservices;
56 this->NewServices = &newservices;
60 newmod = newhandle->CallInit();
61 this->NewServices = NULL;
65 newmod->ModuleSourceFile = filename;
66 newmod->ModuleDLLManager = newhandle;
67 newmod->dying = false;
68 Modules[filename] = newmod;
69 std::string version = newhandle->GetVersion();
72 ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, "New module introduced: %s (Module version %s)",
73 filename.c_str(), version.c_str());
77 ConfigStatus confstatus;
80 AddServices(newservices);
82 newmod->ReadConfig(confstatus);
84 Version v = newmod->GetVersion();
85 ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, "New module introduced: %s (Module version %s)%s",
86 filename.c_str(), version.c_str(), (!(v.Flags & VF_VENDOR) ? " [3rd Party]" : " [Vendor]"));
91 LastModuleError = "Unable to load " + filename + ": " + newhandle->LastError();
92 ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, LastModuleError);
97 catch (CoreException& modexcept)
99 this->NewServices = NULL;
101 // failure in module constructor
104 DoSafeUnload(newmod);
105 ServerInstance->GlobalCulls.AddItem(newhandle);
109 LastModuleError = "Unable to load " + filename + ": " + modexcept.GetReason();
110 ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, LastModuleError);
117 FOREACH_MOD(OnLoadModule, (newmod));
119 ServerInstance->ISupport.Build();
123 /* We must load the modules AFTER initializing the socket engine, now */
124 void ModuleManager::LoadCoreModules(std::map<std::string, ServiceList>& servicemap)
126 std::cout << std::endl << "Loading core commands";
129 DIR* library = opendir(ServerInstance->Config->Paths.Module.c_str());
132 dirent* entry = NULL;
133 while (0 != (entry = readdir(library)))
135 if (InspIRCd::Match(entry->d_name, "core_*.so", ascii_case_insensitive_map))
140 this->NewServices = &servicemap[entry->d_name];
142 if (!Load(entry->d_name, true))
144 ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, this->LastError());
145 std::cout << std::endl << "[" << con_red << "*" << con_reset << "] " << this->LastError() << std::endl << std::endl;
146 ServerInstance->Exit(EXIT_STATUS_MODULE);
151 std::cout << std::endl;