]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules.cpp
kick_channel -> chanrec::KickUser(), server_kick_channel -> chanrec::ServerKickUser()
[user/henk/code/inspircd.git] / src / modules.cpp
index 2a7b2696fa4e98c13df5feffe759ff6bb21330d2..bda6f765b232e2286f3df326391ac7c9453a108a 100644 (file)
  * ---------------------------------------------------
  */
 
-using namespace std;
-
 #include "inspircd_config.h"
 #include "inspircd.h"
-#include "inspircd_io.h"
+#include "configreader.h"
 #include <unistd.h>
 #include <sys/errno.h>
 #include <time.h>
 #include <string>
-#ifdef GCC3
-#include <ext/hash_map>
-#else
-#include <hash_map>
-#endif
 #include <map>
 #include <sstream>
 #include <vector>
@@ -50,125 +43,63 @@ using namespace std;
 #include "typedefs.h"
 #include "modules.h"
 #include "command_parse.h"
+#include "dns.h"
 
 extern ServerConfig *Config;
 extern InspIRCd* ServerInstance;
 extern int MODCOUNT;
-extern std::vector<Module*> modules;
-extern std::vector<ircd_module*> factory;
+extern ModuleList modules;
+extern FactoryList factory;
 extern std::vector<InspSocket*> module_sockets;
 extern std::vector<userrec*> local_users;
 extern time_t TIME;
-class Server;
 extern userrec* fd_ref_table[MAX_DESCRIPTORS];
-
 extern user_hash clientlist;
 extern chan_hash chanlist;
 extern command_table cmdlist;
-ExtModeList EMode;
 
-// returns true if an extended mode character is in use
-bool ModeDefined(char modechar, int type)
-{
-       for (ExtModeListIter i = EMode.begin(); i < EMode.end(); i++)
-       {
-               if ((i->modechar == modechar) && (i->type == type))
-               {
-                       return true;
-               }
-       }
-       return false;
-}
+class Server;
 
-bool ModeIsListMode(char modechar, int type)
-{
-       for (ExtModeListIter i = EMode.begin(); i < EMode.end(); i++)
-       {
-               if ((i->modechar == modechar) && (i->type == type) && (i->list == true))
-               {
-                       return true;
-               }
-       }
-       return false;
-}
+featurelist Features;
 
-bool ModeDefinedOper(char modechar, int type)
-{
-       for (ExtModeListIter i = EMode.begin(); i < EMode.end(); i++)
-       {
-               if ((i->modechar == modechar) && (i->type == type) && (i->needsoper == true))
-               {
-                       return true;
-               }
-       }
-       return false;
-}
+// version is a simple class for holding a modules version number
 
-// returns number of parameters for a custom mode when it is switched on
-int ModeDefinedOn(char modechar, int type)
+Version::Version(int major, int minor, int revision, int build, int flags)
+: Major(major), Minor(minor), Revision(revision), Build(build), Flags(flags)
 {
-       for (ExtModeListIter i = EMode.begin(); i < EMode.end(); i++)
-       {
-               if ((i->modechar == modechar) && (i->type == type))
-               {
-                       return i->params_when_on;
-               }
-       }
-       return 0;
 }
 
-// returns number of parameters for a custom mode when it is switched on
-int ModeDefinedOff(char modechar, int type)
-{
-       for (ExtModeListIter i = EMode.begin(); i < EMode.end(); i++)
-       {
-               if ((i->modechar == modechar) && (i->type == type))
-               {
-                       return i->params_when_off;
-               }
-       }
-       return 0;
-}
+// admin is a simple class for holding a server's administrative info
 
-// returns true if an extended mode character is in use
-bool DoAddExtendedMode(char modechar, int type, bool requires_oper, int params_on, int params_off)
+Admin::Admin(std::string name, std::string email, std::string nick)
+: Name(name), Email(email), Nick(nick)
 {
-       if (ModeDefined(modechar,type)) {
-               return false;
-       }
-       EMode.push_back(ExtMode(modechar,type,requires_oper,params_on,params_off));
-       return true;
 }
 
