1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2009 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/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"
28 // version is a simple class for holding a modules version number
29 Version::Version(const std::string &sversion, int flags, int api_ver)
30 : version(sversion), Flags(flags), API(api_ver)
34 Request::Request(char* anydata, Module* src, Module* dst)
35 : data(anydata), source(src), dest(dst)
37 /* Ensure that because this module doesnt support ID strings, it doesnt break modules that do
38 * by passing them uninitialized pointers (could happen)
43 Request::Request(Module* src, Module* dst, const char* idstr)
44 : id(idstr), source(src), dest(dst)
48 char* Request::GetData()
53 const char* Request::GetId()
58 Module* Request::GetSource()
63 Module* Request::GetDest()
68 const char* Request::Send()
72 return dest->OnRequest(this);
80 Event::Event(char* anydata, Module* src, const std::string &eventid) : data(anydata), source(src), id(eventid) { }
82 char* Event::GetData()
84 return (char*)this->data;
87 Module* Event::GetSource()
92 char* Event::Send(InspIRCd* ServerInstance)
94 FOREACH_MOD(I_OnEvent,OnEvent(this));
98 std::string Event::GetEventID()
104 // These declarations define the behavours of the base class Module (which does nothing at all)
106 Module::Module(InspIRCd* Me) : ServerInstance(Me) { }
107 Module::~Module() { }
109 int Module::OnSendSnotice(char &snomask, std::string &type, const std::string &message) { return 0; }
110 void Module::OnUserConnect(User*) { }
111 void Module::OnUserQuit(User*, const std::string&, const std::string&) { }
112 void Module::OnUserDisconnect(User*) { }
113 void Module::OnUserJoin(User*, Channel*, bool, bool&) { }
114 void Module::OnPostJoin(User*, Channel*) { }
115 void Module::OnUserPart(User*, Channel*, std::string&, bool&) { }
116 void Module::OnRehash(User*, const std::string&) { }
117 int Module::OnUserPreJoin(User*, Channel*, const char*, std::string&, const std::string&) { return 0; }
118 void Module::OnMode(User*, void*, int, const std::string&) { }
119 Version Module::GetVersion() { return Version("Misconfigured", VF_VENDOR, -1); }
120 void Module::OnOper(User*, const std::string&) { }
121 void Module::OnPostOper(User*, const std::string&, const std::string &) { }
122 void Module::OnInfo(User*) { }
123 void Module::OnWhois(User*, User*) { }
124 int Module::OnUserPreInvite(User*, User*, Channel*, time_t) { return 0; }
125 int Module::OnUserPreMessage(User*, void*, int, std::string&, char, CUList&) { return 0; }
126 int Module::OnUserPreNotice(User*, void*, int, std::string&, char, CUList&) { return 0; }
127 int Module::OnUserPreNick(User*, const std::string&) { return 0; }
128 void Module::OnUserPostNick(User*, const std::string&) { }
129 int Module::OnAccessCheck(User*, User*, Channel*, int) { return ACR_DEFAULT; }
130 void Module::On005Numeric(std::string&) { }
131 int Module::OnKill(User*, User*, const std::string&) { return 0; }
132 void Module::OnLoadModule(Module*, const std::string&) { }
133 void Module::OnUnloadModule(Module*, const std::string&) { }
134 void Module::OnBackgroundTimer(time_t) { }
135 int Module::OnPreCommand(std::string&, std::vector<std::string>&, User *, bool, const std::string&) { return 0; }
136 void Module::OnPostCommand(const std::string&, const std::vector<std::string>&, User *, CmdResult, const std::string&) { }
137 bool Module::OnCheckReady(User*) { return true; }
138 int Module::OnUserRegister(User*) { return 0; }
139 int Module::OnUserPreKick(User*, User*, Channel*, const std::string&) { return 0; }
140 void Module::OnUserKick(User*, User*, Channel*, const std::string&, bool&) { }
141 int Module::OnRawMode(User*, Channel*, const char, const std::string &, bool, int, bool) { return 0; }
142 int Module::OnCheckInvite(User*, Channel*) { return 0; }
143 int Module::OnCheckKey(User*, Channel*, const std::string&) { return 0; }
144 int Module::OnCheckLimit(User*, Channel*) { return 0; }
145 int Module::OnCheckBan(User*, Channel*) { return 0; }
146 int Module::OnCheckExtBan(User *, Channel *, char) { return 0; }
147 int Module::OnCheckStringExtBan(const std::string &s, Channel *c, char type) { return 0; }
148 int Module::OnStats(char, User*, string_list&) { return 0; }
149 int Module::OnChangeLocalUserHost(User*, const std::string&) { return 0; }
150 int Module::OnChangeLocalUserGECOS(User*, const std::string&) { return 0; }
151 int Module::OnLocalTopicChange(User*, Channel*, const std::string&) { return 0; }
152 void Module::OnEvent(Event*) { return; }
153 const char* Module::OnRequest(Request*) { return NULL; }
154 int Module::OnPassCompare(Extensible* ex, const std::string &password, const std::string &input, const std::string& hashtype) { return 0; }
155 void Module::OnGlobalOper(User*) { }
156 void Module::OnPostConnect(User*) { }
157 int Module::OnAddBan(User*, Channel*, const std::string &) { return 0; }
158 int Module::OnDelBan(User*, Channel*, const std::string &) { return 0; }
159 void Module::OnRawSocketAccept(int, const std::string&, int) { }
160 int Module::OnRawSocketWrite(int, const char*, int) { return 0; }
161 void Module::OnRawSocketClose(int) { }
162 void Module::OnRawSocketConnect(int) { }
163 int Module::OnRawSocketRead(int, char*, unsigned int, int&) { return 0; }
164 void Module::OnUserMessage(User*, void*, int, const std::string&, char, const CUList&) { }
165 void Module::OnUserNotice(User*, void*, int, const std::string&, char, const CUList&) { }
166 void Module::OnRemoteKill(User*, User*, const std::string&, const std::string&) { }
167 void Module::OnUserInvite(User*, User*, Channel*, time_t) { }
168 void Module::OnPostLocalTopicChange(User*, Channel*, const std::string&) { }
169 void Module::OnGetServerDescription(const std::string&, std::string&) { }
170 void Module::OnSyncUser(User*, Module*, void*) { }
171 void Module::OnSyncChannel(Channel*, Module*, void*) { }
172 void Module::ProtoSendMode(void*, TargetTypeFlags, void*, const std::string&) { }
173 void Module::OnSyncChannelMetaData(Channel*, Module*, void*, const std::string&, bool) { }
174 void Module::OnSyncUserMetaData(User*, Module*, void*, const std::string&, bool) { }
175 void Module::OnSyncOtherMetaData(Module*, void*, bool) { }
176 void Module::OnDecodeMetaData(int, void*, const std::string&, const std::string&) { }
177 void Module::ProtoSendMetaData(void*, TargetTypeFlags, void*, const std::string&, const std::string&) { }
178 void Module::OnWallops(User*, const std::string&) { }
179 void Module::OnChangeHost(User*, const std::string&) { }
180 void Module::OnChangeName(User*, const std::string&) { }
181 void Module::OnAddLine(User*, XLine*) { }
182 void Module::OnDelLine(User*, XLine*) { }
183 void Module::OnExpireLine(XLine*) { }
184 void Module::OnCleanup(int, void*) { }
185 int Module::OnChannelPreDelete(Channel*) { return 0; }
186 void Module::OnChannelDelete(Channel*) { }
187 int Module::OnSetAway(User*, const std::string &) { return 0; }
188 int Module::OnUserList(User*, Channel*, CUList*&) { return 0; }
189 int Module::OnWhoisLine(User*, User*, int&, std::string&) { return 0; }
190 void Module::OnBuildExemptList(MessageType, Channel*, User*, char, CUList&, const std::string&) { }
191 void Module::OnGarbageCollect() { }
192 void Module::OnBufferFlushed(User*) { }
193 void Module::OnText(User*, void*, int, const std::string&, char, CUList&) { }
194 void Module::OnRunTestSuite() { }
195 void Module::OnNamesListItem(User*, User*, Channel*, std::string&, std::string&) { }
196 int Module::OnNumeric(User*, unsigned int, const std::string&) { return 0; }
197 void Module::OnHookUserIO(User*, const std::string&) { }
198 bool Module::OnHostCycle(User* user) { return false; }
200 ModuleManager::ModuleManager(InspIRCd* Ins) : ModCount(0), Instance(Ins)
204 ModuleManager::~ModuleManager()
208 bool ModuleManager::Attach(Implementation i, Module* mod)
210 if (std::find(EventHandlers[i].begin(), EventHandlers[i].end(), mod) != EventHandlers[i].end())
213 EventHandlers[i].push_back(mod);
217 bool ModuleManager::Detach(Implementation i, Module* mod)
219 EventHandlerIter x = std::find(EventHandlers[i].begin(), EventHandlers[i].end(), mod);
221 if (x == EventHandlers[i].end())
224 EventHandlers[i].erase(x);
228 void ModuleManager::Attach(Implementation* i, Module* mod, size_t sz)
230 for (size_t n = 0; n < sz; ++n)
234 void ModuleManager::DetachAll(Module* mod)
236 for (size_t n = I_BEGIN + 1; n != I_END; ++n)
237 Detach((Implementation)n, mod);
240 bool ModuleManager::SetPriority(Module* mod, PriorityState s)
242 for (size_t n = I_BEGIN + 1; n != I_END; ++n)
243 SetPriority(mod, (Implementation)n, s);
248 bool ModuleManager::SetPriority(Module* mod, Implementation i, PriorityState s, Module** modules, size_t sz)
250 /** To change the priority of a module, we first find its position in the vector,
251 * then we find the position of the other modules in the vector that this module
252 * wants to be before/after. We pick off either the first or last of these depending
253 * on which they want, and we make sure our module is *at least* before or after
254 * the first or last of this subset, depending again on the type of priority.
261 /* Locate our module. This is O(n) but it only occurs on module load so we're
262 * not too bothered about it
264 for (size_t x = 0; x != EventHandlers[i].size(); ++x)
266 if (EventHandlers[i][x] == mod)
274 /* Eh? this module doesnt exist, probably trying to set priority on an event
275 * theyre not attached to.
286 /* Module wants to be first, sod everything else */
290 /* Module is submissive and wants to be last... awww. */
292 if (EventHandlers[i].empty())
295 swap_pos = EventHandlers[i].size() - 1;
297 /* Place this module after a set of other modules */
300 /* Find the latest possible position */
303 for (size_t x = 0; x != EventHandlers[i].size(); ++x)
305 for (size_t n = 0; n < sz; ++n)
307 if ((modules[n]) && (EventHandlers[i][x] == modules[n]) && (x >= swap_pos) && (source <= swap_pos))
316 /* Place this module before a set of other modules */
319 swap_pos = EventHandlers[i].size() - 1;
321 for (size_t x = 0; x != EventHandlers[i].size(); ++x)
323 for (size_t n = 0; n < sz; ++n)
325 if ((modules[n]) && (EventHandlers[i][x] == modules[n]) && (x <= swap_pos) && (source >= swap_pos))
336 /* Do we need to swap? */
337 if (swap && (swap_pos != source))
339 /* Suggestion from Phoenix, "shuffle" the modules to better retain call order */
342 if (source > swap_pos)
345 for (unsigned int j = source; j != swap_pos; j += incrmnt)
347 if (( j + incrmnt > EventHandlers[i].size() - 1) || (j + incrmnt < 0))
350 std::swap(EventHandlers[i][j], EventHandlers[i][j+incrmnt]);
357 std::string& ModuleManager::LastError()
359 return LastModuleError;
362 bool ModuleManager::Load(const char* filename)
364 /* Do we have a glob pattern in the filename?
365 * The user wants to load multiple modules which
368 if (strchr(filename,'*') || (strchr(filename,'?')))
371 DIR* library = opendir(Instance->Config->ModPath);
374 /* Try and locate and load all modules matching the pattern */
375 dirent* entry = NULL;
376 while (0 != (entry = readdir(library)))
378 if (InspIRCd::Match(entry->d_name, filename, ascii_case_insensitive_map))
380 if (!this->Load(entry->d_name))
386 /* Loadmodule will now return false if any one of the modules failed
387 * to load (but wont abort when it encounters a bad one) and when 1 or
388 * more modules were actually loaded.
390 return (n_match > 0);
393 char modfile[MAXBUF];
394 snprintf(modfile,MAXBUF,"%s/%s",Instance->Config->ModPath,filename);
395 std::string filename_str = filename;
397 if (!ServerConfig::DirValid(modfile))
399 LastModuleError = "Module " + std::string(filename) + " is not in the module directory that i am configured to look in (is "+Instance->Config->ModPath+" really a symlink?)";
400 Instance->Logs->Log("MODULE", DEFAULT, LastModuleError);
404 if (!ServerConfig::FileExists(modfile))
406 LastModuleError = "Module file could not be found: " + filename_str;
407 Instance->Logs->Log("MODULE", DEFAULT, LastModuleError);
411 if (Modules.find(filename_str) != Modules.end())
413 LastModuleError = "Module " + filename_str + " is already loaded, cannot load a module twice!";
414 Instance->Logs->Log("MODULE", DEFAULT, LastModuleError);
418 Module* newmod = NULL;
419 ircd_module* newhandle = NULL;
423 /* This will throw a CoreException if there's a problem loading
424 * the module file or getting a pointer to the init_module symbol.
426 newhandle = new ircd_module(Instance, modfile, "init_module");
427 newmod = newhandle->CallInit();
431 Version v = newmod->GetVersion();
433 if (v.API != API_VERSION)
438 LastModuleError = "Unable to load " + filename_str + ": Incorrect module API version: " + ConvToStr(v.API) + " (our version: " + ConvToStr(API_VERSION) + ")";
439 Instance->Logs->Log("MODULE", DEFAULT, LastModuleError);
444 Instance->Logs->Log("MODULE", DEFAULT,"New module introduced: %s (API version %d, Module version %s)%s", filename, v.API, v.version.c_str(), (!(v.Flags & VF_VENDOR) ? " [3rd Party]" : " [Vendor]"));
447 Modules[filename_str] = std::make_pair(newhandle, newmod);
452 LastModuleError = "Unable to load " + filename_str + ": Probably missing init_module() entrypoint, but dlsym() didn't notice a problem";
453 Instance->Logs->Log("MODULE", DEFAULT, LastModuleError);
457 /** XXX: Is there anything we can do about this mess? -- Brain */
458 catch (LoadModuleException& modexcept)
465 LastModuleError = "Unable to load " + filename_str + ": Error when loading: " + modexcept.GetReason();
466 Instance->Logs->Log("MODULE", DEFAULT, LastModuleError);
469 catch (FindSymbolException& modexcept)
476 LastModuleError = "Unable to load " + filename_str + ": Error finding symbol: " + modexcept.GetReason();
477 Instance->Logs->Log("MODULE", DEFAULT, LastModuleError);
480 catch (CoreException& modexcept)
487 LastModuleError = "Unable to load " + filename_str + ": " + modexcept.GetReason();
488 Instance->Logs->Log("MODULE", DEFAULT, LastModuleError);
493 FOREACH_MOD_I(Instance,I_OnLoadModule,OnLoadModule(newmod, filename_str));
495 /* We give every module a chance to re-prioritize when we introduce a new one,
496 * not just the one thats loading, as the new module could affect the preference
499 for (std::map<std::string, std::pair<ircd_module*, Module*> >::iterator n = Modules.begin(); n != Modules.end(); ++n)
500 n->second.second->Prioritize();
502 Instance->BuildISupport();
506 bool ModuleManager::Unload(const char* filename)
508 std::string filename_str(filename);
509 std::map<std::string, std::pair<ircd_module*, Module*> >::iterator modfind = Modules.find(filename);
511 if (modfind != Modules.end())
513 if (modfind->second.second->GetVersion().Flags & VF_STATIC)
515 LastModuleError = "Module " + filename_str + " not unloadable (marked static)";
516 Instance->Logs->Log("MODULE", DEFAULT, LastModuleError);
519 std::pair<int,std::string> intercount = GetInterfaceInstanceCount(modfind->second.second);
520 if (intercount.first > 0)
522 LastModuleError = "Failed to unload module " + filename_str + ", being used by " + ConvToStr(intercount.first) + " other(s) via interface '" + intercount.second + "'";
523 Instance->Logs->Log("MODULE", DEFAULT, LastModuleError);
527 /* Give the module a chance to tidy out all its metadata */
528 for (chan_hash::iterator c = Instance->chanlist->begin(); c != Instance->chanlist->end(); c++)
530 modfind->second.second->OnCleanup(TYPE_CHANNEL,c->second);
532 for (user_hash::iterator u = Instance->Users->clientlist->begin(); u != Instance->Users->clientlist->end(); u++)
534 modfind->second.second->OnCleanup(TYPE_USER,u->second);
537 /* Tidy up any dangling resolvers */
538 Instance->Res->CleanResolvers(modfind->second.second);
541 FOREACH_MOD_I(Instance,I_OnUnloadModule,OnUnloadModule(modfind->second.second, modfind->first));
543 this->DetachAll(modfind->second.second);
545 Instance->Parser->RemoveCommands(filename);
547 delete modfind->second.second;
548 delete modfind->second.first;
549 Modules.erase(modfind);
551 Instance->Logs->Log("MODULE", DEFAULT,"Module %s unloaded",filename);
553 Instance->BuildISupport();
557 LastModuleError = "Module " + filename_str + " is not loaded, cannot unload it!";
558 Instance->Logs->Log("MODULE", DEFAULT, LastModuleError);
562 /* We must load the modules AFTER initializing the socket engine, now */
563 void ModuleManager::LoadAll()
565 char configToken[MAXBUF];
568 for(int count = 0; count < Instance->Config->ConfValueEnum(Instance->Config->config_data, "module"); count++)
570 Instance->Config->ConfValue(Instance->Config->config_data, "module", "name", count, configToken, MAXBUF);
571 printf_c("[\033[1;32m*\033[0m] Loading module:\t\033[1;32m%s\033[0m\n",configToken);
573 if (!this->Load(configToken))
575 Instance->Logs->Log("MODULE", DEFAULT, this->LastError());
576 printf_c("\n[\033[1;31m*\033[0m] %s\n\n", this->LastError().c_str());
577 Instance->Exit(EXIT_STATUS_MODULE);
582 bool ModuleManager::PublishFeature(const std::string &FeatureName, Module* Mod)
584 if (Features.find(FeatureName) == Features.end())
586 Features[FeatureName] = Mod;
592 bool ModuleManager::UnpublishFeature(const std::string &FeatureName)
594 featurelist::iterator iter = Features.find(FeatureName);
596 if (iter == Features.end())
599 Features.erase(iter);
603 Module* ModuleManager::FindFeature(const std::string &FeatureName)
605 featurelist::iterator iter = Features.find(FeatureName);
607 if (iter == Features.end())
613 bool ModuleManager::PublishInterface(const std::string &InterfaceName, Module* Mod)
615 interfacelist::iterator iter = Interfaces.find(InterfaceName);
617 if (iter == Interfaces.end())
621 Interfaces[InterfaceName] = std::make_pair(0, ml);
625 iter->second.second.push_back(Mod);
630 bool ModuleManager::UnpublishInterface(const std::string &InterfaceName, Module* Mod)
632 interfacelist::iterator iter = Interfaces.find(InterfaceName);
634 if (iter == Interfaces.end())
637 for (modulelist::iterator x = iter->second.second.begin(); x != iter->second.second.end(); x++)
641 iter->second.second.erase(x);
642 if (iter->second.second.empty())
643 Interfaces.erase(InterfaceName);
650 modulelist* ModuleManager::FindInterface(const std::string &InterfaceName)
652 interfacelist::iterator iter = Interfaces.find(InterfaceName);
653 if (iter == Interfaces.end())
656 return &(iter->second.second);
659 bool ModuleManager::ModuleHasInterface(Module* mod, const std::string& InterfaceName)
661 interfacelist::iterator iter = Interfaces.find(InterfaceName);
662 if (iter == Interfaces.end())
666 modulelist& ml = iter->second.second;
667 modulelist::iterator mi = std::find(ml.begin(), ml.end(), mod);
668 return (mi != ml.end());
672 void ModuleManager::UseInterface(const std::string &InterfaceName)
674 interfacelist::iterator iter = Interfaces.find(InterfaceName);
675 if (iter != Interfaces.end())
676 iter->second.first++;
680 void ModuleManager::DoneWithInterface(const std::string &InterfaceName)
682 interfacelist::iterator iter = Interfaces.find(InterfaceName);
683 if (iter != Interfaces.end())
684 iter->second.first--;
687 std::pair<int,std::string> ModuleManager::GetInterfaceInstanceCount(Module* m)
689 for (interfacelist::iterator iter = Interfaces.begin(); iter != Interfaces.end(); iter++)
691 for (modulelist::iterator x = iter->second.second.begin(); x != iter->second.second.end(); x++)
695 return std::make_pair(iter->second.first, iter->first);
699 return std::make_pair(0, "");
702 const std::string& ModuleManager::GetModuleName(Module* m)
704 static std::string nothing;
706 for (std::map<std::string, std::pair<ircd_module*, Module*> >::iterator n = Modules.begin(); n != Modules.end(); ++n)
708 if (n->second.second == m)
715 /* This is ugly, yes, but hash_map's arent designed to be
716 * addressed in this manner, and this is a bit of a kludge.
717 * Luckily its a specialist function and rarely used by
718 * many modules (in fact, it was specially created to make
719 * m_safelist possible, initially).
722 Channel* InspIRCd::GetChannelIndex(long index)
725 for (chan_hash::iterator n = this->chanlist->begin(); n != this->chanlist->end(); n++, target++)
733 CmdResult InspIRCd::CallCommandHandler(const std::string &commandname, const std::vector<std::string>& parameters, User* user)
735 return this->Parser->CallHandler(commandname, parameters, user);
738 bool InspIRCd::IsValidModuleCommand(const std::string &commandname, int pcnt, User* user)
740 return this->Parser->IsValidCommand(commandname, pcnt, user);
743 void InspIRCd::AddCommand(Command *f)
745 if (!this->Parser->CreateCommand(f))
747 ModuleException err("Command "+std::string(f->command)+" already exists.");
752 void InspIRCd::SendMode(const std::vector<std::string>& parameters, User *user)
754 this->Modes->Process(parameters, user, true);
757 void InspIRCd::DumpText(User* User, const std::string &LinePrefix, std::stringstream &TextStream)
759 std::string CompleteLine = LinePrefix;
761 while (TextStream >> Word)
763 if (CompleteLine.length() + Word.length() + 3 > 500)
765 User->WriteServ(CompleteLine);
766 CompleteLine = LinePrefix;
768 CompleteLine = CompleteLine + Word + " ";
770 User->WriteServ(CompleteLine);
773 User* FindDescriptorHandler::Call(int socket)
775 return reinterpret_cast<User*>(Server->SE->GetRef(socket));
778 bool InspIRCd::AddResolver(Resolver* r, bool cached)
781 return this->Res->AddResolverClass(r);
784 r->TriggerCachedResult();
790 Module* ModuleManager::Find(const std::string &name)
792 std::map<std::string, std::pair<ircd_module*, Module*> >::iterator modfind = Modules.find(name);
794 if (modfind == Modules.end())
797 return modfind->second.second;
800 const std::vector<std::string> ModuleManager::GetAllModuleNames(int filter)
802 std::vector<std::string> retval;
803 for (std::map<std::string, std::pair<ircd_module*, Module*> >::iterator x = Modules.begin(); x != Modules.end(); ++x)
804 if (!filter || (x->second.second->GetVersion().Flags & filter))
805 retval.push_back(x->first);
809 ConfigReader::ConfigReader(InspIRCd* Instance) : ServerInstance(Instance)
811 this->errorlog = new std::ostringstream(std::stringstream::in | std::stringstream::out);
812 this->error = CONF_NO_ERROR;
813 this->data = &ServerInstance->Config->config_data;
814 this->privatehash = false;
819 ConfigReader::~ConfigReader()
822 delete this->errorlog;
823 if(this->privatehash)
828 ConfigReader::ConfigReader(InspIRCd* Instance, const std::string &filename) : ServerInstance(Instance)
830 ServerInstance->Config->ClearStack();
832 this->error = CONF_NO_ERROR;
833 this->data = new ConfigDataHash;
834 this->privatehash = true;
835 this->errorlog = new std::ostringstream(std::stringstream::in | std::stringstream::out);
836 /*** XXX: This might block! */
837 this->readerror = ServerInstance->Config->DoInclude(*this->data, filename, *this->errorlog);
838 if (!this->readerror)
839 this->error = CONF_FILE_NOT_FOUND;
844 std::string ConfigReader::ReadValue(const std::string &tag, const std::string &name, const std::string &default_value, int index, bool allow_linefeeds)
846 /* Don't need to strlcpy() tag and name anymore, ReadConf() takes const char* */
849 if (!ServerInstance->Config->ConfValue(*this->data, tag, name, default_value, index, result, allow_linefeeds))
851 this->error = CONF_VALUE_NOT_FOUND;
856 std::string ConfigReader::ReadValue(const std::string &tag, const std::string &name, int index, bool allow_linefeeds)
858 return ReadValue(tag, name, "", index, allow_linefeeds);
861 bool ConfigReader::ReadFlag(const std::string &tag, const std::string &name, const std::string &default_value, int index)
863 return ServerInstance->Config->ConfValueBool(*this->data, tag, name, default_value, index);
866 bool ConfigReader::ReadFlag(const std::string &tag, const std::string &name, int index)
868 return ReadFlag(tag, name, "", index);
872 int ConfigReader::ReadInteger(const std::string &tag, const std::string &name, const std::string &default_value, int index, bool need_positive)
876 if(!ServerInstance->Config->ConfValueInteger(*this->data, tag, name, default_value, index, result))
878 this->error = CONF_VALUE_NOT_FOUND;
882 if ((need_positive) && (result < 0))
884 this->error = CONF_INT_NEGATIVE;
891 int ConfigReader::ReadInteger(const std::string &tag, const std::string &name, int index, bool need_positive)
893 return ReadInteger(tag, name, "", index, need_positive);
896 long ConfigReader::GetError()
898 long olderr = this->error;
903 void ConfigReader::DumpErrors(bool bail, User* user)
905 ServerInstance->Config->ReportConfigError(this->errorlog->str(), bail, user->uuid);
909 int ConfigReader::Enumerate(const std::string &tag)
911 return ServerInstance->Config->ConfValueEnum(*this->data, tag);
914 int ConfigReader::EnumerateValues(const std::string &tag, int index)
916 return ServerInstance->Config->ConfVarEnum(*this->data, tag, index);
919 bool ConfigReader::Verify()
921 return this->readerror;
925 FileReader::FileReader(InspIRCd* Instance, const std::string &filename) : ServerInstance(Instance)
930 FileReader::FileReader(InspIRCd* Instance) : ServerInstance(Instance)
934 std::string FileReader::Contents()
937 for (file_cache::iterator a = this->fc.begin(); a != this->fc.end(); a++)
945 unsigned long FileReader::ContentSize()
947 return this->contentsize;
950 void FileReader::CalcSize()
953 for (file_cache::iterator a = this->fc.begin(); a != this->fc.end(); a++)
954 n += (a->length() + 2);
955 this->contentsize = n;
958 void FileReader::LoadFile(const std::string &filename)
962 if (ServerInstance->Config->ReadFile(c,filename.c_str()))
970 FileReader::~FileReader()
974 bool FileReader::Exists()
976 return (!(fc.size() == 0));
979 std::string FileReader::GetLine(int x)
981 if ((x<0) || ((unsigned)x>fc.size()))
986 int FileReader::FileSize()