]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
m_sasl Add ServerTracker class for tracking sasl_target
authorAttila Molnar <attilamolnar@hush.com>
Mon, 25 Apr 2016 11:23:29 +0000 (13:23 +0200)
committerAttila Molnar <attilamolnar@hush.com>
Mon, 25 Apr 2016 11:23:29 +0000 (13:23 +0200)
src/modules/m_sasl.cpp

index 639fe677863ece5a76dd5c39448393298cce6813..a6edb8b7079f3ec8ee53092a0d8299db0704ac93 100644 (file)
 #include "modules/account.h"
 #include "modules/sasl.h"
 #include "modules/ssl.h"
 #include "modules/account.h"
 #include "modules/sasl.h"
 #include "modules/ssl.h"
+#include "modules/spanningtree.h"
+
+static std::string sasl_target;
+
+class ServerTracker : public SpanningTreeEventListener
+{
+       bool online;
+
+       void Update(const Server* server, bool linked)
+       {
+               if (sasl_target == "*")
+                       return;
+
+               if (InspIRCd::Match(server->GetName(), sasl_target))
+               {
+                       ServerInstance->Logs->Log(MODNAME, LOG_VERBOSE, "SASL target server \"%s\" %s", sasl_target.c_str(), (linked ? "came online" : "went offline"));
+                       online = linked;
+               }
+       }
+
+       void OnServerLink(const Server* server) CXX11_OVERRIDE
+       {
+               Update(server, true);
+       }
+
+       void OnServerSplit(const Server* server) CXX11_OVERRIDE
+       {
+               Update(server, false);
+       }
+
+ public:
+       ServerTracker(Module* mod)
+               : SpanningTreeEventListener(mod)
+       {
+               Reset();
+       }
+
+       void Reset()
+       {
+               if (sasl_target == "*")
+               {
+                       online = true;
+                       return;
+               }
+
+               online = false;
+
+               ProtocolInterface::ServerList servers;
+               ServerInstance->PI->GetServerList(servers);
+               for (ProtocolInterface::ServerList::const_iterator i = servers.begin(); i != servers.end(); ++i)
+               {
+                       const ProtocolInterface::ServerInfo& server = *i;
+                       if (InspIRCd::Match(server.servername, sasl_target))
+                       {
+                               online = true;
+                               break;
+                       }
+               }
+       }
+
+       bool IsOnline() const { return online; }
+};
 
 class SASLCap : public Cap::Capability
 {
 
 class SASLCap : public Cap::Capability
 {
@@ -62,7 +124,6 @@ class SASLCap : public Cap::Capability
 enum SaslState { SASL_INIT, SASL_COMM, SASL_DONE };
 enum SaslResult { SASL_OK, SASL_FAIL, SASL_ABORT };
 
 enum SaslState { SASL_INIT, SASL_COMM, SASL_DONE };
 enum SaslResult { SASL_OK, SASL_FAIL, SASL_ABORT };
 
-static std::string sasl_target = "*";
 static Events::ModuleEventProvider* saslevprov;
 
 static void SendSASL(const parameterlist& params)
 static Events::ModuleEventProvider* saslevprov;
 
 static void SendSASL(const parameterlist& params)
@@ -280,6 +341,7 @@ class CommandSASL : public Command
 class ModuleSASL : public Module
 {
        SimpleExtItem<SaslAuthenticator> authExt;
 class ModuleSASL : public Module
 {
        SimpleExtItem<SaslAuthenticator> authExt;
+       ServerTracker servertracker;
        SASLCap cap;
        CommandAuthenticate auth;
        CommandSASL sasl;
        SASLCap cap;
        CommandAuthenticate auth;
        CommandSASL sasl;
@@ -288,6 +350,7 @@ class ModuleSASL : public Module
  public:
        ModuleSASL()
                : authExt("sasl_auth", ExtensionItem::EXT_USER, this)
  public:
        ModuleSASL()
                : authExt("sasl_auth", ExtensionItem::EXT_USER, this)
+               , servertracker(this)
                , cap(this)
                , auth(this, authExt, cap)
                , sasl(this, authExt)
                , cap(this)
                , auth(this, authExt, cap)
                , sasl(this, authExt)
@@ -305,6 +368,7 @@ class ModuleSASL : public Module
        void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
        {
                sasl_target = ServerInstance->Config->ConfValue("sasl")->getString("target", "*");
        void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
        {
                sasl_target = ServerInstance->Config->ConfValue("sasl")->getString("target", "*");
+               servertracker.Reset();
        }
 
        ModResult OnUserRegister(LocalUser *user) CXX11_OVERRIDE
        }
 
        ModResult OnUserRegister(LocalUser *user) CXX11_OVERRIDE