-// turns a mode into a listmode
-void ModeMakeList(char modechar)
+Request::Request(char* anydata, Module* src, Module* dst)
+: data(anydata), source(src), dest(dst)
 {
-       for (ExtModeListIter i = EMode.begin(); i < EMode.end(); i++)
-       {
-               if ((i->modechar == modechar) && (i->type == MT_CHANNEL))
-               {
-                       i->list = true;
-                       return;
-               }
-       }
-       return;
+       /* Ensure that because this module doesnt support ID strings, it doesnt break modules that do
+        * by passing them uninitialized pointers (could happen)
+        */
+       id = '\0';
 }
 
-// version is a simple class for holding a modules version number
-
-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
-
-Admin::Admin(std::string name, std::string email, std::string nick) : Name(name), Email(email), Nick(nick) { };
-
-Request::Request(char* anydata, Module* src, Module* dst) : data(anydata), source(src), dest(dst) { };
+Request::Request(Module* src, Module* dst, const char* idstr)
+: id(idstr), source(src), dest(dst)
+{
+};
 
 char* Request::GetData()
 {
        return this->data;
 }
 
+const char* Request::GetId()
+{
+       return this->id;
+}
+
 Module* Request::GetSource()
 {
        return this->source;
@@ -195,7 +126,7 @@ Event::Event(char* anydata, Module* src, const std::string &eventid) : data(anyd
 
 char* Event::GetData()
 {
-       return this->data;
+       return (char*)this->data;
 }
 
 Module* Event::GetSource()
@@ -227,7 +158,6 @@ void                Module::OnUserPart(userrec* user, chanrec* channel, const std::string &par
 void           Module::OnRehash(const std::string &parameter) { }
 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; }
 void           Module::OnMode(userrec* user, void* dest, int target_type, const std::string &text) { };
 Version                Module::GetVersion() { return Version(1,0,0,0,VF_VENDOR); }
 void           Module::OnOper(userrec* user, const std::string &opertype) { };
@@ -245,8 +175,7 @@ int         Module::OnKill(userrec* source, userrec* dest, const std::string &reason) {
 void           Module::OnLoadModule(Module* mod,const std::string &name) { };
 void           Module::OnUnloadModule(Module* mod,const std::string &name) { };
 void           Module::OnBackgroundTimer(time_t curtime) { };
-void           Module::OnSendList(userrec* user, chanrec* channel, char mode) { };
-int            Module::OnPreCommand(const std::string &command, char **parameters, int pcnt, userrec *user, bool validated) { return 0; };
+int            Module::OnPreCommand(const std::string &command, const char** parameters, int pcnt, userrec *user, bool validated) { return 0; };
 bool           Module::OnCheckReady(userrec* user) { return true; };
 void           Module::OnUserRegister(userrec* user) { };
 int            Module::OnUserPreKick(userrec* source, userrec* user, chanrec* chan, const std::string &reason) { return 0; };
@@ -256,7 +185,7 @@ int         Module::OnCheckInvite(userrec* user, chanrec* chan) { return 0; };
 int            Module::OnCheckKey(userrec* user, chanrec* chan, const std::string &keygiven) { return 0; };
 int            Module::OnCheckLimit(userrec* user, chanrec* chan) { return 0; };
 int            Module::OnCheckBan(userrec* user, chanrec* chan) { return 0; };
-int            Module::OnStats(char symbol, userrec* user) { return 0; };
+int            Module::OnStats(char symbol, userrec* user, string_list &results) { return 0; };
 int            Module::OnChangeLocalUserHost(userrec* user, const std::string &newhost) { return 0; };
 int            Module::OnChangeLocalUserGECOS(userrec* user, const std::string &newhost) { return 0; };
 int            Module::OnLocalTopicChange(userrec* user, chanrec* chan, const std::string &topic) { return 0; };
@@ -356,6 +285,50 @@ long Server::PriorityBefore(const std::string &modulename)
        return PRIORITY_DONTCARE;
 }
 
+bool Server::PublishFeature(const std::string &FeatureName, Module* Mod)
+{
+       if (Features.find(FeatureName) == Features.end())
+       {
+               Features[FeatureName] = Mod;
+               return true;
+       }
+       return false;
+}
+
+bool Server::UnpublishFeature(const std::string &FeatureName)
+{
+       featurelist::iterator iter = Features.find(FeatureName);
+       
+       if (iter == Features.end())
+               return false;
+
+       Features.erase(iter);
+       return true;
+}
+
+Module* Server::FindFeature(const std::string &FeatureName)
+{
+       featurelist::iterator iter = Features.find(FeatureName);
+
+       if (iter == Features.end())
+               return NULL;
+
+       return iter->second;
+}
+
+const std::string& Server::GetModuleName(Module* m)
+{
+       static std::string nothing = ""; /* Prevent compiler warning */
+       for (int i = 0; i <= MODCOUNT; i++)
+       {
+               if (modules[i] == m)
+               {
+                       return Config->module_names[i];
+               }
+       }
+       return nothing; /* As above */
+}
+
 void Server::RehashServer()
 {
        WriteOpers("*** Rehashing config file");
@@ -455,11 +428,11 @@ void Server::KickUser(userrec* source, userrec* target, chanrec* chan, const std
 {
        if (source)
        {
-               kick_channel(source,target,chan,(char*)reason.c_str());
+               chan->KickUser(source, target, reason.c_str());
        }
        else
        {
-               server_kick_channel(target,chan,(char*)reason.c_str(),true);
+               chan->ServerKickUser(target, reason.c_str(), true);
        }
 }
 
@@ -473,7 +446,7 @@ bool Server::IsUlined(const std::string &server)
        return is_uline(server.c_str());
 }
 
-bool Server::CallCommandHandler(const std::string &commandname, char** parameters, int pcnt, userrec* user)
+bool Server::CallCommandHandler(const std::string &commandname, const char** parameters, int pcnt, userrec* user)
 {
        return ServerInstance->Parser->CallHandler(commandname,parameters,pcnt,user);
 }
@@ -497,9 +470,9 @@ void Server::AddCommand(command_t *f)
        }
 }
 
-void Server::SendMode(char **parameters, int pcnt, userrec *user)
+void Server::SendMode(const char** parameters, int pcnt, userrec *user)
 {
-       ServerInstance->ModeGrok->ServerMode(parameters,pcnt,user);
+       ServerInstance->ModeGrok->Process(parameters,pcnt,user,true);
 }
 
 void Server::Send(int Socket, const std::string &s)
@@ -642,45 +615,24 @@ Admin Server::GetAdmin()
 }
 
 
