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