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;
65 // returns true if an extended mode character is in use
66 bool ModeDefined(char modechar, int type)
68 for (ExtModeListIter i = EMode.begin(); i < EMode.end(); i++)
70 if ((i->modechar == modechar) && (i->type == type))
78 bool ModeIsListMode(char modechar, int type)
80 for (ExtModeListIter i = EMode.begin(); i < EMode.end(); i++)
82 if ((i->modechar == modechar) && (i->type == type) && (i->list == true))
90 bool ModeDefinedOper(char modechar, int type)
92 for (ExtModeListIter i = EMode.begin(); i < EMode.end(); i++)
94 if ((i->modechar == modechar) && (i->type == type) && (i->needsoper == true))
102 // returns number of parameters for a custom mode when it is switched on
103 int ModeDefinedOn(char modechar, int type)
105 for (ExtModeListIter i = EMode.begin(); i < EMode.end(); i++)
107 if ((i->modechar == modechar) && (i->type == type))
109 return i->params_when_on;
115 // returns number of parameters for a custom mode when it is switched on
116 int ModeDefinedOff(char modechar, int type)
118 for (ExtModeListIter i = EMode.begin(); i < EMode.end(); i++)
120 if ((i->modechar == modechar) && (i->type == type))
122 return i->params_when_off;
128 // returns true if an extended mode character is in use
129 bool DoAddExtendedMode(char modechar, int type, bool requires_oper, int params_on, int params_off)
131 if (ModeDefined(modechar,type)) {
134 EMode.push_back(ExtMode(modechar,type,requires_oper,params_on,params_off));
138 // turns a mode into a listmode
139 void ModeMakeList(char modechar)
141 for (ExtModeListIter i = EMode.begin(); i < EMode.end(); i++)
143 if ((i->modechar == modechar) && (i->type == MT_CHANNEL))
152 // version is a simple class for holding a modules version number
154 Version::Version(int major, int minor, int revision, int build, int flags) : Major(major), Minor(minor), Revision(revision), Build(build), Flags(flags) { };
156 // admin is a simple class for holding a server's administrative info
158 Admin::Admin(std::string name, std::string email, std::string nick) : Name(name), Email(email), Nick(nick) { };
160 Request::Request(void* anydata, Module* src, Module* dst) : data(anydata), source(src), dest(dst) { };
162 char* Request::GetData()
164 return (char*)this->data;
167 Module* Request::GetSource()
172 Module* Request::GetDest()
177 char* Request::Send()
181 return dest->OnRequest(this);
189 Event::Event(void* anydata, Module* src, const std::string &eventid) : data(anydata), source(src), id(eventid) { };
191 char* Event::GetData()
193 return (char*)this->data;
196 Module* Event::GetSource()
203 FOREACH_MOD(I_OnEvent,OnEvent(this));
207 std::string Event::GetEventID()
213 // These declarations define the behavours of the base class Module (which does nothing at all)
215 Module::Module(Server* Me) { }
216 Module::~Module() { }
217 void Module::OnUserConnect(userrec* user) { }
218 void Module::OnUserQuit(userrec* user, const std::string& message) { }
219 void Module::OnUserDisconnect(userrec* user) { }
220 void Module::OnUserJoin(userrec* user, chanrec* channel) { }
221 void Module::OnUserPart(userrec* user, chanrec* channel, const std::string &partmessage) { }
222 void Module::OnRehash(const std::string ¶meter) { }
223 void Module::OnServerRaw(std::string &raw, bool inbound, userrec* user) { }
224 int Module::OnUserPreJoin(userrec* user, chanrec* chan, const char* cname) { return 0; }
225 int Module::OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list ¶ms) { return false; }
226 void Module::OnMode(userrec* user, void* dest, int target_type, const std::string &text) { };
227 Version Module::GetVersion() { return Version(1,0,0,0,VF_VENDOR); }
228 void Module::OnOper(userrec* user, const std::string &opertype) { };
229 void Module::OnPostOper(userrec* user, const std::string &opertype) { };
230 void Module::OnInfo(userrec* user) { };
231 void Module::OnWhois(userrec* source, userrec* dest) { };
232 int Module::OnUserPreInvite(userrec* source,userrec* dest,chanrec* channel) { return 0; };
233 int Module::OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text,char status) { return 0; };
234 int Module::OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text,char status) { return 0; };
235 int Module::OnUserPreNick(userrec* user, const std::string &newnick) { return 0; };
236 void Module::OnUserPostNick(userrec* user, const std::string &oldnick) { };
237 int Module::OnAccessCheck(userrec* source,userrec* dest,chanrec* channel,int access_type) { return ACR_DEFAULT; };
238 void Module::On005Numeric(std::string &output) { };
239 int Module::OnKill(userrec* source, userrec* dest, const std::string &reason) { return 0; };
240 void Module::OnLoadModule(Module* mod,const std::string &name) { };
241 void Module::OnUnloadModule(Module* mod,const std::string &name) { };
242 void Module::OnBackgroundTimer(time_t curtime) { };
243 void Module::OnSendList(userrec* user, chanrec* channel, char mode) { };
244 int Module::OnPreCommand(const std::string &command, char **parameters, int pcnt, userrec *user, bool validated) { return 0; };
245 bool Module::OnCheckReady(userrec* user) { return true; };
246 void Module::OnUserRegister(userrec* user) { };
247 int Module::OnUserPreKick(userrec* source, userrec* user, chanrec* chan, const std::string &reason) { return 0; };
248 void Module::OnUserKick(userrec* source, userrec* user, chanrec* chan, const std::string &reason) { };
249 int Module::OnRawMode(userrec* user, chanrec* chan, char mode, const std::string ¶m, bool adding, int pcnt) { return 0; };
250 int Module::OnCheckInvite(userrec* user, chanrec* chan) { return 0; };
251 int Module::OnCheckKey(userrec* user, chanrec* chan, const std::string &keygiven) { return 0; };
252 int Module::OnCheckLimit(userrec* user, chanrec* chan) { return 0; };
253 int Module::OnCheckBan(userrec* user, chanrec* chan) { return 0; };
254 int Module::OnStats(char symbol, userrec* user) { return 0; };
255 int Module::OnChangeLocalUserHost(userrec* user, const std::string &newhost) { return 0; };
256 int Module::OnChangeLocalUserGECOS(userrec* user, const std::string &newhost) { return 0; };
257 int Module::OnLocalTopicChange(userrec* user, chanrec* chan, const std::string &topic) { return 0; };
258 void Module::OnEvent(Event* event) { return; };
259 char* Module::OnRequest(Request* request) { return NULL; };
260 int Module::OnOperCompare(const std::string &password, const std::string &input) { return 0; };
261 void Module::OnGlobalOper(userrec* user) { };
262 void Module::OnGlobalConnect(userrec* user) { };
263 int Module::OnAddBan(userrec* source, chanrec* channel,const std::string &banmask) { return 0; };
264 int Module::OnDelBan(userrec* source, chanrec* channel,const std::string &banmask) { return 0; };
265 void Module::OnRawSocketAccept(int fd, const std::string &ip, int localport) { };
266 int Module::OnRawSocketWrite(int fd, char* buffer, int count) { return 0; };
267 void Module::OnRawSocketClose(int fd) { };
268 int Module::OnRawSocketRead(int fd, char* buffer, unsigned int count, int &readresult) { return 0; };
269 void Module::OnUserMessage(userrec* user, void* dest, int target_type, const std::string &text, char status) { };
270 void Module::OnUserNotice(userrec* user, void* dest, int target_type, const std::string &text, char status) { };
271 void Module::OnRemoteKill(userrec* source, userrec* dest, const std::string &reason) { };
272 void Module::OnUserInvite(userrec* source,userrec* dest,chanrec* channel) { };
273 void Module::OnPostLocalTopicChange(userrec* user, chanrec* chan, const std::string &topic) { };
274 void Module::OnGetServerDescription(const std::string &servername,std::string &description) { };
275 void Module::OnSyncUser(userrec* user, Module* proto, void* opaque) { };
276 void Module::OnSyncChannel(chanrec* chan, Module* proto, void* opaque) { };
277 void Module::ProtoSendMode(void* opaque, int target_type, void* target, const std::string &modeline) { };
278 void Module::OnSyncChannelMetaData(chanrec* chan, Module* proto,void* opaque, const std::string &extname) { };
279 void Module::OnSyncUserMetaData(userrec* user, Module* proto,void* opaque, const std::string &extname) { };
280 void Module::OnSyncOtherMetaData(Module* proto, void* opaque) { };
281 void Module::OnDecodeMetaData(int target_type, void* target, const std::string &extname, const std::string &extdata) { };
282 void Module::ProtoSendMetaData(void* opaque, int target_type, void* target, const std::string &extname, const std::string &extdata) { };
283 void Module::OnWallops(userrec* user, const std::string &text) { };
284 void Module::OnChangeHost(userrec* user, const std::string &newhost) { };
285 void Module::OnChangeName(userrec* user, const std::string &gecos) { };
286 void Module::OnAddGLine(long duration, userrec* source, const std::string &reason, const std::string &hostmask) { };
287 void Module::OnAddZLine(long duration, userrec* source, const std::string &reason, const std::string &ipmask) { };
288 void Module::OnAddKLine(long duration, userrec* source, const std::string &reason, const std::string &hostmask) { };
289 void Module::OnAddQLine(long duration, userrec* source, const std::string &reason, const std::string &nickmask) { };
290 void Module::OnAddELine(long duration, userrec* source, const std::string &reason, const std::string &hostmask) { };
291 void Module::OnDelGLine(userrec* source, const std::string &hostmask) { };
292 void Module::OnDelZLine(userrec* source, const std::string &ipmask) { };
293 void Module::OnDelKLine(userrec* source, const std::string &hostmask) { };
294 void Module::OnDelQLine(userrec* source, const std::string &nickmask) { };
295 void Module::OnDelELine(userrec* source, const std::string &hostmask) { };
296 void Module::OnCleanup(int target_type, void* item) { };
297 void Module::Implements(char* Implements) { for (int j = 0; j < 255; j++) Implements[j] = 0; };
298 void Module::OnChannelDelete(chanrec* chan) { };
299 Priority Module::Prioritize() { return PRIORITY_DONTCARE; }
300 void Module::OnSetAway(userrec* user) { };
301 void Module::OnCancelAway(userrec* user) { };
303 /* server is a wrapper class that provides methods to all of the C-style
304 * exports in the core
315 void Server::AddSocket(InspSocket* sock)
317 module_sockets.push_back(sock);
320 void Server::RemoveSocket(InspSocket* sock)
322 for (std::vector<InspSocket*>::iterator a = module_sockets.begin(); a < module_sockets.end(); a++)
324 InspSocket* s = (InspSocket*)*a;
330 long Server::PriorityAfter(const std::string &modulename)
332 for (unsigned int j = 0; j < Config->module_names.size(); j++)
334 if (Config->module_names[j] == modulename)
336 return ((j << 8) | PRIORITY_AFTER);
339 return PRIORITY_DONTCARE;
342 long Server::PriorityBefore(const 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_BEFORE);
351 return PRIORITY_DONTCARE;
354 bool Server::PublishFeature(std::string FeatureName, Module* Mod)
356 if (Features.find(FeatureName) == Features.end())
358 Features[FeatureName] = Mod;
364 bool Server::UnpublishFeature(std::string FeatureName)
366 featurelist::iterator iter = Features.find(FeatureName);
368 if (iter == Features.end())
371 Features.erase(iter);
375 Module* Server::FindFeature(std::string FeatureName)
377 featurelist::iterator iter = Features.find(FeatureName);
379 if (iter == Features.end())
385 void Server::RehashServer()
387 WriteOpers("*** Rehashing config file");
388 Config->Read(false,NULL);
391 ServerConfig* Server::GetConfig()
396 std::string Server::GetVersion()
398 return ServerInstance->GetVersionString();
401 void Server::DelSocket(InspSocket* sock)
403 for (std::vector<InspSocket*>::iterator a = module_sockets.begin(); a < module_sockets.end(); a++)
407 module_sockets.erase(a);
413 long Server::GetChannelCount()
415 return (long)chanlist.size();
418 /* This is ugly, yes, but hash_map's arent designed to be
419 * addressed in this manner, and this is a bit of a kludge.
420 * Luckily its a specialist function and rarely used by
421 * many modules (in fact, it was specially created to make
422 * m_safelist possible, initially).
425 chanrec* Server::GetChannelIndex(long index)
428 for (chan_hash::iterator n = chanlist.begin(); n != chanlist.end(); n++, target++)
436 void Server::AddTimer(InspTimer* T)
441 void Server::SendOpers(const std::string &s)
443 WriteOpers("%s",s.c_str());
446 bool Server::MatchText(const std::string &sliteral, const std::string &spattern)
448 return match(sliteral.c_str(),spattern.c_str());
451 void Server::SendToModeMask(const std::string &modes, int flags, const std::string &text)
453 WriteMode(modes.c_str(),flags,"%s",text.c_str());
456 chanrec* Server::JoinUserToChannel(userrec* user, const std::string &cname, const std::string &key)
458 return add_channel(user,cname.c_str(),key.c_str(),false);
461 chanrec* Server::PartUserFromChannel(userrec* user, const std::string &cname, const std::string &reason)
463 return del_channel(user,cname.c_str(),reason.c_str(),false);
466 chanuserlist Server::GetUsers(chanrec* chan)
470 CUList *list = chan->GetUsers();
471 for (CUList::iterator i = list->begin(); i != list->end(); i++)
472 userl.push_back(i->second);
475 void Server::ChangeUserNick(userrec* user, const std::string &nickname)
477 force_nickchange(user,nickname.c_str());
480 void Server::KickUser(userrec* source, userrec* target, chanrec* chan, const std::string &reason)
484 kick_channel(source,target,chan,(char*)reason.c_str());
488 server_kick_channel(target,chan,(char*)reason.c_str(),true);
492 void Server::QuitUser(userrec* user, const std::string &reason)
494 kill_link(user,reason.c_str());
497 bool Server::IsUlined(const std::string &server)
499 return is_uline(server.c_str());
502 bool Server::CallCommandHandler(const std::string &commandname, char** parameters, int pcnt, userrec* user)
504 return ServerInstance->Parser->CallHandler(commandname,parameters,pcnt,user);
507 bool Server::IsValidModuleCommand(const std::string &commandname, int pcnt, userrec* user)
509 return ServerInstance->Parser->IsValidCommand(commandname, pcnt, user);
512 void Server::Log(int level, const std::string &s)
514 log(level,"%s",s.c_str());
517 void Server::AddCommand(command_t *f)
519 if (!ServerInstance->Parser->CreateCommand(f))
521 ModuleException err("Command "+std::string(f->command)+" already exists.");
526 void Server::SendMode(char **parameters, int pcnt, userrec *user)
528 ServerInstance->ModeGrok->ServerMode(parameters,pcnt,user);
531 void Server::Send(int Socket, const std::string &s)
533 Write_NoFormat(Socket,s.c_str());
536 void Server::SendServ(int Socket, const std::string &s)
538 WriteServ_NoFormat(Socket,s.c_str());
541 void Server::SendFrom(int Socket, userrec* User, const std::string &s)
543 WriteFrom_NoFormat(Socket,User,s.c_str());
546 void Server::SendTo(userrec* Source, userrec* Dest, const std::string &s)
550 // if source is NULL, then the message originates from the local server
551 WriteServ_NoFormat(Dest->fd,s.c_str());
555 // otherwise it comes from the user specified
556 WriteTo_NoFormat(Source,Dest,s.c_str());
560 void Server::SendChannelServerNotice(const std::string &ServName, chanrec* Channel, const std::string &text)
562 WriteChannelWithServ_NoFormat((char*)ServName.c_str(), Channel, text.c_str());
565 void Server::SendChannel(userrec* User, chanrec* Channel, const std::string &s, bool IncludeSender)
569 WriteChannel_NoFormat(Channel,User,s.c_str());
573 ChanExceptSender_NoFormat(Channel,User,0,s.c_str());
577 bool Server::CommonChannels(userrec* u1, userrec* u2)
579 return (common_channels(u1,u2) != 0);
582 void Server::DumpText(userrec* User, const std::string &LinePrefix, stringstream &TextStream)
584 std::string CompleteLine = LinePrefix;
585 std::string Word = "";
586 while (TextStream >> Word)
588 if (CompleteLine.length() + Word.length() + 3 > 500)
590 WriteServ_NoFormat(User->fd,CompleteLine.c_str());
591 CompleteLine = LinePrefix;
593 CompleteLine = CompleteLine + Word + " ";
595 WriteServ_NoFormat(User->fd,CompleteLine.c_str());
598 void Server::SendCommon(userrec* User, const std::string &text, bool IncludeSender)
602 WriteCommon_NoFormat(User,text.c_str());
606 WriteCommonExcept_NoFormat(User,text.c_str());
610 void Server::SendWallops(userrec* User, const std::string &text)
612 WriteWallOps(User,false,"%s",text.c_str());
615 void Server::ChangeHost(userrec* user, const std::string &host)
617 ChangeDisplayedHost(user,host.c_str());
620 void Server::ChangeGECOS(userrec* user, const std::string &gecos)
622 ChangeName(user,gecos.c_str());
625 bool Server::IsNick(const std::string &nick)
627 return (isnick(nick.c_str()) != 0);
630 userrec* Server::FindNick(const std::string &nick)
635 userrec* Server::FindDescriptor(int socket)
637 return (socket < 65536 ? fd_ref_table[socket] : NULL);
640 chanrec* Server::FindChannel(const std::string &channel)
642 return FindChan(channel.c_str());
645 std::string Server::ChanMode(userrec* User, chanrec* Chan)
647 return cmode(User,Chan);
650 std::string Server::GetServerName()
652 return Config->ServerName;
655 std::string Server::GetNetworkName()
657 return Config->Network;
660 std::string Server::GetServerDescription()
662 return Config->ServerDesc;
665 Admin Server::GetAdmin()
667 return Admin(Config->AdminName,Config->AdminEmail,Config->AdminNick);
672 bool Server::AddExtendedMode(char modechar, int type, bool requires_oper, int params_when_on, int params_when_off)
674 if (((modechar >= 'A') && (modechar <= 'Z')) || ((modechar >= 'a') && (modechar <= 'z')))
676 if (type == MT_SERVER)
678 ModuleException e("Modes of type MT_SERVER are reserved for future expansion");
682 if (((params_when_on>0) || (params_when_off>0)) && (type == MT_CLIENT))
684 ModuleException e("Parameters on MT_CLIENT modes are not supported");
688 if ((params_when_on>1) || (params_when_off>1))
690 ModuleException e("More than one parameter for an MT_CHANNEL mode is not yet supported");
694 return DoAddExtendedMode(modechar,type,requires_oper,params_when_on,params_when_off);
698 ModuleException e("Muppet modechar detected.");
704 bool Server::AddExtendedListMode(char modechar)
706 bool res = DoAddExtendedMode(modechar,MT_CHANNEL,false,1,1);
708 ModeMakeList(modechar);
712 int Server::CountUsers(chanrec* c)
718 bool Server::UserToPseudo(userrec* user, const std::string &message)
720 unsigned int old_fd = user->fd;
721 Write(old_fd,"ERROR :Closing link (%s@%s) [%s]",user->ident,user->host,message.c_str());
722 user->FlushWriteBuf();
724 user->fd = FD_MAGIC_NUMBER;
726 if (find(local_users.begin(),local_users.end(),user) != local_users.end())
728 local_users.erase(find(local_users.begin(),local_users.end(),user));
729 log(DEBUG,"Delete local user");
732 ServerInstance->SE->DelFd(old_fd);
738 bool Server::PseudoToUser(userrec* alive, userrec* zombie, const std::string &message)
740 log(DEBUG,"PseudoToUser");
741 zombie->fd = alive->fd;
742 FOREACH_MOD(I_OnUserQuit,OnUserQuit(alive,message));
743 alive->fd = FD_MAGIC_NUMBER;
744 alive->FlushWriteBuf();
745 alive->ClearBuffer();
746 // save these for later
747 std::string oldnick = alive->nick;
748 std::string oldhost = alive->host;
749 std::string oldident = alive->ident;
750 kill_link(alive,message.c_str());
751 if (find(local_users.begin(),local_users.end(),alive) != local_users.end())
753 local_users.erase(find(local_users.begin(),local_users.end(),alive));
754 log(DEBUG,"Delete local user");
756 // Fix by brain - cant write the user until their fd table entry is updated
757 fd_ref_table[zombie->fd] = zombie;
758 Write(zombie->fd,":%s!%s@%s NICK %s",oldnick.c_str(),oldident.c_str(),oldhost.c_str(),zombie->nick);
759 for (std::vector<ucrec*>::const_iterator i = zombie->chans.begin(); i != zombie->chans.end(); i++)
761 if (((ucrec*)(*i))->channel != NULL)
763 chanrec* Ptr = ((ucrec*)(*i))->channel;
764 WriteFrom(zombie->fd,zombie,"JOIN %s",Ptr->name);
767 WriteServ(zombie->fd,"332 %s %s :%s", zombie->nick, Ptr->name, Ptr->topic);
768 WriteServ(zombie->fd,"333 %s %s %s %d", zombie->nick, Ptr->name, Ptr->setby, Ptr->topicset);
770 userlist(zombie,Ptr);
771 WriteServ(zombie->fd,"366 %s %s :End of /NAMES list.", zombie->nick, Ptr->name);
774 if ((find(local_users.begin(),local_users.end(),zombie) == local_users.end()) && (zombie->fd != FD_MAGIC_NUMBER))
775 local_users.push_back(zombie);
780 void Server::AddGLine(long duration, const std::string &source, const std::string &reason, const std::string &hostmask)
782 add_gline(duration, source.c_str(), reason.c_str(), hostmask.c_str());
785 void Server::AddQLine(long duration, const std::string &source, const std::string &reason, const std::string &nickname)
787 add_qline(duration, source.c_str(), reason.c_str(), nickname.c_str());
790 void Server::AddZLine(long duration, const std::string &source, const std::string &reason, const std::string &ipaddr)
792 add_zline(duration, source.c_str(), reason.c_str(), ipaddr.c_str());
795 void Server::AddKLine(long duration, const std::string &source, const std::string &reason, const std::string &hostmask)
797 add_kline(duration, source.c_str(), reason.c_str(), hostmask.c_str());
800 void Server::AddELine(long duration, const std::string &source, const std::string &reason, const std::string &hostmask)
802 add_eline(duration, source.c_str(), reason.c_str(), hostmask.c_str());
805 bool Server::DelGLine(const std::string &hostmask)
807 return del_gline(hostmask.c_str());
810 bool Server::DelQLine(const std::string &nickname)
812 return del_qline(nickname.c_str());
815 bool Server::DelZLine(const std::string &ipaddr)
817 return del_zline(ipaddr.c_str());
820 bool Server::DelKLine(const std::string &hostmask)
822 return del_kline(hostmask.c_str());
825 bool Server::DelELine(const std::string &hostmask)
827 return del_eline(hostmask.c_str());
830 long Server::CalcDuration(const std::string &delta)
832 return duration(delta.c_str());
836 * XXX why on *earth* is this in modules.cpp...? I think
837 * perhaps we need a server.cpp for Server:: stuff where possible. -- w00t
839 bool Server::IsValidMask(const std::string &mask)
841 char* dest = (char*)mask.c_str();
842 if (strchr(dest,'!')==0)
844 if (strchr(dest,'@')==0)
846 for (char* i = dest; *i; i++)
849 for (char* i = dest; *i; i++)
853 for (char* i = dest; *i; i++)
859 for (char* i = dest; *i; i++)
868 Module* Server::FindModule(const std::string &name)
870 for (int i = 0; i <= MODCOUNT; i++)
872 if (Config->module_names[i] == name)
880 ConfigReader::ConfigReader()
882 // Config->ClearStack();
884 /* Is there any reason to load the entire config file again here?
885 * it's needed if they specify another config file, but using the
886 * default one we can just use the global config data - pre-parsed!
888 //~ this->cache = new std::stringstream(std::stringstream::in | std::stringstream::out);
889 this->errorlog = new std::ostringstream(std::stringstream::in | std::stringstream::out);
891 //~ this->readerror = Config->LoadConf(CONFIG_FILE, this->cache,this->errorlog);
892 //~ if (!this->readerror)
893 //~ this->error = CONF_FILE_NOT_FOUND;
895 this->data = &Config->config_data;
896 this->privatehash = false;
900 ConfigReader::~ConfigReader()
903 //~ delete this->cache;
905 DELETE(this->errorlog);
906 if(this->privatehash)
911 ConfigReader::ConfigReader(const std::string &filename)
913 Config->ClearStack();
915 this->data = new ConfigDataHash;
916 this->privatehash = true;
917 this->errorlog = new std::ostringstream(std::stringstream::in | std::stringstream::out);
918 this->readerror = Config->LoadConf(*this->data, filename, *this->errorlog);
919 if (!this->readerror)
920 this->error = CONF_FILE_NOT_FOUND;
923 std::string ConfigReader::ReadValue(const std::string &tag, const std::string &name, int index)
925 /* Don't need to strlcpy() tag and name anymore, ReadConf() takes const char* */
928 if (!Config->ConfValue(*this->data, tag, name, index, result))
930 this->error = CONF_VALUE_NOT_FOUND;
937 bool ConfigReader::ReadFlag(const std::string &tag, const std::string &name, int index)
939 return Config->ConfValueBool(*this->data, tag, name, index);
942 long ConfigReader::ReadInteger(const std::string &tag, const std::string &name, int index, bool needs_unsigned)
946 if(!Config->ConfValueInteger(*this->data, tag, name, index, result))
948 this->error = CONF_VALUE_NOT_FOUND;
952 if ((needs_unsigned) && (result < 0))
954 this->error = CONF_NOT_UNSIGNED;
961 long ConfigReader::GetError()
963 long olderr = this->error;
968 void ConfigReader::DumpErrors(bool bail, userrec* user)
970 /* XXX - Duplicated code */
974 printf("There were errors in your configuration:\n%s", this->errorlog->str().c_str());
979 std::string errors = this->errorlog->str();
980 std::string::size_type start;
981 unsigned int prefixlen;
984 /* ":Config->ServerName NOTICE user->nick :" */
985 prefixlen = strlen(Config->ServerName) + strlen(user->nick) + 11;
989 WriteServ(user->fd,"NOTICE %s :There were errors in the configuration file:",user->nick);
991 while(start < errors.length())
993 WriteServ(user->fd, "NOTICE %s :%s",user->nick, errors.substr(start, 510 - prefixlen).c_str());
994 start += 510 - prefixlen;
999 WriteOpers("There were errors in the configuration file:");
1001 while(start < errors.length())
1003 WriteOpers(errors.substr(start, 360).c_str());
1013 int ConfigReader::Enumerate(const std::string &tag)
1015 return Config->ConfValueEnum(*this->data, tag);
1018 int ConfigReader::EnumerateValues(const std::string &tag, int index)
1020 return Config->ConfVarEnum(*this->data, tag, index);
1023 bool ConfigReader::Verify()
1025 return this->readerror;
1029 FileReader::FileReader(const std::string &filename)
1032 readfile(c,filename.c_str());
1036 FileReader::FileReader()
1040 void FileReader::LoadFile(const std::string &filename)
1043 readfile(c,filename.c_str());
1048 FileReader::~FileReader()
1052 bool FileReader::Exists()
1054 return (!(fc.size() == 0));
1057 std::string FileReader::GetLine(int x)
1059 if ((x<0) || ((unsigned)x>fc.size()))
1064 int FileReader::FileSize()
1070 std::vector<Module*> modules(255);
1071 std::vector<ircd_module*> factory(255);