1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
7 * <brain@chatspike.net>
8 * <Craig@chatspike.net>
10 * Written by Craig Edwards, Craig McLure, and others.
11 * This program is free but copyrighted software; see
12 * the file COPYING for details.
14 * ---------------------------------------------------
17 #include "inspircd_config.h"
19 #include "configreader.h"
21 #include <sys/errno.h>
38 #include "inspstring.h"
39 #include "helperfuncs.h"
42 #include "socketengine.h"
45 #include "command_parse.h"
47 extern ServerConfig *Config;
48 extern InspIRCd* ServerInstance;
50 extern ModuleList modules;
51 extern FactoryList factory;
52 extern std::vector<InspSocket*> module_sockets;
53 extern std::vector<userrec*> local_users;
55 extern userrec* fd_ref_table[MAX_DESCRIPTORS];
56 extern user_hash clientlist;
57 extern chan_hash chanlist;
58 extern command_table cmdlist;
64 // returns true if an extended mode character is in use
65 bool ModeDefined(char modechar, int type)
67 for (ExtModeListIter i = EMode.begin(); i < EMode.end(); i++)
69 if ((i->modechar == modechar) && (i->type == type))
77 bool ModeIsListMode(char modechar, int type)
79 for (ExtModeListIter i = EMode.begin(); i < EMode.end(); i++)
81 if ((i->modechar == modechar) && (i->type == type) && (i->list == true))
89 bool ModeDefinedOper(char modechar, int type)
91 for (ExtModeListIter i = EMode.begin(); i < EMode.end(); i++)
93 if ((i->modechar == modechar) && (i->type == type) && (i->needsoper == true))
101 // returns number of parameters for a custom mode when it is switched on
102 int ModeDefinedOn(char modechar, int type)
104 for (ExtModeListIter i = EMode.begin(); i < EMode.end(); i++)
106 if ((i->modechar == modechar) && (i->type == type))
108 return i->params_when_on;
114 // returns number of parameters for a custom mode when it is switched on
115 int ModeDefinedOff(char modechar, int type)
117 for (ExtModeListIter i = EMode.begin(); i < EMode.end(); i++)
119 if ((i->modechar == modechar) && (i->type == type))
121 return i->params_when_off;
127 // returns true if an extended mode character is in use
128 bool DoAddExtendedMode(char modechar, int type, bool requires_oper, int params_on, int params_off)
130 if (ModeDefined(modechar,type)) {
133 EMode.push_back(ExtMode(modechar,type,requires_oper,params_on,params_off));
137 // turns a mode into a listmode
138 void ModeMakeList(char modechar)
140 for (ExtModeListIter i = EMode.begin(); i < EMode.end(); i++)
142 if ((i->modechar == modechar) && (i->type == MT_CHANNEL))
151 // version is a simple class for holding a modules version number
153 Version::Version(int major, int minor, int revision, int build, int flags) : Major(major), Minor(minor), Revision(revision), Build(build), Flags(flags) { };
155 // admin is a simple class for holding a server's administrative info
157 Admin::Admin(std::string name, std::string email, std::string nick) : Name(name), Email(email), Nick(nick) { };
159 Request::Request(char* anydata, Module* src, Module* dst) : data(anydata), source(src), dest(dst) { };
161 char* Request::GetData()
166 Module* Request::GetSource()
171 Module* Request::GetDest()
176 char* Request::Send()
180 return dest->OnRequest(this);
188 Event::Event(char* anydata, Module* src, const std::string &eventid) : data(anydata), source(src), id(eventid) { };
190 char* Event::GetData()
195 Module* Event::GetSource()
202 FOREACH_MOD(I_OnEvent,OnEvent(this));
206 std::string Event::GetEventID()
212 // These declarations define the behavours of the base class Module (which does nothing at all)
214 Module::Module(Server* Me) { }
215 Module::~Module() { }
216 void Module::OnUserConnect(userrec* user) { }
217 void Module::OnUserQuit(userrec* user, const std::string& message) { }
218 void Module::OnUserDisconnect(userrec* user) { }
219 void Module::OnUserJoin(userrec* user, chanrec* channel) { }
220 void Module::OnUserPart(userrec* user, chanrec* channel, const std::string &partmessage) { }
221 void Module::OnRehash(const std::string ¶meter) { }
222 void Module::OnServerRaw(std::string &raw, bool inbound, userrec* user) { }
223 int Module::OnUserPreJoin(userrec* user, chanrec* chan, const char* cname) { return 0; }
224 int Module::OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list ¶ms) { return false; }
225 void Module::OnMode(userrec* user, void* dest, int target_type, const std::string &text) { };
226 Version Module::GetVersion() { return Version(1,0,0,0,VF_VENDOR); }
227 void Module::OnOper(userrec* user, const std::string &opertype) { };
228 void Module::OnPostOper(userrec* user, const std::string &opertype) { };
229 void Module::OnInfo(userrec* user) { };
230 void Module::OnWhois(userrec* source, userrec* dest) { };
231 int Module::OnUserPreInvite(userrec* source,userrec* dest,chanrec* channel) { return 0; };
232 int Module::OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text,char status) { return 0; };
233 int Module::OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text,char status) { return 0; };
234 int Module::OnUserPreNick(userrec* user, const std::string &newnick) { return 0; };
235 void Module::OnUserPostNick(userrec* user, const std::string &oldnick) { };
236 int Module::OnAccessCheck(userrec* source,userrec* dest,chanrec* channel,int access_type) { return ACR_DEFAULT; };
237 void Module::On005Numeric(std::string &output) { };
238 int Module::OnKill(userrec* source, userrec* dest, const std::string &reason) { return 0; };
239 void Module::OnLoadModule(Module* mod,const std::string &name) { };
240 void Module::OnUnloadModule(Module* mod,const std::string &name) { };
241 void Module::OnBackgroundTimer(time_t curtime) { };
242 void Module::OnSendList(userrec* user, chanrec* channel, char mode) { };
243 int Module::OnPreCommand(const std::string &command, char **parameters, int pcnt, userrec *user, bool validated) { return 0; };
244 bool Module::OnCheckReady(userrec* user) { return true; };
245 void Module::OnUserRegister(userrec* user) { };
246 int Module::OnUserPreKick(userrec* source, userrec* user, chanrec* chan, const std::string &reason) { return 0; };
247 void Module::OnUserKick(userrec* source, userrec* user, chanrec* chan, const std::string &reason) { };
248 int Module::OnRawMode(userrec* user, chanrec* chan, char mode, const std::string ¶m, bool adding, int pcnt) { return 0; };
249 int Module::OnCheckInvite(userrec* user, chanrec* chan) { return 0; };
250 int Module::OnCheckKey(userrec* user, chanrec* chan, const std::string &keygiven) { return 0; };
251 int Module::OnCheckLimit(userrec* user, chanrec* chan) { return 0; };
252 int Module::OnCheckBan(userrec* user, chanrec* chan) { return 0; };
253 int Module::OnStats(char symbol, userrec* user) { return 0; };
254 int Module::OnChangeLocalUserHost(userrec* user, const std::string &newhost) { return 0; };
255 int Module::OnChangeLocalUserGECOS(userrec* user, const std::string &newhost) { return 0; };
256 int Module::OnLocalTopicChange(userrec* user, chanrec* chan, const std::string &topic) { return 0; };
257 void Module::OnEvent(Event* event) { return; };
258 char* Module::OnRequest(Request* request) { return NULL; };
259 int Module::OnOperCompare(const std::string &password, const std::string &input) { return 0; };
260 void Module::OnGlobalOper(userrec* user) { };
261 void Module::OnGlobalConnect(userrec* user) { };
262 int Module::OnAddBan(userrec* source, chanrec* channel,const std::string &banmask) { return 0; };
263 int Module::OnDelBan(userrec* source, chanrec* channel,const std::string &banmask) { return 0; };
264 void Module::OnRawSocketAccept(int fd, const std::string &ip, int localport) { };
265 int Module::OnRawSocketWrite(int fd, char* buffer, int count) { return 0; };
266 void Module::OnRawSocketClose(int fd) { };
267 int Module::OnRawSocketRead(int fd, char* buffer, unsigned int count, int &readresult) { return 0; };
268 void Module::OnUserMessage(userrec* user, void* dest, int target_type, const std::string &text, char status) { };
269 void Module::OnUserNotice(userrec* user, void* dest, int target_type, const std::string &text, char status) { };
270 void Module::OnRemoteKill(userrec* source, userrec* dest, const std::string &reason) { };
271 void Module::OnUserInvite(userrec* source,userrec* dest,chanrec* channel) { };
272 void Module::OnPostLocalTopicChange(userrec* user, chanrec* chan, const std::string &topic) { };
273 void Module::OnGetServerDescription(const std::string &servername,std::string &description) { };
274 void Module::OnSyncUser(userrec* user, Module* proto, void* opaque) { };
275 void Module::OnSyncChannel(chanrec* chan, Module* proto, void* opaque) { };
276 void Module::ProtoSendMode(void* opaque, int target_type, void* target, const std::string &modeline) { };
277 void Module::OnSyncChannelMetaData(chanrec* chan, Module* proto,void* opaque, const std::string &extname) { };
278 void Module::OnSyncUserMetaData(userrec* user, Module* proto,void* opaque, const std::string &extname) { };
279 void Module::OnSyncOtherMetaData(Module* proto, void* opaque) { };
280 void Module::OnDecodeMetaData(int target_type, void* target, const std::string &extname, const std::string &extdata) { };
281 void Module::ProtoSendMetaData(void* opaque, int target_type, void* target, const std::string &extname, const std::string &extdata) { };
282 void Module::OnWallops(userrec* user, const std::string &text) { };
283 void Module::OnChangeHost(userrec* user, const std::string &newhost) { };
284 void Module::OnChangeName(userrec* user, const std::string &gecos) { };
285 void Module::OnAddGLine(long duration, userrec* source, const std::string &reason, const std::string &hostmask) { };
286 void Module::OnAddZLine(long duration, userrec* source, const std::string &reason, const std::string &ipmask) { };
287 void Module::OnAddKLine(long duration, userrec* source, const std::string &reason, const std::string &hostmask) { };
288 void Module::OnAddQLine(long duration, userrec* source, const std::string &reason, const std::string &nickmask) { };
289 void Module::OnAddELine(long duration, userrec* source, const std::string &reason, const std::string &hostmask) { };
290 void Module::OnDelGLine(userrec* source, const std::string &hostmask) { };
291 void Module::OnDelZLine(userrec* source, const std::string &ipmask) { };
292 void Module::OnDelKLine(userrec* source, const std::string &hostmask) { };
293 void Module::OnDelQLine(userrec* source, const std::string &nickmask) { };
294 void Module::OnDelELine(userrec* source, const std::string &hostmask) { };
295 void Module::OnCleanup(int target_type, void* item) { };
296 void Module::Implements(char* Implements) { for (int j = 0; j < 255; j++) Implements[j] = 0; };
297 void Module::OnChannelDelete(chanrec* chan) { };
298 Priority Module::Prioritize() { return PRIORITY_DONTCARE; }
299 void Module::OnSetAway(userrec* user) { };
300 void Module::OnCancelAway(userrec* user) { };
302 /* server is a wrapper class that provides methods to all of the C-style
303 * exports in the core
314 void Server::AddSocket(InspSocket* sock)
316 module_sockets.push_back(sock);
319 void Server::RemoveSocket(InspSocket* sock)
321 for (std::vector<InspSocket*>::iterator a = module_sockets.begin(); a < module_sockets.end(); a++)
323 InspSocket* s = (InspSocket*)*a;
329 long Server::PriorityAfter(const std::string &modulename)
331 for (unsigned int j = 0; j < Config->module_names.size(); j++)
333 if (Config->module_names[j] == modulename)
335 return ((j << 8) | PRIORITY_AFTER);
338 return PRIORITY_DONTCARE;
341 long Server::PriorityBefore(const std::string &modulename)
343 for (unsigned int j = 0; j < Config->module_names.size(); j++)
345 if (Config->module_names[j] == modulename)
347 return ((j << 8) | PRIORITY_BEFORE);
350 return PRIORITY_DONTCARE;
353 void Server::RehashServer()
355 WriteOpers("*** Rehashing config file");
356 Config->Read(false,NULL);
359 ServerConfig* Server::GetConfig()
364 std::string Server::GetVersion()
366 return ServerInstance->GetVersionString();
369 void Server::DelSocket(InspSocket* sock)
371 for (std::vector<InspSocket*>::iterator a = module_sockets.begin(); a < module_sockets.end(); a++)
375 module_sockets.erase(a);
381 long Server::GetChannelCount()
383 return (long)chanlist.size();
386 /* This is ugly, yes, but hash_map's arent designed to be
387 * addressed in this manner, and this is a bit of a kludge.
388 * Luckily its a specialist function and rarely used by
389 * many modules (in fact, it was specially created to make
390 * m_safelist possible, initially).
393 chanrec* Server::GetChannelIndex(long index)
396 for (chan_hash::iterator n = chanlist.begin(); n != chanlist.end(); n++, target++)
404 void Server::AddTimer(InspTimer* T)
409 void Server::SendOpers(const std::string &s)
411 WriteOpers("%s",s.c_str());
414 bool Server::MatchText(const std::string &sliteral, const std::string &spattern)
416 return match(sliteral.c_str(),spattern.c_str());
419 void Server::SendToModeMask(const std::string &modes, int flags, const std::string &text)
421 WriteMode(modes.c_str(),flags,"%s",text.c_str());
424 chanrec* Server::JoinUserToChannel(userrec* user, const std::string &cname, const std::string &key)
426 return add_channel(user,cname.c_str(),key.c_str(),false);
429 chanrec* Server::PartUserFromChannel(userrec* user, const std::string &cname, const std::string &reason)
431 return del_channel(user,cname.c_str(),reason.c_str(),false);
434 chanuserlist Server::GetUsers(chanrec* chan)
438 CUList *list = chan->GetUsers();
439 for (CUList::iterator i = list->begin(); i != list->end(); i++)
440 userl.push_back(i->second);
443 void Server::ChangeUserNick(userrec* user, const std::string &nickname)
445 force_nickchange(user,nickname.c_str());
448 void Server::KickUser(userrec* source, userrec* target, chanrec* chan, const std::string &reason)
452 kick_channel(source,target,chan,(char*)reason.c_str());
456 server_kick_channel(target,chan,(char*)reason.c_str(),true);
460 void Server::QuitUser(userrec* user, const std::string &reason)
462 kill_link(user,reason.c_str());
465 bool Server::IsUlined(const std::string &server)
467 return is_uline(server.c_str());
470 bool Server::CallCommandHandler(const std::string &commandname, char** parameters, int pcnt, userrec* user)
472 return ServerInstance->Parser->CallHandler(commandname,parameters,pcnt,user);
475 bool Server::IsValidModuleCommand(const std::string &commandname, int pcnt, userrec* user)
477 return ServerInstance->Parser->IsValidCommand(commandname, pcnt, user);
480 void Server::Log(int level, const std::string &s)
482 log(level,"%s",s.c_str());
485 void Server::AddCommand(command_t *f)
487 if (!ServerInstance->Parser->CreateCommand(f))
489 ModuleException err("Command "+std::string(f->command)+" already exists.");
494 void Server::SendMode(char **parameters, int pcnt, userrec *user)
496 ServerInstance->ModeGrok->ServerMode(parameters,pcnt,user);
499 void Server::Send(int Socket, const std::string &s)
501 Write_NoFormat(Socket,s.c_str());
504 void Server::SendServ(int Socket, const std::string &s)
506 WriteServ_NoFormat(Socket,s.c_str());
509 void Server::SendFrom(int Socket, userrec* User, const std::string &s)
511 WriteFrom_NoFormat(Socket,User,s.c_str());
514 void Server::SendTo(userrec* Source, userrec* Dest, const std::string &s)
518 // if source is NULL, then the message originates from the local server
519 WriteServ_NoFormat(Dest->fd,s.c_str());
523 // otherwise it comes from the user specified
524 WriteTo_NoFormat(Source,Dest,s.c_str());
528 void Server::SendChannelServerNotice(const std::string &ServName, chanrec* Channel, const std::string &text)
530 WriteChannelWithServ_NoFormat((char*)ServName.c_str(), Channel, text.c_str());
533 void Server::SendChannel(userrec* User, chanrec* Channel, const std::string &s, bool IncludeSender)
537 WriteChannel_NoFormat(Channel,User,s.c_str());
541 ChanExceptSender_NoFormat(Channel,User,0,s.c_str());
545 bool Server::CommonChannels(userrec* u1, userrec* u2)
547 return (common_channels(u1,u2) != 0);
550 void Server::DumpText(userrec* User, const std::string &LinePrefix, stringstream &TextStream)
552 std::string CompleteLine = LinePrefix;
553 std::string Word = "";
554 while (TextStream >> Word)
556 if (CompleteLine.length() + Word.length() + 3 > 500)
558 WriteServ_NoFormat(User->fd,CompleteLine.c_str());
559 CompleteLine = LinePrefix;
561 CompleteLine = CompleteLine + Word + " ";
563 WriteServ_NoFormat(User->fd,CompleteLine.c_str());
566 void Server::SendCommon(userrec* User, const std::string &text, bool IncludeSender)
570 WriteCommon_NoFormat(User,text.c_str());
574 WriteCommonExcept_NoFormat(User,text.c_str());
578 void Server::SendWallops(userrec* User, const std::string &text)
580 WriteWallOps(User,false,"%s",text.c_str());
583 void Server::ChangeHost(userrec* user, const std::string &host)
585 ChangeDisplayedHost(user,host.c_str());
588 void Server::ChangeGECOS(userrec* user, const std::string &gecos)
590 ChangeName(user,gecos.c_str());
593 bool Server::IsNick(const std::string &nick)
595 return (isnick(nick.c_str()) != 0);
598 userrec* Server::FindNick(const std::string &nick)
603 userrec* Server::FindDescriptor(int socket)
605 return (socket < 65536 ? fd_ref_table[socket] : NULL);
608 chanrec* Server::FindChannel(const std::string &channel)
610 return FindChan(channel.c_str());
613 std::string Server::ChanMode(userrec* User, chanrec* Chan)
615 return cmode(User,Chan);
618 std::string Server::GetServerName()
620 return Config->ServerName;
623 std::string Server::GetNetworkName()
625 return Config->Network;
628 std::string Server::GetServerDescription()
630 return Config->ServerDesc;
633 Admin Server::GetAdmin()
635 return Admin(Config->AdminName,Config->AdminEmail,Config->AdminNick);
640 bool Server::AddExtendedMode(char modechar, int type, bool requires_oper, int params_when_on, int params_when_off)
642 if (((modechar >= 'A') && (modechar <= 'Z')) || ((modechar >= 'a') && (modechar <= 'z')))
644 if (type == MT_SERVER)
646 ModuleException e("Modes of type MT_SERVER are reserved for future expansion");
650 if (((params_when_on>0) || (params_when_off>0)) && (type == MT_CLIENT))
652 ModuleException e("Parameters on MT_CLIENT modes are not supported");
656 if ((params_when_on>1) || (params_when_off>1))
658 ModuleException e("More than one parameter for an MT_CHANNEL mode is not yet supported");
662 return DoAddExtendedMode(modechar,type,requires_oper,params_when_on,params_when_off);
666 ModuleException e("Muppet modechar detected.");
672 bool Server::AddExtendedListMode(char modechar)
674 bool res = DoAddExtendedMode(modechar,MT_CHANNEL,false,1,1);
676 ModeMakeList(modechar);
680 int Server::CountUsers(chanrec* c)
686 bool Server::UserToPseudo(userrec* user, const std::string &message)
688 unsigned int old_fd = user->fd;
689 Write(old_fd,"ERROR :Closing link (%s@%s) [%s]",user->ident,user->host,message.c_str());
690 user->FlushWriteBuf();
692 user->fd = FD_MAGIC_NUMBER;
694 if (find(local_users.begin(),local_users.end(),user) != local_users.end())
696 local_users.erase(find(local_users.begin(),local_users.end(),user));
697 log(DEBUG,"Delete local user");
700 ServerInstance->SE->DelFd(old_fd);
706 bool Server::PseudoToUser(userrec* alive, userrec* zombie, const std::string &message)
708 log(DEBUG,"PseudoToUser");
709 zombie->fd = alive->fd;
710 FOREACH_MOD(I_OnUserQuit,OnUserQuit(alive,message));
711 alive->fd = FD_MAGIC_NUMBER;
712 alive->FlushWriteBuf();
713 alive->ClearBuffer();
714 // save these for later
715 std::string oldnick = alive->nick;
716 std::string oldhost = alive->host;
717 std::string oldident = alive->ident;
718 kill_link(alive,message.c_str());
719 if (find(local_users.begin(),local_users.end(),alive) != local_users.end())
721 local_users.erase(find(local_users.begin(),local_users.end(),alive));
722 log(DEBUG,"Delete local user");
724 // Fix by brain - cant write the user until their fd table entry is updated
725 fd_ref_table[zombie->fd] = zombie;
726 Write(zombie->fd,":%s!%s@%s NICK %s",oldnick.c_str(),oldident.c_str(),oldhost.c_str(),zombie->nick);
727 for (std::vector<ucrec*>::const_iterator i = zombie->chans.begin(); i != zombie->chans.end(); i++)
729 if (((ucrec*)(*i))->channel != NULL)
731 chanrec* Ptr = ((ucrec*)(*i))->channel;
732 WriteFrom(zombie->fd,zombie,"JOIN %s",Ptr->name);
735 WriteServ(zombie->fd,"332 %s %s :%s", zombie->nick, Ptr->name, Ptr->topic);
736 WriteServ(zombie->fd,"333 %s %s %s %d", zombie->nick, Ptr->name, Ptr->setby, Ptr->topicset);
738 userlist(zombie,Ptr);
739 WriteServ(zombie->fd,"366 %s %s :End of /NAMES list.", zombie->nick, Ptr->name);
742 if ((find(local_users.begin(),local_users.end(),zombie) == local_users.end()) && (zombie->fd != FD_MAGIC_NUMBER))
743 local_users.push_back(zombie);
748 void Server::AddGLine(long duration, const std::string &source, const std::string &reason, const std::string &hostmask)
750 add_gline(duration, source.c_str(), reason.c_str(), hostmask.c_str());
753 void Server::AddQLine(long duration, const std::string &source, const std::string &reason, const std::string &nickname)
755 add_qline(duration, source.c_str(), reason.c_str(), nickname.c_str());
758 void Server::AddZLine(long duration, const std::string &source, const std::string &reason, const std::string &ipaddr)
760 add_zline(duration, source.c_str(), reason.c_str(), ipaddr.c_str());
763 void Server::AddKLine(long duration, const std::string &source, const std::string &reason, const std::string &hostmask)
765 add_kline(duration, source.c_str(), reason.c_str(), hostmask.c_str());
768 void Server::AddELine(long duration, const std::string &source, const std::string &reason, const std::string &hostmask)
770 add_eline(duration, source.c_str(), reason.c_str(), hostmask.c_str());
773 bool Server::DelGLine(const std::string &hostmask)
775 return del_gline(hostmask.c_str());
778 bool Server::DelQLine(const std::string &nickname)
780 return del_qline(nickname.c_str());
783 bool Server::DelZLine(const std::string &ipaddr)
785 return del_zline(ipaddr.c_str());
788 bool Server::DelKLine(const std::string &hostmask)
790 return del_kline(hostmask.c_str());
793 bool Server::DelELine(const std::string &hostmask)
795 return del_eline(hostmask.c_str());
798 long Server::CalcDuration(const std::string &delta)
800 return duration(delta.c_str());
804 * XXX why on *earth* is this in modules.cpp...? I think
805 * perhaps we need a server.cpp for Server:: stuff where possible. -- w00t
807 bool Server::IsValidMask(const std::string &mask)
809 char* dest = (char*)mask.c_str();
810 if (strchr(dest,'!')==0)
812 if (strchr(dest,'@')==0)
814 for (char* i = dest; *i; i++)
817 for (char* i = dest; *i; i++)
821 for (char* i = dest; *i; i++)
827 for (char* i = dest; *i; i++)
836 Module* Server::FindModule(const std::string &name)
838 for (int i = 0; i <= MODCOUNT; i++)
840 if (Config->module_names[i] == name)
848 ConfigReader::ConfigReader()
850 // Config->ClearStack();
852 /* Is there any reason to load the entire config file again here?
853 * it's needed if they specify another config file, but using the
854 * default one we can just use the global config data - pre-parsed!
856 //~ this->cache = new std::stringstream(std::stringstream::in | std::stringstream::out);
857 this->errorlog = new std::ostringstream(std::stringstream::in | std::stringstream::out);
859 //~ this->readerror = Config->LoadConf(CONFIG_FILE, this->cache,this->errorlog);
860 //~ if (!this->readerror)
861 //~ this->error = CONF_FILE_NOT_FOUND;
863 this->data = &Config->config_data;
864 this->privatehash = false;
868 ConfigReader::~ConfigReader()
871 //~ delete this->cache;
873 delete this->errorlog;
874 if(this->privatehash)
879 ConfigReader::ConfigReader(const std::string &filename)
881 Config->ClearStack();
883 this->data = new ConfigDataHash;
884 this->privatehash = true;
885 this->errorlog = new std::ostringstream(std::stringstream::in | std::stringstream::out);
886 this->readerror = Config->LoadConf(*this->data, filename, *this->errorlog);
887 if (!this->readerror)
888 this->error = CONF_FILE_NOT_FOUND;
891 std::string ConfigReader::ReadValue(const std::string &tag, const std::string &name, int index)
893 /* Don't need to strlcpy() tag and name anymore, ReadConf() takes const char* */
896 if (!Config->ConfValue(*this->data, tag, name, index, result))
898 this->error = CONF_VALUE_NOT_FOUND;
905 bool ConfigReader::ReadFlag(const std::string &tag, const std::string &name, int index)
907 return Config->ConfValueBool(*this->data, tag, name, index);
910 long ConfigReader::ReadInteger(const std::string &tag, const std::string &name, int index, bool needs_unsigned)
914 if(!Config->ConfValueInteger(*this->data, tag, name, index, result))
916 this->error = CONF_VALUE_NOT_FOUND;
920 if ((needs_unsigned) && (result < 0))
922 this->error = CONF_NOT_UNSIGNED;
929 long ConfigReader::GetError()
931 long olderr = this->error;
936 void ConfigReader::DumpErrors(bool bail, userrec* user)
938 /* XXX - Duplicated code */
942 printf("There were errors in your configuration:\n%s", this->errorlog->str().c_str());
947 std::string errors = this->errorlog->str();
948 std::string::size_type start;
949 unsigned int prefixlen;
952 /* ":Config->ServerName NOTICE user->nick :" */
953 prefixlen = strlen(Config->ServerName) + strlen(user->nick) + 11;
957 WriteServ(user->fd,"NOTICE %s :There were errors in the configuration file:",user->nick);
959 while(start < errors.length())
961 WriteServ(user->fd, "NOTICE %s :%s",user->nick, errors.substr(start, 510 - prefixlen).c_str());
962 start += 510 - prefixlen;
967 WriteOpers("There were errors in the configuration file:");
969 while(start < errors.length())
971 WriteOpers(errors.substr(start, 360).c_str());
981 int ConfigReader::Enumerate(const std::string &tag)
983 return Config->ConfValueEnum(*this->data, tag);
986 int ConfigReader::EnumerateValues(const std::string &tag, int index)
988 return Config->ConfVarEnum(*this->data, tag, index);
991 bool ConfigReader::Verify()
993 return this->readerror;
997 FileReader::FileReader(const std::string &filename)
1000 readfile(c,filename.c_str());
1004 FileReader::FileReader()
1008 void FileReader::LoadFile(const std::string &filename)
1011 readfile(c,filename.c_str());
1016 FileReader::~FileReader()
1020 bool FileReader::Exists()
1022 return (!(fc.size() == 0));
1025 std::string FileReader::GetLine(int x)
1027 if ((x<0) || ((unsigned)x>fc.size()))
1032 int FileReader::FileSize()
1038 std::vector<Module*> modules(255);
1039 std::vector<ircd_module*> factory(255);