]> git.stg.codes - stg.git/blobdiff - projects/stargazer/plugins/authorization/ao/ao.cpp
Cleanup ip2user on errors
[stg.git] / projects / stargazer / plugins / authorization / ao / ao.cpp
index 193b20bc2e5ffe3160b6182b4c170541a9ab6caa..7079d7d9b5548c41fb147a96c82acd081e39803a 100644 (file)
@@ -27,6 +27,7 @@ $Author: faust $
 #include <unistd.h>
 
 #include <csignal>
 #include <unistd.h>
 
 #include <csignal>
+#include <cassert>
 #include <algorithm> // for_each
 #include <functional> // mem_fun_ref
 
 #include <algorithm> // for_each
 #include <functional> // mem_fun_ref
 
@@ -34,32 +35,20 @@ $Author: faust $
 #include "stg/users.h"
 #include "stg/user_property.h"
 #include "stg/common.h"
 #include "stg/users.h"
 #include "stg/user_property.h"
 #include "stg/common.h"
+#include "stg/plugin_creator.h"
 #include "ao.h"
 
 #include "ao.h"
 
-class AO_CREATOR
-{
-private:
-    AUTH_AO * ao;
-
-public:
-    AO_CREATOR()
-        : ao(new AUTH_AO())
-        {
-        };
-    ~AO_CREATOR()
-        {
-        delete ao;
-        };
-
-    AUTH_AO * GetPlugin()
-        {
-        return ao;
-        };
-};
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-AO_CREATOR aoc;
+PLUGIN_CREATOR<AUTH_AO> aoc;
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+PLUGIN * GetPlugin()
+{
+return aoc.GetPlugin();
+}
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
@@ -75,13 +64,6 @@ public:
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-PLUGIN * GetPlugin()
-{
-return aoc.GetPlugin();
-}
-//-----------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
 const string AUTH_AO::GetVersion() const
 {
 return "Always Online authorizator v.1.0";
 const string AUTH_AO::GetVersion() const
 {
 return "Always Online authorizator v.1.0";
@@ -123,7 +105,8 @@ list<USER_PTR>::iterator users_iter;
 users_iter = usersList.begin();
 while (users_iter != usersList.end())
     {
 users_iter = usersList.begin();
 while (users_iter != usersList.end())
     {
-    Unauthorize(*users_iter);
+    if ((*users_iter)->IsAuthorizedBy(this))
+        users->Unauthorize((*users_iter)->GetLogin(), this);
     UnSetUserNotifiers(*users_iter);
     ++users_iter;
     }
     UnSetUserNotifiers(*users_iter);
     ++users_iter;
     }
@@ -219,11 +202,7 @@ void AUTH_AO::GetUsers()
 {
 USER_PTR u;
 int h = users->OpenSearch();
 {
 USER_PTR u;
 int h = users->OpenSearch();
-if (!h)
-    {
-    printfd(__FILE__, "users->OpenSearch() error\n");
-    return;
-    }
+assert(h && "USERS::OpenSearch is always correct");
 
 while (!users->SearchNext(h, &u))
     {
 
 while (!users->SearchNext(h, &u))
     {
@@ -234,21 +213,14 @@ while (!users->SearchNext(h, &u))
 users->CloseSearch(h);
 }
 //-----------------------------------------------------------------------------
 users->CloseSearch(h);
 }
 //-----------------------------------------------------------------------------
-void AUTH_AO::Unauthorize(USER_PTR u) const
-{
-u->Unauthorize(this);
-}
-//-----------------------------------------------------------------------------
-void AUTH_AO::UpdateUserAuthorization(USER_PTR u) const
+void AUTH_AO::UpdateUserAuthorization(CONST_USER_PTR u) const
 {
 if (u->GetProperty().alwaysOnline)
     {
     USER_IPS ips = u->GetProperty().ips;
     if (ips.OnlyOneIP())
         {
 {
 if (u->GetProperty().alwaysOnline)
     {
     USER_IPS ips = u->GetProperty().ips;
     if (ips.OnlyOneIP())
         {
-        if (u->Authorize(ips[0].ip, 0xFFffFFff, this) == 0)
-            {
-            }
+        users->Authorize(u->GetLogin(), ips[0].ip, 0xFFffFFff, this);
         }
     }
 }
         }
     }
 }
@@ -262,7 +234,7 @@ UpdateUserAuthorization(u);
 //-----------------------------------------------------------------------------
 void AUTH_AO::DelUser(USER_PTR u)
 {
 //-----------------------------------------------------------------------------
 void AUTH_AO::DelUser(USER_PTR u)
 {
-Unauthorize(u);
+users->Unauthorize(u->GetLogin(), this);
 UnSetUserNotifiers(u);
 usersList.remove(u);
 }
 UnSetUserNotifiers(u);
 usersList.remove(u);
 }
@@ -277,7 +249,8 @@ template <typename varParamType>
 void CHG_BEFORE_NOTIFIER<varParamType>::Notify(const varParamType &, const varParamType &)
 {
 //EVENT_LOOP_SINGLETON::GetInstance().Enqueue(auth, &AUTH_AO::Unauthorize, user);
 void CHG_BEFORE_NOTIFIER<varParamType>::Notify(const varParamType &, const varParamType &)
 {
 //EVENT_LOOP_SINGLETON::GetInstance().Enqueue(auth, &AUTH_AO::Unauthorize, user);
-auth.Unauthorize(user);
+if (user->IsAuthorizedBy(&auth))
+    auth.users->Unauthorize(user->GetLogin(), &auth);
 }
 //-----------------------------------------------------------------------------
 template <typename varParamType>
 }
 //-----------------------------------------------------------------------------
 template <typename varParamType>