]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules.cpp
OOPS! We try again, since I'm smoking craq. LF is 0x0a NOT CR.
[user/henk/code/inspircd.git] / src / modules.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2007 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include "inspircd.h"
15 #include "configreader.h"
16 #include "users.h"
17 #include "modules.h"
18 #include "wildcard.h"
19 #include "mode.h"
20 #include "xline.h"
21 #include "socket.h"
22 #include "socketengine.h"
23 #include "command_parse.h"
24 #include "dns.h"
25
26 // version is a simple class for holding a modules version number
27 Version::Version(int major, int minor, int revision, int build, int flags, int api_ver)
28 : Major(major), Minor(minor), Revision(revision), Build(build), Flags(flags), API(api_ver)
29 {
30 }
31
32 Request::Request(char* anydata, Module* src, Module* dst)
33 : data(anydata), source(src), dest(dst)
34 {
35         /* Ensure that because this module doesnt support ID strings, it doesnt break modules that do
36          * by passing them uninitialized pointers (could happen)
37          */
38         id = '\0';
39 }
40
41 Request::Request(Module* src, Module* dst, const char* idstr)
42 : id(idstr), source(src), dest(dst)
43 {
44 }
45
46 char* Request::GetData()
47 {
48         return this->data;
49 }
50
51 const char* Request::GetId()
52 {
53         return this->id;
54 }
55
56 Module* Request::GetSource()
57 {
58         return this->source;
59 }
60
61 Module* Request::GetDest()
62 {
63         return this->dest;
64 }
65
66 char* Request::Send()
67 {
68         if (this->dest)
69         {
70                 return dest->OnRequest(this);
71         }
72         else
73         {
74                 return NULL;
75         }
76 }
77
78 Event::Event(char* anydata, Module* src, const std::string &eventid) : data(anydata), source(src), id(eventid) { }
79
80 char* Event::GetData()
81 {
82         return (char*)this->data;
83 }
84
85 Module* Event::GetSource()
86 {
87         return this->source;
88 }
89
90 char* Event::Send(InspIRCd* ServerInstance)
91 {
92         FOREACH_MOD(I_OnEvent,OnEvent(this));
93         return NULL;
94 }
95
96 std::string Event::GetEventID()
97 {
98         return this->id;
99 }
100
101
102 // These declarations define the behavours of the base class Module (which does nothing at all)
103
104                 Module::Module(InspIRCd* Me) : ServerInstance(Me) { }
105                 Module::~Module() { }
106 void            Module::OnUserConnect(userrec* user) { }
107 void            Module::OnUserQuit(userrec* user, const std::string& message, const std::string &oper_message) { }
108 void            Module::OnUserDisconnect(userrec* user) { }
109 void            Module::OnUserJoin(userrec* user, chanrec* channel, bool &silent) { }
110 void            Module::OnPostJoin(userrec* user, chanrec* channel) { }
111 void            Module::OnUserPart(userrec* user, chanrec* channel, const std::string &partmessage, bool &silent) { }
112 void            Module::OnRehash(userrec* user, const std::string &parameter) { }
113 void            Module::OnServerRaw(std::string &raw, bool inbound, userrec* user) { }
114 int             Module::OnUserPreJoin(userrec* user, chanrec* chan, const char* cname, std::string &privs) { return 0; }
115 void            Module::OnMode(userrec* user, void* dest, int target_type, const std::string &text) { }
116 Version         Module::GetVersion() { return Version(1,0,0,0,VF_VENDOR,-1); }
117 void            Module::OnOper(userrec* user, const std::string &opertype) { }
118 void            Module::OnPostOper(userrec* user, const std::string &opertype) { }
119 void            Module::OnInfo(userrec* user) { }
120 void            Module::OnWhois(userrec* source, userrec* dest) { }
121 int             Module::OnUserPreInvite(userrec* source,userrec* dest,chanrec* channel) { return 0; }
122 int             Module::OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text,char status, CUList &exempt_list) { return 0; }
123 int             Module::OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text,char status, CUList &exempt_list) { return 0; }
124 int             Module::OnUserPreNick(userrec* user, const std::string &newnick) { return 0; }
125 void            Module::OnUserPostNick(userrec* user, const std::string &oldnick) { }
126 int             Module::OnAccessCheck(userrec* source,userrec* dest,chanrec* channel,int access_type) { return ACR_DEFAULT; }
127 void            Module::On005Numeric(std::string &output) { }
128 int             Module::OnKill(userrec* source, userrec* dest, const std::string &reason) { return 0; }
129 void            Module::OnLoadModule(Module* mod,const std::string &name) { }
130 void            Module::OnUnloadModule(Module* mod,const std::string &name) { }
131 void            Module::OnBackgroundTimer(time_t curtime) { }
132 int             Module::OnPreCommand(const std::string &command, const char** parameters, int pcnt, userrec *user, bool validated, const std::string &original_line) { return 0; }
133 void            Module::OnPostCommand(const std::string &command, const char** parameters, int pcnt, userrec *user, CmdResult result, const std::string &original_line) { }
134 bool            Module::OnCheckReady(userrec* user) { return true; }
135 int             Module::OnUserRegister(userrec* user) { return 0; }
136 int             Module::OnUserPreKick(userrec* source, userrec* user, chanrec* chan, const std::string &reason) { return 0; }
137 void            Module::OnUserKick(userrec* source, userrec* user, chanrec* chan, const std::string &reason, bool &silent) { }
138 int             Module::OnCheckInvite(userrec* user, chanrec* chan) { return 0; }
139 int             Module::OnCheckKey(userrec* user, chanrec* chan, const std::string &keygiven) { return 0; }
140 int             Module::OnCheckLimit(userrec* user, chanrec* chan) { return 0; }
141 int             Module::OnCheckBan(userrec* user, chanrec* chan) { return 0; }
142 int             Module::OnStats(char symbol, userrec* user, string_list &results) { return 0; }
143 int             Module::OnChangeLocalUserHost(userrec* user, const std::string &newhost) { return 0; }
144 int             Module::OnChangeLocalUserGECOS(userrec* user, const std::string &newhost) { return 0; }
145 int             Module::OnLocalTopicChange(userrec* user, chanrec* chan, const std::string &topic) { return 0; }
146 void            Module::OnEvent(Event* event) { return; }
147 char*           Module::OnRequest(Request* request) { return NULL; }
148 int             Module::OnOperCompare(const std::string &password, const std::string &input, int tagnumber) { return 0; }
149 void            Module::OnGlobalOper(userrec* user) { }
150 void            Module::OnPostConnect(userrec* user) { }
151 int             Module::OnAddBan(userrec* source, chanrec* channel,const std::string &banmask) { return 0; }
152 int             Module::OnDelBan(userrec* source, chanrec* channel,const std::string &banmask) { return 0; }
153 void            Module::OnRawSocketAccept(int fd, const std::string &ip, int localport) { }
154 int             Module::OnRawSocketWrite(int fd, const char* buffer, int count) { return 0; }
155 void            Module::OnRawSocketClose(int fd) { }
156 void            Module::OnRawSocketConnect(int fd) { }
157 int             Module::OnRawSocketRead(int fd, char* buffer, unsigned int count, int &readresult) { return 0; }
158 void            Module::OnUserMessage(userrec* user, void* dest, int target_type, const std::string &text, char status, const CUList &exempt_list) { }
159 void            Module::OnUserNotice(userrec* user, void* dest, int target_type, const std::string &text, char status, const CUList &exempt_list) { }
160 void            Module::OnRemoteKill(userrec* source, userrec* dest, const std::string &reason, const std::string &operreason) { }
161 void            Module::OnUserInvite(userrec* source,userrec* dest,chanrec* channel) { }
162 void            Module::OnPostLocalTopicChange(userrec* user, chanrec* chan, const std::string &topic) { }
163 void            Module::OnGetServerDescription(const std::string &servername,std::string &description) { }
164 void            Module::OnSyncUser(userrec* user, Module* proto, void* opaque) { }
165 void            Module::OnSyncChannel(chanrec* chan, Module* proto, void* opaque) { }
166 void            Module::ProtoSendMode(void* opaque, int target_type, void* target, const std::string &modeline) { }
167 void            Module::OnSyncChannelMetaData(chanrec* chan, Module* proto,void* opaque, const std::string &extname, bool displayable) { }
168 void            Module::OnSyncUserMetaData(userrec* user, Module* proto,void* opaque, const std::string &extname, bool displayable) { }
169 void            Module::OnSyncOtherMetaData(Module* proto, void* opaque, bool displayable) { }
170 void            Module::OnDecodeMetaData(int target_type, void* target, const std::string &extname, const std::string &extdata) { }
171 void            Module::ProtoSendMetaData(void* opaque, int target_type, void* target, const std::string &extname, const std::string &extdata) { }
172 void            Module::OnWallops(userrec* user, const std::string &text) { }
173 void            Module::OnChangeHost(userrec* user, const std::string &newhost) { }
174 void            Module::OnChangeName(userrec* user, const std::string &gecos) { }
175 void            Module::OnAddGLine(long duration, userrec* source, const std::string &reason, const std::string &hostmask) { }
176 void            Module::OnAddZLine(long duration, userrec* source, const std::string &reason, const std::string &ipmask) { }
177 void            Module::OnAddKLine(long duration, userrec* source, const std::string &reason, const std::string &hostmask) { }
178 void            Module::OnAddQLine(long duration, userrec* source, const std::string &reason, const std::string &nickmask) { }
179 void            Module::OnAddELine(long duration, userrec* source, const std::string &reason, const std::string &hostmask) { }
180 void            Module::OnDelGLine(userrec* source, const std::string &hostmask) { }
181 void            Module::OnDelZLine(userrec* source, const std::string &ipmask) { }
182 void            Module::OnDelKLine(userrec* source, const std::string &hostmask) { }
183 void            Module::OnDelQLine(userrec* source, const std::string &nickmask) { }
184 void            Module::OnDelELine(userrec* source, const std::string &hostmask) { }
185 void            Module::OnCleanup(int target_type, void* item) { }
186 void            Module::Implements(char* Implements) { for (int j = 0; j < 255; j++) Implements[j] = 0; }
187 void            Module::OnChannelDelete(chanrec* chan) { }
188 Priority        Module::Prioritize() { return PRIORITY_DONTCARE; }
189 void            Module::OnSetAway(userrec* user) { }
190 void            Module::OnCancelAway(userrec* user) { }
191 int             Module::OnUserList(userrec* user, chanrec* Ptr, CUList* &userlist) { return 0; }
192 int             Module::OnWhoisLine(userrec* user, userrec* dest, int &numeric, std::string &text) { return 0; }
193 void            Module::OnBuildExemptList(MessageType message_type, chanrec* chan, userrec* sender, char status, CUList &exempt_list) { }
194 void            Module::OnGarbageCollect() { }
195 void            Module::OnBufferFlushed(userrec* user) { }
196
197 long InspIRCd::PriorityAfter(const std::string &modulename)
198 {
199         for (unsigned int j = 0; j < this->Config->module_names.size(); j++)
200         {
201                 if (this->Config->module_names[j] == modulename)
202                 {
203                         return ((j << 8) | PRIORITY_AFTER);
204                 }
205         }
206         return PRIORITY_DONTCARE;
207 }
208
209 long InspIRCd::PriorityBefore(const std::string &modulename)
210 {
211         for (unsigned int j = 0; j < this->Config->module_names.size(); j++)
212         {
213                 if (this->Config->module_names[j] == modulename)
214                 {
215                         return ((j << 8) | PRIORITY_BEFORE);
216                 }
217         }
218         return PRIORITY_DONTCARE;
219 }
220
221 bool InspIRCd::PublishFeature(const std::string &FeatureName, Module* Mod)
222 {
223         if (Features.find(FeatureName) == Features.end())
224         {
225                 Features[FeatureName] = Mod;
226                 return true;
227         }
228         return false;
229 }
230
231 bool InspIRCd::UnpublishFeature(const std::string &FeatureName)
232 {
233         featurelist::iterator iter = Features.find(FeatureName);
234         
235         if (iter == Features.end())
236                 return false;
237
238         Features.erase(iter);
239         return true;
240 }
241
242 Module* InspIRCd::FindFeature(const std::string &FeatureName)
243 {
244         featurelist::iterator iter = Features.find(FeatureName);
245
246         if (iter == Features.end())
247                 return NULL;
248
249         return iter->second;
250 }
251
252 bool InspIRCd::PublishInterface(const std::string &InterfaceName, Module* Mod)
253 {
254         interfacelist::iterator iter = Interfaces.find(InterfaceName);
255
256         if (iter == Interfaces.end())
257         {
258                 modulelist ml;
259                 ml.push_back(Mod);
260                 Interfaces[InterfaceName] = std::make_pair(0, ml);
261                 return true;
262         }
263         else
264         {
265                 iter->second.second.push_back(Mod);
266                 return true;
267         }
268         return false;
269 }
270
271 bool InspIRCd::UnpublishInterface(const std::string &InterfaceName, Module* Mod)
272 {
273         interfacelist::iterator iter = Interfaces.find(InterfaceName);
274
275         if (iter == Interfaces.end())
276                 return false;
277
278         for (modulelist::iterator x = iter->second.second.begin(); x != iter->second.second.end(); x++)
279         {
280                 if (*x == Mod)
281                 {
282                         iter->second.second.erase(x);
283                         if (iter->second.second.empty())
284                                 Interfaces.erase(InterfaceName);
285                         return true;
286                 }
287         }
288         return false;
289 }
290
291 modulelist* InspIRCd::FindInterface(const std::string &InterfaceName)
292 {
293         interfacelist::iterator iter = Interfaces.find(InterfaceName);
294         if (iter == Interfaces.end())
295                 return NULL;
296         else
297                 return &(iter->second.second);
298 }
299
300 void InspIRCd::UseInterface(const std::string &InterfaceName)
301 {
302         interfacelist::iterator iter = Interfaces.find(InterfaceName);
303         if (iter != Interfaces.end())
304                 iter->second.first++;
305
306 }
307
308 void InspIRCd::DoneWithInterface(const std::string &InterfaceName)
309 {
310         interfacelist::iterator iter = Interfaces.find(InterfaceName);
311         if (iter != Interfaces.end())
312                 iter->second.first--;
313 }
314
315 std::pair<int,std::string> InspIRCd::GetInterfaceInstanceCount(Module* m)
316 {
317         for (interfacelist::iterator iter = Interfaces.begin(); iter != Interfaces.end(); iter++)
318         {
319                 for (modulelist::iterator x = iter->second.second.begin(); x != iter->second.second.end(); x++)
320                 {
321                         if (*x == m)
322                         {
323                                 return std::make_pair(iter->second.first, iter->first);
324                         }
325                 }
326         }
327         return std::make_pair(0, "");
328 }
329
330 const std::string& InspIRCd::GetModuleName(Module* m)
331 {
332         static std::string nothing; /* Prevent compiler warning */
333
334         if (!this->GetModuleCount())
335                 return nothing;
336
337         for (int i = 0; i <= this->GetModuleCount(); i++)
338         {
339                 if (this->modules[i] == m)
340                 {
341                         return this->Config->module_names[i];
342                 }
343         }
344         return nothing; /* As above */
345 }
346
347 void InspIRCd::RehashServer()
348 {
349         this->WriteOpers("*** Rehashing config file");
350         this->RehashUsersAndChans();
351         this->Config->Read(false,NULL);
352         this->ResetMaxBans();
353         this->Res->Rehash();
354 }
355
356 /* This is ugly, yes, but hash_map's arent designed to be
357  * addressed in this manner, and this is a bit of a kludge.
358  * Luckily its a specialist function and rarely used by
359  * many modules (in fact, it was specially created to make
360  * m_safelist possible, initially).
361  */
362
363 chanrec* InspIRCd::GetChannelIndex(long index)
364 {
365         int target = 0;
366         for (chan_hash::iterator n = this->chanlist->begin(); n != this->chanlist->end(); n++, target++)
367         {
368                 if (index == target)
369                         return n->second;
370         }
371         return NULL;
372 }
373
374 bool InspIRCd::MatchText(const std::string &sliteral, const std::string &spattern)
375 {
376         return match(sliteral.c_str(),spattern.c_str());
377 }
378
379 CmdResult InspIRCd::CallCommandHandler(const std::string &commandname, const char** parameters, int pcnt, userrec* user)
380 {
381         return this->Parser->CallHandler(commandname,parameters,pcnt,user);
382 }
383
384 bool InspIRCd::IsValidModuleCommand(const std::string &commandname, int pcnt, userrec* user)
385 {
386         return this->Parser->IsValidCommand(commandname, pcnt, user);
387 }
388
389 void InspIRCd::AddCommand(command_t *f)
390 {
391         if (!this->Parser->CreateCommand(f))
392         {
393                 ModuleException err("Command "+std::string(f->command)+" already exists.");
394                 throw (err);
395         }
396 }
397
398 void InspIRCd::SendMode(const char** parameters, int pcnt, userrec *user)
399 {
400         this->Modes->Process(parameters,pcnt,user,true);
401 }
402
403 void InspIRCd::DumpText(userrec* User, const std::string &LinePrefix, stringstream &TextStream)
404 {
405         std::string CompleteLine = LinePrefix;
406         std::string Word;
407         while (TextStream >> Word)
408         {
409                 if (CompleteLine.length() + Word.length() + 3 > 500)
410                 {
411                         User->WriteServ(CompleteLine);
412                         CompleteLine = LinePrefix;
413                 }
414                 CompleteLine = CompleteLine + Word + " ";
415         }
416         User->WriteServ(CompleteLine);
417 }
418
419 userrec* InspIRCd::FindDescriptor(int socket)
420 {
421         return reinterpret_cast<userrec*>(this->SE->GetRef(socket));
422 }
423
424 bool InspIRCd::AddMode(ModeHandler* mh, const unsigned char mode)
425 {
426         return this->Modes->AddMode(mh,mode);
427 }
428
429 bool InspIRCd::AddModeWatcher(ModeWatcher* mw)
430 {
431         return this->Modes->AddModeWatcher(mw);
432 }
433
434 bool InspIRCd::DelModeWatcher(ModeWatcher* mw)
435 {
436         return this->Modes->DelModeWatcher(mw);
437 }
438
439 bool InspIRCd::AddResolver(Resolver* r, bool cached)
440 {
441         if (!cached)
442                 return this->Res->AddResolverClass(r);
443         else
444         {
445                 r->TriggerCachedResult();
446                 delete r;
447                 return true;
448         }
449 }
450
451 void InspIRCd::AddGLine(long duration, const std::string &source, const std::string &reason, const std::string &hostmask)
452 {
453         XLines->add_gline(duration, source.c_str(), reason.c_str(), hostmask.c_str());
454         XLines->apply_lines(APPLY_GLINES);
455 }
456
457 void InspIRCd::AddQLine(long duration, const std::string &source, const std::string &reason, const std::string &nickname)
458 {
459         XLines->add_qline(duration, source.c_str(), reason.c_str(), nickname.c_str());
460         XLines->apply_lines(APPLY_QLINES);
461 }
462
463 void InspIRCd::AddZLine(long duration, const std::string &source, const std::string &reason, const std::string &ipaddr)
464 {
465         XLines->add_zline(duration, source.c_str(), reason.c_str(), ipaddr.c_str());
466         XLines->apply_lines(APPLY_ZLINES);
467 }
468
469 void InspIRCd::AddKLine(long duration, const std::string &source, const std::string &reason, const std::string &hostmask)
470 {
471         XLines->add_kline(duration, source.c_str(), reason.c_str(), hostmask.c_str());
472         XLines->apply_lines(APPLY_KLINES);
473 }
474
475 void InspIRCd::AddELine(long duration, const std::string &source, const std::string &reason, const std::string &hostmask)
476 {
477         XLines->add_eline(duration, source.c_str(), reason.c_str(), hostmask.c_str());
478 }
479
480 bool InspIRCd::DelGLine(const std::string &hostmask)
481 {
482         return XLines->del_gline(hostmask.c_str());
483 }
484
485 bool InspIRCd::DelQLine(const std::string &nickname)
486 {
487         return XLines->del_qline(nickname.c_str());
488 }
489
490 bool InspIRCd::DelZLine(const std::string &ipaddr)
491 {
492         return XLines->del_zline(ipaddr.c_str());
493 }
494
495 bool InspIRCd::DelKLine(const std::string &hostmask)
496 {
497         return XLines->del_kline(hostmask.c_str());
498 }
499
500 bool InspIRCd::DelELine(const std::string &hostmask)
501 {
502         return XLines->del_eline(hostmask.c_str());
503 }
504
505 /*
506  * XXX why on *earth* is this in modules.cpp...? I think
507  * perhaps we need a server.cpp for InspIRCd:: stuff where possible. -- w00t
508  */
509 bool InspIRCd::IsValidMask(const std::string &mask)
510 {
511         char* dest = (char*)mask.c_str();
512         if (strchr(dest,'!')==0)
513                 return false;
514         if (strchr(dest,'@')==0)
515                 return false;
516         for (char* i = dest; *i; i++)
517                 if (*i < 32)
518                         return false;
519         for (char* i = dest; *i; i++)
520                 if (*i > 126)
521                         return false;
522         unsigned int c = 0;
523         for (char* i = dest; *i; i++)
524                 if (*i == '!')
525                         c++;
526         if (c>1)
527                 return false;
528         c = 0;
529         for (char* i = dest; *i; i++)
530                 if (*i == '@')
531                         c++;
532         if (c>1)
533                 return false;
534
535         return true;
536 }
537
538 Module* InspIRCd::FindModule(const std::string &name)
539 {
540         for (int i = 0; i <= this->GetModuleCount(); i++)
541         {
542                 if (this->Config->module_names[i] == name)
543                 {
544                         return this->modules[i];
545                 }
546         }
547         return NULL;
548 }
549
550 ConfigReader::ConfigReader(InspIRCd* Instance) : ServerInstance(Instance)
551 {
552         /* Is there any reason to load the entire config file again here?
553          * it's needed if they specify another config file, but using the
554          * default one we can just use the global config data - pre-parsed!
555          */
556         this->errorlog = new std::ostringstream(std::stringstream::in | std::stringstream::out);
557         
558         this->data = &ServerInstance->Config->config_data;
559         this->privatehash = false;
560 }
561
562
563 ConfigReader::~ConfigReader()
564 {
565         if (this->errorlog)
566                 DELETE(this->errorlog);
567         if(this->privatehash)
568                 DELETE(this->data);
569 }
570
571
572 ConfigReader::ConfigReader(InspIRCd* Instance, const std::string &filename) : ServerInstance(Instance)
573 {
574         ServerInstance->Config->ClearStack();
575
576         this->data = new ConfigDataHash;
577         this->privatehash = true;
578         this->errorlog = new std::ostringstream(std::stringstream::in | std::stringstream::out);
579         this->readerror = ServerInstance->Config->LoadConf(*this->data, filename, *this->errorlog);
580         if (!this->readerror)
581                 this->error = CONF_FILE_NOT_FOUND;
582 }
583
584
585 std::string ConfigReader::ReadValue(const std::string &tag, const std::string &name, const std::string &default_value, int index, bool allow_linefeeds)
586 {
587         /* Don't need to strlcpy() tag and name anymore, ReadConf() takes const char* */ 
588         std::string result;
589         
590         if (!ServerInstance->Config->ConfValue(*this->data, tag, name, default_value, index, result, allow_linefeeds))
591         {
592                 this->error = CONF_VALUE_NOT_FOUND;
593         }
594         return result;
595 }
596
597 std::string ConfigReader::ReadValue(const std::string &tag, const std::string &name, int index, bool allow_linefeeds)
598 {
599         return ReadValue(tag, name, "", index, allow_linefeeds);
600 }
601
602 bool ConfigReader::ReadFlag(const std::string &tag, const std::string &name, const std::string &default_value, int index)
603 {
604         return ServerInstance->Config->ConfValueBool(*this->data, tag, name, default_value, index);
605 }
606
607 bool ConfigReader::ReadFlag(const std::string &tag, const std::string &name, int index)
608 {
609         return ReadFlag(tag, name, "", index);
610 }
611
612
613 long ConfigReader::ReadInteger(const std::string &tag, const std::string &name, const std::string &default_value, int index, bool needs_unsigned)
614 {
615         int result;
616         
617         if(!ServerInstance->Config->ConfValueInteger(*this->data, tag, name, default_value, index, result))
618         {
619                 this->error = CONF_VALUE_NOT_FOUND;
620                 return 0;
621         }
622         
623         if ((needs_unsigned) && (result < 0))
624         {
625                 this->error = CONF_NOT_UNSIGNED;
626                 return 0;
627         }
628         
629         return result;
630 }
631
632 long ConfigReader::ReadInteger(const std::string &tag, const std::string &name, int index, bool needs_unsigned)
633 {
634         return ReadInteger(tag, name, "", index, needs_unsigned);
635 }
636
637 long ConfigReader::GetError()
638 {
639         long olderr = this->error;
640         this->error = 0;
641         return olderr;
642 }
643
644 void ConfigReader::DumpErrors(bool bail, userrec* user)
645 {
646         ServerInstance->Config->ReportConfigError(this->errorlog->str(), bail, user);
647 }
648
649
650 int ConfigReader::Enumerate(const std::string &tag)
651 {
652         return ServerInstance->Config->ConfValueEnum(*this->data, tag);
653 }
654
655 int ConfigReader::EnumerateValues(const std::string &tag, int index)
656 {
657         return ServerInstance->Config->ConfVarEnum(*this->data, tag, index);
658 }
659
660 bool ConfigReader::Verify()
661 {
662         return this->readerror;
663 }
664
665
666 FileReader::FileReader(InspIRCd* Instance, const std::string &filename) : ServerInstance(Instance)
667 {
668         LoadFile(filename);
669 }
670
671 FileReader::FileReader(InspIRCd* Instance) : ServerInstance(Instance)
672 {
673 }
674
675 std::string FileReader::Contents()
676 {
677         std::string x;
678         for (file_cache::iterator a = this->fc.begin(); a != this->fc.end(); a++)
679         {
680                 x.append(*a);
681                 x.append("\r\n");
682         }
683         return x;
684 }
685
686 unsigned long FileReader::ContentSize()
687 {
688         return this->contentsize;
689 }
690
691 void FileReader::CalcSize()
692 {
693         unsigned long n = 0;
694         for (file_cache::iterator a = this->fc.begin(); a != this->fc.end(); a++)
695                 n += (a->length() + 2);
696         this->contentsize = n;
697 }
698
699 void FileReader::LoadFile(const std::string &filename)
700 {
701         file_cache c;
702         c.clear();
703         if (ServerInstance->Config->ReadFile(c,filename.c_str()))
704         {
705                 this->fc = c;
706                 this->CalcSize();
707         }
708 }
709
710
711 FileReader::~FileReader()
712 {
713 }
714
715 bool FileReader::Exists()
716 {
717         return (!(fc.size() == 0));
718 }
719
720 std::string FileReader::GetLine(int x)
721 {
722         if ((x<0) || ((unsigned)x>fc.size()))
723                 return "";
724         return fc[x];
725 }
726
727 int FileReader::FileSize()
728 {
729         return fc.size();
730 }
731
732