X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/6f7160dd027c8ce7e2760aa369768ba39ab80181..687631532197750696d35aa12c40406b04fb878d:/projects/stargazer/user_impl.cpp?ds=sidebyside diff --git a/projects/stargazer/user_impl.cpp b/projects/stargazer/user_impl.cpp index f18dd76e..8d648d4f 100644 --- a/projects/stargazer/user_impl.cpp +++ b/projects/stargazer/user_impl.cpp @@ -36,23 +36,24 @@ #include // access #include - +#include + +#include "stg/users.h" +#include "stg/common.h" +#include "stg/script_executer.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), @@ -115,7 +116,7 @@ tariff = tariffs->GetNoTariff(); ips = StrToIPS("*"); deleted = false; lastWriteStat = stgTime + random() % settings->GetStatWritePeriod(); -lastWriteDeatiledStat = stgTime; +lastWriteDetailedStat = stgTime; property.tariffName.AddBeforeNotifier(&tariffNotifier); property.passive.AddBeforeNotifier(&passiveNotifier); @@ -132,7 +133,7 @@ pthread_mutex_init(&mutex, &attr); //----------------------------------------------------------------------------- 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), @@ -193,7 +194,7 @@ connected = 0; deleted = u.deleted; lastWriteStat = u.lastWriteStat; -lastWriteDeatiledStat = u.lastWriteDeatiledStat; +lastWriteDetailedStat = u.lastWriteDetailedStat; settings = u.settings; @@ -351,7 +352,7 @@ if (store->SaveMonthStat(stat, t1.tm_mon, t1.tm_year, login)) 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__); /* @@ -424,7 +425,7 @@ ScanMessage(); return 0; } //----------------------------------------------------------------------------- -void USER_IMPL::Unauthorize(const BASE_AUTH * auth) +void USER_IMPL::Unauthorize(const AUTH * auth) { STG_LOCKER lock(&mutex, __FILE__, __LINE__); /* @@ -441,7 +442,7 @@ if (authorizedBy.empty()) } } //----------------------------------------------------------------------------- -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? @@ -458,7 +459,7 @@ STG_LOCKER lock(&mutex, __FILE__, __LINE__); if (!fakeConnect) { - string scriptOnConnect = settings->GetScriptDir() + "/OnConnect"; + string scriptOnConnect = settings->GetScriptsDir() + "/OnConnect"; if (access(scriptOnConnect.c_str(), X_OK) == 0) { @@ -515,7 +516,7 @@ if (!lastIPForDisconnect) if (!fakeDisconnect) { - string scriptOnDisonnect = settings->GetScriptDir() + "/OnDisconnect"; + string scriptOnDisonnect = settings->GetScriptsDir() + "/OnDisconnect"; if (access(scriptOnDisonnect.c_str(), X_OK) == 0) { @@ -907,11 +908,35 @@ STG_LOCKER lock(&mutex, __FILE__, __LINE__); currIP.DelAfterNotifier(n); } //----------------------------------------------------------------------------- +void USER_IMPL::AddConnectedBeforeNotifier(PROPERTY_NOTIFIER_BASE * n) +{ +STG_LOCKER lock(&mutex, __FILE__, __LINE__); +connected.AddBeforeNotifier(n); +} +//----------------------------------------------------------------------------- +void USER_IMPL::DelConnectedBeforeNotifier(PROPERTY_NOTIFIER_BASE * n) +{ +STG_LOCKER lock(&mutex, __FILE__, __LINE__); +connected.DelBeforeNotifier(n); +} +//----------------------------------------------------------------------------- +void USER_IMPL::AddConnectedAfterNotifier(PROPERTY_NOTIFIER_BASE * n) +{ +STG_LOCKER lock(&mutex, __FILE__, __LINE__); +connected.AddAfterNotifier(n); +} +//----------------------------------------------------------------------------- +void USER_IMPL::DelConnectedAfterNotifier(PROPERTY_NOTIFIER_BASE * 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) { @@ -933,7 +958,7 @@ void USER_IMPL::OnDelete() { STG_LOCKER lock(&mutex, __FILE__, __LINE__); -string scriptOnDel = settings->GetScriptDir() + "/OnUserDel"; +string scriptOnDel = settings->GetScriptsDir() + "/OnUserDel"; if (access(scriptOnDel.c_str(), X_OK) == 0) { @@ -980,7 +1005,7 @@ printfd(__FILE__, "USER::WriteDetailedStat() - size = %d\n", ts.size()); 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()); @@ -990,12 +1015,12 @@ if (ts.size() && !disabledDetailStat) 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; } //----------------------------------------------------------------------------- @@ -1190,7 +1215,7 @@ int USER_IMPL::SendMessage(STG_MSG & msg) const { // No lock `cause we are already locked from caller int ret = -1; -set::iterator it(authorizedBy.begin()); +set::iterator it(authorizedBy.begin()); while (it != authorizedBy.end()) { if (!(*it++)->SendMessage(msg, currIP))