+bool Server::AddMode(ModeHandler* mh, const unsigned char mode)
+{
+       return ServerInstance->ModeGrok->AddMode(mh,mode);
+}
 
-bool Server::AddExtendedMode(char modechar, int type, bool requires_oper, int params_when_on, int params_when_off)
+bool Server::AddModeWatcher(ModeWatcher* mw)
 {
-       if (((modechar >= 'A') && (modechar <= 'Z')) || ((modechar >= 'a') && (modechar <= 'z')))
-       {
-               if (type == MT_SERVER)
-               {
-                       ModuleException e("Modes of type MT_SERVER are reserved for future expansion");
-                       throw(e);
-                       return false;
-               }
-               if (((params_when_on>0) || (params_when_off>0)) && (type == MT_CLIENT))
-               {
-                       ModuleException e("Parameters on MT_CLIENT modes are not supported");
-                       throw(e);
-                       return false;
-               }
-               if ((params_when_on>1) || (params_when_off>1))
-               {
-                       ModuleException e("More than one parameter for an MT_CHANNEL mode is not yet supported");
-                       throw(e);
-                       return false;
-               }
-               return DoAddExtendedMode(modechar,type,requires_oper,params_when_on,params_when_off);
-       }
-       else
-       {
-               ModuleException e("Muppet modechar detected.");
-               throw(e);
-       }
-       return false;
+       return ServerInstance->ModeGrok->AddModeWatcher(mw);
 }
 
