]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules.cpp
/LOADMODULE and /UNLOADMODULE all successfully working!
[user/henk/code/inspircd.git] / src / modules.cpp
index 23b45e8aa2379e97bfaab4d63b251d472ba5563a..f068dc5911a5678a7e08a62fee9559a161cf9cc2 100644 (file)
@@ -1,3 +1,19 @@
+/*       +------------------------------------+
+ *       | Inspire Internet Relay Chat Daemon |
+ *       +------------------------------------+
+ *
+ *  Inspire is copyright (C) 2002-2004 ChatSpike-Dev.
+ *                       E-mail:
+ *                <brain@chatspike.net>
+ *               <Craig@chatspike.net>
+ *     
+ * Written by Craig Edwards, Craig McLure, and others.
+ * This program is free but copyrighted software; see
+ *            the file COPYING for details.
+ *
+ * ---------------------------------------------------
+ */
+
 #include "inspircd.h"
 #include "inspircd_io.h"
 #include "inspircd_util.h"
@@ -35,6 +51,7 @@
 #include "mode.h"
 #include "xline.h"
 #include "commands.h"
+#include "inspstring.h"
 
 #ifdef GCC3
 #define nspace __gnu_cxx
 using namespace std;
 
 extern int MODCOUNT;
-extern vector<Module*> modules;
-extern vector<ircd_module*> factory;
+extern std::vector<Module*> modules;
+extern std::vector<ircd_module*> factory;
+
+extern time_t TIME;
 
 extern int LogLevel;
 extern char ServerName[MAXBUF];
@@ -75,7 +94,6 @@ extern time_t nb_start;
 extern std::vector<int> fd_reap;
 extern std::vector<std::string> module_names;
 
-extern char bannerBuffer[MAXBUF];
 extern int boundPortCount;
 extern int portCount;
 extern int UDPportCount;
@@ -92,29 +110,35 @@ extern FILE *log_file;
 
 namespace nspace
 {
-       template<> struct nspace::hash<in_addr>
-       {
-               size_t operator()(const struct in_addr &a) const
-               {
-                       size_t q;
-                       memcpy(&q,&a,sizeof(size_t));
-                       return q;
-               }
-       };
-
-       template<> struct nspace::hash<string>
-       {
-               size_t operator()(const string &s) const
-               {
-                       char a[MAXBUF];
-                       static struct hash<const char *> strhash;
-                       strcpy(a,s.c_str());
-                       strlower(a);
-                       return strhash(a);
-               }
-       };
-}      
-
+#ifdef GCC34
+        template<> struct hash<in_addr>
+#else
+        template<> struct nspace::hash<in_addr>
+#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<string>
+#else
+        template<> struct nspace::hash<string>
+#endif
+        {
+                size_t operator()(const string &s) const
+                {
+                        char a[MAXBUF];
+                        static struct hash<const char *> strhash;
+                        strlcpy(a,s.c_str(),MAXBUF);
+                        strlower(a);
+                        return strhash(a);
+                }
+        };
+}
 
 struct StrHashComp
 {
@@ -122,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);
        }
 
@@ -187,7 +211,6 @@ bool ModeDefined(char modechar, int type)
        log(DEBUG,"Size of extmodes vector is %d",EMode.size());
        for (ExtModeListIter i = EMode.begin(); i < EMode.end(); i++)
        {
-               log(DEBUG,"i->modechar==%c, modechar=%c, i->type=%d, type=%d",i->modechar,modechar,i->type,type);
                if ((i->modechar == modechar) && (i->type == type))
                {
                        return true;
@@ -201,7 +224,6 @@ bool ModeIsListMode(char modechar, int type)
        log(DEBUG,"Size of extmodes vector is %d",EMode.size());
        for (ExtModeListIter i = EMode.begin(); i < EMode.end(); i++)
        {
-               log(DEBUG,"i->modechar==%c, modechar=%c, i->type=%d, type=%d",i->modechar,modechar,i->type,type);
                if ((i->modechar == modechar) && (i->type == type) && (i->list == true))
                {
                        return true;
@@ -215,7 +237,6 @@ bool ModeDefinedOper(char modechar, int type)
        log(DEBUG,"Size of extmodes vector is %d",EMode.size());
        for (ExtModeListIter i = EMode.begin(); i < EMode.end(); i++)
        {
-               log(DEBUG,"i->modechar==%c, modechar=%c, i->type=%d, type=%d",i->modechar,modechar,i->type,type);
                if ((i->modechar == modechar) && (i->type == type) && (i->needsoper == true))
                {
                        return true;
@@ -276,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
 
@@ -294,16 +315,21 @@ 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 &params) { 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) { };
 
 
 // server is a wrapper class that provides methods to all of the C-style
@@ -326,8 +352,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);
 }
 
@@ -391,9 +417,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)
@@ -553,7 +579,8 @@ int Server::CountUsers(chanrec* c)
 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;
 }
@@ -563,13 +590,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;
 };
@@ -579,8 +609,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)
        {
@@ -595,8 +625,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)
        {
@@ -612,8 +642,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)
        {
@@ -643,6 +673,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)
 {