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(ModuleDLLFactory);
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&) { }
154 ModuleManager::ModuleManager() : ModCount(0)
158 ModuleManager::~ModuleManager()
162 bool ModuleManager::Attach(Implementation i, Module* mod)
164 if (std::find(EventHandlers[i].begin(), EventHandlers[i].end(), mod) != EventHandlers[i].end())
167 EventHandlers[i].push_back(mod);
171 bool ModuleManager::Detach(Implementation i, Module* mod)
173 EventHandlerIter x = std::find(EventHandlers[i].begin(), EventHandlers[i].end(), mod);
175 if (x == EventHandlers[i].end())
178 EventHandlers[i].erase(x);
182 void ModuleManager::Attach(Implementation* i, Module* mod, size_t sz)
184 for (size_t n = 0; n < sz; ++n)
188 void ModuleManager::DetachAll(Module* mod)
190 for (size_t n = I_BEGIN + 1; n != I_END; ++n)
191 Detach((Implementation)n, mod);
194 bool ModuleManager::SetPriority(Module* mod, Priority s)
196 for (size_t n = I_BEGIN + 1; n != I_END; ++n)
197 SetPriority(mod, (Implementation)n, s);
202 bool ModuleManager::SetPriority(Module* mod, Implementation i, Priority s, Module** modules, size_t sz)
204 /** To change the priority of a module, we first find its position in the vector,
205 * then we find the position of the other modules in the vector that this module
206 * wants to be before/after. We pick off either the first or last of these depending
207 * on which they want, and we make sure our module is *at least* before or after
208 * the first or last of this subset, depending again on the type of priority.
215 /* Locate our module. This is O(n) but it only occurs on module load so we're
216 * not too bothered about it
218 for (size_t x = 0; x != EventHandlers[i].size(); ++x)
220 if (EventHandlers[i][x] == mod)
228 /* Eh? this module doesnt exist, probably trying to set priority on an event
229 * theyre not attached to.
237 case PRIORITY_DONTCARE:
240 /* Module wants to be first, sod everything else */
242 if (prioritizationState != PRIO_STATE_FIRST)
247 /* Module wants to be last. */
249 if (prioritizationState != PRIO_STATE_FIRST)
251 else if (EventHandlers[i].empty())
254 swap_pos = EventHandlers[i].size() - 1;
256 /* Place this module after a set of other modules */
259 /* Find the latest possible position */
262 for (size_t x = 0; x != EventHandlers[i].size(); ++x)
264 for (size_t n = 0; n < sz; ++n)
266 if ((modules[n]) && (EventHandlers[i][x] == modules[n]) && (x >= swap_pos) && (source <= swap_pos))
275 /* Place this module before a set of other modules */
276 case PRIORITY_BEFORE:
278 swap_pos = EventHandlers[i].size() - 1;
280 for (size_t x = 0; x != EventHandlers[i].size(); ++x)
282 for (size_t n = 0; n < sz; ++n)
284 if ((modules[n]) && (EventHandlers[i][x] == modules[n]) && (x <= swap_pos) && (source >= swap_pos))
295 /* Do we need to swap? */
296 if (swap && (swap_pos != source))
298 // We are going to change positions; we'll need to run again to verify all requirements
299 if (prioritizationState == PRIO_STATE_LAST)
300 prioritizationState = PRIO_STATE_AGAIN;
301 /* Suggestion from Phoenix, "shuffle" the modules to better retain call order */
304 if (source > swap_pos)
307 for (unsigned int j = source; j != swap_pos; j += incrmnt)
309 if (( j + incrmnt > EventHandlers[i].size() - 1) || (j + incrmnt < 0))
312 std::swap(EventHandlers[i][j], EventHandlers[i][j+incrmnt]);
319 std::string& ModuleManager::LastError()
321 return LastModuleError;
324 bool ModuleManager::Load(const char* filename)
326 /* Do we have a glob pattern in the filename?
327 * The user wants to load multiple modules which
330 if (strchr(filename,'*') || (strchr(filename,'?')))
333 DIR* library = opendir(ServerInstance->Config->ModPath.c_str());
336 /* Try and locate and load all modules matching the pattern */
337 dirent* entry = NULL;
338 while (0 != (entry = readdir(library)))
340 if (InspIRCd::Match(entry->d_name, filename, ascii_case_insensitive_map))
342 if (!this->Load(entry->d_name))
348 /* Loadmodule will now return false if any one of the modules failed
349 * to load (but wont abort when it encounters a bad one) and when 1 or
350 * more modules were actually loaded.
352 return (n_match > 0 ? false : true);
355 char modfile[MAXBUF];
356 snprintf(modfile,MAXBUF,"%s/%s",ServerInstance->Config->ModPath.c_str(),filename);
357 std::string filename_str = filename;
359 if (!ServerConfig::FileExists(modfile))
361 LastModuleError = "Module file could not be found: " + filename_str;
362 ServerInstance->Logs->Log("MODULE", DEFAULT, LastModuleError);
366 if (Modules.find(filename_str) != Modules.end())
368 LastModuleError = "Module " + filename_str + " is already loaded, cannot load a module twice!";
369 ServerInstance->Logs->Log("MODULE", DEFAULT, LastModuleError);
373 Module* newmod = NULL;
374 DLLFactory* newhandle = NULL;
378 /* This will throw a CoreException if there's a problem loading
379 * the module file or getting a pointer to the init_module symbol.
381 newhandle = new DLLFactory(modfile, "init_module");
382 if (newhandle->init_func)
383 newmod = newhandle->init_func();
387 newmod->ModuleSourceFile = filename_str;
388 newmod->ModuleDLLFactory = newhandle;
389 Version v = newmod->GetVersion();
391 ServerInstance->Logs->Log("MODULE", DEFAULT,"New module introduced: %s (Module version %s)%s", filename, v.version.c_str(), (!(v.Flags & VF_VENDOR) ? " [3rd Party]" : " [Vendor]"));
393 Modules[filename_str] = newmod;
398 LastModuleError = "Unable to load " + filename_str + ": Probably missing init_module() entrypoint, but dlsym() didn't notice a problem";
399 ServerInstance->Logs->Log("MODULE", DEFAULT, LastModuleError);
403 /** XXX: Is there anything we can do about this mess? -- Brain
404 * Yeah, don't use exceptions without RAII. -- Daniel
406 catch (LoadModuleException& modexcept)
413 LastModuleError = "Unable to load " + filename_str + ": Error when loading: " + modexcept.GetReason();
414 ServerInstance->Logs->Log("MODULE", DEFAULT, LastModuleError);
417 catch (FindSymbolException& modexcept)
424 LastModuleError = "Unable to load " + filename_str + ": Error finding symbol: " + modexcept.GetReason();
425 ServerInstance->Logs->Log("MODULE", DEFAULT, LastModuleError);
428 catch (CoreException& modexcept)
435 LastModuleError = "Unable to load " + filename_str + ": " + modexcept.GetReason();
436 ServerInstance->Logs->Log("MODULE", DEFAULT, LastModuleError);
441 FOREACH_MOD(I_OnLoadModule,OnLoadModule(newmod, filename_str));
443 /* We give every module a chance to re-prioritize when we introduce a new one,
444 * not just the one thats loading, as the new module could affect the preference
447 for(int tries = 0; tries < 20; tries++)
449 prioritizationState = tries > 0 ? PRIO_STATE_LAST : PRIO_STATE_FIRST;
450 for (std::map<std::string, Module*>::iterator n = Modules.begin(); n != Modules.end(); ++n)
451 n->second->Prioritize();
453 if (prioritizationState == PRIO_STATE_LAST)
456 ServerInstance->Logs->Log("MODULE", DEFAULT, "Hook priority dependency loop detected while loading " + filename_str);
459 ServerInstance->BuildISupport();
463 bool ModuleManager::Unload(const char* filename)
465 std::string filename_str(filename);
466 std::map<std::string, Module*>::iterator modfind = Modules.find(filename);
468 if (modfind != Modules.end())
470 if (modfind->second->GetVersion().Flags & VF_STATIC)
472 LastModuleError = "Module " + filename_str + " not unloadable (marked static)";
473 ServerInstance->Logs->Log("MODULE", DEFAULT, LastModuleError);
476 std::pair<int,std::string> intercount = GetInterfaceInstanceCount(modfind->second);
477 if (intercount.first > 0)
479 LastModuleError = "Failed to unload module " + filename_str + ", being used by " + ConvToStr(intercount.first) + " other(s) via interface '" + intercount.second + "'";
480 ServerInstance->Logs->Log("MODULE", DEFAULT, LastModuleError);
484 std::vector<ExtensionItem*> items = Extensible::BeginUnregister(modfind->second);
485 /* Give the module a chance to tidy out all its metadata */
486 for (chan_hash::iterator c = ServerInstance->chanlist->begin(); c != ServerInstance->chanlist->end(); c++)
488 modfind->second->OnCleanup(TYPE_CHANNEL,c->second);
489 c->second->doUnhookExtensions(items);
490 const UserMembList* users = c->second->GetUsers();
491 for(UserMembCIter mi = users->begin(); mi != users->end(); mi++)
492 mi->second->doUnhookExtensions(items);
494 for (user_hash::iterator u = ServerInstance->Users->clientlist->begin(); u != ServerInstance->Users->clientlist->end(); u++)
496 modfind->second->OnCleanup(TYPE_USER,u->second);
497 u->second->doUnhookExtensions(items);
500 /* Tidy up any dangling resolvers */
501 ServerInstance->Res->CleanResolvers(modfind->second);
503 FOREACH_MOD(I_OnUnloadModule,OnUnloadModule(modfind->second, modfind->first));
505 this->DetachAll(modfind->second);
507 ServerInstance->Parser->RemoveCommands(modfind->second);
508 ServerInstance->Modes->RemoveModes(modfind->second);
510 ServerInstance->GlobalCulls.AddItem(modfind->second);
511 Modules.erase(modfind);
513 ServerInstance->Logs->Log("MODULE", DEFAULT,"Module %s unloaded",filename);
515 ServerInstance->BuildISupport();
519 LastModuleError = "Module " + filename_str + " is not loaded, cannot unload it!";
520 ServerInstance->Logs->Log("MODULE", DEFAULT, LastModuleError);
524 /* We must load the modules AFTER initializing the socket engine, now */
525 void ModuleManager::LoadAll()
527 char configToken[MAXBUF];
530 printf("\nLoading core commands");
533 DIR* library = opendir(ServerInstance->Config->ModPath.c_str());
536 dirent* entry = NULL;
537 while (0 != (entry = readdir(library)))
539 if (InspIRCd::Match(entry->d_name, "cmd_*.so", ascii_case_insensitive_map))
544 if (!Load(entry->d_name))
546 ServerInstance->Logs->Log("MODULE", DEFAULT, this->LastError());
547 printf_c("\n[\033[1;31m*\033[0m] %s\n\n", this->LastError().c_str());
548 ServerInstance->Exit(EXIT_STATUS_MODULE);
556 for(int count = 0; count < ServerInstance->Config->ConfValueEnum("module"); count++)
558 ServerInstance->Config->ConfValue("module", "name", count, configToken, MAXBUF);
559 printf_c("[\033[1;32m*\033[0m] Loading module:\t\033[1;32m%s\033[0m\n",configToken);
561 if (!this->Load(configToken))
563 ServerInstance->Logs->Log("MODULE", DEFAULT, this->LastError());
564 printf_c("\n[\033[1;31m*\033[0m] %s\n\n", this->LastError().c_str());
565 ServerInstance->Exit(EXIT_STATUS_MODULE);
570 bool ModuleManager::PublishFeature(const std::string &FeatureName, Module* Mod)
572 if (Features.find(FeatureName) == Features.end())
574 Features[FeatureName] = Mod;
580 bool ModuleManager::UnpublishFeature(const std::string &FeatureName)
582 featurelist::iterator iter = Features.find(FeatureName);
584 if (iter == Features.end())
587 Features.erase(iter);
591 Module* ModuleManager::FindFeature(const std::string &FeatureName)
593 featurelist::iterator iter = Features.find(FeatureName);
595 if (iter == Features.end())
601 bool ModuleManager::PublishInterface(const std::string &InterfaceName, Module* Mod)
603 interfacelist::iterator iter = Interfaces.find(InterfaceName);
605 if (iter == Interfaces.end())
609 Interfaces[InterfaceName] = std::make_pair(0, ml);
613 iter->second.second.push_back(Mod);
618 bool ModuleManager::UnpublishInterface(const std::string &InterfaceName, Module* Mod)
620 interfacelist::iterator iter = Interfaces.find(InterfaceName);
622 if (iter == Interfaces.end())
625 for (modulelist::iterator x = iter->second.second.begin(); x != iter->second.second.end(); x++)
629 iter->second.second.erase(x);
630 if (iter->second.second.empty())
631 Interfaces.erase(InterfaceName);
638 modulelist* ModuleManager::FindInterface(const std::string &InterfaceName)
640 interfacelist::iterator iter = Interfaces.find(InterfaceName);
641 if (iter == Interfaces.end())
644 return &(iter->second.second);
647 bool ModuleManager::ModuleHasInterface(Module* mod, const std::string& InterfaceName)
649 interfacelist::iterator iter = Interfaces.find(InterfaceName);
650 if (iter == Interfaces.end())
654 modulelist& ml = iter->second.second;
655 modulelist::iterator mi = std::find(ml.begin(), ml.end(), mod);
656 return (mi != ml.end());
660 void ModuleManager::UseInterface(const std::string &InterfaceName)
662 interfacelist::iterator iter = Interfaces.find(InterfaceName);
663 if (iter != Interfaces.end())
664 iter->second.first++;
668 void ModuleManager::DoneWithInterface(const std::string &InterfaceName)
670 interfacelist::iterator iter = Interfaces.find(InterfaceName);
671 if (iter != Interfaces.end())
672 iter->second.first--;
675 std::pair<int,std::string> ModuleManager::GetInterfaceInstanceCount(Module* m)
677 for (interfacelist::iterator iter = Interfaces.begin(); iter != Interfaces.end(); iter++)
679 for (modulelist::iterator x = iter->second.second.begin(); x != iter->second.second.end(); x++)
683 return std::make_pair(iter->second.first, iter->first);
687 return std::make_pair(0, "");
690 const std::string& ModuleManager::GetModuleName(Module* m)
692 static std::string nothing;
694 for (std::map<std::string, Module*>::iterator n = Modules.begin(); n != Modules.end(); ++n)
703 /* This is ugly, yes, but hash_map's arent designed to be
704 * addressed in this manner, and this is a bit of a kludge.
705 * Luckily its a specialist function and rarely used by
706 * many modules (in fact, it was specially created to make
707 * m_safelist possible, initially).
710 Channel* InspIRCd::GetChannelIndex(long index)
713 for (chan_hash::iterator n = this->chanlist->begin(); n != this->chanlist->end(); n++, target++)
721 CmdResult InspIRCd::CallCommandHandler(const std::string &commandname, const std::vector<std::string>& parameters, User* user)
723 return this->Parser->CallHandler(commandname, parameters, user);
726 bool InspIRCd::IsValidModuleCommand(const std::string &commandname, int pcnt, User* user)
728 return this->Parser->IsValidCommand(commandname, pcnt, user);
731 void InspIRCd::AddCommand(Command *f)
733 if (!this->Parser->CreateCommand(f))
735 ModuleException err("Command "+std::string(f->command)+" already exists.");
740 void InspIRCd::SendMode(const std::vector<std::string>& parameters, User *user)
742 this->Modes->Process(parameters, user);
745 void InspIRCd::DumpText(User* user, const std::string &text)
753 PI->PushToClient(user, text);
757 void InspIRCd::DumpText(User* user, const char *text, ...)
762 va_start(argsPtr, text);
763 vsnprintf(line, MAXBUF, text, argsPtr);
766 DumpText(user, std::string(line));
769 void InspIRCd::DumpText(User* user, const std::string &LinePrefix, std::stringstream &TextStream)
772 int start_pos = LinePrefix.length();
774 memcpy(line, LinePrefix.data(), pos);
776 while (TextStream >> Word)
778 int len = Word.length();
779 if (pos + len + 12 > MAXBUF)
782 DumpText(user, std::string(line));
786 memcpy(line + pos + 1, Word.data(), len);
790 DumpText(user, std::string(line));
793 bool InspIRCd::AddResolver(Resolver* r, bool cached)
796 return this->Res->AddResolverClass(r);
799 r->TriggerCachedResult();
805 Module* ModuleManager::Find(const std::string &name)
807 std::map<std::string, Module*>::iterator modfind = Modules.find(name);
809 if (modfind == Modules.end())
812 return modfind->second;
815 const std::vector<std::string> ModuleManager::GetAllModuleNames(int filter)
817 std::vector<std::string> retval;
818 for (std::map<std::string, Module*>::iterator x = Modules.begin(); x != Modules.end(); ++x)
819 if (!filter || (x->second->GetVersion().Flags & filter))
820 retval.push_back(x->first);
824 ConfigReader::ConfigReader()
830 ConfigReader::~ConfigReader()
835 std::string ConfigReader::ReadValue(const std::string &tag, const std::string &name, const std::string &default_value, int index, bool allow_linefeeds)
837 /* Don't need to strlcpy() tag and name anymore, ReadConf() takes const char* */
840 if (!ServerInstance->Config->ConfValue(tag, name, default_value, index, result, allow_linefeeds))
842 this->error = CONF_VALUE_NOT_FOUND;
847 std::string ConfigReader::ReadValue(const std::string &tag, const std::string &name, int index, bool allow_linefeeds)
849 return ReadValue(tag, name, "", index, allow_linefeeds);
852 bool ConfigReader::ReadFlag(const std::string &tag, const std::string &name, const std::string &default_value, int index)
854 return ServerInstance->Config->ConfValueBool(tag, name, default_value, index);
857 bool ConfigReader::ReadFlag(const std::string &tag, const std::string &name, int index)
859 return ReadFlag(tag, name, "", index);
863 int ConfigReader::ReadInteger(const std::string &tag, const std::string &name, const std::string &default_value, int index, bool need_positive)
867 if(!ServerInstance->Config->ConfValueInteger(tag, name, default_value, index, result))
869 this->error = CONF_VALUE_NOT_FOUND;
873 if ((need_positive) && (result < 0))
875 this->error = CONF_INT_NEGATIVE;
882 int ConfigReader::ReadInteger(const std::string &tag, const std::string &name, int index, bool need_positive)
884 return ReadInteger(tag, name, "", index, need_positive);
887 long ConfigReader::GetError()
889 long olderr = this->error;
894 int ConfigReader::Enumerate(const std::string &tag)
896 return ServerInstance->Config->ConfValueEnum(tag);
899 int ConfigReader::EnumerateValues(const std::string &tag, int index)
901 return ServerInstance->Config->ConfVarEnum(tag, index);
904 FileReader::FileReader(const std::string &filename)
909 FileReader::FileReader()
913 std::string FileReader::Contents()
916 for (file_cache::iterator a = this->fc.begin(); a != this->fc.end(); a++)
924 unsigned long FileReader::ContentSize()
926 return this->contentsize;
929 void FileReader::CalcSize()
932 for (file_cache::iterator a = this->fc.begin(); a != this->fc.end(); a++)
933 n += (a->length() + 2);
934 this->contentsize = n;
937 void FileReader::LoadFile(const std::string &filename)
941 if (ServerInstance->Config->ReadFile(c,filename.c_str()))
949 FileReader::~FileReader()
953 bool FileReader::Exists()
955 return (!(fc.size() == 0));
958 std::string FileReader::GetLine(int x)
960 if ((x<0) || ((unsigned)x>fc.size()))
965 int FileReader::FileSize()