]> git.stg.codes - stg.git/blobdiff - projects/stargazer/users_impl.cpp
Various fixes of issues reported by static analyzers.
[stg.git] / projects / stargazer / users_impl.cpp
index d66456af5aabf74bb0f5fa49d578d5d0e88f02e1..e973d2cd7192197a7744e3ba5a06c9135a5b30a2 100644 (file)
@@ -51,29 +51,18 @@ extern volatile time_t stgTime;
 //#define USERS_DEBUG 1
 
 //-----------------------------------------------------------------------------
-USERS_IMPL::USERS_IMPL(SETTINGS_IMPL * s, STORE * st, TARIFFS * t, const ADMIN * sa)
-    : USERS(),
-      users(),
-      usersToDelete(),
-      /*userIPNotifiersBefore(),
-      userIPNotifiersAfter(),*/
-      ipIndex(),
-      loginIndex(),
-      settings(s),
+USERS_IMPL::USERS_IMPL(SETTINGS_IMPL * s, STORE * st,
+                       TARIFFS * t, SERVICES & svcs,
+                       const ADMIN * sa)
+    : settings(s),
       tariffs(t),
+      m_services(svcs),
       store(st),
       sysAdmin(sa),
       WriteServLog(GetStgLogger()),
       nonstop(false),
       isRunning(false),
-      mutex(),
-      thread(),
-      handle(0),
-      searchDescriptors(),
-      onAddNotifiers(),
-      onDelNotifiers(),
-      onAddNotifiersImpl(),
-      onDelNotifiersImpl()
+      handle(0)
 {
 pthread_mutexattr_t attr;
 pthread_mutexattr_init(&attr);
@@ -126,6 +115,13 @@ if (FindByNameNonLock(login, &u))
 return 0;
 }
 //-----------------------------------------------------------------------------
+bool USERS_IMPL::Exists(const std::string & login) const
+{
+STG_LOCKER lock(&mutex);
+const std::map<std::string, user_iter>::const_iterator iter(loginIndex.find(login));
+return iter != loginIndex.end();
+}
+//-----------------------------------------------------------------------------
 bool USERS_IMPL::TariffInUse(const std::string & tariffName) const
 {
 STG_LOCKER lock(&mutex);
@@ -164,7 +160,7 @@ if (store->AddUser(login))
     }
 //////
 
-USER_IMPL u(settings, store, tariffs, sysAdmin, this);
+USER_IMPL u(settings, store, tariffs, sysAdmin, this, m_services);
 
 /*struct tm * tms;
 time_t t = stgTime;
@@ -323,6 +319,7 @@ STG_LOCKER lock(&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());
     return false;
     }
 
@@ -350,7 +347,7 @@ user_iter ui;
 
 for (unsigned int i = 0; i < usersList.size(); i++)
     {
-    USER_IMPL u(settings, store, tariffs, sysAdmin, this);
+    USER_IMPL u(settings, store, tariffs, sysAdmin, this, m_services);
 
     u.SetLogin(usersList[i]);
     users.push_front(u);
@@ -422,21 +419,13 @@ while (us->nonstop)
         {
         //printfd(__FILE__, "Monitor=%d file TRAFFCOUNTER %s\n", tc->monitoring, monFile.c_str());
         touchTime = stgTime;
-        TouchFile(monFile.c_str());
+        TouchFile(monFile);
         }
 
     stgUsleep(100000);
     } //while (us->nonstop)
 
-user_iter ui = us->users.begin();
-while (ui != us->users.end())
-    {
-    us->DelUserFromIndexes(ui);
-    ++ui;
-    }
-
-std::list<USER_TO_DEL>::iterator iter;
-iter = us->usersToDelete.begin();
+std::list<USER_TO_DEL>::iterator iter(us->usersToDelete.begin());
 while (iter != us->usersToDelete.end())
     {
     iter->delTime -= 2 * userDeleteDelayTime;