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: 2009/06/19 12:50:32 $
 
  33 #include "base_auth.h"
 
  36 #include "../../../users.h"
 
  40 extern "C" BASE_PLUGIN * GetPlugin();
 
  43 //-----------------------------------------------------------------------------
 
  44 template <typename varParamType>
 
  45 class CHG_BEFORE_NOTIFIER: public PROPERTY_NOTIFIER_BASE<varParamType>
 
  48     void Notify(const varParamType & oldValue, const varParamType & newValue);
 
  49     void        SetUser(user_iter u) { user = u; }
 
  50     user_iter   GetUser() {return user; }
 
  51     void        SetAuthorizator(const AUTH_STRESS * a) { auth = a; }
 
  55     const       AUTH_STRESS * auth;
 
  57 //-----------------------------------------------------------------------------
 
  58 template <typename varParamType>
 
  59 class CHG_AFTER_NOTIFIER: public PROPERTY_NOTIFIER_BASE<varParamType>
 
  62     void        Notify(const varParamType & oldValue, const varParamType & newValue);
 
  63     void        SetUser(user_iter u) { user = u; }
 
  64     user_iter   GetUser() {return user; }
 
  65     void        SetAuthorizator(const AUTH_STRESS * a) { auth = a; }
 
  69     const AUTH_STRESS * auth;
 
  71 //-----------------------------------------------------------------------------
 
  72 class AUTH_STRESS_SETTINGS
 
  75                     AUTH_STRESS_SETTINGS();
 
  76     const string&   GetStrError() const { return errorStr; }
 
  77     int             ParseSettings(const MODULE_SETTINGS & s);
 
  78     int             GetAverageOnlineTime() const;
 
  80     int             ParseIntInRange(const string & str, int min, int max, int * val);
 
  81     int             averageOnlineTime;
 
  84 //-----------------------------------------------------------------------------
 
  85 class AUTH_STRESS :public BASE_AUTH
 
  89     virtual ~AUTH_STRESS(){};
 
  91     void                SetUsers(USERS * u);
 
  92     void                SetTariffs(TARIFFS * t){};
 
  93     void                SetAdmins(ADMINS * a){};
 
  94     void                SetTraffcounter(TRAFFCOUNTER * tc){};
 
  95     void                SetStore(BASE_STORE * ){};
 
  96     void                SetStgSettings(const SETTINGS *){};
 
 101     void                SetSettings(const MODULE_SETTINGS & s);
 
 103     const string      & GetStrError() const;
 
 104     const string        GetVersion() const;
 
 105     uint16_t            GetStartPosition() const;
 
 106     uint16_t            GetStopPosition() const;
 
 108     void                AddUser(user_iter u);
 
 109     void                DelUser(user_iter u);
 
 111     void                Authorize(user_iter u) const;
 
 112     void                Unauthorize(user_iter u) const;
 
 114     int                 SendMessage(const STG_MSG & msg, uint32_t ip) const;
 
 118     void                SetUserNotifiers(user_iter u);
 
 119     void                UnSetUserNotifiers(user_iter u);
 
 123     static void *       Run(void *);
 
 125     mutable string      errorStr;
 
 126     AUTH_STRESS_SETTINGS    stressSettings;
 
 128     list<user_iter>     usersList;
 
 130     MODULE_SETTINGS     settings;
 
 133     pthread_mutex_t     mutex;
 
 135     list<CHG_BEFORE_NOTIFIER<USER_IPS> >    BeforeChgIPNotifierList;
 
 136     list<CHG_AFTER_NOTIFIER<USER_IPS> >     AfterChgIPNotifierList;
 
 138     class ADD_USER_NONIFIER: public NOTIFIER_BASE<user_iter>
 
 141         ADD_USER_NONIFIER(){};
 
 142         virtual ~ADD_USER_NONIFIER(){};
 
 144         void SetAuthorizator(AUTH_STRESS * a) { auth = a; }
 
 145         void Notify(const user_iter & user)
 
 154     class DEL_USER_NONIFIER: public NOTIFIER_BASE<user_iter>
 
 157         DEL_USER_NONIFIER(){};
 
 158         virtual ~DEL_USER_NONIFIER(){};
 
 160         void SetAuthorizator(AUTH_STRESS * a) { auth = a; }
 
 161         void Notify(const user_iter & user)
 
 171 //-----------------------------------------------------------------------------