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;
455 ServerInstance->Extensions.BeginUnregister(modfind->second, items);
456 /* Give the module a chance to tidy out all its metadata */
457 for (chan_hash::iterator c = ServerInstance->chanlist->begin(); c != ServerInstance->chanlist->end(); c++)
459 modfind->second->OnCleanup(TYPE_CHANNEL,c->second);
460 c->second->doUnhookExtensions(items);
461 const UserMembList* users = c->second->GetUsers();
462 for(UserMembCIter mi = users->begin(); mi != users->end(); mi++)
463 mi->second->doUnhookExtensions(items);
465 for (user_hash::iterator u = ServerInstance->Users->clientlist->begin(); u != ServerInstance->Users->clientlist->end(); u++)
467 modfind->second->OnCleanup(TYPE_USER,u->second);
468 u->second->doUnhookExtensions(items);
471 /* Tidy up any dangling resolvers */
472 ServerInstance->Res->CleanResolvers(modfind->second);
474 FOREACH_MOD(I_OnUnloadModule,OnUnloadModule(modfind->second, modfind->first));
476 this->DetachAll(modfind->second);
478 ServerInstance->GlobalCulls.AddItem(modfind->second);
479 Modules.erase(modfind);
481 ServerInstance->Logs->Log("MODULE", DEFAULT,"Module %s unloaded",filename);
483 ServerInstance->BuildISupport();
487 LastModuleError = "Module " + filename_str + " is not loaded, cannot unload it!";
488 ServerInstance->Logs->Log("MODULE", DEFAULT, LastModuleError);
492 /* We must load the modules AFTER initializing the socket engine, now */
493 void ModuleManager::LoadAll()
495 char configToken[MAXBUF];
498 printf("\nLoading core commands");
501 DIR* library = opendir(ServerInstance->Config->ModPath.c_str());
504 dirent* entry = NULL;
505 while (0 != (entry = readdir(library)))
507 if (InspIRCd::Match(entry->d_name, "cmd_*.so", ascii_case_insensitive_map))
512 if (!Load(entry->d_name))
514 ServerInstance->Logs->Log("MODULE", DEFAULT, this->LastError());
515 printf_c("\n[\033[1;31m*\033[0m] %s\n\n", this->LastError().c_str());
516 ServerInstance->Exit(EXIT_STATUS_MODULE);
524 for(int count = 0; count < ServerInstance->Config->ConfValueEnum("module"); count++)
526 ServerInstance->Config->ConfValue("module", "name", count, configToken, MAXBUF);
527 printf_c("[\033[1;32m*\033[0m] Loading module:\t\033[1;32m%s\033[0m\n",configToken);
529 if (!this->Load(configToken))
531 ServerInstance->Logs->Log("MODULE", DEFAULT, this->LastError());
532 printf_c("\n[\033[1;31m*\033[0m] %s\n\n", this->LastError().c_str());
533 ServerInstance->Exit(EXIT_STATUS_MODULE);
538 bool ModuleManager::PublishFeature(const std::string &FeatureName, Module* Mod)
540 if (Features.find(FeatureName) == Features.end())
542 Features[FeatureName] = Mod;
548 bool ModuleManager::UnpublishFeature(const std::string &FeatureName)
550 featurelist::iterator iter = Features.find(FeatureName);
552 if (iter == Features.end())
555 Features.erase(iter);
559 Module* ModuleManager::FindFeature(const std::string &FeatureName)
561 featurelist::iterator iter = Features.find(FeatureName);
563 if (iter == Features.end())
569 bool ModuleManager::PublishInterface(const std::string &InterfaceName, Module* Mod)
571 interfacelist::iterator iter = Interfaces.find(InterfaceName);
573 if (iter == Interfaces.end())
577 Interfaces[InterfaceName] = std::make_pair(0, ml);
581 iter->second.second.push_back(Mod);
586 bool ModuleManager::UnpublishInterface(const std::string &InterfaceName, Module* Mod)
588 interfacelist::iterator iter = Interfaces.find(InterfaceName);
590 if (iter == Interfaces.end())
593 for (modulelist::iterator x = iter->second.second.begin(); x != iter->second.second.end(); x++)
597 iter->second.second.erase(x);
598 if (iter->second.second.empty())
599 Interfaces.erase(InterfaceName);
606 modulelist* ModuleManager::FindInterface(const std::string &InterfaceName)
608 interfacelist::iterator iter = Interfaces.find(InterfaceName);
609 if (iter == Interfaces.end())
612 return &(iter->second.second);
615 bool ModuleManager::ModuleHasInterface(Module* mod, const std::string& InterfaceName)
617 interfacelist::iterator iter = Interfaces.find(InterfaceName);
618 if (iter == Interfaces.end())
622 modulelist& ml = iter->second.second;
623 modulelist::iterator mi = std::find(ml.begin(), ml.end(), mod);
624 return (mi != ml.end());
628 void ModuleManager::UseInterface(const std::string &InterfaceName)
630 interfacelist::iterator iter = Interfaces.find(InterfaceName);
631 if (iter != Interfaces.end())
632 iter->second.first++;
636 void ModuleManager::DoneWithInterface(const std::string &InterfaceName)
638 interfacelist::iterator iter = Interfaces.find(InterfaceName);
639 if (iter != Interfaces.end())
640 iter->second.first--;
643 std::pair<int,std::string> ModuleManager::GetInterfaceInstanceCount(Module* m)
645 for (interfacelist::iterator iter = Interfaces.begin(); iter != Interfaces.end(); iter++)
647 for (modulelist::iterator x = iter->second.second.begin(); x != iter->second.second.end(); x++)
651 return std::make_pair(iter->second.first, iter->first);
655 return std::make_pair(0, "");
658 const std::string& ModuleManager::GetModuleName(Module* m)
660 static std::string nothing;
662 for (std::map<std::string, Module*>::iterator n = Modules.begin(); n != Modules.end(); ++n)
671 CmdResult InspIRCd::CallCommandHandler(const std::string &commandname, const std::vector<std::string>& parameters, User* user)
673 return this->Parser->CallHandler(commandname, parameters, user);
676 bool InspIRCd::IsValidModuleCommand(const std::string &commandname, int pcnt, User* user)
678 return this->Parser->IsValidCommand(commandname, pcnt, user);
681 void InspIRCd::AddCommand(Command *f)
683 if (!this->Parser->AddCommand(f))
685 throw ModuleException("Command "+std::string(f->command)+" already exists.");
689 void InspIRCd::SendMode(const std::vector<std::string>& parameters, User *user)
691 this->Modes->Process(parameters, user);
694 void InspIRCd::DumpText(User* user, const std::string &text)
702 PI->PushToClient(user, text);
706 void InspIRCd::DumpText(User* user, const char *text, ...)
711 va_start(argsPtr, text);
712 vsnprintf(line, MAXBUF, text, argsPtr);
715 DumpText(user, std::string(line));
718 void InspIRCd::DumpText(User* user, const std::string &LinePrefix, std::stringstream &TextStream)
721 int start_pos = LinePrefix.length();
723 memcpy(line, LinePrefix.data(), pos);
725 while (TextStream >> Word)
727 int len = Word.length();
728 if (pos + len + 12 > MAXBUF)
731 DumpText(user, std::string(line));
735 memcpy(line + pos + 1, Word.data(), len);
739 DumpText(user, std::string(line));
742 bool InspIRCd::AddResolver(Resolver* r, bool cached)
745 return this->Res->AddResolverClass(r);
748 r->TriggerCachedResult();
754 Module* ModuleManager::Find(const std::string &name)
756 std::map<std::string, Module*>::iterator modfind = Modules.find(name);
758 if (modfind == Modules.end())
761 return modfind->second;
764 const std::vector<std::string> ModuleManager::GetAllModuleNames(int filter)
766 std::vector<std::string> retval;
767 for (std::map<std::string, Module*>::iterator x = Modules.begin(); x != Modules.end(); ++x)
768 if (!filter || (x->second->GetVersion().Flags & filter))
769 retval.push_back(x->first);
773 ConfigReader::ConfigReader()
779 ConfigReader::~ConfigReader()
784 std::string ConfigReader::ReadValue(const std::string &tag, const std::string &name, const std::string &default_value, int index, bool allow_linefeeds)
786 /* Don't need to strlcpy() tag and name anymore, ReadConf() takes const char* */
789 if (!ServerInstance->Config->ConfValue(tag, name, default_value, index, result, allow_linefeeds))
791 this->error = CONF_VALUE_NOT_FOUND;
796 std::string ConfigReader::ReadValue(const std::string &tag, const std::string &name, int index, bool allow_linefeeds)
798 return ReadValue(tag, name, "", index, allow_linefeeds);
801 bool ConfigReader::ReadFlag(const std::string &tag, const std::string &name, const std::string &default_value, int index)
803 return ServerInstance->Config->ConfValueBool(tag, name, default_value, index);
806 bool ConfigReader::ReadFlag(const std::string &tag, const std::string &name, int index)
808 return ReadFlag(tag, name, "", index);
812 int ConfigReader::ReadInteger(const std::string &tag, const std::string &name, const std::string &default_value, int index, bool need_positive)
816 if(!ServerInstance->Config->ConfValueInteger(tag, name, default_value, index, result))
818 this->error = CONF_VALUE_NOT_FOUND;
822 if ((need_positive) && (result < 0))
824 this->error = CONF_INT_NEGATIVE;
831 int ConfigReader::ReadInteger(const std::string &tag, const std::string &name, int index, bool need_positive)
833 return ReadInteger(tag, name, "", index, need_positive);
836 long ConfigReader::GetError()
838 long olderr = this->error;
843 int ConfigReader::Enumerate(const std::string &tag)
845 return ServerInstance->Config->ConfValueEnum(tag);
848 int ConfigReader::EnumerateValues(const std::string &tag, int index)
850 return ServerInstance->Config->ConfVarEnum(tag, index);
853 FileReader::FileReader(const std::string &filename)
858 FileReader::FileReader()
862 std::string FileReader::Contents()
865 for (file_cache::iterator a = this->fc.begin(); a != this->fc.end(); a++)
873 unsigned long FileReader::ContentSize()
875 return this->contentsize;
878 void FileReader::CalcSize()
881 for (file_cache::iterator a = this->fc.begin(); a != this->fc.end(); a++)
882 n += (a->length() + 2);
883 this->contentsize = n;
886 void FileReader::LoadFile(const std::string &filename)
890 if (ServerInstance->Config->ReadFile(c,filename.c_str()))
898 FileReader::~FileReader()
902 bool FileReader::Exists()
904 return (!(fc.size() == 0));
907 std::string FileReader::GetLine(int x)
909 if ((x<0) || ((unsigned)x>fc.size()))
914 int FileReader::FileSize()