summaryrefslogtreecommitdiff
path: root/src/modules/m_sasl.cpp
diff options
context:
space:
mode:
authordanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>2009-09-13 20:30:25 +0000
committerdanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>2009-09-13 20:30:25 +0000
commit6d57bbe05c31c79eaad02fe81cfb9c1ed6b79c58 (patch)
treee0c89ed36b00f4c2925d7f39c32a835657b0fa6e /src/modules/m_sasl.cpp
parent7eea21b8d43b0d5993e88b62d9d4894c2af49303 (diff)
Change Extensible to use strongly typed entries
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11696 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src/modules/m_sasl.cpp')
-rw-r--r--src/modules/m_sasl.cpp89
1 files changed, 30 insertions, 59 deletions
diff --git a/src/modules/m_sasl.cpp b/src/modules/m_sasl.cpp
index 1436afa3d..069fbdec8 100644
--- a/src/modules/m_sasl.cpp
+++ b/src/modules/m_sasl.cpp
@@ -37,8 +37,6 @@ class SaslAuthenticator : public classbase
SaslAuthenticator(User *user_, std::string method, InspIRCd *instance, Module *ctor)
: ServerInstance(instance), user(user_), state(SASL_INIT), state_announced(false)
{
- this->user->Extend("sasl_authenticator", this);
-
parameterlist params;
params.push_back("*");
params.push_back("SASL");
@@ -147,18 +145,15 @@ class SaslAuthenticator : public classbase
this->state_announced = true;
}
-
- ~SaslAuthenticator()
- {
- this->user->Shrink("sasl_authenticator");
- this->AnnounceState();
- }
};
class CommandAuthenticate : public Command
{
public:
- CommandAuthenticate (InspIRCd* Instance, Module* Creator) : Command(Instance, Creator, "AUTHENTICATE", 0, 1, true)
+ SimpleExtItem<SaslAuthenticator>& authExt;
+ GenericCap& cap;
+ CommandAuthenticate (InspIRCd* Instance, Module* Creator, SimpleExtItem<SaslAuthenticator>& ext, GenericCap& Cap)
+ : Command(Instance, Creator, "AUTHENTICATE", 0, 1, true), authExt(ext), cap(Cap)
{
}
@@ -167,14 +162,17 @@ class CommandAuthenticate : public Command
/* Only allow AUTHENTICATE on unregistered clients */
if (user->registered != REG_ALL)
{
- if (!user->GetExt("sasl"))
+ if (!cap.ext.get(user))
return CMD_FAILURE;
- SaslAuthenticator *sasl;
- if (!(user->GetExt("sasl_authenticator", sasl)))
- sasl = new SaslAuthenticator(user, parameters[0], ServerInstance, creator);
+ SaslAuthenticator *sasl = authExt.get(user);
+ if (!sasl)
+ authExt.set(user, new SaslAuthenticator(user, parameters[0], ServerInstance, creator));
else if (sasl->SendClientMessage(parameters) == false) // IAL abort extension --nenolod
- delete sasl;
+ {
+ sasl->AnnounceState();
+ authExt.unset(user);
+ }
}
return CMD_FAILURE;
}
@@ -183,7 +181,9 @@ class CommandAuthenticate : public Command
class CommandSASL : public Command
{
public:
- CommandSASL(InspIRCd* Instance, Module* Creator) : Command(Instance, Creator, "SASL", 0, 2)
+ SimpleExtItem<SaslAuthenticator>& authExt;
+ CommandSASL(InspIRCd* Instance, Module* Creator, SimpleExtItem<SaslAuthenticator>& ext)
+ : Command(Instance, Creator, "SASL", 0, 2), authExt(ext)
{
this->disabled = true; // should not be called by users
}
@@ -197,15 +197,15 @@ class CommandSASL : public Command
return CMD_FAILURE;
}
- SaslAuthenticator *sasl;
- if (!target->GetExt("sasl_authenticator", sasl))
+ SaslAuthenticator *sasl = authExt.get(target);
+ if (!sasl)
return CMD_FAILURE;
SaslState state = sasl->ProcessInboundMessage(parameters);
if (state == SASL_DONE)
{
- delete sasl;
- target->Shrink("sasl");
+ sasl->AnnounceState();
+ authExt.unset(target);
}
return CMD_SUCCESS;
}
@@ -218,12 +218,13 @@ class CommandSASL : public Command
class ModuleSASL : public Module
{
+ SimpleExtItem<SaslAuthenticator> authExt;
+ GenericCap cap;
CommandAuthenticate auth;
CommandSASL sasl;
public:
-
ModuleSASL(InspIRCd* Me)
- : Module(Me), auth(Me, this), sasl(Me, this)
+ : Module(Me), authExt("sasl_auth", this), cap(this, "sasl"), auth(Me, this, authExt, cap), sasl(Me, this, authExt)
{
Implementation eventlist[] = { I_OnEvent, I_OnUserRegister, I_OnPostConnect, I_OnUserDisconnect, I_OnCleanup };
ServerInstance->Modules->Attach(eventlist, this, 5);
@@ -235,60 +236,30 @@ class ModuleSASL : public Module
ServerInstance->Logs->Log("m_sasl", DEFAULT, "WARNING: m_services_account.so and m_cap.so are not loaded! m_sasl.so will NOT function correctly until these two modules are loaded!");
}
- virtual ModResult OnUserRegister(User *user)
+ ModResult OnUserRegister(User *user)
{
- SaslAuthenticator *sasl_;
- if (user->GetExt("sasl_authenticator", sasl_))
+ SaslAuthenticator *sasl_ = authExt.get(user);
+ if (sasl_)
{
sasl_->Abort();
- delete sasl_;
- user->Shrink("sasl_authenticator");
+ authExt.unset(user);
}
return MOD_RES_PASSTHRU;
}
- virtual void OnCleanup(int target_type, void *item)
- {
- if (target_type == TYPE_USER)
- OnUserDisconnect((User*)item);
- }
-
- virtual void OnUserDisconnect(User *user)
- {
- SaslAuthenticator *sasl_;
- if (user->GetExt("sasl_authenticator", sasl_))
- {
- delete sasl_;
- user->Shrink("sasl_authenticator");
- }
- }
-
- virtual void OnPostConnect(User* user)
- {
- if (!IS_LOCAL(user))
- return;
-
- std::string* str = NULL;
-
- if (user->GetExt("accountname", str))
- ServerInstance->PI->SendMetaData(user, "accountname", *str);
-
- return;
- }
-
- virtual ~ModuleSASL()
+ ~ModuleSASL()
{
}
- virtual Version GetVersion()
+ Version GetVersion()
{
return Version("$Id$",VF_VENDOR,API_VERSION);
}
- virtual void OnEvent(Event *ev)
+ void OnEvent(Event *ev)
{
- GenericCapHandler(ev, "sasl", "sasl");
+ cap.HandleEvent(ev);
}
};