]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules.cpp
Note: connect() cant time out for inspsockets in this commit. They'll sit in memory...
[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::OnPostConnect(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 int             Module::OnUserList(userrec* user, chanrec* Ptr) { return 0; };
213
214
215 long InspIRCd::PriorityAfter(const std::string &modulename)
216 {
217         for (unsigned int j = 0; j < this->Config->module_names.size(); j++)
218         {
219                 if (this->Config->module_names[j] == modulename)
220                 {
221                         return ((j << 8) | PRIORITY_AFTER);
222                 }
223         }
224         return PRIORITY_DONTCARE;
225 }
226
227 long InspIRCd::PriorityBefore(const std::string &modulename)
228 {
229         for (unsigned int j = 0; j < this->Config->module_names.size(); j++)
230         {
231                 if (this->Config->module_names[j] == modulename)
232                 {
233                         return ((j << 8) | PRIORITY_BEFORE);
234                 }
235         }
236         return PRIORITY_DONTCARE;
237 }
238
239 bool InspIRCd::PublishFeature(const std::string &FeatureName, Module* Mod)
240 {
241         if (Features.find(FeatureName) == Features.end())
242         {
243                 Features[FeatureName] = Mod;
244                 return true;
245         }
246         return false;
247 }
248
249 bool InspIRCd::UnpublishFeature(const std::string &FeatureName)
250 {
251         featurelist::iterator iter = Features.find(FeatureName);
252         
253         if (iter == Features.end())
254                 return false;
255
256         Features.erase(iter);
257         return true;
258 }
259
260 Module* InspIRCd::FindFeature(const std::string &FeatureName)
261 {
262         featurelist::iterator iter = Features.find(FeatureName);
263
264         if (iter == Features.end())
265                 return NULL;
266
267         return iter->second;
268 }
269
270 const std::string& InspIRCd::GetModuleName(Module* m)
271 {
272         static std::string nothing = ""; /* Prevent compiler warning */
273         for (int i = 0; i <= this->GetModuleCount(); i++)
274         {
275                 if (this->modules[i] == m)
276                 {
277                         return this->Config->module_names[i];
278                 }
279         }
280         return nothing; /* As above */
281 }
282
283 void InspIRCd::RehashServer()
284 {
285         this->WriteOpers("*** Rehashing config file");
286         this->Config->Read(false,NULL);
287 }
288
289 /* This is ugly, yes, but hash_map's arent designed to be
290  * addressed in this manner, and this is a bit of a kludge.
291  * Luckily its a specialist function and rarely used by
292  * many modules (in fact, it was specially created to make
293  * m_safelist possible, initially).
294  */
295
296 chanrec* InspIRCd::GetChannelIndex(long index)
297 {
298         int target = 0;
299         for (chan_hash::iterator n = this->chanlist.begin(); n != this->chanlist.end(); n++, target++)
300         {
301                 if (index == target)
302                         return n->second;
303         }
304         return NULL;
305 }
306
307 bool InspIRCd::MatchText(const std::string &sliteral, const std::string &spattern)
308 {
309         return match(sliteral.c_str(),spattern.c_str());
310 }
311
312 bool InspIRCd::CallCommandHandler(const std::string &commandname, const char** parameters, int pcnt, userrec* user)
313 {
314         return this->Parser->CallHandler(commandname,parameters,pcnt,user);
315 }
316
317 bool InspIRCd::IsValidModuleCommand(const std::string &commandname, int pcnt, userrec* user)
318 {
319         return this->Parser->IsValidCommand(commandname, pcnt, user);
320 }
321
322 void InspIRCd::AddCommand(command_t *f)
323 {
324         if (!this->Parser->CreateCommand(f))
325         {
326                 ModuleException err("Command "+std::string(f->command)+" already exists.");
327                 throw (err);
328         }
329 }
330
331 void InspIRCd::SendMode(const char** parameters, int pcnt, userrec *user)
332 {
333         this->Modes->Process(parameters,pcnt,user,true);
334 }
335
336 void InspIRCd::DumpText(userrec* User, const std::string &LinePrefix, stringstream &TextStream)
337 {
338         std::string CompleteLine = LinePrefix;
339         std::string Word = "";
340         while (TextStream >> Word)
341         {
342                 if (CompleteLine.length() + Word.length() + 3 > 500)
343                 {
344                         User->WriteServ(CompleteLine);
345                         CompleteLine = LinePrefix;
346                 }
347                 CompleteLine = CompleteLine + Word + " ";
348         }
349         User->WriteServ(CompleteLine);
350 }
351
352 userrec* InspIRCd::FindDescriptor(int socket)
353 {
354         return reinterpret_cast<userrec*>(this->SE->GetRef(socket));
355 }
356
357 bool InspIRCd::AddMode(ModeHandler* mh, const unsigned char mode)
358 {
359         return this->Modes->AddMode(mh,mode);
360 }
361
362 bool InspIRCd::AddModeWatcher(ModeWatcher* mw)
363 {
364         return this->Modes->AddModeWatcher(mw);
365 }
366
367 bool InspIRCd::DelModeWatcher(ModeWatcher* mw)
368 {
369         return this->Modes->DelModeWatcher(mw);
370 }
371
372 bool InspIRCd::AddResolver(Resolver* r)
373 {
374         return this->Res->AddResolverClass(r);
375 }
376
377 bool InspIRCd::UserToPseudo(userrec* user, const std::string &message)
378 {
379         unsigned int old_fd = user->GetFd();
380         user->Write("ERROR :Closing link (%s@%s) [%s]",user->ident,user->host,message.c_str());
381         user->FlushWriteBuf();
382         user->ClearBuffer();
383         user->SetFd(FD_MAGIC_NUMBER);
384
385         if (find(local_users.begin(),local_users.end(),user) != local_users.end())
386         {
387                 local_users.erase(find(local_users.begin(),local_users.end(),user));
388         }
389
390         this->SE->DelFd(user);
391         shutdown(old_fd,2);
392         close(old_fd);
393         return true;
394 }
395
396 bool InspIRCd::PseudoToUser(userrec* alive, userrec* zombie, const std::string &message)
397 {
398         zombie->SetFd(alive->GetFd());
399         FOREACH_MOD_I(this,I_OnUserQuit,OnUserQuit(alive,message));
400         alive->SetFd(FD_MAGIC_NUMBER);
401         alive->FlushWriteBuf();
402         alive->ClearBuffer();
403         // save these for later
404         std::string oldnick = alive->nick;
405         std::string oldhost = alive->host;
406         std::string oldident = alive->ident;
407         userrec::QuitUser(this,alive,message.c_str());
408         if (find(local_users.begin(),local_users.end(),alive) != local_users.end())
409         {
410                 local_users.erase(find(local_users.begin(),local_users.end(),alive));
411         }
412         // Fix by brain - cant write the user until their fd table entry is updated
413         zombie->Write(":%s!%s@%s NICK %s",oldnick.c_str(),oldident.c_str(),oldhost.c_str(),zombie->nick);
414         for (std::vector<ucrec*>::const_iterator i = zombie->chans.begin(); i != zombie->chans.end(); i++)
415         {
416                 if (((ucrec*)(*i))->channel != NULL)
417                 {
418                                 chanrec* Ptr = ((ucrec*)(*i))->channel;
419                                 zombie->WriteFrom(zombie,"JOIN %s",Ptr->name);
420                                 if (Ptr->topicset)
421                                 {
422                                         zombie->WriteServ("332 %s %s :%s", zombie->nick, Ptr->name, Ptr->topic);
423                                         zombie->WriteServ("333 %s %s %s %d", zombie->nick, Ptr->name, Ptr->setby, Ptr->topicset);
424                                 }
425                                 Ptr->UserList(zombie);
426                                 zombie->WriteServ("366 %s %s :End of /NAMES list.", zombie->nick, Ptr->name);
427                 }
428         }
429         if ((find(local_users.begin(),local_users.end(),zombie) == local_users.end()) && (zombie->GetFd() != FD_MAGIC_NUMBER))
430                 local_users.push_back(zombie);
431         return true;
432 }
433
434 void InspIRCd::AddGLine(long duration, const std::string &source, const std::string &reason, const std::string &hostmask)
435 {
436         XLines->add_gline(duration, source.c_str(), reason.c_str(), hostmask.c_str());
437         XLines->apply_lines(APPLY_GLINES);
438 }
439
440 void InspIRCd::AddQLine(long duration, const std::string &source, const std::string &reason, const std::string &nickname)
441 {
442         XLines->add_qline(duration, source.c_str(), reason.c_str(), nickname.c_str());
443         XLines->apply_lines(APPLY_QLINES);
444 }
445
446 void InspIRCd::AddZLine(long duration, const std::string &source, const std::string &reason, const std::string &ipaddr)
447 {
448         XLines->add_zline(duration, source.c_str(), reason.c_str(), ipaddr.c_str());
449         XLines->apply_lines(APPLY_ZLINES);
450 }
451
452 void InspIRCd::AddKLine(long duration, const std::string &source, const std::string &reason, const std::string &hostmask)
453 {
454         XLines->add_kline(duration, source.c_str(), reason.c_str(), hostmask.c_str());
455         XLines->apply_lines(APPLY_KLINES);
456 }
457
458 void InspIRCd::AddELine(long duration, const std::string &source, const std::string &reason, const std::string &hostmask)
459 {
460         XLines->add_eline(duration, source.c_str(), reason.c_str(), hostmask.c_str());
461 }
462
463 bool InspIRCd::DelGLine(const std::string &hostmask)
464 {
465         return XLines->del_gline(hostmask.c_str());
466 }
467
468 bool InspIRCd::DelQLine(const std::string &nickname)
469 {
470         return XLines->del_qline(nickname.c_str());
471 }
472
473 bool InspIRCd::DelZLine(const std::string &ipaddr)
474 {
475         return XLines->del_zline(ipaddr.c_str());
476 }
477
478 bool InspIRCd::DelKLine(const std::string &hostmask)
479 {
480         return XLines->del_kline(hostmask.c_str());
481 }
482
483 bool InspIRCd::DelELine(const std::string &hostmask)
484 {
485         return XLines->del_eline(hostmask.c_str());
486 }
487
488 /*
489  * XXX why on *earth* is this in modules.cpp...? I think
490  * perhaps we need a server.cpp for InspIRCd:: stuff where possible. -- w00t
491  */
492 bool InspIRCd::IsValidMask(const std::string &mask)
493 {
494         char* dest = (char*)mask.c_str();
495         if (strchr(dest,'!')==0)
496                 return false;
497         if (strchr(dest,'@')==0)
498                 return false;
499         for (char* i = dest; *i; i++)
500                 if (*i < 32)
501                         return false;
502         for (char* i = dest; *i; i++)
503                 if (*i > 126)
504                         return false;
505         unsigned int c = 0;
506         for (char* i = dest; *i; i++)
507                 if (*i == '!')
508                         c++;
509         if (c>1)
510                 return false;
511         c = 0;
512         for (char* i = dest; *i; i++)
513                 if (*i == '@')
514                         c++;
515         if (c>1)
516                 return false;
517
518         return true;
519 }
520
521 Module* InspIRCd::FindModule(const std::string &name)
522 {
523         for (int i = 0; i <= this->GetModuleCount(); i++)
524         {
525                 if (this->Config->module_names[i] == name)
526                 {
527                         return this->modules[i];
528                 }
529         }
530         return NULL;
531 }
532
533 ConfigReader::ConfigReader(InspIRCd* Instance) : ServerInstance(Instance)
534 {
535         /* Is there any reason to load the entire config file again here?
536          * it's needed if they specify another config file, but using the
537          * default one we can just use the global config data - pre-parsed!
538          */
539         this->errorlog = new std::ostringstream(std::stringstream::in | std::stringstream::out);
540         
541         this->data = &ServerInstance->Config->config_data;
542         this->privatehash = false;
543 }
544
545
546 ConfigReader::~ConfigReader()
547 {
548         if (this->errorlog)
549                 DELETE(this->errorlog);
550         if(this->privatehash)
551                 DELETE(this->data);
552 }
553
554
555 ConfigReader::ConfigReader(InspIRCd* Instance, const std::string &filename) : ServerInstance(Instance)
556 {
557         ServerInstance->Config->ClearStack();
558
559         this->data = new ConfigDataHash;
560         this->privatehash = true;
561         this->errorlog = new std::ostringstream(std::stringstream::in | std::stringstream::out);
562         this->readerror = ServerInstance->Config->LoadConf(*this->data, filename, *this->errorlog);
563         if (!this->readerror)
564                 this->error = CONF_FILE_NOT_FOUND;
565 };
566
567 std::string ConfigReader::ReadValue(const std::string &tag, const std::string &name, int index)
568 {
569         /* Don't need to strlcpy() tag and name anymore, ReadConf() takes const char* */ 
570         std::string result;
571         
572         if (!ServerInstance->Config->ConfValue(*this->data, tag, name, index, result))
573         {
574                 this->error = CONF_VALUE_NOT_FOUND;
575                 return "";
576         }
577         
578         return result;
579 }
580
581 bool ConfigReader::ReadFlag(const std::string &tag, const std::string &name, int index)
582 {
583         return ServerInstance->Config->ConfValueBool(*this->data, tag, name, index);
584 }
585
586 long ConfigReader::ReadInteger(const std::string &tag, const std::string &name, int index, bool needs_unsigned)
587 {
588         int result;
589         
590         if(!ServerInstance->Config->ConfValueInteger(*this->data, tag, name, index, result))
591         {
592                 this->error = CONF_VALUE_NOT_FOUND;
593                 return 0;
594         }
595         
596         if ((needs_unsigned) && (result < 0))
597         {
598                 this->error = CONF_NOT_UNSIGNED;
599                 return 0;
600         }
601         
602         return result;
603 }
604
605 long ConfigReader::GetError()
606 {
607         long olderr = this->error;
608         this->error = 0;
609         return olderr;
610 }
611
612 void ConfigReader::DumpErrors(bool bail, userrec* user)
613 {
614         /* XXX - Duplicated code */
615         
616         if (bail)
617         {
618                 printf("There were errors in your configuration:\n%s", this->errorlog->str().c_str());
619                 InspIRCd::Exit(ERROR);
620         }
621         else
622         {
623                 std::string errors = this->errorlog->str();
624                 std::string::size_type start;
625                 unsigned int prefixlen;
626                 
627                 start = 0;
628                 /* ":ServerInstance->Config->ServerName NOTICE user->nick :" */
629                 prefixlen = strlen(ServerInstance->Config->ServerName) + strlen(user->nick) + 11;
630         
631                 if (user)
632                 {
633                         user->WriteServ("NOTICE %s :There were errors in the configuration file:",user->nick);
634                         
635                         while(start < errors.length())
636                         {
637                                 user->WriteServ("NOTICE %s :%s",user->nick, errors.substr(start, 510 - prefixlen).c_str());
638                                 start += 510 - prefixlen;
639                         }
640                 }
641                 else
642                 {
643                         ServerInstance->WriteOpers("There were errors in the configuration file:");
644                         
645                         while(start < errors.length())
646                         {
647                                 ServerInstance->WriteOpers(errors.substr(start, 360).c_str());
648                                 start += 360;
649                         }
650                 }
651
652                 return;
653         }
654 }
655
656
657 int ConfigReader::Enumerate(const std::string &tag)
658 {
659         return ServerInstance->Config->ConfValueEnum(*this->data, tag);
660 }
661
662 int ConfigReader::EnumerateValues(const std::string &tag, int index)
663 {
664         return ServerInstance->Config->ConfVarEnum(*this->data, tag, index);
665 }
666
667 bool ConfigReader::Verify()
668 {
669         return this->readerror;
670 }
671
672
673 FileReader::FileReader(InspIRCd* Instance, const std::string &filename) : ServerInstance(Instance)
674 {
675         file_cache c;
676         ServerInstance->Config->ReadFile(c,filename.c_str());
677         this->fc = c;
678         this->CalcSize();
679 }
680
681 FileReader::FileReader(InspIRCd* Instance) : ServerInstance(Instance)
682 {
683 }
684
685 std::string FileReader::Contents()
686 {
687         std::string x = "";
688         for (file_cache::iterator a = this->fc.begin(); a != this->fc.end(); a++)
689         {
690                 x.append(*a);
691                 x.append("\r\n");
692         }
693         return x;
694 }
695
696 unsigned long FileReader::ContentSize()
697 {
698         return this->contentsize;
699 }
700
701 void FileReader::CalcSize()
702 {
703         unsigned long n = 0;
704         for (file_cache::iterator a = this->fc.begin(); a != this->fc.end(); a++)
705                 n += (a->length() + 2);
706         this->contentsize = n;
707 }
708
709 void FileReader::LoadFile(const std::string &filename)
710 {
711         file_cache c;
712         ServerInstance->Config->ReadFile(c,filename.c_str());
713         this->fc = c;
714         this->CalcSize();
715 }
716
717
718 FileReader::~FileReader()
719 {
720 }
721
722 bool FileReader::Exists()
723 {
724         return (!(fc.size() == 0));
725 }
726
727 std::string FileReader::GetLine(int x)
728 {
729         if ((x<0) || ((unsigned)x>fc.size()))
730                 return "";
731         return fc[x];
732 }
733
734 int FileReader::FileSize()
735 {
736         return fc.size();
737 }
738
739