#include <unistd.h> // access
#include <cassert>
-
+#include <cstdlib>
+
+#include "stg/users.h"
+#include "stg/common.h"
+#include "stg/scriptexecuter.h"
+#include "stg/tariff.h"
+#include "stg/tariffs.h"
+#include "stg/admin.h"
#include "user_impl.h"
-#include "users.h"
-#include "common.h"
-#include "settings.h"
-#include "script_executer.h"
-#include "tariff.h"
-#include "tariffs.h"
-#include "admin.h"
-
-USER_IMPL::USER_IMPL(const SETTINGS * s,
- const BASE_STORE * st,
+#include "settings_impl.h"
+
+USER_IMPL::USER_IMPL(const SETTINGS_IMPL * s,
+ const STORE * st,
const TARIFFS * t,
- const ADMIN & a,
+ const ADMIN * a,
const USERS * u)
: users(u),
- property(s),
+ property(s->GetScriptsDir()),
WriteServLog(GetStgLogger()),
login(),
id(0),
ips = StrToIPS("*");
deleted = false;
lastWriteStat = stgTime + random() % settings->GetStatWritePeriod();
-lastWriteDeatiledStat = stgTime;
+lastWriteDetailedStat = stgTime;
property.tariffName.AddBeforeNotifier(&tariffNotifier);
property.passive.AddBeforeNotifier(&passiveNotifier);
//-----------------------------------------------------------------------------
USER_IMPL::USER_IMPL(const USER_IMPL & u)
: users(u.users),
- property(u.settings),
+ property(u.settings->GetScriptsDir()),
WriteServLog(GetStgLogger()),
login(u.login),
id(u.id),
deleted = u.deleted;
lastWriteStat = u.lastWriteStat;
-lastWriteDeatiledStat = u.lastWriteDeatiledStat;
+lastWriteDetailedStat = u.lastWriteDetailedStat;
settings = u.settings;
return 0;
}
//-----------------------------------------------------------------------------
-int USER_IMPL::Authorize(uint32_t ip, const string &, uint32_t dirs, const BASE_AUTH * auth)
+int USER_IMPL::Authorize(uint32_t ip, uint32_t dirs, const AUTH * auth)
{
STG_LOCKER lock(&mutex, __FILE__, __LINE__);
/*
return 0;
}
//-----------------------------------------------------------------------------
-void USER_IMPL::Unauthorize(const BASE_AUTH * auth)
+void USER_IMPL::Unauthorize(const AUTH * auth)
{
STG_LOCKER lock(&mutex, __FILE__, __LINE__);
/*
}
}
//-----------------------------------------------------------------------------
-bool USER_IMPL::IsAuthorizedBy(const BASE_AUTH * auth) const
+bool USER_IMPL::IsAuthorizedBy(const AUTH * auth) const
{
STG_LOCKER lock(&mutex, __FILE__, __LINE__);
// Is this user authorized by specified authorizer?
if (!fakeConnect)
{
- string scriptOnConnect = settings->GetScriptDir() + "/OnConnect";
+ string scriptOnConnect = settings->GetScriptsDir() + "/OnConnect";
if (access(scriptOnConnect.c_str(), X_OK) == 0)
{
if (!fakeDisconnect)
{
- string scriptOnDisonnect = settings->GetScriptDir() + "/OnDisconnect";
+ string scriptOnDisonnect = settings->GetScriptsDir() + "/OnDisconnect";
if (access(scriptOnDisonnect.c_str(), X_OK) == 0)
{
{
if (connected)
{
- lastActivityTime = *const_cast<time_t *>(&stgTime);
+ property.Stat().lastActivityTime = stgTime;
}
if (!connected && IsInetable())
{
currIP.DelAfterNotifier(n);
}
//-----------------------------------------------------------------------------
+void USER_IMPL::AddConnectedBeforeNotifier(PROPERTY_NOTIFIER_BASE<bool> * n)
+{
+STG_LOCKER lock(&mutex, __FILE__, __LINE__);
+connected.AddBeforeNotifier(n);
+}
+//-----------------------------------------------------------------------------
+void USER_IMPL::DelConnectedBeforeNotifier(PROPERTY_NOTIFIER_BASE<bool> * n)
+{
+STG_LOCKER lock(&mutex, __FILE__, __LINE__);
+connected.DelBeforeNotifier(n);
+}
+//-----------------------------------------------------------------------------
+void USER_IMPL::AddConnectedAfterNotifier(PROPERTY_NOTIFIER_BASE<bool> * n)
+{
+STG_LOCKER lock(&mutex, __FILE__, __LINE__);
+connected.AddAfterNotifier(n);
+}
+//-----------------------------------------------------------------------------
+void USER_IMPL::DelConnectedAfterNotifier(PROPERTY_NOTIFIER_BASE<bool> * n)
+{
+STG_LOCKER lock(&mutex, __FILE__, __LINE__);
+connected.DelAfterNotifier(n);
+}
+//-----------------------------------------------------------------------------
void USER_IMPL::OnAdd()
{
STG_LOCKER lock(&mutex, __FILE__, __LINE__);
-string scriptOnAdd = settings->GetScriptDir() + "/OnUserAdd";
+string scriptOnAdd = settings->GetScriptsDir() + "/OnUserAdd";
if (access(scriptOnAdd.c_str(), X_OK) == 0)
{
{
STG_LOCKER lock(&mutex, __FILE__, __LINE__);
-string scriptOnDel = settings->GetScriptDir() + "/OnUserDel";
+string scriptOnDel = settings->GetScriptsDir() + "/OnUserDel";
if (access(scriptOnDel.c_str(), X_OK) == 0)
{
if (ts.size() && !disabledDetailStat)
{
- if (store->WriteDetailedStat(ts, lastWriteDeatiledStat, login))
+ if (store->WriteDetailedStat(ts, lastWriteDetailedStat, login))
{
printfd(__FILE__, "USER::WriteDetailStat() - failed to write current detail stat\n");
WriteServLog("Cannot write detail stat for user %s.", login.c_str());
printfd(__FILE__, "USER::WriteDetailStat() - pushing detail stat to queue\n");
STG_LOCKER lock(&mutex, __FILE__, __LINE__);
traffStatSaved.second.swap(ts);
- traffStatSaved.first = lastWriteDeatiledStat;
+ traffStatSaved.first = lastWriteDetailedStat;
}
return -1;
}
}
-lastWriteDeatiledStat = stgTime;
+lastWriteDetailedStat = stgTime;
return 0;
}
//-----------------------------------------------------------------------------
{
// No lock `cause we are already locked from caller
int ret = -1;
-set<const BASE_AUTH*>::iterator it(authorizedBy.begin());
+set<const AUTH*>::iterator it(authorizedBy.begin());
while (it != authorizedBy.end())
{
if (!(*it++)->SendMessage(msg, currIP))