1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2009 InspIRCd Development Team
6 * See: http://wiki.inspircd.org/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
19 #include "socketengine.h"
20 #include "command_parse.h"
22 #include "exitcodes.h"
29 // version is a simple class for holding a modules version number
31 VersionBase<API_VERSION>::VersionBase(const std::string &modv, int flags, int, const std::string& rev)
32 : description(modv), version(rev), Flags(flags)
36 Request::Request(Module* src, Module* dst, const char* idstr)
37 : id(idstr), source(src), dest(dst)
44 dest->OnRequest(*this);
47 Event::Event(Module* src, const std::string &eventid) : source(src), id(eventid) { }
51 FOREACH_MOD(I_OnEvent,OnEvent(*this));
54 // These declarations define the behavours of the base class Module (which does nothing at all)
59 ServerInstance->GlobalCulls.AddItem(ModuleDLLManager);
64 ModResult Module::OnSendSnotice(char &snomask, std::string &type, const std::string &message) { return MOD_RES_PASSTHRU; }
65 void Module::OnUserConnect(User*) { }
66 void Module::OnUserQuit(User*, const std::string&, const std::string&) { }
67 void Module::OnUserDisconnect(User*) { }
68 void Module::OnUserJoin(Membership*, bool, bool, CUList&) { }
69 void Module::OnPostJoin(Membership*) { }
70 void Module::OnUserPart(Membership*, std::string&, CUList&) { }
71 void Module::OnPreRehash(User*, const std::string&) { }
72 void Module::OnModuleRehash(User*, const std::string&) { }
73 void Module::OnRehash(User*) { }
74 ModResult Module::OnUserPreJoin(User*, Channel*, const char*, std::string&, const std::string&) { return MOD_RES_PASSTHRU; }
75 void Module::OnMode(User*, void*, int, const std::vector<std::string>&, const std::vector<TranslateType>&) { }
76 void Module::OnOper(User*, const std::string&) { }
77 void Module::OnPostOper(User*, const std::string&, const std::string &) { }
78 void Module::OnInfo(User*) { }
79 void Module::OnWhois(User*, User*) { }
80 ModResult Module::OnUserPreInvite(User*, User*, Channel*, time_t) { return MOD_RES_PASSTHRU; }
81 ModResult Module::OnUserPreMessage(User*, void*, int, std::string&, char, CUList&) { return MOD_RES_PASSTHRU; }
82 ModResult Module::OnUserPreNotice(User*, void*, int, std::string&, char, CUList&) { return MOD_RES_PASSTHRU; }
83 ModResult Module::OnUserPreNick(User*, const std::string&) { return MOD_RES_PASSTHRU; }
84 void Module::OnUserPostNick(User*, const std::string&) { }
85 ModResult Module::OnPreMode(User*, User*, Channel*, const std::vector<std::string>&) { return MOD_RES_PASSTHRU; }
86 void Module::On005Numeric(std::string&) { }
87 ModResult Module::OnKill(User*, User*, const std::string&) { return MOD_RES_PASSTHRU; }
88 void Module::OnLoadModule(Module*, const std::string&) { }
89 void Module::OnUnloadModule(Module*, const std::string&) { }
90 void Module::OnBackgroundTimer(time_t) { }
91 ModResult Module::OnPreCommand(std::string&, std::vector<std::string>&, User *, bool, const std::string&) { return MOD_RES_PASSTHRU; }
92 void Module::OnPostCommand(const std::string&, const std::vector<std::string>&, User *, CmdResult, const std::string&) { }
93 ModResult Module::OnCheckReady(User*) { return MOD_RES_PASSTHRU; }
94 ModResult Module::OnUserRegister(User*) { return MOD_RES_PASSTHRU; }
95 ModResult Module::OnUserPreKick(User*, Membership*, const std::string&) { return MOD_RES_PASSTHRU; }
96 void Module::OnUserKick(User*, Membership*, const std::string&, CUList&) { }
97 ModResult Module::OnRawMode(User*, Channel*, const char, const std::string &, bool, int) { return MOD_RES_PASSTHRU; }
98 ModResult Module::OnCheckInvite(User*, Channel*) { return MOD_RES_PASSTHRU; }
99 ModResult Module::OnCheckKey(User*, Channel*, const std::string&) { return MOD_RES_PASSTHRU; }
100 ModResult Module::OnCheckLimit(User*, Channel*) { return MOD_RES_PASSTHRU; }
101 ModResult Module::OnCheckChannelBan(User*, Channel*) { return MOD_RES_PASSTHRU; }
102 ModResult Module::OnCheckBan(User*, Channel*, const std::string&) { return MOD_RES_PASSTHRU; }
103 ModResult Module::OnExtBanCheck(User*, Channel*, char) { return MOD_RES_PASSTHRU; }
104 ModResult Module::OnStats(char, User*, string_list&) { return MOD_RES_PASSTHRU; }
105 ModResult Module::OnChangeLocalUserHost(User*, const std::string&) { return MOD_RES_PASSTHRU; }
106 ModResult Module::OnChangeLocalUserGECOS(User*, const std::string&) { return MOD_RES_PASSTHRU; }
107 ModResult Module::OnPreTopicChange(User*, Channel*, const std::string&) { return MOD_RES_PASSTHRU; }
108 void Module::OnEvent(Event&) { }
109 void Module::OnRequest(Request&) { }
110 ModResult Module::OnPassCompare(Extensible* ex, const std::string &password, const std::string &input, const std::string& hashtype) { return MOD_RES_PASSTHRU; }
111 void Module::OnGlobalOper(User*) { }
112 void Module::OnPostConnect(User*) { }
113 ModResult Module::OnAddBan(User*, Channel*, const std::string &) { return MOD_RES_PASSTHRU; }
114 ModResult Module::OnDelBan(User*, Channel*, const std::string &) { return MOD_RES_PASSTHRU; }
115 void Module::OnStreamSocketAccept(StreamSocket*, irc::sockets::sockaddrs*, irc::sockets::sockaddrs*) { }
116 int Module::OnStreamSocketWrite(StreamSocket*, std::string&) { return -1; }
117 void Module::OnStreamSocketClose(StreamSocket*) { }
118 void Module::OnStreamSocketConnect(StreamSocket*) { }
119 int Module::OnStreamSocketRead(StreamSocket*, std::string&) { return -1; }
120 void Module::OnUserMessage(User*, void*, int, const std::string&, char, const CUList&) { }
121 void Module::OnUserNotice(User*, void*, int, const std::string&, char, const CUList&) { }
122 void Module::OnRemoteKill(User*, User*, const std::string&, const std::string&) { }
123 void Module::OnUserInvite(User*, User*, Channel*, time_t) { }
124 void Module::OnPostTopicChange(User*, Channel*, const std::string&) { }
125 void Module::OnGetServerDescription(const std::string&, std::string&) { }
126 void Module::OnSyncUser(User*, Module*, void*) { }
127 void Module::OnSyncChannel(Channel*, Module*, void*) { }
128 void Module::OnSyncNetwork(Module*, void*) { }
129 void Module::ProtoSendMode(void*, TargetTypeFlags, void*, const std::vector<std::string>&, const std::vector<TranslateType>&) { }
130 void Module::OnDecodeMetaData(Extensible*, const std::string&, const std::string&) { }
131 void Module::ProtoSendMetaData(void*, Extensible*, const std::string&, const std::string&) { }
132 void Module::OnWallops(User*, const std::string&) { }
133 void Module::OnChangeHost(User*, const std::string&) { }
134 void Module::OnChangeName(User*, const std::string&) { }
135 void Module::OnChangeIdent(User*, const std::string&) { }
136 void Module::OnAddLine(User*, XLine*) { }
137 void Module::OnDelLine(User*, XLine*) { }
138 void Module::OnExpireLine(XLine*) { }
139 void Module::OnCleanup(int, void*) { }
140 ModResult Module::OnChannelPreDelete(Channel*) { return MOD_RES_PASSTHRU; }
141 void Module::OnChannelDelete(Channel*) { }
142 ModResult Module::OnSetAway(User*, const std::string &) { return MOD_RES_PASSTHRU; }
143 ModResult Module::OnUserList(User*, Channel*) { return MOD_RES_PASSTHRU; }
144 ModResult Module::OnWhoisLine(User*, User*, int&, std::string&) { return MOD_RES_PASSTHRU; }
145 void Module::OnBuildNeighborList(User*, UserChanList&, std::map<User*,bool>&) { }
146 void Module::OnGarbageCollect() { }
147 void Module::OnText(User*, void*, int, const std::string&, char, CUList&) { }
148 void Module::OnRunTestSuite() { }
149 void Module::OnNamesListItem(User*, Membership*, std::string&, std::string&) { }
150 ModResult Module::OnNumeric(User*, unsigned int, const std::string&) { return MOD_RES_PASSTHRU; }
151 void Module::OnHookIO(StreamSocket*, ListenSocketBase*) { }
152 void Module::OnSendWhoLine(User*, User*, Channel*, std::string&) { }
153 ModResult Module::OnChannelRestrictionApply(User*, Channel*, const char*) { return MOD_RES_PASSTHRU; }
155 ModuleManager::ModuleManager() : ModCount(0)
159 ModuleManager::~ModuleManager()
163 bool ModuleManager::Attach(Implementation i, Module* mod)
165 if (std::find(EventHandlers[i].begin(), EventHandlers[i].end(), mod) != EventHandlers[i].end())
168 EventHandlers[i].push_back(mod);
172 bool ModuleManager::Detach(Implementation i, Module* mod)
174 EventHandlerIter x = std::find(EventHandlers[i].begin(), EventHandlers[i].end(), mod);
176 if (x == EventHandlers[i].end())
179 EventHandlers[i].erase(x);
183 void ModuleManager::Attach(Implementation* i, Module* mod, size_t sz)
185 for (size_t n = 0; n < sz; ++n)
189 void ModuleManager::DetachAll(Module* mod)
191 for (size_t n = I_BEGIN + 1; n != I_END; ++n)
192 Detach((Implementation)n, mod);
195 bool ModuleManager::SetPriority(Module* mod, Priority s)
197 for (size_t n = I_BEGIN + 1; n != I_END; ++n)
198 SetPriority(mod, (Implementation)n, s);
203 bool ModuleManager::SetPriority(Module* mod, Implementation i, Priority s, Module** modules, size_t sz)
205 /** To change the priority of a module, we first find its position in the vector,
206 * then we find the position of the other modules in the vector that this module
207 * wants to be before/after. We pick off either the first or last of these depending
208 * on which they want, and we make sure our module is *at least* before or after
209 * the first or last of this subset, depending again on the type of priority.
216 /* Locate our module. This is O(n) but it only occurs on module load so we're
217 * not too bothered about it
219 for (size_t x = 0; x != EventHandlers[i].size(); ++x)
221 if (EventHandlers[i][x] == mod)
229 /* Eh? this module doesnt exist, probably trying to set priority on an event
230 * theyre not attached to.
238 case PRIORITY_DONTCARE:
241 /* Module wants to be first, sod everything else */
243 if (prioritizationState != PRIO_STATE_FIRST)
248 /* Module wants to be last. */
250 if (prioritizationState != PRIO_STATE_FIRST)
252 else if (EventHandlers[i].empty())
255 swap_pos = EventHandlers[i].size() - 1;
257 /* Place this module after a set of other modules */
260 /* Find the latest possible position */
263 for (size_t x = 0; x != EventHandlers[i].size(); ++x)
265 for (size_t n = 0; n < sz; ++n)
267 if ((modules[n]) && (EventHandlers[i][x] == modules[n]) && (x >= swap_pos) && (source <= swap_pos))
276 /* Place this module before a set of other modules */
277 case PRIORITY_BEFORE:
279 swap_pos = EventHandlers[i].size() - 1;
281 for (size_t x = 0; x != EventHandlers[i].size(); ++x)
283 for (size_t n = 0; n < sz; ++n)
285 if ((modules[n]) && (EventHandlers[i][x] == modules[n]) && (x <= swap_pos) && (source >= swap_pos))
296 /* Do we need to swap? */
297 if (swap && (swap_pos != source))
299 // We are going to change positions; we'll need to run again to verify all requirements
300 if (prioritizationState == PRIO_STATE_LAST)
301 prioritizationState = PRIO_STATE_AGAIN;
302 /* Suggestion from Phoenix, "shuffle" the modules to better retain call order */
305 if (source > swap_pos)
308 for (unsigned int j = source; j != swap_pos; j += incrmnt)
310 if (( j + incrmnt > EventHandlers[i].size() - 1) || (j + incrmnt < 0))
313 std::swap(EventHandlers[i][j], EventHandlers[i][j+incrmnt]);
320 std::string& ModuleManager::LastError()
322 return LastModuleError;
325 bool ModuleManager::Load(const char* filename)
327 /* Do we have a glob pattern in the filename?
328 * The user wants to load multiple modules which
331 if (strchr(filename,'*') || (strchr(filename,'?')))
334 DIR* library = opendir(ServerInstance->Config->ModPath.c_str());
337 /* Try and locate and load all modules matching the pattern */
338 dirent* entry = NULL;
339 while (0 != (entry = readdir(library)))
341 if (InspIRCd::Match(entry->d_name, filename, ascii_case_insensitive_map))
343 if (!this->Load(entry->d_name))
349 /* Loadmodule will now return false if any one of the modules failed
350 * to load (but wont abort when it encounters a bad one) and when 1 or
351 * more modules were actually loaded.
353 return (n_match > 0 ? false : true);
356 char modfile[MAXBUF];
357 snprintf(modfile,MAXBUF,"%s/%s",ServerInstance->Config->ModPath.c_str(),filename);
358 std::string filename_str = filename;
360 if (!ServerConfig::FileExists(modfile))
362 LastModuleError = "Module file could not be found: " + filename_str;
363 ServerInstance->Logs->Log("MODULE", DEFAULT, LastModuleError);
367 if (Modules.find(filename_str) != Modules.end())
369 LastModuleError = "Module " + filename_str + " is already loaded, cannot load a module twice!";
370 ServerInstance->Logs->Log("MODULE", DEFAULT, LastModuleError);
374 Module* newmod = NULL;
375 DLLManager* newhandle = new DLLManager(modfile);
379 newmod = newhandle->callInit();
383 newmod->ModuleSourceFile = filename_str;
384 newmod->ModuleDLLManager = newhandle;
385 Version v = newmod->GetVersion();
387 ServerInstance->Logs->Log("MODULE", DEFAULT,"New module introduced: %s (Module version %s)%s",
388 filename, v.version.c_str(), (!(v.Flags & VF_VENDOR) ? " [3rd Party]" : " [Vendor]"));
390 Modules[filename_str] = newmod;
394 LastModuleError = "Unable to load " + filename_str + ": " + newhandle->LastError();
395 ServerInstance->Logs->Log("MODULE", DEFAULT, LastModuleError);
400 catch (CoreException& modexcept)
402 // failure in module constructor
405 LastModuleError = "Unable to load " + filename_str + ": " + modexcept.GetReason();
406 ServerInstance->Logs->Log("MODULE", DEFAULT, LastModuleError);
411 FOREACH_MOD(I_OnLoadModule,OnLoadModule(newmod, filename_str));
413 /* We give every module a chance to re-prioritize when we introduce a new one,
414 * not just the one thats loading, as the new module could affect the preference
417 for(int tries = 0; tries < 20; tries++)
419 prioritizationState = tries > 0 ? PRIO_STATE_LAST : PRIO_STATE_FIRST;
420 for (std::map<std::string, Module*>::iterator n = Modules.begin(); n != Modules.end(); ++n)
421 n->second->Prioritize();
423 if (prioritizationState == PRIO_STATE_LAST)
426 ServerInstance->Logs->Log("MODULE", DEFAULT, "Hook priority dependency loop detected while loading " + filename_str);
429 ServerInstance->BuildISupport();
433 bool ModuleManager::Unload(const char* filename)
435 std::string filename_str(filename);
436 std::map<std::string, Module*>::iterator modfind = Modules.find(filename);
438 if (modfind != Modules.end())
440 if (modfind->second->GetVersion().Flags & VF_STATIC)
442 LastModuleError = "Module " + filename_str + " not unloadable (marked static)";
443 ServerInstance->Logs->Log("MODULE", DEFAULT, LastModuleError);
446 std::pair<int,std::string> intercount = GetInterfaceInstanceCount(modfind->second);
447 if (intercount.first > 0)
449 LastModuleError = "Failed to unload module " + filename_str + ", being used by " + ConvToStr(intercount.first) + " other(s) via interface '" + intercount.second + "'";
450 ServerInstance->Logs->Log("MODULE", DEFAULT, LastModuleError);
454 std::vector<ExtensionItem*> items = Extensible::BeginUnregister(modfind->second);
455 /* Give the module a chance to tidy out all its metadata */
456 for (chan_hash::iterator c = ServerInstance->chanlist->begin(); c != ServerInstance->chanlist->end(); c++)
458 modfind->second->OnCleanup(TYPE_CHANNEL,c->second);
459 c->second->doUnhookExtensions(items);
460 const UserMembList* users = c->second->GetUsers();
461 for(UserMembCIter mi = users->begin(); mi != users->end(); mi++)
462 mi->second->doUnhookExtensions(items);
464 for (user_hash::iterator u = ServerInstance->Users->clientlist->begin(); u != ServerInstance->Users->clientlist->end(); u++)
466 modfind->second->OnCleanup(TYPE_USER,u->second);
467 u->second->doUnhookExtensions(items);
470 /* Tidy up any dangling resolvers */
471 ServerInstance->Res->CleanResolvers(modfind->second);
473 FOREACH_MOD(I_OnUnloadModule,OnUnloadModule(modfind->second, modfind->first));
475 this->DetachAll(modfind->second);
477 ServerInstance->Parser->RemoveCommands(modfind->second);
478 ServerInstance->Modes->RemoveModes(modfind->second);
480 ServerInstance->GlobalCulls.AddItem(modfind->second);
481 Modules.erase(modfind);
483 ServerInstance->Logs->Log("MODULE", DEFAULT,"Module %s unloaded",filename);
485 ServerInstance->BuildISupport();
489 LastModuleError = "Module " + filename_str + " is not loaded, cannot unload it!";
490 ServerInstance->Logs->Log("MODULE", DEFAULT, LastModuleError);
494 /* We must load the modules AFTER initializing the socket engine, now */
495 void ModuleManager::LoadAll()
497 char configToken[MAXBUF];
500 printf("\nLoading core commands");
503 DIR* library = opendir(ServerInstance->Config->ModPath.c_str());
506 dirent* entry = NULL;
507 while (0 != (entry = readdir(library)))
509 if (InspIRCd::Match(entry->d_name, "cmd_*.so", ascii_case_insensitive_map))
514 if (!Load(entry->d_name))
516 ServerInstance->Logs->Log("MODULE", DEFAULT, this->LastError());
517 printf_c("\n[\033[1;31m*\033[0m] %s\n\n", this->LastError().c_str());
518 ServerInstance->Exit(EXIT_STATUS_MODULE);
526 for(int count = 0; count < ServerInstance->Config->ConfValueEnum("module"); count++)
528 ServerInstance->Config->ConfValue("module", "name", count, configToken, MAXBUF);
529 printf_c("[\033[1;32m*\033[0m] Loading module:\t\033[1;32m%s\033[0m\n",configToken);
531 if (!this->Load(configToken))
533 ServerInstance->Logs->Log("MODULE", DEFAULT, this->LastError());
534 printf_c("\n[\033[1;31m*\033[0m] %s\n\n", this->LastError().c_str());
535 ServerInstance->Exit(EXIT_STATUS_MODULE);
540 bool ModuleManager::PublishFeature(const std::string &FeatureName, Module* Mod)
542 if (Features.find(FeatureName) == Features.end())
544 Features[FeatureName] = Mod;
550 bool ModuleManager::UnpublishFeature(const std::string &FeatureName)
552 featurelist::iterator iter = Features.find(FeatureName);
554 if (iter == Features.end())
557 Features.erase(iter);
561 Module* ModuleManager::FindFeature(const std::string &FeatureName)
563 featurelist::iterator iter = Features.find(FeatureName);
565 if (iter == Features.end())
571 bool ModuleManager::PublishInterface(const std::string &InterfaceName, Module* Mod)
573 interfacelist::iterator iter = Interfaces.find(InterfaceName);
575 if (iter == Interfaces.end())
579 Interfaces[InterfaceName] = std::make_pair(0, ml);
583 iter->second.second.push_back(Mod);
588 bool ModuleManager::UnpublishInterface(const std::string &InterfaceName, Module* Mod)
590 interfacelist::iterator iter = Interfaces.find(InterfaceName);
592 if (iter == Interfaces.end())
595 for (modulelist::iterator x = iter->second.second.begin(); x != iter->second.second.end(); x++)
599 iter->second.second.erase(x);
600 if (iter->second.second.empty())
601 Interfaces.erase(InterfaceName);
608 modulelist* ModuleManager::FindInterface(const std::string &InterfaceName)
610 interfacelist::iterator iter = Interfaces.find(InterfaceName);
611 if (iter == Interfaces.end())
614 return &(iter->second.second);
617 bool ModuleManager::ModuleHasInterface(Module* mod, const std::string& InterfaceName)
619 interfacelist::iterator iter = Interfaces.find(InterfaceName);
620 if (iter == Interfaces.end())
624 modulelist& ml = iter->second.second;
625 modulelist::iterator mi = std::find(ml.begin(), ml.end(), mod);
626 return (mi != ml.end());
630 void ModuleManager::UseInterface(const std::string &InterfaceName)
632 interfacelist::iterator iter = Interfaces.find(InterfaceName);
633 if (iter != Interfaces.end())
634 iter->second.first++;
638 void ModuleManager::DoneWithInterface(const std::string &InterfaceName)
640 interfacelist::iterator iter = Interfaces.find(InterfaceName);
641 if (iter != Interfaces.end())
642 iter->second.first--;
645 std::pair<int,std::string> ModuleManager::GetInterfaceInstanceCount(Module* m)
647 for (interfacelist::iterator iter = Interfaces.begin(); iter != Interfaces.end(); iter++)
649 for (modulelist::iterator x = iter->second.second.begin(); x != iter->second.second.end(); x++)
653 return std::make_pair(iter->second.first, iter->first);
657 return std::make_pair(0, "");
660 const std::string& ModuleManager::GetModuleName(Module* m)
662 static std::string nothing;
664 for (std::map<std::string, Module*>::iterator n = Modules.begin(); n != Modules.end(); ++n)
673 /* This is ugly, yes, but hash_map's arent designed to be
674 * addressed in this manner, and this is a bit of a kludge.
675 * Luckily its a specialist function and rarely used by
676 * many modules (in fact, it was specially created to make
677 * m_safelist possible, initially).
680 Channel* InspIRCd::GetChannelIndex(long index)
683 for (chan_hash::iterator n = this->chanlist->begin(); n != this->chanlist->end(); n++, target++)
691 CmdResult InspIRCd::CallCommandHandler(const std::string &commandname, const std::vector<std::string>& parameters, User* user)
693 return this->Parser->CallHandler(commandname, parameters, user);
696 bool InspIRCd::IsValidModuleCommand(const std::string &commandname, int pcnt, User* user)
698 return this->Parser->IsValidCommand(commandname, pcnt, user);
701 void InspIRCd::AddCommand(Command *f)
703 if (!this->Parser->CreateCommand(f))
705 ModuleException err("Command "+std::string(f->command)+" already exists.");
710 void InspIRCd::SendMode(const std::vector<std::string>& parameters, User *user)
712 this->Modes->Process(parameters, user);
715 void InspIRCd::DumpText(User* user, const std::string &text)
723 PI->PushToClient(user, text);
727 void InspIRCd::DumpText(User* user, const char *text, ...)
732 va_start(argsPtr, text);
733 vsnprintf(line, MAXBUF, text, argsPtr);
736 DumpText(user, std::string(line));
739 void InspIRCd::DumpText(User* user, const std::string &LinePrefix, std::stringstream &TextStream)
742 int start_pos = LinePrefix.length();
744 memcpy(line, LinePrefix.data(), pos);
746 while (TextStream >> Word)
748 int len = Word.length();
749 if (pos + len + 12 > MAXBUF)
752 DumpText(user, std::string(line));
756 memcpy(line + pos + 1, Word.data(), len);
760 DumpText(user, std::string(line));
763 bool InspIRCd::AddResolver(Resolver* r, bool cached)
766 return this->Res->AddResolverClass(r);
769 r->TriggerCachedResult();
775 Module* ModuleManager::Find(const std::string &name)
777 std::map<std::string, Module*>::iterator modfind = Modules.find(name);
779 if (modfind == Modules.end())
782 return modfind->second;
785 const std::vector<std::string> ModuleManager::GetAllModuleNames(int filter)
787 std::vector<std::string> retval;
788 for (std::map<std::string, Module*>::iterator x = Modules.begin(); x != Modules.end(); ++x)
789 if (!filter || (x->second->GetVersion().Flags & filter))
790 retval.push_back(x->first);
794 ConfigReader::ConfigReader()
800 ConfigReader::~ConfigReader()
805 std::string ConfigReader::ReadValue(const std::string &tag, const std::string &name, const std::string &default_value, int index, bool allow_linefeeds)
807 /* Don't need to strlcpy() tag and name anymore, ReadConf() takes const char* */
810 if (!ServerInstance->Config->ConfValue(tag, name, default_value, index, result, allow_linefeeds))
812 this->error = CONF_VALUE_NOT_FOUND;
817 std::string ConfigReader::ReadValue(const std::string &tag, const std::string &name, int index, bool allow_linefeeds)
819 return ReadValue(tag, name, "", index, allow_linefeeds);
822 bool ConfigReader::ReadFlag(const std::string &tag, const std::string &name, const std::string &default_value, int index)
824 return ServerInstance->Config->ConfValueBool(tag, name, default_value, index);
827 bool ConfigReader::ReadFlag(const std::string &tag, const std::string &name, int index)
829 return ReadFlag(tag, name, "", index);
833 int ConfigReader::ReadInteger(const std::string &tag, const std::string &name, const std::string &default_value, int index, bool need_positive)
837 if(!ServerInstance->Config->ConfValueInteger(tag, name, default_value, index, result))
839 this->error = CONF_VALUE_NOT_FOUND;
843 if ((need_positive) && (result < 0))
845 this->error = CONF_INT_NEGATIVE;
852 int ConfigReader::ReadInteger(const std::string &tag, const std::string &name, int index, bool need_positive)
854 return ReadInteger(tag, name, "", index, need_positive);
857 long ConfigReader::GetError()
859 long olderr = this->error;
864 int ConfigReader::Enumerate(const std::string &tag)
866 return ServerInstance->Config->ConfValueEnum(tag);
869 int ConfigReader::EnumerateValues(const std::string &tag, int index)
871 return ServerInstance->Config->ConfVarEnum(tag, index);
874 FileReader::FileReader(const std::string &filename)
879 FileReader::FileReader()
883 std::string FileReader::Contents()
886 for (file_cache::iterator a = this->fc.begin(); a != this->fc.end(); a++)
894 unsigned long FileReader::ContentSize()
896 return this->contentsize;
899 void FileReader::CalcSize()
902 for (file_cache::iterator a = this->fc.begin(); a != this->fc.end(); a++)
903 n += (a->length() + 2);
904 this->contentsize = n;
907 void FileReader::LoadFile(const std::string &filename)
911 if (ServerInstance->Config->ReadFile(c,filename.c_str()))
919 FileReader::~FileReader()
923 bool FileReader::Exists()
925 return (!(fc.size() == 0));
928 std::string FileReader::GetLine(int x)
930 if ((x<0) || ((unsigned)x>fc.size()))
935 int FileReader::FileSize()