-bool Server::AddExtendedListMode(char modechar)
+bool Server::DelModeWatcher(ModeWatcher* mw)
 {
-       bool res = DoAddExtendedMode(modechar,MT_CHANNEL,false,1,1);
-       if (res)
-               ModeMakeList(modechar);
-       return res;
+       return ServerInstance->ModeGrok->DelModeWatcher(mw);
+}
+
+bool Server::AddResolver(Resolver* r)
+{
+       return ServerInstance->Res->AddResolverClass(r);
 }
 
 int Server::CountUsers(chanrec* c)
@@ -688,7 +640,6 @@ int Server::CountUsers(chanrec* c)
        return usercount(c);
 }
 
-
 bool Server::UserToPseudo(userrec* user, const std::string &message)
 {
        unsigned int old_fd = user->fd;
@@ -754,21 +705,25 @@ bool Server::PseudoToUser(userrec* alive, userrec* zombie, const std::string &me
 void Server::AddGLine(long duration, const std::string &source, const std::string &reason, const std::string &hostmask)
 {
        add_gline(duration, source.c_str(), reason.c_str(), hostmask.c_str());
+       apply_lines(APPLY_GLINES);
 }
 
 void Server::AddQLine(long duration, const std::string &source, const std::string &reason, const std::string &nickname)
 {
        add_qline(duration, source.c_str(), reason.c_str(), nickname.c_str());
+       apply_lines(APPLY_QLINES);
 }
 
 void Server::AddZLine(long duration, const std::string &source, const std::string &reason, const std::string &ipaddr)
 {
        add_zline(duration, source.c_str(), reason.c_str(), ipaddr.c_str());
+       apply_lines(APPLY_ZLINES);
 }
 
 void Server::AddKLine(long duration, const std::string &source, const std::string &reason, const std::string &hostmask)
 {
        add_kline(duration, source.c_str(), reason.c_str(), hostmask.c_str());
+       apply_lines(APPLY_KLINES);
 }
 
 void Server::AddELine(long duration, const std::string &source, const std::string &reason, const std::string &hostmask)
@@ -876,9 +831,9 @@ ConfigReader::~ConfigReader()
        //~ if (this->cache)
                //~ delete this->cache;
        if (this->errorlog)
-               delete this->errorlog;
+               DELETE(this->errorlog);
        if(this->privatehash)
-               delete this->data;
+               DELETE(this->data);
 }
 
 
@@ -1005,17 +960,43 @@ FileReader::FileReader(const std::string &filename)
        file_cache c;
        readfile(c,filename.c_str());
        this->fc = c;
+       this->CalcSize();
 }
 
 FileReader::FileReader()
 {
 }
 
+std::string FileReader::Contents()
+{
+       std::string x = "";
+       for (file_cache::iterator a = this->fc.begin(); a != this->fc.end(); a++)
+       {
+               x.append(*a);
+               x.append("\r\n");
+       }
+       return x;
+}
+
+unsigned long FileReader::ContentSize()
+{
+       return this->contentsize;
+}
+
+void FileReader::CalcSize()
+{
+       unsigned long n = 0;
+       for (file_cache::iterator a = this->fc.begin(); a != this->fc.end(); a++)
+               n += (a->length() + 2);
+       this->contentsize = n;
+}
+
 void FileReader::LoadFile(const std::string &filename)
 {
        file_cache c;
        readfile(c,filename.c_str());
        this->fc = c;
+       this->CalcSize();
 }