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)
35 LastModuleError = "You can't load modules with a path: " + filename;
39 const std::string moduleFile = ServerInstance->Config->Paths.PrependModule(filename);
41 if (!FileSystem::FileExists(moduleFile))
43 LastModuleError = "Module file could not be found: " + filename;
44 ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, LastModuleError);
48 if (Modules.find(filename) != Modules.end())
50 LastModuleError = "Module " + filename + " is already loaded, cannot load a module twice!";
51 ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, LastModuleError);
55 Module* newmod = NULL;
56 DLLManager* newhandle = new DLLManager(moduleFile.c_str());
57 ServiceList newservices;
59 this->NewServices = &newservices;
63 newmod = newhandle->CallInit();
64 this->NewServices = NULL;
68 newmod->ModuleSourceFile = filename;
69 newmod->ModuleDLLManager = newhandle;
70 newmod->dying = false;
71 Modules[filename] = newmod;
72 std::string version = newhandle->GetVersion();
75 ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, "New module introduced: %s (Module version %s)",
76 filename.c_str(), version.c_str());
80 ConfigStatus confstatus;
83 AddServices(newservices);
85 newmod->ReadConfig(confstatus);
87 Version v = newmod->GetVersion();
88 ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, "New module introduced: %s (Module version %s)%s",
89 filename.c_str(), version.c_str(), (!(v.Flags & VF_VENDOR) ? " [3rd Party]" : " [Vendor]"));
94 LastModuleError = "Unable to load " + filename + ": " + newhandle->LastError();
95 ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, LastModuleError);
100 catch (CoreException& modexcept)
102 this->NewServices = NULL;
104 // failure in module constructor
107 DoSafeUnload(newmod);
108 ServerInstance->GlobalCulls.AddItem(newhandle);
112 LastModuleError = "Unable to load " + filename + ": " + modexcept.GetReason();
113 ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, LastModuleError);
120 FOREACH_MOD(OnLoadModule, (newmod));
122 ServerInstance->ISupport.Build();
126 /* We must load the modules AFTER initializing the socket engine, now */
127 void ModuleManager::LoadCoreModules(std::map<std::string, ServiceList>& servicemap)
129 std::cout << std::endl << "Loading core commands";
132 DIR* library = opendir(ServerInstance->Config->Paths.Module.c_str());
135 dirent* entry = NULL;
136 while (0 != (entry = readdir(library)))
138 if (InspIRCd::Match(entry->d_name, "core_*.so", ascii_case_insensitive_map))
143 this->NewServices = &servicemap[entry->d_name];
145 if (!Load(entry->d_name, true))
147 ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, this->LastError());
148 std::cout << std::endl << "[" << con_red << "*" << con_reset << "] " << this->LastError() << std::endl << std::endl;
149 ServerInstance->Exit(EXIT_STATUS_MODULE);
154 std::cout << std::endl;