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