+++ /dev/null
-###############################################################################
-# $Id: Makefile,v 1.2 2005/10/11 12:18:55 nobunaga Exp $
-###############################################################################
-
-#LIB_NAME = includes
-
-#INCS = *.h
-#include ../Makefile.in
-
-all:
- echo hi
-
-install:
- echo install
\ No newline at end of file
+++ /dev/null
- /*
- $Revision: 1.5 $
- $Date: 2010/03/04 11:49:52 $
- $Author: faust $
- */
-
-#ifndef BASE_SETTINGS_H
-#define BASE_SETTINGS_H
-
-#include <string.h>
-#include <string>
-#include <vector>
-
-using namespace std;
-
-//-----------------------------------------------------------------------------
-struct PARAM_VALUE
-{
- PARAM_VALUE()
- : param(),
- value()
- {};
- bool operator==(const PARAM_VALUE & rhs) const
- { return !strcasecmp(param.c_str(), rhs.param.c_str()); };
-
- bool operator<(const PARAM_VALUE & rhs) const
- { return strcasecmp(param.c_str(), rhs.param.c_str()) < 0; };
-
- string param;
- vector<string> value;
-};
-//-----------------------------------------------------------------------------
-struct MODULE_SETTINGS
-{
- MODULE_SETTINGS()
- : moduleName(),
- moduleParams()
- {};
- MODULE_SETTINGS(const MODULE_SETTINGS & rvalue)
- : moduleName(rvalue.moduleName),
- moduleParams(rvalue.moduleParams)
- {};
- bool operator==(const MODULE_SETTINGS & rhs) const
- { return !strcasecmp(moduleName.c_str(), rhs.moduleName.c_str()); };
-
- bool operator<(const MODULE_SETTINGS & rhs) const
- { return strcasecmp(moduleName.c_str(), rhs.moduleName.c_str()) < 0; };
-
-string moduleName;
-vector<PARAM_VALUE> moduleParams;
-};
-//-----------------------------------------------------------------------------
-#endif //BASE_SETTINGS_H
-
-
+++ /dev/null
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-/*
- * Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
- */
-
- /*
- $Revision: 1.16 $
- $Date: 2010/01/19 11:09:48 $
- $Author: faust $
- */
-
-#ifndef BASE_STORE_H
-#define BASE_STORE_H
-
-#include <string>
-#include <vector>
-#include <map>
-
-#include "user_stat.h"
-#include "user_conf.h"
-#include "corp_conf.h"
-#include "service_conf.h"
-#include "admin_conf.h"
-#include "tariff_conf.h"
-#include "base_settings.h"
-#include "stg_message.h"
-
-using namespace std;
-//-----------------------------------------------------------------------------
-class BASE_STORE
-{
-public:
- virtual ~BASE_STORE(){};
- virtual int GetUsersList(vector<string> * usersList) const = 0;
- virtual int AddUser(const string & login) const = 0;
- virtual int DelUser(const string & login) const = 0;
- virtual int SaveUserStat(const USER_STAT & stat, const string & login) const = 0;
- virtual int SaveUserConf(const USER_CONF & conf, const string & login) const = 0;
- virtual int RestoreUserStat(USER_STAT * stat, const string & login) const = 0;
- virtual int RestoreUserConf(USER_CONF * conf, const string & login) const = 0;
-
- virtual int WriteUserChgLog(const string & login,
- const string & admLogin,
- uint32_t admIP,
- const string & paramName,
- const string & oldValue,
- const string & newValue,
- const string & message = "") const = 0;
-
- virtual int WriteUserConnect(const string & login, uint32_t ip) const = 0;
-
- virtual int WriteUserDisconnect(const string & login,
- const DIR_TRAFF & up,
- const DIR_TRAFF & down,
- const DIR_TRAFF & sessionUp,
- const DIR_TRAFF & sessionDown,
- double cash,
- double freeMb,
- const std::string & reason) const = 0;
-
- virtual int WriteDetailedStat(const map<IP_DIR_PAIR, STAT_NODE> & statTree,
- time_t lastStat,
- const string & login) const = 0;
-
- virtual int AddMessage(STG_MSG * msg, const string & login) const = 0;
- virtual int EditMessage(const STG_MSG & msg, const string & login) const = 0;
- virtual int GetMessage(uint64_t id, STG_MSG * msg, const string & login) const = 0;
- virtual int DelMessage(uint64_t id, const string & login) const = 0;
- virtual int GetMessageHdrs(vector<STG_MSG_HDR> * hdrsList, const string & login) const = 0;
-
-
- virtual int SaveMonthStat(const USER_STAT & stat, int month, int year, const string & login) const = 0;
-
- virtual int GetAdminsList(vector<string> * adminsList) const = 0;
- virtual int SaveAdmin(const ADMIN_CONF & ac) const = 0;
- virtual int RestoreAdmin(ADMIN_CONF * ac, const string & login) const = 0;
- virtual int AddAdmin(const string & login) const = 0;
- virtual int DelAdmin(const string & login) const = 0;
-
- virtual int GetTariffsList(vector<string> * tariffsList) const = 0;
- virtual int AddTariff(const string & name) const = 0;
- virtual int DelTariff(const string & name) const = 0;
- virtual int SaveTariff(const TARIFF_DATA & td, const string & tariffName) const = 0;
- virtual int RestoreTariff(TARIFF_DATA * td, const string & tariffName) const = 0;
-
- virtual int GetCorpsList(vector<string> * corpsList) const = 0;
- virtual int SaveCorp(const CORP_CONF & cc) const = 0;
- virtual int RestoreCorp(CORP_CONF * cc, const string & name) const = 0;
- virtual int AddCorp(const string & name) const = 0;
- virtual int DelCorp(const string & name) const = 0;
-
- virtual int GetServicesList(vector<string> * corpsList) const = 0;
- virtual int SaveService(const SERVICE_CONF & sc) const = 0;
- virtual int RestoreService(SERVICE_CONF * sc, const string & name) const = 0;
- virtual int AddService(const string & name) const = 0;
- virtual int DelService(const string & name) const = 0;
-
- virtual void SetSettings(const MODULE_SETTINGS & s) = 0;
- virtual int ParseSettings() = 0;
- virtual const string & GetStrError() const = 0;
- virtual const string & GetVersion() const = 0;
-};
-//-----------------------------------------------------------------------------
-
-#endif //BASE_STORE_H
-
--- /dev/null
+ /*
+ $Revision: 1.5 $
+ $Date: 2010/03/04 11:49:52 $
+ $Author: faust $
+ */
+
+#ifndef MODULE_SETTINGS_H
+#define MODULE_SETTINGS_H
+
+#include <cstring> // strcasecmp
+#include <string>
+#include <vector>
+
+//-----------------------------------------------------------------------------
+struct PARAM_VALUE
+{
+ PARAM_VALUE()
+ : param(),
+ value()
+ {}
+ bool operator==(const PARAM_VALUE & rhs) const
+ { return !strcasecmp(param.c_str(), rhs.param.c_str()); }
+
+ bool operator<(const PARAM_VALUE & rhs) const
+ { return strcasecmp(param.c_str(), rhs.param.c_str()) < 0; }
+
+ std::string param;
+ std::vector<std::string> value;
+};
+//-----------------------------------------------------------------------------
+struct MODULE_SETTINGS
+{
+ MODULE_SETTINGS()
+ : moduleName(),
+ moduleParams()
+ {}
+ MODULE_SETTINGS(const MODULE_SETTINGS & rvalue)
+ : moduleName(rvalue.moduleName),
+ moduleParams(rvalue.moduleParams)
+ {}
+ bool operator==(const MODULE_SETTINGS & rhs) const
+ { return !strcasecmp(moduleName.c_str(), rhs.moduleName.c_str()); }
+
+ bool operator<(const MODULE_SETTINGS & rhs) const
+ { return strcasecmp(moduleName.c_str(), rhs.moduleName.c_str()) < 0; }
+
+ std::string moduleName;
+ std::vector<PARAM_VALUE> moduleParams;
+};
+//-----------------------------------------------------------------------------
+#endif
class TRAFFCOUNTER;
class SETTINGS;
-class BASE_STORE;
+class STORE;
class MODULE_SETTINGS;
-class PLUGIN : private NONCOPYABLE
-{
+class PLUGIN : private NONCOPYABLE {
public:
virtual ~PLUGIN() = 0;
virtual void SetUsers(USERS * u) = 0;
virtual void SetTariffs(TARIFFS * t) = 0;
virtual void SetAdmins(ADMINS * a) = 0;
virtual void SetTraffcounter(TRAFFCOUNTER * tc) = 0;
- virtual void SetStore(BASE_STORE * st) = 0;
+ virtual void SetStore(STORE * st) = 0;
virtual void SetStgSettings(const SETTINGS * s) = 0;
virtual void SetSettings(const MODULE_SETTINGS & s) = 0;
virtual int ParseSettings() = 0;
--- /dev/null
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/*
+ * Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
+ */
+
+ /*
+ $Revision: 1.16 $
+ $Date: 2010/01/19 11:09:48 $
+ $Author: faust $
+ */
+
+#ifndef STORE_H
+#define STORE_H
+
+#include <string>
+#include <vector>
+#include <map>
+
+#include "user_stat.h"
+#include "user_conf.h"
+#include "corp_conf.h"
+#include "service_conf.h"
+#include "admin_conf.h"
+#include "tariff_conf.h"
+#include "settings.h"
+#include "stg_message.h"
+
+//-----------------------------------------------------------------------------
+class STORE {
+public:
+ virtual int GetUsersList(std::vector<std::string> * usersList) const = 0;
+ virtual int AddUser(const std::string & login) const = 0;
+ virtual int DelUser(const std::string & login) const = 0;
+ virtual int SaveUserStat(const USER_STAT & stat, const std::string & login) const = 0;
+ virtual int SaveUserConf(const USER_CONF & conf, const std::string & login) const = 0;
+ virtual int RestoreUserStat(USER_STAT * stat, const std::string & login) const = 0;
+ virtual int RestoreUserConf(USER_CONF * conf, const std::string & login) const = 0;
+
+ virtual int WriteUserChgLog(const std::string & login,
+ const std::string & admLogin,
+ uint32_t admIP,
+ const std::string & paramName,
+ const std::string & oldValue,
+ const std::string & newValue,
+ const std::string & message = "") const = 0;
+
+ virtual int WriteUserConnect(const std::string & login, uint32_t ip) const = 0;
+
+ virtual int WriteUserDisconnect(const std::string & login,
+ const DIR_TRAFF & up,
+ const DIR_TRAFF & down,
+ const DIR_TRAFF & sessionUp,
+ const DIR_TRAFF & sessionDown,
+ double cash,
+ double freeMb,
+ const std::string & reason) const = 0;
+
+ virtual int WriteDetailedStat(const TRAFF_STAT & statTree,
+ time_t lastStat,
+ const std::string & login) const = 0;
+
+ virtual int AddMessage(STG_MSG * msg, const std::string & login) const = 0;
+ virtual int EditMessage(const STG_MSG & msg, const std::string & login) const = 0;
+ virtual int GetMessage(uint64_t id, STG_MSG * msg, const std::string & login) const = 0;
+ virtual int DelMessage(uint64_t id, const std::string & login) const = 0;
+ virtual int GetMessageHdrs(vector<STG_MSG_HDR> * hdrsList, const std::string & login) const = 0;
+
+ virtual int SaveMonthStat(const USER_STAT & stat, int month, int year, const std::string & login) const = 0;
+
+ virtual int GetAdminsList(std::vector<std::string> * adminsList) const = 0;
+ virtual int SaveAdmin(const ADMIN_CONF & ac) const = 0;
+ virtual int RestoreAdmin(ADMIN_CONF * ac, const std::string & login) const = 0;
+ virtual int AddAdmin(const std::string & login) const = 0;
+ virtual int DelAdmin(const std::string & login) const = 0;
+
+ virtual int GetTariffsList(std::vector<std::string> * tariffsList) const = 0;
+ virtual int AddTariff(const std::string & name) const = 0;
+ virtual int DelTariff(const std::string & name) const = 0;
+ virtual int SaveTariff(const TARIFF_DATA & td, const std::string & tariffName) const = 0;
+ virtual int RestoreTariff(TARIFF_DATA * td, const std::string & tariffName) const = 0;
+
+ virtual int GetCorpsList(std::vector<std::string> * corpsList) const = 0;
+ virtual int SaveCorp(const CORP_CONF & cc) const = 0;
+ virtual int RestoreCorp(CORP_CONF * cc, const std::string & name) const = 0;
+ virtual int AddCorp(const std::string & name) const = 0;
+ virtual int DelCorp(const std::string & name) const = 0;
+
+ virtual int GetServicesList(std::vector<std::string> * corpsList) const = 0;
+ virtual int SaveService(const SERVICE_CONF & sc) const = 0;
+ virtual int RestoreService(SERVICE_CONF * sc, const std::string & name) const = 0;
+ virtual int AddService(const std::string & name) const = 0;
+ virtual int DelService(const std::string & name) const = 0;
+
+ virtual void SetSettings(const MODULE_SETTINGS & s) = 0;
+ virtual int ParseSettings() = 0;
+ virtual const std::string & GetStrError() const = 0;
+ virtual const std::string & GetVersion() const = 0;
+};
+//-----------------------------------------------------------------------------
+
+#endif
virtual time_t GetConnectedModificationTime() const = 0;
virtual int GetAuthorized() const = 0;
virtual int Authorize(uint32_t ip,
- const std::string & iface,
uint32_t enabledDirs,
- const BASE_AUTH * auth) = 0;
- virtual void Unauthorize(const BASE_AUTH * auth) = 0;
- virtual bool IsAuthorizedBy(const BASE_AUTH * auth) const = 0;
+ const AUTH * auth) = 0;
+ virtual void Unauthorize(const AUTH * auth) = 0;
+ virtual bool IsAuthorizedBy(const AUTH * auth) const = 0;
virtual int AddMessage(STG_MSG * msg) = 0;
#include <algorithm>
#include "common.h"
-#include "base_store.h"
+#include "store.h"
#include "settings.h"
#include "conffiles.h"
#include "service_conf.h"
#include "admin_conf.h"
#include "tariff_conf.h"
-#include "base_settings.h"
+#include "module_settings.h"
#include "stg_message.h"
using namespace std;
{
printfd(__FILE__, "Start\n");
-BASE_STORE * fromStore = NULL;
-BASE_STORE * toStore = NULL;
+STORE * fromStore = NULL;
+STORE * toStore = NULL;
SETTINGS * settings = NULL;
return -1;
}
-BASE_STORE * (*GetSourceStore)();
-BASE_STORE * (*GetDestStore)();
+STORE * (*GetSourceStore)();
+STORE * (*GetDestStore)();
GetSourceStore = (BASE_STORE * (*)())dlsym(src_lh, "GetStore");
if (!GetSourceStore)
{
PROG = stargazer
-SRCS = ./admin.cpp \
- ./admins.cpp \
+SRCS = ./admin_impl.cpp \
+ ./admins_impl.cpp \
./main.cpp \
./settings.cpp \
./stg_timer.cpp \
- ./tariff.cpp \
- ./tariffs.cpp \
+ ./tariff_impl.cpp \
+ ./tariffs_impl.cpp \
./traffcounter.cpp \
- ./user.cpp \
+ ./user_impl.cpp \
./user_property.cpp \
- ./users.cpp \
+ ./users_impl.cpp \
./plugin_runner.cpp \
./store_loader.cpp \
./pidfile.cpp \
endif
endif
-deps: $(SRCS) ../../Makefile.conf
+deps: $(SRCS) ../../Makefile.conf
$(MAKE) -C $(DIR_LIBSRC) includes
@>deps ;\
for file in $(SRCS); do\
#define ADMINS_IMPL_H
#include <pthread.h>
+
#include <list>
#include <map>
#include "admin.h"
#include "admin_impl.h"
#include "stg_locker.h"
-#include "base_store.h"
+#include "store.h"
#include "noncopyable.h"
class ADMINS_IMPL : private NONCOPYABLE, public ADMINS {
public:
- ADMINS_IMPL(BASE_STORE * st);
- virtual ~ADMINS_IMPL() {};
+ ADMINS_IMPL(STORE * st);
+ virtual ~ADMINS_IMPL() {}
int Add(const string & login, const ADMIN & admin);
int Del(const string & login, const ADMIN & admin);
int Change(const ADMIN_CONF & ac, const ADMIN & admin);
void PrintAdmins() const;
- const ADMIN * GetSysAdmin() const { return &stg; };
- const ADMIN * GetNoAdmin() const { return &noAdmin; };
+ const ADMIN * GetSysAdmin() const { return &stg; }
+ const ADMIN * GetNoAdmin() const { return &noAdmin; }
bool FindAdmin(const std::string & l, ADMIN ** admin);
bool AdminExists(const std::string & login) const;
bool AdminCorrect(const std::string & login,
const std::string & password,
ADMIN * admin) const;
- const std::string & GetStrError() const { return strError; };
+ const std::string & GetStrError() const { return strError; }
int OpenSearch() const;
int SearchNext(int, ADMIN_CONF * ac) const;
ADMIN_IMPL stg;
ADMIN_IMPL noAdmin;
list<ADMIN_IMPL> data;
- BASE_STORE * store;
- STG_LOGGER & WriteServLog;
+ STORE * store;
+ STG_LOGGER & WriteServLog;
mutable map<int, const_admin_iter> searchDescriptors;
mutable unsigned int handle;
mutable pthread_mutex_t mutex;
- std::string strError;
+ std::string strError;
};
+
#endif
#include "settings.h"
#include "user.h"
-#include "users.h"
-#include "admins.h"
+#include "users_impl.h"
+#include "admins_impl.h"
+#include "tariffs_impl.h"
#include "common.h"
#include "traffcounter.h"
#include "base_plugin.h"
dataStore = storeLoader.GetStore();
WriteServLog("Storage plugin: %s. Loading successfull.", dataStore->GetVersion().c_str());
-tariffs = new TARIFFS(dataStore);
-admins = new ADMINS(dataStore);
-users = new USERS(settings, dataStore, tariffs, admins->GetSysAdmin());
+tariffs = new TARIFFS_IMPL(dataStore);
+admins = new ADMINS_IMPL(dataStore);
+users = new USERS_IMPL(settings, dataStore, tariffs, *admins->GetSysAdmin());
traffCnt = new TRAFFCOUNTER(users, tariffs, settings->GetRulesFileName());
traffCnt->SetMonitorDir(settings->GetMonitorDir());
#include "conffiles.h"
//-----------------------------------------------------------------------------
-PLUGIN_RUNNER::PLUGIN_RUNNER(const string & pFileName,
+PLUGIN_RUNNER::PLUGIN_RUNNER(const std::string & pFileName,
const MODULE_SETTINGS & ms,
ADMINS * a,
TARIFFS * t,
isPluginLoaded = 0;
}
//-----------------------------------------------------------------------------
-BASE_PLUGIN * PLUGIN_RUNNER::GetPlugin()
+PLUGIN * PLUGIN_RUNNER::GetPlugin()
{
return plugin;
}
if (!libHandle)
{
- errorStr = string("Plugin loading failed. ") + dlerror();
+ errorStr = std::string("Plugin loading failed. ") + dlerror();
printfd(__FILE__, "%s\n", errorStr.c_str());
return -1;
}
-BASE_PLUGIN * (*GetPlugin)();
-GetPlugin = (BASE_PLUGIN * (*)())dlsym(libHandle, "GetPlugin");
+PLUGIN * (*GetPlugin)();
+GetPlugin = (PLUGIN * (*)())dlsym(libHandle, "GetPlugin");
if (!GetPlugin)
{
- errorStr = string("GetPlugin() not found. ") + dlerror();
+ errorStr = std::string("GetPlugin() not found. ") + dlerror();
return -1;
}
plugin = GetPlugin();
return 0;
}
//-----------------------------------------------------------------------------
-const string & PLUGIN_RUNNER::GetStrError() const
+const std::string & PLUGIN_RUNNER::GetStrError() const
{
return errorStr;
}
return plugin->GetStopPosition();
}
//-----------------------------------------------------------------------------
-
#ifndef PLUGIN_RUNNER_H
#define PLUGIN_RUNNER_H
+
#include <pthread.h>
+
#include <string>
-#include "base_plugin.h"
-#include "base_settings.h"
+#include "plugin.h"
+#include "module_settings.h"
#include "traffcounter.h"
#include "tariffs.h"
#include "admins.h"
#include "users.h"
-using namespace std;
//-----------------------------------------------------------------------------
-class PLUGIN_RUNNER
-{
+class PLUGIN_RUNNER {
public:
- PLUGIN_RUNNER(const string & pluginFileName,
+ PLUGIN_RUNNER(const std::string & pluginFileName,
const MODULE_SETTINGS & ms,
ADMINS * admins,
TARIFFS * tariffs,
USERS * users,
TRAFFCOUNTER * tc,
- BASE_STORE * store,
+ STORE * store,
const SETTINGS * s);
PLUGIN_RUNNER(const PLUGIN_RUNNER & rvalue);
~PLUGIN_RUNNER();
int Restart();
bool IsRunning();
- const string & GetStrError() const;
- BASE_PLUGIN * GetPlugin();
- const string & GetFileName() const { return pluginFileName; };
+ const std::string & GetStrError() const;
+ PLUGIN * GetPlugin();
+ const std::string & GetFileName() const { return pluginFileName; }
int Load();
int Unload();
uint16_t GetStopPosition() const;
private:
- string pluginFileName;
- string pluginSettingFileName;
+ std::string pluginFileName;
+ std::string pluginSettingFileName;
- BASE_PLUGIN * plugin;
+ PLUGIN * plugin;
int isPluginLoaded;
- string errorStr;
+ std::string errorStr;
void * libHandle;
bool isRunning;
ADMINS * admins;
TARIFFS * tariffs;
USERS * users;
- BASE_STORE * store;
+ STORE * store;
TRAFFCOUNTER * traffCnt;
const SETTINGS * stgSettings;
MODULE_SETTINGS modSettings;
};
//-----------------------------------------------------------------------------
#endif //PLUGIN_RUNNER_H
-
-
#include <signal.h>
#include "ao.h"
-#include "../../../user.h"
+#include "user.h"
+#include "users.h"
+#include "../../../user_property.h"
#include "../../../eventloop.h"
class AO_CREATOR
//-----------------------------------------------------------------------------
// ëÌÁÓÓ ÄÌÑ ÐÏÉÓËÁ ÀÚÅÒÁ × ÓÐÉÓËÅ ÎÏÔÉÆÉËÁÔÏÒÏ×
template <typename varType>
-class IS_CONTAINS_USER: public binary_function<varType, user_iter, bool>
+class IS_CONTAINS_USER: public binary_function<varType, USER_PTR, bool>
{
public:
- bool operator()(varType notifier, user_iter user) const
+ bool operator()(varType notifier, USER_PTR user) const
{
return notifier.GetUser() == user;
};
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
-BASE_PLUGIN * GetPlugin()
+PLUGIN * GetPlugin()
{
return aoc.GetPlugin();
}
{
GetUsers();
-list<user_iter>::iterator users_iter;
+list<USER_PTR>::iterator users_iter;
/*onAddUserNotifier.SetAuthorizator(this);
onDelUserNotifier.SetAuthorizator(this);*/
users->DelNotifierUserAdd(&onAddUserNotifier);
users->DelNotifierUserDel(&onDelUserNotifier);
-list<user_iter>::iterator users_iter;
+list<USER_PTR>::iterator users_iter;
users_iter = usersList.begin();
while (users_iter != usersList.end())
{
return 70;
}
//-----------------------------------------------------------------------------
-void AUTH_AO::SetUserNotifiers(user_iter u)
+void AUTH_AO::SetUserNotifiers(USER_PTR u)
{
// ---------- AlwaysOnline -------------------
CHG_BEFORE_NOTIFIER<int> BeforeChgAONotifier(*this, u);
AfterChgAONotifier.SetUser(u);*/
AfterChgAONotifierList.push_front(AfterChgAONotifier);
-u->property.alwaysOnline.AddBeforeNotifier(&(*BeforeChgAONotifierList.begin()));
-u->property.alwaysOnline.AddAfterNotifier(&(*AfterChgAONotifierList.begin()));
+u->GetProperty().alwaysOnline.AddBeforeNotifier(&(*BeforeChgAONotifierList.begin()));
+u->GetProperty().alwaysOnline.AddAfterNotifier(&(*AfterChgAONotifierList.begin()));
// ---------- AlwaysOnline end ---------------
// ---------- IP -------------------
AfterChgIPNotifier.SetUser(u);*/
AfterChgIPNotifierList.push_front(AfterChgIPNotifier);
-u->property.ips.AddBeforeNotifier(&(*BeforeChgIPNotifierList.begin()));
-u->property.ips.AddAfterNotifier(&(*AfterChgIPNotifierList.begin()));
+u->GetProperty().ips.AddBeforeNotifier(&(*BeforeChgIPNotifierList.begin()));
+u->GetProperty().ips.AddAfterNotifier(&(*AfterChgIPNotifierList.begin()));
// ---------- IP end ---------------
}
//-----------------------------------------------------------------------------
-void AUTH_AO::UnSetUserNotifiers(user_iter u)
+void AUTH_AO::UnSetUserNotifiers(USER_PTR u)
{
// --- AlwaysOnline ---
IS_CONTAINS_USER<CHG_BEFORE_NOTIFIER<int> > IsContainsUserAOB;
if (aoBIter != BeforeChgAONotifierList.end())
{
- aoBIter->GetUser()->property.alwaysOnline.DelBeforeNotifier(&(*aoBIter));
+ aoBIter->GetUser()->GetProperty().alwaysOnline.DelBeforeNotifier(&(*aoBIter));
BeforeChgAONotifierList.erase(aoBIter);
}
if (aoAIter != AfterChgAONotifierList.end())
{
- aoAIter->GetUser()->property.alwaysOnline.DelAfterNotifier(&(*aoAIter));
+ aoAIter->GetUser()->GetProperty().alwaysOnline.DelAfterNotifier(&(*aoAIter));
AfterChgAONotifierList.erase(aoAIter);
}
// --- AlwaysOnline end ---
if (ipBIter != BeforeChgIPNotifierList.end())
{
- ipBIter->GetUser()->property.ips.DelBeforeNotifier(&(*ipBIter));
+ ipBIter->GetUser()->GetProperty().ips.DelBeforeNotifier(&(*ipBIter));
BeforeChgIPNotifierList.erase(ipBIter);
}
if (ipAIter != AfterChgIPNotifierList.end())
{
- ipAIter->GetUser()->property.ips.DelAfterNotifier(&(*ipAIter));
+ ipAIter->GetUser()->GetProperty().ips.DelAfterNotifier(&(*ipAIter));
AfterChgIPNotifierList.erase(ipAIter);
}
// --- IP end ---
//-----------------------------------------------------------------------------
void AUTH_AO::GetUsers()
{
-user_iter u;
+USER_PTR u;
int h = users->OpenSearch();
if (!h)
{
users->CloseSearch(h);
}
//-----------------------------------------------------------------------------
-void AUTH_AO::Unauthorize(user_iter u) const
+void AUTH_AO::Unauthorize(USER_PTR u) const
{
u->Unauthorize(this);
}
//-----------------------------------------------------------------------------
-void AUTH_AO::UpdateUserAuthorization(user_iter u) const
+void AUTH_AO::UpdateUserAuthorization(USER_PTR u) const
{
-if (u->property.alwaysOnline)
+if (u->GetProperty().alwaysOnline)
{
- USER_IPS ips = u->property.ips;
+ USER_IPS ips = u->GetProperty().ips;
if (ips.OnlyOneIP())
{
if (u->Authorize(ips[0].ip, "", 0xFFffFFff, this) == 0)
}
}
//-----------------------------------------------------------------------------
-void AUTH_AO::AddUser(user_iter u)
+void AUTH_AO::AddUser(USER_PTR u)
{
SetUserNotifiers(u);
usersList.push_back(u);
UpdateUserAuthorization(u);
}
//-----------------------------------------------------------------------------
-void AUTH_AO::DelUser(user_iter u)
+void AUTH_AO::DelUser(USER_PTR u)
{
Unauthorize(u);
UnSetUserNotifiers(u);
-list<user_iter>::iterator users_iter;
+list<USER_PTR>::iterator users_iter;
users_iter = usersList.begin();
while (users_iter != usersList.end())
EVENT_LOOP_SINGLETON::GetInstance().Enqueue(auth, &AUTH_AO::UpdateUserAuthorization, user);
}
//-----------------------------------------------------------------------------
-
#ifndef AO_H
#define AO_H
-#include <string>
#include <pthread.h>
-#include "base_auth.h"
-#include "base_store.h"
+
+#include <string>
+#include <list>
+
+#include "auth.h"
+#include "store.h"
#include "notifer.h"
#include "user_ips.h"
-#include "../../../users.h"
+#include "user.h"
-using namespace std;
-
-extern "C" BASE_PLUGIN * GetPlugin();
+extern "C" PLUGIN * GetPlugin();
class AUTH_AO;
+class USERS;
//-----------------------------------------------------------------------------
template <typename varParamType>
-class CHG_BEFORE_NOTIFIER: public PROPERTY_NOTIFIER_BASE<varParamType>
-{
+class CHG_BEFORE_NOTIFIER: public PROPERTY_NOTIFIER_BASE<varParamType> {
public:
- CHG_BEFORE_NOTIFIER(AUTH_AO & a, user_iter u) : user(u), auth(a) {}
+ CHG_BEFORE_NOTIFIER(AUTH_AO & a, USER_PTR u) : user(u), auth(a) {}
void Notify(const varParamType & oldValue, const varParamType & newValue);
- //void SetUser(user_iter u) { user = u; }
- user_iter GetUser() {return user; }
- //void SetAuthorizator(const AUTH_AO * a) { auth = a; }
+ USER_PTR GetUser() const { return user; }
private:
- user_iter user;
+ USER_PTR user;
const AUTH_AO & auth;
};
//-----------------------------------------------------------------------------
template <typename varParamType>
-class CHG_AFTER_NOTIFIER: public PROPERTY_NOTIFIER_BASE<varParamType>
-{
+class CHG_AFTER_NOTIFIER: public PROPERTY_NOTIFIER_BASE<varParamType> {
public:
- CHG_AFTER_NOTIFIER(AUTH_AO & a, user_iter u) : user(u), auth(a) {}
+ CHG_AFTER_NOTIFIER(AUTH_AO & a, USER_PTR u) : user(u), auth(a) {}
void Notify(const varParamType & oldValue, const varParamType & newValue);
- //void SetUser(user_iter u) { user = u; }
- user_iter GetUser() {return user; }
- //void SetAuthorizator(const AUTH_AO * a) { auth = a; }
+ USER_PTR GetUser() const { return user; }
private:
- user_iter user;
+ USER_PTR user;
const AUTH_AO & auth;
};
//-----------------------------------------------------------------------------
-class AUTH_AO_SETTINGS
-{
+class AUTH_AO_SETTINGS {
public:
- const string& GetStrError() const { static string s; return s; }
+ const std::string & GetStrError() const { static std::string s; return s; }
int ParseSettings(const MODULE_SETTINGS &) { return 0; }
};
//-----------------------------------------------------------------------------
-class AUTH_AO :public BASE_AUTH
-{
+class AUTH_AO :public AUTH {
public:
AUTH_AO();
virtual ~AUTH_AO(){};
void SetUsers(USERS * u);
- void SetTariffs(TARIFFS *){};
- void SetAdmins(ADMINS *){};
- void SetTraffcounter(TRAFFCOUNTER *){};
- void SetStore(BASE_STORE *){};
- void SetStgSettings(const SETTINGS *){};
+ void SetTariffs(TARIFFS *) {}
+ void SetAdmins(ADMINS *) {}
+ void SetTraffcounter(TRAFFCOUNTER *) {}
+ void SetStore(STORE *) {}
+ void SetStgSettings(const SETTINGS *) {}
int Start();
int Stop();
- int Reload() { return 0; };
+ int Reload() { return 0; }
bool IsRunning();
void SetSettings(const MODULE_SETTINGS & s);
int ParseSettings();
- const string & GetStrError() const;
- const string GetVersion() const;
+ const std::string & GetStrError() const;
+ const std::string GetVersion() const;
uint16_t GetStartPosition() const;
uint16_t GetStopPosition() const;
- void AddUser(user_iter u);
- void DelUser(user_iter u);
+ void AddUser(USER_PTR u);
+ void DelUser(USER_PTR u);
- void UpdateUserAuthorization(user_iter u) const;
- void Unauthorize(user_iter u) const;
+ void UpdateUserAuthorization(USER_PTR u) const;
+ void Unauthorize(USER_PTR u) const;
int SendMessage(const STG_MSG & msg, uint32_t ip) const;
private:
void GetUsers();
- void SetUserNotifiers(user_iter u);
- void UnSetUserNotifiers(user_iter u);
+ void SetUserNotifiers(USER_PTR u);
+ void UnSetUserNotifiers(USER_PTR u);
- mutable string errorStr;
+ mutable std::string errorStr;
AUTH_AO_SETTINGS aoSettings;
- USERS * users;
- list<user_iter> usersList;
+ USERS * users;
+ std::list<USER_PTR> usersList;
bool isRunning;
MODULE_SETTINGS settings;
list<CHG_BEFORE_NOTIFIER<USER_IPS> > BeforeChgIPNotifierList;
list<CHG_AFTER_NOTIFIER<USER_IPS> > AfterChgIPNotifierList;
- class ADD_USER_NONIFIER: public NOTIFIER_BASE<user_iter>
- {
+ class ADD_USER_NONIFIER: public NOTIFIER_BASE<USER_PTR> {
public:
- ADD_USER_NONIFIER(AUTH_AO & a) : auth(a) {};
- virtual ~ADD_USER_NONIFIER(){};
+ ADD_USER_NONIFIER(AUTH_AO & a) : auth(a) {}
+ virtual ~ADD_USER_NONIFIER() {}
- //void SetAuthorizator(AUTH_AO * a) { auth = a; }
- void Notify(const user_iter & user)
+ void Notify(const USER_PTR & user)
{
auth.AddUser(user);
}
AUTH_AO & auth;
} onAddUserNotifier;
- class DEL_USER_NONIFIER: public NOTIFIER_BASE<user_iter>
- {
+ class DEL_USER_NONIFIER: public NOTIFIER_BASE<USER_PTR> {
public:
- DEL_USER_NONIFIER(AUTH_AO & a) : auth(a) {};
- virtual ~DEL_USER_NONIFIER(){};
+ DEL_USER_NONIFIER(AUTH_AO & a) : auth(a) {}
+ virtual ~DEL_USER_NONIFIER() {}
- //void SetAuthorizator(AUTH_AO * a) { auth = a; }
- void Notify(const user_iter & user)
+ void Notify(const USER_PTR & user)
{
auth.DelUser(user);
}
//-----------------------------------------------------------------------------
#endif
-
-
#include "inetaccess.h"
#include "common.h"
+#include "stg_locker.h"
+#include "tariff.h"
+#include "../../../settings.h"
+#include "../../../user_property.h"
extern volatile const time_t stgTime;
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
-BASE_PLUGIN * GetPlugin()
+PLUGIN * GetPlugin()
{
return iac.GetPlugin();
}
uint32_t sip = *((uint32_t*)&outerAddr.sin_addr);
uint16_t sport = htons(outerAddr.sin_port);
-user_iter user;
+USER_PTR user;
if (users->FindByName(login, &user) == 0)
{
printfd(__FILE__, "User %s FOUND!\n", user->GetLogin().c_str());
return 0;
}
//-----------------------------------------------------------------------------
-int AUTH_IA::PacketProcessor(char * buff, int dataLen, uint32_t sip, uint16_t sport, int protoVer, user_iter * user)
+int AUTH_IA::PacketProcessor(char * buff, int dataLen, uint32_t sip, uint16_t sport, int protoVer, USER_PTR * user)
{
STG_LOCKER lock(&mutex, __FILE__, __LINE__);
// ôÕÔ ÓÏÂÒÁÎÙ ÏÂÒÁÂÏÔÞÉËÉ ÒÁÚÎÙÈ ÐÁËÅÔÏ×
if (iaUser->port != sport)
iaUser->port = sport;
-if (iaUser->password != (*user)->property.password.Get())
+if (iaUser->password != (*user)->GetProperty().password.Get())
{
- InitEncrypt(&iaUser->ctx, (*user)->property.password.Get());
- iaUser->password = (*user)->property.password.Get();
+ InitEncrypt(&iaUser->ctx, (*user)->GetProperty().password.Get());
+ iaUser->password = (*user)->GetProperty().password.Get();
}
buff += offset;
pn = pi->second;
}
-if ((*user)->property.disabled.Get())
+if ((*user)->GetProperty().disabled.Get())
{
SendError(sip, sport, protoVer, "õÞÅÔÎÁÑ ÚÁÐÉÓØ ÚÁÂÌÏËÉÒÏ×ÁÎÁ");
return 0;
}
-if ((*user)->property.passive.Get())
+if ((*user)->GetProperty().passive.Get())
{
SendError(sip, sport, protoVer, "õÞÅÔÎÁÑ ÚÁÐÉÓØ ÚÁÍÏÒÏÖÅÎÁ");
return 0;
return 0;
}
-user_iter u;
+USER_PTR u;
if (users->FindByIPIdx(sip, &u) == 0 && u->GetLogin() != (*user)->GetLogin())
{
printfd(__FILE__, "IP address alredy in use. IP \'%s\'", inet_ntostring(sip).c_str());
}
// ôÅÐÅÒØ ÍÙ ÄÏÌÖÎÙ ÐÒÏ×ÅÒÉÔØ, ÍÏÖÅÔ ÌÉ ÐÏÌØÚÏ×ÁÔÅÌØ ÐÏÄËÌÀÞÉÔÓÑ Ó ÜÔÏÇÏ ÁÄÒÅÓÁ.
-int ipFound = (*user)->property.ips.Get().IsIPInIPS(sip);
+int ipFound = (*user)->GetProperty().ips.Get().IsIPInIPS(sip);
if (!ipFound)
{
printfd(__FILE__, "User %s. IP address is incorrect. IP \'%s\'\n", (*user)->GetLogin().c_str(), inet_ntostring(sip).c_str());
{
case 6:
connSyn6 = (CONN_SYN_6*)(buff - offset);
- ret = Process_CONN_SYN_6(connSyn6, &(it->second), user, sip);
+ ret = Process_CONN_SYN_6(connSyn6, &(it->second), sip);
break;
case 7:
connSyn7 = (CONN_SYN_7*)(buff - offset);
- ret = Process_CONN_SYN_7(connSyn7, &(it->second), user, sip);
+ ret = Process_CONN_SYN_7(connSyn7, &(it->second), sip);
break;
case 8:
connSyn8 = (CONN_SYN_8*)(buff - offset);
- ret = Process_CONN_SYN_8(connSyn8, &(it->second), user, sip);
+ ret = Process_CONN_SYN_8(connSyn8, &(it->second), sip);
break;
}
switch (protoVer)
{
case 6:
- Send_CONN_SYN_ACK_6(iaUser, user, sip);
+ Send_CONN_SYN_ACK_6(iaUser, sip);
break;
case 7:
- Send_CONN_SYN_ACK_7(iaUser, user, sip);
+ Send_CONN_SYN_ACK_7(iaUser, sip);
break;
case 8:
- Send_CONN_SYN_ACK_8(iaUser, user, sip);
+ Send_CONN_SYN_ACK_8(iaUser, sip);
break;
}
break;
switch (protoVer)
{
case 6:
- ret = Process_CONN_ACK_6(connAck, iaUser, user, sip);
+ ret = Process_CONN_ACK_6(connAck, iaUser, sip);
break;
case 7:
- ret = Process_CONN_ACK_7(connAck, iaUser, user, sip);
+ ret = Process_CONN_ACK_7(connAck, iaUser, sip);
break;
case 8:
- ret = Process_CONN_ACK_8((CONN_ACK_8*)(buff - offset), iaUser, user, sip);
+ ret = Process_CONN_ACK_8((CONN_ACK_8*)(buff - offset), iaUser, sip);
break;
}
switch (protoVer)
{
case 6:
- ret = Process_ALIVE_ACK_6(aliveAck, iaUser, user, sip);
+ ret = Process_ALIVE_ACK_6(aliveAck, iaUser, sip);
break;
case 7:
- ret = Process_ALIVE_ACK_7(aliveAck, iaUser, user, sip);
+ ret = Process_ALIVE_ACK_7(aliveAck, iaUser, sip);
break;
case 8:
- ret = Process_ALIVE_ACK_8((ALIVE_ACK_8*)(buff - offset), iaUser, user, sip);
+ ret = Process_ALIVE_ACK_8((ALIVE_ACK_8*)(buff - offset), iaUser, sip);
break;
}
break;
switch (protoVer)
{
case 6:
- ret = Process_DISCONN_SYN_6(disconnSyn, iaUser, user, sip);
+ ret = Process_DISCONN_SYN_6(disconnSyn, iaUser, sip);
break;
case 7:
- ret = Process_DISCONN_SYN_7(disconnSyn, iaUser, user, sip);
+ ret = Process_DISCONN_SYN_7(disconnSyn, iaUser, sip);
break;
case 8:
- ret = Process_DISCONN_SYN_8((DISCONN_SYN_8*)(buff - offset), iaUser, user, sip);
+ ret = Process_DISCONN_SYN_8((DISCONN_SYN_8*)(buff - offset), iaUser, sip);
break;
}
switch (protoVer)
{
case 6:
- ret = Process_DISCONN_ACK_6(disconnAck, iaUser, user, sip, it);
+ ret = Process_DISCONN_ACK_6(disconnAck, iaUser, sip, it);
break;
case 7:
- ret = Process_DISCONN_ACK_7(disconnAck, iaUser, user, sip, it);
+ ret = Process_DISCONN_ACK_7(disconnAck, iaUser, sip, it);
break;
case 8:
- ret = Process_DISCONN_ACK_8((DISCONN_ACK_8*)(buff - offset), iaUser, user, sip, it);
+ ret = Process_DISCONN_ACK_8((DISCONN_ACK_8*)(buff - offset), iaUser, sip, it);
break;
}
return 0;
}
//-----------------------------------------------------------------------------
-void AUTH_IA::DelUser(user_iter u)
+void AUTH_IA::DelUser(USER_PTR u)
{
STG_LOCKER lock(&mutex, __FILE__, __LINE__);
return 0;
}
//-----------------------------------------------------------------------------
-int AUTH_IA::Process_CONN_SYN_6(CONN_SYN_6 *, IA_USER * iaUser, user_iter *, uint32_t)
+int AUTH_IA::Process_CONN_SYN_6(CONN_SYN_6 *, IA_USER * iaUser, uint32_t)
{
if (!(iaUser->phase.GetPhase() == 1 || iaUser->phase.GetPhase() == 3))
return -1;
return 0;
}
//-----------------------------------------------------------------------------
-int AUTH_IA::Process_CONN_SYN_7(CONN_SYN_7 * connSyn, IA_USER * iaUser, user_iter * user, uint32_t sip)
+int AUTH_IA::Process_CONN_SYN_7(CONN_SYN_7 * connSyn, IA_USER * iaUser, uint32_t sip)
{
-return Process_CONN_SYN_6(connSyn, iaUser, user, sip);
+return Process_CONN_SYN_6(connSyn, iaUser, sip);
}
//-----------------------------------------------------------------------------
-int AUTH_IA::Process_CONN_SYN_8(CONN_SYN_8 * connSyn, IA_USER * iaUser, user_iter * user, uint32_t sip)
+int AUTH_IA::Process_CONN_SYN_8(CONN_SYN_8 * connSyn, IA_USER * iaUser, uint32_t sip)
{
#ifdef ARCH_BE
SwapBytes(connSyn->dirs);
#endif
-int ret = Process_CONN_SYN_6((CONN_SYN_6*)connSyn, iaUser, user, sip);
+int ret = Process_CONN_SYN_6((CONN_SYN_6*)connSyn, iaUser, sip);
enabledDirs = connSyn->dirs;
return ret;
}
//-----------------------------------------------------------------------------
-int AUTH_IA::Process_CONN_ACK_6(CONN_ACK_6 * connAck, IA_USER * iaUser, user_iter *, uint32_t sip)
+int AUTH_IA::Process_CONN_ACK_6(CONN_ACK_6 * connAck, IA_USER * iaUser, uint32_t sip)
{
#ifdef ARCH_BE
SwapBytes(connAck->len);
return -1;
}
//-----------------------------------------------------------------------------
-int AUTH_IA::Process_CONN_ACK_7(CONN_ACK_7 * connAck, IA_USER * iaUser, user_iter * user, uint32_t sip)
+int AUTH_IA::Process_CONN_ACK_7(CONN_ACK_7 * connAck, IA_USER * iaUser, uint32_t sip)
{
-return Process_CONN_ACK_6(connAck, iaUser, user, sip);
+return Process_CONN_ACK_6(connAck, iaUser, sip);
}
//-----------------------------------------------------------------------------
-int AUTH_IA::Process_CONN_ACK_8(CONN_ACK_8 * connAck, IA_USER * iaUser, user_iter *, uint32_t sip)
+int AUTH_IA::Process_CONN_ACK_8(CONN_ACK_8 * connAck, IA_USER * iaUser, uint32_t sip)
{
#ifdef ARCH_BE
SwapBytes(connAck->len);
return -1;
}
//-----------------------------------------------------------------------------
-int AUTH_IA::Process_ALIVE_ACK_6(ALIVE_ACK_6 * aliveAck, IA_USER * iaUser, user_iter *, uint32_t)
+int AUTH_IA::Process_ALIVE_ACK_6(ALIVE_ACK_6 * aliveAck, IA_USER * iaUser, uint32_t)
{
#ifdef ARCH_BE
SwapBytes(aliveAck->len);
return 0;
}
//-----------------------------------------------------------------------------
-int AUTH_IA::Process_ALIVE_ACK_7(ALIVE_ACK_7 * aliveAck, IA_USER * iaUser, user_iter * user, uint32_t sip)
+int AUTH_IA::Process_ALIVE_ACK_7(ALIVE_ACK_7 * aliveAck, IA_USER * iaUser, uint32_t sip)
{
-return Process_ALIVE_ACK_6(aliveAck, iaUser, user, sip);
+return Process_ALIVE_ACK_6(aliveAck, iaUser, sip);
}
//-----------------------------------------------------------------------------
-int AUTH_IA::Process_ALIVE_ACK_8(ALIVE_ACK_8 * aliveAck, IA_USER * iaUser, user_iter *, uint32_t)
+int AUTH_IA::Process_ALIVE_ACK_8(ALIVE_ACK_8 * aliveAck, IA_USER * iaUser, uint32_t)
{
#ifdef ARCH_BE
SwapBytes(aliveAck->len);
return 0;
}
//-----------------------------------------------------------------------------
-int AUTH_IA::Process_DISCONN_SYN_6(DISCONN_SYN_6 *, IA_USER * iaUser, user_iter *, uint32_t)
+int AUTH_IA::Process_DISCONN_SYN_6(DISCONN_SYN_6 *, IA_USER * iaUser, uint32_t)
{
printfd(__FILE__, "DISCONN_SYN_6\n");
if (iaUser->phase.GetPhase() != 3)
return 0;
}
//-----------------------------------------------------------------------------
-int AUTH_IA::Process_DISCONN_SYN_7(DISCONN_SYN_7 * disconnSyn, IA_USER * iaUser, user_iter * user, uint32_t sip)
+int AUTH_IA::Process_DISCONN_SYN_7(DISCONN_SYN_7 * disconnSyn, IA_USER * iaUser, uint32_t sip)
{
-return Process_DISCONN_SYN_6(disconnSyn, iaUser, user, sip);
+return Process_DISCONN_SYN_6(disconnSyn, iaUser, sip);
}
//-----------------------------------------------------------------------------
-int AUTH_IA::Process_DISCONN_SYN_8(DISCONN_SYN_8 *, IA_USER * iaUser, user_iter *, uint32_t)
+int AUTH_IA::Process_DISCONN_SYN_8(DISCONN_SYN_8 *, IA_USER * iaUser, uint32_t)
{
if (iaUser->phase.GetPhase() != 3)
{
//-----------------------------------------------------------------------------
int AUTH_IA::Process_DISCONN_ACK_6(DISCONN_ACK_6 * disconnAck,
IA_USER * iaUser,
- user_iter *,
uint32_t,
map<uint32_t, IA_USER>::iterator)
{
return 0;
}
//-----------------------------------------------------------------------------
-int AUTH_IA::Process_DISCONN_ACK_7(DISCONN_ACK_7 * disconnAck, IA_USER * iaUser, user_iter * user, uint32_t sip, map<uint32_t, IA_USER>::iterator it)
+int AUTH_IA::Process_DISCONN_ACK_7(DISCONN_ACK_7 * disconnAck, IA_USER * iaUser, uint32_t sip, map<uint32_t, IA_USER>::iterator it)
{
-return Process_DISCONN_ACK_6(disconnAck, iaUser, user, sip, it);
+return Process_DISCONN_ACK_6(disconnAck, iaUser, sip, it);
}
//-----------------------------------------------------------------------------
-int AUTH_IA::Process_DISCONN_ACK_8(DISCONN_ACK_8 * disconnAck, IA_USER * iaUser, user_iter *, uint32_t, map<uint32_t, IA_USER>::iterator)
+int AUTH_IA::Process_DISCONN_ACK_8(DISCONN_ACK_8 * disconnAck, IA_USER * iaUser, uint32_t, map<uint32_t, IA_USER>::iterator)
{
#ifdef ARCH_BE
SwapBytes(disconnAck->len);
return 0;
}
//-----------------------------------------------------------------------------
-int AUTH_IA::Send_CONN_SYN_ACK_6(IA_USER * iaUser, user_iter *, uint32_t sip)
+int AUTH_IA::Send_CONN_SYN_ACK_6(IA_USER * iaUser, uint32_t sip)
{
//+++ Fill static data in connSynAck +++
// TODO Move this code. It must be executed only once
return Send(sip, iaSettings.GetUserPort(), (char*)&connSynAck6, Min8(sizeof(CONN_SYN_ACK_6)));;
}
//-----------------------------------------------------------------------------
-int AUTH_IA::Send_CONN_SYN_ACK_7(IA_USER * iaUser, user_iter * user, uint32_t sip)
+int AUTH_IA::Send_CONN_SYN_ACK_7(IA_USER * iaUser, uint32_t sip)
{
-return Send_CONN_SYN_ACK_6(iaUser, user, sip);
+return Send_CONN_SYN_ACK_6(iaUser, sip);
}
//-----------------------------------------------------------------------------
-int AUTH_IA::Send_CONN_SYN_ACK_8(IA_USER * iaUser, user_iter *, uint32_t sip)
+int AUTH_IA::Send_CONN_SYN_ACK_8(IA_USER * iaUser, uint32_t sip)
{
strcpy((char*)connSynAck8.hdr.magic, IA_ID);
connSynAck8.hdr.protoVer[0] = 0;
for (int i = 0; i < DIR_NUM; i++)
{
- aliveSyn6.md[i] = iaUser->user->property.down.Get()[i];
- aliveSyn6.mu[i] = iaUser->user->property.up.Get()[i];
+ aliveSyn6.md[i] = iaUser->user->GetProperty().down.Get()[i];
+ aliveSyn6.mu[i] = iaUser->user->GetProperty().up.Get()[i];
aliveSyn6.sd[i] = iaUser->user->GetSessionDownload()[i];
aliveSyn6.su[i] = iaUser->user->GetSessionUpload()[i];
}
else
{
- double fmb = iaUser->user->property.freeMb;
+ double fmb = iaUser->user->GetProperty().freeMb;
fmb = fmb < 0 ? 0 : fmb;
snprintf((char*)aliveSyn6.freeMb, IA_FREEMB_LEN, "%.3f", fmb / p);
}
}
else
{
- double fmb = iaUser->user->property.freeMb;
+ double fmb = iaUser->user->GetProperty().freeMb;
fmb = fmb < 0 ? 0 : fmb;
snprintf((char*)aliveSyn6.freeMb, IA_FREEMB_LEN, "C%.3f", fmb);
}
iaUser->aliveSent = true;
#endif
-aliveSyn6.cash =(int64_t) (iaUser->user->property.cash.Get() * 1000.0);
+aliveSyn6.cash =(int64_t) (iaUser->user->GetProperty().cash.Get() * 1000.0);
if (!stgSettings->GetShowFeeInCash())
aliveSyn6.cash -= (int64_t)(tf->GetFee() * 1000.0);
for (int i = 0; i < DIR_NUM; i++)
{
- aliveSyn8.md[i] = iaUser->user->property.down.Get()[i];
- aliveSyn8.mu[i] = iaUser->user->property.up.Get()[i];
+ aliveSyn8.md[i] = iaUser->user->GetProperty().down.Get()[i];
+ aliveSyn8.mu[i] = iaUser->user->GetProperty().up.Get()[i];
aliveSyn8.sd[i] = iaUser->user->GetSessionDownload()[i];
aliveSyn8.su[i] = iaUser->user->GetSessionUpload()[i];
}
else
{
- double fmb = iaUser->user->property.freeMb;
+ double fmb = iaUser->user->GetProperty().freeMb;
fmb = fmb < 0 ? 0 : fmb;
snprintf((char*)aliveSyn8.freeMb, IA_FREEMB_LEN, "%.3f", fmb / p);
}
}
else
{
- double fmb = iaUser->user->property.freeMb;
+ double fmb = iaUser->user->GetProperty().freeMb;
fmb = fmb < 0 ? 0 : fmb;
snprintf((char*)aliveSyn8.freeMb, IA_FREEMB_LEN, "C%.3f", fmb);
}
const TARIFF * tf = iaUser->user->GetTariff();
-aliveSyn8.cash =(int64_t) (iaUser->user->property.cash.Get() * 1000.0);
+aliveSyn8.cash =(int64_t) (iaUser->user->GetProperty().cash.Get() * 1000.0);
if (!stgSettings->GetShowFeeInCash())
aliveSyn8.cash -= (int64_t)(tf->GetFee() * 1000.0);
#include <ctime>
#include <string>
#include <map>
+#include <list>
#include <functional>
#include <utility>
#include "os_int.h"
-#include "base_auth.h"
-#include "base_store.h"
+#include "auth.h"
+#include "store.h"
#include "notifer.h"
#include "user_ips.h"
-#include "../../../user.h"
-#include "../../../users.h"
+#include "user.h"
+#include "users.h"
#include "ia_packets.h"
#include "blowfish.h"
#include "stg_logger.h"
#include "utime.h"
-using namespace std;
-
-extern "C" BASE_PLUGIN * GetPlugin();
+extern "C" PLUGIN * GetPlugin();
#define IA_PROTO_VER (6)
class AUTH_IA;
//-----------------------------------------------------------------------------
-enum FREEMB
-{
+enum FREEMB {
freeMb0 = 0,
freeMb1,
freeMb2,
freeMbNone = 101
};
//-----------------------------------------------------------------------------
-class IA_PHASE
-{
+class IA_PHASE {
public:
IA_PHASE();
~IA_PHASE();
const UTIME & GetTime() const;
#ifdef IA_PHASE_DEBUG
- void SetUserLogin(const string & login);
- void SetLogFileName(const string & logFileName);
+ void SetUserLogin(const std::string & login);
+ void SetLogFileName(const std::string & logFileName);
#endif
private:
#ifdef IA_PHASE_DEBUG
void WritePhaseChange(int newPhase);
- string log;
- string login;
+ std::string log;
+ std::string login;
FILE * flog;
#endif
};
//-----------------------------------------------------------------------------
-struct IA_USER
-{
+struct IA_USER {
IA_USER()
: lastSendAlive(0),
rnd(random()),
memcpy(&ctx, &u.ctx, sizeof(BLOWFISH_CTX));
};
- user_iter user;
- //int phase;
- //UTIME phaseTime;
+ USER_PTR user;
IA_PHASE phase;
UTIME lastSendAlive;
uint32_t rnd;
uint16_t port;
BLOWFISH_CTX ctx;
- list<STG_MSG> messagesToSend;
+ std::list<STG_MSG> messagesToSend;
int protoVer;
- string password;
+ std::string password;
#ifdef IA_DEBUG
bool aliveSent;
#endif
};
//-----------------------------------------------------------------------------
-class AUTH_IA_SETTINGS
-{
+class AUTH_IA_SETTINGS {
public:
AUTH_IA_SETTINGS();
virtual ~AUTH_IA_SETTINGS() {};
- const string& GetStrError() const { return errorStr; };
+ const std::string & GetStrError() const { return errorStr; };
int ParseSettings(const MODULE_SETTINGS & s);
int GetUserDelay() const { return userDelay; };
int GetUserTimeout() const { return userTimeout; };
FREEMB GetFreeMbShowType() const { return freeMbShowType; };
private:
- int ParseIntInRange(const string & str, int min, int max, int * val);
+ int ParseIntInRange(const std::string & str, int min, int max, int * val);
int userDelay;
int userTimeout;
uint16_t port;
- string errorStr;
+ std::string errorStr;
FREEMB freeMbShowType;
};
//-----------------------------------------------------------------------------
-class AUTH_IA :public BASE_AUTH
-{
+class AUTH_IA :public BASE_AUTH {
public:
AUTH_IA();
virtual ~AUTH_IA();
- void SetUsers(USERS * u) { users = u; };
- void SetTariffs(TARIFFS *) {};
- void SetAdmins(ADMINS *) {};
- void SetTraffcounter(TRAFFCOUNTER *) {};
- void SetStore(BASE_STORE *) {};
- void SetStgSettings(const SETTINGS * s) { stgSettings = s; };
- void SetSettings(const MODULE_SETTINGS & s) { settings = s; };
+ void SetUsers(USERS * u) { users = u; }
+ void SetTariffs(TARIFFS *) {}
+ void SetAdmins(ADMINS *) {}
+ void SetTraffcounter(TRAFFCOUNTER *) {}
+ void SetStore(STORE *) {}
+ void SetStgSettings(const SETTINGS * s) { stgSettings = s; }
+ void SetSettings(const MODULE_SETTINGS & s) { settings = s; }
int ParseSettings();
int Start();
int Stop();
- int Reload() { return 0; };
- bool IsRunning() { return isRunningRunTimeouter || isRunningRun; };
+ int Reload() { return 0; }
+ bool IsRunning() { return isRunningRunTimeouter || isRunningRun; }
- const string & GetStrError() const { return errorStr; };
- const string GetVersion() const { return "InetAccess authorization plugin v.1.4"; };
- uint16_t GetStartPosition() const { return 50; };
- uint16_t GetStopPosition() const { return 50; };
+ const std::string & GetStrError() const { return errorStr; }
+ const std::string GetVersion() const { return "InetAccess authorization plugin v.1.4"; }
+ uint16_t GetStartPosition() const { return 50; }
+ uint16_t GetStopPosition() const { return 50; }
int SendMessage(const STG_MSG & msg, uint32_t ip) const;
static void * RunTimeouter(void * d);
int PrepareNet();
int FinalizeNet();
- void DelUser(user_iter u);
+ void DelUser(USER_PTR u);
int RecvData(char * buffer, int bufferSize);
int CheckHeader(const char * buffer, int * protoVer);
- int PacketProcessor(char * buff, int dataLen, uint32_t sip, uint16_t sport, int protoVer, user_iter * user);
+ int PacketProcessor(char * buff, int dataLen, uint32_t sip, uint16_t sport, int protoVer, USER_PTR * user);
- int Process_CONN_SYN_6(CONN_SYN_6 * connSyn, IA_USER * iaUser, user_iter * user, uint32_t sip);
- int Process_CONN_SYN_7(CONN_SYN_7 * connSyn, IA_USER * iaUser, user_iter * user, uint32_t sip);
- int Process_CONN_SYN_8(CONN_SYN_8 * connSyn, IA_USER * iaUser, user_iter * user, uint32_t sip);
+ int Process_CONN_SYN_6(CONN_SYN_6 * connSyn, IA_USER * iaUser, uint32_t sip);
+ int Process_CONN_SYN_7(CONN_SYN_7 * connSyn, IA_USER * iaUser, uint32_t sip);
+ int Process_CONN_SYN_8(CONN_SYN_8 * connSyn, IA_USER * iaUser, uint32_t sip);
- int Process_CONN_ACK_6(CONN_ACK_6 * connAck, IA_USER * iaUser, user_iter * user, uint32_t sip);
- int Process_CONN_ACK_7(CONN_ACK_7 * connAck, IA_USER * iaUser, user_iter * user, uint32_t sip);
- int Process_CONN_ACK_8(CONN_ACK_8 * connAck, IA_USER * iaUser, user_iter * user, uint32_t sip);
+ int Process_CONN_ACK_6(CONN_ACK_6 * connAck, IA_USER * iaUser, uint32_t sip);
+ int Process_CONN_ACK_7(CONN_ACK_7 * connAck, IA_USER * iaUser, uint32_t sip);
+ int Process_CONN_ACK_8(CONN_ACK_8 * connAck, IA_USER * iaUser, uint32_t sip);
- int Process_ALIVE_ACK_6(ALIVE_ACK_6 * aliveAck, IA_USER * iaUser, user_iter * user, uint32_t sip);
- int Process_ALIVE_ACK_7(ALIVE_ACK_7 * aliveAck, IA_USER * iaUser, user_iter * user, uint32_t sip);
- int Process_ALIVE_ACK_8(ALIVE_ACK_8 * aliveAck, IA_USER * iaUser, user_iter * user, uint32_t sip);
+ int Process_ALIVE_ACK_6(ALIVE_ACK_6 * aliveAck, IA_USER * iaUser, uint32_t sip);
+ int Process_ALIVE_ACK_7(ALIVE_ACK_7 * aliveAck, IA_USER * iaUser, uint32_t sip);
+ int Process_ALIVE_ACK_8(ALIVE_ACK_8 * aliveAck, IA_USER * iaUser, uint32_t sip);
- int Process_DISCONN_SYN_6(DISCONN_SYN_6 * disconnSyn, IA_USER * iaUser, user_iter * user, uint32_t sip);
- int Process_DISCONN_SYN_7(DISCONN_SYN_7 * disconnSyn, IA_USER * iaUser, user_iter * user, uint32_t sip);
- int Process_DISCONN_SYN_8(DISCONN_SYN_8 * disconnSyn, IA_USER * iaUser, user_iter * user, uint32_t sip);
+ int Process_DISCONN_SYN_6(DISCONN_SYN_6 * disconnSyn, IA_USER * iaUser, uint32_t sip);
+ int Process_DISCONN_SYN_7(DISCONN_SYN_7 * disconnSyn, IA_USER * iaUser, uint32_t sip);
+ int Process_DISCONN_SYN_8(DISCONN_SYN_8 * disconnSyn, IA_USER * iaUser, uint32_t sip);
int Process_DISCONN_ACK_6(DISCONN_ACK_6 * disconnSyn,
IA_USER * iaUser,
- user_iter * user,
uint32_t sip,
map<uint32_t, IA_USER>::iterator it);
int Process_DISCONN_ACK_7(DISCONN_ACK_7 * disconnSyn,
IA_USER * iaUser,
- user_iter * user,
uint32_t sip,
map<uint32_t, IA_USER>::iterator it);
int Process_DISCONN_ACK_8(DISCONN_ACK_8 * disconnSyn,
IA_USER * iaUser,
- user_iter * user,
uint32_t sip,
map<uint32_t, IA_USER>::iterator it);
- int Send_CONN_SYN_ACK_6(IA_USER * iaUser, user_iter * user, uint32_t sip);
- int Send_CONN_SYN_ACK_7(IA_USER * iaUser, user_iter * user, uint32_t sip);
- int Send_CONN_SYN_ACK_8(IA_USER * iaUser, user_iter * user, uint32_t sip);
+ int Send_CONN_SYN_ACK_6(IA_USER * iaUser, uint32_t sip);
+ int Send_CONN_SYN_ACK_7(IA_USER * iaUser, uint32_t sip);
+ int Send_CONN_SYN_ACK_8(IA_USER * iaUser, uint32_t sip);
int Send_ALIVE_SYN_6(IA_USER * iaUser, uint32_t sip);
int Send_ALIVE_SYN_7(IA_USER * iaUser, uint32_t sip);
int Timeouter();
- int SendError(uint32_t ip, uint16_t port, int protoVer, const string & text);
+ int SendError(uint32_t ip, uint16_t port, int protoVer, const std::string & text);
int Send(uint32_t ip, uint16_t port, const char * buffer, int len);
int RealSendMessage6(const STG_MSG & msg, uint32_t ip, IA_USER & user);
int RealSendMessage7(const STG_MSG & msg, uint32_t ip, IA_USER & user);
BLOWFISH_CTX ctxS; //for loginS
- mutable string errorStr;
+ mutable std::string errorStr;
AUTH_IA_SETTINGS iaSettings;
MODULE_SETTINGS settings;
USERS * users;
const SETTINGS * stgSettings;
- mutable map<uint32_t, IA_USER> ip2user;
+ mutable std::map<uint32_t, IA_USER> ip2user;
pthread_t recvThread;
pthread_t timeouterThread;
FIN_6 fin6;
FIN_8 fin8;
- map<string, int> packetTypes;
+ std::map<std::string, int> packetTypes;
STG_LOGGER & WriteServLog;
uint32_t enabledDirs;
- class DEL_USER_NONIFIER: public NOTIFIER_BASE<user_iter>
- {
+ class DEL_USER_NONIFIER: public NOTIFIER_BASE<USER_PTR> {
public:
- DEL_USER_NONIFIER(AUTH_IA & a) : auth(a) {};
- virtual ~DEL_USER_NONIFIER(){};
+ DEL_USER_NONIFIER(AUTH_IA & a) : auth(a) {}
+ virtual ~DEL_USER_NONIFIER() {}
- void Notify(const user_iter & user)
+ void Notify(const USER_PTR & user)
{
auth.DelUser(user);
}
class UnauthorizeUser : std::unary_function<const std::pair<uint32_t, IA_USER> &, void> {
public:
- UnauthorizeUser(AUTH_IA * a) : auth(a) {};
+ UnauthorizeUser(AUTH_IA * a) : auth(a) {}
void operator()(const std::pair<uint32_t, IA_USER> & p)
{
p.second.user->Unauthorize(auth);
//-----------------------------------------------------------------------------
#endif
-
-
#ifndef STRESS_H
#define STRESS_H
-#include <string>
#include <pthread.h>
-#include "base_auth.h"
+
+#include <string>
+#include <list>
+
+#include "auth.h"
#include "notifer.h"
#include "user_ips.h"
-#include "../../../users.h"
+#include "users.h"
-using namespace std;
-
-extern "C" BASE_PLUGIN * GetPlugin();
+extern "C" PLUGIN * GetPlugin();
class AUTH_STRESS;
//-----------------------------------------------------------------------------
template <typename varParamType>
-class CHG_BEFORE_NOTIFIER: public PROPERTY_NOTIFIER_BASE<varParamType>
-{
+class CHG_BEFORE_NOTIFIER: public PROPERTY_NOTIFIER_BASE<varParamType> {
public:
void Notify(const varParamType & oldValue, const varParamType & newValue);
void SetUser(user_iter u) { user = u; }
};
//-----------------------------------------------------------------------------
template <typename varParamType>
-class CHG_AFTER_NOTIFIER: public PROPERTY_NOTIFIER_BASE<varParamType>
-{
+class CHG_AFTER_NOTIFIER: public PROPERTY_NOTIFIER_BASE<varParamType> {
public:
void Notify(const varParamType & oldValue, const varParamType & newValue);
void SetUser(user_iter u) { user = u; }
const AUTH_STRESS * auth;
};
//-----------------------------------------------------------------------------
-class AUTH_STRESS_SETTINGS
-{
+class AUTH_STRESS_SETTINGS {
public:
AUTH_STRESS_SETTINGS();
- const string& GetStrError() const { return errorStr; }
+ const std::string & GetStrError() const { return errorStr; }
int ParseSettings(const MODULE_SETTINGS & s);
int GetAverageOnlineTime() const;
private:
- int ParseIntInRange(const string & str, int min, int max, int * val);
+ int ParseIntInRange(const std::string & str, int min, int max, int * val);
int averageOnlineTime;
- string errorStr;
+ std::string errorStr;
};
//-----------------------------------------------------------------------------
-class AUTH_STRESS :public BASE_AUTH
-{
+class AUTH_STRESS :public AUTH {
public:
AUTH_STRESS();
- virtual ~AUTH_STRESS(){};
+ virtual ~AUTH_STRESS() {}
void SetUsers(USERS * u);
- void SetTariffs(TARIFFS * t){};
- void SetAdmins(ADMINS * a){};
- void SetTraffcounter(TRAFFCOUNTER * tc){};
- void SetStore(BASE_STORE * ){};
- void SetStgSettings(const SETTINGS *){};
+ void SetTariffs(TARIFFS * t) {}
+ void SetAdmins(ADMINS * a) {}
+ void SetTraffcounter(TRAFFCOUNTER * tc) {}
+ void SetStore(STORE * ) {}
+ void SetStgSettings(const SETTINGS *) {}
int Start();
int Stop();
bool IsRunning();
void SetSettings(const MODULE_SETTINGS & s);
int ParseSettings();
- const string & GetStrError() const;
- const string GetVersion() const;
+ const std::string & GetStrError() const;
+ const std::string GetVersion() const;
uint16_t GetStartPosition() const;
uint16_t GetStopPosition() const;
static void * Run(void *);
- mutable string errorStr;
+ mutable std::string errorStr;
AUTH_STRESS_SETTINGS stressSettings;
USERS * users;
- list<user_iter> usersList;
+ std::list<user_iter> usersList;
bool isRunning;
MODULE_SETTINGS settings;
pthread_t thread;
pthread_mutex_t mutex;
- list<CHG_BEFORE_NOTIFIER<USER_IPS> > BeforeChgIPNotifierList;
- list<CHG_AFTER_NOTIFIER<USER_IPS> > AfterChgIPNotifierList;
+ std::list<CHG_BEFORE_NOTIFIER<USER_IPS> > BeforeChgIPNotifierList;
+ std::list<CHG_AFTER_NOTIFIER<USER_IPS> > AfterChgIPNotifierList;
- class ADD_USER_NONIFIER: public NOTIFIER_BASE<user_iter>
- {
+ class ADD_USER_NONIFIER: public NOTIFIER_BASE<user_iter> {
public:
- ADD_USER_NONIFIER(){};
- virtual ~ADD_USER_NONIFIER(){};
+ ADD_USER_NONIFIER() {}
+ virtual ~ADD_USER_NONIFIER() {}
void SetAuthorizator(AUTH_STRESS * a) { auth = a; }
void Notify(const user_iter & user)
AUTH_STRESS * auth;
} onAddUserNotifier;
- class DEL_USER_NONIFIER: public NOTIFIER_BASE<user_iter>
- {
+ class DEL_USER_NONIFIER: public NOTIFIER_BASE<user_iter> {
public:
- DEL_USER_NONIFIER(){};
- virtual ~DEL_USER_NONIFIER(){};
+ DEL_USER_NONIFIER() {}
+ virtual ~DEL_USER_NONIFIER() {}
void SetAuthorizator(AUTH_STRESS * a) { auth = a; }
void Notify(const user_iter & user)
//-----------------------------------------------------------------------------
#endif
-
-
$Author: faust $
*/
-#include <string>
#include <pthread.h>
+#include <string>
+
#include "os_int.h"
-#include "base_plugin.h"
-#include "base_settings.h"
+#include "plugin.h"
+#include "module_settings.h"
using namespace std;
-extern "C" BASE_PLUGIN * GetPlugin();
+extern "C" PLUGIN * GetPlugin();
//-----------------------------------------------------------------------------
-struct iphdr_eth
-{
+struct iphdr_eth {
uint8_t ihl:4,
version:4;
uint8_t tos;
char iface[10];
};
//-----------------------------------------------------------------------------
-class CAP_SETTINGS//: public BASE_SETTINGS
-{
+class CAP_SETTINGS {
public:
- const string& GetStrError() const { static string s; return s; }
- int ParseSettings(const MODULE_SETTINGS & s) { return 0; };
+ const string & GetStrError() const { static string s; return s; }
+ int ParseSettings(const MODULE_SETTINGS & s) { return 0; }
};
//-----------------------------------------------------------------------------
-class DEBUG_CAP :public BASE_PLUGIN
+class DEBUG_CAP :public PLUGIN
{
public:
DEBUG_CAP();
- virtual ~DEBUG_CAP(){};
+ virtual ~DEBUG_CAP() {}
- void SetUsers(USERS * u){};
- void SetTariffs(TARIFFS * t){};
- void SetAdmins(ADMINS * a){};
+ void SetUsers(USERS * u) {}
+ void SetTariffs(TARIFFS * t) {}
+ void SetAdmins(ADMINS * a) {}
void SetTraffcounter(TRAFFCOUNTER * tc);
- void SetStore(BASE_STORE *){};
- void SetStgSettings(const SETTINGS *){};
+ void SetStore(STORE *) {}
+ void SetStgSettings(const SETTINGS *) {}
int Start();
int Stop();
- int Reload() { return 0; };
- int ParseSettings() { return 0; };
- void SetSettings(const MODULE_SETTINGS & s){};
+ int Reload() { return 0; }
+ int ParseSettings() { return 0; }
+ void SetSettings(const MODULE_SETTINGS & s) {}
bool IsRunning();
const string & GetStrError() const;
const string GetVersion() const;
TRAFFCOUNTER * traffCnt;
};
//-----------------------------------------------------------------------------
-
NF_CAP * nf;
} cnc;
-BASE_PLUGIN * GetPlugin()
+PLUGIN * GetPlugin()
{
return cnc.GetCapturer();
}
#ifndef __CAP_NF_H__
#define __CAP_NF_H__
-#include <string>
#include <pthread.h>
+#include <string>
+
#include "os_int.h"
-#include "base_plugin.h"
+#include "plugin.h"
+#include "module_settings.h"
#define VERSION "CAP_NF v. 0.4"
#define START_POS 0
#define STOP_POS 0
-struct NF_HEADER
-{
+class USERS;
+class USER;
+class TARIFFS;
+class ADMINS;
+class TRAFFCOUNTER;
+class STORE;
+class SETTINGS;
+
+struct NF_HEADER {
uint16_t version; // Protocol version
uint16_t count; // Flows count
uint32_t uptime; // System uptime
uint16_t sInterval; // Sampling mode and interval
} __attribute__ ((packed));
-struct NF_DATA
-{
+struct NF_DATA {
uint32_t srcAddr; // Flow source address
uint32_t dstAddr; // Flow destination address
uint32_t nextHop; // IP addres on next hop router
#define BUF_SIZE (sizeof(NF_HEADER) + 30 * sizeof(NF_DATA))
-class NF_CAP : public BASE_PLUGIN
-{
+class NF_CAP : public PLUGIN {
public:
NF_CAP();
~NF_CAP();
- void SetUsers(USERS *) {};
- void SetTariffs(TARIFFS *) {};
- void SetAdmins(ADMINS *) {};
- void SetTraffcounter(TRAFFCOUNTER * tc) { traffCnt = tc; };
- void SetStore(BASE_STORE *) {};
- void SetStgSettings(const SETTINGS *) {};
- void SetSettings(const MODULE_SETTINGS & s) { settings = s; };
+ void SetUsers(USERS *) {}
+ void SetTariffs(TARIFFS *) {}
+ void SetAdmins(ADMINS *) {}
+ void SetTraffcounter(TRAFFCOUNTER * tc) { traffCnt = tc; }
+ void SetStore(STORE *) {}
+ void SetStgSettings(const SETTINGS *) {}
+ void SetSettings(const MODULE_SETTINGS & s) { settings = s; }
int ParseSettings();
int Start();
int Stop();
- int Reload() { return 0; };
- bool IsRunning() { return runningTCP || runningUDP; };
- const string & GetStrError() const { return errorStr; };
- const string GetVersion() const { return VERSION; };
- uint16_t GetStartPosition() const { return START_POS; };
- uint16_t GetStopPosition() const { return STOP_POS; };
+ int Reload() { return 0; }
+ bool IsRunning() { return runningTCP || runningUDP; }
+ const string & GetStrError() const { return errorStr; }
+ const string GetVersion() const { return VERSION; }
+ uint16_t GetStartPosition() const { return START_POS; }
+ uint16_t GetStopPosition() const { return STOP_POS; }
private:
TRAFFCOUNTER * traffCnt;
bool OpenTCP();
bool OpenUDP();
- void CloseTCP() { close(sockTCP); };
- void CloseUDP() { close(sockUDP); };
+ void CloseTCP() { close(sockTCP); }
+ void CloseUDP() { close(sockUDP); }
bool WaitPackets(int sd) const;
};
-extern "C" BASE_PLUGIN * GetPlugin();
+extern "C" PLUGIN * GetPlugin();
#endif
#define BUFF_LEN (16384) /* max mtu -> lo=16436 TODO why?*/
//-----------------------------------------------------------------------------
-struct DIVERT_DATA
-{
+struct DIVERT_DATA {
int sock;
short int port;
unsigned char buffer[BUFF_LEN];
pollfd pollddiv;
DIVERT_DATA cddiv; //capture data
//-----------------------------------------------------------------------------
-class DIVERT_CAP_CREATOR
-{
+class DIVERT_CAP_CREATOR {
private:
DIVERT_CAP * divc;
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
-BASE_PLUGIN * GetPlugin()
+PLUGIN * GetPlugin()
{
return dcc.GetCapturer();
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
-const string DIVERT_CAP::GetVersion() const
+const std::string DIVERT_CAP::GetVersion() const
{
return "Divert_cap v.1.0";
}
traffCnt = tc;
}
//-----------------------------------------------------------------------------
-const string & DIVERT_CAP::GetStrError() const
+const std::string & DIVERT_CAP::GetStrError() const
{
return errorStr;
}
return 0;
}
//-----------------------------------------------------------------------------
-int DIVERT_CAP::ParseIntInRange(const string & str, int min, int max, int * val)
+int DIVERT_CAP::ParseIntInRange(const std::string & str, int min, int max, int * val)
{
if (str2x(str.c_str(), *val))
{
#ifndef DIVERT_CAP_H
#define DIVERT_CAP_H
-#include <string>
#include <pthread.h>
-#include "base_plugin.h"
-#include "base_settings.h"
+#include <string>
+
+#include "plugin.h"
+#include "module_settings.h"
#include "../../../traffcounter.h"
-using namespace std;
+class USERS;
+class TARIFFS;
+class ADMINS;
+class TRAFFCOUNTER;
+class SETTINGS;
-extern "C" BASE_PLUGIN * GetPlugin();
+extern "C" PLUGIN * GetPlugin();
//-----------------------------------------------------------------------------
-class DIVERT_CAP :public BASE_PLUGIN
-{
+class DIVERT_CAP : public PLUGIN {
public:
DIVERT_CAP();
- virtual ~DIVERT_CAP(){};
+ virtual ~DIVERT_CAP() {}
- void SetUsers(USERS *){};
- void SetTariffs(TARIFFS *){};
- void SetAdmins(ADMINS *){};
+ void SetUsers(USERS *) {}
+ void SetTariffs(TARIFFS *) {}
+ void SetAdmins(ADMINS *) {}
void SetTraffcounter(TRAFFCOUNTER * tc);
- void SetStore(BASE_STORE *){};
- void SetStgSettings(const SETTINGS *){};
+ void SetStore(STORE *) {}
+ void SetStgSettings(const SETTINGS *) {}
int Start();
int Stop();
- int Reload() { return 0; };
+ int Reload() { return 0; }
bool IsRunning();
void SetSettings(const MODULE_SETTINGS & s);
int ParseSettings();
- const string & GetStrError() const;
- const string GetVersion() const;
+ const std::string & GetStrError() const;
+ const std::string GetVersion() const;
uint16_t GetStartPosition() const;
uint16_t GetStopPosition() const;
int DivertCapRead(char * buffer, int blen, char ** iface, int n);
int DivertCapClose();
- int ParseIntInRange(const string & str, int min, int max, int * val);
+ int ParseIntInRange(const std::string & str, int min, int max, int * val);
MODULE_SETTINGS settings;
int port;
- mutable string errorStr;
+ mutable std::string errorStr;
pthread_t thread;
bool nonstop;
bool isRunning;
- //int capSock;
-
TRAFFCOUNTER * traffCnt;
};
//-----------------------------------------------------------------------------
-
#endif
#include <signal.h>
#include <unistd.h>
-#include <string>
-#include <vector>
-
#include "ether_cap.h"
#include "common.h"
#include "raw_ip_packet.h"
-using namespace std;
-
//#define CAP_DEBUG 1
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
-class BPF_CAP_CREATOR
-{
+class BPF_CAP_CREATOR {
private:
BPF_CAP * bpfc;
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
-BASE_PLUGIN * GetPlugin()
+PLUGIN * GetPlugin()
{
return bcc.GetCapturer();
}
{
//char sep[]= ", \t\n\r";
//char *s;
-string ifaces;
+std::string ifaces;
//char * str;
//char *p;
return 0;
}
//-----------------------------------------------------------------------------
-string BPF_CAP_SETTINGS::GetIface(unsigned int num)
+std::string BPF_CAP_SETTINGS::GetIface(unsigned int num)
{
if (num >= iface.size())
{
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
-const string BPF_CAP::GetVersion() const
+const std::string BPF_CAP::GetVersion() const
{
return "bpf_cap v.1.0";
}
traffCnt = tc;
}
//-----------------------------------------------------------------------------
-const string & BPF_CAP::GetStrError() const
+const std::string & BPF_CAP::GetStrError() const
{
return errorStr;
}
//if (ioctl(cd[n].fd, BIOCSBLEN, (caddr_t)&l) < 0)
if (ioctl(bd->fd, BIOCSBLEN, (caddr_t)&l) < 0)
{
- errorStr = bd->iface + " BIOCSBLEN " + string(strerror(errno));
+ errorStr = bd->iface + " BIOCSBLEN " + std::string(strerror(errno));
printfd(__FILE__, "ioctl failed: '%s'\n", errorStr.c_str());
return -1;
}
//if (ioctl(cd[n].fd, BIOCSETIF, (caddr_t)&ifr) < 0 )
if (ioctl(bd->fd, BIOCSETIF, (caddr_t)&ifr) < 0)
{
- errorStr = bd->iface + " BIOCSETIF " + string(strerror(errno));
+ errorStr = bd->iface + " BIOCSETIF " + std::string(strerror(errno));
printfd(__FILE__, "ioctl failed: '%s'\n", errorStr.c_str());
return -1;
}
//if (ioctl(cd[n].fd, BIOCIMMEDIATE, &im) < 0 )
if (ioctl(bd->fd, BIOCIMMEDIATE, &im) < 0)
{
- errorStr = bd->iface + " BIOCIMMEDIATE " + string(strerror(errno));
+ errorStr = bd->iface + " BIOCIMMEDIATE " + std::string(strerror(errno));
printfd(__FILE__, "ioctl failed: '%s'\n", errorStr.c_str());
return -1;
}
#ifndef ETHER_CAP_H
#define ETHER_CAP_H
+#include <pthread.h>
+
#include <string>
#include <vector>
-#include <pthread.h>
#ifdef FREE_BSD5
#include <inttypes.h>
#include <sys/inttypes.h>
#endif
-#include "base_plugin.h"
-#include "base_settings.h"
+#include "plugin.h"
+#include "module_settings.h"
#include "../../../traffcounter.h"
-using namespace std;
+extern "C" PLUGIN * GetPlugin();
-extern "C" BASE_PLUGIN * GetPlugin();
-
-#define BUFF_LEN (128)
+#define BUFF_LEN (128)
//-----------------------------------------------------------------------------
-struct BPF_DATA
-{
+struct BPF_DATA {
BPF_DATA()
{
fd = 0;
bh = NULL;
canRead = 1;
iface = "";
- //memset(&polld, 0, sizeof(pollfd));
};
BPF_DATA(const BPF_DATA & bd)
bh = bd.bh;
canRead = bd.canRead;
iface = bd.iface;
- //memcpy(&polld, &bd.polld, sizeof(pollfd));
};
int fd;
uint8_t buffer[BUFF_LEN];
struct bpf_hdr * bh;
int canRead;
-string iface;
-//pollfd polld;
+std::string iface;
};
//-----------------------------------------------------------------------------
-class BPF_CAP_SETTINGS
-{
+class BPF_CAP_SETTINGS {
public:
- virtual ~BPF_CAP_SETTINGS(){};
- const string& GetStrError() const { return errorStr; }
+ virtual ~BPF_CAP_SETTINGS() {}
+ const std::string & GetStrError() const { return errorStr; }
int ParseSettings(const MODULE_SETTINGS & s);
- string GetIface(unsigned int num);
+ std::string GetIface(unsigned int num);
private:
- vector<string> iface;
- mutable string errorStr;
+ std::vector<std::string> iface;
+ mutable std::string errorStr;
};
//-----------------------------------------------------------------------------
-class BPF_CAP :public BASE_PLUGIN
-{
+class BPF_CAP : public PLUGIN {
public:
BPF_CAP();
- virtual ~BPF_CAP(){};
+ virtual ~BPF_CAP() {}
- void SetUsers(USERS *){};
- void SetTariffs(TARIFFS *){};
- void SetAdmins(ADMINS *){};
+ void SetUsers(USERS *) {}
+ void SetTariffs(TARIFFS *) {}
+ void SetAdmins(ADMINS *) {}
void SetTraffcounter(TRAFFCOUNTER * tc);
- void SetStore(BASE_STORE *){};
- void SetStgSettings(const SETTINGS *){};
+ void SetStore(STORE *) {}
+ void SetStgSettings(const SETTINGS *) {}
int Start();
int Stop();
- int Reload() { return 0; };
+ int Reload() { return 0; }
bool IsRunning();
void SetSettings(const MODULE_SETTINGS & s);
int ParseSettings();
- const string & GetStrError() const;
- const string GetVersion() const;
+ const std::string & GetStrError() const;
+ const std::string GetVersion() const;
uint16_t GetStartPosition() const;
uint16_t GetStopPosition() const;
private:
static void * Run(void *);
int BPFCapOpen();
- //int BPFCapOpen(int n);
int BPFCapOpen(BPF_DATA * bd);
int BPFCapClose();
int BPFCapRead(char * buffer, int blen, char ** iface);
int BPFCapRead(char * buffer, int blen, char ** iface, BPF_DATA * bd);
- BPF_CAP_SETTINGS capSettings;
+ BPF_CAP_SETTINGS capSettings;
- mutable string errorStr;
+ mutable std::string errorStr;
- vector<BPF_DATA> bpfData;
- vector<pollfd> polld;
+ std::vector<BPF_DATA> bpfData;
+ std::vector<pollfd> polld;
- pthread_t thread;
- bool nonstop;
- bool isRunning;
- int capSock;
- MODULE_SETTINGS settings;
+ pthread_t thread;
+ bool nonstop;
+ bool isRunning;
+ int capSock;
+ MODULE_SETTINGS settings;
- TRAFFCOUNTER * traffCnt;
+ TRAFFCOUNTER * traffCnt;
};
//-----------------------------------------------------------------------------
-#endif //ETHER_CAP_H
-
+#endif
//#define CAP_DEBUG 1
-
//-----------------------------------------------------------------------------
class ETHER_CAP_CREATOR
{
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
-BASE_PLUGIN * GetPlugin()
+PLUGIN * GetPlugin()
{
return ecc.GetCapturer();
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
-const string ETHER_CAP::GetVersion() const
+const std::string ETHER_CAP::GetVersion() const
{
return "Ether_cap v.1.2";
}
traffCnt = tc;
}
//-----------------------------------------------------------------------------
-const string & ETHER_CAP::GetStrError() const
+const std::string & ETHER_CAP::GetStrError() const
{
return errorStr;
}
#include <string>
-#include "base_plugin.h"
-#include "base_settings.h"
+#include "plugin.h"
+#include "module_settings.h"
#include "../../../traffcounter.h"
-using namespace std;
+class USERS;
+class TARIFFS;
+class ADMINS;
+class TRAFFCOUNTER;
+class SETTINGS;
-extern "C" BASE_PLUGIN * GetPlugin();
+extern "C" PLUGIN * GetPlugin();
//-----------------------------------------------------------------------------
-class ETHER_CAP :public BASE_PLUGIN
-{
+class ETHER_CAP :public PLUGIN {
public:
ETHER_CAP();
- virtual ~ETHER_CAP(){};
+ virtual ~ETHER_CAP() {}
- void SetUsers(USERS *){};
- void SetTariffs(TARIFFS *){};
- void SetAdmins(ADMINS *){};
+ void SetUsers(USERS *) {}
+ void SetTariffs(TARIFFS *) {}
+ void SetAdmins(ADMINS *) {}
void SetTraffcounter(TRAFFCOUNTER * tc);
- void SetStore(BASE_STORE *){};
- void SetStgSettings(const SETTINGS *){};
+ void SetStore(STORE *) {}
+ void SetStgSettings(const SETTINGS *) {}
int Start();
int Stop();
- int Reload() { return 0; };
+ int Reload() { return 0; }
bool IsRunning();
- void SetSettings(const MODULE_SETTINGS &){};
- int ParseSettings(){ return 0; };
- const string & GetStrError() const;
- const string GetVersion() const;
+ void SetSettings(const MODULE_SETTINGS &) {}
+ int ParseSettings() { return 0; }
+ const std::string & GetStrError() const;
+ const std::string GetVersion() const;
uint16_t GetStartPosition() const;
uint16_t GetStopPosition() const;
int EthCapRead(void * buffer, int blen, char ** iface);
bool WaitPackets(int sd) const;
- mutable string errorStr;
+ mutable std::string errorStr;
pthread_t thread;
bool nonstop;
};
//-----------------------------------------------------------------------------
-#endif //ETHER_CAP_H
-
+#endif
#include "raw_ip_packet.h"
extern "C"
- {
- #include "libipq.h"
- }
-
-class IPQ_CAP_CREATOR
{
+#include "libipq.h"
+}
+
+class IPQ_CAP_CREATOR {
private:
IPQ_CAP * ic;
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
-BASE_PLUGIN * GetPlugin()
+PLUGIN * GetPlugin()
{
return icc.GetCapturer();
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
-const string IPQ_CAP::GetVersion() const
+const std::string IPQ_CAP::GetVersion() const
{
return "ipq_cap v.1.2";
}
traffCnt = tc;
}
//-----------------------------------------------------------------------------
-const string & IPQ_CAP::GetStrError() const
+const std::string & IPQ_CAP::GetStrError() const
{
return errorStr;
}
+#ifndef IPQ_CAP_H
+#define IPQ_CAP_H
+
#include <string>
-#include "base_plugin.h"
-#include "base_settings.h"
+#include "plugin.h"
+#include "module_settings.h"
#include "../../../traffcounter.h"
#define BUFSIZE (256)
#define PAYLOAD_LEN (96)
-using namespace std;
+class USERS;
+class TARIFFS;
+class ADMINS;
+class TRAFFCOUNTER;
+class SETTINGS;
-extern "C" BASE_PLUGIN * GetPlugin();
+extern "C" PLUGIN * GetPlugin();
//-----------------------------------------------------------------------------
-class IPQ_CAP :public BASE_PLUGIN
-{
+class IPQ_CAP :public PLUGIN {
public:
IPQ_CAP();
- virtual ~IPQ_CAP(){};
+ virtual ~IPQ_CAP() {}
- void SetUsers(USERS *){};
- void SetTariffs(TARIFFS *){};
- void SetAdmins(ADMINS *){};
+ void SetUsers(USERS *) {}
+ void SetTariffs(TARIFFS *) {}
+ void SetAdmins(ADMINS *) {}
void SetTraffcounter(TRAFFCOUNTER * tc);
- void SetStore(BASE_STORE *){};
- void SetStgSettings(const SETTINGS *){};
+ void SetStore(STORE *) {}
+ void SetStgSettings(const SETTINGS *) {}
int Start();
int Stop();
- int Reload() { return 0; };
+ int Reload() { return 0; }
bool IsRunning();
- void SetSettings(const MODULE_SETTINGS &){};
- int ParseSettings(){ return 0; };
+ void SetSettings(const MODULE_SETTINGS &) {}
+ int ParseSettings() { return 0; }
const string & GetStrError() const;
const string GetVersion() const;
uint16_t GetStartPosition() const;
int IPQCapClose();
int IPQCapRead(void * buffer, int blen);
- struct ipq_handle *ipq_h;
+ struct ipq_handle * ipq_h;
mutable string errorStr;
pthread_t thread;
TRAFFCOUNTER * traffCnt;
unsigned char buf[BUFSIZE];
};
+
+#endif
#include "rpcconfig.h"
-#include "../../../admin.h"
-#include "../../../admins.h"
-#include "../../../users.h"
-#include "../../../tariffs.h"
-#include "../../../traffcounter.h"
-#include "../../../settings.h"
-#include "base_store.h"
-#include "base_settings.h"
+#include "admin.h"
+#include "module_settings.h"
#include "info_methods.h"
#include "users_methods.h"
#include "admins_methods.h"
#include "messages_methods.h"
-class RPC_CONFIG_CREATOR
-{
+class RPC_CONFIG_CREATOR {
private:
RPC_CONFIG * rpcconfig;
RPC_CONFIG_CREATOR()
: rpcconfig(new RPC_CONFIG())
{
- };
+ }
~RPC_CONFIG_CREATOR()
{
delete rpcconfig;
- };
+ }
RPC_CONFIG * GetPlugin()
{
return rpcconfig;
- };
+ }
};
RPC_CONFIG_CREATOR rpcc;
#include <xmlrpc-c/server_abyss.hpp>
#include "os_int.h"
-#include "base_plugin.h"
+#include "plugin.h"
#include "admin_conf.h"
#define RPC_CONFIG_VERSION "Stargazer RPC v. 0.2"
-extern "C" BASE_PLUGIN * GetPlugin();
+extern "C" PLUGIN * GetPlugin();
class ADMINS;
class TARIFFS;
class USERS;
-class BASE_STORE;
+class STORE;
class RPC_CONFIG_SETTINGS
{
PRIV priviledges;
};
-class RPC_CONFIG :public BASE_PLUGIN
+class RPC_CONFIG :public PLUGIN
{
public:
RPC_CONFIG();
void SetUsers(USERS * u) { users = u; }
void SetTariffs(TARIFFS * t) { tariffs = t; }
void SetAdmins(ADMINS * a) { admins = a; }
- void SetStore(BASE_STORE * s) { store = s; }
+ void SetStore(STORE * s) { store = s; }
void SetTraffcounter(TRAFFCOUNTER *) {}
void SetStgSettings(const SETTINGS * s) { stgSettings = s; }
void SetSettings(const MODULE_SETTINGS & s) { settings = s; }
USERS * users;
ADMINS * admins;
TARIFFS * tariffs;
- BASE_STORE * store;
+ STORE * store;
MODULE_SETTINGS settings;
const SETTINGS * stgSettings;
xmlrpc_c::registry rpcRegistry;
#include "user_helper.h"
-#include "../../../tariffs.h"
-#include "../../../admin.h"
-#include "base_store.h"
+#include "tariffs.h"
+#include "admin.h"
+#include "store.h"
#include "user_ips.h"
#include "utils.h"
#include "common.h"
bool USER_HELPER::SetUserInfo(const xmlrpc_c::value & info,
const ADMIN & admin,
const std::string & login,
- const BASE_STORE & store,
+ const STORE & store,
TARIFFS * tariffs)
{
std::map<std::string, xmlrpc_c::value> structVal(
#include <xmlrpc-c/base.hpp>
-#include "../../../users.h"
+#include "users.h"
class ADMIN;
-class BASE_STORE;
+class STORE;
class TARIFFS;
class USER_HELPER
bool SetUserInfo(const xmlrpc_c::value & info,
const ADMIN & admin,
const std::string & login,
- const BASE_STORE & store,
+ const STORE & store,
TARIFFS * tariffs);
private:
user_iter & iter;
#include <xmlrpc-c/base.hpp>
#include <xmlrpc-c/registry.hpp>
-
class RPC_CONFIG;
class ADMINS;
class TARIFFS;
class USERS;
-class BASE_STORE;
+class STORE;
class IP_MASK;
class METHOD_USER_GET : public xmlrpc_c::method {
METHOD_USER_CHG(RPC_CONFIG * c,
ADMINS * a,
TARIFFS * t,
- BASE_STORE * s,
+ STORE * s,
USERS * u)
: config(c),
admins(a),
RPC_CONFIG * config;
ADMINS * admins;
TARIFFS * tariffs;
- BASE_STORE * store;
+ STORE * store;
USERS * users;
};
public:
METHOD_USER_CASH_ADD(RPC_CONFIG * c,
ADMINS * a,
- BASE_STORE * s,
+ STORE * s,
USERS * u)
: config(c),
admins(a),
private:
RPC_CONFIG * config;
ADMINS * admins;
- BASE_STORE * store;
+ STORE * store;
USERS * users;
};
public:
METHOD_USER_CASH_SET(RPC_CONFIG * c,
ADMINS * a,
- BASE_STORE * s,
+ STORE * s,
USERS * u)
: config(c),
admins(a),
private:
RPC_CONFIG * config;
ADMINS * admins;
- BASE_STORE * store;
+ STORE * store;
USERS * users;
};
METHOD_USER_TARIFF_CHANGE(RPC_CONFIG * c,
ADMINS * a,
TARIFFS * t,
- BASE_STORE * s,
+ STORE * s,
USERS * u)
: config(c),
admins(a),
RPC_CONFIG * config;
ADMINS * admins;
TARIFFS * tariffs;
- BASE_STORE * store;
+ STORE * store;
USERS * users;
};
#include <boost/thread.hpp>
-#include "base_store.h"
-#include "base_settings.h"
+#include "store.h"
+#include "module_settings.h"
#include "common.h"
+#include "users.h"
+#include "tariffs.h"
+#include "admins.h"
// TODO: Fix this shit!!!
-#include "../../../users.h"
-#include "../../../tariffs.h"
-#include "../../../admins.h"
#include "../../../settings.h"
#include "stgconfig.h"
#include <string>
-#include "base_plugin.h"
+#include "plugin.h"
#include "os_int.h"
#include "main_thread.h"
class USERS;
class TARIFFS;
class ADMINS;
-class BASE_STORE;
+class STORE;
class TRAFFCOUNTER;
class SETTINGS;
-class STGCONFIG2 : public BASE_PLUGIN
-{
+class STGCONFIG2 : public PLUGIN {
public:
STGCONFIG2();
virtual ~STGCONFIG2();
- void SetUsers(USERS * u) { users = u; };
- void SetTariffs(TARIFFS * t) { tariffs = t; };
- void SetAdmins(ADMINS * a) { admins = a; };
- void SetStore(BASE_STORE * s) { store = s; };
- void SetTraffcounter(TRAFFCOUNTER *) {};
- void SetStgSettings(const SETTINGS * s) { stgSettings = s; };
- void SetSettings(const MODULE_SETTINGS & s) { modSettings = s; };
+ void SetUsers(USERS * u) { users = u; }
+ void SetTariffs(TARIFFS * t) { tariffs = t; }
+ void SetAdmins(ADMINS * a) { admins = a; }
+ void SetStore(STORE * s) { store = s; }
+ void SetTraffcounter(TRAFFCOUNTER *) {}
+ void SetStgSettings(const SETTINGS * s) { stgSettings = s; }
+ void SetSettings(const MODULE_SETTINGS & s) { modSettings = s; }
int ParseSettings();
int Start();
int Stop();
- int Reload() { return 0; };
+ int Reload() { return 0; }
bool IsRunning();
- const std::string & GetStrError() const { return errorStr; };
- const std::string GetVersion() const { return PLUGIN_VERSION; };
- uint16_t GetStartPosition() const { return 220; };
- uint16_t GetStopPosition() const { return 220; };
+ const std::string & GetStrError() const { return errorStr; }
+ const std::string GetVersion() const { return PLUGIN_VERSION; }
+ uint16_t GetStartPosition() const { return 220; }
+ uint16_t GetStopPosition() const { return 220; }
private:
USERS * users;
TARIFFS * tariffs;
ADMINS * admins;
- BASE_STORE * store;
+ STORE * store;
const SETTINGS * stgSettings;
MODULE_SETTINGS modSettings;
};
-extern "C" BASE_PLUGIN * GetPlugin();
+extern "C" PLUGIN * GetPlugin();
#endif
if (cp->currParser)
{
cp->currParser->SetAnswerList(&cp->answerList);
- cp->currParser->SetCurrAdmin(cp->currAdmin);
+ cp->currParser->SetCurrAdmin(*cp->currAdmin);
cp->currParser->ParseStart(data, el, attr);
}
else
for (unsigned int i = 0; i < cp->dataParser.size(); i++)
{
cp->dataParser[i]->SetAnswerList(&cp->answerList);
- cp->dataParser[i]->SetCurrAdmin(cp->currAdmin);
+ cp->dataParser[i]->SetCurrAdmin(*cp->currAdmin);
cp->dataParser[i]->Reset();
if (cp->dataParser[i]->ParseStart(data, el, attr) == 0)
{
#include <sys/socket.h>
#include <string>
+#include <list>
#include "parser.h"
-#include "../../../users.h"
-#include "../../../admins.h"
-#include "../../../tariffs.h"
+#include "users.h"
+#include "admins.h"
+#include "tariffs.h"
#include "stg_logger.h"
-using namespace std;
-
#define STG_HEADER "SG04"
#define OK_HEADER "OKHD"
#define ERR_HEADER "ERHD"
#define ERR_LOGINS "ERLS"
//-----------------------------------------------------------------------------
-class CONFIGPROTO
-{
+class CONFIGPROTO {
public:
CONFIGPROTO();
~CONFIGPROTO();
void SetAdmins(ADMINS * a);
void SetUsers(USERS * u);
void SetTariffs(TARIFFS * t);
- void SetStore(BASE_STORE * s);
+ void SetStore(STORE * s);
void SetStgSettings(const SETTINGS * s);
uint32_t GetAdminIP() const;
int Prepare();
int Stop();
- const string & GetStrError() const;
+ const std::string & GetStrError() const;
static void * Run(void * a);
private:
int ParseCommand();
- list<string> answerList;
- list<string> requestList;
- uint32_t adminIP;
- string adminLogin;
- uint16_t port;
- pthread_t thrReciveSendConf;
- bool nonstop;
- int state;
- ADMIN currAdmin;
- STG_LOGGER & WriteServLog;
+ std::list<std::string> answerList;
+ std::list<std::string> requestList;
+ uint32_t adminIP;
+ std::string adminLogin;
+ uint16_t port;
+ pthread_t thrReciveSendConf;
+ bool nonstop;
+ int state;
+ ADMIN * currAdmin;
+ STG_LOGGER & WriteServLog;
- int listenSocket;
+ int listenSocket;
PARSER_GET_SERVER_INFO parserGetServInfo;
ADMINS * admins;
BASE_PARSER * currParser;
- vector<BASE_PARSER*> dataParser;
+ vector<BASE_PARSER *> dataParser;
XML_Parser xmlParser;
- string errorStr;
+ std::string errorStr;
friend void ParseXMLStart(void *data, const char *el, const char **attr);
friend void ParseXMLEnd(void *data, const char *el);
};
//-----------------------------------------------------------------------------
#endif //CONFIGPROTO_H
-
-#include <string.h>
-#include <errno.h>
#include <stdio.h>
#include <sys/utsname.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
+
+#include <cstring>
+#include <cerrno>
#include <sstream>
#include "parser.h"
#include "version.h"
+#include "tariffs.h"
+#include "../../../settings.h"
+#include "../../../user_property.h"
#define UNAME_LEN (256)
//-----------------------------------------------------------------------------
string s;
string enc;
-user_iter u;
+USER_PTR u;
answerList->erase(answerList->begin(), answerList->end());
s = "<login value=\"" + u->GetLogin() + "\"/>";
answerList->push_back(s);
-if (currAdmin.GetPriv()->userConf || currAdmin.GetPriv()->userPasswd)
- s = "<password value=\"" + u->property.password.Get() + "\" />";
+if (currAdmin->GetPriv()->userConf || currAdmin->GetPriv()->userPasswd)
+ s = "<password value=\"" + u->GetProperty().password.Get() + "\" />";
else
s = "<password value=\"++++++\"/>";
answerList->push_back(s);
-strprintf(&s, "<cash value=\"%f\" />", u->property.cash.Get());
+strprintf(&s, "<cash value=\"%f\" />", u->GetProperty().cash.Get());
answerList->push_back(s);
-strprintf(&s, "<freemb value=\"%f\" />", u->property.freeMb.Get());
+strprintf(&s, "<freemb value=\"%f\" />", u->GetProperty().freeMb.Get());
answerList->push_back(s);
-strprintf(&s, "<credit value=\"%f\" />", u->property.credit.Get());
+strprintf(&s, "<credit value=\"%f\" />", u->GetProperty().credit.Get());
answerList->push_back(s);
-if (u->property.nextTariff.Get() != "")
+if (u->GetProperty().nextTariff.Get() != "")
{
strprintf(&s, "<tariff value=\"%s/%s\" />",
- u->property.tariffName.Get().c_str(),
- u->property.nextTariff.Get().c_str());
+ u->GetProperty().tariffName.Get().c_str(),
+ u->GetProperty().nextTariff.Get().c_str());
}
else
{
strprintf(&s, "<tariff value=\"%s\" />",
- u->property.tariffName.Get().c_str());
+ u->GetProperty().tariffName.Get().c_str());
}
answerList->push_back(s);
-Encode12str(enc, u->property.note);
+Encode12str(enc, u->GetProperty().note);
s = "<note value=\"" + enc + "\" />";
answerList->push_back(s);
-Encode12str(enc, u->property.phone);
+Encode12str(enc, u->GetProperty().phone);
s = "<phone value=\"" + enc + "\" />";
answerList->push_back(s);
-Encode12str(enc, u->property.address);
+Encode12str(enc, u->GetProperty().address);
s = "<address value=\"" + enc + "\" />";
answerList->push_back(s);
-Encode12str(enc, u->property.email);
+Encode12str(enc, u->GetProperty().email);
s = "<email value=\"" + enc + "\" />";
answerList->push_back(s);
vector<USER_PROPERTY_LOGGED<string> *> userdata;
-userdata.push_back(u->property.userdata0.GetPointer());
-userdata.push_back(u->property.userdata1.GetPointer());
-userdata.push_back(u->property.userdata2.GetPointer());
-userdata.push_back(u->property.userdata3.GetPointer());
-userdata.push_back(u->property.userdata4.GetPointer());
-userdata.push_back(u->property.userdata5.GetPointer());
-userdata.push_back(u->property.userdata6.GetPointer());
-userdata.push_back(u->property.userdata7.GetPointer());
-userdata.push_back(u->property.userdata8.GetPointer());
-userdata.push_back(u->property.userdata9.GetPointer());
+userdata.push_back(u->GetProperty().userdata0.GetPointer());
+userdata.push_back(u->GetProperty().userdata1.GetPointer());
+userdata.push_back(u->GetProperty().userdata2.GetPointer());
+userdata.push_back(u->GetProperty().userdata3.GetPointer());
+userdata.push_back(u->GetProperty().userdata4.GetPointer());
+userdata.push_back(u->GetProperty().userdata5.GetPointer());
+userdata.push_back(u->GetProperty().userdata6.GetPointer());
+userdata.push_back(u->GetProperty().userdata7.GetPointer());
+userdata.push_back(u->GetProperty().userdata8.GetPointer());
+userdata.push_back(u->GetProperty().userdata9.GetPointer());
string tmpI;
for (unsigned i = 0; i < userdata.size(); i++)
answerList->push_back(s);
}
-Encode12str(enc, u->property.realName);
+Encode12str(enc, u->GetProperty().realName);
s = "<name value=\"" + enc + "\" />";
answerList->push_back(s);
-Encode12str(enc, u->property.group);
+Encode12str(enc, u->GetProperty().group);
s = "<GROUP value=\"" + enc + "\" />";
answerList->push_back(s);
strprintf(&s, "<status value=\"%d\" />", u->GetConnected());
answerList->push_back(s);
-strprintf(&s, "<aonline value=\"%d\" />", u->property.alwaysOnline.Get());
+strprintf(&s, "<aonline value=\"%d\" />", u->GetProperty().alwaysOnline.Get());
answerList->push_back(s);
strprintf(&s, "<currip value=\"%s\" />", inet_ntostring(u->GetCurrIP()).c_str());
answerList->push_back(s);
stringstream sstr;
-sstr << u->property.ips.Get();
+sstr << u->GetProperty().ips.Get();
strprintf(&s, "<ip value=\"%s\" />", sstr.str().c_str());
answerList->push_back(s);
sprintf(ss, "<traff");
DIR_TRAFF upload;
DIR_TRAFF download;
-download = u->property.down.Get();
-upload = u->property.up.Get();
+download = u->GetProperty().down.Get();
+upload = u->GetProperty().up.Get();
for (int j = 0; j < DIR_NUM; j++)
{
answerList->push_back(ss);
delete[] ss;
-strprintf(&s, "<down value=\"%d\" />", u->property.disabled.Get());
+strprintf(&s, "<down value=\"%d\" />", u->GetProperty().disabled.Get());
answerList->push_back(s);
-strprintf(&s, "<DisableDetailStat value=\"%d\" />", u->property.disabledDetailStat.Get());
+strprintf(&s, "<DisableDetailStat value=\"%d\" />", u->GetProperty().disabledDetailStat.Get());
answerList->push_back(s);
-strprintf(&s, "<passive value=\"%d\" />", u->property.passive.Get());
+strprintf(&s, "<passive value=\"%d\" />", u->GetProperty().passive.Get());
answerList->push_back(s);
-strprintf(&s, "<LastCash value=\"%f\" />", u->property.lastCashAdd.Get());
+strprintf(&s, "<LastCash value=\"%f\" />", u->GetProperty().lastCashAdd.Get());
answerList->push_back(s);
-strprintf(&s, "<LastTimeCash value=\"%ld\" />", u->property.lastCashAddTime.Get());
+strprintf(&s, "<LastTimeCash value=\"%ld\" />", u->GetProperty().lastCashAddTime.Get());
answerList->push_back(s);
-strprintf(&s, "<LastActivityTime value=\"%ld\" />", u->property.lastActivityTime.Get());
+strprintf(&s, "<LastActivityTime value=\"%ld\" />", u->GetProperty().lastActivityTime.Get());
answerList->push_back(s);
-strprintf(&s, "<CreditExpire value=\"%ld\" />", u->property.creditExpire.Get());
+strprintf(&s, "<CreditExpire value=\"%ld\" />", u->GetProperty().creditExpire.Get());
answerList->push_back(s);
strprintf(&s, "</user>");
string enc;
-user_iter u;
+USER_PTR u;
int h = users->OpenSearch();
if (!h)
userStart = "<user login=\"" + u->GetLogin() + "\">";
middle = "";
- if (u->property.password.ModificationTime() > lastUserUpdateTime)
+ if (u->GetProperty().password.ModificationTime() > lastUserUpdateTime)
{
- if (currAdmin.GetPriv()->userConf || currAdmin.GetPriv()->userPasswd)
- s = "<password value=\"" + u->property.password.Get() + "\" />";
+ if (currAdmin->GetPriv()->userConf || currAdmin->GetPriv()->userPasswd)
+ s = "<password value=\"" + u->GetProperty().password.Get() + "\" />";
else
s = "<password value=\"++++++\"/>";
middle += s;
}
- if (u->property.cash.ModificationTime() > lastUserUpdateTime)
+ if (u->GetProperty().cash.ModificationTime() > lastUserUpdateTime)
{
- strprintf(&s, "<cash value=\"%f\" />", u->property.cash.Get());
+ strprintf(&s, "<cash value=\"%f\" />", u->GetProperty().cash.Get());
middle += s;
- //printfd(__FILE__, "cash value=\"%f\"\n", u->property.cash.Get());
+ //printfd(__FILE__, "cash value=\"%f\"\n", u->GetProperty().cash.Get());
}
- if (u->property.freeMb.ModificationTime() > lastUserUpdateTime)
+ if (u->GetProperty().freeMb.ModificationTime() > lastUserUpdateTime)
{
- strprintf(&s, "<freemb value=\"%f\" />", u->property.freeMb.Get());
+ strprintf(&s, "<freemb value=\"%f\" />", u->GetProperty().freeMb.Get());
middle += s;
}
- if (u->property.credit.ModificationTime() > lastUserUpdateTime)
+ if (u->GetProperty().credit.ModificationTime() > lastUserUpdateTime)
{
- strprintf(&s, "<credit value=\"%f\" />", u->property.credit.Get());
+ strprintf(&s, "<credit value=\"%f\" />", u->GetProperty().credit.Get());
middle += s;
}
- if (u->property.nextTariff.Get() != "")
+ if (u->GetProperty().nextTariff.Get() != "")
{
- if (u->property.tariffName.ModificationTime() > lastUserUpdateTime
- || u->property.nextTariff.ModificationTime() > lastUserUpdateTime)
+ if (u->GetProperty().tariffName.ModificationTime() > lastUserUpdateTime
+ || u->GetProperty().nextTariff.ModificationTime() > lastUserUpdateTime)
{
strprintf(&s, "<tariff value=\"%s/%s\" />",
- u->property.tariffName.Get().c_str(),
- u->property.nextTariff.Get().c_str());
+ u->GetProperty().tariffName.Get().c_str(),
+ u->GetProperty().nextTariff.Get().c_str());
middle += s;
}
}
else
{
- if (u->property.tariffName.ModificationTime() > lastUserUpdateTime)
+ if (u->GetProperty().tariffName.ModificationTime() > lastUserUpdateTime)
{
strprintf(&s, "<tariff value=\"%s\" />",
- u->property.tariffName.Get().c_str());
+ u->GetProperty().tariffName.Get().c_str());
middle += s;
}
}
- if (u->property.note.ModificationTime() > lastUserUpdateTime)
+ if (u->GetProperty().note.ModificationTime() > lastUserUpdateTime)
{
- Encode12str(enc, u->property.note);
+ Encode12str(enc, u->GetProperty().note);
strprintf(&s, "<note value=\"%s\" />", enc.c_str());
middle += s;
}
- if (u->property.phone.ModificationTime() > lastUserUpdateTime)
+ if (u->GetProperty().phone.ModificationTime() > lastUserUpdateTime)
{
- Encode12str(enc, u->property.phone);
+ Encode12str(enc, u->GetProperty().phone);
strprintf(&s, "<phone value=\"%s\" />", enc.c_str());
middle += s;
}
- if (u->property.address.ModificationTime() > lastUserUpdateTime)
+ if (u->GetProperty().address.ModificationTime() > lastUserUpdateTime)
{
- Encode12str(enc, u->property.address);
+ Encode12str(enc, u->GetProperty().address);
strprintf(&s, "<address value=\"%s\" />", enc.c_str());
middle += s;
}
- if (u->property.email.ModificationTime() > lastUserUpdateTime)
+ if (u->GetProperty().email.ModificationTime() > lastUserUpdateTime)
{
- Encode12str(enc, u->property.email);
+ Encode12str(enc, u->GetProperty().email);
strprintf(&s, "<email value=\"%s\" />", enc.c_str());
middle += s;
}
vector<USER_PROPERTY_LOGGED<string> *> userdata;
- userdata.push_back(u->property.userdata0.GetPointer());
- userdata.push_back(u->property.userdata1.GetPointer());
- userdata.push_back(u->property.userdata2.GetPointer());
- userdata.push_back(u->property.userdata3.GetPointer());
- userdata.push_back(u->property.userdata4.GetPointer());
- userdata.push_back(u->property.userdata5.GetPointer());
- userdata.push_back(u->property.userdata6.GetPointer());
- userdata.push_back(u->property.userdata7.GetPointer());
- userdata.push_back(u->property.userdata8.GetPointer());
- userdata.push_back(u->property.userdata9.GetPointer());
+ userdata.push_back(u->GetProperty().userdata0.GetPointer());
+ userdata.push_back(u->GetProperty().userdata1.GetPointer());
+ userdata.push_back(u->GetProperty().userdata2.GetPointer());
+ userdata.push_back(u->GetProperty().userdata3.GetPointer());
+ userdata.push_back(u->GetProperty().userdata4.GetPointer());
+ userdata.push_back(u->GetProperty().userdata5.GetPointer());
+ userdata.push_back(u->GetProperty().userdata6.GetPointer());
+ userdata.push_back(u->GetProperty().userdata7.GetPointer());
+ userdata.push_back(u->GetProperty().userdata8.GetPointer());
+ userdata.push_back(u->GetProperty().userdata9.GetPointer());
string tmpI;
for (unsigned i = 0; i < userdata.size(); i++)
}
}
- if (u->property.realName.ModificationTime() > lastUserUpdateTime)
+ if (u->GetProperty().realName.ModificationTime() > lastUserUpdateTime)
{
- Encode12str(enc, u->property.realName);
+ Encode12str(enc, u->GetProperty().realName);
strprintf(&s, "<name value=\"%s\" />", enc.c_str());
middle += s;
}
- if (u->property.group.ModificationTime() > lastUserUpdateTime)
+ if (u->GetProperty().group.ModificationTime() > lastUserUpdateTime)
{
- Encode12str(enc, u->property.group);
+ Encode12str(enc, u->GetProperty().group);
strprintf(&s, "<GROUP value=\"%s\" />", enc.c_str());
middle += s;
}
- if (u->property.alwaysOnline.ModificationTime() > lastUserUpdateTime)
+ if (u->GetProperty().alwaysOnline.ModificationTime() > lastUserUpdateTime)
{
- strprintf(&s, "<aonline value=\"%d\" />", u->property.alwaysOnline.Get());
+ strprintf(&s, "<aonline value=\"%d\" />", u->GetProperty().alwaysOnline.Get());
middle += s;
}
middle += s;
}
- if (u->property.ips.ModificationTime() > lastUserUpdateTime)
+ if (u->GetProperty().ips.ModificationTime() > lastUserUpdateTime)
{
stringstream sstr;
- sstr << u->property.ips.Get();
+ sstr << u->GetProperty().ips.Get();
strprintf(&s, "<ip value=\"%s\" />", sstr.str().c_str());
middle += s;
}
traffStart = "<traff";
DIR_TRAFF upload;
DIR_TRAFF download;
- download = u->property.down.Get();
- upload = u->property.up.Get();
+ download = u->GetProperty().down.Get();
+ upload = u->GetProperty().up.Get();
traffMiddle = "";
- if (u->property.up.ModificationTime() > lastUserUpdateTime)
+ if (u->GetProperty().up.ModificationTime() > lastUserUpdateTime)
{
for (int j = 0; j < DIR_NUM; j++)
{
}
}
- if (u->property.down.ModificationTime() > lastUserUpdateTime)
+ if (u->GetProperty().down.ModificationTime() > lastUserUpdateTime)
{
for (int j = 0; j < DIR_NUM; j++)
{
middle += traffFinish;
}
- if (u->property.disabled.ModificationTime() > lastUserUpdateTime)
+ if (u->GetProperty().disabled.ModificationTime() > lastUserUpdateTime)
{
- strprintf(&s, "<down value=\"%d\" />", u->property.disabled.Get());
+ strprintf(&s, "<down value=\"%d\" />", u->GetProperty().disabled.Get());
middle += s;
}
- if (u->property.disabledDetailStat.ModificationTime() > lastUserUpdateTime)
+ if (u->GetProperty().disabledDetailStat.ModificationTime() > lastUserUpdateTime)
{
- strprintf(&s, "<DisableDetailStat value=\"%d\" />", u->property.disabledDetailStat.Get());
+ strprintf(&s, "<DisableDetailStat value=\"%d\" />", u->GetProperty().disabledDetailStat.Get());
middle += s;
}
//printfd(__FILE__, ">>>>> %s\n", s.c_str());
- if (u->property.passive.ModificationTime() > lastUserUpdateTime)
+ if (u->GetProperty().passive.ModificationTime() > lastUserUpdateTime)
{
- strprintf(&s, "<passive value=\"%d\" />", u->property.passive.Get());
+ strprintf(&s, "<passive value=\"%d\" />", u->GetProperty().passive.Get());
middle += s;
}
- if (u->property.lastCashAdd.ModificationTime() > lastUserUpdateTime)
+ if (u->GetProperty().lastCashAdd.ModificationTime() > lastUserUpdateTime)
{
- strprintf(&s, "<LastCash value=\"%f\" />", u->property.lastCashAdd.Get());
+ strprintf(&s, "<LastCash value=\"%f\" />", u->GetProperty().lastCashAdd.Get());
middle += s;
}
- if (u->property.lastCashAddTime.ModificationTime() > lastUserUpdateTime)
+ if (u->GetProperty().lastCashAddTime.ModificationTime() > lastUserUpdateTime)
{
- strprintf(&s, "<LastTimeCash value=\"%ld\" />", u->property.lastCashAddTime.Get());
+ strprintf(&s, "<LastTimeCash value=\"%ld\" />", u->GetProperty().lastCashAddTime.Get());
middle += s;
}
- if (u->property.lastActivityTime.ModificationTime() > lastUserUpdateTime)
+ if (u->GetProperty().lastActivityTime.ModificationTime() > lastUserUpdateTime)
{
- strprintf(&s, "<LastActivityTime value=\"%ld\" />", u->property.lastActivityTime.Get());
+ strprintf(&s, "<LastActivityTime value=\"%ld\" />", u->GetProperty().lastActivityTime.Get());
middle += s;
}
- if (u->property.creditExpire.ModificationTime() > lastUserUpdateTime)
+ if (u->GetProperty().creditExpire.ModificationTime() > lastUserUpdateTime)
{
- strprintf(&s, "<CreditExpire value=\"%ld\" />", u->property.creditExpire.Get());
+ strprintf(&s, "<CreditExpire value=\"%ld\" />", u->GetProperty().creditExpire.Get());
middle += s;
}
//-----------------------------------------------------------------------------
int PARSER_ADD_USER::CheckUserData()
{
-user_iter u;
+USER_PTR u;
if (users->FindByName(login, &u))
{
- return users->Add(login, currAdmin);
+ return users->Add(login, *currAdmin);
}
return -1;
}
//-----------------------------------------------------------------------------
int PARSER_CHG_USER::AplayChanges()
{
-user_iter u;
+USER_PTR u;
res = 0;
if (users->FindByName(login, &u))
}
if (!ucr->ips.res_empty())
- if (!u->property.ips.Set(ucr->ips.const_data(), currAdmin, login, store))
+ if (!u->GetProperty().ips.Set(ucr->ips.const_data(), *currAdmin, login, store))
res = -1;
if (!ucr->address.res_empty())
- if (!u->property.address.Set(ucr->address.const_data(), currAdmin, login, store))
+ if (!u->GetProperty().address.Set(ucr->address.const_data(), *currAdmin, login, store))
res = -1;
if (!ucr->alwaysOnline.res_empty())
- if (!u->property.alwaysOnline.Set(ucr->alwaysOnline.const_data(),
- currAdmin, login, store))
+ if (!u->GetProperty().alwaysOnline.Set(ucr->alwaysOnline.const_data(),
+ *currAdmin, login, store))
res = -1;
if (!ucr->creditExpire.res_empty())
- if (!u->property.creditExpire.Set(ucr->creditExpire.const_data(),
- currAdmin, login, store))
+ if (!u->GetProperty().creditExpire.Set(ucr->creditExpire.const_data(),
+ *currAdmin, login, store))
res = -1;
if (!ucr->credit.res_empty())
- if (!u->property.credit.Set(ucr->credit.const_data(), currAdmin, login, store))
+ if (!u->GetProperty().credit.Set(ucr->credit.const_data(), *currAdmin, login, store))
res = -1;
if (!usr->freeMb.res_empty())
- if (!u->property.freeMb.Set(usr->freeMb.const_data(), currAdmin, login, store))
+ if (!u->GetProperty().freeMb.Set(usr->freeMb.const_data(), *currAdmin, login, store))
res = -1;
if (!ucr->disabled.res_empty())
- if (!u->property.disabled.Set(ucr->disabled.const_data(), currAdmin, login, store))
+ if (!u->GetProperty().disabled.Set(ucr->disabled.const_data(), *currAdmin, login, store))
res = -1;
if (!ucr->disabledDetailStat.res_empty())
- if (!u->property.disabledDetailStat.Set(ucr->disabledDetailStat.const_data(), currAdmin, login, store))
+ if (!u->GetProperty().disabledDetailStat.Set(ucr->disabledDetailStat.const_data(), *currAdmin, login, store))
res = -1;
if (!ucr->email.res_empty())
- if (!u->property.email.Set(ucr->email.const_data(), currAdmin, login, store))
+ if (!u->GetProperty().email.Set(ucr->email.const_data(), *currAdmin, login, store))
res = -1;
if (!ucr->group.res_empty())
- if (!u->property.group.Set(ucr->group.const_data(), currAdmin, login, store))
+ if (!u->GetProperty().group.Set(ucr->group.const_data(), *currAdmin, login, store))
res = -1;
if (!ucr->note.res_empty())
- if (!u->property.note.Set(ucr->note.const_data(), currAdmin, login, store))
+ if (!u->GetProperty().note.Set(ucr->note.const_data(), *currAdmin, login, store))
res = -1;
vector<USER_PROPERTY_LOGGED<string> *> userdata;
-userdata.push_back(u->property.userdata0.GetPointer());
-userdata.push_back(u->property.userdata1.GetPointer());
-userdata.push_back(u->property.userdata2.GetPointer());
-userdata.push_back(u->property.userdata3.GetPointer());
-userdata.push_back(u->property.userdata4.GetPointer());
-userdata.push_back(u->property.userdata5.GetPointer());
-userdata.push_back(u->property.userdata6.GetPointer());
-userdata.push_back(u->property.userdata7.GetPointer());
-userdata.push_back(u->property.userdata8.GetPointer());
-userdata.push_back(u->property.userdata9.GetPointer());
+userdata.push_back(u->GetProperty().userdata0.GetPointer());
+userdata.push_back(u->GetProperty().userdata1.GetPointer());
+userdata.push_back(u->GetProperty().userdata2.GetPointer());
+userdata.push_back(u->GetProperty().userdata3.GetPointer());
+userdata.push_back(u->GetProperty().userdata4.GetPointer());
+userdata.push_back(u->GetProperty().userdata5.GetPointer());
+userdata.push_back(u->GetProperty().userdata6.GetPointer());
+userdata.push_back(u->GetProperty().userdata7.GetPointer());
+userdata.push_back(u->GetProperty().userdata8.GetPointer());
+userdata.push_back(u->GetProperty().userdata9.GetPointer());
for (int i = 0; i < (int)userdata.size(); i++)
{
if (!ucr->userdata[i].res_empty())
{
- if(!userdata[i]->Set(ucr->userdata[i].const_data(), currAdmin, login, store))
+ if(!userdata[i]->Set(ucr->userdata[i].const_data(), *currAdmin, login, store))
res = -1;
}
}
if (!ucr->passive.res_empty())
- if (!u->property.passive.Set(ucr->passive.const_data(), currAdmin, login, store))
+ if (!u->GetProperty().passive.Set(ucr->passive.const_data(), *currAdmin, login, store))
res = -1;
if (!ucr->password.res_empty())
- if (!u->property.password.Set(ucr->password.const_data(), currAdmin, login, store))
+ if (!u->GetProperty().password.Set(ucr->password.const_data(), *currAdmin, login, store))
res = -1;
if (!ucr->phone.res_empty())
- if (!u->property.phone.Set(ucr->phone.const_data(), currAdmin, login, store))
+ if (!u->GetProperty().phone.Set(ucr->phone.const_data(), *currAdmin, login, store))
res = -1;
if (!ucr->realName.res_empty())
- if (!u->property.realName.Set(ucr->realName.const_data(), currAdmin, login, store))
+ if (!u->GetProperty().realName.Set(ucr->realName.const_data(), *currAdmin, login, store))
res = -1;
if (!usr->cash.res_empty())
{
- //if (currAdmin->GetPriv()->userCash)
+ //if (*currAdmin->GetPriv()->userCash)
{
if (cashMustBeAdded)
{
- if (!u->property.cash.Set(usr->cash.const_data() + u->property.cash,
- currAdmin,
+ if (!u->GetProperty().cash.Set(usr->cash.const_data() + u->GetProperty().cash,
+ *currAdmin,
login,
store,
cashMsg))
}
else
{
- if (!u->property.cash.Set(usr->cash.const_data(), currAdmin, login, store, cashMsg))
+ if (!u->GetProperty().cash.Set(usr->cash.const_data(), *currAdmin, login, store, cashMsg))
res = -1;
}
}
{
if (tariffs->FindByName(ucr->tariffName.const_data()))
{
- if (!u->property.tariffName.Set(ucr->tariffName.const_data(), currAdmin, login, store))
+ if (!u->GetProperty().tariffName.Set(ucr->tariffName.const_data(), *currAdmin, login, store))
res = -1;
u->ResetNextTariff();
}
{
if (tariffs->FindByName(ucr->nextTariff.const_data()))
{
- if (!u->property.nextTariff.Set(ucr->nextTariff.const_data(), currAdmin, login, store))
+ if (!u->GetProperty().nextTariff.Set(ucr->nextTariff.const_data(), *currAdmin, login, store))
res = -1;
}
else
}
}
-DIR_TRAFF up = u->property.up;
-DIR_TRAFF down = u->property.down;
+DIR_TRAFF up = u->GetProperty().up;
+DIR_TRAFF down = u->GetProperty().down;
int upCount = 0;
int downCount = 0;
for (int i = 0; i < DIR_NUM; i++)
}
if (upCount)
- if (!u->property.up.Set(up, currAdmin, login, store))
+ if (!u->GetProperty().up.Set(up, *currAdmin, login, store))
res = -1;
if (downCount)
- if (!u->property.down.Set(down, currAdmin, login, store))
+ if (!u->GetProperty().down.Set(down, *currAdmin, login, store))
res = -1;
/*if (!usr->down.res_empty())
{
- u->property.down.Set(usr->down.const_data(), currAdmin, login, store);
+ u->GetProperty().down.Set(usr->down.const_data(), *currAdmin, login, store);
}
if (!usr->up.res_empty())
{
- u->property.up.Set(usr->up.const_data(), currAdmin, login, store);
+ u->GetProperty().up.Set(usr->up.const_data(), *currAdmin, login, store);
}*/
u->WriteConf();
if (strcasecmp(el, "DelUser") == 0)
{
if (!res)
- users->Del(u->GetLogin(), currAdmin);
+ users->Del(u->GetLogin(), *currAdmin);
return 0;
}
return 0;
}
- user_iter user;
+ USER_PTR user;
if (users->FindByName(attr[1], &user))
{
result = false;
return 0;
}
- if (strcmp(user->property.password.Get().c_str(), attr[3]))
+ if (strcmp(user->GetProperty().password.Get().c_str(), attr[3]))
{
result = false;
CreateAnswer();
#include <list>
#include <string>
+#include <vector>
#include "resetable.h"
#include "stg_const.h"
-#include "base_store.h"
-#include "../../../admins.h"
-#include "../../../users.h"
+#include "store.h"
+#include "admins.h"
+#include "admin.h"
+#include "users.h"
#include "stg_message.h"
-using namespace std;
+class TARIFFS;
+class SETTINGS;
//-----------------------------------------------------------------------------
-class BASE_PARSER
-{
+class BASE_PARSER {
public:
BASE_PARSER()
: admins(NULL),
settings(NULL),
currAdmin(),
depth(0)
- { };
- virtual ~BASE_PARSER() {};
+ { }
+ virtual ~BASE_PARSER() {}
virtual int ParseStart(void *data, const char *el, const char **attr) = 0;
virtual int ParseEnd(void *data, const char *el) = 0;
virtual void CreateAnswer() = 0;
- virtual void SetAnswerList(list<string> * ansList) { answerList = ansList; };
+ virtual void SetAnswerList(std::list<std::string> * ansList) { answerList = ansList; }
- virtual void SetUsers(USERS * u) { users = u; };
- virtual void SetAdmins(ADMINS * a) { admins = a; };
- virtual void SetTariffs(TARIFFS * t) { tariffs = t; };
- virtual void SetStore(BASE_STORE * s) { store = s; };
- virtual void SetStgSettings(const SETTINGS * s) { settings = s; };
+ virtual void SetUsers(USERS * u) { users = u; }
+ virtual void SetAdmins(ADMINS * a) { admins = a; }
+ virtual void SetTariffs(TARIFFS * t) { tariffs = t; }
+ virtual void SetStore(STORE * s) { store = s; }
+ virtual void SetStgSettings(const SETTINGS * s) { settings = s; }
- virtual void SetCurrAdmin(const ADMIN & cua) { currAdmin = cua; };
- virtual string & GetStrError(){return strError;};
- virtual void Reset(){ answerList->clear(); depth = 0; };
+ virtual void SetCurrAdmin(ADMIN & cua) { currAdmin = &cua; }
+ virtual std::string & GetStrError() { return strError; }
+ virtual void Reset() { answerList->clear(); depth = 0; }
protected:
- string strError;
+ std::string strError;
ADMINS * admins;
USERS * users;
TARIFFS * tariffs;
- BASE_STORE * store;
+ STORE * store;
const SETTINGS * settings;
- ADMIN currAdmin;
+ ADMIN * currAdmin;
int depth;
- list<string> * answerList;
+ std::list<std::string> * answerList;
};
//-----------------------------------------------------------------------------
-class PARSER_GET_ADMINS: public BASE_PARSER
-{
+class PARSER_GET_ADMINS: public BASE_PARSER {
public:
int ParseStart(void *data, const char *el, const char **attr);
int ParseEnd(void *data, const char *el);
void CreateAnswer();
};
//-----------------------------------------------------------------------------
-class PARSER_ADD_ADMIN: public BASE_PARSER
-{
+class PARSER_ADD_ADMIN: public BASE_PARSER {
public:
PARSER_ADD_ADMIN() : BASE_PARSER() {}
int ParseStart(void *data, const char *el, const char **attr);
int ParseEnd(void *data, const char *el);
void CreateAnswer();
private:
- string adminToAdd;
+ std::string adminToAdd;
};
//-----------------------------------------------------------------------------
-class PARSER_DEL_ADMIN: public BASE_PARSER
-{
+class PARSER_DEL_ADMIN: public BASE_PARSER {
public:
PARSER_DEL_ADMIN() : BASE_PARSER() {}
int ParseStart(void *data, const char *el, const char **attr);
void CreateAnswer();
private:
int CheckAttr(const char **attr);
- string adminToDel;
+ std::string adminToDel;
};
//-----------------------------------------------------------------------------
-class PARSER_CHG_ADMIN: public BASE_PARSER
-{
+class PARSER_CHG_ADMIN: public BASE_PARSER {
public:
PARSER_CHG_ADMIN() : BASE_PARSER() {}
int ParseStart(void *data, const char *el, const char **attr);
int ParseEnd(void *data, const char *el);
void CreateAnswer();
private:
- RESETABLE<string> login;
- RESETABLE<string> password;
- RESETABLE<string> privAsString;
+ RESETABLE<std::string> login;
+ RESETABLE<std::string> password;
+ RESETABLE<std::string> privAsString;
};
//-----------------------------------------------------------------------------
-class PARSER_GET_SERVER_INFO: public BASE_PARSER
-{
+class PARSER_GET_SERVER_INFO: public BASE_PARSER {
public:
int ParseStart(void *data, const char *el, const char **attr);
int ParseEnd(void *data, const char *el);
void CreateAnswer();
};
-
//-----------------------------------------------------------------------------
-class PARSER_GET_USER: public BASE_PARSER
-{
+class PARSER_GET_USER: public BASE_PARSER {
public:
PARSER_GET_USER();
~PARSER_GET_USER(){};
int ParseEnd(void *data, const char *el);
void CreateAnswer();
private:
- string login;
+ std::string login;
};
//-----------------------------------------------------------------------------
-class PARSER_GET_USERS: public BASE_PARSER
-{
+class PARSER_GET_USERS: public BASE_PARSER {
public:
PARSER_GET_USERS();
int ParseStart(void *data, const char *el, const char **attr);
bool lastUpdateFound;
};
//-----------------------------------------------------------------------------
-class PARSER_GET_TARIFFS: public BASE_PARSER
-{
+class PARSER_GET_TARIFFS: public BASE_PARSER {
public:
int ParseStart(void *data, const char *el, const char **attr);
int ParseEnd(void *data, const char *el);
void CreateAnswer();
};
//-----------------------------------------------------------------------------
-class PARSER_ADD_TARIFF: public BASE_PARSER
-{
+class PARSER_ADD_TARIFF: public BASE_PARSER {
public:
PARSER_ADD_TARIFF() : BASE_PARSER() {}
int ParseStart(void *data, const char *el, const char **attr);
int ParseEnd(void *data, const char *el);
void CreateAnswer();
private:
- string tariffToAdd;
+ std::string tariffToAdd;
};
//-----------------------------------------------------------------------------
-class PARSER_DEL_TARIFF: public BASE_PARSER
-{
+class PARSER_DEL_TARIFF: public BASE_PARSER {
public:
PARSER_DEL_TARIFF() : BASE_PARSER() {}
int ParseStart(void *data, const char *el, const char **attr);
int ParseEnd(void *data, const char *el);
void CreateAnswer();
private:
- string tariffToDel;
+ std::string tariffToDel;
};
//-----------------------------------------------------------------------------
-class PARSER_CHG_TARIFF: public BASE_PARSER
-{
+class PARSER_CHG_TARIFF: public BASE_PARSER {
public:
PARSER_CHG_TARIFF() : BASE_PARSER() {}
int ParseStart(void *data, const char *el, const char **attr);
int ParseEnd(void *data, const char *el);
void CreateAnswer();
private:
- int ParseSlashedIntParams(int paramsNum, const string & s, int * params);
- int ParseSlashedDoubleParams(int paramsNum, const string & s, double * params);
+ int ParseSlashedIntParams(int paramsNum, const std::string & s, int * params);
+ int ParseSlashedDoubleParams(int paramsNum, const std::string & s, double * params);
int CheckTariffData();
int AplayChanges();
TARIFF_DATA_RES td;
};
//-----------------------------------------------------------------------------/
-class PARSER_ADD_USER: public BASE_PARSER
-{
+class PARSER_ADD_USER: public BASE_PARSER {
public:
PARSER_ADD_USER();
- ~PARSER_ADD_USER(){};
+ ~PARSER_ADD_USER() {}
int ParseStart(void *data, const char *el, const char **attr);
int ParseEnd(void *data, const char *el);
void CreateAnswer();
void Reset();
private:
int CheckUserData();
- string login;
+ std::string login;
};
//-----------------------------------------------------------------------------
-class PARSER_CHG_USER: public BASE_PARSER
-{
+class PARSER_CHG_USER: public BASE_PARSER {
public:
PARSER_CHG_USER();
~PARSER_CHG_USER();
void CreateAnswer();
void Reset();
private:
- string EncChar2String(const char *);
+ std::string EncChar2String(const char *);
int AplayChanges();
USER_STAT_RES * usr;
USER_CONF_RES * ucr;
RESETABLE<uint64_t> * upr;
RESETABLE<uint64_t> * downr;
- string cashMsg;
- string login;
+ std::string cashMsg;
+ std::string login;
bool cashMustBeAdded;
int res;
};
//-----------------------------------------------------------------------------
-class PARSER_DEL_USER: public BASE_PARSER
-{
+class PARSER_DEL_USER: public BASE_PARSER {
public:
PARSER_DEL_USER() : BASE_PARSER(), res(0) {}
int ParseStart(void *data, const char *el, const char **attr);
private:
int res;
- user_iter u;
+ USER * u;
};
//-----------------------------------------------------------------------------
-class PARSER_CHECK_USER: public BASE_PARSER
-{
+class PARSER_CHECK_USER: public BASE_PARSER {
public:
PARSER_CHECK_USER() : BASE_PARSER(), result(false) {}
int ParseStart(void *data, const char *el, const char **attr);
bool result;
};
//-----------------------------------------------------------------------------
-class PARSER_SEND_MESSAGE: public BASE_PARSER
-{
+class PARSER_SEND_MESSAGE: public BASE_PARSER {
public:
PARSER_SEND_MESSAGE() : BASE_PARSER(), result(0) {}
int ParseStart(void *data, const char *el, const char **attr);
int ParseLogins(const char * logins);
enum {res_ok, res_params_error, res_unknown};
- vector<string> logins;
+ std::vector<std::string> logins;
int result;
STG_MSG msg;
- user_iter u;
+ USER * u;
};
//-----------------------------------------------------------------------------
#endif //PARSER_H
//-----------------------------------------------------------------------------
void PARSER_GET_ADMINS::CreateAnswer()
{
-const PRIV * priv = currAdmin.GetPriv();
+const PRIV * priv = currAdmin->GetPriv();
if (!priv->adminChg)
{
//answerList->clear();
//answerList->clear();
answerList->erase(answerList->begin(), answerList->end());
-if (admins->Del(adminToDel, currAdmin) == 0)
+if (admins->Del(adminToDel, *currAdmin) == 0)
{
answerList->push_back("<DelAdmin Result=\"Ok\"/>");
}
//answerList->clear();
answerList->erase(answerList->begin(), answerList->end());
-if (admins->Add(adminToAdd, currAdmin) == 0)
+if (admins->Add(adminToAdd, *currAdmin) == 0)
{
answerList->push_back("<AddAdmin Result=\"Ok\"/>");
}
conf.priv.tariffChg = (p & 0x3000) >> 0x0C; // 1000+2000
}
- if (admins->Change(conf, currAdmin) != 0)
+ if (admins->Change(conf, *currAdmin) != 0)
{
strprintf(&s, "<ChgAdmin Result = \"%s\"/>", admins->GetStrError().c_str());
answerList->push_back(s);
#include <cstring>
#include "parser.h"
+#include "tariffs.h"
const int pt_mega = 1024 * 1024;
//-----------------------------------------------------------------------------
//answerList->clear();
answerList->erase(answerList->begin(), answerList->end());
-if (tariffs->Add(tariffToAdd, currAdmin) == 0)
+if (tariffs->Add(tariffToAdd, *currAdmin) == 0)
{
answerList->push_back("<AddTariff Result=\"Ok\"/>");
}
return;
}
-if (tariffs->Del(tariffToDel, currAdmin) == 0)
+if (tariffs->Del(tariffToDel, *currAdmin) == 0)
{
answerList->push_back("<DelTariff Result=\"Ok\"/>");
}
if (!td.tariffConf.name.data().empty())
{
TARIFF_DATA tariffData = td.GetData();
- if (tariffs->Chg(tariffData, currAdmin) == 0)
+ if (tariffs->Chg(tariffData, *currAdmin) == 0)
{
answerList->push_back("<SetTariff Result=\"ok\"/>");
return;
state = confHdr;
return ENODATA;
}
-currAdmin.SetAdminIP(adminIP);
+currAdmin->SetIP(adminIP);
adminLogin = login;
state = confLoginCipher;
return 0;
total += ret;
}
-if (currAdmin.GetLogin() == "")
+if (currAdmin->GetLogin() == "")
{
state = confHdr;
return ENODATA;
}
-EnDecodeInit(currAdmin.GetPassword().c_str(), ADM_PASSWD_LEN, &ctx);
+EnDecodeInit(currAdmin->GetPassword().c_str(), ADM_PASSWD_LEN, &ctx);
for (int i = 0; i < ADM_LOGIN_LEN/8; i++)
{
return 0;
}
-if (strncmp(currAdmin.GetLogin().c_str(), login, ADM_LOGIN_LEN) != 0)
+if (strncmp(currAdmin->GetLogin().c_str(), login, ADM_LOGIN_LEN) != 0)
{
state = confHdr;
return ENODATA;
requestList.clear();
BLOWFISH_CTX ctx;
-EnDecodeInit(currAdmin.GetPassword().c_str(), ADM_PASSWD_LEN, &ctx);
+EnDecodeInit(currAdmin->GetPassword().c_str(), ADM_PASSWD_LEN, &ctx);
while (1)
{
int k = 0;
int ret = 0;
-EnDecodeInit(currAdmin.GetPassword().c_str(), ADM_PASSWD_LEN, &ctx);
+EnDecodeInit(currAdmin->GetPassword().c_str(), ADM_PASSWD_LEN, &ctx);
while (li != answerList.end())
{
#include <unistd.h>
#include <signal.h>
+#include <algorithm>
+
#include "stgconfig.h"
-#include "../../../tariffs.h"
-#include "../../../admins.h"
-#include "../../../users.h"
+#include "tariffs.h"
+#include "admins.h"
+#include "users.h"
class STGCONFIG_CREATOR
{
{
}
//-----------------------------------------------------------------------------
-const string& STG_CONFIG_SETTINGS::GetStrError() const
+const std::string & STG_CONFIG_SETTINGS::GetStrError() const
{
return errorStr;
}
//-----------------------------------------------------------------------------
-int STG_CONFIG_SETTINGS::ParseIntInRange(const string & str, int min, int max, int * val)
+int STG_CONFIG_SETTINGS::ParseIntInRange(const std::string & str, int min, int max, int * val)
{
if (str2x(str.c_str(), *val))
{
vector<PARAM_VALUE>::const_iterator pvi;
///////////////////////////
pv.param = "Port";
-pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv);
+pvi = std::find(s.moduleParams.begin(), s.moduleParams.end(), pv);
if (pvi == s.moduleParams.end())
{
errorStr = "Parameter \'Port\' not found.";
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
-BASE_PLUGIN * GetPlugin()
+PLUGIN * GetPlugin()
{
return stgc.GetPlugin();
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
-const string STG_CONFIG::GetVersion() const
+const std::string STG_CONFIG::GetVersion() const
{
return "Stg configurator v.0.08";
}
return ret;
}
//-----------------------------------------------------------------------------
-const string & STG_CONFIG::GetStrError() const
+const std::string & STG_CONFIG::GetStrError() const
{
return errorStr;
}
-#include <string>
-#include <pthread.h>
-#include "base_plugin.h"
-#include "base_store.h"
-#include "configproto.h"
-//#include "user_ips.h"
-//#include "../../../users.h"
+#ifndef STGCONFIG_H
+#define STGCONFIG_H
-using namespace std;
+#include <pthread.h>
-extern "C" BASE_PLUGIN * GetPlugin();
+#include <string>
-class STG_CONFIG;
+#include "plugin.h"
+#include "store.h"
+#include "configproto.h"
-//-----------------------------------------------------------------------------
-/*template <typename varParamType>
-class CHG_BEFORE_NOTIFIER: public PROPERTY_NOTIFIER_BASE<varParamType>
-{
-public:
- void Notify(const varParamType & oldValue, const varParamType & newValue)
- {
- auth->Unauthorize(user);
- }
- void SetUser(USER * u) { user = u; }
- void SetAuthorizaror(const AUTH_AO * a) { auth = a; }
+extern "C" PLUGIN * GetPlugin();
-private:
- USER * user;
- const AUTH_AO * auth;
-};
-//-----------------------------------------------------------------------------
-template <typename varParamType>
-class CHG_AFTER_NOTIFIER: public PROPERTY_NOTIFIER_BASE<varParamType>
-{
-public:
- void Notify(const varParamType & oldValue, const varParamType & newValue)
- {
- auth->UpdateUserAuthorization(user);
- }
- void SetUser(USER * u) { user = u; }
- void SetAuthorizaror(const AUTH_AO * a) { auth = a; }
+class STG_CONFIG;
-private:
- USER * user;
- const AUTH_AO * auth;
-};*/
-//-----------------------------------------------------------------------------
-class STG_CONFIG_SETTINGS
-{
+class STG_CONFIG_SETTINGS {
public:
STG_CONFIG_SETTINGS();
- virtual ~STG_CONFIG_SETTINGS(){};
- const string & GetStrError() const;
+ virtual ~STG_CONFIG_SETTINGS() {}
+ const std::string & GetStrError() const;
int ParseSettings(const MODULE_SETTINGS & s);
uint16_t GetPort() const;
private:
- int ParseIntInRange(const string & str, int min, int max, int * val);
- string errorStr;
+ int ParseIntInRange(const std::string & str, int min, int max, int * val);
+ std::string errorStr;
int port;
};
//-----------------------------------------------------------------------------
-class STG_CONFIG :public BASE_PLUGIN
-{
+class STG_CONFIG :public PLUGIN {
public:
STG_CONFIG();
virtual ~STG_CONFIG(){};
void SetUsers(USERS * u);
void SetTariffs(TARIFFS * t);
void SetAdmins(ADMINS * a);
- void SetStore(BASE_STORE * s);
- void SetTraffcounter(TRAFFCOUNTER *){};
+ void SetStore(STORE * s);
+ void SetTraffcounter(TRAFFCOUNTER *) {}
void SetStgSettings(const SETTINGS * s);
void SetSettings(const MODULE_SETTINGS & s);
int ParseSettings();
int Start();
int Stop();
- int Reload() { return 0; };
+ int Reload() { return 0; }
bool IsRunning();
- const string & GetStrError() const;
- const string GetVersion() const;
+ const std::string & GetStrError() const;
+ const std::string GetVersion() const;
uint16_t GetStartPosition() const;
uint16_t GetStopPosition() const;
private:
static void * Run(void *);
- mutable string errorStr;
+ mutable std::string errorStr;
STG_CONFIG_SETTINGS stgConfigSettings;
pthread_t thread;
bool nonstop;
USERS * users;
ADMINS * admins;
TARIFFS * tariffs;
- BASE_STORE * store;
+ STORE * store;
MODULE_SETTINGS settings;
const SETTINGS * stgSettings;
};
//-----------------------------------------------------------------------------
-
+#endif
#include <string>
#include "parser.h"
-#include "../../../users.h"
-#include "../../../admins.h"
-#include "../../../tariffs.h"
+#include "users.h"
+#include "admins.h"
+#include "tariffs.h"
#include "stg_logger.h"
using namespace std;
void SetAdmins(ADMINS * a);
void SetUsers(USERS * u);
void SetTariffs(TARIFFS * t);
- void SetStore(BASE_STORE * s);
+ void SetStore(STORE * s);
void SetStgSettings(const SETTINGS * s);
const string & GetAdminLogin();
uint32_t GetAdminIP();
ADMINS * admins;
USERS * users;
TARIFFS * tariffs;
- BASE_STORE * store;
+ STORE * store;
const SETTINGS * settings;
BASE_PARSER * currParser;
};
//-----------------------------------------------------------------------------
#endif //CONFIGPROTO_H
-
#include "resetable.h"
#include "stg_const.h"
-#include "base_store.h"
-#include "../../../admins.h"
-#include "../../../users.h"
+#include "store.h"
+#include "admins.h"
+#include "users.h"
#include "stg_message.h"
//-----------------------------------------------------------------------------
-class BASE_PARSER
-{
+class BASE_PARSER {
public:
BASE_PARSER()
: admins(NULL),
settings(NULL),
currAdmin(NULL),
depth(0)
- { };
- virtual ~BASE_PARSER(){};
+ { }
+ virtual ~BASE_PARSER() {}
virtual int ParseStart(void *data, const char *el, const char **attr) = 0;
virtual int ParseEnd(void *data, const char *el) = 0;
virtual void CreateAnswer() = 0;
- virtual void SetAnswerList(list<string> * ansList){answerList = ansList;};
+ virtual void SetAnswerList(list<string> * ansList) { answerList = ansList; }
- virtual void SetUsers(USERS * u){users = u;};
- virtual void SetAdmins(ADMINS * a){admins = a;};
- virtual void SetTariffs(TARIFFS * t){tariffs = t;};
- virtual void SetStore(BASE_STORE * s){store = s;};
- virtual void SetStgSettings(const SETTINGS * s){settings = s;};
+ virtual void SetUsers(USERS * u) { users = u; }
+ virtual void SetAdmins(ADMINS * a) { admins = a; }
+ virtual void SetTariffs(TARIFFS * t) { tariffs = t; }
+ virtual void SetStore(STORE * s) { store = s; }
+ virtual void SetStgSettings(const SETTINGS * s) { settings = s; }
- virtual void SetCurrAdmin(const ADMIN * cua){currAdmin = cua;};
- virtual string & GetStrError(){return strError;};
- virtual void Reset(){ answerList->clear(); depth = 0; };
+ virtual void SetCurrAdmin(const ADMIN * cua) { currAdmin = cua; }
+ virtual string & GetStrError() { return strError; }
+ virtual void Reset(){ answerList->clear(); depth = 0; }
protected:
string strError;
ADMINS * admins;
USERS * users;
TARIFFS * tariffs;
- BASE_STORE * store;
+ STORE * store;
const SETTINGS * settings;
const ADMIN * currAdmin;
int depth;
list<string> * answerList;
};
//-----------------------------------------------------------------------------
-class PARSER_GET_ADMINS: public BASE_PARSER
-{
+class PARSER_GET_ADMINS: public BASE_PARSER {
public:
int ParseStart(void *data, const char *el, const char **attr);
int ParseEnd(void *data, const char *el);
void CreateAnswer();
};
//-----------------------------------------------------------------------------
-class PARSER_ADD_ADMIN: public BASE_PARSER
-{
+class PARSER_ADD_ADMIN: public BASE_PARSER {
public:
int ParseStart(void *data, const char *el, const char **attr);
int ParseEnd(void *data, const char *el);
string adminToAdd;
};
//-----------------------------------------------------------------------------
-class PARSER_DEL_ADMIN: public BASE_PARSER
-{
+class PARSER_DEL_ADMIN: public BASE_PARSER {
public:
int ParseStart(void *data, const char *el, const char **attr);
int ParseEnd(void *data, const char *el);
string adminToDel;
};
//-----------------------------------------------------------------------------
-class PARSER_CHG_ADMIN: public BASE_PARSER
-{
+class PARSER_CHG_ADMIN: public BASE_PARSER {
public:
int ParseStart(void *data, const char *el, const char **attr);
int ParseEnd(void *data, const char *el);
RESETABLE<string> privAsString;
};
//-----------------------------------------------------------------------------
-class PARSER_GET_SERVER_INFO: public BASE_PARSER
-{
+class PARSER_GET_SERVER_INFO: public BASE_PARSER {
public:
int ParseStart(void *data, const char *el, const char **attr);
int ParseEnd(void *data, const char *el);
};
//-----------------------------------------------------------------------------
-class PARSER_GET_USER: public BASE_PARSER
-{
+class PARSER_GET_USER: public BASE_PARSER {
public:
PARSER_GET_USER();
- ~PARSER_GET_USER(){};
+ ~PARSER_GET_USER() {}
int ParseStart(void *data, const char *el, const char **attr);
int ParseEnd(void *data, const char *el);
void CreateAnswer();
string login;
};
//-----------------------------------------------------------------------------
-class PARSER_GET_USERS: public BASE_PARSER
-{
+class PARSER_GET_USERS: public BASE_PARSER {
public:
PARSER_GET_USERS();
int ParseStart(void *data, const char *el, const char **attr);
bool lastUpdateFound;
};
//-----------------------------------------------------------------------------
-class PARSER_GET_TARIFFS: public BASE_PARSER
-{
+class PARSER_GET_TARIFFS: public BASE_PARSER {
public:
int ParseStart(void *data, const char *el, const char **attr);
int ParseEnd(void *data, const char *el);
void CreateAnswer();
};
//-----------------------------------------------------------------------------
-class PARSER_ADD_TARIFF: public BASE_PARSER
-{
+class PARSER_ADD_TARIFF: public BASE_PARSER {
public:
int ParseStart(void *data, const char *el, const char **attr);
int ParseEnd(void *data, const char *el);
string tariffToAdd;
};
//-----------------------------------------------------------------------------
-class PARSER_DEL_TARIFF: public BASE_PARSER
-{
+class PARSER_DEL_TARIFF: public BASE_PARSER {
public:
int ParseStart(void *data, const char *el, const char **attr);
int ParseEnd(void *data, const char *el);
string tariffToDel;
};
//-----------------------------------------------------------------------------
-class PARSER_CHG_TARIFF: public BASE_PARSER
-{
+class PARSER_CHG_TARIFF: public BASE_PARSER {
public:
int ParseStart(void *data, const char *el, const char **attr);
int ParseEnd(void *data, const char *el);
TARIFF_DATA_RES td;
};
//-----------------------------------------------------------------------------/
-class PARSER_ADD_USER: public BASE_PARSER
-{
+class PARSER_ADD_USER: public BASE_PARSER {
public:
PARSER_ADD_USER();
- virtual ~PARSER_ADD_USER(){};
+ virtual ~PARSER_ADD_USER() {}
int ParseStart(void *data, const char *el, const char **attr);
int ParseEnd(void *data, const char *el);
void CreateAnswer();
string login;
};
//-----------------------------------------------------------------------------
-class PARSER_CHG_USER: public BASE_PARSER
-{
+class PARSER_CHG_USER: public BASE_PARSER {
public:
PARSER_CHG_USER();
~PARSER_CHG_USER();
int res;
};
//-----------------------------------------------------------------------------
-class PARSER_DEL_USER: public BASE_PARSER
-{
+class PARSER_DEL_USER: public BASE_PARSER {
public:
int ParseStart(void *data, const char *el, const char **attr);
int ParseEnd(void *data, const char *el);
user_iter u;
};
//-----------------------------------------------------------------------------
-class PARSER_CHECK_USER: public BASE_PARSER
-{
+class PARSER_CHECK_USER: public BASE_PARSER {
public:
int ParseStart(void *data, const char *el, const char **attr);
int ParseEnd(void *data, const char *el);
bool result;
};
//-----------------------------------------------------------------------------
-class PARSER_SEND_MESSAGE: public BASE_PARSER
-{
+class PARSER_SEND_MESSAGE: public BASE_PARSER {
public:
int ParseStart(void *data, const char *el, const char **attr);
int ParseEnd(void *data, const char *el);
user_iter u;
};
//-----------------------------------------------------------------------------
-#endif //PARSER_H
-
-
+#endif
#include <string>
#include <list>
-#include "base_plugin.h"
-#include "base_store.h"
+#include "plugin.h"
+#include "store.h"
#include "configproto.h"
using namespace std;
-extern "C" BASE_PLUGIN * GetPlugin();
+extern "C" PLUGIN * GetPlugin();
class STG_CONFIG;
//-----------------------------------------------------------------------------
-class STG_CONFIG_SETTINGS
-{
+class STG_CONFIG_SETTINGS {
public:
STG_CONFIG_SETTINGS();
- virtual ~STG_CONFIG_SETTINGS(){};
+ virtual ~STG_CONFIG_SETTINGS() {}
const string & GetStrError() const;
int ParseSettings(const MODULE_SETTINGS & s);
uint16_t GetPort();
int port;
};
//-----------------------------------------------------------------------------
-class STG_CONFIG: public BASE_PLUGIN
-{
+class STG_CONFIG: public PLUGIN {
public:
STG_CONFIG();
- virtual ~STG_CONFIG(){};
+ virtual ~STG_CONFIG() {}
- void SetUsers(USERS * u) { users = u; };
- void SetTariffs(TARIFFS * t) { tariffs = t; };
- void SetAdmins(ADMINS * a) { admins = a; };
- void SetStore(BASE_STORE * s) { store = s; };
- void SetTraffcounter(TRAFFCOUNTER *) {};
- void SetStgSettings(const SETTINGS * s) { stgConfigSettings = s; };
- void SetSettings(const MODULE_SETTINGS & s) { settings = s; };
+ void SetUsers(USERS * u) { users = u; }
+ void SetTariffs(TARIFFS * t) { tariffs = t; }
+ void SetAdmins(ADMINS * a) { admins = a; }
+ void SetStore(STORE * s) { store = s; }
+ void SetTraffcounter(TRAFFCOUNTER *) {}
+ void SetStgSettings(const SETTINGS * s) { stgConfigSettings = s; }
+ void SetSettings(const MODULE_SETTINGS & s) { settings = s; }
int ParseSettings();
int Start();
int Stop();
- int Reload() { return 0; };
- bool IsRunning() { return running; };
+ int Reload() { return 0; }
+ bool IsRunning() { return running; }
- const string & GetStrError() const { return errorStr; };
+ const string & GetStrError() const { return errorStr; }
string GetVersion() const;
uint16_t GetStartPosition() const;
uint16_t GetStopPosition() const;
USERS * users;
ADMINS * admins;
TARIFFS * tariffs;
- BASE_STORE * store;
+ STORE * store;
MODULE_SETTINGS settings;
const SETTINGS * stgSettings;
#include <unistd.h>
#include <signal.h>
+#include <algorithm>
+
#include "ping.h"
-#include "../../../user.h"
+#include "user.h"
+#include "stg_locker.h"
+#include "../../../settings.h"
+#include "../../../user_property.h"
class PING_CREATOR
{
//-----------------------------------------------------------------------------
// ëÌÁÓÓ ÄÌÑ ÐÏÉÓËÁ ÀÚÅÒÁ × ÓÐÉÓËÅ ÎÏÔÉÆÉËÁÔÏÒÏ×
template <typename varType>
-class IS_CONTAINS_USER: public binary_function<varType, user_iter, bool>
+class IS_CONTAINS_USER: public binary_function<varType, USER_PTR, bool>
{
public:
- IS_CONTAINS_USER(const user_iter & u) : user(u) {}
+ IS_CONTAINS_USER(const USER_PTR & u) : user(u) {}
bool operator()(varType notifier) const
{
return notifier.GetUser() == user;
};
private:
- const user_iter & user;
+ const USER_PTR & user;
};
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
-BASE_PLUGIN * GetPlugin()
+PLUGIN * GetPlugin()
{
return pc.GetPlugin();
}
vector<PARAM_VALUE>::const_iterator pvi;
pv.param = "PingDelay";
-pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv);
+pvi = std::find(s.moduleParams.begin(), s.moduleParams.end(), pv);
if (pvi == s.moduleParams.end())
{
errorStr = "Parameter \'PingDelay\' not found.";
return 0;
}
//-----------------------------------------------------------------------------
-int PING_SETTINGS::ParseIntInRange(const string & str, int min, int max, int * val)
+int PING_SETTINGS::ParseIntInRange(const std::string & str, int min, int max, int * val)
{
if (str2x(str.c_str(), *val))
{
pthread_mutex_destroy(&mutex);
}
//-----------------------------------------------------------------------------
-const string PING::GetVersion() const
+const std::string PING::GetVersion() const
{
return "Pinger v.1.01";
}
users = u;
}
//-----------------------------------------------------------------------------
-const string & PING::GetStrError() const
+const std::string & PING::GetStrError() const
{
return errorStr;
}
users->DelNotifierUserAdd(&onAddUserNotifier);
users->DelNotifierUserDel(&onDelUserNotifier);
-list<user_iter>::iterator users_iter;
+list<USER_PTR>::iterator users_iter;
users_iter = usersList.begin();
while (users_iter != usersList.end())
{
{
PING * ping = (PING*)d;
ping->isRunning = true;
-list<user_iter>::iterator iter;
+list<USER_PTR>::iterator iter;
uint32_t ip;
time_t t;
STG_LOCKER lock(&ping->mutex, __FILE__, __LINE__);
while (iter != ping->usersList.end())
{
- if ((*iter)->property.ips.ConstData().OnlyOneIP())
+ if ((*iter)->GetProperty().ips.ConstData().OnlyOneIP())
{
- ip = (*iter)->property.ips.ConstData()[0].ip;
+ ip = (*iter)->GetProperty().ips.ConstData()[0].ip;
if (ping->pinger.GetIPTime(ip, &t) == 0)
{
if (t)
return 100;
}
//-----------------------------------------------------------------------------
-void PING::SetUserNotifiers(user_iter u)
+void PING::SetUserNotifiers(USER_PTR u)
{
CHG_CURRIP_NOTIFIER_PING ChgCurrIPNotifier(*this, u);
CHG_IPS_NOTIFIER_PING ChgIPNotifier(*this, u);
ChgIPNotifierList.push_front(ChgIPNotifier);
u->AddCurrIPAfterNotifier(&(*ChgCurrIPNotifierList.begin()));
-u->property.ips.AddAfterNotifier(&(*ChgIPNotifierList.begin()));
+u->GetProperty().ips.AddAfterNotifier(&(*ChgIPNotifierList.begin()));
}
//-----------------------------------------------------------------------------
-void PING::UnSetUserNotifiers(user_iter u)
+void PING::UnSetUserNotifiers(USER_PTR u)
{
// --- CurrIP ---
IS_CONTAINS_USER<CHG_CURRIP_NOTIFIER_PING> IsContainsUserCurrIP(u);
if (IPIter != ChgIPNotifierList.end())
{
- IPIter->GetUser()->property.ips.DelAfterNotifier(&(*IPIter));
+ IPIter->GetUser()->GetProperty().ips.DelAfterNotifier(&(*IPIter));
ChgIPNotifierList.erase(IPIter);
}
// --- IP end ---
{
STG_LOCKER lock(&mutex, __FILE__, __LINE__);
-user_iter u;
+USER_PTR u;
int h = users->OpenSearch();
if (!h)
{
{
usersList.push_back(u);
SetUserNotifiers(u);
- if (u->property.ips.ConstData().OnlyOneIP())
+ if (u->GetProperty().ips.ConstData().OnlyOneIP())
{
- pinger.AddIP(u->property.ips.ConstData()[0].ip);
+ pinger.AddIP(u->GetProperty().ips.ConstData()[0].ip);
}
else
{
users->CloseSearch(h);
}
//-----------------------------------------------------------------------------
-void PING::AddUser(user_iter u)
+void PING::AddUser(USER_PTR u)
{
STG_LOCKER lock(&mutex, __FILE__, __LINE__);
usersList.push_back(u);
}
//-----------------------------------------------------------------------------
-void PING::DelUser(user_iter u)
+void PING::DelUser(USER_PTR u)
{
STG_LOCKER lock(&mutex, __FILE__, __LINE__);
UnSetUserNotifiers(u);
-list<user_iter>::iterator users_iter;
+list<USER_PTR>::iterator users_iter;
users_iter = usersList.begin();
while (users_iter != usersList.end())
}
}
//-----------------------------------------------------------------------------
-void ADD_USER_NONIFIER_PING::Notify(const user_iter & user)
+void ADD_USER_NONIFIER_PING::Notify(const USER_PTR & user)
{
ping.AddUser(user);
}
//-----------------------------------------------------------------------------
-void DEL_USER_NONIFIER_PING::Notify(const user_iter & user)
+void DEL_USER_NONIFIER_PING::Notify(const USER_PTR & user)
{
ping.DelUser(user);
}
#include <pthread.h>
#include <string>
+#include <list>
#include "os_int.h"
-#include "base_plugin.h"
+#include "plugin.h"
+#include "module_settings.h"
#include "notifer.h"
#include "user_ips.h"
#include "pinger.h"
-#include "../../../users.h"
+#include "users.h"
-using namespace std;
-
-extern "C" BASE_PLUGIN * GetPlugin();
+extern "C" PLUGIN * GetPlugin();
class PING;
+class USER;
+class SETTINGS;
//-----------------------------------------------------------------------------*/
-class CHG_CURRIP_NOTIFIER_PING: public PROPERTY_NOTIFIER_BASE<uint32_t>
-{
+class CHG_CURRIP_NOTIFIER_PING: public PROPERTY_NOTIFIER_BASE<uint32_t> {
public:
- CHG_CURRIP_NOTIFIER_PING(const PING & p, user_iter u) : user(u), ping(p) {}
+ CHG_CURRIP_NOTIFIER_PING(const PING & p, USER_PTR u) : user(u), ping(p) {}
void Notify(const uint32_t & oldIP, const uint32_t & newIP);
- user_iter GetUser() const { return user; }
+ USER_PTR GetUser() const { return user; }
private:
- user_iter user;
+ USER_PTR user;
const PING & ping;
};
//-----------------------------------------------------------------------------
-class CHG_IPS_NOTIFIER_PING: public PROPERTY_NOTIFIER_BASE<USER_IPS>
-{
+class CHG_IPS_NOTIFIER_PING: public PROPERTY_NOTIFIER_BASE<USER_IPS> {
public:
- CHG_IPS_NOTIFIER_PING(const PING & p, user_iter u) : user(u), ping(p) {}
+ CHG_IPS_NOTIFIER_PING(const PING & p, USER_PTR u) : user(u), ping(p) {}
void Notify(const USER_IPS & oldIPS, const USER_IPS & newIPS);
- user_iter GetUser() const { return user; }
+ USER_PTR GetUser() const { return user; }
private:
- user_iter user;
+ USER_PTR user;
const PING & ping;
};
//-----------------------------------------------------------------------------
-class ADD_USER_NONIFIER_PING: public NOTIFIER_BASE<user_iter>
-{
+class ADD_USER_NONIFIER_PING: public NOTIFIER_BASE<USER_PTR> {
public:
ADD_USER_NONIFIER_PING(PING & p) : ping(p) {}
virtual ~ADD_USER_NONIFIER_PING() {}
- void Notify(const user_iter & user);
+ void Notify(const USER_PTR & user);
private:
PING & ping;
};
//-----------------------------------------------------------------------------
-class DEL_USER_NONIFIER_PING: public NOTIFIER_BASE<user_iter>
-{
+class DEL_USER_NONIFIER_PING: public NOTIFIER_BASE<USER_PTR> {
public:
DEL_USER_NONIFIER_PING(PING & p) : ping(p) {}
virtual ~DEL_USER_NONIFIER_PING() {}
- void Notify(const user_iter & user);
+ void Notify(const USER_PTR & user);
private:
PING & ping;
};
//-----------------------------------------------------------------------------
-class PING_SETTINGS
-{
+class PING_SETTINGS {
public:
PING_SETTINGS();
virtual ~PING_SETTINGS() {}
- const string& GetStrError() const { return errorStr; }
+ const std::string & GetStrError() const { return errorStr; }
int ParseSettings(const MODULE_SETTINGS & s);
int GetPingDelay() const { return pingDelay; }
private:
- int ParseIntInRange(const string & str, int min, int max, int * val);
+ int ParseIntInRange(const std::string & str, int min, int max, int * val);
int pingDelay;
- mutable string errorStr;
+ mutable std::string errorStr;
};
//-----------------------------------------------------------------------------
-class PING: public BASE_PLUGIN
-{
+class PING : public PLUGIN {
friend class CHG_CURRIP_NOTIFIER_PING;
friend class CHG_IPS_NOTIFIER_PING;
public:
void SetTariffs(TARIFFS *) {}
void SetAdmins(ADMINS *) {}
void SetTraffcounter(TRAFFCOUNTER *) {}
- void SetStore(BASE_STORE *) {}
+ void SetStore(STORE *) {}
void SetStgSettings(const SETTINGS *) {}
void SetSettings(const MODULE_SETTINGS & s);
int ParseSettings();
int Reload() { return 0; }
bool IsRunning();
- const string & GetStrError() const;
- const string GetVersion() const;
+ const std::string & GetStrError() const;
+ const std::string GetVersion() const;
uint16_t GetStartPosition() const;
uint16_t GetStopPosition() const;
- void AddUser(user_iter u);
- void DelUser(user_iter u);
+ void AddUser(USER_PTR u);
+ void DelUser(USER_PTR u);
private:
void GetUsers();
- void SetUserNotifiers(user_iter u);
- void UnSetUserNotifiers(user_iter u);
+ void SetUserNotifiers(USER_PTR u);
+ void UnSetUserNotifiers(USER_PTR u);
static void * Run(void * d);
- mutable string errorStr;
+ mutable std::string errorStr;
PING_SETTINGS pingSettings;
MODULE_SETTINGS settings;
USERS * users;
- list<user_iter> usersList;
+ std::list<USER_PTR> usersList;
/*
ÍÙ ÄÏÌÖÎÙ ÐÅÒÅÐÒÏ×ÅÒÉÔØ ×ÏÚÍÏÖÎÏÓÔØ ÐÉÎÇÏ×ÁÎÉÑ ÀÚÅÒÁ ÐÒÉ ÉÚÍÅÎÅÎÉÉ
bool isRunning;
mutable STG_PINGER pinger;
- list<CHG_CURRIP_NOTIFIER_PING> ChgCurrIPNotifierList;
- list<CHG_IPS_NOTIFIER_PING> ChgIPNotifierList;
+ std::list<CHG_CURRIP_NOTIFIER_PING> ChgCurrIPNotifierList;
+ std::list<CHG_IPS_NOTIFIER_PING> ChgIPNotifierList;
ADD_USER_NONIFIER_PING onAddUserNotifier;
DEL_USER_NONIFIER_PING onDelUserNotifier;
#include <algorithm>
#include "radius.h"
+#include "store.h"
#include "common.h"
+#include "user_conf.h"
+#include "../../../user_property.h"
extern volatile const time_t stgTime;
-void InitEncrypt(BLOWFISH_CTX * ctx, const string & password);
+void InitEncrypt(BLOWFISH_CTX * ctx, const std::string & password);
void Decrypt(BLOWFISH_CTX * ctx, char * dst, const char * src, int len8);
void Encrypt(BLOWFISH_CTX * ctx, char * dst, const char * src, int len8);
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
-class RAD_CREATOR
-{
+class RAD_CREATOR {
private:
RADIUS * rad;
RAD_CREATOR()
: rad(new RADIUS())
{
- };
+ }
~RAD_CREATOR()
{
delete rad;
- };
+ }
RADIUS * GetPlugin()
{
return rad;
- };
+ }
};
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
-BASE_PLUGIN * GetPlugin()
+PLUGIN * GetPlugin()
{
return radc.GetPlugin();
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
-int RAD_SETTINGS::ParseIntInRange(const string & str, int min, int max, int * val)
+int RAD_SETTINGS::ParseIntInRange(const std::string & str, int min, int max, int * val)
{
if (str2x(str.c_str(), *val))
{
return 0;
}
//-----------------------------------------------------------------------------
-int RAD_SETTINGS::ParseServices(const vector<string> & str, list<string> * lst)
+int RAD_SETTINGS::ParseServices(const std::vector<std::string> & str, std::list<std::string> * lst)
{
- copy(str.begin(), str.end(), back_inserter(*lst));
- list<string>::iterator it(find(lst->begin(),
- lst->end(),
- "empty"));
- if (it != lst->end())
- *it = "";
+std::copy(str.begin(), str.end(), std::back_inserter(*lst));
+std::list<std::string>::iterator it(std::find(lst->begin(),
+ lst->end(),
+ "empty"));
+if (it != lst->end())
+ *it = "";
- return 0;
+return 0;
}
//-----------------------------------------------------------------------------
int RAD_SETTINGS::ParseSettings(const MODULE_SETTINGS & s)
{
int p;
PARAM_VALUE pv;
-vector<PARAM_VALUE>::const_iterator pvi;
+std::vector<PARAM_VALUE>::const_iterator pvi;
///////////////////////////
pv.param = "Port";
-pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv);
+pvi = std::find(s.moduleParams.begin(), s.moduleParams.end(), pv);
if (pvi == s.moduleParams.end())
{
errorStr = "Parameter \'Port\' not found.";
port = p;
///////////////////////////
pv.param = "Password";
-pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv);
+pvi = std::find(s.moduleParams.begin(), s.moduleParams.end(), pv);
if (pvi == s.moduleParams.end())
{
errorStr = "Parameter \'Password\' not found.";
password = pvi->value[0];
///////////////////////////
pv.param = "AuthServices";
-pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv);
+pvi = std::find(s.moduleParams.begin(), s.moduleParams.end(), pv);
if (pvi != s.moduleParams.end())
{
ParseServices(pvi->value, &authServices);
}
///////////////////////////
pv.param = "AcctServices";
-pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv);
+pvi = std::find(s.moduleParams.begin(), s.moduleParams.end(), pv);
if (pvi != s.moduleParams.end())
{
ParseServices(pvi->value, &acctServices);
settings = s;
}
//-----------------------------------------------------------------------------
-void RADIUS::SetStore(BASE_STORE * s)
+void RADIUS::SetStore(STORE * s)
{
store = s;
}
return isRunning;
}
//-----------------------------------------------------------------------------
-const string RADIUS::GetVersion() const
+const std::string RADIUS::GetVersion() const
{
return "RADIUS data access plugin v 0.6";
}
//-----------------------------------------------------------------------------
int RADIUS::Start()
{
-string password(radSettings.GetPassword());
+std::string password(radSettings.GetPassword());
authServices = radSettings.GetAuthServices();
acctServices = radSettings.GetAcctServices();
nonstop = false;
-map<string, RAD_SESSION>::iterator it;
+std::map<std::string, RAD_SESSION>::iterator it;
for (it = sessions.begin(); it != sessions.end(); ++it)
{
- user_iter ui;
+ USER_PTR ui;
if (users->FindByName(it->second.userName, &ui))
{
ui->Unauthorize(this);
//-----------------------------------------------------------------------------
int RADIUS::ProcessAuthPacket(RAD_PACKET * packet)
{
-user_iter ui;
+USER_PTR ui;
if (!CanAcctService((char *)packet->service))
{
//-----------------------------------------------------------------------------
int RADIUS::ProcessPostAuthPacket(RAD_PACKET * packet)
{
-user_iter ui;
+USER_PTR ui;
if (!CanAcctService((char *)packet->service))
{
// I think that only Framed-User services has sense to be accountable
// So we have to supply a Framed-IP
-USER_IPS ips = ui->property.ips;
+USER_IPS ips = ui->GetProperty().ips;
packet->packetType = RAD_ACCEPT_PACKET;
// Additional checking for Framed-User service
//-----------------------------------------------------------------------------
int RADIUS::ProcessAcctStartPacket(RAD_PACKET * packet)
{
-user_iter ui;
+USER_PTR ui;
if (!FindUser(&ui, (char *)packet->login))
{
packet->packetType = RAD_REJECT_PACKET;
return -1;
}
- USER_IPS ips = ui->property.ips;
+ USER_IPS ips = ui->GetProperty().ips;
if (ui->Authorize(ips[0].ip, "", 0xffFFffFF, this))
{
printfd(__FILE__, "RADIUS::ProcessAcctStartPacket cannot authorize user '%s'\n", packet->login);
//-----------------------------------------------------------------------------
int RADIUS::ProcessAcctStopPacket(RAD_PACKET * packet)
{
-map<string, RAD_SESSION>::iterator sid;
+std::map<std::string, RAD_SESSION>::iterator sid;
if ((sid = sessions.find((const char *)packet->sessid)) == sessions.end())
{
return -1;
}
-user_iter ui;
+USER_PTR ui;
if (!FindUser(&ui, sid->second.userName))
{
return 0;
}
//-----------------------------------------------------------------------------
-void RADIUS::PrintServices(const list<string> & svcs)
+void RADIUS::PrintServices(const std::list<std::string> & svcs)
{
- for_each(svcs.begin(), svcs.end(), Printer());
+for_each(svcs.begin(), svcs.end(), Printer());
}
//-----------------------------------------------------------------------------
-bool RADIUS::FindUser(user_iter * ui, const std::string & login) const
+bool RADIUS::FindUser(USER_PTR * ui, const std::string & login) const
{
if (users->FindByName(login, ui))
{
//-----------------------------------------------------------------------------
bool RADIUS::CanAuthService(const std::string & svc) const
{
- return find(authServices.begin(), authServices.end(), svc) != authServices.end();
+return find(authServices.begin(), authServices.end(), svc) != authServices.end();
}
//-----------------------------------------------------------------------------
bool RADIUS::CanAcctService(const std::string & svc) const
{
- return find(acctServices.begin(), acctServices.end(), svc) != acctServices.end();
+return find(acctServices.begin(), acctServices.end(), svc) != acctServices.end();
}
//-----------------------------------------------------------------------------
bool RADIUS::IsAllowedService(const std::string & svc) const
{
- return CanAuthService(svc) || CanAcctService(svc);
+return CanAuthService(svc) || CanAcctService(svc);
}
//-----------------------------------------------------------------------------
bool RADIUS::WaitPackets(int sd) const
}
//-----------------------------------------------------------------------------
inline
-void InitEncrypt(BLOWFISH_CTX * ctx, const string & password)
+void InitEncrypt(BLOWFISH_CTX * ctx, const std::string & password)
{
unsigned char keyL[RAD_PASSWORD_LEN]; // Пароль для шифровки
memset(keyL, 0, RAD_PASSWORD_LEN);
#include <cstdlib>
#include <string>
#include <list>
+#include <map>
+#include <vector>
#include "os_int.h"
-#include "base_auth.h"
+#include "auth.h"
+#include "module_settings.h"
#include "notifer.h"
#include "user_ips.h"
-#include "../../../user.h"
-#include "../../../users.h"
+#include "user.h"
+#include "users.h"
#include "blowfish.h"
#include "rad_packets.h"
-using namespace std;
-
-extern "C" BASE_PLUGIN * GetPlugin();
+extern "C" PLUGIN * GetPlugin();
#define RAD_DEBUG (1)
class RADIUS;
//-----------------------------------------------------------------------------
-class RAD_SETTINGS
-{
+class RAD_SETTINGS {
public:
RAD_SETTINGS() : port(0) {}
virtual ~RAD_SETTINGS() {}
int ParseSettings(const MODULE_SETTINGS & s);
uint16_t GetPort() const { return port; }
const std::string & GetPassword() const { return password; }
- const list<string> & GetAuthServices() const { return authServices; }
- const list<string> & GetAcctServices() const { return acctServices; }
+ const std::list<string> & GetAuthServices() const { return authServices; }
+ const std::list<string> & GetAcctServices() const { return acctServices; }
private:
- int ParseIntInRange(const string & str, int min, int max, int * val);
- int ParseServices(const vector<string> & str, list<string> * lst);
+ int ParseIntInRange(const std::string & str, int min, int max, int * val);
+ int ParseServices(const std::vector<std::string> & str, std::list<std::string> * lst);
uint16_t port;
- string errorStr;
- string password;
- list<string> authServices;
- list<string> acctServices;
+ std::string errorStr;
+ std::string password;
+ std::list<std::string> authServices;
+ std::list<std::string> acctServices;
};
//-----------------------------------------------------------------------------
struct RAD_SESSION {
std::string serviceType;
};
//-----------------------------------------------------------------------------
-class RADIUS :public BASE_AUTH
-{
+class RADIUS :public AUTH {
public:
RADIUS();
- virtual ~RADIUS(){};
+ virtual ~RADIUS() {};
void SetUsers(USERS * u);
- void SetTariffs(TARIFFS *){};
- void SetAdmins(ADMINS *){};
- void SetTraffcounter(TRAFFCOUNTER *){};
- void SetStore(BASE_STORE * );
+ void SetTariffs(TARIFFS *) {}
+ void SetAdmins(ADMINS *) {}
+ void SetTraffcounter(TRAFFCOUNTER *) {}
+ void SetStore(STORE * );
void SetStgSettings(const SETTINGS * s);
void SetSettings(const MODULE_SETTINGS & s);
int ParseSettings();
int Start();
int Stop();
- int Reload() { return 0; };
+ int Reload() { return 0; }
bool IsRunning();
- const string & GetStrError() const { return errorStr; };
- const string GetVersion() const;
+ const std::string & GetStrError() const { return errorStr; }
+ const std::string GetVersion() const;
uint16_t GetStartPosition() const;
uint16_t GetStopPosition() const;
- int SendMessage(const STG_MSG &, uint32_t) const { return 0; };
+ int SendMessage(const STG_MSG &, uint32_t) const { return 0; }
private:
static void * Run(void *);
int ProcessAcctUpdatePacket(RAD_PACKET * packet);
int ProcessAcctOtherPacket(RAD_PACKET * packet);
- bool FindUser(user_iter * ui, const std::string & login) const;
+ bool FindUser(USER_PTR * ui, const std::string & login) const;
bool CanAuthService(const std::string & svc) const;
bool CanAcctService(const std::string & svc) const;
bool IsAllowedService(const std::string & svc) const;
BLOWFISH_CTX ctx;
- mutable string errorStr;
+ mutable std::string errorStr;
RAD_SETTINGS radSettings;
MODULE_SETTINGS settings;
- list<string> authServices;
- list<string> acctServices;
- map<string, RAD_SESSION> sessions;
+ std::list<std::string> authServices;
+ std::list<std::string> acctServices;
+ std::map<std::string, RAD_SESSION> sessions;
bool nonstop;
bool isRunning;
USERS * users;
const SETTINGS * stgSettings;
- const BASE_STORE * store;
+ const STORE * store;
pthread_t thread;
pthread_mutex_t mutex;
#include "common.h"
#include "ur_functor.h"
#include "send_functor.h"
+#include "stg_locker.h"
+#include "../../../user_property.h"
extern volatile const time_t stgTime;
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
-BASE_PLUGIN * GetPlugin()
+PLUGIN * GetPlugin()
{
return rsc.GetPlugin();
}
{
}
//-----------------------------------------------------------------------------
-RS_USER::RS_USER(const std::vector<uint32_t> & r, user_iter it)
+RS_USER::RS_USER(const std::vector<uint32_t> & r, USER_PTR it)
: lastSentTime(0),
user(it),
routers(r),
//-----------------------------------------------------------------------------
bool REMOTE_SCRIPT::GetUsers()
{
-user_iter u;
+USER_PTR u;
int h = users->OpenSearch();
if (!h)
return false;
}
//-----------------------------------------------------------------------------
-void REMOTE_SCRIPT::ChangedIP(user_iter u, uint32_t oldIP, uint32_t newIP)
+void REMOTE_SCRIPT::ChangedIP(USER_PTR u, uint32_t oldIP, uint32_t newIP)
{
/*
* When ip changes process looks like:
return std::vector<uint32_t>();
}
//-----------------------------------------------------------------------------
-string REMOTE_SCRIPT::GetUserParam(user_iter u, const string & paramName) const
+string REMOTE_SCRIPT::GetUserParam(USER_PTR u, const string & paramName) const
{
string value = "";
if (strcasecmp(paramName.c_str(), "cash") == 0)
- strprintf(&value, "%f", u->property.cash.Get());
+ strprintf(&value, "%f", u->GetProperty().cash.Get());
else
if (strcasecmp(paramName.c_str(), "freeMb") == 0)
- strprintf(&value, "%f", u->property.freeMb.Get());
+ strprintf(&value, "%f", u->GetProperty().freeMb.Get());
else
if (strcasecmp(paramName.c_str(), "passive") == 0)
- strprintf(&value, "%d", u->property.passive.Get());
+ strprintf(&value, "%d", u->GetProperty().passive.Get());
else
if (strcasecmp(paramName.c_str(), "disabled") == 0)
- strprintf(&value, "%d", u->property.disabled.Get());
+ strprintf(&value, "%d", u->GetProperty().disabled.Get());
else
if (strcasecmp(paramName.c_str(), "alwaysOnline") == 0)
- strprintf(&value, "%d", u->property.alwaysOnline.Get());
+ strprintf(&value, "%d", u->GetProperty().alwaysOnline.Get());
else
if (strcasecmp(paramName.c_str(), "tariffName") == 0 ||
strcasecmp(paramName.c_str(), "tariff") == 0)
- value = "\"" + u->property.tariffName.Get() + "\"";
+ value = "\"" + u->GetProperty().tariffName.Get() + "\"";
else
if (strcasecmp(paramName.c_str(), "nextTariff") == 0)
- value = "\"" + u->property.nextTariff.Get() + "\"";
+ value = "\"" + u->GetProperty().nextTariff.Get() + "\"";
else
if (strcasecmp(paramName.c_str(), "address") == 0)
- value = "\"" + u->property.address.Get() + "\"";
+ value = "\"" + u->GetProperty().address.Get() + "\"";
else
if (strcasecmp(paramName.c_str(), "note") == 0)
- value = "\"" + u->property.note.Get() + "\"";
+ value = "\"" + u->GetProperty().note.Get() + "\"";
else
if (strcasecmp(paramName.c_str(), "group") == 0)
- value = "\"" + u->property.group.Get() + "\"";
+ value = "\"" + u->GetProperty().group.Get() + "\"";
else
if (strcasecmp(paramName.c_str(), "email") == 0)
- value = "\"" + u->property.email.Get() + "\"";
+ value = "\"" + u->GetProperty().email.Get() + "\"";
else
if (strcasecmp(paramName.c_str(), "realName") == 0)
- value = "\"" + u->property.realName.Get() + "\"";
+ value = "\"" + u->GetProperty().realName.Get() + "\"";
else
if (strcasecmp(paramName.c_str(), "credit") == 0)
- strprintf(&value, "%f", u->property.credit.Get());
+ strprintf(&value, "%f", u->GetProperty().credit.Get());
else
if (strcasecmp(paramName.c_str(), "userdata0") == 0)
- value = "\"" + u->property.userdata0.Get() + "\"";
+ value = "\"" + u->GetProperty().userdata0.Get() + "\"";
else
if (strcasecmp(paramName.c_str(), "userdata1") == 0)
- value = "\"" + u->property.userdata1.Get() + "\"";
+ value = "\"" + u->GetProperty().userdata1.Get() + "\"";
else
if (strcasecmp(paramName.c_str(), "userdata2") == 0)
- value = "\"" + u->property.userdata2.Get() + "\"";
+ value = "\"" + u->GetProperty().userdata2.Get() + "\"";
else
if (strcasecmp(paramName.c_str(), "userdata3") == 0)
- value = "\"" + u->property.userdata3.Get() + "\"";
+ value = "\"" + u->GetProperty().userdata3.Get() + "\"";
else
if (strcasecmp(paramName.c_str(), "userdata4") == 0)
- value = "\"" + u->property.userdata4.Get() + "\"";
+ value = "\"" + u->GetProperty().userdata4.Get() + "\"";
else
if (strcasecmp(paramName.c_str(), "userdata5") == 0)
- value = "\"" + u->property.userdata5.Get() + "\"";
+ value = "\"" + u->GetProperty().userdata5.Get() + "\"";
else
if (strcasecmp(paramName.c_str(), "userdata6") == 0)
- value = "\"" + u->property.userdata6.Get() + "\"";
+ value = "\"" + u->GetProperty().userdata6.Get() + "\"";
else
if (strcasecmp(paramName.c_str(), "userdata7") == 0)
- value = "\"" + u->property.userdata7.Get() + "\"";
+ value = "\"" + u->GetProperty().userdata7.Get() + "\"";
else
if (strcasecmp(paramName.c_str(), "userdata8") == 0)
- value = "\"" + u->property.userdata8.Get() + "\"";
+ value = "\"" + u->GetProperty().userdata8.Get() + "\"";
else
if (strcasecmp(paramName.c_str(), "userdata9") == 0)
- value = "\"" + u->property.userdata9.Get() + "\"";
+ value = "\"" + u->GetProperty().userdata9.Get() + "\"";
else
if (strcasecmp(paramName.c_str(), "enabledDirs") == 0)
value = u->GetEnabledDirs();
return value;
}
//-----------------------------------------------------------------------------
-void REMOTE_SCRIPT::SetUserNotifier(user_iter u)
+void REMOTE_SCRIPT::SetUserNotifier(USER_PTR u)
{
RS_CHG_AFTER_NOTIFIER<uint32_t> afterChgIPNotifier(*this, u);
u->AddCurrIPAfterNotifier(&(*afterChgIPNotifierList.begin()));
}
//-----------------------------------------------------------------------------
-void REMOTE_SCRIPT::UnSetUserNotifier(user_iter u)
+void REMOTE_SCRIPT::UnSetUserNotifier(USER_PTR u)
{
list<RS_CHG_AFTER_NOTIFIER<uint32_t> >::iterator ipAIter;
std::list<list<RS_CHG_AFTER_NOTIFIER<uint32_t> >::iterator> toErase;
#include <cstring>
#include <string>
+#include <list>
#include <map>
#include <functional>
#include <utility>
-#include "base_store.h"
+#include "plugin.h"
+#include "store.h"
+#include "module_settings.h"
#include "os_int.h"
#include "notifer.h"
#include "user_ips.h"
-#include "../../../user.h"
-#include "../../../users.h"
+#include "user.h"
+#include "users.h"
#include "blowfish.h"
#include "rs_packets.h"
#include "nrmap_parser.h"
-extern "C" BASE_PLUGIN * GetPlugin();
+extern "C" PLUGIN * GetPlugin();
#define RS_DEBUG (1)
#define MAX_SHORT_PCKT (3)
class REMOTE_SCRIPT;
+class SETTINGS;
//-----------------------------------------------------------------------------
-class RS_ADD_USER_NONIFIER: public NOTIFIER_BASE<user_iter>
-{
+class RS_ADD_USER_NONIFIER: public NOTIFIER_BASE<USER_PTR> {
public:
RS_ADD_USER_NONIFIER(REMOTE_SCRIPT & r) : rs(r) {}
virtual ~RS_ADD_USER_NONIFIER() {}
- void Notify(const user_iter & user);
+ void Notify(const USER_PTR & user);
private:
REMOTE_SCRIPT & rs;
};
//-----------------------------------------------------------------------------
-class RS_DEL_USER_NONIFIER: public NOTIFIER_BASE<user_iter>
-{
+class RS_DEL_USER_NONIFIER: public NOTIFIER_BASE<USER_PTR> {
public:
RS_DEL_USER_NONIFIER(REMOTE_SCRIPT & r) : rs(r) {}
virtual ~RS_DEL_USER_NONIFIER() {}
- void Notify(const user_iter & user);
+ void Notify(const USER_PTR & user);
private:
REMOTE_SCRIPT & rs;
};
//-----------------------------------------------------------------------------
template <typename varParamType>
-class RS_CHG_AFTER_NOTIFIER: public PROPERTY_NOTIFIER_BASE<varParamType>
-{
+class RS_CHG_AFTER_NOTIFIER: public PROPERTY_NOTIFIER_BASE<varParamType> {
public:
- RS_CHG_AFTER_NOTIFIER(REMOTE_SCRIPT & r, user_iter u) : user(u), rs(r) {}
+ RS_CHG_AFTER_NOTIFIER(REMOTE_SCRIPT & r, USER_PTR u) : user(u), rs(r) {}
void Notify(const varParamType & oldValue, const varParamType & newValue);
- user_iter GetUser() {return user; }
+ USER_PTR GetUser() {return user; }
private:
- user_iter user;
+ USER_PTR user;
REMOTE_SCRIPT & rs;
};
//-----------------------------------------------------------------------------
-struct RS_USER
-{
+struct RS_USER {
RS_USER();
-RS_USER(const std::vector<uint32_t> & r, user_iter it);
+RS_USER(const std::vector<uint32_t> & r, USER_PTR it);
time_t lastSentTime;
-user_iter user;
+USER_PTR user;
std::vector<uint32_t> routers;
int shortPacketsCount;
};
//-----------------------------------------------------------------------------
-class RS_SETTINGS
-{
+class RS_SETTINGS {
public:
RS_SETTINGS();
- virtual ~RS_SETTINGS() {};
- const std::string & GetStrError() const { return errorStr; };
- int ParseSettings(const MODULE_SETTINGS & s);
- int GetSendPeriod() const { return sendPeriod; };
- int GetPort() const { return port; };
- const std::vector<NET_ROUTER> & GetSubnetsMap() const { return netRouters; };
- const std::vector<std::string> & GetUserParams() const { return userParams; };
- const std::string & GetPassword() const { return password; };
- const std::string & GetMapFileName() const { return subnetFile; };
+ virtual ~RS_SETTINGS() {}
+ const std::string & GetStrError() const { return errorStr; }
+ int ParseSettings(const MODULE_SETTINGS & s)
+ int GetSendPeriod() const { return sendPeriod; }
+ int GetPort() const { return port; }
+ const std::vector<NET_ROUTER> & GetSubnetsMap() const { return netRouters; }
+ const std::vector<std::string> & GetUserParams() const { return userParams; }
+ const std::string & GetPassword() const { return password; }
+ const std::string & GetMapFileName() const { return subnetFile; }
private:
int ParseIntInRange(const std::string & str, int min, int max, int * val);
uint16_t port;
string errorStr;
std::vector<NET_ROUTER> netRouters;
- std::vector<string> userParams;
+ std::vector<string> userParams;
string password;
string subnetFile;
};
//-----------------------------------------------------------------------------
-class REMOTE_SCRIPT : public BASE_PLUGIN
-{
+class REMOTE_SCRIPT : public PLUGIN {
public:
REMOTE_SCRIPT();
virtual ~REMOTE_SCRIPT();
- void SetUsers(USERS * u) { users = u; };
- void SetTariffs(TARIFFS *) {};
- void SetAdmins(ADMINS *) {};
- void SetTraffcounter(TRAFFCOUNTER *) {};
- void SetStore(BASE_STORE *) {};
- void SetStgSettings(const SETTINGS *) {};
- void SetSettings(const MODULE_SETTINGS & s) { settings = s; };
+ void SetUsers(USERS * u) { users = u; }
+ void SetTariffs(TARIFFS *) {}
+ void SetAdmins(ADMINS *) {}
+ void SetTraffcounter(TRAFFCOUNTER *) {}
+ void SetStore(STORE *) {}
+ void SetStgSettings(const SETTINGS *) {}
+ void SetSettings(const MODULE_SETTINGS & s) { settings = s; }
int ParseSettings();
int Start();
int Stop();
int Reload();
- bool IsRunning() { return isRunning; };
+ bool IsRunning() { return isRunning; }
- const std::string & GetStrError() const { return errorStr; };
- const std::string GetVersion() const { return "Remote script v 0.3"; };
- uint16_t GetStartPosition() const { return 20; };
- uint16_t GetStopPosition() const { return 20; };
+ const std::string & GetStrError() const { return errorStr; }
+ const std::string GetVersion() const { return "Remote script v 0.3"; }
+ uint16_t GetStartPosition() const { return 20; }
+ uint16_t GetStopPosition() const { return 20; }
- void DelUser(user_iter u) { UnSetUserNotifier(u); };
- void AddUser(user_iter u) { SetUserNotifier(u); };
+ void DelUser(USER_PTR u) { UnSetUserNotifier(u); }
+ void AddUser(USER_PTR u) { SetUserNotifier(u); }
- void ChangedIP(user_iter u, uint32_t oldIP, uint32_t newIP);
+ void ChangedIP(USER_PTR u, uint32_t oldIP, uint32_t newIP);
private:
static void * Run(void *);
std::vector<uint32_t> IP2Routers(uint32_t ip);
bool GetUsers();
- std::string GetUserParam(user_iter u, const std::string & paramName) const;
+ std::string GetUserParam(USER_PTR u, const std::string & paramName) const;
- void SetUserNotifier(user_iter u);
- void UnSetUserNotifier(user_iter u);
+ void SetUserNotifier(USER_PTR u);
+ void UnSetUserNotifier(USER_PTR u);
void InitEncrypt(BLOWFISH_CTX * ctx, const string & password) const;
void Encrypt(BLOWFISH_CTX * ctx, char * dst, const char * src, size_t len8) const;
friend class DisconnectUser;
};
//-----------------------------------------------------------------------------
-class DisconnectUser : public std::unary_function<std::pair<const uint32_t, RS_USER> &, void>
-{
+class DisconnectUser : public std::unary_function<std::pair<const uint32_t, RS_USER> &, void> {
public:
- DisconnectUser(REMOTE_SCRIPT & rs) : rscript(rs) {};
+ DisconnectUser(REMOTE_SCRIPT & rs) : rscript(rs) {}
void operator()(std::pair<const uint32_t, RS_USER> & p)
{
rscript.Send(p.first, p.second, true);
REMOTE_SCRIPT & rscript;
};
//-----------------------------------------------------------------------------
-inline void RS_ADD_USER_NONIFIER::Notify(const user_iter & user)
+inline void RS_ADD_USER_NONIFIER::Notify(const USER_PTR & user)
{
printfd(__FILE__, "ADD_USER_NONIFIER\n");
rs.AddUser(user);
}
//-----------------------------------------------------------------------------
-inline void RS_DEL_USER_NONIFIER::Notify(const user_iter & user)
+inline void RS_DEL_USER_NONIFIER::Notify(const USER_PTR & user)
{
printfd(__FILE__, "DEL_USER_NONIFIER\n");
rs.DelUser(user);
#include <string>
-#include "base_settings.h"
-#include "base_store.h"
+#include "module_settings.h"
+#include "store.h"
#include "conffiles.h"
#include "user_traff.h"
-using namespace std;
//-----------------------------------------------------------------------------
-extern "C" BASE_STORE * GetStore();
+extern "C" STORE * GetStore();
//-----------------------------------------------------------------------------
-class FILES_STORE_SETTINGS//: public BASE_SETTINGS
-{
+class FILES_STORE_SETTINGS {
public:
FILES_STORE_SETTINGS();
virtual ~FILES_STORE_SETTINGS();
virtual int ParseSettings(const MODULE_SETTINGS & s);
- virtual const string & GetStrError() const;
+ virtual const std::string & GetStrError() const;
- string GetWorkDir() const;
- string GetUsersDir() const;
- string GetAdminsDir() const;
- string GetTariffsDir() const;
+ std::string GetWorkDir() const;
+ std::string GetUsersDir() const;
+ std::string GetAdminsDir() const;
+ std::string GetTariffsDir() const;
mode_t GetStatMode() const;
mode_t GetStatModeDir() const;
int User2UID(const char * user, uid_t * uid);
int Group2GID(const char * gr, gid_t * gid);
int Str2Mode(const char * str, mode_t * mode);
- int ParseOwner(const vector<PARAM_VALUE> & moduleParams, const string & owner, uid_t * uid);
- int ParseGroup(const vector<PARAM_VALUE> & moduleParams, const string & group, uid_t * uid);
- int ParseMode(const vector<PARAM_VALUE> & moduleParams, const string & modeStr, mode_t * mode);
- int ParseYesNo(const string & value, bool * val);
+ int ParseOwner(const std::vector<PARAM_VALUE> & moduleParams, const std::string & owner, uid_t * uid);
+ int ParseGroup(const std::vector<PARAM_VALUE> & moduleParams, const std::string & group, uid_t * uid);
+ int ParseMode(const std::vector<PARAM_VALUE> & moduleParams, const std::string & modeStr, mode_t * mode);
+ int ParseYesNo(const std::string & value, bool * val);
- string errorStr;
+ std::string errorStr;
- string workDir;
- string usersDir;
- string adminsDir;
- string tariffsDir;
+ std::string workDir;
+ std::string usersDir;
+ std::string adminsDir;
+ std::string tariffsDir;
mode_t statMode;
uid_t statUID;
bool readBak;
};
//-----------------------------------------------------------------------------
-class FILES_STORE: public BASE_STORE
-{
+class FILES_STORE: public STORE {
public:
FILES_STORE();
virtual ~FILES_STORE();
- virtual const string & GetStrError() const;
+ virtual const std::string & GetStrError() const;
//User
- virtual int GetUsersList(vector<string> * usersList) const;
- virtual int AddUser(const string & login) const;
- virtual int DelUser(const string & login) const;
- virtual int SaveUserStat(const USER_STAT & stat, const string & login) const;
- virtual int SaveUserConf(const USER_CONF & conf, const string & login) const;
-
- virtual int RestoreUserStat(USER_STAT * stat, const string & login) const;
- virtual int RestoreUserConf(USER_CONF * conf, const string & login) const;
-
- virtual int WriteUserChgLog(const string & login,
- const string & admLogin,
- uint32_t admIP,
- const string & paramName,
- const string & oldValue,
- const string & newValue,
- const string & message = "") const;
- virtual int WriteUserConnect(const string & login, uint32_t ip) const;
- virtual int WriteUserDisconnect(const string & login,
+ virtual int GetUsersList(std::vector<std::string> * usersList) const;
+ virtual int AddUser(const std::string & login) const;
+ virtual int DelUser(const std::string & login) const;
+ virtual int SaveUserStat(const USER_STAT & stat, const std::string & login) const;
+ virtual int SaveUserConf(const USER_CONF & conf, const std::string & login) const;
+
+ virtual int RestoreUserStat(USER_STAT * stat, const std::string & login) const;
+ virtual int RestoreUserConf(USER_CONF * conf, const std::string & login) const;
+
+ virtual int WriteUserChgLog(const std::string & login,
+ const std::string & admLogin,
+ uint32_t admIP,
+ const std::string & paramName,
+ const std::string & oldValue,
+ const std::string & newValue,
+ const std::string & message = "") const;
+ virtual int WriteUserConnect(const std::string & login, uint32_t ip) const;
+ virtual int WriteUserDisconnect(const std::string & login,
const DIR_TRAFF & up,
const DIR_TRAFF & down,
const DIR_TRAFF & sessionUp,
double freeMb,
const std::string & reason) const;
- virtual int WriteDetailedStat(const map<IP_DIR_PAIR, STAT_NODE> & statTree,
+ virtual int WriteDetailedStat(const TRAFF_STAT & statTree,
time_t lastStat,
- const string & login) const;
-
- virtual int AddMessage(STG_MSG * msg, const string & login) const;
- virtual int EditMessage(const STG_MSG & msg, const string & login) const;
- virtual int GetMessage(uint64_t id, STG_MSG * msg, const string & login) const;
- virtual int DelMessage(uint64_t id, const string & login) const;
- virtual int GetMessageHdrs(vector<STG_MSG_HDR> * hdrsList, const string & login) const;
- virtual int ReadMessage(const string & fileName,
+ const std::string & login) const;
+
+ virtual int AddMessage(STG_MSG * msg, const std::string & login) const;
+ virtual int EditMessage(const STG_MSG & msg, const std::string & login) const;
+ virtual int GetMessage(uint64_t id, STG_MSG * msg, const std::string & login) const;
+ virtual int DelMessage(uint64_t id, const std::string & login) const;
+ virtual int GetMessageHdrs(std::vector<STG_MSG_HDR> * hdrsList, const std::string & login) const;
+ virtual int ReadMessage(const std::string & fileName,
STG_MSG_HDR * hdr,
- string * text) const;
+ std::string * text) const;
- virtual int SaveMonthStat(const USER_STAT & stat, int month, int year, const string & login) const;
+ virtual int SaveMonthStat(const USER_STAT & stat, int month, int year, const std::string & login) const;
//Admin
- virtual int GetAdminsList(vector<string> * adminsList) const;
- virtual int AddAdmin(const string & login) const;
- virtual int DelAdmin(const string & login) const;
- virtual int RestoreAdmin(ADMIN_CONF * ac, const string & login) const;
+ virtual int GetAdminsList(std::vector<std::string> * adminsList) const;
+ virtual int AddAdmin(const std::string & login) const;
+ virtual int DelAdmin(const std::string & login) const;
+ virtual int RestoreAdmin(ADMIN_CONF * ac, const std::string & login) const;
virtual int SaveAdmin(const ADMIN_CONF & ac) const;
//Tariff
- virtual int GetTariffsList(vector<string> * tariffsList) const;
- virtual int AddTariff(const string & name) const;
- virtual int DelTariff(const string & name) const;
- virtual int SaveTariff(const TARIFF_DATA & td, const string & tariffName) const;
- virtual int RestoreTariff(TARIFF_DATA * td, const string & tariffName) const;
+ virtual int GetTariffsList(std::vector<std::string> * tariffsList) const;
+ virtual int AddTariff(const std::string & name) const;
+ virtual int DelTariff(const std::string & name) const;
+ virtual int SaveTariff(const TARIFF_DATA & td, const std::string & tariffName) const;
+ virtual int RestoreTariff(TARIFF_DATA * td, const std::string & tariffName) const;
//Corparation
- virtual int GetCorpsList(vector<string> *) const {return 0;};
- virtual int SaveCorp(const CORP_CONF &) const {return 0;};
- virtual int RestoreCorp(CORP_CONF *, const string &) const {return 0;};
- virtual int AddCorp(const string &) const {return 0;};
- virtual int DelCorp(const string &) const {return 0;};
+ virtual int GetCorpsList(std::vector<std::string> *) const { return 0; }
+ virtual int SaveCorp(const CORP_CONF &) const { return 0; }
+ virtual int RestoreCorp(CORP_CONF *, const std::string &) const { return 0; }
+ virtual int AddCorp(const std::string &) const { return 0; }
+ virtual int DelCorp(const std::string &) const { return 0; }
// Services
- virtual int GetServicesList(vector<string> *) const {return 0;};
- virtual int SaveService(const SERVICE_CONF &) const {return 0;};
- virtual int RestoreService(SERVICE_CONF *, const string &) const {return 0;};
- virtual int AddService(const string &) const {return 0;};
- virtual int DelService(const string &) const {return 0;};
+ virtual int GetServicesList(std::vector<std::string> *) const { return 0; }
+ virtual int SaveService(const SERVICE_CONF &) const { return 0; }
+ virtual int RestoreService(SERVICE_CONF *, const std::string &) const { return 0; }
+ virtual int AddService(const std::string &) const { return 0; }
+ virtual int DelService(const std::string &) const { return 0; }
- //virtual BASE_SETTINGS * GetStoreSettings();
virtual void SetSettings(const MODULE_SETTINGS & s);
virtual int ParseSettings();
- virtual const string & GetVersion() const;
+ virtual const std::string & GetVersion() const;
private:
- virtual int RestoreUserStat(USER_STAT * stat, const string & login, const string & fileName) const;
- virtual int RestoreUserConf(USER_CONF * conf, const string & login, const string & fileName) const;
+ virtual int RestoreUserStat(USER_STAT * stat, const std::string & login, const std::string & fileName) const;
+ virtual int RestoreUserConf(USER_CONF * conf, const std::string & login, const std::string & fileName) const;
- virtual int WriteLogString(const string & str, const string & login) const;
- virtual int WriteLog2String(const string & str, const string & login) const;
+ virtual int WriteLogString(const std::string & str, const std::string & login) const;
+ virtual int WriteLog2String(const std::string & str, const std::string & login) const;
int RemoveDir(const char * path) const;
int Touch(const std::string & path) const;
mutable string errorStr;
- string version;
+ std::string version;
FILES_STORE_SETTINGS storeSettings;
MODULE_SETTINGS settings;
mutable pthread_mutex_t mutex;
};
//-----------------------------------------------------------------------------
-#endif //FILE_STORE_H
+#endif
#ifndef FIREBIRD_STORE_H
#define FIREBIRD_STORE_H
+#include <ctime>
#include <string>
#include <vector>
#include <map>
-#include "base_store.h"
+#include "store.h"
#include "stg_locker.h"
#include "ibpp.h"
-//#include "firebird_database.h"
-struct ToLower
-{
-char operator() (char c) const { return std::tolower(c); }
+struct ToLower {
+ char operator() (char c) const { return std::tolower(c); }
};
-extern "C" BASE_STORE * GetStore();
+extern "C" STORE * GetStore();
-class FIREBIRD_STORE : public BASE_STORE {
+class FIREBIRD_STORE : public STORE {
public:
FIREBIRD_STORE();
virtual ~FIREBIRD_STORE();
double cash,
double freeMb,
const std::string & reason) const;
- int WriteDetailedStat(const std::map<IP_DIR_PAIR, STAT_NODE> & statTree,
+ int WriteDetailedStat(const TRAFF_STAT & statTree,
time_t lastStat,
const std::string & login) const;
mutable IBPP::TLR tlr;
int SaveStat(const USER_STAT & stat, const std::string & login, int year = 0, int month = 0) const;
-
- time_t ts2time_t(const IBPP::Timestamp & ts) const;
- void time_t2ts(time_t t, IBPP::Timestamp * ts) const;
- void ym2date(int year, int month, IBPP::Date * date) const;
};
-#endif //FIREBIRD_STORE_H
+time_t ts2time_t(const IBPP::Timestamp & ts) const;
+void time_t2ts(time_t t, IBPP::Timestamp * ts) const;
+void ym2date(int year, int month, IBPP::Date * date) const;
+#endif //FIREBIRD_STORE_H
#include "ibpp.h"
//-----------------------------------------------------------------------------
-time_t FIREBIRD_STORE::ts2time_t(const IBPP::Timestamp & ts) const
+time_t ts2time_t(const IBPP::Timestamp & ts) const
{
char buf[32];
int year, month, day, hour, min, sec;
return mktime(&time_tm);
}
//-----------------------------------------------------------------------------
-void FIREBIRD_STORE::time_t2ts(time_t t, IBPP::Timestamp * ts) const
+void time_t2ts(time_t t, IBPP::Timestamp * ts) const
{
struct tm res;
*ts = IBPP::Timestamp(res.tm_year + 1900, res.tm_mon + 1, res.tm_mday, res.tm_hour, res.tm_min, res.tm_sec);
}
//-----------------------------------------------------------------------------
-void FIREBIRD_STORE::ym2date(int year, int month, IBPP::Date * date) const
+void ym2date(int year, int month, IBPP::Date * date) const
{
date->SetDate(year + 1900, month + 1, 1);
date->EndOfMonth();
}
//-----------------------------------------------------------------------------
-
#include <string>
-#include "base_settings.h"
-#include "base_store.h"
+#include "module_settings.h"
+#include "store.h"
#include "user_traff.h"
using namespace std;
//-----------------------------------------------------------------------------
-extern "C" BASE_STORE * GetStore();
+extern "C" STORE * GetStore();
//-----------------------------------------------------------------------------
-class MYSQL_STORE_SETTINGS//: public BASE_SETTINGS
+class MYSQL_STORE_SETTINGS
{
public:
MYSQL_STORE_SETTINGS();
const MODULE_SETTINGS * settings;
int ParseParam(const vector<PARAM_VALUE> & moduleParams,
- const string & name, string & result);
+ const string & name, string & result);
- string errorStr;
+ string errorStr;
string dbUser;
string dbPass;
- string dbName;
+ string dbName;
string dbHost;
};
//-----------------------------------------------------------------------------
-class MYSQL_STORE: public BASE_STORE
+class MYSQL_STORE: public STORE
{
public:
MYSQL_STORE();
private:
virtual int WriteLogString(const string & str, const string & login) const;
- int GetAllParams(vector<string> * ParamList, const string & table, const string & name) const;
- int CheckAllTables(MYSQL * sock);
- bool IsTablePresent(const string & str,MYSQL * sock);
+ int GetAllParams(vector<string> * ParamList, const string & table, const string & name) const;
+ int CheckAllTables(MYSQL * sock);
+ bool IsTablePresent(const string & str,MYSQL * sock);
mutable string errorStr;
-// int Reconnect();
- int MysqlQuery(const char* sQuery,MYSQL * sock) const;
+// int Reconnect();
+ int MysqlQuery(const char* sQuery,MYSQL * sock) const;
int MysqlGetQuery(const char * Query,MYSQL * & sock) const;
int MysqlSetQuery(const char * Query) const;
MYSQL * MysqlConnect() const ;
string version;
MYSQL_STORE_SETTINGS storeSettings;
MODULE_SETTINGS settings;
- //mutable MYSQL mysql;
- //mutable MYSQL* sock;
+ //mutable MYSQL mysql;
+ //mutable MYSQL* sock;
};
//-----------------------------------------------------------------------------
-#endif //FILE_STORE_H
+#endif
#include <vector>
#include <map>
-#include "base_store.h"
+#include "store.h"
// Minimal DB version is 5
// Recommended DB version is 6 (support FreeMb logging on disconnects)
#define DB_MIN_VERSION 5
-extern "C" BASE_STORE * GetStore();
+extern "C" STORE * GetStore();
-class POSTGRESQL_STORE : public BASE_STORE {
+class POSTGRESQL_STORE : public STORE {
public:
POSTGRESQL_STORE();
virtual ~POSTGRESQL_STORE();
#include "store_loader.h"
#include "common.h"
+#include "store.h"
+#include "settings.h"
STORE_LOADER::STORE_LOADER(const SETTINGS & settings)
: isLoaded(false),
#include <string>
-#include "base_store.h"
-#include "base_settings.h"
-#include "settings.h"
+#include "module_settings.h"
#include "noncopyable.h"
-class STORE_LOADER : private NONCOPYABLE
-{
+class STORE;
+class SETTINGS;
+
+class STORE_LOADER : private NONCOPYABLE {
public:
STORE_LOADER(const SETTINGS & settings);
~STORE_LOADER();
bool Load();
bool Unload();
- BASE_STORE * GetStore() { return plugin; };
+ STORE * GetStore() { return plugin; }
- const std::string & GetStrError() const { return errorStr; };
+ const std::string & GetStrError() const { return errorStr; }
private:
bool isLoaded;
void * handle;
- BASE_STORE * plugin;
+ STORE * plugin;
std::string errorStr;
MODULE_SETTINGS storeSettings;
std::string pluginFileName;
#include "tariffs_impl.h"
#include "stg_locker.h"
#include "stg_logger.h"
-#include "base_store.h"
+#include "store.h"
#include "admin.h"
using namespace std;
//-----------------------------------------------------------------------------
-TARIFFS_IMPL::TARIFFS_IMPL(BASE_STORE * st)
+TARIFFS_IMPL::TARIFFS_IMPL(STORE * st)
: tariffs(),
store(st),
WriteServLog(GetStgLogger()),
#define TARIFF_DAY 0
#define TARIFF_NIGHT 1
-class BASE_STORE;
+class STORE;
class STG_LOGGER;
class ADMIN;
class TARIFFS_IMPL : public TARIFFS {
public:
- TARIFFS_IMPL(BASE_STORE * store);
+ TARIFFS_IMPL(STORE * store);
virtual ~TARIFFS_IMPL();
int ReadTariffs ();
const TARIFF * FindByName(const std::string & name) const;
void GetTariffsData(std::list<TARIFF_DATA> * tdl);
- const std::string & GetStrError() const { return strError; };
+ const std::string & GetStrError() const { return strError; }
private:
- std::list<TARIFF_IMPL> tariffs;
- BASE_STORE * store;
- STG_LOGGER & WriteServLog;
+ std::list<TARIFF_IMPL> tariffs;
+ STORE * store;
+ STG_LOGGER & WriteServLog;
mutable pthread_mutex_t mutex;
- std::string strError;
- TARIFF_IMPL noTariff;
+ std::string strError;
+ TARIFF_IMPL noTariff;
};
#endif
$Author: faust $
*/
+/* inet_aton */
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
#include <csignal>
#include <cassert>
#include <cstdio> // Functions fopen and similar
#include "traffcounter.h"
#include "common.h"
#include "stg_locker.h"
+#include "stg_timer.h"
#define FLUSH_TIME (10)
#define REMOVE_TIME (31)
};
//-----------------------------------------------------------------------------
-TRAFFCOUNTER::TRAFFCOUNTER(USERS * u, const TARIFFS *, const string & fn)
+TRAFFCOUNTER::TRAFFCOUNTER(USERS * u, const TARIFFS *, const std::string & fn)
: WriteServLog(GetStgLogger()),
rulesFileName(fn),
monitoring(false),
printfd(__FILE__, "TRAFFCOUNTER::Start()\n");
int h = users->OpenSearch();
-user_iter u;
+USER_PTR u;
if (!h)
{
WriteServLog("TRAFFCOUNTER: Cannot get users.");
return -1;
}
-user_iter u;
+USER_PTR u;
while (users->SearchNext(h, &u) == 0)
{
UnSetUserNotifiers(u);
if (tc->monitoring && (touchTime + MONITOR_TIME_DELAY_SEC <= stgTime))
{
- string monFile(tc->monitorDir + "/traffcounter_r");
+ std::string monFile(tc->monitorDir + "/traffcounter_r");
printfd(__FILE__, "Monitor=%d file TRAFFCOUNTER %s\n", tc->monitoring, monFile.c_str());
touchTime = stgTime;
TouchFile(monFile.c_str());
if (monitoring && (touchTime + MONITOR_TIME_DELAY_SEC <= stgTime))
{
- static string monFile = monitorDir + "/traffcounter_p";
+ static std::string monFile = monitorDir + "/traffcounter_p";
printfd(__FILE__, "Monitor=%d file TRAFFCOUNTER %s\n", monitoring, monFile.c_str());
touchTime = stgTime;
TouchFile(monFile.c_str());
//TODO use result of lower_bound to inserting new record
// Adding packet to a tree.
- pair<pp_iter, bool> insertResult = packets.insert(pair<RAW_PACKET,
- PACKET_EXTRA_DATA>(rawPacket, ed));
+ std::pair<pp_iter, bool> insertResult = packets.insert(std::make_pair(rawPacket, ed));
pp_iter newPacket = insertResult.first;
// Adding packet reference to an IP index.
- ip2packets.insert(pair<uint32_t, pp_iter>(ipU, newPacket));
- ip2packets.insert(pair<uint32_t, pp_iter>(ipD, newPacket));
+ ip2packets.insert(std::make_pair(ipU, newPacket));
+ ip2packets.insert(std::make_pair(ipD, newPacket));
}
}
//-----------------------------------------------------------------------------
}*/
if (stgTime - pi->second.updateTime < REMOVE_TIME)
{
- pair<pp_iter, bool> res = newPackets.insert(*pi);
+ std::pair<pp_iter, bool> res = newPackets.insert(*pi);
if (res.second)
{
- ip2packets.insert(make_pair(pi->first.GetSrcIP(), res.first));
- ip2packets.insert(make_pair(pi->first.GetDstIP(), res.first));
+ ip2packets.insert(std::make_pair(pi->first.GetSrcIP(), res.first));
+ ip2packets.insert(std::make_pair(pi->first.GetDstIP(), res.first));
}
}
++pi;
}
//-----------------------------------------------------------------------------
-void TRAFFCOUNTER::AddUser(user_iter user)
+void TRAFFCOUNTER::AddUser(USER_PTR user)
{
printfd(__FILE__, "AddUser: %s\n", user->GetLogin().c_str());
uint32_t uip = user->GetCurrIP();
-pair<ip2p_iter, ip2p_iter> pi;
+std::pair<ip2p_iter, ip2p_iter> pi;
STG_LOCKER lock(&mutex, __FILE__, __LINE__);
// Find all packets with IP belongs to this user
void TRAFFCOUNTER::DelUser(uint32_t uip)
{
printfd(__FILE__, "DelUser: %s \n", inet_ntostring(uip).c_str());
-pair<ip2p_iter, ip2p_iter> pi;
+std::pair<ip2p_iter, ip2p_iter> pi;
STG_LOCKER lock(&mutex, __FILE__, __LINE__);
pi = ip2packets.equal_range(uip);
ip2packets.erase(pi.first, pi.second);
}
//-----------------------------------------------------------------------------
-void TRAFFCOUNTER::SetUserNotifiers(user_iter user)
+void TRAFFCOUNTER::SetUserNotifiers(USER_PTR user)
{
// Adding user. Adding notifiers to user.
TRF_IP_BEFORE ipBNotifier(*this, user);
user->AddCurrIPAfterNotifier(&(*ipAfterNotifiers.begin()));
}
//-----------------------------------------------------------------------------
-void TRAFFCOUNTER::UnSetUserNotifiers(user_iter user)
+void TRAFFCOUNTER::UnSetUserNotifiers(USER_PTR user)
{
// Removing user. Removing notifiers from user.
-list<TRF_IP_BEFORE>::iterator bi;
-list<TRF_IP_AFTER>::iterator ai;
+std::list<TRF_IP_BEFORE>::iterator bi;
+std::list<TRF_IP_AFTER>::iterator ai;
bi = ipBeforeNotifiers.begin();
while (bi != ipBeforeNotifiers.end())
enum { ICMP_RPOTO = 1, TCP_PROTO = 6, UDP_PROTO = 17 };
-list<RULE>::const_iterator ln;
+std::list<RULE>::const_iterator ln;
ln = rules.begin();
while (ln != rules.end())
return;
};
//-----------------------------------------------------------------------------
-void TRAFFCOUNTER::SetRulesFile(const string & fn)
+void TRAFFCOUNTER::SetRulesFile(const std::string & fn)
{
rulesFileName = fn;
}
return;
}
//-----------------------------------------------------------------------------
-void TRAFFCOUNTER::SetMonitorDir(const string & monitorDir)
+void TRAFFCOUNTER::SetMonitorDir(const std::string & monitorDir)
{
TRAFFCOUNTER::monitorDir = monitorDir;
monitoring = (monitorDir != "");
#define PROTOMAX (5)
+class TARIFFS;
+
//-----------------------------------------------------------------------------
struct RULE
{
time_t flushTime; // Last flush time
time_t updateTime; // Last update time
-user_iter userU; // Uploader
+USER_PTR userU; // Uploader
bool userUPresent; // Uploader is registered user
-user_iter userD; // Downloader
+USER_PTR userD; // Downloader
bool userDPresent; // Downloader is registered user
int dirU; // Upload direction
int dirD; // Download direction
class TRF_IP_BEFORE: public PROPERTY_NOTIFIER_BASE<uint32_t>
{
public:
- TRF_IP_BEFORE(TRAFFCOUNTER & t, user_iter u)
+ TRF_IP_BEFORE(TRAFFCOUNTER & t, USER_PTR u)
: PROPERTY_NOTIFIER_BASE<uint32_t>(),
traffCnt(t),
user(u)
{};
void Notify(const uint32_t & oldValue, const uint32_t & newValue);
- void SetUser(user_iter u) { user = u; }
- user_iter GetUser() const { return user; }
+ void SetUser(USER_PTR u) { user = u; }
+ USER_PTR GetUser() const { return user; }
private:
TRAFFCOUNTER & traffCnt;
- user_iter user;
+ USER_PTR user;
};
//-----------------------------------------------------------------------------
class TRF_IP_AFTER: public PROPERTY_NOTIFIER_BASE<uint32_t>
{
public:
- TRF_IP_AFTER(TRAFFCOUNTER & t, user_iter u)
+ TRF_IP_AFTER(TRAFFCOUNTER & t, USER_PTR u)
: PROPERTY_NOTIFIER_BASE<uint32_t>(),
traffCnt(t),
user(u)
{};
void Notify(const uint32_t & oldValue, const uint32_t & newValue);
- void SetUser(user_iter u) { user = u; }
- user_iter GetUser() const { return user; }
+ void SetUser(USER_PTR u) { user = u; }
+ USER_PTR GetUser() const { return user; }
private:
TRAFFCOUNTER & traffCnt;
- user_iter user;
+ USER_PTR user;
};
//-----------------------------------------------------------------------------
-class ADD_USER_NONIFIER: public NOTIFIER_BASE<user_iter>
+class ADD_USER_NONIFIER: public NOTIFIER_BASE<USER_PTR>
{
public:
ADD_USER_NONIFIER(TRAFFCOUNTER & t) :
- NOTIFIER_BASE<user_iter>(),
+ NOTIFIER_BASE<USER_PTR>(),
traffCnt(t) {};
virtual ~ADD_USER_NONIFIER(){};
- void Notify(const user_iter & user);
+ void Notify(const USER_PTR & user);
private:
TRAFFCOUNTER & traffCnt;
};
//-----------------------------------------------------------------------------
-class DEL_USER_NONIFIER: public NOTIFIER_BASE<user_iter>
+class DEL_USER_NONIFIER: public NOTIFIER_BASE<USER_PTR>
{
public:
DEL_USER_NONIFIER(TRAFFCOUNTER & t) :
- NOTIFIER_BASE<user_iter>(),
+ NOTIFIER_BASE<USER_PTR>(),
traffCnt(t) {};
virtual ~DEL_USER_NONIFIER(){};
- void Notify(const user_iter & user);
+ void Notify(const USER_PTR & user);
private:
TRAFFCOUNTER & traffCnt;
};
void FlushAndRemove();
- void AddUser(user_iter user);
+ void AddUser(USER_PTR user);
void DelUser(uint32_t uip);
- void SetUserNotifiers(user_iter user);
- void UnSetUserNotifiers(user_iter user);
+ void SetUserNotifiers(USER_PTR user);
+ void UnSetUserNotifiers(USER_PTR user);
std::list<RULE> rules;
typedef std::list<RULE>::iterator rule_iter;
}
//-----------------------------------------------------------------------------
inline
-void ADD_USER_NONIFIER::Notify(const user_iter & user)
+void ADD_USER_NONIFIER::Notify(const USER_PTR & user)
{
EVENT_LOOP_SINGLETON::GetInstance().Enqueue(traffCnt, &TRAFFCOUNTER::SetUserNotifiers, user);
}
//-----------------------------------------------------------------------------
inline
-void DEL_USER_NONIFIER::Notify(const user_iter & user)
+void DEL_USER_NONIFIER::Notify(const USER_PTR & user)
{
EVENT_LOOP_SINGLETON::GetInstance().Enqueue(traffCnt, &TRAFFCOUNTER::UnSetUserNotifiers, user);
EVENT_LOOP_SINGLETON::GetInstance().Enqueue(traffCnt, &TRAFFCOUNTER::DelUser, user->GetCurrIP());
#include "admin.h"
USER_IMPL::USER_IMPL(const SETTINGS * s,
- const BASE_STORE * st,
+ const STORE * st,
const TARIFFS * t,
const ADMIN & a,
const USERS * u)
return 0;
}
//-----------------------------------------------------------------------------
-int USER_IMPL::Authorize(uint32_t ip, const string &, uint32_t dirs, const BASE_AUTH * auth)
+int USER_IMPL::Authorize(uint32_t ip, uint32_t dirs, const AUTH * auth)
{
STG_LOCKER lock(&mutex, __FILE__, __LINE__);
/*
return 0;
}
//-----------------------------------------------------------------------------
-void USER_IMPL::Unauthorize(const BASE_AUTH * auth)
+void USER_IMPL::Unauthorize(const AUTH * auth)
{
STG_LOCKER lock(&mutex, __FILE__, __LINE__);
/*
}
}
//-----------------------------------------------------------------------------
-bool USER_IMPL::IsAuthorizedBy(const BASE_AUTH * auth) const
+bool USER_IMPL::IsAuthorizedBy(const AUTH * auth) const
{
STG_LOCKER lock(&mutex, __FILE__, __LINE__);
// Is this user authorized by specified authorizer?
{
// No lock `cause we are already locked from caller
int ret = -1;
-set<const BASE_AUTH*>::iterator it(authorizedBy.begin());
+set<const AUTH*>::iterator it(authorizedBy.begin());
while (it != authorizedBy.end())
{
if (!(*it++)->SendMessage(msg, currIP))
#include <ctime>
#include <list>
#include <string>
-#include <map>
#include <set>
#include "user.h"
#include "user_conf.h"
#include "user_ips.h"
#include "user_property.h"
-#include "base_auth.h"
+#include "auth.h"
#include "stg_message.h"
#include "noncopyable.h"
-using namespace std;
-
//-----------------------------------------------------------------------------
class TARIFF;
class TARIFFS;
USER_IMPL * user;
};
//-----------------------------------------------------------------------------
-class CHG_TARIFF_NOTIFIER : public PROPERTY_NOTIFIER_BASE<string>,
+class CHG_TARIFF_NOTIFIER : public PROPERTY_NOTIFIER_BASE<std::string>,
private NONCOPYABLE {
public:
CHG_TARIFF_NOTIFIER(USER_IMPL * u) : user(u) {}
- void Notify(const string & oldTariff, const string & newTariff);
+ void Notify(const std::string & oldTariff, const std::string & newTariff);
private:
USER_IMPL * user;
friend class CHG_IP_NOTIFIER;
public:
USER_IMPL(const SETTINGS * settings,
- const BASE_STORE * store,
+ const STORE * store,
const TARIFFS * tariffs,
const ADMIN & sysAdmin,
const USERS * u);
int WriteStat();
int WriteMonthStat();
- string const & GetLogin() const { return login; }
- void SetLogin(string const & l);
+ std::string const & GetLogin() const { return login; }
+ void SetLogin(std::string const & l);
uint32_t GetCurrIP() const { return currIP; }
time_t GetCurrIPModificationTime() const { return currIP.ModificationTime(); }
bool GetConnected() const { return connected; }
time_t GetConnectedModificationTime() const { return connected.ModificationTime(); }
int GetAuthorized() const { return authorizedBy.size(); }
- int Authorize(uint32_t ip, const string & iface, uint32_t enabledDirs, const BASE_AUTH * auth);
- void Unauthorize(const BASE_AUTH * auth);
- bool IsAuthorizedBy(const BASE_AUTH * auth) const;
+ int Authorize(uint32_t ip, uint32_t enabledDirs, const AUTH * auth);
+ void Unauthorize(const AUTH * auth);
+ bool IsAuthorizedBy(const AUTH * auth) const;
int AddMessage(STG_MSG * msg);
void PrintUser() const;
void Run();
- const string & GetStrError() const { return errorStr; }
+ const std::string & GetStrError() const { return errorStr; }
USER_PROPERTIES & GetProperty() { return property; };
const USER_PROPERTIES & GetProperty() const { return property; };
void ProcessNewMonth();
bool IsInetable();
- string GetEnabledDirs();
+ std::string GetEnabledDirs();
void OnAdd();
void OnDelete();
time_t lastScanMessages;
- string login;
+ std::string login;
int id;
bool __connected;
USER_PROPERTY<bool> connected;
time_t pingTime;
const ADMIN & sysAdmin;
- const BASE_STORE * store;
+ const STORE * store;
const TARIFFS * tariffs;
const TARIFF * tariff;
const SETTINGS * settings;
- set<const BASE_AUTH *> authorizedBy;
+ std::set<const AUTH *> authorizedBy;
- list<STG_MSG> messages;
+ std::list<STG_MSG> messages;
bool deleted;
USER_PROPERTY<time_t> & lastCashAddTime;
USER_PROPERTY<double> & freeMb;
USER_PROPERTY<time_t> & lastActivityTime;
- USER_PROPERTY<string> & password;
+ USER_PROPERTY<std::string> & password;
USER_PROPERTY<int> & passive;
USER_PROPERTY<int> & disabled;
USER_PROPERTY<int> & disabledDetailStat;
USER_PROPERTY<int> & alwaysOnline;
- USER_PROPERTY<string> & tariffName;
- USER_PROPERTY<string> & nextTariff;
- USER_PROPERTY<string> & address;
- USER_PROPERTY<string> & note;
- USER_PROPERTY<string> & group;
- USER_PROPERTY<string> & email;
- USER_PROPERTY<string> & phone;
- USER_PROPERTY<string> & realName;
+ USER_PROPERTY<std::string> & tariffName;
+ USER_PROPERTY<std::string> & nextTariff;
+ USER_PROPERTY<std::string> & address;
+ USER_PROPERTY<std::string> & note;
+ USER_PROPERTY<std::string> & group;
+ USER_PROPERTY<std::string> & email;
+ USER_PROPERTY<std::string> & phone;
+ USER_PROPERTY<std::string> & realName;
USER_PROPERTY<double> & credit;
USER_PROPERTY<time_t> & creditExpire;
USER_PROPERTY<USER_IPS> & ips;
- USER_PROPERTY<string> & userdata0;
- USER_PROPERTY<string> & userdata1;
- USER_PROPERTY<string> & userdata2;
- USER_PROPERTY<string> & userdata3;
- USER_PROPERTY<string> & userdata4;
- USER_PROPERTY<string> & userdata5;
- USER_PROPERTY<string> & userdata6;
- USER_PROPERTY<string> & userdata7;
- USER_PROPERTY<string> & userdata8;
- USER_PROPERTY<string> & userdata9;
+ USER_PROPERTY<std::string> & userdata0;
+ USER_PROPERTY<std::string> & userdata1;
+ USER_PROPERTY<std::string> & userdata2;
+ USER_PROPERTY<std::string> & userdata3;
+ USER_PROPERTY<std::string> & userdata4;
+ USER_PROPERTY<std::string> & userdata5;
+ USER_PROPERTY<std::string> & userdata6;
+ USER_PROPERTY<std::string> & userdata7;
+ USER_PROPERTY<std::string> & userdata8;
+ USER_PROPERTY<std::string> & userdata9;
// End properties
mutable pthread_mutex_t mutex;
- string errorStr;
+ std::string errorStr;
};
//-----------------------------------------------------------------------------
$Author: faust $
*/
-
#ifndef USER_PROPERTY_H
#define USER_PROPERTY_H
#include <iostream>
#include <algorithm>
-#include "base_store.h"
+#include "store.h"
#include "stg_logger.h"
#include "admin.h"
#include "settings.h"
#include "stg_locker.h"
#include "script_executer.h"
-using namespace std;
-
extern const volatile time_t stgTime;
//-----------------------------------------------------------------------------
template<typename varT>
-class USER_PROPERTY
- {
+class USER_PROPERTY {
public:
USER_PROPERTY(varT& val);
- USER_PROPERTY<varT>& operator= (const varT&);
- USER_PROPERTY<varT>& operator-= (const varT&);
virtual ~USER_PROPERTY();
+ void Set(const varT & rvalue);
+
+ USER_PROPERTY<varT>& operator= (const varT & rvalue);
+ USER_PROPERTY<varT>& operator-= (const varT & rvalue);
+
const varT * operator&() const throw();
const varT& ConstData() const throw();
return value;
}
- //bool IsEmpty() const throw();
-
void AddBeforeNotifier(PROPERTY_NOTIFIER_BASE<varT> * n);
void DelBeforeNotifier(PROPERTY_NOTIFIER_BASE<varT> * n);
time_t ModificationTime() const throw();
void ModifyTime() throw();
-protected:
+private:
varT & value;
time_t modificationTime;
- //typedef set<PROPERTY_NOTIFIER_BASE<varT> *>::iterator notifier_iter_t;
- mutable set<PROPERTY_NOTIFIER_BASE<varT> *> beforeNotifiers;
- mutable set<PROPERTY_NOTIFIER_BASE<varT> *> afterNotifiers;
+ set<PROPERTY_NOTIFIER_BASE<varT> *> beforeNotifiers;
+ set<PROPERTY_NOTIFIER_BASE<varT> *> afterNotifiers;
mutable pthread_mutex_t mutex;
- };
+};
//-----------------------------------------------------------------------------
template<typename varT>
-class USER_PROPERTY_LOGGED: public USER_PROPERTY<varT>
- {
+class USER_PROPERTY_LOGGED: public USER_PROPERTY<varT> {
public:
- USER_PROPERTY_LOGGED(varT& val,
+ USER_PROPERTY_LOGGED(varT & val,
const string n,
bool isPassword,
bool isStat,
const SETTINGS * s);
virtual ~USER_PROPERTY_LOGGED();
- //operator const varT&() const throw();;
USER_PROPERTY_LOGGED<varT> * GetPointer() throw();
const varT & Get() const;
const string & GetName() const;
bool Set(const varT & val,
const ADMIN & admin,
const string & login,
- const BASE_STORE * store,
+ const STORE * store,
const string & msg = "");
-protected:
+private:
void WriteAccessDenied(const string & login,
- const ADMIN & admin,
+ const ADMIN & admin,
const string & parameter);
- void WriteSuccessChange(const string & login,
- const ADMIN & admin,
- const string & parameter,
- const string & oldValue,
- const string & newValue,
- const string & msg,
- const BASE_STORE * store);
+ void WriteSuccessChange(const string & login,
+ const ADMIN & admin,
+ const string & parameter,
+ const string & oldValue,
+ const string & newValue,
+ const string & msg,
+ const STORE * store);
void OnChange(const string & login,
const string & paramName,
mutable pthread_mutex_t mutex;
STG_LOGGER & stgLogger; // server's logger
const SETTINGS * settings;
- };
+};
//-----------------------------------------------------------------------------
-class USER_PROPERTIES
- {
- friend class USER;
+class USER_PROPERTIES {
/*
В этом месте важен порядок следования приватной и открытой частей.
Это связано с тем, что часть которая находится в публичной секции
public:
USER_PROPERTIES(const SETTINGS * settings);
+ USER_STAT & Stat() { return stat; }
+ USER_CONF & Conf() { return conf; }
const USER_STAT & GetStat() const { return stat; }
const USER_CONF & GetConf() const { return conf; }
void SetStat(const USER_STAT & s) { stat = s; }
USER_PROPERTY_LOGGED<string> userdata7;
USER_PROPERTY_LOGGED<string> userdata8;
USER_PROPERTY_LOGGED<string> userdata9;
- };
-
+};
//=============================================================================
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
template <typename varT>
USER_PROPERTY<varT>::USER_PROPERTY(varT& val)
-:
-value(val)
+ : value(val)
{
pthread_mutex_init(&mutex, NULL);
modificationTime = stgTime;
}
//-----------------------------------------------------------------------------
template <typename varT>
-USER_PROPERTY<varT>& USER_PROPERTY<varT>::operator= (const varT& newValue)
+void USER_PROPERTY<varT>::Set(const varT & rvalue)
{
STG_LOCKER locker(&mutex, __FILE__, __LINE__);
-/*
-TODO
-if (value == newValue)
- return *this;*/
-
typename set<PROPERTY_NOTIFIER_BASE<varT> *>::iterator ni;
varT oldVal = value;
ni = beforeNotifiers.begin();
while (ni != beforeNotifiers.end())
- (*ni++)->Notify(oldVal, newValue);
+ (*ni++)->Notify(oldVal, rvalue);
-value = newValue;
+value = rvalue;
modificationTime = stgTime;
ni = afterNotifiers.begin();
while (ni != afterNotifiers.end())
- (*ni++)->Notify(oldVal, newValue);
-
+ (*ni++)->Notify(oldVal, rvalue);
+}
+//-----------------------------------------------------------------------------
+template <typename varT>
+USER_PROPERTY<varT>& USER_PROPERTY<varT>::operator= (const varT & newValue)
+{
+Set(newValue);
return *this;
}
//-----------------------------------------------------------------------------
template <typename varT>
-USER_PROPERTY<varT>& USER_PROPERTY<varT>::operator-= (const varT& delta)
+USER_PROPERTY<varT>& USER_PROPERTY<varT>::operator-= (const varT & delta)
{
-STG_LOCKER locker(&mutex, __FILE__, __LINE__);
-
-typename set<PROPERTY_NOTIFIER_BASE<varT> *>::iterator ni;
-
-varT oldVal = value;
-
-ni = beforeNotifiers.begin();
-while (ni != beforeNotifiers.end())
- (*ni++)->Notify(oldVal, oldVal - delta);
-
-value -= delta;
-modificationTime = stgTime;
-
-ni = afterNotifiers.begin();
-while (ni != afterNotifiers.end())
- (*ni++)->Notify(oldVal, value);
-
+varT newValue = ConstData() - delta;
+Set(newValue);
return *this;
}
//-----------------------------------------------------------------------------
template <typename varT>
const varT * USER_PROPERTY<varT>::operator&() const throw()
{
-STG_LOCKER locker(&mutex, __FILE__, __LINE__);
return &value;
}
//-----------------------------------------------------------------------------
template <typename varT>
const varT& USER_PROPERTY<varT>::ConstData() const throw()
{
-STG_LOCKER locker(&mutex, __FILE__, __LINE__);
return value;
}
//-----------------------------------------------------------------------------
-/*template <typename varT>
-bool USER_PROPERTY<varT>::IsEmpty() const throw()
-{
-STG_LOCKER locker(&mutex, __FILE__, __LINE__);
-return !is_set;
-}*/
-//-----------------------------------------------------------------------------
template <typename varT>
void USER_PROPERTY<varT>::AddBeforeNotifier(PROPERTY_NOTIFIER_BASE<varT> * n)
{
template <typename varT>
time_t USER_PROPERTY<varT>::ModificationTime() const throw()
{
-STG_LOCKER locker(&mutex, __FILE__, __LINE__);
return modificationTime;
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
template <typename varT>
-USER_PROPERTY_LOGGED<varT>::USER_PROPERTY_LOGGED(
- varT& val,
- string n,
- bool isPass,
- bool isSt,
- STG_LOGGER & logger,
- const SETTINGS * s)
-
-:USER_PROPERTY<varT>(val),
-stgLogger(logger)
+USER_PROPERTY_LOGGED<varT>::USER_PROPERTY_LOGGED(varT& val,
+ string n,
+ bool isPass,
+ bool isSt,
+ STG_LOGGER & logger,
+ const SETTINGS * s)
+
+ : USER_PROPERTY<varT>(val),
+ stgLogger(logger)
{
pthread_mutex_init(&mutex, NULL);
STG_LOCKER locker(&mutex, __FILE__, __LINE__);
-USER_PROPERTY<varT>::value = val;
isPassword = isPass;
isStat = isSt;
name = n;
template <typename varT>
USER_PROPERTY_LOGGED<varT>::~USER_PROPERTY_LOGGED()
{
-STG_LOCKER locker(&mutex, __FILE__, __LINE__);
}
//-----------------------------------------------------------------------------
template <typename varT>
USER_PROPERTY_LOGGED<varT> * USER_PROPERTY_LOGGED<varT>::GetPointer() throw()
{
-STG_LOCKER locker(&mutex, __FILE__, __LINE__);
return this;
}
//-----------------------------------------------------------------------------
template <typename varT>
const varT & USER_PROPERTY_LOGGED<varT>::Get() const
{
-STG_LOCKER locker(&mutex, __FILE__, __LINE__);
-return USER_PROPERTY<varT>::value;
+return USER_PROPERTY<varT>::ConstData();
};
//-------------------------------------------------------------------------
template <typename varT>
const string & USER_PROPERTY_LOGGED<varT>::GetName() const
{
-STG_LOCKER locker(&mutex, __FILE__, __LINE__);
return name;
};
//-------------------------------------------------------------------------
bool USER_PROPERTY_LOGGED<varT>::Set(const varT & val,
const ADMIN & admin,
const string & login,
- const BASE_STORE * store,
+ const STORE * store,
const string & msg)
{
STG_LOCKER locker(&mutex, __FILE__, __LINE__);
const PRIV * priv = admin.GetPriv();
string adm_login = admin.GetLogin();
-string adm_ip = admin.GetAdminIPStr();
+string adm_ip = admin.GetIPStr();
if ((priv->userConf && !isStat) || (priv->userStat && isStat) || (priv->userPasswd && isPassword) || (priv->userCash && name == "cash"))
{
oldVal.flags(oldVal.flags() | ios::fixed);
newVal.flags(newVal.flags() | ios::fixed);
- oldVal << USER_PROPERTY<varT>::value;
+ oldVal << USER_PROPERTY<varT>::ConstData();
newVal << val;
OnChange(login, name, oldVal.str(), newVal.str(), admin);
{
WriteSuccessChange(login, admin, name, oldVal.str(), newVal.str(), msg, store);
}
- USER_PROPERTY<varT>::operator =(val);
+ USER_PROPERTY<varT>::Set(val);
return true;
}
else
//-------------------------------------------------------------------------
template <typename varT>
void USER_PROPERTY_LOGGED<varT>::WriteSuccessChange(const string & login,
- const ADMIN & admin,
- const string & parameter,
- const string & oldValue,
- const string & newValue,
- const string & msg,
- const BASE_STORE * store)
+ const ADMIN & admin,
+ const string & parameter,
+ const string & oldValue,
+ const string & newValue,
+ const string & msg,
+ const STORE * store)
{
stgLogger("%s User \'%s\': \'%s\' parameter changed from \'%s\' to \'%s\'. %s",
admin.GetLogStr().c_str(),
newValue.c_str(),
msg.c_str());
-store->WriteUserChgLog(login, admin.GetLogin(), admin.GetAdminIP(), parameter, oldValue, newValue, msg);
+store->WriteUserChgLog(login, admin.GetLogin(), admin.GetIP(), parameter, oldValue, newValue, msg);
}
//-------------------------------------------------------------------------
template <typename varT>
if (access(str1.c_str(), X_OK) == 0)
{
- string str2("\"" + str1 + "\" \"" + login + "\" \"" + paramName + "\" \"" + oldValue + "\" \"" + newValue + "\" \"" + admin.GetLogin() + "\" \"" + admin.GetAdminIPStr() + "\"");
+ string str2("\"" + str1 + "\" \"" + login + "\" \"" + paramName + "\" \"" + oldValue + "\" \"" + newValue + "\" \"" + admin.GetLogin() + "\" \"" + admin.GetIPStr() + "\"");
ScriptExec(str2);
}
else
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
-template<typename varT>
+/*template<typename varT>
stringstream & operator<< (stringstream & s, const USER_PROPERTY<varT> & v)
{
s << v.ConstData();
return s;
-}
+}*/
//-----------------------------------------------------------------------------
template<typename varT>
-ostream & operator<< (ostream & o, const USER_PROPERTY<varT> & v)
+ostream & operator<< (ostream & stream, const USER_PROPERTY<varT> & value)
{
-return o << v.ConstData();
+return stream << value.ConstData();
}
//-----------------------------------------------------------------------------
-
#endif // USER_PROPERTY_H
-
#include "os_int.h"
-#include "base_store.h"
+#include "store.h"
#include "settings.h"
#include "users.h"
#include "user.h"
friend class PROPERTY_NOTIFER_IP_AFTER;
public:
- USERS_IMPL(SETTINGS * s, BASE_STORE * store, TARIFFS * tariffs, const ADMIN & sysAdmin);
+ USERS_IMPL(SETTINGS * s, STORE * store, TARIFFS * tariffs, const ADMIN & sysAdmin);
virtual ~USERS_IMPL();
int FindByName(const std::string & login, USER_PTR * user);
SETTINGS * settings;
TARIFFS * tariffs;
- BASE_STORE * store;
+ STORE * store;
const ADMIN & sysAdmin;
STG_LOGGER & WriteServLog;