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.
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.
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
18 * Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
23 $Date: 2010/10/07 20:04:48 $
43 #include "stg_logger.h"
46 #include "noncopyable.h"
47 #include "eventloop.h"
49 const int userDeleteDelayTime = 120;
53 //-----------------------------------------------------------------------------
54 class PROPERTY_NOTIFER_IP_BEFORE: public PROPERTY_NOTIFIER_BASE<uint32_t>
57 PROPERTY_NOTIFER_IP_BEFORE(USERS & us, user_iter u) : users(us), user(u) {};
58 void Notify(const uint32_t & oldValue, const uint32_t & newValue);
59 user_iter GetUser() const { return user; };
64 //-----------------------------------------------------------------------------
65 class PROPERTY_NOTIFER_IP_AFTER: public PROPERTY_NOTIFIER_BASE<uint32_t>
68 PROPERTY_NOTIFER_IP_AFTER(USERS & us, user_iter u) : users(us), user(u) {};
69 void Notify(const uint32_t & oldValue, const uint32_t & newValue);
70 user_iter GetUser() const { return user; };
75 //-----------------------------------------------------------------------------
83 list<USER>::iterator iter;
86 //-----------------------------------------------------------------------------
87 class USERS : private NONCOPYABLE
89 friend class PROPERTY_NOTIFER_IP_BEFORE;
90 friend class PROPERTY_NOTIFER_IP_AFTER;
93 USERS(SETTINGS * s, BASE_STORE * store, TARIFFS * tariffs, const ADMIN & sysAdmin);
96 int FindByName(const string & login, user_iter * user) const;
97 int FindByID(int id, user_iter * user);
99 bool TariffInUse(const string & tariffName);
101 void AddNotifierUserAdd(NOTIFIER_BASE<user_iter> *);
102 void DelNotifierUserAdd(NOTIFIER_BASE<user_iter> *);
104 void AddNotifierUserDel(NOTIFIER_BASE<user_iter> *);
105 void DelNotifierUserDel(NOTIFIER_BASE<user_iter> *);
107 int Add(const string & login, const ADMIN & admin);
108 void Del(const string & login, const ADMIN & admin);
113 int FindByIPIdx(uint32_t ip, user_iter * user);
116 int SearchNext(int handler, user_iter * u);
117 int CloseSearch(int handler);
123 void AddToIPIdx(user_iter);
124 void DelFromIPIdx(uint32_t ip);
126 int FindByNameNonLock(const string & login, user_iter * user) const;
127 int FindByIDNonLock(int id, user_iter * user);
130 void ProcessActions();
132 void SetUserNotifiers(user_iter user);
133 void UnSetUserNotifiers(user_iter user);
135 void AddUserIntoIndexes(user_iter user);
136 void DelUserFromIndexes(user_iter user);
138 static void * Run(void *);
139 void NewMinute(const struct tm * t);
140 void NewDay(const struct tm * t);
141 void DayResetTraff(const struct tm * t);
143 bool TimeToWriteDetailStat(const struct tm * t);
146 list<USER_TO_DEL> usersToDelete;
147 list<PROPERTY_NOTIFER_IP_BEFORE> userIPNotifiersBefore;
148 list<PROPERTY_NOTIFER_IP_AFTER> userIPNotifiersAfter;
150 map<uint32_t, user_iter> ipIndex;
151 map<string, user_iter> loginIndex;
156 const ADMIN sysAdmin;
157 STG_LOGGER & WriteServLog;
162 mutable pthread_mutex_t mutex;
164 mutable unsigned int handle;
166 mutable map<int, user_iter> searchDescriptors;
168 set <NOTIFIER_BASE<user_iter>*> onAddNotifiers;
169 set <NOTIFIER_BASE<user_iter>*> onDelNotifiers;
171 //-----------------------------------------------------------------------------
173 void PROPERTY_NOTIFER_IP_BEFORE::Notify(const uint32_t & oldValue,
179 //EVENT_LOOP_SINGLETON::GetInstance().Enqueue(users, &USERS::DelFromIPIdx, oldValue);
180 // Using explicit call to assure that index is valid, because fast reconnect with delayed call can result in authorization error
181 users.DelFromIPIdx(oldValue);
183 //-----------------------------------------------------------------------------
185 void PROPERTY_NOTIFER_IP_AFTER::Notify(const uint32_t &,
186 const uint32_t & newValue)
191 //EVENT_LOOP_SINGLETON::GetInstance().Enqueue(users, &USERS::AddToIPIdx, user);
192 // Using explicit call to assure that index is valid, because fast reconnect with delayed call can result in authorization error
193 users.AddToIPIdx(user);
195 //-----------------------------------------------------------------------------