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
30 Version::Version(const std::string &sversion, int flags, int api_ver)
31 : version(sversion), Flags(flags), API(api_ver)
35 Request::Request(char* anydata, Module* src, Module* dst)
36 : data(anydata), source(src), dest(dst)
38 /* Ensure that because this module doesnt support ID strings, it doesnt break modules that do
39 * by passing them uninitialized pointers (could happen)
44 Request::Request(Module* src, Module* dst, const char* idstr)
45 : id(idstr), source(src), dest(dst)
49 char* Request::GetData()
54 const char* Request::GetId()
59 Module* Request::GetSource()
64 Module* Request::GetDest()
69 const char* Request::Send()
73 return dest->OnRequest(this);
81 Event::Event(char* anydata, Module* src, const std::string &eventid) : data(anydata), source(src), id(eventid) { }
83 char* Event::GetData()
85 return (char*)this->data;
88 Module* Event::GetSource()
93 char* Event::Send(InspIRCd* ServerInstance)
95 FOREACH_MOD(I_OnEvent,OnEvent(this));
99 std::string Event::GetEventID()
105 // These declarations define the behavours of the base class Module (which does nothing at all)
107 Module::Module(InspIRCd* Me) : ServerInstance(Me) { }
108 Module::~Module() { }
110 int Module::OnSendSnotice(char &snomask, std::string &type, const std::string &message) { return 0; }
111 void Module::OnUserConnect(User*) { }
112 void Module::OnUserQuit(User*, const std::string&, const std::string&) { }
113 void Module::OnUserDisconnect(User*) { }
114 void Module::OnUserJoin(User*, Channel*, bool, bool&) { }
115 void Module::OnPostJoin(User*, Channel*) { }
116 void Module::OnUserPart(User*, Channel*, std::string&, bool&) { }
117 void Module::OnRehash(User*, const std::string&) { }
118 int Module::OnUserPreJoin(User*, Channel*, const char*, std::string&, const std::string&) { return 0; }
119 void Module::OnMode(User*, void*, int, const std::deque<std::string>&, const std::deque<TranslateType>&) { }
120 Version Module::GetVersion() { return Version("Misconfigured", VF_VENDOR, -1); }
121 void Module::OnOper(User*, const std::string&) { }
122 void Module::OnPostOper(User*, const std::string&, const std::string &) { }
123 void Module::OnInfo(User*) { }
124 void Module::OnWhois(User*, User*) { }
125 int Module::OnUserPreInvite(User*, User*, Channel*, time_t) { return 0; }
126 int Module::OnUserPreMessage(User*, void*, int, std::string&, char, CUList&) { return 0; }
127 int Module::OnUserPreNotice(User*, void*, int, std::string&, char, CUList&) { return 0; }
128 int Module::OnUserPreNick(User*, const std::string&) { return 0; }
129 void Module::OnUserPostNick(User*, const std::string&) { }
130 int Module::OnAccessCheck(User*, User*, Channel*, int) { return ACR_DEFAULT; }
131 void Module::On005Numeric(std::string&) { }
132 int Module::OnKill(User*, User*, const std::string&) { return 0; }
133 void Module::OnLoadModule(Module*, const std::string&) { }
134 void Module::OnUnloadModule(Module*, const std::string&) { }
135 void Module::OnBackgroundTimer(time_t) { }
136 int Module::OnPreCommand(std::string&, std::vector<std::string>&, User *, bool, const std::string&) { return 0; }
137 void Module::OnPostCommand(const std::string&, const std::vector<std::string>&, User *, CmdResult, const std::string&) { }
138 bool Module::OnCheckReady(User*) { return true; }
139 int Module::OnUserRegister(User*) { return 0; }
140 int Module::OnUserPreKick(User*, User*, Channel*, const std::string&) { return 0; }
141 void Module::OnUserKick(User*, User*, Channel*, const std::string&, bool&) { }
142 int Module::OnRawMode(User*, Channel*, const char, const std::string &, bool, int, bool) { return 0; }
143 int Module::OnCheckInvite(User*, Channel*) { return 0; }
144 int Module::OnCheckKey(User*, Channel*, const std::string&) { return 0; }
145 int Module::OnCheckLimit(User*, Channel*) { return 0; }
146 int Module::OnCheckBan(User*, Channel*) { return 0; }
147 int Module::OnCheckExtBan(User *, Channel *, char) { return 0; }
148 int Module::OnCheckStringExtBan(const std::string &s, Channel *c, char type) { return 0; }
149 int Module::OnStats(char, User*, string_list&) { return 0; }
150 int Module::OnChangeLocalUserHost(User*, const std::string&) { return 0; }
151 int Module::OnChangeLocalUserGECOS(User*, const std::string&) { return 0; }
152 int Module::OnLocalTopicChange(User*, Channel*, const std::string&) { return 0; }
153 void Module::OnEvent(Event*) { return; }
154 const char* Module::OnRequest(Request*) { return NULL; }
155 int Module::OnPassCompare(Extensible* ex, const std::string &password, const std::string &input, const std::string& hashtype) { return 0; }
156 void Module::OnGlobalOper(User*) { }
157 void Module::OnPostConnect(User*) { }
158 int Module::OnAddBan(User*, Channel*, const std::string &) { return 0; }
159 int Module::OnDelBan(User*, Channel*, const std::string &) { return 0; }
160 void Module::OnRawSocketAccept(int, const std::string&, int) { }
161 int Module::OnRawSocketWrite(int, const char*, int) { return 0; }
162 void Module::OnRawSocketClose(int) { }
163 void Module::OnRawSocketConnect(int) { }
164 int Module::OnRawSocketRead(int, char*, unsigned int, int&) { return 0; }
165 void Module::OnUserMessage(User*, void*, int, const std::string&, char, const CUList&) { }
166 void Module::OnUserNotice(User*, void*, int, const std::string&, char, const CUList&) { }
167 void Module::OnRemoteKill(User*, User*, const std::string&, const std::string&) { }
168 void Module::OnUserInvite(User*, User*, Channel*, time_t) { }
169 void Module::OnPostLocalTopicChange(User*, Channel*, const std::string&) { }
170 void Module::OnGetServerDescription(const std::string&, std::string&) { }
171 void Module::OnSyncUser(User*, Module*, void*) { }
172 void Module::OnSyncChannel(Channel*, Module*, void*) { }
173 void Module::ProtoSendMode(void*, TargetTypeFlags, void*, const std::deque<std::string>&, const std::deque<TranslateType>&) { }
174 void Module::OnSyncChannelMetaData(Channel*, Module*, void*, const std::string&, bool) { }
175 void Module::OnSyncUserMetaData(User*, Module*, void*, const std::string&, bool) { }
176 void Module::OnSyncOtherMetaData(Module*, void*, bool) { }
177 void Module::OnDecodeMetaData(int, void*, const std::string&, const std::string&) { }
178 void Module::ProtoSendMetaData(void*, TargetTypeFlags, void*, const std::string&, const std::string&) { }
179 void Module::OnWallops(User*, const std::string&) { }
180 void Module::OnChangeHost(User*, const std::string&) { }
181 void Module::OnChangeName(User*, const std::string&) { }
182 void Module::OnAddLine(User*, XLine*) { }
183 void Module::OnDelLine(User*, XLine*) { }
184 void Module::OnExpireLine(XLine*) { }
185 void Module::OnCleanup(int, void*) { }
186 int Module::OnChannelPreDelete(Channel*) { return 0; }
187 void Module::OnChannelDelete(Channel*) { }
188 int Module::OnSetAway(User*, const std::string &) { return 0; }
189 int Module::OnUserList(User*, Channel*, CUList*&) { return 0; }
190 int Module::OnWhoisLine(User*, User*, int&, std::string&) { return 0; }
191 void Module::OnBuildExemptList(MessageType, Channel*, User*, char, CUList&, const std::string&) { }
192 void Module::OnGarbageCollect() { }
193 void Module::OnBufferFlushed(User*) { }
194 void Module::OnText(User*, void*, int, const std::string&, char, CUList&) { }
195 void Module::OnRunTestSuite() { }
196 void Module::OnNamesListItem(User*, User*, Channel*, std::string&, std::string&) { }
197 int Module::OnNumeric(User*, unsigned int, const std::string&) { return 0; }
198 void Module::OnHookUserIO(User*, const std::string&) { }
199 bool Module::OnHostCycle(User* user) { return false; }
201 ModuleManager::ModuleManager(InspIRCd* Ins) : ModCount(0), Instance(Ins)
205 ModuleManager::~ModuleManager()
209 bool ModuleManager::Attach(Implementation i, Module* mod)
211 if (std::find(EventHandlers[i].begin(), EventHandlers[i].end(), mod) != EventHandlers[i].end())
214 EventHandlers[i].push_back(mod);
218 bool ModuleManager::Detach(Implementation i, Module* mod)
220 EventHandlerIter x = std::find(EventHandlers[i].begin(), EventHandlers[i].end(), mod);
222 if (x == EventHandlers[i].end())
225 EventHandlers[i].erase(x);
229 void ModuleManager::Attach(Implementation* i, Module* mod, size_t sz)
231 for (size_t n = 0; n < sz; ++n)
235 void ModuleManager::DetachAll(Module* mod)
237 for (size_t n = I_BEGIN + 1; n != I_END; ++n)
238 Detach((Implementation)n, mod);
241 bool ModuleManager::SetPriority(Module* mod, Priority s)
243 for (size_t n = I_BEGIN + 1; n != I_END; ++n)
244 SetPriority(mod, (Implementation)n, s);
249 bool ModuleManager::SetPriority(Module* mod, Implementation i, Priority s, Module** modules, size_t sz)
251 /** To change the priority of a module, we first find its position in the vector,
252 * then we find the position of the other modules in the vector that this module
253 * wants to be before/after. We pick off either the first or last of these depending
254 * on which they want, and we make sure our module is *at least* before or after
255 * the first or last of this subset, depending again on the type of priority.
262 /* Locate our module. This is O(n) but it only occurs on module load so we're
263 * not too bothered about it
265 for (size_t x = 0; x != EventHandlers[i].size(); ++x)
267 if (EventHandlers[i][x] == mod)
275 /* Eh? this module doesnt exist, probably trying to set priority on an event
276 * theyre not attached to.
284 case PRIORITY_DONTCARE:
287 /* Module wants to be first, sod everything else */
291 /* Module is submissive and wants to be last... awww. */
293 if (EventHandlers[i].empty())
296 swap_pos = EventHandlers[i].size() - 1;
298 /* Place this module after a set of other modules */
301 /* Find the latest possible position */
304 for (size_t x = 0; x != EventHandlers[i].size(); ++x)
306 for (size_t n = 0; n < sz; ++n)
308 if ((modules[n]) && (EventHandlers[i][x] == modules[n]) && (x >= swap_pos) && (source <= swap_pos))
317 /* Place this module before a set of other modules */
318 case PRIORITY_BEFORE:
320 swap_pos = EventHandlers[i].size() - 1;
322 for (size_t x = 0; x != EventHandlers[i].size(); ++x)
324 for (size_t n = 0; n < sz; ++n)
326 if ((modules[n]) && (EventHandlers[i][x] == modules[n]) && (x <= swap_pos) && (source >= swap_pos))
337 /* Do we need to swap? */
338 if (swap && (swap_pos != source))
340 /* Suggestion from Phoenix, "shuffle" the modules to better retain call order */
343 if (source > swap_pos)
346 for (unsigned int j = source; j != swap_pos; j += incrmnt)
348 if (( j + incrmnt > EventHandlers[i].size() - 1) || (j + incrmnt < 0))
351 std::swap(EventHandlers[i][j], EventHandlers[i][j+incrmnt]);
358 std::string& ModuleManager::LastError()
360 return LastModuleError;
363 bool ModuleManager::Load(const char* filename)
365 /* Do we have a glob pattern in the filename?
366 * The user wants to load multiple modules which
369 if (strchr(filename,'*') || (strchr(filename,'?')))
372 DIR* library = opendir(Instance->Config->ModPath);
375 /* Try and locate and load all modules matching the pattern */
376 dirent* entry = NULL;
377 while (0 != (entry = readdir(library)))
379 if (InspIRCd::Match(entry->d_name, filename, ascii_case_insensitive_map))
381 if (!this->Load(entry->d_name))
387 /* Loadmodule will now return false if any one of the modules failed
388 * to load (but wont abort when it encounters a bad one) and when 1 or
389 * more modules were actually loaded.
391 return (n_match > 0 ? false : true);
394 char modfile[MAXBUF];
395 snprintf(modfile,MAXBUF,"%s/%s",Instance->Config->ModPath,filename);
396 std::string filename_str = filename;
398 if (!ServerConfig::DirValid(modfile))
400 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?)";
401 Instance->Logs->Log("MODULE", DEFAULT, LastModuleError);
405 if (!ServerConfig::FileExists(modfile))
407 LastModuleError = "Module file could not be found: " + filename_str;
408 Instance->Logs->Log("MODULE", DEFAULT, LastModuleError);
412 if (Modules.find(filename_str) != Modules.end())
414 LastModuleError = "Module " + filename_str + " is already loaded, cannot load a module twice!";
415 Instance->Logs->Log("MODULE", DEFAULT, LastModuleError);
419 Module* newmod = NULL;
420 ircd_module* newhandle = NULL;
424 /* This will throw a CoreException if there's a problem loading
425 * the module file or getting a pointer to the init_module symbol.
427 newhandle = new ircd_module(Instance, modfile, "init_module");
428 newmod = newhandle->CallInit();
432 Version v = newmod->GetVersion();
434 if (v.API != API_VERSION)
439 LastModuleError = "Unable to load " + filename_str + ": Incorrect module API version: " + ConvToStr(v.API) + " (our version: " + ConvToStr(API_VERSION) + ")";
440 Instance->Logs->Log("MODULE", DEFAULT, LastModuleError);
445 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]"));
448 Modules[filename_str] = std::make_pair(newhandle, newmod);
453 LastModuleError = "Unable to load " + filename_str + ": Probably missing init_module() entrypoint, but dlsym() didn't notice a problem";
454 Instance->Logs->Log("MODULE", DEFAULT, LastModuleError);
458 /** XXX: Is there anything we can do about this mess? -- Brain */
459 catch (LoadModuleException& modexcept)
466 LastModuleError = "Unable to load " + filename_str + ": Error when loading: " + modexcept.GetReason();
467 Instance->Logs->Log("MODULE", DEFAULT, LastModuleError);
470 catch (FindSymbolException& modexcept)
477 LastModuleError = "Unable to load " + filename_str + ": Error finding symbol: " + modexcept.GetReason();
478 Instance->Logs->Log("MODULE", DEFAULT, LastModuleError);
481 catch (CoreException& modexcept)
488 LastModuleError = "Unable to load " + filename_str + ": " + modexcept.GetReason();
489 Instance->Logs->Log("MODULE", DEFAULT, LastModuleError);
494 FOREACH_MOD_I(Instance,I_OnLoadModule,OnLoadModule(newmod, filename_str));
496 /* We give every module a chance to re-prioritize when we introduce a new one,
497 * not just the one thats loading, as the new module could affect the preference
500 for (std::map<std::string, std::pair<ircd_module*, Module*> >::iterator n = Modules.begin(); n != Modules.end(); ++n)
501 n->second.second->Prioritize();
503 Instance->BuildISupport();
507 bool ModuleManager::Unload(const char* filename)
509 std::string filename_str(filename);
510 std::map<std::string, std::pair<ircd_module*, Module*> >::iterator modfind = Modules.find(filename);
512 if (modfind != Modules.end())
514 if (modfind->second.second->GetVersion().Flags & VF_STATIC)
516 LastModuleError = "Module " + filename_str + " not unloadable (marked static)";
517 Instance->Logs->Log("MODULE", DEFAULT, LastModuleError);
520 std::pair<int,std::string> intercount = GetInterfaceInstanceCount(modfind->second.second);
521 if (intercount.first > 0)
523 LastModuleError = "Failed to unload module " + filename_str + ", being used by " + ConvToStr(intercount.first) + " other(s) via interface '" + intercount.second + "'";
524 Instance->Logs->Log("MODULE", DEFAULT, LastModuleError);
528 /* Give the module a chance to tidy out all its metadata */
529 for (chan_hash::iterator c = Instance->chanlist->begin(); c != Instance->chanlist->end(); c++)
531 modfind->second.second->OnCleanup(TYPE_CHANNEL,c->second);
533 for (user_hash::iterator u = Instance->Users->clientlist->begin(); u != Instance->Users->clientlist->end(); u++)
535 modfind->second.second->OnCleanup(TYPE_USER,u->second);
538 /* Tidy up any dangling resolvers */
539 Instance->Res->CleanResolvers(modfind->second.second);
542 FOREACH_MOD_I(Instance,I_OnUnloadModule,OnUnloadModule(modfind->second.second, modfind->first));
544 this->DetachAll(modfind->second.second);
546 Instance->Parser->RemoveCommands(filename);
548 delete modfind->second.second;
549 delete modfind->second.first;
550 Modules.erase(modfind);
552 Instance->Logs->Log("MODULE", DEFAULT,"Module %s unloaded",filename);
554 Instance->BuildISupport();
558 LastModuleError = "Module " + filename_str + " is not loaded, cannot unload it!";
559 Instance->Logs->Log("MODULE", DEFAULT, LastModuleError);
563 /* We must load the modules AFTER initializing the socket engine, now */
564 void ModuleManager::LoadAll()
566 char configToken[MAXBUF];
569 for(int count = 0; count < Instance->Config->ConfValueEnum(Instance->Config->config_data, "module"); count++)
571 Instance->Config->ConfValue(Instance->Config->config_data, "module", "name", count, configToken, MAXBUF);
572 printf_c("[\033[1;32m*\033[0m] Loading module:\t\033[1;32m%s\033[0m\n",configToken);
574 if (!this->Load(configToken))
576 Instance->Logs->Log("MODULE", DEFAULT, this->LastError());
577 printf_c("\n[\033[1;31m*\033[0m] %s\n\n", this->LastError().c_str());
578 Instance->Exit(EXIT_STATUS_MODULE);
583 bool ModuleManager::PublishFeature(const std::string &FeatureName, Module* Mod)
585 if (Features.find(FeatureName) == Features.end())
587 Features[FeatureName] = Mod;
593 bool ModuleManager::UnpublishFeature(const std::string &FeatureName)
595 featurelist::iterator iter = Features.find(FeatureName);
597 if (iter == Features.end())
600 Features.erase(iter);
604 Module* ModuleManager::FindFeature(const std::string &FeatureName)
606 featurelist::iterator iter = Features.find(FeatureName);
608 if (iter == Features.end())
614 bool ModuleManager::PublishInterface(const std::string &InterfaceName, Module* Mod)
616 interfacelist::iterator iter = Interfaces.find(InterfaceName);
618 if (iter == Interfaces.end())
622 Interfaces[InterfaceName] = std::make_pair(0, ml);
626 iter->second.second.push_back(Mod);
631 bool ModuleManager::UnpublishInterface(const std::string &InterfaceName, Module* Mod)
633 interfacelist::iterator iter = Interfaces.find(InterfaceName);
635 if (iter == Interfaces.end())
638 for (modulelist::iterator x = iter->second.second.begin(); x != iter->second.second.end(); x++)
642 iter->second.second.erase(x);
643 if (iter->second.second.empty())
644 Interfaces.erase(InterfaceName);
651 modulelist* ModuleManager::FindInterface(const std::string &InterfaceName)
653 interfacelist::iterator iter = Interfaces.find(InterfaceName);
654 if (iter == Interfaces.end())
657 return &(iter->second.second);
660 bool ModuleManager::ModuleHasInterface(Module* mod, const std::string& InterfaceName)
662 interfacelist::iterator iter = Interfaces.find(InterfaceName);
663 if (iter == Interfaces.end())
667 modulelist& ml = iter->second.second;
668 modulelist::iterator mi = std::find(ml.begin(), ml.end(), mod);
669 return (mi != ml.end());
673 void ModuleManager::UseInterface(const std::string &InterfaceName)
675 interfacelist::iterator iter = Interfaces.find(InterfaceName);
676 if (iter != Interfaces.end())
677 iter->second.first++;
681 void ModuleManager::DoneWithInterface(const std::string &InterfaceName)
683 interfacelist::iterator iter = Interfaces.find(InterfaceName);
684 if (iter != Interfaces.end())
685 iter->second.first--;
688 std::pair<int,std::string> ModuleManager::GetInterfaceInstanceCount(Module* m)
690 for (interfacelist::iterator iter = Interfaces.begin(); iter != Interfaces.end(); iter++)
692 for (modulelist::iterator x = iter->second.second.begin(); x != iter->second.second.end(); x++)
696 return std::make_pair(iter->second.first, iter->first);
700 return std::make_pair(0, "");
703 const std::string& ModuleManager::GetModuleName(Module* m)
705 static std::string nothing;
707 for (std::map<std::string, std::pair<ircd_module*, Module*> >::iterator n = Modules.begin(); n != Modules.end(); ++n)
709 if (n->second.second == m)
716 /* This is ugly, yes, but hash_map's arent designed to be
717 * addressed in this manner, and this is a bit of a kludge.
718 * Luckily its a specialist function and rarely used by
719 * many modules (in fact, it was specially created to make
720 * m_safelist possible, initially).
723 Channel* InspIRCd::GetChannelIndex(long index)
726 for (chan_hash::iterator n = this->chanlist->begin(); n != this->chanlist->end(); n++, target++)
734 CmdResult InspIRCd::CallCommandHandler(const std::string &commandname, const std::vector<std::string>& parameters, User* user)
736 return this->Parser->CallHandler(commandname, parameters, user);
739 bool InspIRCd::IsValidModuleCommand(const std::string &commandname, int pcnt, User* user)
741 return this->Parser->IsValidCommand(commandname, pcnt, user);
744 void InspIRCd::AddCommand(Command *f)
746 if (!this->Parser->CreateCommand(f))
748 ModuleException err("Command "+std::string(f->command)+" already exists.");
753 void InspIRCd::SendMode(const std::vector<std::string>& parameters, User *user)
755 this->Modes->Process(parameters, user, true);
758 void InspIRCd::DumpText(User* User, const std::string &LinePrefix, std::stringstream &TextStream)
760 std::string CompleteLine = LinePrefix;
762 while (TextStream >> Word)
764 if (CompleteLine.length() + Word.length() + 3 > 500)
766 User->WriteServ(CompleteLine);
767 CompleteLine = LinePrefix;
769 CompleteLine = CompleteLine + Word + " ";
771 User->WriteServ(CompleteLine);
774 User* FindDescriptorHandler::Call(int socket)
776 return reinterpret_cast<User*>(Server->SE->GetRef(socket));
779 bool InspIRCd::AddResolver(Resolver* r, bool cached)
782 return this->Res->AddResolverClass(r);
785 r->TriggerCachedResult();
791 Module* ModuleManager::Find(const std::string &name)
793 std::map<std::string, std::pair<ircd_module*, Module*> >::iterator modfind = Modules.find(name);
795 if (modfind == Modules.end())
798 return modfind->second.second;
801 const std::vector<std::string> ModuleManager::GetAllModuleNames(int filter)
803 std::vector<std::string> retval;
804 for (std::map<std::string, std::pair<ircd_module*, Module*> >::iterator x = Modules.begin(); x != Modules.end(); ++x)
805 if (!filter || (x->second.second->GetVersion().Flags & filter))
806 retval.push_back(x->first);
810 ConfigReader::ConfigReader(InspIRCd* Instance) : ServerInstance(Instance)
812 this->errorlog = new std::ostringstream(std::stringstream::in | std::stringstream::out);
813 this->error = CONF_NO_ERROR;
814 this->data = &ServerInstance->Config->config_data;
815 this->privatehash = false;
820 ConfigReader::~ConfigReader()
823 delete this->errorlog;
824 if(this->privatehash)
829 ConfigReader::ConfigReader(InspIRCd* Instance, const std::string &filename) : ServerInstance(Instance)
831 ServerInstance->Config->ClearStack();
833 this->error = CONF_NO_ERROR;
834 this->data = new ConfigDataHash;
835 this->privatehash = true;
836 this->errorlog = new std::ostringstream(std::stringstream::in | std::stringstream::out);
837 /*** XXX: This might block! */
838 this->readerror = ServerInstance->Config->DoInclude(*this->data, filename, *this->errorlog);
839 if (!this->readerror)
840 this->error = CONF_FILE_NOT_FOUND;
845 std::string ConfigReader::ReadValue(const std::string &tag, const std::string &name, const std::string &default_value, int index, bool allow_linefeeds)
847 /* Don't need to strlcpy() tag and name anymore, ReadConf() takes const char* */
850 if (!ServerInstance->Config->ConfValue(*this->data, tag, name, default_value, index, result, allow_linefeeds))
852 this->error = CONF_VALUE_NOT_FOUND;
857 std::string ConfigReader::ReadValue(const std::string &tag, const std::string &name, int index, bool allow_linefeeds)
859 return ReadValue(tag, name, "", index, allow_linefeeds);
862 bool ConfigReader::ReadFlag(const std::string &tag, const std::string &name, const std::string &default_value, int index)
864 return ServerInstance->Config->ConfValueBool(*this->data, tag, name, default_value, index);
867 bool ConfigReader::ReadFlag(const std::string &tag, const std::string &name, int index)
869 return ReadFlag(tag, name, "", index);
873 int ConfigReader::ReadInteger(const std::string &tag, const std::string &name, const std::string &default_value, int index, bool need_positive)
877 if(!ServerInstance->Config->ConfValueInteger(*this->data, tag, name, default_value, index, result))
879 this->error = CONF_VALUE_NOT_FOUND;
883 if ((need_positive) && (result < 0))
885 this->error = CONF_INT_NEGATIVE;
892 int ConfigReader::ReadInteger(const std::string &tag, const std::string &name, int index, bool need_positive)
894 return ReadInteger(tag, name, "", index, need_positive);
897 long ConfigReader::GetError()
899 long olderr = this->error;
904 void ConfigReader::DumpErrors(bool bail, User* user)
906 ServerInstance->Config->ReportConfigError(this->errorlog->str(), bail, user->uuid);
910 int ConfigReader::Enumerate(const std::string &tag)
912 return ServerInstance->Config->ConfValueEnum(*this->data, tag);
915 int ConfigReader::EnumerateValues(const std::string &tag, int index)
917 return ServerInstance->Config->ConfVarEnum(*this->data, tag, index);
920 bool ConfigReader::Verify()
922 return this->readerror;
926 FileReader::FileReader(InspIRCd* Instance, const std::string &filename) : ServerInstance(Instance)
931 FileReader::FileReader(InspIRCd* Instance) : ServerInstance(Instance)
935 std::string FileReader::Contents()
938 for (file_cache::iterator a = this->fc.begin(); a != this->fc.end(); a++)
946 unsigned long FileReader::ContentSize()
948 return this->contentsize;
951 void FileReader::CalcSize()
954 for (file_cache::iterator a = this->fc.begin(); a != this->fc.end(); a++)
955 n += (a->length() + 2);
956 this->contentsize = n;
959 void FileReader::LoadFile(const std::string &filename)
963 if (ServerInstance->Config->ReadFile(c,filename.c_str()))
971 FileReader::~FileReader()
975 bool FileReader::Exists()
977 return (!(fc.size() == 0));
980 std::string FileReader::GetLine(int x)
982 if ((x<0) || ((unsigned)x>fc.size()))
987 int FileReader::FileSize()