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"
48 extern ServerConfig *Config;
49 extern InspIRCd* ServerInstance;
51 extern ModuleList modules;
52 extern FactoryList factory;
53 extern std::vector<InspSocket*> module_sockets;
54 extern std::vector<userrec*> local_users;
56 extern userrec* fd_ref_table[MAX_DESCRIPTORS];
57 extern user_hash clientlist;
58 extern chan_hash chanlist;
59 extern command_table cmdlist;
65 // version is a simple class for holding a modules version number
67 Version::Version(int major, int minor, int revision, int build, int flags)
68 : Major(major), Minor(minor), Revision(revision), Build(build), Flags(flags)
72 // admin is a simple class for holding a server's administrative info
74 Admin::Admin(std::string name, std::string email, std::string nick)
75 : Name(name), Email(email), Nick(nick)
79 Request::Request(char* anydata, Module* src, Module* dst)
80 : data(anydata), source(src), dest(dst)
82 /* Ensure that because this module doesnt support ID strings, it doesnt break modules that do
83 * by passing them uninitialized pointers (could happen)
88 Request::Request(Module* src, Module* dst, const char* idstr)
89 : id(idstr), source(src), dest(dst)
93 char* Request::GetData()
98 const char* Request::GetId()
103 Module* Request::GetSource()
108 Module* Request::GetDest()
113 char* Request::Send()
117 return dest->OnRequest(this);
125 Event::Event(char* anydata, Module* src, const std::string &eventid) : data(anydata), source(src), id(eventid) { };
127 char* Event::GetData()
129 return (char*)this->data;
132 Module* Event::GetSource()
139 FOREACH_MOD(I_OnEvent,OnEvent(this));
143 std::string Event::GetEventID()
149 // These declarations define the behavours of the base class Module (which does nothing at all)
151 Module::Module(Server* Me) { }
152 Module::~Module() { }
153 void Module::OnUserConnect(userrec* user) { }
154 void Module::OnUserQuit(userrec* user, const std::string& message) { }
155 void Module::OnUserDisconnect(userrec* user) { }
156 void Module::OnUserJoin(userrec* user, chanrec* channel) { }
157 void Module::OnUserPart(userrec* user, chanrec* channel, const std::string &partmessage) { }
158 void Module::OnRehash(const std::string ¶meter) { }
159 void Module::OnServerRaw(std::string &raw, bool inbound, userrec* user) { }
160 int Module::OnUserPreJoin(userrec* user, chanrec* chan, const char* cname) { return 0; }
161 void Module::OnMode(userrec* user, void* dest, int target_type, const std::string &text) { };
162 Version Module::GetVersion() { return Version(1,0,0,0,VF_VENDOR); }
163 void Module::OnOper(userrec* user, const std::string &opertype) { };
164 void Module::OnPostOper(userrec* user, const std::string &opertype) { };
165 void Module::OnInfo(userrec* user) { };
166 void Module::OnWhois(userrec* source, userrec* dest) { };
167 int Module::OnUserPreInvite(userrec* source,userrec* dest,chanrec* channel) { return 0; };
168 int Module::OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text,char status) { return 0; };
169 int Module::OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text,char status) { return 0; };
170 int Module::OnUserPreNick(userrec* user, const std::string &newnick) { return 0; };
171 void Module::OnUserPostNick(userrec* user, const std::string &oldnick) { };
172 int Module::OnAccessCheck(userrec* source,userrec* dest,chanrec* channel,int access_type) { return ACR_DEFAULT; };
173 void Module::On005Numeric(std::string &output) { };
174 int Module::OnKill(userrec* source, userrec* dest, const std::string &reason) { return 0; };
175 void Module::OnLoadModule(Module* mod,const std::string &name) { };
176 void Module::OnUnloadModule(Module* mod,const std::string &name) { };
177 void Module::OnBackgroundTimer(time_t curtime) { };
178 int Module::OnPreCommand(const std::string &command, const char** parameters, int pcnt, userrec *user, bool validated) { return 0; };
179 bool Module::OnCheckReady(userrec* user) { return true; };
180 void Module::OnUserRegister(userrec* user) { };
181 int Module::OnUserPreKick(userrec* source, userrec* user, chanrec* chan, const std::string &reason) { return 0; };
182 void Module::OnUserKick(userrec* source, userrec* user, chanrec* chan, const std::string &reason) { };
183 int Module::OnRawMode(userrec* user, chanrec* chan, char mode, const std::string ¶m, bool adding, int pcnt) { return 0; };
184 int Module::OnCheckInvite(userrec* user, chanrec* chan) { return 0; };
185 int Module::OnCheckKey(userrec* user, chanrec* chan, const std::string &keygiven) { return 0; };
186 int Module::OnCheckLimit(userrec* user, chanrec* chan) { return 0; };
187 int Module::OnCheckBan(userrec* user, chanrec* chan) { return 0; };
188 int Module::OnStats(char symbol, userrec* user, string_list &results) { return 0; };
189 int Module::OnChangeLocalUserHost(userrec* user, const std::string &newhost) { return 0; };
190 int Module::OnChangeLocalUserGECOS(userrec* user, const std::string &newhost) { return 0; };
191 int Module::OnLocalTopicChange(userrec* user, chanrec* chan, const std::string &topic) { return 0; };
192 void Module::OnEvent(Event* event) { return; };
193 char* Module::OnRequest(Request* request) { return NULL; };
194 int Module::OnOperCompare(const std::string &password, const std::string &input) { return 0; };
195 void Module::OnGlobalOper(userrec* user) { };
196 void Module::OnGlobalConnect(userrec* user) { };
197 int Module::OnAddBan(userrec* source, chanrec* channel,const std::string &banmask) { return 0; };
198 int Module::OnDelBan(userrec* source, chanrec* channel,const std::string &banmask) { return 0; };
199 void Module::OnRawSocketAccept(int fd, const std::string &ip, int localport) { };
200 int Module::OnRawSocketWrite(int fd, char* buffer, int count) { return 0; };
201 void Module::OnRawSocketClose(int fd) { };
202 int Module::OnRawSocketRead(int fd, char* buffer, unsigned int count, int &readresult) { return 0; };
203 void Module::OnUserMessage(userrec* user, void* dest, int target_type, const std::string &text, char status) { };
204 void Module::OnUserNotice(userrec* user, void* dest, int target_type, const std::string &text, char status) { };
205 void Module::OnRemoteKill(userrec* source, userrec* dest, const std::string &reason) { };
206 void Module::OnUserInvite(userrec* source,userrec* dest,chanrec* channel) { };
207 void Module::OnPostLocalTopicChange(userrec* user, chanrec* chan, const std::string &topic) { };
208 void Module::OnGetServerDescription(const std::string &servername,std::string &description) { };
209 void Module::OnSyncUser(userrec* user, Module* proto, void* opaque) { };
210 void Module::OnSyncChannel(chanrec* chan, Module* proto, void* opaque) { };
211 void Module::ProtoSendMode(void* opaque, int target_type, void* target, const std::string &modeline) { };
212 void Module::OnSyncChannelMetaData(chanrec* chan, Module* proto,void* opaque, const std::string &extname) { };
213 void Module::OnSyncUserMetaData(userrec* user, Module* proto,void* opaque, const std::string &extname) { };
214 void Module::OnSyncOtherMetaData(Module* proto, void* opaque) { };
215 void Module::OnDecodeMetaData(int target_type, void* target, const std::string &extname, const std::string &extdata) { };
216 void Module::ProtoSendMetaData(void* opaque, int target_type, void* target, const std::string &extname, const std::string &extdata) { };
217 void Module::OnWallops(userrec* user, const std::string &text) { };
218 void Module::OnChangeHost(userrec* user, const std::string &newhost) { };
219 void Module::OnChangeName(userrec* user, const std::string &gecos) { };
220 void Module::OnAddGLine(long duration, userrec* source, const std::string &reason, const std::string &hostmask) { };
221 void Module::OnAddZLine(long duration, userrec* source, const std::string &reason, const std::string &ipmask) { };
222 void Module::OnAddKLine(long duration, userrec* source, const std::string &reason, const std::string &hostmask) { };
223 void Module::OnAddQLine(long duration, userrec* source, const std::string &reason, const std::string &nickmask) { };
224 void Module::OnAddELine(long duration, userrec* source, const std::string &reason, const std::string &hostmask) { };
225 void Module::OnDelGLine(userrec* source, const std::string &hostmask) { };
226 void Module::OnDelZLine(userrec* source, const std::string &ipmask) { };
227 void Module::OnDelKLine(userrec* source, const std::string &hostmask) { };
228 void Module::OnDelQLine(userrec* source, const std::string &nickmask) { };
229 void Module::OnDelELine(userrec* source, const std::string &hostmask) { };
230 void Module::OnCleanup(int target_type, void* item) { };
231 void Module::Implements(char* Implements) { for (int j = 0; j < 255; j++) Implements[j] = 0; };
232 void Module::OnChannelDelete(chanrec* chan) { };
233 Priority Module::Prioritize() { return PRIORITY_DONTCARE; }
234 void Module::OnSetAway(userrec* user) { };
235 void Module::OnCancelAway(userrec* user) { };
237 /* server is a wrapper class that provides methods to all of the C-style
238 * exports in the core
249 void Server::AddSocket(InspSocket* sock)
251 module_sockets.push_back(sock);
254 void Server::RemoveSocket(InspSocket* sock)
256 for (std::vector<InspSocket*>::iterator a = module_sockets.begin(); a < module_sockets.end(); a++)
258 InspSocket* s = (InspSocket*)*a;
264 long Server::PriorityAfter(const std::string &modulename)
266 for (unsigned int j = 0; j < Config->module_names.size(); j++)
268 if (Config->module_names[j] == modulename)
270 return ((j << 8) | PRIORITY_AFTER);
273 return PRIORITY_DONTCARE;
276 long Server::PriorityBefore(const std::string &modulename)
278 for (unsigned int j = 0; j < Config->module_names.size(); j++)
280 if (Config->module_names[j] == modulename)
282 return ((j << 8) | PRIORITY_BEFORE);
285 return PRIORITY_DONTCARE;
288 bool Server::PublishFeature(const std::string &FeatureName, Module* Mod)
290 if (Features.find(FeatureName) == Features.end())
292 Features[FeatureName] = Mod;
298 bool Server::UnpublishFeature(const std::string &FeatureName)
300 featurelist::iterator iter = Features.find(FeatureName);
302 if (iter == Features.end())
305 Features.erase(iter);
309 Module* Server::FindFeature(const std::string &FeatureName)
311 featurelist::iterator iter = Features.find(FeatureName);
313 if (iter == Features.end())
319 const std::string& Server::GetModuleName(Module* m)
321 static std::string nothing = ""; /* Prevent compiler warning */
322 for (int i = 0; i <= MODCOUNT; i++)
326 return Config->module_names[i];
329 return nothing; /* As above */
332 void Server::RehashServer()
334 WriteOpers("*** Rehashing config file");
335 Config->Read(false,NULL);
338 ServerConfig* Server::GetConfig()
343 std::string Server::GetVersion()
345 return ServerInstance->GetVersionString();
348 void Server::DelSocket(InspSocket* sock)
350 for (std::vector<InspSocket*>::iterator a = module_sockets.begin(); a < module_sockets.end(); a++)
354 module_sockets.erase(a);
360 long Server::GetChannelCount()
362 return (long)chanlist.size();
365 /* This is ugly, yes, but hash_map's arent designed to be
366 * addressed in this manner, and this is a bit of a kludge.
367 * Luckily its a specialist function and rarely used by
368 * many modules (in fact, it was specially created to make
369 * m_safelist possible, initially).
372 chanrec* Server::GetChannelIndex(long index)
375 for (chan_hash::iterator n = chanlist.begin(); n != chanlist.end(); n++, target++)
383 void Server::AddTimer(InspTimer* T)
388 void Server::SendOpers(const std::string &s)
390 WriteOpers("%s",s.c_str());
393 bool Server::MatchText(const std::string &sliteral, const std::string &spattern)
395 return match(sliteral.c_str(),spattern.c_str());
398 void Server::SendToModeMask(const std::string &modes, int flags, const std::string &text)
400 WriteMode(modes.c_str(),flags,"%s",text.c_str());
403 chanrec* Server::JoinUserToChannel(userrec* user, const std::string &cname, const std::string &key)
405 return add_channel(user,cname.c_str(),key.c_str(),false);
408 chanrec* Server::PartUserFromChannel(userrec* user, const std::string &cname, const std::string &reason)
410 return del_channel(user,cname.c_str(),reason.c_str(),false);
413 chanuserlist Server::GetUsers(chanrec* chan)
417 CUList *list = chan->GetUsers();
418 for (CUList::iterator i = list->begin(); i != list->end(); i++)
419 userl.push_back(i->second);
422 void Server::ChangeUserNick(userrec* user, const std::string &nickname)
424 force_nickchange(user,nickname.c_str());
427 void Server::KickUser(userrec* source, userrec* target, chanrec* chan, const std::string &reason)
431 kick_channel(source,target,chan,(char*)reason.c_str());
435 server_kick_channel(target,chan,(char*)reason.c_str(),true);
439 void Server::QuitUser(userrec* user, const std::string &reason)
441 kill_link(user,reason.c_str());
444 bool Server::IsUlined(const std::string &server)
446 return is_uline(server.c_str());
449 bool Server::CallCommandHandler(const std::string &commandname, const char** parameters, int pcnt, userrec* user)
451 return ServerInstance->Parser->CallHandler(commandname,parameters,pcnt,user);
454 bool Server::IsValidModuleCommand(const std::string &commandname, int pcnt, userrec* user)
456 return ServerInstance->Parser->IsValidCommand(commandname, pcnt, user);
459 void Server::Log(int level, const std::string &s)
461 log(level,"%s",s.c_str());
464 void Server::AddCommand(command_t *f)
466 if (!ServerInstance->Parser->CreateCommand(f))
468 ModuleException err("Command "+std::string(f->command)+" already exists.");
473 void Server::SendMode(const char** parameters, int pcnt, userrec *user)
475 ServerInstance->ModeGrok->Process(parameters,pcnt,user,true);
478 void Server::Send(int Socket, const std::string &s)
480 Write_NoFormat(Socket,s.c_str());
483 void Server::SendServ(int Socket, const std::string &s)
485 WriteServ_NoFormat(Socket,s.c_str());
488 void Server::SendFrom(int Socket, userrec* User, const std::string &s)
490 WriteFrom_NoFormat(Socket,User,s.c_str());
493 void Server::SendTo(userrec* Source, userrec* Dest, const std::string &s)
497 // if source is NULL, then the message originates from the local server
498 WriteServ_NoFormat(Dest->fd,s.c_str());
502 // otherwise it comes from the user specified
503 WriteTo_NoFormat(Source,Dest,s.c_str());
507 void Server::SendChannelServerNotice(const std::string &ServName, chanrec* Channel, const std::string &text)
509 WriteChannelWithServ_NoFormat((char*)ServName.c_str(), Channel, text.c_str());
512 void Server::SendChannel(userrec* User, chanrec* Channel, const std::string &s, bool IncludeSender)
516 WriteChannel_NoFormat(Channel,User,s.c_str());
520 ChanExceptSender_NoFormat(Channel,User,0,s.c_str());
524 bool Server::CommonChannels(userrec* u1, userrec* u2)
526 return (common_channels(u1,u2) != 0);
529 void Server::DumpText(userrec* User, const std::string &LinePrefix, stringstream &TextStream)
531 std::string CompleteLine = LinePrefix;
532 std::string Word = "";
533 while (TextStream >> Word)
535 if (CompleteLine.length() + Word.length() + 3 > 500)
537 WriteServ_NoFormat(User->fd,CompleteLine.c_str());
538 CompleteLine = LinePrefix;
540 CompleteLine = CompleteLine + Word + " ";
542 WriteServ_NoFormat(User->fd,CompleteLine.c_str());
545 void Server::SendCommon(userrec* User, const std::string &text, bool IncludeSender)
549 WriteCommon_NoFormat(User,text.c_str());
553 WriteCommonExcept_NoFormat(User,text.c_str());
557 void Server::SendWallops(userrec* User, const std::string &text)
559 WriteWallOps(User,false,"%s",text.c_str());
562 void Server::ChangeHost(userrec* user, const std::string &host)
564 ChangeDisplayedHost(user,host.c_str());
567 void Server::ChangeGECOS(userrec* user, const std::string &gecos)
569 ChangeName(user,gecos.c_str());
572 bool Server::IsNick(const std::string &nick)
574 return (isnick(nick.c_str()) != 0);
577 userrec* Server::FindNick(const std::string &nick)
582 userrec* Server::FindDescriptor(int socket)
584 return (socket < 65536 ? fd_ref_table[socket] : NULL);
587 chanrec* Server::FindChannel(const std::string &channel)
589 return FindChan(channel.c_str());
592 std::string Server::ChanMode(userrec* User, chanrec* Chan)
594 return cmode(User,Chan);
597 std::string Server::GetServerName()
599 return Config->ServerName;
602 std::string Server::GetNetworkName()
604 return Config->Network;
607 std::string Server::GetServerDescription()
609 return Config->ServerDesc;
612 Admin Server::GetAdmin()
614 return Admin(Config->AdminName,Config->AdminEmail,Config->AdminNick);
618 bool Server::AddMode(ModeHandler* mh, const unsigned char mode)
620 return ServerInstance->ModeGrok->AddMode(mh,mode);
623 bool Server::AddModeWatcher(ModeWatcher* mw)
625 return ServerInstance->ModeGrok->AddModeWatcher(mw);
628 bool Server::DelModeWatcher(ModeWatcher* mw)
630 return ServerInstance->ModeGrok->DelModeWatcher(mw);
633 bool Server::AddResolver(Resolver* r)
635 return ServerInstance->Res->AddResolverClass(r);
638 int Server::CountUsers(chanrec* c)
643 bool Server::UserToPseudo(userrec* user, const std::string &message)
645 unsigned int old_fd = user->fd;
646 Write(old_fd,"ERROR :Closing link (%s@%s) [%s]",user->ident,user->host,message.c_str());
647 user->FlushWriteBuf();
649 user->fd = FD_MAGIC_NUMBER;
651 if (find(local_users.begin(),local_users.end(),user) != local_users.end())
653 local_users.erase(find(local_users.begin(),local_users.end(),user));
654 log(DEBUG,"Delete local user");
657 ServerInstance->SE->DelFd(old_fd);
663 bool Server::PseudoToUser(userrec* alive, userrec* zombie, const std::string &message)
665 log(DEBUG,"PseudoToUser");
666 zombie->fd = alive->fd;
667 FOREACH_MOD(I_OnUserQuit,OnUserQuit(alive,message));
668 alive->fd = FD_MAGIC_NUMBER;
669 alive->FlushWriteBuf();
670 alive->ClearBuffer();
671 // save these for later
672 std::string oldnick = alive->nick;
673 std::string oldhost = alive->host;
674 std::string oldident = alive->ident;
675 kill_link(alive,message.c_str());
676 if (find(local_users.begin(),local_users.end(),alive) != local_users.end())
678 local_users.erase(find(local_users.begin(),local_users.end(),alive));
679 log(DEBUG,"Delete local user");
681 // Fix by brain - cant write the user until their fd table entry is updated
682 fd_ref_table[zombie->fd] = zombie;
683 Write(zombie->fd,":%s!%s@%s NICK %s",oldnick.c_str(),oldident.c_str(),oldhost.c_str(),zombie->nick);
684 for (std::vector<ucrec*>::const_iterator i = zombie->chans.begin(); i != zombie->chans.end(); i++)
686 if (((ucrec*)(*i))->channel != NULL)
688 chanrec* Ptr = ((ucrec*)(*i))->channel;
689 WriteFrom(zombie->fd,zombie,"JOIN %s",Ptr->name);
692 WriteServ(zombie->fd,"332 %s %s :%s", zombie->nick, Ptr->name, Ptr->topic);
693 WriteServ(zombie->fd,"333 %s %s %s %d", zombie->nick, Ptr->name, Ptr->setby, Ptr->topicset);
695 userlist(zombie,Ptr);
696 WriteServ(zombie->fd,"366 %s %s :End of /NAMES list.", zombie->nick, Ptr->name);
699 if ((find(local_users.begin(),local_users.end(),zombie) == local_users.end()) && (zombie->fd != FD_MAGIC_NUMBER))
700 local_users.push_back(zombie);
705 void Server::AddGLine(long duration, const std::string &source, const std::string &reason, const std::string &hostmask)
707 add_gline(duration, source.c_str(), reason.c_str(), hostmask.c_str());
708 apply_lines(APPLY_GLINES);
711 void Server::AddQLine(long duration, const std::string &source, const std::string &reason, const std::string &nickname)
713 add_qline(duration, source.c_str(), reason.c_str(), nickname.c_str());
714 apply_lines(APPLY_QLINES);
717 void Server::AddZLine(long duration, const std::string &source, const std::string &reason, const std::string &ipaddr)
719 add_zline(duration, source.c_str(), reason.c_str(), ipaddr.c_str());
720 apply_lines(APPLY_ZLINES);
723 void Server::AddKLine(long duration, const std::string &source, const std::string &reason, const std::string &hostmask)
725 add_kline(duration, source.c_str(), reason.c_str(), hostmask.c_str());
726 apply_lines(APPLY_KLINES);
729 void Server::AddELine(long duration, const std::string &source, const std::string &reason, const std::string &hostmask)
731 add_eline(duration, source.c_str(), reason.c_str(), hostmask.c_str());
734 bool Server::DelGLine(const std::string &hostmask)
736 return del_gline(hostmask.c_str());
739 bool Server::DelQLine(const std::string &nickname)
741 return del_qline(nickname.c_str());
744 bool Server::DelZLine(const std::string &ipaddr)
746 return del_zline(ipaddr.c_str());
749 bool Server::DelKLine(const std::string &hostmask)
751 return del_kline(hostmask.c_str());
754 bool Server::DelELine(const std::string &hostmask)
756 return del_eline(hostmask.c_str());
759 long Server::CalcDuration(const std::string &delta)
761 return duration(delta.c_str());
765 * XXX why on *earth* is this in modules.cpp...? I think
766 * perhaps we need a server.cpp for Server:: stuff where possible. -- w00t
768 bool Server::IsValidMask(const std::string &mask)
770 char* dest = (char*)mask.c_str();
771 if (strchr(dest,'!')==0)
773 if (strchr(dest,'@')==0)
775 for (char* i = dest; *i; i++)
778 for (char* i = dest; *i; i++)
782 for (char* i = dest; *i; i++)
788 for (char* i = dest; *i; i++)
797 Module* Server::FindModule(const std::string &name)
799 for (int i = 0; i <= MODCOUNT; i++)
801 if (Config->module_names[i] == name)
809 ConfigReader::ConfigReader()
811 // Config->ClearStack();
813 /* Is there any reason to load the entire config file again here?
814 * it's needed if they specify another config file, but using the
815 * default one we can just use the global config data - pre-parsed!
817 //~ this->cache = new std::stringstream(std::stringstream::in | std::stringstream::out);
818 this->errorlog = new std::ostringstream(std::stringstream::in | std::stringstream::out);
820 //~ this->readerror = Config->LoadConf(CONFIG_FILE, this->cache,this->errorlog);
821 //~ if (!this->readerror)
822 //~ this->error = CONF_FILE_NOT_FOUND;
824 this->data = &Config->config_data;
825 this->privatehash = false;
829 ConfigReader::~ConfigReader()
832 //~ delete this->cache;
834 DELETE(this->errorlog);
835 if(this->privatehash)
840 ConfigReader::ConfigReader(const std::string &filename)
842 Config->ClearStack();
844 this->data = new ConfigDataHash;
845 this->privatehash = true;
846 this->errorlog = new std::ostringstream(std::stringstream::in | std::stringstream::out);
847 this->readerror = Config->LoadConf(*this->data, filename, *this->errorlog);
848 if (!this->readerror)
849 this->error = CONF_FILE_NOT_FOUND;
852 std::string ConfigReader::ReadValue(const std::string &tag, const std::string &name, int index)
854 /* Don't need to strlcpy() tag and name anymore, ReadConf() takes const char* */
857 if (!Config->ConfValue(*this->data, tag, name, index, result))
859 this->error = CONF_VALUE_NOT_FOUND;
866 bool ConfigReader::ReadFlag(const std::string &tag, const std::string &name, int index)
868 return Config->ConfValueBool(*this->data, tag, name, index);
871 long ConfigReader::ReadInteger(const std::string &tag, const std::string &name, int index, bool needs_unsigned)
875 if(!Config->ConfValueInteger(*this->data, tag, name, index, result))
877 this->error = CONF_VALUE_NOT_FOUND;
881 if ((needs_unsigned) && (result < 0))
883 this->error = CONF_NOT_UNSIGNED;
890 long ConfigReader::GetError()
892 long olderr = this->error;
897 void ConfigReader::DumpErrors(bool bail, userrec* user)
899 /* XXX - Duplicated code */
903 printf("There were errors in your configuration:\n%s", this->errorlog->str().c_str());
908 std::string errors = this->errorlog->str();
909 std::string::size_type start;
910 unsigned int prefixlen;
913 /* ":Config->ServerName NOTICE user->nick :" */
914 prefixlen = strlen(Config->ServerName) + strlen(user->nick) + 11;
918 WriteServ(user->fd,"NOTICE %s :There were errors in the configuration file:",user->nick);
920 while(start < errors.length())
922 WriteServ(user->fd, "NOTICE %s :%s",user->nick, errors.substr(start, 510 - prefixlen).c_str());
923 start += 510 - prefixlen;
928 WriteOpers("There were errors in the configuration file:");
930 while(start < errors.length())
932 WriteOpers(errors.substr(start, 360).c_str());
942 int ConfigReader::Enumerate(const std::string &tag)
944 return Config->ConfValueEnum(*this->data, tag);
947 int ConfigReader::EnumerateValues(const std::string &tag, int index)
949 return Config->ConfVarEnum(*this->data, tag, index);
952 bool ConfigReader::Verify()
954 return this->readerror;
958 FileReader::FileReader(const std::string &filename)
961 readfile(c,filename.c_str());
966 FileReader::FileReader()
970 std::string FileReader::Contents()
973 for (file_cache::iterator a = this->fc.begin(); a != this->fc.end(); a++)
981 unsigned long FileReader::ContentSize()
983 return this->contentsize;
986 void FileReader::CalcSize()
989 for (file_cache::iterator a = this->fc.begin(); a != this->fc.end(); a++)
990 n += (a->length() + 2);
991 this->contentsize = n;
994 void FileReader::LoadFile(const std::string &filename)
997 readfile(c,filename.c_str());
1003 FileReader::~FileReader()
1007 bool FileReader::Exists()
1009 return (!(fc.size() == 0));
1012 std::string FileReader::GetLine(int x)
1014 if ((x<0) || ((unsigned)x>fc.size()))
1019 int FileReader::FileSize()
1025 std::vector<Module*> modules(255);
1026 std::vector<ircd_module*> factory(255);