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