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"
28 bool ModuleManager::Load(const std::string& modname, bool defer)
30 /* Don't allow people to specify paths for modules, it doesn't work as expected */
31 if (modname.find('/') != std::string::npos)
33 LastModuleError = "You can't load modules with a path: " + modname;
37 const std::string filename = ExpandModName(modname);
38 const std::string moduleFile = ServerInstance->Config->Paths.PrependModule(filename);
40 if (!FileSystem::FileExists(moduleFile))
42 LastModuleError = "Module file could not be found: " + filename;
43 ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, LastModuleError);
47 if (Modules.find(filename) != Modules.end())
49 LastModuleError = "Module " + filename + " is already loaded, cannot load a module twice!";
50 ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, LastModuleError);
54 Module* newmod = NULL;
55 DLLManager* newhandle = new DLLManager(moduleFile.c_str());
56 ServiceList newservices;
58 this->NewServices = &newservices;
62 newmod = newhandle->CallInit();
63 this->NewServices = NULL;
67 newmod->ModuleSourceFile = filename;
68 newmod->ModuleDLLManager = newhandle;
69 Modules[filename] = newmod;
70 std::string version = newhandle->GetVersion();
72 version.assign("unknown");
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" << std::flush;
131 DIR* library = opendir(ServerInstance->Config->Paths.Module.c_str());
134 dirent* entry = NULL;
135 while (0 != (entry = readdir(library)))
137 if (InspIRCd::Match(entry->d_name, "core_*.so", ascii_case_insensitive_map))
139 std::cout << "." << std::flush;
141 this->NewServices = &servicemap[entry->d_name];
143 if (!Load(entry->d_name, true))
145 ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, this->LastError());
146 std::cout << std::endl << "[" << con_red << "*" << con_reset << "] " << this->LastError() << std::endl << std::endl;
147 ServerInstance->Exit(EXIT_STATUS_MODULE);
152 std::cout << std::endl;