1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2007 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 * ---------------------------------------------------
15 #include "configreader.h"
22 #include "socketengine.h"
23 #include "command_parse.h"
31 // version is a simple class for holding a modules version number
32 Version::Version(int major, int minor, int revision, int build, int flags, int api_ver)
33 : Major(major), Minor(minor), Revision(revision), Build(build), Flags(flags), API(api_ver)
37 Request::Request(char* anydata, Module* src, Module* dst)
38 : data(anydata), source(src), dest(dst)
40 /* Ensure that because this module doesnt support ID strings, it doesnt break modules that do
41 * by passing them uninitialized pointers (could happen)
46 Request::Request(Module* src, Module* dst, const char* idstr)
47 : id(idstr), source(src), dest(dst)
51 char* Request::GetData()
56 const char* Request::GetId()
61 Module* Request::GetSource()
66 Module* Request::GetDest()
75 return dest->OnRequest(this);
83 Event::Event(char* anydata, Module* src, const std::string &eventid) : data(anydata), source(src), id(eventid) { }
85 char* Event::GetData()
87 return (char*)this->data;
90 Module* Event::GetSource()
95 char* Event::Send(InspIRCd* ServerInstance)
97 FOREACH_MOD(I_OnEvent,OnEvent(this));
101 std::string Event::GetEventID()
107 // These declarations define the behavours of the base class Module (which does nothing at all)
109 Module::Module(InspIRCd* Me) : ServerInstance(Me) { }
110 Module::~Module() { }
111 void Module::OnUserConnect(userrec* user) { }
112 void Module::OnUserQuit(userrec* user, const std::string& message, const std::string &oper_message) { }
113 void Module::OnUserDisconnect(userrec* user) { }
114 void Module::OnUserJoin(userrec* user, chanrec* channel, bool &silent) { }
115 void Module::OnPostJoin(userrec* user, chanrec* channel) { }
116 void Module::OnUserPart(userrec* user, chanrec* channel, const std::string &partmessage, bool &silent) { }
117 void Module::OnRehash(userrec* user, const std::string ¶meter) { }
118 void Module::OnServerRaw(std::string &raw, bool inbound, userrec* user) { }
119 int Module::OnUserPreJoin(userrec* user, chanrec* chan, const char* cname, std::string &privs) { return 0; }
120 void Module::OnMode(userrec* user, void* dest, int target_type, const std::string &text) { }
121 Version Module::GetVersion() { return Version(1,0,0,0,VF_VENDOR,-1); }
122 void Module::OnOper(userrec* user, const std::string &opertype) { }
123 void Module::OnPostOper(userrec* user, const std::string &opertype) { }
124 void Module::OnInfo(userrec* user) { }
125 void Module::OnWhois(userrec* source, userrec* dest) { }
126 int Module::OnUserPreInvite(userrec* source,userrec* dest,chanrec* channel) { return 0; }
127 int Module::OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text,char status, CUList &exempt_list) { return 0; }
128 int Module::OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text,char status, CUList &exempt_list) { return 0; }
129 int Module::OnUserPreNick(userrec* user, const std::string &newnick) { return 0; }
130 void Module::OnUserPostNick(userrec* user, const std::string &oldnick) { }
131 int Module::OnAccessCheck(userrec* source,userrec* dest,chanrec* channel,int access_type) { return ACR_DEFAULT; }
132 void Module::On005Numeric(std::string &output) { }
133 int Module::OnKill(userrec* source, userrec* dest, const std::string &reason) { return 0; }
134 void Module::OnLoadModule(Module* mod,const std::string &name) { }
135 void Module::OnUnloadModule(Module* mod,const std::string &name) { }
136 void Module::OnBackgroundTimer(time_t curtime) { }
137 int Module::OnPreCommand(const std::string &command, const char** parameters, int pcnt, userrec *user, bool validated, const std::string &original_line) { return 0; }
138 void Module::OnPostCommand(const std::string &command, const char** parameters, int pcnt, userrec *user, CmdResult result, const std::string &original_line) { }
139 bool Module::OnCheckReady(userrec* user) { return true; }
140 int Module::OnUserRegister(userrec* user) { return 0; }
141 int Module::OnUserPreKick(userrec* source, userrec* user, chanrec* chan, const std::string &reason) { return 0; }
142 void Module::OnUserKick(userrec* source, userrec* user, chanrec* chan, const std::string &reason, bool &silent) { }
143 int Module::OnCheckInvite(userrec* user, chanrec* chan) { return 0; }
144 int Module::OnCheckKey(userrec* user, chanrec* chan, const std::string &keygiven) { return 0; }
145 int Module::OnCheckLimit(userrec* user, chanrec* chan) { return 0; }
146 int Module::OnCheckBan(userrec* user, chanrec* chan) { return 0; }
147 int Module::OnStats(char symbol, userrec* user, string_list &results) { return 0; }
148 int Module::OnChangeLocalUserHost(userrec* user, const std::string &newhost) { return 0; }
149 int Module::OnChangeLocalUserGECOS(userrec* user, const std::string &newhost) { return 0; }
150 int Module::OnLocalTopicChange(userrec* user, chanrec* chan, const std::string &topic) { return 0; }
151 void Module::OnEvent(Event* event) { return; }
152 char* Module::OnRequest(Request* request) { return NULL; }
153 int Module::OnOperCompare(const std::string &password, const std::string &input, int tagnumber) { return 0; }
154 void Module::OnGlobalOper(userrec* user) { }
155 void Module::OnPostConnect(userrec* user) { }
156 int Module::OnAddBan(userrec* source, chanrec* channel,const std::string &banmask) { return 0; }
157 int Module::OnDelBan(userrec* source, chanrec* channel,const std::string &banmask) { return 0; }
158 void Module::OnRawSocketAccept(int fd, const std::string &ip, int localport) { }
159 int Module::OnRawSocketWrite(int fd, const char* buffer, int count) { return 0; }
160 void Module::OnRawSocketClose(int fd) { }
161 void Module::OnRawSocketConnect(int fd) { }
162 int Module::OnRawSocketRead(int fd, char* buffer, unsigned int count, int &readresult) { return 0; }
163 void Module::OnUserMessage(userrec* user, void* dest, int target_type, const std::string &text, char status, const CUList &exempt_list) { }
164 void Module::OnUserNotice(userrec* user, void* dest, int target_type, const std::string &text, char status, const CUList &exempt_list) { }
165 void Module::OnRemoteKill(userrec* source, userrec* dest, const std::string &reason, const std::string &operreason) { }
166 void Module::OnUserInvite(userrec* source,userrec* dest,chanrec* channel) { }
167 void Module::OnPostLocalTopicChange(userrec* user, chanrec* chan, const std::string &topic) { }
168 void Module::OnGetServerDescription(const std::string &servername,std::string &description) { }
169 void Module::OnSyncUser(userrec* user, Module* proto, void* opaque) { }
170 void Module::OnSyncChannel(chanrec* chan, Module* proto, void* opaque) { }
171 void Module::ProtoSendMode(void* opaque, int target_type, void* target, const std::string &modeline) { }
172 void Module::OnSyncChannelMetaData(chanrec* chan, Module* proto,void* opaque, const std::string &extname, bool displayable) { }
173 void Module::OnSyncUserMetaData(userrec* user, Module* proto,void* opaque, const std::string &extname, bool displayable) { }
174 void Module::OnSyncOtherMetaData(Module* proto, void* opaque, bool displayable) { }
175 void Module::OnDecodeMetaData(int target_type, void* target, const std::string &extname, const std::string &extdata) { }
176 void Module::ProtoSendMetaData(void* opaque, int target_type, void* target, const std::string &extname, const std::string &extdata) { }
177 void Module::OnWallops(userrec* user, const std::string &text) { }
178 void Module::OnChangeHost(userrec* user, const std::string &newhost) { }
179 void Module::OnChangeName(userrec* user, const std::string &gecos) { }
180 void Module::OnAddGLine(long duration, userrec* source, const std::string &reason, const std::string &hostmask) { }
181 void Module::OnAddZLine(long duration, userrec* source, const std::string &reason, const std::string &ipmask) { }
182 void Module::OnAddKLine(long duration, userrec* source, const std::string &reason, const std::string &hostmask) { }
183 void Module::OnAddQLine(long duration, userrec* source, const std::string &reason, const std::string &nickmask) { }
184 void Module::OnAddELine(long duration, userrec* source, const std::string &reason, const std::string &hostmask) { }
185 void Module::OnDelGLine(userrec* source, const std::string &hostmask) { }
186 void Module::OnDelZLine(userrec* source, const std::string &ipmask) { }
187 void Module::OnDelKLine(userrec* source, const std::string &hostmask) { }
188 void Module::OnDelQLine(userrec* source, const std::string &nickmask) { }
189 void Module::OnDelELine(userrec* source, const std::string &hostmask) { }
190 void Module::OnCleanup(int target_type, void* item) { }
191 void Module::Implements(char* Implements) { for (int j = 0; j < 255; j++) Implements[j] = 0; }
192 void Module::OnChannelDelete(chanrec* chan) { }
193 Priority Module::Prioritize() { return PRIORITY_DONTCARE; }
194 void Module::OnSetAway(userrec* user) { }
195 void Module::OnCancelAway(userrec* user) { }
196 int Module::OnUserList(userrec* user, chanrec* Ptr, CUList* &userlist) { return 0; }
197 int Module::OnWhoisLine(userrec* user, userrec* dest, int &numeric, std::string &text) { return 0; }
198 void Module::OnBuildExemptList(MessageType message_type, chanrec* chan, userrec* sender, char status, CUList &exempt_list) { }
199 void Module::OnGarbageCollect() { }
200 void Module::OnBufferFlushed(userrec* user) { }
203 char* InspIRCd::ModuleError()
208 void InspIRCd::EraseFactory(int j)
211 for (std::vector<ircd_module*>::iterator t = factory.begin(); t != factory.end(); t++)
217 factory.push_back(NULL);
224 void InspIRCd::EraseModule(int j)
227 for (ModuleList::iterator m = modules.begin(); m!= modules.end(); m++)
233 modules.push_back(NULL);
239 for (std::vector<std::string>::iterator v = Config->module_names.begin(); v != Config->module_names.end(); v++)
243 Config->module_names.erase(v);
251 void InspIRCd::MoveTo(std::string modulename,int slot)
253 unsigned int v2 = 256;
254 for (unsigned int v = 0; v < Config->module_names.size(); v++)
256 if (Config->module_names[v] == modulename)
258 // found an instance, swap it with the item at the end
263 if ((v2 != (unsigned int)slot) && (v2 < 256))
265 // Swap the module names over
266 Config->module_names[v2] = Config->module_names[slot];
267 Config->module_names[slot] = modulename;
268 // now swap the module factories
269 ircd_module* temp = factory[v2];
270 factory[v2] = factory[slot];
271 factory[slot] = temp;
272 // now swap the module objects
273 Module* temp_module = modules[v2];
274 modules[v2] = modules[slot];
275 modules[slot] = temp_module;
276 // now swap the implement lists (we dont
277 // need to swap the global or recount it)
278 for (int n = 0; n < 255; n++)
280 char x = Config->implement_lists[v2][n];
281 Config->implement_lists[v2][n] = Config->implement_lists[slot][n];
282 Config->implement_lists[slot][n] = x;
287 void InspIRCd::MoveAfter(std::string modulename, std::string after)
289 for (unsigned int v = 0; v < Config->module_names.size(); v++)
291 if (Config->module_names[v] == after)
293 MoveTo(modulename, v);
299 void InspIRCd::MoveBefore(std::string modulename, std::string before)
301 for (unsigned int v = 0; v < Config->module_names.size(); v++)
303 if (Config->module_names[v] == before)
307 MoveTo(modulename, v-1);
311 MoveTo(modulename, v);
318 void InspIRCd::MoveToFirst(std::string modulename)
320 MoveTo(modulename,0);
323 void InspIRCd::MoveToLast(std::string modulename)
325 MoveTo(modulename,this->GetModuleCount());
328 bool InspIRCd::UnloadModule(const char* filename)
330 std::string filename_str = filename;
331 for (unsigned int j = 0; j != Config->module_names.size(); j++)
333 if (Config->module_names[j] == filename_str)
335 if (modules[j]->GetVersion().Flags & VF_STATIC)
337 this->Log(DEFAULT,"Failed to unload STATIC module %s",filename);
338 snprintf(MODERR,MAXBUF,"Module not unloadable (marked static)");
341 std::pair<int,std::string> intercount = GetInterfaceInstanceCount(modules[j]);
342 if (intercount.first > 0)
344 this->Log(DEFAULT,"Failed to unload module %s, being used by %d other(s) via interface '%s'",filename, intercount.first, intercount.second.c_str());
345 snprintf(MODERR,MAXBUF,"Module not unloadable (Still in use by %d other module%s which %s using its interface '%s') -- unload dependent modules first!",
347 intercount.first > 1 ? "s" : "",
348 intercount.first > 1 ? "are" : "is",
349 intercount.second.c_str());
352 /* Give the module a chance to tidy out all its metadata */
353 for (chan_hash::iterator c = this->chanlist->begin(); c != this->chanlist->end(); c++)
355 modules[j]->OnCleanup(TYPE_CHANNEL,c->second);
357 for (user_hash::iterator u = this->clientlist->begin(); u != this->clientlist->end(); u++)
359 modules[j]->OnCleanup(TYPE_USER,u->second);
362 /* Tidy up any dangling resolvers */
363 this->Res->CleanResolvers(modules[j]);
365 FOREACH_MOD_I(this,I_OnUnloadModule,OnUnloadModule(modules[j],Config->module_names[j]));
367 for(int t = 0; t < 255; t++)
369 Config->global_implementation[t] -= Config->implement_lists[j][t];
372 /* We have to renumber implement_lists after unload because the module numbers change!
374 for(int j2 = j; j2 < 254; j2++)
376 for(int t = 0; t < 255; t++)
378 Config->implement_lists[j2][t] = Config->implement_lists[j2+1][t];
383 Parser->RemoveCommands(filename);
384 this->EraseModule(j);
385 this->EraseFactory(j);
386 this->Log(DEFAULT,"Module %s unloaded",filename);
392 this->Log(DEFAULT,"Module %s is not loaded, cannot unload it!",filename);
393 snprintf(MODERR,MAXBUF,"Module not loaded");
397 bool InspIRCd::LoadModule(const char* filename)
399 /* Do we have a glob pattern in the filename?
400 * The user wants to load multiple modules which
403 if (strchr(filename,'*') || (strchr(filename,'?')))
406 DIR* library = opendir(Config->ModPath);
409 /* Try and locate and load all modules matching the pattern */
410 dirent* entry = NULL;
411 while ((entry = readdir(library)))
413 if (this->MatchText(entry->d_name, filename))
415 if (!this->LoadModule(entry->d_name))
421 /* Loadmodule will now return false if any one of the modules failed
422 * to load (but wont abort when it encounters a bad one) and when 1 or
423 * more modules were actually loaded.
425 return (n_match > 0);
428 char modfile[MAXBUF];
429 snprintf(modfile,MAXBUF,"%s/%s",Config->ModPath,filename);
430 std::string filename_str = filename;
432 if (!ServerConfig::DirValid(modfile))
434 this->Log(DEFAULT,"Module %s is not within the modules directory.",modfile);
435 snprintf(MODERR,MAXBUF,"Module %s is not within the modules directory.",modfile);
438 if (ServerConfig::FileExists(modfile))
441 for (unsigned int j = 0; j < Config->module_names.size(); j++)
443 if (Config->module_names[j] == filename_str)
445 this->Log(DEFAULT,"Module %s is already loaded, cannot load a module twice!",modfile);
446 snprintf(MODERR,MAXBUF,"Module already loaded");
451 ircd_module* a = NULL;
454 a = new ircd_module(this, modfile);
455 factory[this->ModCount+1] = a;
456 if (factory[this->ModCount+1]->LastError())
458 this->Log(DEFAULT,"Unable to load %s: %s",modfile,factory[this->ModCount+1]->LastError());
459 snprintf(MODERR,MAXBUF,"Loader/Linker error: %s",factory[this->ModCount+1]->LastError());
462 if ((long)factory[this->ModCount+1]->factory != -1)
464 m = factory[this->ModCount+1]->factory->CreateModule(this);
466 Version v = m->GetVersion();
468 if (v.API != API_VERSION)
471 this->Log(DEFAULT,"Unable to load %s: Incorrect module API version: %d (our version: %d)",modfile,v.API,API_VERSION);
472 snprintf(MODERR,MAXBUF,"Loader/Linker error: Incorrect module API version: %d (our version: %d)",v.API,API_VERSION);
477 this->Log(DEFAULT,"New module introduced: %s (API version %d, Module version %d.%d.%d.%d)%s", filename, v.API, v.Major, v.Minor, v.Revision, v.Build, (!(v.Flags & VF_VENDOR) ? " [3rd Party]" : " [Vendor]"));
480 modules[this->ModCount+1] = m;
481 /* save the module and the module's classfactory, if
482 * this isnt done, random crashes can occur :/ */
483 Config->module_names.push_back(filename);
485 char* x = &Config->implement_lists[this->ModCount+1][0];
486 for(int t = 0; t < 255; t++)
489 modules[this->ModCount+1]->Implements(x);
491 for(int t = 0; t < 255; t++)
492 Config->global_implementation[t] += Config->implement_lists[this->ModCount+1][t];
496 this->Log(DEFAULT,"Unable to load %s",modfile);
497 snprintf(MODERR,MAXBUF,"Factory function failed: Probably missing init_module() entrypoint.");
501 catch (CoreException& modexcept)
503 this->Log(DEFAULT,"Unable to load %s: %s",modfile,modexcept.GetReason());
504 snprintf(MODERR,MAXBUF,"Factory function of %s threw an exception: %s", modexcept.GetSource(), modexcept.GetReason());
510 this->Log(DEFAULT,"InspIRCd: startup: Module Not Found %s",modfile);
511 snprintf(MODERR,MAXBUF,"Module file could not be found");
515 FOREACH_MOD_I(this,I_OnLoadModule,OnLoadModule(modules[this->ModCount],filename_str));
516 // now work out which modules, if any, want to move to the back of the queue,
517 // and if they do, move them there.
518 std::vector<std::string> put_to_back;
519 std::vector<std::string> put_to_front;
520 std::map<std::string,std::string> put_before;
521 std::map<std::string,std::string> put_after;
522 for (unsigned int j = 0; j < Config->module_names.size(); j++)
524 if (modules[j]->Prioritize() == PRIORITY_LAST)
525 put_to_back.push_back(Config->module_names[j]);
526 else if (modules[j]->Prioritize() == PRIORITY_FIRST)
527 put_to_front.push_back(Config->module_names[j]);
528 else if ((modules[j]->Prioritize() & 0xFF) == PRIORITY_BEFORE)
529 put_before[Config->module_names[j]] = Config->module_names[modules[j]->Prioritize() >> 8];
530 else if ((modules[j]->Prioritize() & 0xFF) == PRIORITY_AFTER)
531 put_after[Config->module_names[j]] = Config->module_names[modules[j]->Prioritize() >> 8];
533 for (unsigned int j = 0; j < put_to_back.size(); j++)
534 MoveToLast(put_to_back[j]);
535 for (unsigned int j = 0; j < put_to_front.size(); j++)
536 MoveToFirst(put_to_front[j]);
537 for (std::map<std::string,std::string>::iterator j = put_before.begin(); j != put_before.end(); j++)
538 MoveBefore(j->first,j->second);
539 for (std::map<std::string,std::string>::iterator j = put_after.begin(); j != put_after.end(); j++)
540 MoveAfter(j->first,j->second);
545 long InspIRCd::PriorityAfter(const std::string &modulename)
547 for (unsigned int j = 0; j < this->Config->module_names.size(); j++)
549 if (this->Config->module_names[j] == modulename)
551 return ((j << 8) | PRIORITY_AFTER);
554 return PRIORITY_DONTCARE;
557 long InspIRCd::PriorityBefore(const std::string &modulename)
559 for (unsigned int j = 0; j < this->Config->module_names.size(); j++)
561 if (this->Config->module_names[j] == modulename)
563 return ((j << 8) | PRIORITY_BEFORE);
566 return PRIORITY_DONTCARE;
569 bool InspIRCd::PublishFeature(const std::string &FeatureName, Module* Mod)
571 if (Features.find(FeatureName) == Features.end())
573 Features[FeatureName] = Mod;
579 bool InspIRCd::UnpublishFeature(const std::string &FeatureName)
581 featurelist::iterator iter = Features.find(FeatureName);
583 if (iter == Features.end())
586 Features.erase(iter);
590 Module* InspIRCd::FindFeature(const std::string &FeatureName)
592 featurelist::iterator iter = Features.find(FeatureName);
594 if (iter == Features.end())
600 bool InspIRCd::PublishInterface(const std::string &InterfaceName, Module* Mod)
602 interfacelist::iterator iter = Interfaces.find(InterfaceName);
604 if (iter == Interfaces.end())
608 Interfaces[InterfaceName] = std::make_pair(0, ml);
613 iter->second.second.push_back(Mod);
619 bool InspIRCd::UnpublishInterface(const std::string &InterfaceName, Module* Mod)
621 interfacelist::iterator iter = Interfaces.find(InterfaceName);
623 if (iter == Interfaces.end())
626 for (modulelist::iterator x = iter->second.second.begin(); x != iter->second.second.end(); x++)
630 iter->second.second.erase(x);
631 if (iter->second.second.empty())
632 Interfaces.erase(InterfaceName);
639 modulelist* InspIRCd::FindInterface(const std::string &InterfaceName)
641 interfacelist::iterator iter = Interfaces.find(InterfaceName);
642 if (iter == Interfaces.end())
645 return &(iter->second.second);
648 void InspIRCd::UseInterface(const std::string &InterfaceName)
650 interfacelist::iterator iter = Interfaces.find(InterfaceName);
651 if (iter != Interfaces.end())
652 iter->second.first++;
656 void InspIRCd::DoneWithInterface(const std::string &InterfaceName)
658 interfacelist::iterator iter = Interfaces.find(InterfaceName);
659 if (iter != Interfaces.end())
660 iter->second.first--;
663 std::pair<int,std::string> InspIRCd::GetInterfaceInstanceCount(Module* m)
665 for (interfacelist::iterator iter = Interfaces.begin(); iter != Interfaces.end(); iter++)
667 for (modulelist::iterator x = iter->second.second.begin(); x != iter->second.second.end(); x++)
671 return std::make_pair(iter->second.first, iter->first);
675 return std::make_pair(0, "");
678 const std::string& InspIRCd::GetModuleName(Module* m)
680 static std::string nothing; /* Prevent compiler warning */
682 if (!this->GetModuleCount())
685 for (int i = 0; i <= this->GetModuleCount(); i++)
687 if (this->modules[i] == m)
689 return this->Config->module_names[i];
692 return nothing; /* As above */
695 /* This is ugly, yes, but hash_map's arent designed to be
696 * addressed in this manner, and this is a bit of a kludge.
697 * Luckily its a specialist function and rarely used by
698 * many modules (in fact, it was specially created to make
699 * m_safelist possible, initially).
702 chanrec* InspIRCd::GetChannelIndex(long index)
705 for (chan_hash::iterator n = this->chanlist->begin(); n != this->chanlist->end(); n++, target++)
713 bool InspIRCd::MatchText(const std::string &sliteral, const std::string &spattern)
715 return match(sliteral.c_str(),spattern.c_str());
718 CmdResult InspIRCd::CallCommandHandler(const std::string &commandname, const char** parameters, int pcnt, userrec* user)
720 return this->Parser->CallHandler(commandname,parameters,pcnt,user);
723 bool InspIRCd::IsValidModuleCommand(const std::string &commandname, int pcnt, userrec* user)
725 return this->Parser->IsValidCommand(commandname, pcnt, user);
728 void InspIRCd::AddCommand(command_t *f)
730 if (!this->Parser->CreateCommand(f))
732 ModuleException err("Command "+std::string(f->command)+" already exists.");
737 void InspIRCd::SendMode(const char** parameters, int pcnt, userrec *user)
739 this->Modes->Process(parameters,pcnt,user,true);
742 void InspIRCd::DumpText(userrec* User, const std::string &LinePrefix, stringstream &TextStream)
744 std::string CompleteLine = LinePrefix;
746 while (TextStream >> Word)
748 if (CompleteLine.length() + Word.length() + 3 > 500)
750 User->WriteServ(CompleteLine);
751 CompleteLine = LinePrefix;
753 CompleteLine = CompleteLine + Word + " ";
755 User->WriteServ(CompleteLine);
758 userrec* FindDescriptorHandler::Call(int socket)
760 return reinterpret_cast<userrec*>(Server->SE->GetRef(socket));
763 bool InspIRCd::AddMode(ModeHandler* mh, const unsigned char mode)
765 return this->Modes->AddMode(mh,mode);
768 bool InspIRCd::AddModeWatcher(ModeWatcher* mw)
770 return this->Modes->AddModeWatcher(mw);
773 bool InspIRCd::DelModeWatcher(ModeWatcher* mw)
775 return this->Modes->DelModeWatcher(mw);
778 bool InspIRCd::AddResolver(Resolver* r, bool cached)
781 return this->Res->AddResolverClass(r);
784 r->TriggerCachedResult();
790 void InspIRCd::AddGLine(long duration, const std::string &source, const std::string &reason, const std::string &hostmask)
792 XLines->add_gline(duration, source.c_str(), reason.c_str(), hostmask.c_str());
793 XLines->apply_lines(APPLY_GLINES);
796 void InspIRCd::AddQLine(long duration, const std::string &source, const std::string &reason, const std::string &nickname)
798 XLines->add_qline(duration, source.c_str(), reason.c_str(), nickname.c_str());
799 XLines->apply_lines(APPLY_QLINES);
802 void InspIRCd::AddZLine(long duration, const std::string &source, const std::string &reason, const std::string &ipaddr)
804 XLines->add_zline(duration, source.c_str(), reason.c_str(), ipaddr.c_str());
805 XLines->apply_lines(APPLY_ZLINES);
808 void InspIRCd::AddKLine(long duration, const std::string &source, const std::string &reason, const std::string &hostmask)
810 XLines->add_kline(duration, source.c_str(), reason.c_str(), hostmask.c_str());
811 XLines->apply_lines(APPLY_KLINES);
814 void InspIRCd::AddELine(long duration, const std::string &source, const std::string &reason, const std::string &hostmask)
816 XLines->add_eline(duration, source.c_str(), reason.c_str(), hostmask.c_str());
819 bool InspIRCd::DelGLine(const std::string &hostmask)
821 return XLines->del_gline(hostmask.c_str());
824 bool InspIRCd::DelQLine(const std::string &nickname)
826 return XLines->del_qline(nickname.c_str());
829 bool InspIRCd::DelZLine(const std::string &ipaddr)
831 return XLines->del_zline(ipaddr.c_str());
834 bool InspIRCd::DelKLine(const std::string &hostmask)
836 return XLines->del_kline(hostmask.c_str());
839 bool InspIRCd::DelELine(const std::string &hostmask)
841 return XLines->del_eline(hostmask.c_str());
845 * XXX why on *earth* is this in modules.cpp...? I think
846 * perhaps we need a server.cpp for InspIRCd:: stuff where possible. -- w00t
848 bool InspIRCd::IsValidMask(const std::string &mask)
850 char* dest = (char*)mask.c_str();
854 for (char* i = dest; *i; i++)
856 /* out of range character, bad mask */
857 if (*i < 32 || *i > 126)
873 /* valid masks only have 1 ! and @ */
874 if (exclamation != 1 || atsign != 1)
880 Module* InspIRCd::FindModule(const std::string &name)
882 for (int i = 0; i <= this->GetModuleCount(); i++)
884 if (this->Config->module_names[i] == name)
886 return this->modules[i];
892 ConfigReader::ConfigReader(InspIRCd* Instance) : ServerInstance(Instance)
894 /* Is there any reason to load the entire config file again here?
895 * it's needed if they specify another config file, but using the
896 * default one we can just use the global config data - pre-parsed!
898 this->errorlog = new std::ostringstream(std::stringstream::in | std::stringstream::out);
900 this->data = &ServerInstance->Config->config_data;
901 this->privatehash = false;
905 ConfigReader::~ConfigReader()
908 DELETE(this->errorlog);
909 if(this->privatehash)
914 ConfigReader::ConfigReader(InspIRCd* Instance, const std::string &filename) : ServerInstance(Instance)
916 ServerInstance->Config->ClearStack();
918 this->data = new ConfigDataHash;
919 this->privatehash = true;
920 this->errorlog = new std::ostringstream(std::stringstream::in | std::stringstream::out);
921 this->readerror = ServerInstance->Config->LoadConf(*this->data, filename, *this->errorlog);
922 if (!this->readerror)
923 this->error = CONF_FILE_NOT_FOUND;
927 std::string ConfigReader::ReadValue(const std::string &tag, const std::string &name, const std::string &default_value, int index, bool allow_linefeeds)
929 /* Don't need to strlcpy() tag and name anymore, ReadConf() takes const char* */
932 if (!ServerInstance->Config->ConfValue(*this->data, tag, name, default_value, index, result, allow_linefeeds))
934 this->error = CONF_VALUE_NOT_FOUND;
939 std::string ConfigReader::ReadValue(const std::string &tag, const std::string &name, int index, bool allow_linefeeds)
941 return ReadValue(tag, name, "", index, allow_linefeeds);
944 bool ConfigReader::ReadFlag(const std::string &tag, const std::string &name, const std::string &default_value, int index)
946 return ServerInstance->Config->ConfValueBool(*this->data, tag, name, default_value, index);
949 bool ConfigReader::ReadFlag(const std::string &tag, const std::string &name, int index)
951 return ReadFlag(tag, name, "", index);
955 long ConfigReader::ReadInteger(const std::string &tag, const std::string &name, const std::string &default_value, int index, bool needs_unsigned)
959 if(!ServerInstance->Config->ConfValueInteger(*this->data, tag, name, default_value, index, result))
961 this->error = CONF_VALUE_NOT_FOUND;
965 if ((needs_unsigned) && (result < 0))
967 this->error = CONF_NOT_UNSIGNED;
974 long ConfigReader::ReadInteger(const std::string &tag, const std::string &name, int index, bool needs_unsigned)
976 return ReadInteger(tag, name, "", index, needs_unsigned);
979 long ConfigReader::GetError()
981 long olderr = this->error;
986 void ConfigReader::DumpErrors(bool bail, userrec* user)
988 ServerInstance->Config->ReportConfigError(this->errorlog->str(), bail, user);
992 int ConfigReader::Enumerate(const std::string &tag)
994 return ServerInstance->Config->ConfValueEnum(*this->data, tag);
997 int ConfigReader::EnumerateValues(const std::string &tag, int index)
999 return ServerInstance->Config->ConfVarEnum(*this->data, tag, index);
1002 bool ConfigReader::Verify()
1004 return this->readerror;
1008 FileReader::FileReader(InspIRCd* Instance, const std::string &filename) : ServerInstance(Instance)
1013 FileReader::FileReader(InspIRCd* Instance) : ServerInstance(Instance)
1017 std::string FileReader::Contents()
1020 for (file_cache::iterator a = this->fc.begin(); a != this->fc.end(); a++)
1028 unsigned long FileReader::ContentSize()
1030 return this->contentsize;
1033 void FileReader::CalcSize()
1035 unsigned long n = 0;
1036 for (file_cache::iterator a = this->fc.begin(); a != this->fc.end(); a++)
1037 n += (a->length() + 2);
1038 this->contentsize = n;
1041 void FileReader::LoadFile(const std::string &filename)
1045 if (ServerInstance->Config->ReadFile(c,filename.c_str()))
1053 FileReader::~FileReader()
1057 bool FileReader::Exists()
1059 return (!(fc.size() == 0));
1062 std::string FileReader::GetLine(int x)
1064 if ((x<0) || ((unsigned)x>fc.size()))
1069 int FileReader::FileSize()