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 * ---------------------------------------------------
19 #include "inspircd_config.h"
21 #include "inspircd_io.h"
23 #include <sys/errno.h>
27 #include <ext/hash_map>
45 #include "inspstring.h"
46 #include "helperfuncs.h"
49 #include "socketengine.h"
52 #include "command_parse.h"
54 extern ServerConfig *Config;
55 extern InspIRCd* ServerInstance;
57 extern std::vector<Module*> modules;
58 extern std::vector<ircd_module*> factory;
59 extern std::vector<InspSocket*> module_sockets;
60 extern std::vector<userrec*> local_users;
63 extern userrec* fd_ref_table[MAX_DESCRIPTORS];
65 extern user_hash clientlist;
66 extern chan_hash chanlist;
67 extern command_table cmdlist;
70 // returns true if an extended mode character is in use
71 bool ModeDefined(char modechar, int type)
73 for (ExtModeListIter i = EMode.begin(); i < EMode.end(); i++)
75 if ((i->modechar == modechar) && (i->type == type))
83 bool ModeIsListMode(char modechar, int type)
85 for (ExtModeListIter i = EMode.begin(); i < EMode.end(); i++)
87 if ((i->modechar == modechar) && (i->type == type) && (i->list == true))
95 bool ModeDefinedOper(char modechar, int type)
97 for (ExtModeListIter i = EMode.begin(); i < EMode.end(); i++)
99 if ((i->modechar == modechar) && (i->type == type) && (i->needsoper == true))
107 // returns number of parameters for a custom mode when it is switched on
108 int ModeDefinedOn(char modechar, int type)
110 for (ExtModeListIter i = EMode.begin(); i < EMode.end(); i++)
112 if ((i->modechar == modechar) && (i->type == type))
114 return i->params_when_on;
120 // returns number of parameters for a custom mode when it is switched on
121 int ModeDefinedOff(char modechar, int type)
123 for (ExtModeListIter i = EMode.begin(); i < EMode.end(); i++)
125 if ((i->modechar == modechar) && (i->type == type))
127 return i->params_when_off;
133 // returns true if an extended mode character is in use
134 bool DoAddExtendedMode(char modechar, int type, bool requires_oper, int params_on, int params_off)
136 if (ModeDefined(modechar,type)) {
139 EMode.push_back(ExtMode(modechar,type,requires_oper,params_on,params_off));
143 // turns a mode into a listmode
144 void ModeMakeList(char modechar)
146 for (ExtModeListIter i = EMode.begin(); i < EMode.end(); i++)
148 if ((i->modechar == modechar) && (i->type == MT_CHANNEL))
157 // version is a simple class for holding a modules version number
159 Version::Version(int major, int minor, int revision, int build, int flags) : Major(major), Minor(minor), Revision(revision), Build(build), Flags(flags) { };
161 // admin is a simple class for holding a server's administrative info
163 Admin::Admin(std::string name, std::string email, std::string nick) : Name(name), Email(email), Nick(nick) { };
165 Request::Request(char* anydata, Module* src, Module* dst) : data(anydata), source(src), dest(dst) { };
167 char* Request::GetData()
172 Module* Request::GetSource()
177 Module* Request::GetDest()
182 char* Request::Send()
186 return dest->OnRequest(this);
194 Event::Event(char* anydata, Module* src, const std::string &eventid) : data(anydata), source(src), id(eventid) { };
196 char* Event::GetData()
201 Module* Event::GetSource()
208 FOREACH_MOD(I_OnEvent,OnEvent(this));
212 std::string Event::GetEventID()
218 // These declarations define the behavours of the base class Module (which does nothing at all)
220 Module::Module(Server* Me) { }
221 Module::~Module() { }
222 void Module::OnUserConnect(userrec* user) { }
223 void Module::OnUserQuit(userrec* user, std::string message) { }
224 void Module::OnUserDisconnect(userrec* user) { }
225 void Module::OnUserJoin(userrec* user, chanrec* channel) { }
226 void Module::OnUserPart(userrec* user, chanrec* channel, std::string partmessage) { }
227 void Module::OnRehash(std::string parameter) { }
228 void Module::OnServerRaw(std::string &raw, bool inbound, userrec* user) { }
229 int Module::OnUserPreJoin(userrec* user, chanrec* chan, const char* cname) { return 0; }
230 int Module::OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list ¶ms) { return false; }
231 void Module::OnMode(userrec* user, void* dest, int target_type, std::string text) { };
232 Version Module::GetVersion() { return Version(1,0,0,0,VF_VENDOR); }
233 void Module::OnOper(userrec* user, std::string opertype) { };
234 void Module::OnPostOper(userrec* user, std::string opertype) { };
235 void Module::OnInfo(userrec* user) { };
236 void Module::OnWhois(userrec* source, userrec* dest) { };
237 int Module::OnUserPreInvite(userrec* source,userrec* dest,chanrec* channel) { return 0; };
238 int Module::OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text,char status) { return 0; };
239 int Module::OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text,char status) { return 0; };
240 int Module::OnUserPreNick(userrec* user, std::string newnick) { return 0; };
241 void Module::OnUserPostNick(userrec* user, std::string oldnick) { };
242 int Module::OnAccessCheck(userrec* source,userrec* dest,chanrec* channel,int access_type) { return ACR_DEFAULT; };
243 void Module::On005Numeric(std::string &output) { };
244 int Module::OnKill(userrec* source, userrec* dest, std::string reason) { return 0; };
245 void Module::OnLoadModule(Module* mod,std::string name) { };
246 void Module::OnUnloadModule(Module* mod,std::string name) { };
247 void Module::OnBackgroundTimer(time_t curtime) { };
248 void Module::OnSendList(userrec* user, chanrec* channel, char mode) { };
249 int Module::OnPreCommand(std::string command, char **parameters, int pcnt, userrec *user, bool validated) { return 0; };
250 bool Module::OnCheckReady(userrec* user) { return true; };
251 void Module::OnUserRegister(userrec* user) { };
252 int Module::OnUserPreKick(userrec* source, userrec* user, chanrec* chan, std::string reason) { return 0; };
253 void Module::OnUserKick(userrec* source, userrec* user, chanrec* chan, std::string reason) { };
254 int Module::OnRawMode(userrec* user, chanrec* chan, char mode, std::string param, bool adding, int pcnt) { return 0; };
255 int Module::OnCheckInvite(userrec* user, chanrec* chan) { return 0; };
256 int Module::OnCheckKey(userrec* user, chanrec* chan, std::string keygiven) { return 0; };
257 int Module::OnCheckLimit(userrec* user, chanrec* chan) { return 0; };
258 int Module::OnCheckBan(userrec* user, chanrec* chan) { return 0; };
259 int Module::OnStats(char symbol, userrec* user) { return 0; };
260 int Module::OnChangeLocalUserHost(userrec* user, std::string newhost) { return 0; };
261 int Module::OnChangeLocalUserGECOS(userrec* user, std::string newhost) { return 0; };
262 int Module::OnLocalTopicChange(userrec* user, chanrec* chan, std::string topic) { return 0; };
263 void Module::OnEvent(Event* event) { return; };
264 char* Module::OnRequest(Request* request) { return NULL; };
265 int Module::OnOperCompare(std::string password, std::string input) { return 0; };
266 void Module::OnGlobalOper(userrec* user) { };
267 void Module::OnGlobalConnect(userrec* user) { };
268 int Module::OnAddBan(userrec* source, chanrec* channel,std::string banmask) { return 0; };
269 int Module::OnDelBan(userrec* source, chanrec* channel,std::string banmask) { return 0; };
270 void Module::OnRawSocketAccept(int fd, std::string ip, int localport) { };
271 int Module::OnRawSocketWrite(int fd, char* buffer, int count) { return 0; };
272 void Module::OnRawSocketClose(int fd) { };
273 int Module::OnRawSocketRead(int fd, char* buffer, unsigned int count, int &readresult) { return 0; };
274 void Module::OnUserMessage(userrec* user, void* dest, int target_type, std::string text, char status) { };
275 void Module::OnUserNotice(userrec* user, void* dest, int target_type, std::string text, char status) { };
276 void Module::OnRemoteKill(userrec* source, userrec* dest, std::string reason) { };
277 void Module::OnUserInvite(userrec* source,userrec* dest,chanrec* channel) { };
278 void Module::OnPostLocalTopicChange(userrec* user, chanrec* chan, std::string topic) { };
279 void Module::OnGetServerDescription(std::string servername,std::string &description) { };
280 void Module::OnSyncUser(userrec* user, Module* proto, void* opaque) { };
281 void Module::OnSyncChannel(chanrec* chan, Module* proto, void* opaque) { };
282 void Module::ProtoSendMode(void* opaque, int target_type, void* target, std::string modeline) { };
283 void Module::OnSyncChannelMetaData(chanrec* chan, Module* proto,void* opaque, std::string extname) { };
284 void Module::OnSyncUserMetaData(userrec* user, Module* proto,void* opaque, std::string extname) { };
285 void Module::OnSyncOtherMetaData(Module* proto, void* opaque) { };
286 void Module::OnDecodeMetaData(int target_type, void* target, std::string extname, std::string extdata) { };
287 void Module::ProtoSendMetaData(void* opaque, int target_type, void* target, std::string extname, std::string extdata) { };
288 void Module::OnWallops(userrec* user, std::string text) { };
289 void Module::OnChangeHost(userrec* user, std::string newhost) { };
290 void Module::OnChangeName(userrec* user, std::string gecos) { };
291 void Module::OnAddGLine(long duration, userrec* source, std::string reason, std::string hostmask) { };
292 void Module::OnAddZLine(long duration, userrec* source, std::string reason, std::string ipmask) { };
293 void Module::OnAddKLine(long duration, userrec* source, std::string reason, std::string hostmask) { };
294 void Module::OnAddQLine(long duration, userrec* source, std::string reason, std::string nickmask) { };
295 void Module::OnAddELine(long duration, userrec* source, std::string reason, std::string hostmask) { };
296 void Module::OnDelGLine(userrec* source, std::string hostmask) { };
297 void Module::OnDelZLine(userrec* source, std::string ipmask) { };
298 void Module::OnDelKLine(userrec* source, std::string hostmask) { };
299 void Module::OnDelQLine(userrec* source, std::string nickmask) { };
300 void Module::OnDelELine(userrec* source, std::string hostmask) { };
301 void Module::OnCleanup(int target_type, void* item) { };
302 void Module::Implements(char* Implements) { for (int j = 0; j < 255; j++) Implements[j] = 0; };
303 void Module::OnChannelDelete(chanrec* chan) { };
304 Priority Module::Prioritize() { return PRIORITY_DONTCARE; }
305 void Module::OnSetAway(userrec* user) { };
306 void Module::OnCancelAway(userrec* user) { };
308 /* server is a wrapper class that provides methods to all of the C-style
309 * exports in the core
320 void Server::AddSocket(InspSocket* sock)
322 module_sockets.push_back(sock);
325 void Server::RemoveSocket(InspSocket* sock)
327 for (std::vector<InspSocket*>::iterator a = module_sockets.begin(); a < module_sockets.end(); a++)
329 InspSocket* s = (InspSocket*)*a;
332 log(DEBUG,"Forcibly removed socket");
333 ServerInstance->SE->DelFd(s->GetFd());
335 module_sockets.erase(a);
342 long Server::PriorityAfter(std::string modulename)
344 for (unsigned int j = 0; j < Config->module_names.size(); j++)
346 if (Config->module_names[j] == modulename)
348 return ((j << 8) | PRIORITY_AFTER);
351 return PRIORITY_DONTCARE;
354 long Server::PriorityBefore(std::string modulename)
356 for (unsigned int j = 0; j < Config->module_names.size(); j++)
358 if (Config->module_names[j] == modulename)
360 return ((j << 8) | PRIORITY_BEFORE);
363 return PRIORITY_DONTCARE;
366 void Server::RehashServer()
368 WriteOpers("*** Rehashing config file");
369 Config->Read(false,NULL);
372 ServerConfig* Server::GetConfig()
377 std::string Server::GetVersion()
379 return ServerInstance->GetVersionString();
382 void Server::DelSocket(InspSocket* sock)
384 for (std::vector<InspSocket*>::iterator a = module_sockets.begin(); a < module_sockets.end(); a++)
388 module_sockets.erase(a);
394 long Server::GetChannelCount()
396 return (long)chanlist.size();
399 /* This is ugly, yes, but hash_map's arent designed to be
400 * addressed in this manner, and this is a bit of a kludge.
401 * Luckily its a specialist function and rarely used by
402 * many modules (in fact, it was specially created to make
403 * m_safelist possible, initially).
406 chanrec* Server::GetChannelIndex(long index)
409 for (chan_hash::iterator n = chanlist.begin(); n != chanlist.end(); n++, target++)
417 void Server::AddTimer(InspTimer* T)
422 void Server::SendOpers(std::string s)
424 WriteOpers("%s",s.c_str());
427 bool Server::MatchText(std::string sliteral, std::string spattern)
429 char literal[MAXBUF],pattern[MAXBUF];
430 strlcpy(literal,sliteral.c_str(),MAXBUF);
431 strlcpy(pattern,spattern.c_str(),MAXBUF);
432 return match(literal,pattern);
435 void Server::SendToModeMask(std::string modes, int flags, std::string text)
437 WriteMode(modes.c_str(),flags,"%s",text.c_str());
440 chanrec* Server::JoinUserToChannel(userrec* user, std::string cname, std::string key)
442 return add_channel(user,cname.c_str(),key.c_str(),false);
445 chanrec* Server::PartUserFromChannel(userrec* user, std::string cname, std::string reason)
447 return del_channel(user,cname.c_str(),reason.c_str(),false);
450 chanuserlist Server::GetUsers(chanrec* chan)
454 CUList *list = chan->GetUsers();
455 for (CUList::iterator i = list->begin(); i != list->end(); i++)
456 userl.push_back(i->second);
459 void Server::ChangeUserNick(userrec* user, std::string nickname)
461 force_nickchange(user,nickname.c_str());
464 void Server::KickUser(userrec* source, userrec* target, chanrec* chan, std::string reason)
468 kick_channel(source,target,chan,(char*)reason.c_str());
472 server_kick_channel(target,chan,(char*)reason.c_str(),true);
476 void Server::QuitUser(userrec* user, std::string reason)
478 kill_link(user,reason.c_str());
481 bool Server::IsUlined(std::string server)
483 return is_uline(server.c_str());
486 bool Server::CallCommandHandler(std::string commandname, char** parameters, int pcnt, userrec* user)
488 return ServerInstance->Parser->CallHandler(commandname,parameters,pcnt,user);
491 bool Server::IsValidModuleCommand(std::string commandname, int pcnt, userrec* user)
493 return ServerInstance->Parser->IsValidCommand(commandname, pcnt, user);
496 void Server::Log(int level, std::string s)
498 log(level,"%s",s.c_str());
501 void Server::AddCommand(command_t *f)
503 if (!ServerInstance->Parser->CreateCommand(f))
505 ModuleException err("Command "+std::string(f->command)+" already exists.");
510 void Server::SendMode(char **parameters, int pcnt, userrec *user)
512 ServerInstance->ModeGrok->ServerMode(parameters,pcnt,user);
515 void Server::Send(int Socket, std::string s)
517 Write_NoFormat(Socket,s.c_str());
520 void Server::SendServ(int Socket, std::string s)
522 WriteServ_NoFormat(Socket,s.c_str());
525 void Server::SendFrom(int Socket, userrec* User, std::string s)
527 WriteFrom_NoFormat(Socket,User,s.c_str());
530 void Server::SendTo(userrec* Source, userrec* Dest, std::string s)
534 // if source is NULL, then the message originates from the local server
535 WriteServ_NoFormat(Dest->fd,s.c_str());
539 // otherwise it comes from the user specified
540 WriteTo_NoFormat(Source,Dest,s.c_str());
544 void Server::SendChannelServerNotice(std::string ServName, chanrec* Channel, std::string text)
546 WriteChannelWithServ_NoFormat((char*)ServName.c_str(), Channel, text.c_str());
549 void Server::SendChannel(userrec* User, chanrec* Channel, std::string s,bool IncludeSender)
553 WriteChannel_NoFormat(Channel,User,s.c_str());
557 ChanExceptSender_NoFormat(Channel,User,0,s.c_str());
561 bool Server::CommonChannels(userrec* u1, userrec* u2)
563 return (common_channels(u1,u2) != 0);
566 void Server::DumpText(userrec* User, std::string LinePrefix, stringstream &TextStream)
568 std::string CompleteLine = LinePrefix;
569 std::string Word = "";
570 while (TextStream >> Word)
572 if (CompleteLine.length() + Word.length() + 3 > 500)
574 WriteServ_NoFormat(User->fd,CompleteLine.c_str());
575 CompleteLine = LinePrefix;
577 CompleteLine = CompleteLine + Word + " ";
579 WriteServ_NoFormat(User->fd,CompleteLine.c_str());
582 void Server::SendCommon(userrec* User, std::string text,bool IncludeSender)
586 WriteCommon_NoFormat(User,text.c_str());
590 WriteCommonExcept_NoFormat(User,text.c_str());
594 void Server::SendWallops(userrec* User, std::string text)
596 WriteWallOps(User,false,"%s",text.c_str());
599 void Server::ChangeHost(userrec* user, std::string host)
601 ChangeDisplayedHost(user,host.c_str());
604 void Server::ChangeGECOS(userrec* user, std::string gecos)
606 ChangeName(user,gecos.c_str());
609 bool Server::IsNick(std::string nick)
611 return (isnick(nick.c_str()) != 0);
614 userrec* Server::FindNick(std::string nick)
619 userrec* Server::FindDescriptor(int socket)
621 return (socket < 65536 ? fd_ref_table[socket] : NULL);
624 chanrec* Server::FindChannel(std::string channel)
626 return FindChan(channel.c_str());
629 std::string Server::ChanMode(userrec* User, chanrec* Chan)
631 return cmode(User,Chan);
634 std::string Server::GetServerName()
636 return Config->ServerName;
639 std::string Server::GetNetworkName()
641 return Config->Network;
644 std::string Server::GetServerDescription()
646 return Config->ServerDesc;
649 Admin Server::GetAdmin()
651 return Admin(Config->AdminName,Config->AdminEmail,Config->AdminNick);
656 bool Server::AddExtendedMode(char modechar, int type, bool requires_oper, int params_when_on, int params_when_off)
658 if (((modechar >= 'A') && (modechar <= 'Z')) || ((modechar >= 'a') && (modechar <= 'z')))
660 if (type == MT_SERVER)
662 ModuleException e("Modes of type MT_SERVER are reserved for future expansion");
666 if (((params_when_on>0) || (params_when_off>0)) && (type == MT_CLIENT))
668 ModuleException e("Parameters on MT_CLIENT modes are not supported");
672 if ((params_when_on>1) || (params_when_off>1))
674 ModuleException e("More than one parameter for an MT_CHANNEL mode is not yet supported");
678 return DoAddExtendedMode(modechar,type,requires_oper,params_when_on,params_when_off);
682 ModuleException e("Muppet modechar detected.");
688 bool Server::AddExtendedListMode(char modechar)
690 bool res = DoAddExtendedMode(modechar,MT_CHANNEL,false,1,1);
692 ModeMakeList(modechar);
696 int Server::CountUsers(chanrec* c)
702 bool Server::UserToPseudo(userrec* user,std::string message)
704 unsigned int old_fd = user->fd;
705 Write(old_fd,"ERROR :Closing link (%s@%s) [%s]",user->ident,user->host,message.c_str());
706 user->FlushWriteBuf();
708 user->fd = FD_MAGIC_NUMBER;
710 if (find(local_users.begin(),local_users.end(),user) != local_users.end())
712 local_users.erase(find(local_users.begin(),local_users.end(),user));
713 log(DEBUG,"Delete local user");
716 ServerInstance->SE->DelFd(old_fd);
722 bool Server::PseudoToUser(userrec* alive,userrec* zombie,std::string message)
724 log(DEBUG,"PseudoToUser");
725 zombie->fd = alive->fd;
726 FOREACH_MOD(I_OnUserQuit,OnUserQuit(alive,message));
727 alive->fd = FD_MAGIC_NUMBER;
728 alive->FlushWriteBuf();
729 alive->ClearBuffer();
730 // save these for later
731 std::string oldnick = alive->nick;
732 std::string oldhost = alive->host;
733 std::string oldident = alive->ident;
734 kill_link(alive,message.c_str());
735 if (find(local_users.begin(),local_users.end(),alive) != local_users.end())
737 local_users.erase(find(local_users.begin(),local_users.end(),alive));
738 log(DEBUG,"Delete local user");
740 // Fix by brain - cant write the user until their fd table entry is updated
741 fd_ref_table[zombie->fd] = zombie;
742 Write(zombie->fd,":%s!%s@%s NICK %s",oldnick.c_str(),oldident.c_str(),oldhost.c_str(),zombie->nick);
743 for (std::vector<ucrec*>::const_iterator i = zombie->chans.begin(); i != zombie->chans.end(); i++)
745 if (((ucrec*)(*i))->channel != NULL)
747 chanrec* Ptr = ((ucrec*)(*i))->channel;
748 WriteFrom(zombie->fd,zombie,"JOIN %s",Ptr->name);
751 WriteServ(zombie->fd,"332 %s %s :%s", zombie->nick, Ptr->name, Ptr->topic);
752 WriteServ(zombie->fd,"333 %s %s %s %d", zombie->nick, Ptr->name, Ptr->setby, Ptr->topicset);
754 userlist(zombie,Ptr);
755 WriteServ(zombie->fd,"366 %s %s :End of /NAMES list.", zombie->nick, Ptr->name);
758 if ((find(local_users.begin(),local_users.end(),zombie) == local_users.end()) && (zombie->fd != FD_MAGIC_NUMBER))
759 local_users.push_back(zombie);
764 void Server::AddGLine(long duration, std::string source, std::string reason, std::string hostmask)
766 add_gline(duration, source.c_str(), reason.c_str(), hostmask.c_str());
769 void Server::AddQLine(long duration, std::string source, std::string reason, std::string nickname)
771 add_qline(duration, source.c_str(), reason.c_str(), nickname.c_str());
774 void Server::AddZLine(long duration, std::string source, std::string reason, std::string ipaddr)
776 add_zline(duration, source.c_str(), reason.c_str(), ipaddr.c_str());
779 void Server::AddKLine(long duration, std::string source, std::string reason, std::string hostmask)
781 add_kline(duration, source.c_str(), reason.c_str(), hostmask.c_str());
784 void Server::AddELine(long duration, std::string source, std::string reason, std::string hostmask)
786 add_eline(duration, source.c_str(), reason.c_str(), hostmask.c_str());
789 bool Server::DelGLine(std::string hostmask)
791 return del_gline(hostmask.c_str());
794 bool Server::DelQLine(std::string nickname)
796 return del_qline(nickname.c_str());
799 bool Server::DelZLine(std::string ipaddr)
801 return del_zline(ipaddr.c_str());
804 bool Server::DelKLine(std::string hostmask)
806 return del_kline(hostmask.c_str());
809 bool Server::DelELine(std::string hostmask)
811 return del_eline(hostmask.c_str());
814 long Server::CalcDuration(std::string delta)
816 return duration(delta.c_str());
819 bool Server::IsValidMask(std::string mask)
821 char* dest = (char*)mask.c_str();
822 if (strchr(dest,'!')==0)
824 if (strchr(dest,'@')==0)
826 for (char* i = dest; *i; i++)
829 for (char* i = dest; *i; i++)
833 for (char* i = dest; *i; i++)
839 for (char* i = dest; *i; i++)
848 Module* Server::FindModule(std::string name)
850 for (int i = 0; i <= MODCOUNT; i++)
852 if (Config->module_names[i] == name)
860 ConfigReader::ConfigReader()
862 Config->ClearStack();
863 this->cache = new std::stringstream(std::stringstream::in | std::stringstream::out);
864 this->errorlog = new std::stringstream(std::stringstream::in | std::stringstream::out);
865 this->readerror = Config->LoadConf(CONFIG_FILE,this->cache,this->errorlog);
866 if (!this->readerror)
867 this->error = CONF_FILE_NOT_FOUND;
871 ConfigReader::~ConfigReader()
876 delete this->errorlog;
880 ConfigReader::ConfigReader(const std::string &filename)
882 Config->ClearStack();
883 this->cache = new std::stringstream(std::stringstream::in | std::stringstream::out);
884 this->errorlog = new std::stringstream(std::stringstream::in | std::stringstream::out);
885 this->readerror = Config->LoadConf(filename.c_str(),this->cache,this->errorlog);
886 if (!this->readerror)
887 this->error = CONF_FILE_NOT_FOUND;
890 std::string ConfigReader::ReadValue(const std::string &tag, const std::string &name, int index)
892 /* Don't need to strlcpy() tag and name anymore, ReadConf() takes const char* */
894 int res = Config->ReadConf(cache, tag.c_str(), name.c_str(), index, val);
897 this->error = CONF_VALUE_NOT_FOUND;
903 bool ConfigReader::ReadFlag(const std::string &tag, const std::string &name, int index)
905 /* Don't need to strlcpy() tag and name anymore, ReadConf() takes const char* */
909 int res = Config->ReadConf(cache, tag.c_str(), name.c_str(), index, val);
912 this->error = CONF_VALUE_NOT_FOUND;
918 return ((s == "yes") || (s == "YES") || (s == "true") || (s == "TRUE") || (s == "1"));
921 long ConfigReader::ReadInteger(const std::string &tag, const std::string &name, int index, bool needs_unsigned)
925 int res = Config->ReadConf(cache, tag.c_str(), name.c_str(), index, val);
928 this->error = CONF_VALUE_NOT_FOUND;
931 for (char* i = val; *i; i++)
935 this->error = CONF_NOT_A_NUMBER;
939 if ((needs_unsigned) && (atoi(val)<0))
941 this->error = CONF_NOT_UNSIGNED;
947 long ConfigReader::GetError()
949 long olderr = this->error;
954 void ConfigReader::DumpErrors(bool bail, userrec* user)
958 printf("There were errors in your configuration:\n%s",errorlog->str().c_str());
967 WriteServ(user->fd,"NOTICE %s :There were errors in the configuration file:",user->nick);
969 while (!errorlog->eof())
971 errorlog->getline(dataline,1024);
972 WriteServ(user->fd,"NOTICE %s :%s",user->nick,dataline);
977 WriteOpers("There were errors in the configuration file:",user->nick);
979 while (!errorlog->eof())
981 errorlog->getline(dataline,1024);
982 WriteOpers(dataline);
991 int ConfigReader::Enumerate(const std::string &tag)
993 return Config->EnumConf(cache,tag.c_str());
996 int ConfigReader::EnumerateValues(const std::string &tag, int index)
998 return Config->EnumValues(cache, tag.c_str(), index);
1001 bool ConfigReader::Verify()
1003 return this->readerror;
1007 FileReader::FileReader(const std::string &filename)
1010 readfile(c,filename.c_str());
1014 FileReader::FileReader()
1018 void FileReader::LoadFile(const std::string &filename)
1021 readfile(c,filename.c_str());
1026 FileReader::~FileReader()
1030 bool FileReader::Exists()
1032 return (!(fc.size() == 0));
1035 std::string FileReader::GetLine(int x)
1037 if ((x<0) || ((unsigned)x>fc.size()))
1042 int FileReader::FileSize()
1048 std::vector<Module*> modules(255);
1049 std::vector<ircd_module*> factory(255);