]> git.stg.codes - stg.git/blob - projects/stargazer/users_impl.cpp
Fix compilation issues
[stg.git] / projects / stargazer / users_impl.cpp
1 /*
2  *    This program is free software; you can redistribute it and/or modify
3  *    it under the terms of the GNU General Public License as published by
4  *    the Free Software Foundation; either version 2 of the License, or
5  *    (at your option) any later version.
6  *
7  *    This program is distributed in the hope that it will be useful,
8  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
9  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  *    GNU General Public License for more details.
11  *
12  *    You should have received a copy of the GNU General Public License
13  *    along with this program; if not, write to the Free Software
14  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15  */
16
17 /*
18  *    Date: 27.10.2002
19  */
20
21 /*
22  *    Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
23  */
24
25 /*
26  $Revision: 1.61 $
27  $Date: 2010/09/13 05:56:42 $
28  $Author: faust $
29  */
30
31 #ifndef _GNU_SOURCE
32 #define _GNU_SOURCE
33 #endif
34
35 #include <pthread.h>
36 #include <csignal>
37 #include <cassert>
38 #include <algorithm>
39 #include <utility>
40 #include <string>
41 #include <vector>
42
43 #include "settings.h"
44 #include "users_impl.h"
45 #include "common.h"
46 #include "stg_timer.h"
47
48 using namespace std;
49
50 extern const volatile time_t stgTime;
51
52 //#define USERS_DEBUG 1
53
54 //-----------------------------------------------------------------------------
55 USERS_IMPL::USERS_IMPL(SETTINGS * s, STORE * st, TARIFFS * t, const ADMIN & sa)
56     : users(),
57       usersToDelete(),
58       userIPNotifiersBefore(),
59       userIPNotifiersAfter(),
60       ipIndex(),
61       loginIndex(),
62       settings(s),
63       tariffs(t),
64       store(st),
65       sysAdmin(sa),
66       WriteServLog(GetStgLogger()),
67       nonstop(false),
68       isRunning(false),
69       mutex(),
70       thread(),
71       handle(0),
72       searchDescriptors(),
73       onAddNotifiers(),
74       onDelNotifiers()
75 {
76 pthread_mutexattr_t attr;
77 pthread_mutexattr_init(&attr);
78 pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
79 pthread_mutex_init(&mutex, &attr);
80 }
81 //-----------------------------------------------------------------------------
82 USERS_IMPL::~USERS_IMPL()
83 {
84 pthread_mutex_destroy(&mutex);
85 }
86 //-----------------------------------------------------------------------------
87 int USERS_IMPL::FindByNameNonLock(const string & login, user_iter * user)
88 {
89 map<string, user_iter>::iterator iter;
90 iter = loginIndex.find(login);
91 if (iter != loginIndex.end())
92     {
93     if (user)
94         *user = iter->second;
95     return 0;
96     }
97 return -1;
98 }
99 //-----------------------------------------------------------------------------
100 int USERS_IMPL::FindByName(const string & login, USER_PTR * user)
101 {
102 STG_LOCKER lock(&mutex, __FILE__, __LINE__);
103 user_iter u;
104 int res = FindByNameNonLock(login, &u);
105 if (res)
106     return -1;
107 *user = &(*u);
108 return 0;
109 }
110 //-----------------------------------------------------------------------------
111 bool USERS_IMPL::TariffInUse(const string & tariffName) const
112 {
113 STG_LOCKER lock(&mutex, __FILE__, __LINE__);
114 list<USER_IMPL>::const_iterator iter;
115 iter = users.begin();
116 while (iter != users.end())
117     {
118     if (iter->GetProperty().tariffName.Get() == tariffName)
119         return true;
120     ++iter;
121     }
122 return false;
123 }
124 //-----------------------------------------------------------------------------
125 int USERS_IMPL::Add(const string & login, const ADMIN & admin)
126 {
127 STG_LOCKER lock(&mutex, __FILE__, __LINE__);
128 const PRIV * priv = admin.GetPriv();
129
130 if (!priv->userAddDel)
131     {
132     WriteServLog("%s tried to add user \'%s\'. Access denied.",
133          admin.GetLogStr().c_str(), login.c_str());
134     /*errorStr = "Admin \'" + admin.GetLogin() +
135                "\': tried to add user \'" + ud->login + "\'. Access denied.";*/
136     return -1;
137     }
138
139 //////
140 if (store->AddUser(login))
141     {
142     //TODO
143     //WriteServLog("Admin \'%s\': tried to add user \'%s\'. Access denied.",
144     //     admin.GetLogin().c_str(), ud->login.c_str());
145     return -1;
146     }
147 //////
148
149 USER_IMPL u(settings, store, tariffs, sysAdmin, this);
150
151 /*struct tm * tms;
152 time_t t = stgTime;
153
154 tms = localtime(&t);
155
156 tms->tm_hour = 0;
157 tms->tm_min = 0;
158 tms->tm_sec = 0;
159
160 if (settings->GetDayResetTraff() > tms->tm_mday)
161     tms->tm_mon -= 1;
162
163 tms->tm_mday = settings->GetDayResetTraff();*/
164
165 u.SetLogin(login);
166
167 u.SetPassiveTimeAsNewUser();
168
169 u.WriteConf();
170 u.WriteStat();
171
172 WriteServLog("%s User \'%s\' added.",
173          admin.GetLogStr().c_str(), login.c_str());
174
175 u.OnAdd();
176
177 users.push_front(u);
178
179 AddUserIntoIndexes(users.begin());
180 SetUserNotifiers(users.begin());
181
182 // õ×ÅÄÏÍÌÑÅÍ ×ÓÅÈ ÖÅÌÁÀÝÉÈ, ÞÔÏ ÄÏÂÁ×ÌÅΠÎÏ×ÙÊ ÐÏÌØÚÏ×ÁÔÅÌØ
183 set<NOTIFIER_BASE<USER_PTR> *>::iterator ni = onAddNotifiers.begin();
184 while (ni != onAddNotifiers.end())
185     {
186     (*ni)->Notify(&users.front());
187     ++ni;
188     }
189
190 return 0;
191 }
192 //-----------------------------------------------------------------------------
193 void USERS_IMPL::Del(const string & login, const ADMIN & admin)
194 {
195 const PRIV * priv = admin.GetPriv();
196 user_iter u;
197
198 if (!priv->userAddDel)
199     {
200     WriteServLog("%s tried to remove user \'%s\'. Access denied.",
201          admin.GetLogStr().c_str(), login.c_str());
202     return;
203     }
204
205
206     {
207     STG_LOCKER lock(&mutex, __FILE__, __LINE__);
208
209     if (FindByNameNonLock(login, &u))
210         {
211         WriteServLog("%s tried to delete user \'%s\': not found.",
212                      admin.GetLogStr().c_str(),
213                      login.c_str());
214         return;
215         }
216     }
217
218 set<NOTIFIER_BASE<USER_PTR> *>::iterator ni = onDelNotifiers.begin();
219 while (ni != onDelNotifiers.end())
220     {
221     (*ni)->Notify(&(*u));
222     ++ni;
223     }
224
225     {
226     STG_LOCKER lock(&mutex, __FILE__, __LINE__);
227
228     u->OnDelete();
229     u->SetDeleted();
230
231     USER_TO_DEL utd;
232     utd.iter = u;
233     utd.delTime = stgTime;
234     usersToDelete.push_back(utd);
235
236     UnSetUserNotifiers(u);
237     DelUserFromIndexes(u);
238
239     WriteServLog("%s User \'%s\' deleted.",
240              admin.GetLogStr().c_str(), login.c_str());
241
242     }
243 }
244 //-----------------------------------------------------------------------------
245 int USERS_IMPL::ReadUsers()
246 {
247 vector<string> usersList;
248 usersList.clear();
249 if (store->GetUsersList(&usersList) < 0)
250     {
251     WriteServLog(store->GetStrError().c_str());
252     exit(1);
253     }
254
255 user_iter ui;
256
257 for (unsigned int i = 0; i < usersList.size(); i++)
258     {
259     USER_IMPL u(settings, store, tariffs, sysAdmin, this);
260
261     u.SetLogin(usersList[i]);
262     users.push_front(u);
263     ui = users.begin();
264
265     AddUserIntoIndexes(ui);
266     SetUserNotifiers(ui);
267
268     if (ui->ReadConf() < 0)
269         return -1;
270
271     if (ui->ReadStat() < 0)
272         return -1;
273     }
274
275 return 0;
276 }
277 //-----------------------------------------------------------------------------
278 void * USERS_IMPL::Run(void * d)
279 {
280 printfd(__FILE__, "=====================| pid: %d |===================== \n", getpid());
281 USERS_IMPL * us = (USERS_IMPL*) d;
282
283 struct tm t;
284 time_t tt = stgTime;
285 localtime_r(&tt, &t);
286
287 int min = t.tm_min;
288 int day = t.tm_mday;
289
290 printfd(__FILE__,"Day = %d Min = %d\n", day, min);
291
292 time_t touchTime = stgTime - MONITOR_TIME_DELAY_SEC;
293 string monFile = us->settings->GetMonitorDir() + "/users_r";
294 printfd(__FILE__, "Monitor=%d file USERS %s\n", us->settings->GetMonitoring(), monFile.c_str());
295
296 us->isRunning = true;
297 while (us->nonstop)
298     {
299     //printfd(__FILE__,"New Minute. old = %02d current = %02d\n", min, t->tm_min);
300     //printfd(__FILE__,"New Day.    old = %2d current = %2d\n", day, t->tm_mday);
301
302     for_each(us->users.begin(), us->users.end(), mem_fun_ref(&USER_IMPL::Run));
303
304     tt = stgTime;
305     localtime_r(&tt, &t);
306
307     if (min != t.tm_min)
308         {
309         printfd(__FILE__,"Sec = %d\n", stgTime);
310         printfd(__FILE__,"New Minute. old = %d current = %d\n", min, t.tm_min);
311         min = t.tm_min;
312
313         us->NewMinute(t);
314         }
315
316     if (day != t.tm_mday)
317         {
318         printfd(__FILE__,"Sec = %d\n", stgTime);
319         printfd(__FILE__,"New Day. old = %d current = %d\n", day, t.tm_mday);
320         day = t.tm_mday;
321         us->NewDay(t);
322         }
323
324     if (us->settings->GetMonitoring() && (touchTime + MONITOR_TIME_DELAY_SEC <= stgTime))
325         {
326         //printfd(__FILE__, "Monitor=%d file TRAFFCOUNTER %s\n", tc->monitoring, monFile.c_str());
327         touchTime = stgTime;
328         TouchFile(monFile.c_str());
329         }
330
331     stgUsleep(100000);
332     } //while (us->nonstop)
333
334 user_iter ui = us->users.begin();
335 while (ui != us->users.end())
336     {
337     us->UnSetUserNotifiers(ui);
338     us->DelUserFromIndexes(ui);
339     ui++;
340     }
341
342 list<USER_TO_DEL>::iterator iter;
343 iter = us->usersToDelete.begin();
344 while (iter != us->usersToDelete.end())
345     {
346     iter->delTime -= 2 * userDeleteDelayTime;
347     ++iter;
348     }
349 us->RealDelUser();
350
351 us->isRunning = false;
352
353 return NULL;
354 }
355 //-----------------------------------------------------------------------------
356 void USERS_IMPL::NewMinute(const struct tm & t)
357 {
358 //Write traff, reset session traff. Fake disconnect-connect
359 if (t.tm_hour == 23 && t.tm_min == 59)
360     {
361     printfd(__FILE__,"MidnightResetSessionStat\n");
362     for_each(users.begin(), users.end(), mem_fun_ref(&USER_IMPL::MidnightResetSessionStat));
363     }
364
365 if (TimeToWriteDetailStat(t))
366     {
367     //printfd(__FILE__, "USER::WriteInetStat\n");
368     int usersCnt = 0;
369
370     // ðÉÛÅÍ ÀÚÅÒÏ× ÞÁÓÔÑÍÉ. ÷ ÐÅÒÅÒÙ×ÁÈ ×ÙÚÙ×ÁÅÍ USER::Run
371     list<USER_IMPL>::iterator usr = users.begin();
372     while (usr != users.end())
373         {
374         usersCnt++;
375         usr->WriteDetailStat();
376         usr++;
377         if (usersCnt % 10 == 0)
378             for_each(users.begin(), users.end(), mem_fun_ref(&USER_IMPL::Run));
379         }
380     }
381
382 RealDelUser();
383 }
384 //-----------------------------------------------------------------------------
385 void USERS_IMPL::NewDay(const struct tm & t)
386 {
387 struct tm t1;
388 time_t tt = stgTime;
389 localtime_r(&tt, &t1);
390 int dayFee = settings->GetDayFee();
391
392 if (dayFee == 0)
393     dayFee = DaysInCurrentMonth();
394
395 printfd(__FILE__, "DayFee = %d\n", dayFee);
396 printfd(__FILE__, "Today = %d DayResetTraff = %d\n", t1.tm_mday, settings->GetDayResetTraff());
397 printfd(__FILE__, "DayFeeIsLastDay = %d\n", settings->GetDayFeeIsLastDay());
398
399 if (!settings->GetDayFeeIsLastDay())
400     {
401     printfd(__FILE__, "DayResetTraff - 1 -\n");
402     DayResetTraff(t1);
403     //printfd(__FILE__, "DayResetTraff - 1 - 1 -\n");
404     }
405
406 if (settings->GetSpreadFee())
407     {
408     printfd(__FILE__, "Spread DayFee\n");
409     for_each(users.begin(), users.end(), mem_fun_ref(&USER_IMPL::ProcessDayFeeSpread));
410     }
411 else
412     {
413     if (t.tm_mday == dayFee)
414         {
415         printfd(__FILE__, "DayFee\n");
416         for_each(users.begin(), users.end(), mem_fun_ref(&USER_IMPL::ProcessDayFee));
417         }
418     }
419
420 if (settings->GetDayFeeIsLastDay())
421     {
422     printfd(__FILE__, "DayResetTraff - 2 -\n");
423     DayResetTraff(t1);
424     }
425 }
426 //-----------------------------------------------------------------------------
427 void USERS_IMPL::DayResetTraff(const struct tm & t1)
428 {
429 int dayResetTraff = settings->GetDayResetTraff();
430 if (dayResetTraff == 0)
431     dayResetTraff = DaysInCurrentMonth();
432 if (t1.tm_mday == dayResetTraff)
433     {
434     printfd(__FILE__, "ResetTraff\n");
435     for_each(users.begin(), users.end(), mem_fun_ref(&USER_IMPL::ProcessNewMonth));
436     for_each(users.begin(), users.end(), mem_fun_ref(&USER_IMPL::SetPrepaidTraff));
437     }
438 }
439 //-----------------------------------------------------------------------------
440 int USERS_IMPL::Start()
441 {
442 if (ReadUsers())
443     {
444     WriteServLog("USERS: Error: Cannot read users!");
445     return -1;
446     }
447
448 nonstop = true;
449 if (pthread_create(&thread, NULL, Run, this))
450     {
451     WriteServLog("USERS: Error: Cannot start thread!");
452     return -1;
453     }
454 return 0;
455 }
456 //-----------------------------------------------------------------------------
457 int USERS_IMPL::Stop()
458 {
459 printfd(__FILE__, "USERS::Stop()\n");
460
461 if (!isRunning)
462     {
463     //printfd(__FILE__, "Alredy stopped\n");
464     return 0;
465     }
466
467 nonstop = false;
468
469 //5 seconds to thread stops itself
470 unsigned i;
471 for (i = 0; i < 25 * (users.size() / 50 + 1); i++)
472     {
473     if (!isRunning)
474         break;
475
476     usleep(200000);
477     }
478
479 //after 5 seconds waiting thread still running. now kill it
480 if (isRunning)
481     {
482     printfd(__FILE__, "kill USERS thread.\n");
483     //TODO pthread_cancel()
484     if (pthread_kill(thread, SIGINT))
485         {
486         //errorStr = "Cannot kill USERS thread.";
487         //printfd(__FILE__, "Cannot kill USERS thread.\n");
488         //return 0;
489         }
490     printfd(__FILE__, "USERS killed\n");
491     }
492
493 printfd(__FILE__, "Before USERS::Run()\n");
494 for_each(users.begin(), users.end(), mem_fun_ref(&USER_IMPL::Run));
495
496 // 'cause bind2st accepts only constant first param
497 for (list<USER_IMPL>::iterator it = users.begin();
498      it != users.end();
499      ++it)
500     it->WriteDetailStat(true);
501
502 for_each(users.begin(), users.end(), mem_fun_ref(&USER_IMPL::WriteStat));
503 for_each(users.begin(), users.end(), mem_fun_ref(&USER_IMPL::WriteConf));
504
505 printfd(__FILE__, "USERS::Stop()\n");
506 return 0;
507 }
508 //-----------------------------------------------------------------------------
509 void USERS_IMPL::RealDelUser()
510 {
511 STG_LOCKER lock(&mutex, __FILE__, __LINE__);
512
513 printfd(__FILE__, "RealDelUser() users to del: %d\n", usersToDelete.size());
514
515 list<USER_TO_DEL>::iterator iter;
516 iter = usersToDelete.begin();
517 while (iter != usersToDelete.end())
518     {
519     printfd(__FILE__, "RealDelUser() user=%s\n", iter->iter->GetLogin().c_str());
520     if (iter->delTime + userDeleteDelayTime < stgTime)
521         {
522         printfd(__FILE__, "RealDelUser() user=%s removed from DB\n", iter->iter->GetLogin().c_str());
523         if (store->DelUser(iter->iter->GetLogin()))
524             {
525             WriteServLog("Error removing user \'%s\' from database.", iter->iter->GetLogin().c_str());
526             }
527         users.erase(iter->iter);
528         usersToDelete.erase(iter++);
529         }
530     else
531         {
532         ++iter;
533         }
534     }
535 return;
536 }
537 //-----------------------------------------------------------------------------
538 int USERS_IMPL::GetUserNum() const
539 {
540 return users.size();
541 }
542 //-----------------------------------------------------------------------------
543 void USERS_IMPL::AddToIPIdx(user_iter user)
544 {
545 printfd(__FILE__, "USERS: Add IP Idx\n");
546 uint32_t ip = user->GetCurrIP();
547 //assert(ip && "User has non-null ip");
548 if (!ip)
549     return; // User has disconnected
550
551 STG_LOCKER lock(&mutex, __FILE__, __LINE__);
552
553 const map<uint32_t, user_iter>::iterator it(
554         ipIndex.lower_bound(ip)
555 );
556
557 assert((it == ipIndex.end() || it->first != ip) && "User is not in index");
558
559 ipIndex.insert(it, std::make_pair(ip, user));
560 }
561 //-----------------------------------------------------------------------------
562 void USERS_IMPL::DelFromIPIdx(uint32_t ip)
563 {
564 printfd(__FILE__, "USERS: Del IP Idx\n");
565 assert(ip && "User has non-null ip");
566
567 STG_LOCKER lock(&mutex, __FILE__, __LINE__);
568
569 const map<uint32_t, user_iter>::iterator it(
570         ipIndex.find(ip)
571 );
572
573 //assert(it != ipIndex.end() && "User is in index");
574 if (it == ipIndex.end())
575     return; // User has not been added
576
577 ipIndex.erase(it);
578 }
579 //-----------------------------------------------------------------------------
580 int USERS_IMPL::FindByIPIdx(uint32_t ip, USER_PTR * usr) const
581 {
582 STG_LOCKER lock(&mutex, __FILE__, __LINE__);
583
584 map<uint32_t, user_iter>::const_iterator it;
585 it = ipIndex.find(ip);
586
587 if (it == ipIndex.end())
588     {
589     //printfd(__FILE__, "User NOT found in IP_Index!!!\n");
590     return -1;
591     }
592 *usr = &(*it->second);
593 //printfd(__FILE__, "User found in IP_Index\n");
594 return 0;
595 }
596 //-----------------------------------------------------------------------------
597 bool USERS_IMPL::IsIPInIndex(uint32_t ip) const
598 {
599 STG_LOCKER lock(&mutex, __FILE__, __LINE__);
600
601 map<uint32_t, user_iter>::const_iterator it;
602 it = ipIndex.find(ip);
603
604 return it != ipIndex.end();
605 }
606 //-----------------------------------------------------------------------------
607 void USERS_IMPL::AddNotifierUserAdd(NOTIFIER_BASE<USER_PTR> * n)
608 {
609 STG_LOCKER lock(&mutex, __FILE__, __LINE__);
610 onAddNotifiers.insert(n);
611 }
612 //-----------------------------------------------------------------------------
613 void USERS_IMPL::DelNotifierUserAdd(NOTIFIER_BASE<USER_PTR> * n)
614 {
615 STG_LOCKER lock(&mutex, __FILE__, __LINE__);
616 //printfd(__FILE__, "DelNotifierUserAdd\n");
617 onAddNotifiers.erase(n);
618 }
619 //-----------------------------------------------------------------------------
620 void USERS_IMPL::AddNotifierUserDel(NOTIFIER_BASE<USER_PTR> * n)
621 {
622 STG_LOCKER lock(&mutex, __FILE__, __LINE__);
623 onDelNotifiers.insert(n);
624 }
625 //-----------------------------------------------------------------------------
626 void USERS_IMPL::DelNotifierUserDel(NOTIFIER_BASE<USER_PTR> * n)
627 {
628 STG_LOCKER lock(&mutex, __FILE__, __LINE__);
629 onDelNotifiers.erase(n);
630 }
631 //-----------------------------------------------------------------------------
632 int USERS_IMPL::OpenSearch()
633 {
634 STG_LOCKER lock(&mutex, __FILE__, __LINE__);
635 handle++;
636 searchDescriptors[handle] = users.begin();
637 return handle;
638 }
639 //-----------------------------------------------------------------------------
640 int USERS_IMPL::SearchNext(int h, USER_PTR * user)
641 {
642 STG_LOCKER lock(&mutex, __FILE__, __LINE__);
643
644 if (searchDescriptors.find(h) == searchDescriptors.end())
645     {
646     WriteServLog("USERS. Incorrect search handle.");
647     return -1;
648     }
649
650 if (searchDescriptors[h] == users.end())
651     return -1;
652
653 while (searchDescriptors[h]->GetDeleted())
654     {
655     ++searchDescriptors[h];
656     if (searchDescriptors[h] == users.end())
657         {
658         return -1;
659         }
660     }
661
662 *user = &(*searchDescriptors[h]);
663
664 ++searchDescriptors[h];
665
666 return 0;
667 }
668 //-----------------------------------------------------------------------------
669 int USERS_IMPL::CloseSearch(int h)
670 {
671 STG_LOCKER lock(&mutex, __FILE__, __LINE__);
672 if (searchDescriptors.find(h) != searchDescriptors.end())
673     {
674     searchDescriptors.erase(searchDescriptors.find(h));
675     return 0;
676     }
677
678 WriteServLog("USERS. Incorrect search handle.");
679 return -1;
680 }
681 //-----------------------------------------------------------------------------
682 void USERS_IMPL::SetUserNotifiers(user_iter user)
683 {
684 STG_LOCKER lock(&mutex, __FILE__, __LINE__);
685
686 PROPERTY_NOTIFER_IP_BEFORE nb(*this, user);
687 PROPERTY_NOTIFER_IP_AFTER  na(*this, user);
688
689 userIPNotifiersBefore.push_front(nb);
690 userIPNotifiersAfter.push_front(na);
691
692 user->AddCurrIPBeforeNotifier(&(*userIPNotifiersBefore.begin()));
693 user->AddCurrIPAfterNotifier(&(*userIPNotifiersAfter.begin()));
694 }
695 //-----------------------------------------------------------------------------
696 void USERS_IMPL::UnSetUserNotifiers(user_iter user)
697 {
698 STG_LOCKER lock(&mutex, __FILE__, __LINE__);
699
700 list<PROPERTY_NOTIFER_IP_BEFORE>::iterator  bi;
701 list<PROPERTY_NOTIFER_IP_AFTER>::iterator   ai;
702
703 bi = userIPNotifiersBefore.begin();
704 while (bi != userIPNotifiersBefore.end())
705     {
706     if (bi->GetUser() == user)
707         {
708         bi->GetUser()->DelCurrIPBeforeNotifier(&(*bi));
709         userIPNotifiersBefore.erase(bi);
710         //printfd(__FILE__, "Notifier Before removed. User %s\n", bi->GetUser()->GetLogin().c_str());
711         break;
712         }
713     bi++;
714     }
715
716 ai = userIPNotifiersAfter.begin();
717 while (ai != userIPNotifiersAfter.end())
718     {
719     if (ai->GetUser() == user)
720         {
721         ai->GetUser()->DelCurrIPAfterNotifier(&(*ai));
722         userIPNotifiersAfter.erase(ai);
723         //printfd(__FILE__, "Notifier After removed. User %s\n", ai->GetUser()->GetLogin().c_str());
724         break;
725         }
726     ai++;
727     }
728 }
729 //-----------------------------------------------------------------------------
730 void USERS_IMPL::AddUserIntoIndexes(user_iter user)
731 {
732 STG_LOCKER lock(&mutex, __FILE__, __LINE__);
733 loginIndex.insert(make_pair(user->GetLogin(), user));
734 }
735 //-----------------------------------------------------------------------------
736 void USERS_IMPL::DelUserFromIndexes(user_iter user)
737 {
738 STG_LOCKER lock(&mutex, __FILE__, __LINE__);
739 loginIndex.erase(user->GetLogin());
740 }
741 //-----------------------------------------------------------------------------
742 bool USERS_IMPL::TimeToWriteDetailStat(const struct tm & t)
743 {
744 int statTime = settings->GetDetailStatWritePeriod();
745
746 switch (statTime)
747     {
748     case dsPeriod_1:
749         if (t.tm_min == 0)
750             return true;
751         break;
752     case dsPeriod_1_2:
753         if (t.tm_min % 30 == 0)
754             return true;
755         break;
756     case dsPeriod_1_4:
757         if (t.tm_min % 15 == 0)
758             return true;
759         break;
760     case dsPeriod_1_6:
761         if (t.tm_min % 10 == 0)
762             return true;
763         break;
764     }
765 return false;
766 }