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