X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules.cpp;h=1bed5bd183996d3cdeab9e667c7fe281dbac9017;hb=406ab09f22f46a6cee5559e96f0325768188ffa4;hp=d4f98cc865974426bb44996a9f9d11dceda5f7bf;hpb=740b09e2aee345c6fde199986d8eab6e0db224e3;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules.cpp b/src/modules.cpp index d4f98cc86..1bed5bd18 100644 --- a/src/modules.cpp +++ b/src/modules.cpp @@ -51,6 +51,7 @@ #include "mode.h" #include "xline.h" #include "commands.h" +#include "inspstring.h" #ifdef GCC3 #define nspace __gnu_cxx @@ -61,8 +62,10 @@ using namespace std; extern int MODCOUNT; -extern vector modules; -extern vector factory; +extern std::vector modules; +extern std::vector factory; + +extern time_t TIME; extern int LogLevel; extern char ServerName[MAXBUF]; @@ -107,29 +110,35 @@ extern FILE *log_file; namespace nspace { - template<> struct nspace::hash - { - size_t operator()(const struct in_addr &a) const - { - size_t q; - memcpy(&q,&a,sizeof(size_t)); - return q; - } - }; - - template<> struct nspace::hash - { - size_t operator()(const string &s) const - { - char a[MAXBUF]; - static struct hash strhash; - strcpy(a,s.c_str()); - strlower(a); - return strhash(a); - } - }; -} - +#ifdef GCC34 + template<> struct hash +#else + template<> struct nspace::hash +#endif + { + size_t operator()(const struct in_addr &a) const + { + size_t q; + memcpy(&q,&a,sizeof(size_t)); + return q; + } + }; +#ifdef GCC34 + template<> struct hash +#else + template<> struct nspace::hash +#endif + { + size_t operator()(const string &s) const + { + char a[MAXBUF]; + static struct hash strhash; + strlcpy(a,s.c_str(),MAXBUF); + strlower(a); + return strhash(a); + } + }; +} struct StrHashComp { @@ -137,8 +146,8 @@ struct StrHashComp bool operator()(const string& s1, const string& s2) const { char a[MAXBUF],b[MAXBUF]; - strcpy(a,s1.c_str()); - strcpy(b,s2.c_str()); + strlcpy(a,s1.c_str(),MAXBUF); + strlcpy(b,s2.c_str(),MAXBUF); return (strcasecmp(a,b) == 0); } @@ -288,7 +297,7 @@ void ModeMakeList(char modechar) // version is a simple class for holding a modules version number -Version::Version(int major, int minor, int revision, int build) : Major(major), Minor(minor), Revision(revision), Build(build) { }; +Version::Version(int major, int minor, int revision, int build, int flags) : Major(major), Minor(minor), Revision(revision), Build(build), Flags(flags) { }; // admin is a simple class for holding a server's administrative info @@ -300,23 +309,29 @@ void Module::OnUserConnect(userrec* user) { } void Module::OnUserQuit(userrec* user) { } void Module::OnUserJoin(userrec* user, chanrec* channel) { } void Module::OnUserPart(userrec* user, chanrec* channel) { } -void Module::OnPacketTransmit(char *p) { } -void Module::OnPacketReceive(char *p) { } +void Module::OnPacketTransmit(std::string &data, std::string serv) { } +void Module::OnPacketReceive(std::string &data, std::string serv) { } void Module::OnRehash() { } void Module::OnServerRaw(std::string &raw, bool inbound, userrec* user) { } int Module::OnUserPreJoin(userrec* user, chanrec* chan, const char* cname) { return 0; } int Module::OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list ¶ms) { return false; } -Version Module::GetVersion() { return Version(1,0,0,0); } +Version Module::GetVersion() { return Version(1,0,0,0,VF_VENDOR); } void Module::OnOper(userrec* user) { }; void Module::OnInfo(userrec* user) { }; void Module::OnWhois(userrec* source, userrec* dest) { }; -int Module::OnUserPreMessage(userrec* user,void* dest,int target_type, std::string text) { return 0; }; -int Module::OnUserPreNotice(userrec* user,void* dest,int target_type, std::string text) { return 0; }; +int Module::OnUserPreInvite(userrec* source,userrec* dest,chanrec* channel) { return 0; }; +int Module::OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text) { return 0; }; +int Module::OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text) { return 0; }; int Module::OnUserPreNick(userrec* user, std::string newnick) { return 0; }; +void Module::OnUserPostNick(userrec* user, std::string oldnick) { }; int Module::OnAccessCheck(userrec* source,userrec* dest,chanrec* channel,int access_type) { return ACR_DEFAULT; }; string_list Module::OnUserSync(userrec* user) { string_list empty; return empty; } string_list Module::OnChannelSync(chanrec* chan) { string_list empty; return empty; } - +void Module::On005Numeric(std::string &output) { }; +int Module::OnKill(userrec* source, userrec* dest, std::string reason) { return 0; }; +void Module::OnLoadModule(Module* mod,std::string name) { }; +void Module::OnBackgroundTimer(time_t curtime) { }; +void Module::OnSendList(userrec* user, chanrec* channel, char mode) { }; // server is a wrapper class that provides methods to all of the C-style // exports in the core @@ -338,8 +353,8 @@ void Server::SendOpers(std::string s) bool Server::MatchText(std::string sliteral, std::string spattern) { char literal[MAXBUF],pattern[MAXBUF]; - strncpy(literal,sliteral.c_str(),MAXBUF); - strncpy(pattern,spattern.c_str(),MAXBUF); + strlcpy(literal,sliteral.c_str(),MAXBUF); + strlcpy(pattern,spattern.c_str(),MAXBUF); return match(literal,pattern); } @@ -403,9 +418,9 @@ void Server::Log(int level, std::string s) log(level,"%s",s.c_str()); } -void Server::AddCommand(char* cmd, handlerfunc f, char flags, int minparams) +void Server::AddCommand(char* cmd, handlerfunc f, char flags, int minparams, char* source) { - createcommand(cmd,f,flags,minparams); + createcommand(cmd,f,flags,minparams,source); } void Server::SendMode(char **parameters, int pcnt, userrec *user) @@ -562,10 +577,106 @@ int Server::CountUsers(chanrec* c) } +bool Server::UserToPseudo(userrec* user,std::string message) +{ + unsigned int old_fd = user->fd; + user->fd = FD_MAGIC_NUMBER; + Write(old_fd,"ERROR :Closing link (%s@%s) [%s]",user->ident,user->host,message.c_str()); + close(old_fd); + shutdown (old_fd,2); +} + +bool Server::PseudoToUser(userrec* alive,userrec* zombie,std::string message) +{ + zombie->fd = alive->fd; + alive->fd = FD_MAGIC_NUMBER; + Write(zombie->fd,":%s!%s@%s NICK %s",alive->nick,alive->ident,alive->host,zombie->nick); + kill_link(alive,message.c_str()); + for (int i = 0; i != MAXCHANS; i++) + { + if (zombie->chans[i].channel != NULL) + { + if (zombie->chans[i].channel->name) + { + chanrec* Ptr = zombie->chans[i].channel; + WriteFrom(zombie->fd,zombie,"JOIN %s",Ptr->name); + if (Ptr->topicset) + { + WriteServ(zombie->fd,"332 %s %s :%s", zombie->nick, Ptr->name, Ptr->topic); + WriteServ(zombie->fd,"333 %s %s %s %d", zombie->nick, Ptr->name, Ptr->setby, Ptr->topicset); + } + userlist(zombie,Ptr); + WriteServ(zombie->fd,"366 %s %s :End of /NAMES list.", zombie->nick, Ptr->name); + WriteServ(zombie->fd,"324 %s %s +%s",zombie->nick, Ptr->name,chanmodes(Ptr)); + WriteServ(zombie->fd,"329 %s %s %d", zombie->nick, Ptr->name, Ptr->created); + + } + } + } + +} + +void Server::AddGLine(long duration, std::string source, std::string reason, std::string hostmask) +{ + add_gline(duration, source.c_str(), reason.c_str(), hostmask.c_str()); +} + +void Server::AddQLine(long duration, std::string source, std::string reason, std::string nickname) +{ + add_qline(duration, source.c_str(), reason.c_str(), nickname.c_str()); +} + +void Server::AddZLine(long duration, std::string source, std::string reason, std::string ipaddr) +{ + add_zline(duration, source.c_str(), reason.c_str(), ipaddr.c_str()); +} + +void Server::AddKLine(long duration, std::string source, std::string reason, std::string hostmask) +{ + add_kline(duration, source.c_str(), reason.c_str(), hostmask.c_str()); +} + +void Server::AddELine(long duration, std::string source, std::string reason, std::string hostmask) +{ + add_eline(duration, source.c_str(), reason.c_str(), hostmask.c_str()); +} + +bool Server::DelGLine(std::string hostmask) +{ + del_gline(hostmask.c_str()); +} + +bool Server::DelQLine(std::string nickname) +{ + del_qline(nickname.c_str()); +} + +bool Server::DelZLine(std::string ipaddr) +{ + del_zline(ipaddr.c_str()); +} + +bool Server::DelKLine(std::string hostmask) +{ + del_kline(hostmask.c_str()); +} + +bool Server::DelELine(std::string hostmask) +{ + del_eline(hostmask.c_str()); +} + +long Server::CalcDuration(std::string delta) +{ + return duration(delta.c_str()); +} + + ConfigReader::ConfigReader() { this->cache = new std::stringstream(std::stringstream::in | std::stringstream::out); - this->readerror = LoadConf(CONFIG_FILE,this->cache); + this->errorlog = new std::stringstream(std::stringstream::in | std::stringstream::out); + this->readerror = LoadConf(CONFIG_FILE,this->cache,this->errorlog); if (!this->readerror) this->error = CONF_FILE_NOT_FOUND; } @@ -575,13 +686,16 @@ ConfigReader::~ConfigReader() { if (this->cache) delete this->cache; + if (this->errorlog) + delete this->errorlog; } ConfigReader::ConfigReader(std::string filename) { this->cache = new std::stringstream(std::stringstream::in | std::stringstream::out); - this->readerror = LoadConf(filename.c_str(),this->cache); + this->errorlog = new std::stringstream(std::stringstream::in | std::stringstream::out); + this->readerror = LoadConf(filename.c_str(),this->cache,this->errorlog); if (!this->readerror) this->error = CONF_FILE_NOT_FOUND; }; @@ -591,8 +705,8 @@ std::string ConfigReader::ReadValue(std::string tag, std::string name, int index char val[MAXBUF]; char t[MAXBUF]; char n[MAXBUF]; - strncpy(t,tag.c_str(),MAXBUF); - strncpy(n,name.c_str(),MAXBUF); + strlcpy(t,tag.c_str(),MAXBUF); + strlcpy(n,name.c_str(),MAXBUF); int res = ReadConf(cache,t,n,index,val); if (!res) { @@ -607,8 +721,8 @@ bool ConfigReader::ReadFlag(std::string tag, std::string name, int index) char val[MAXBUF]; char t[MAXBUF]; char n[MAXBUF]; - strncpy(t,tag.c_str(),MAXBUF); - strncpy(n,name.c_str(),MAXBUF); + strlcpy(t,tag.c_str(),MAXBUF); + strlcpy(n,name.c_str(),MAXBUF); int res = ReadConf(cache,t,n,index,val); if (!res) { @@ -624,8 +738,8 @@ long ConfigReader::ReadInteger(std::string tag, std::string name, int index, boo char val[MAXBUF]; char t[MAXBUF]; char n[MAXBUF]; - strncpy(t,tag.c_str(),MAXBUF); - strncpy(n,name.c_str(),MAXBUF); + strlcpy(t,tag.c_str(),MAXBUF); + strlcpy(n,name.c_str(),MAXBUF); int res = ReadConf(cache,t,n,index,val); if (!res) { @@ -655,6 +769,38 @@ long ConfigReader::GetError() return olderr; } +void ConfigReader::DumpErrors(bool bail, userrec* user) +{ + if (bail) + { + printf("There were errors in your configuration:\n%s",errorlog->str().c_str()); + exit(0); + } + else + { + char dataline[1024]; + if (user) + { + WriteServ(user->fd,"NOTICE %s :There were errors in the configuration file:",user->nick); + while (!errorlog->eof()) + { + errorlog->getline(dataline,1024); + WriteServ(user->fd,"NOTICE %s :%s",user->nick,dataline); + } + } + else + { + WriteOpers("There were errors in the configuration file:",user->nick); + while (!errorlog->eof()) + { + errorlog->getline(dataline,1024); + WriteOpers(dataline); + } + } + return; + } +} + int ConfigReader::Enumerate(std::string tag) {