-UsersImpl::UsersImpl(SettingsImpl * s, Store * st,
- Tariffs * t, Services & svcs,
- const Admin& sa)
+UsersImpl::UsersImpl(SettingsImpl * s, Store * store,
+ Tariffs * tariffs, Services & svcs,
+ const Admin& sysAdmin)
-pthread_mutexattr_t attr;
-pthread_mutexattr_init(&attr);
-pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
-pthread_mutex_init(&mutex, &attr);
-pthread_mutex_destroy(&mutex);
-}
-//-----------------------------------------------------------------------------
-int UsersImpl::FindByNameNonLock(const std::string & login, user_iter * user)
-{
-const std::map<std::string, user_iter>::const_iterator iter(loginIndex.find(login));
+const auto iter = loginIndex.find(login);
}
//-----------------------------------------------------------------------------
int UsersImpl::FindByName(const std::string & login, UserPtr * user)
{
}
//-----------------------------------------------------------------------------
int UsersImpl::FindByName(const std::string & login, UserPtr * user)
{
//-----------------------------------------------------------------------------
int UsersImpl::FindByName(const std::string & login, ConstUserPtr * user) const
{
//-----------------------------------------------------------------------------
int UsersImpl::FindByName(const std::string & login, ConstUserPtr * user) const
{
//-----------------------------------------------------------------------------
bool UsersImpl::Exists(const std::string & login) const
{
//-----------------------------------------------------------------------------
bool UsersImpl::Exists(const std::string & login) const
{
-STG_LOCKER lock(&mutex);
-const std::map<std::string, user_iter>::const_iterator iter(loginIndex.find(login));
+std::lock_guard<std::mutex> lock(m_mutex);
+const auto iter = loginIndex.find(login);
return iter != loginIndex.end();
}
//-----------------------------------------------------------------------------
bool UsersImpl::TariffInUse(const std::string & tariffName) const
{
return iter != loginIndex.end();
}
//-----------------------------------------------------------------------------
bool UsersImpl::TariffInUse(const std::string & tariffName) const
{
//-----------------------------------------------------------------------------
int UsersImpl::Add(const std::string & login, const Admin * admin)
{
//-----------------------------------------------------------------------------
int UsersImpl::Add(const std::string & login, const Admin * admin)
{
{
WriteServLog("%s tried to add user \'%s\'. Access denied.",
admin->logStr().c_str(), login.c_str());
return -1;
}
{
WriteServLog("%s tried to add user \'%s\'. Access denied.",
admin->logStr().c_str(), login.c_str());
return -1;
}
-UserImpl u(settings, store, tariffs, &sysAdmin, this, m_services);
+UserImpl u(settings, m_store, m_tariffs, &m_sysAdmin, this, m_services);
{
WriteServLog("%s tried to remove user \'%s\'. Access denied.",
admin->logStr().c_str(), login.c_str());
{
WriteServLog("%s tried to remove user \'%s\'. Access denied.",
admin->logStr().c_str(), login.c_str());
-STG_LOCKER lock(&mutex);
-if (FindByNameNonLock(login, &iter))
+std::lock_guard<std::mutex> lock(m_mutex);
+if (!FindByNameNonLock(login, &iter))
-STG_LOCKER lock(&mutex);
-if (FindByNameNonLock(login, &iter))
+std::lock_guard<std::mutex> lock(m_mutex);
+if (!FindByNameNonLock(login, &iter))
{
WriteServLog("Attempt to unauthorize non-existant user '%s'", login.c_str());
printfd(__FILE__, "Attempt to unauthorize non-existant user '%s'", login.c_str());
{
WriteServLog("Attempt to unauthorize non-existant user '%s'", login.c_str());
printfd(__FILE__, "Attempt to unauthorize non-existant user '%s'", login.c_str());
- UserImpl u(settings, store, tariffs, &sysAdmin, this, m_services);
+ UserImpl u(settings, m_store, m_tariffs, &m_sysAdmin, this, m_services);
printfd(__FILE__,"Day = %d Min = %d\n", day, min);
time_t touchTime = stgTime - MONITOR_TIME_DELAY_SEC;
printfd(__FILE__,"Day = %d Min = %d\n", day, min);
time_t touchTime = stgTime - MONITOR_TIME_DELAY_SEC;
-std::string monFile = us->settings->GetMonitorDir() + "/users_r";
-printfd(__FILE__, "Monitor=%d file USERS %s\n", us->settings->GetMonitoring(), monFile.c_str());
+std::string monFile = settings->GetMonitorDir() + "/users_r";
+printfd(__FILE__, "Monitor=%d file USERS %s\n", settings->GetMonitoring(), monFile.c_str());
{
//printfd(__FILE__,"New Minute. old = %02d current = %02d\n", min, t->tm_min);
//printfd(__FILE__,"New Day. old = %2d current = %2d\n", day, t->tm_mday);
{
//printfd(__FILE__,"New Minute. old = %02d current = %02d\n", min, t->tm_min);
//printfd(__FILE__,"New Day. old = %2d current = %2d\n", day, t->tm_mday);
printfd(__FILE__,"New Minute. old = %d current = %d\n", min, t.tm_min);
min = t.tm_min;
printfd(__FILE__,"New Minute. old = %d current = %d\n", min, t.tm_min);
min = t.tm_min;
printfd(__FILE__,"Sec = %d\n", stgTime);
printfd(__FILE__,"New Day. old = %d current = %d\n", day, t.tm_mday);
day = t.tm_mday;
printfd(__FILE__,"Sec = %d\n", stgTime);
printfd(__FILE__,"New Day. old = %d current = %d\n", day, t.tm_mday);
day = t.tm_mday;
{
//printfd(__FILE__, "Monitor=%d file TRAFFCOUNTER %s\n", tc->monitoring, monFile.c_str());
touchTime = stgTime;
{
//printfd(__FILE__, "Monitor=%d file TRAFFCOUNTER %s\n", tc->monitoring, monFile.c_str());
touchTime = stgTime;
}
//-----------------------------------------------------------------------------
void UsersImpl::NewMinute(const struct tm & t)
}
//-----------------------------------------------------------------------------
void UsersImpl::NewMinute(const struct tm & t)
//-----------------------------------------------------------------------------
void UsersImpl::DayResetTraff(const struct tm & t1)
{
//-----------------------------------------------------------------------------
void UsersImpl::DayResetTraff(const struct tm & t1)
{
-nonstop = true;
-if (pthread_create(&thread, NULL, Run, this))
- {
- WriteServLog("USERS: Error: Cannot start thread!");
- return -1;
- }
+m_thread = std::jthread([this](auto token){ Run(std::move(token)); });
//5 seconds to thread stops itself
struct timespec ts = {0, 200000000};
//5 seconds to thread stops itself
struct timespec ts = {0, 200000000};
- if (pthread_kill(thread, SIGINT))
- {
- //errorStr = "Cannot kill USERS thread.";
- //printfd(__FILE__, "Cannot kill USERS thread.\n");
- //return 0;
- }
- printfd(__FILE__, "USERS killed\n");
printfd(__FILE__, "Before USERS::Run()\n");
for_each(users.begin(), users.end(), [](auto& user){ user.Run(); });
printfd(__FILE__, "Before USERS::Run()\n");
for_each(users.begin(), users.end(), [](auto& user){ user.Run(); });
-// 'cause bind2st accepts only constant first param
-for (std::list<UserImpl>::iterator it = users.begin();
- it != users.end();
- ++it)
- it->WriteDetailStat(true);
+for (auto& user : users)
+ user.WriteDetailStat(true);
for_each(users.begin(), users.end(), [](auto& user){ user.WriteStat(); });
//for_each(users.begin(), users.end(), mem_fun_ref(&UserImpl::WriteConf));
for_each(users.begin(), users.end(), [](auto& user){ user.WriteStat(); });
//for_each(users.begin(), users.end(), mem_fun_ref(&UserImpl::WriteConf));
//-----------------------------------------------------------------------------
void UsersImpl::RealDelUser()
{
//-----------------------------------------------------------------------------
void UsersImpl::RealDelUser()
{
while (iter != usersToDelete.end())
{
printfd(__FILE__, "RealDelUser() user=%s\n", iter->iter->GetLogin().c_str());
if (iter->delTime + userDeleteDelayTime < stgTime)
{
printfd(__FILE__, "RealDelUser() user=%s removed from DB\n", iter->iter->GetLogin().c_str());
while (iter != usersToDelete.end())
{
printfd(__FILE__, "RealDelUser() user=%s\n", iter->iter->GetLogin().c_str());
if (iter->delTime + userDeleteDelayTime < stgTime)
{
printfd(__FILE__, "RealDelUser() user=%s removed from DB\n", iter->iter->GetLogin().c_str());
}
//-----------------------------------------------------------------------------
void UsersImpl::AddToIPIdx(user_iter user)
}
//-----------------------------------------------------------------------------
void UsersImpl::AddToIPIdx(user_iter user)
printfd(__FILE__, "USERS: Add IP Idx\n");
uint32_t ip = user->GetCurrIP();
//assert(ip && "User has non-null ip");
printfd(__FILE__, "USERS: Add IP Idx\n");
uint32_t ip = user->GetCurrIP();
//assert(ip && "User has non-null ip");
printfd(__FILE__, "USERS: Del IP Idx\n");
assert(ip && "User has non-null ip");
printfd(__FILE__, "USERS: Del IP Idx\n");
assert(ip && "User has non-null ip");
//-----------------------------------------------------------------------------
bool UsersImpl::FindByIPIdx(uint32_t ip, user_iter & iter) const
{
//-----------------------------------------------------------------------------
bool UsersImpl::FindByIPIdx(uint32_t ip, user_iter & iter) const
{
//-----------------------------------------------------------------------------
bool UsersImpl::IsIPInIndex(uint32_t ip) const
{
//-----------------------------------------------------------------------------
bool UsersImpl::IsIPInIndex(uint32_t ip) const
{
}
//-----------------------------------------------------------------------------
bool UsersImpl::IsIPInUse(uint32_t ip, const std::string & login, ConstUserPtr * user) const
{
}
//-----------------------------------------------------------------------------
bool UsersImpl::IsIPInUse(uint32_t ip, const std::string & login, ConstUserPtr * user) const
{
while (iter != users.end())
{
if (iter->GetLogin() != login &&
!iter->GetProperties().ips.Get().isAnyIP() &&
iter->GetProperties().ips.Get().find(ip))
{
while (iter != users.end())
{
if (iter->GetLogin() != login &&
!iter->GetProperties().ips.Get().isAnyIP() &&
iter->GetProperties().ips.Get().find(ip))
{
//-----------------------------------------------------------------------------
void UsersImpl::AddNotifierUserAdd(NotifierBase<UserPtr> * n)
{
//-----------------------------------------------------------------------------
void UsersImpl::AddNotifierUserAdd(NotifierBase<UserPtr> * n)
{
onAddNotifiers.insert(n);
}
//-----------------------------------------------------------------------------
void UsersImpl::DelNotifierUserAdd(NotifierBase<UserPtr> * n)
{
onAddNotifiers.insert(n);
}
//-----------------------------------------------------------------------------
void UsersImpl::DelNotifierUserAdd(NotifierBase<UserPtr> * n)
{
onAddNotifiers.erase(n);
}
//-----------------------------------------------------------------------------
void UsersImpl::AddNotifierUserDel(NotifierBase<UserPtr> * n)
{
onAddNotifiers.erase(n);
}
//-----------------------------------------------------------------------------
void UsersImpl::AddNotifierUserDel(NotifierBase<UserPtr> * n)
{
onDelNotifiers.insert(n);
}
//-----------------------------------------------------------------------------
void UsersImpl::DelNotifierUserDel(NotifierBase<UserPtr> * n)
{
onDelNotifiers.insert(n);
}
//-----------------------------------------------------------------------------
void UsersImpl::DelNotifierUserDel(NotifierBase<UserPtr> * n)
{
onDelNotifiers.erase(n);
}
//-----------------------------------------------------------------------------
void UsersImpl::AddNotifierUserAdd(NotifierBase<UserImplPtr> * n)
{
onDelNotifiers.erase(n);
}
//-----------------------------------------------------------------------------
void UsersImpl::AddNotifierUserAdd(NotifierBase<UserImplPtr> * n)
{
onAddNotifiersImpl.insert(n);
}
//-----------------------------------------------------------------------------
void UsersImpl::DelNotifierUserAdd(NotifierBase<UserImplPtr> * n)
{
onAddNotifiersImpl.insert(n);
}
//-----------------------------------------------------------------------------
void UsersImpl::DelNotifierUserAdd(NotifierBase<UserImplPtr> * n)
{
onAddNotifiersImpl.erase(n);
}
//-----------------------------------------------------------------------------
void UsersImpl::AddNotifierUserDel(NotifierBase<UserImplPtr> * n)
{
onAddNotifiersImpl.erase(n);
}
//-----------------------------------------------------------------------------
void UsersImpl::AddNotifierUserDel(NotifierBase<UserImplPtr> * n)
{
onDelNotifiersImpl.insert(n);
}
//-----------------------------------------------------------------------------
void UsersImpl::DelNotifierUserDel(NotifierBase<UserImplPtr> * n)
{
onDelNotifiersImpl.insert(n);
}
//-----------------------------------------------------------------------------
void UsersImpl::DelNotifierUserDel(NotifierBase<UserImplPtr> * n)
{
onDelNotifiersImpl.erase(n);
}
//-----------------------------------------------------------------------------
onDelNotifiersImpl.erase(n);
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
int UsersImpl::SearchNext(int h, UserPtr * user)
{
//-----------------------------------------------------------------------------
int UsersImpl::SearchNext(int h, UserPtr * user)
{
//-----------------------------------------------------------------------------
int UsersImpl::SearchNext(int h, UserImpl ** user)
{
//-----------------------------------------------------------------------------
int UsersImpl::SearchNext(int h, UserImpl ** user)
{
//-----------------------------------------------------------------------------
int UsersImpl::CloseSearch(int h)
{
//-----------------------------------------------------------------------------
int UsersImpl::CloseSearch(int h)
{
if (searchDescriptors.find(h) != searchDescriptors.end())
{
searchDescriptors.erase(searchDescriptors.find(h));
if (searchDescriptors.find(h) != searchDescriptors.end())
{
searchDescriptors.erase(searchDescriptors.find(h));
//-----------------------------------------------------------------------------
void UsersImpl::AddUserIntoIndexes(user_iter user)
{
//-----------------------------------------------------------------------------
void UsersImpl::AddUserIntoIndexes(user_iter user)
{
loginIndex.insert(make_pair(user->GetLogin(), user));
}
//-----------------------------------------------------------------------------
void UsersImpl::DelUserFromIndexes(user_iter user)
{
loginIndex.insert(make_pair(user->GetLogin(), user));
}
//-----------------------------------------------------------------------------
void UsersImpl::DelUserFromIndexes(user_iter user)
{
loginIndex.erase(user->GetLogin());
}
//-----------------------------------------------------------------------------
bool UsersImpl::TimeToWriteDetailStat(const struct tm & t)
{
loginIndex.erase(user->GetLogin());
}
//-----------------------------------------------------------------------------
bool UsersImpl::TimeToWriteDetailStat(const struct tm & t)
{