From: Maxim Mamontov Date: Thu, 18 Sep 2014 20:06:51 +0000 (+0300) Subject: Removed unused stuff. X-Git-Url: https://git.stg.codes/stg.git/commitdiff_plain/9dc2984179d989f8774ea7ff6d72c81d376b5a2c?ds=sidebyside Removed unused stuff. --- diff --git a/projects/stargazer/plugins/configuration/sgconfig/configproto.cpp b/projects/stargazer/plugins/configuration/sgconfig/configproto.cpp index dff8760a..eb8fbcde 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/configproto.cpp +++ b/projects/stargazer/plugins/configuration/sgconfig/configproto.cpp @@ -184,7 +184,7 @@ while(nonstop) if (currParser) { printfd(__FILE__, "Parser reset\n"); - currParser->Reset(); + //currParser->Reset(); currParser = NULL; } @@ -203,31 +203,5 @@ return 0; void CONFIGPROTO::SetAdmins(ADMINS * a) { admins = a; -for (size_t i = 0; i < dataParser.size(); i++) - dataParser[i]->SetAdmins(a); -} -//----------------------------------------------------------------------------- -void CONFIGPROTO::SetUsers(USERS * u) -{ -for (size_t i = 0; i < dataParser.size(); i++) - dataParser[i]->SetUsers(u); -} -//----------------------------------------------------------------------------- -void CONFIGPROTO::SetTariffs(TARIFFS * t) -{ -for (size_t i = 0; i < dataParser.size(); i++) - dataParser[i]->SetTariffs(t); -} -//----------------------------------------------------------------------------- -void CONFIGPROTO::SetStore(STORE * s) -{ -for (size_t i = 0; i < dataParser.size(); i++) - dataParser[i]->SetStore(s); -} -//----------------------------------------------------------------------------- -void CONFIGPROTO::SetStgSettings(const SETTINGS * s) -{ -for (size_t i = 0; i < dataParser.size(); i++) - dataParser[i]->SetStgSettings(s); } //----------------------------------------------------------------------------- diff --git a/projects/stargazer/plugins/configuration/sgconfig/configproto.h b/projects/stargazer/plugins/configuration/sgconfig/configproto.h index b50b434a..42d5e7fa 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/configproto.h +++ b/projects/stargazer/plugins/configuration/sgconfig/configproto.h @@ -63,10 +63,6 @@ public: void SetPort(uint16_t p) { port = p; } void SetAdmins(ADMINS * a); - void SetUsers(USERS * u); - void SetTariffs(TARIFFS * t); - void SetStore(STORE * s); - void SetStgSettings(const SETTINGS * s); uint32_t GetAdminIP() const { return adminIP; } int Prepare(); int Stop(); diff --git a/projects/stargazer/plugins/configuration/sgconfig/parser.cpp b/projects/stargazer/plugins/configuration/sgconfig/parser.cpp index 52c0ea9b..b984adf6 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/parser.cpp +++ b/projects/stargazer/plugins/configuration/sgconfig/parser.cpp @@ -20,36 +20,28 @@ #include "parser.h" -#include "stg/tariffs.h" -#include "stg/admin.h" -#include "stg/users.h" -#include "stg/user_property.h" -#include "stg/settings.h" -#include "stg/logger.h" -#include "stg/version.h" -#include "stg/store.h" - #include -#include // sprintf //----------------------------------------------------------------------------- // BASE PARSER //----------------------------------------------------------------------------- -int BASE_PARSER::Start(void *, const char *el, const char **) +int BASE_PARSER::Start(void *, const char * el, const char **) { -if (strcasecmp(el, tag.c_str()) == 0) - return 0; + if (strcasecmp(el, m_tag.c_str()) == 0) + return 0; -return -1; + return -1; } //----------------------------------------------------------------------------- -int BASE_PARSER::End(void *, const char *el) +int BASE_PARSER::End(void *, const char * el) { -if (strcasecmp(el, tag.c_str()) == 0) + if (m_depth == 1) { - CreateAnswer(); - return 0; + if (strcasecmp(el, m_tag.c_str()) != 0) + return -1; + CreateAnswer(); } -return -1; + --m_depth; + return 0; } diff --git a/projects/stargazer/plugins/configuration/sgconfig/parser.h b/projects/stargazer/plugins/configuration/sgconfig/parser.h index 2e68f8e9..035dae8f 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/parser.h +++ b/projects/stargazer/plugins/configuration/sgconfig/parser.h @@ -21,74 +21,38 @@ #ifndef PARSER_H #define PARSER_H -#include "stg/message.h" -#include "stg/tariff_conf.h" -#include "stg/resetable.h" -#include "stg/const.h" - #include -#include -class TARIFFS; -class SETTINGS; -class STORE; -class ADMINS; class ADMIN; -class USERS; -class USER; -class USER_STAT_RES; -class USER_CONF_RES; - -//----------------------------------------------------------------------------- -class BASE_PARSER { -public: - BASE_PARSER(const ADMIN & admin, const std::string & t) - : strError(), - admins(NULL), - users(NULL), - tariffs(NULL), - store(NULL), - settings(NULL), - currAdmin(admin), - depth(0), - tag(t) - {} - virtual ~BASE_PARSER() {} - virtual int Start(void *data, const char *el, const char **attr); - virtual int End(void *data, const char *el); - - virtual void Reset() { answer.clear(); depth = 0; } - - void SetUsers(USERS * u) { users = u; } - void SetAdmins(ADMINS * a) { admins = a; } - void SetTariffs(TARIFFS * t) { tariffs = t; } - void SetStore(STORE * s) { store = s; } - void SetStgSettings(const SETTINGS * s) { settings = s; } - const std::string & GetStrError() const { return strError; } - const std::string & GetAnswer() const { return answer; } - const std::string & GetTag() const { return tag; } - std::string GetOpenTag() const { return "<" + tag + ">"; } - std::string GetCloseTag() const { return ""; } - -protected: - BASE_PARSER(const BASE_PARSER & rvalue); - BASE_PARSER & operator=(const BASE_PARSER & rvalue); - - std::string strError; - ADMINS * admins; - USERS * users; - TARIFFS * tariffs; - STORE * store; - const SETTINGS * settings; - const ADMIN & currAdmin; - int depth; - std::string answer; - std::string tag; - -private: - virtual void CreateAnswer() = 0; +class BASE_PARSER +{ + public: + BASE_PARSER(const ADMIN & admin, const std::string & t) + : m_currAdmin(admin), + m_depth(0), + m_tag(t) + {} + virtual ~BASE_PARSER() {} + virtual int Start(void * data, const char * el, const char ** attr); + virtual int End(void * data, const char * el); + + const std::string & GetAnswer() const { return m_answer; } + const std::string & GetTag() const { return m_tag; } + std::string GetOpenTag() const { return "<" + m_tag + ">"; } + std::string GetCloseTag() const { return ""; } + + protected: + BASE_PARSER(const BASE_PARSER & rvalue); + BASE_PARSER & operator=(const BASE_PARSER & rvalue); + + const ADMIN & m_currAdmin; + size_t m_depth; + std::string m_answer; + std::string m_tag; + + private: + virtual void CreateAnswer() = 0; }; -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- + #endif //PARSER_H diff --git a/projects/stargazer/plugins/configuration/sgconfig/parser_admins.cpp b/projects/stargazer/plugins/configuration/sgconfig/parser_admins.cpp index c75dc8a7..01ae9e81 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/parser_admins.cpp +++ b/projects/stargazer/plugins/configuration/sgconfig/parser_admins.cpp @@ -33,16 +33,16 @@ using STG::PARSER::CHG_ADMIN; void GET_ADMINS::CreateAnswer() { - const PRIV * priv = currAdmin.GetPriv(); + const PRIV * priv = m_currAdmin.GetPriv(); if (!priv->adminChg) { - answer = ""; + m_answer = ""; return; } - answer.clear(); + m_answer.clear(); - answer += GetOpenTag(); + m_answer += GetOpenTag(); ADMIN_CONF ac; int h = m_admins.OpenSearch(); @@ -55,15 +55,15 @@ void GET_ADMINS::CreateAnswer() (ac.priv.userAddDel << 8) + (ac.priv.adminChg << 10) + (ac.priv.tariffChg << 12); - answer += ""; + m_answer += ""; } m_admins.CloseSearch(h); - answer += GetCloseTag(); + m_answer += GetCloseTag(); } int DEL_ADMIN::Start(void *, const char * el, const char ** attr) { - if (strcasecmp(el, tag.c_str()) == 0) + if (strcasecmp(el, m_tag.c_str()) == 0) { admin = attr[1]; return 0; @@ -73,15 +73,15 @@ int DEL_ADMIN::Start(void *, const char * el, const char ** attr) void DEL_ADMIN::CreateAnswer() { - if (m_admins.Del(admin, &currAdmin) == 0) - answer = "<" + tag + " Result=\"Ok\"/>"; + if (m_admins.Del(admin, &m_currAdmin) == 0) + m_answer = "<" + m_tag + " Result=\"Ok\"/>"; else - answer = "<" + tag + " Result=\"Error. " + m_admins.GetStrError() + "\"/>"; + m_answer = "<" + m_tag + " Result=\"Error. " + m_admins.GetStrError() + "\"/>"; } int ADD_ADMIN::Start(void *, const char *el, const char **attr) { - if (strcasecmp(el, tag.c_str()) == 0) + if (strcasecmp(el, m_tag.c_str()) == 0) { admin = attr[1]; return 0; @@ -91,15 +91,15 @@ int ADD_ADMIN::Start(void *, const char *el, const char **attr) void ADD_ADMIN::CreateAnswer() { - if (m_admins.Add(admin, &currAdmin) == 0) - answer = "<" + tag + " Result=\"Ok\"/>"; + if (m_admins.Add(admin, &m_currAdmin) == 0) + m_answer = "<" + m_tag + " Result=\"Ok\"/>"; else - answer = "<" + tag + " Result=\"Error. " + m_admins.GetStrError() + "\"/>"; + m_answer = "<" + m_tag + " Result=\"Error. " + m_admins.GetStrError() + "\"/>"; } int CHG_ADMIN::Start(void *, const char * el, const char ** attr) { - if (strcasecmp(el, tag.c_str()) == 0) + if (strcasecmp(el, m_tag.c_str()) == 0) { for (size_t i = 0; i < 6; i += 2) { @@ -139,7 +139,7 @@ void CHG_ADMIN::CreateAnswer() if (m_admins.Find(login, &origAdmin)) { - answer = "<" + tag + " Result = \"Admin '" + login + "' is not found.\"/>"; + m_answer = "<" + m_tag + " Result = \"Admin '" + login + "' is not found.\"/>"; return; } @@ -153,18 +153,18 @@ void CHG_ADMIN::CreateAnswer() int p = 0; if (str2x(privAsString.data().c_str(), p) < 0) { - answer = "<" + tag + " Result = \"Incorrect parameter Priv.\"/>"; + m_answer = "<" + m_tag + " Result = \"Incorrect parameter Priv.\"/>"; return; } conf.priv.FromInt(p); } - if (m_admins.Change(conf, &currAdmin) != 0) - answer = "<" + tag + " Result = \"" + m_admins.GetStrError() + "\"/>"; + if (m_admins.Change(conf, &m_currAdmin) != 0) + m_answer = "<" + m_tag + " Result = \"" + m_admins.GetStrError() + "\"/>"; else - answer = "<" + tag + " Result = \"Ok\"/>"; + m_answer = "<" + m_tag + " Result = \"Ok\"/>"; } else - answer = "<" + tag + " Result = \"Incorrect parameter login.\"/>"; + m_answer = "<" + m_tag + " Result = \"Incorrect parameter login.\"/>"; } diff --git a/projects/stargazer/plugins/configuration/sgconfig/parser_auth_by.cpp b/projects/stargazer/plugins/configuration/sgconfig/parser_auth_by.cpp index e16745c5..2137ef6b 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/parser_auth_by.cpp +++ b/projects/stargazer/plugins/configuration/sgconfig/parser_auth_by.cpp @@ -27,7 +27,7 @@ using STG::PARSER::AUTH_BY; int AUTH_BY::Start(void * /*data*/, const char *el, const char **attr) { - if (strcasecmp(el, tag.c_str()) != 0) + if (strcasecmp(el, m_tag.c_str()) != 0) return -1; if (!attr[1]) @@ -42,13 +42,13 @@ void AUTH_BY::CreateAnswer() CONST_USER_PTR u; if (m_users.FindByName(m_login, &u)) { - answer = ""; + m_answer = ""; return; } - answer = ""; + m_answer = ""; std::vector list(u->GetAuthorizers()); for (std::vector::const_iterator it = list.begin(); it != list.end(); ++it) - answer += ""; - answer += ""; + m_answer += ""; + m_answer += ""; } diff --git a/projects/stargazer/plugins/configuration/sgconfig/parser_message.cpp b/projects/stargazer/plugins/configuration/sgconfig/parser_message.cpp index 18767320..2e41fcc9 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/parser_message.cpp +++ b/projects/stargazer/plugins/configuration/sgconfig/parser_message.cpp @@ -30,7 +30,7 @@ using STG::PARSER::SEND_MESSAGE; int SEND_MESSAGE::Start(void *, const char *el, const char **attr) { - if (strcasecmp(el, tag.c_str()) != 0) + if (strcasecmp(el, m_tag.c_str()) != 0) return -1; for (size_t i = 0; i < 14; i++) @@ -85,7 +85,7 @@ int SEND_MESSAGE::Start(void *, const char *el, const char **attr) int SEND_MESSAGE::End(void *, const char *el) { - if (strcasecmp(el, tag.c_str()) != 0) + if (strcasecmp(el, m_tag.c_str()) != 0) return -1; m_result = res_unknown; @@ -126,13 +126,13 @@ void SEND_MESSAGE::CreateAnswer() switch (m_result) { case res_ok: - answer = ""; + m_answer = ""; break; case res_params_error: - answer = ""; + m_answer = ""; break; case res_unknown: - answer = ""; + m_answer = ""; break; } } diff --git a/projects/stargazer/plugins/configuration/sgconfig/parser_tariffs.cpp b/projects/stargazer/plugins/configuration/sgconfig/parser_tariffs.cpp index 8d54b1d5..2e8d1ff3 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/parser_tariffs.cpp +++ b/projects/stargazer/plugins/configuration/sgconfig/parser_tariffs.cpp @@ -76,21 +76,21 @@ bool String2AOS(const std::string & source, A & array, size_t size, RESETABLE void GET_TARIFFS::CreateAnswer() { - answer = GetOpenTag(); + m_answer = GetOpenTag(); std::list dataList; m_tariffs.GetTariffsData(&dataList); std::list::const_iterator it = dataList.begin(); for (; it != dataList.end(); ++it) { - answer += "tariffConf.name + "\">"; + m_answer += "tariffConf.name + "\">"; for (size_t i = 0; i < DIR_NUM; i++) - answer += "dirPrice[i].hDay) + ":" + x2str(it->dirPrice[i].mDay) + "-" + x2str(it->dirPrice[i].hNight) + ":" + x2str(it->dirPrice[i].mNight) + "\"/>"; - answer += "dirPrice, DIR_NUM, &DIRPRICE_DATA::priceDayA, pt_mega) + "\"/>" + + m_answer += "dirPrice, DIR_NUM, &DIRPRICE_DATA::priceDayA, pt_mega) + "\"/>" + "dirPrice, DIR_NUM, &DIRPRICE_DATA::priceDayB, pt_mega) + "\"/>" + "dirPrice, DIR_NUM, &DIRPRICE_DATA::priceNightA, pt_mega) + "\"/>" + "dirPrice, DIR_NUM, &DIRPRICE_DATA::priceNightB, pt_mega) + "\"/>" + @@ -105,12 +105,12 @@ void GET_TARIFFS::CreateAnswer() ""; } - answer += GetCloseTag(); + m_answer += GetCloseTag(); } int ADD_TARIFF::Start(void *, const char * el, const char ** attr) { - if (strcasecmp(el, tag.c_str()) != 0) + if (strcasecmp(el, m_tag.c_str()) != 0) return -1; if (attr[1] == NULL) @@ -122,15 +122,15 @@ int ADD_TARIFF::Start(void *, const char * el, const char ** attr) void ADD_TARIFF::CreateAnswer() { - if (m_tariffs.Add(tariff, &currAdmin) == 0) - answer = "<" + tag + " Result=\"Ok\"/>"; + if (m_tariffs.Add(tariff, &m_currAdmin) == 0) + m_answer = "<" + m_tag + " Result=\"Ok\"/>"; else - answer = "<" + tag + " Result=\"Error. " + m_tariffs.GetStrError() + "\"/>"; + m_answer = "<" + m_tag + " Result=\"Error. " + m_tariffs.GetStrError() + "\"/>"; } int DEL_TARIFF::Start(void *, const char * el, const char ** attr) { - if (strcasecmp(el, tag.c_str()) != 0) + if (strcasecmp(el, m_tag.c_str()) != 0) return -1; if (attr[1] == NULL) @@ -143,20 +143,20 @@ int DEL_TARIFF::Start(void *, const char * el, const char ** attr) void DEL_TARIFF::CreateAnswer() { if (m_users.TariffInUse(tariff)) - answer = "<" + tag + " Result=\"Error. Tariff \'" + tariff + "\' cannot be deleted, it is in use.\"/>"; - else if (m_tariffs.Del(tariff, &currAdmin) == 0) - answer = "<" + tag + " Result=\"Ok\"/>"; + m_answer = "<" + m_tag + " Result=\"Error. Tariff \'" + tariff + "\' cannot be deleted, it is in use.\"/>"; + else if (m_tariffs.Del(tariff, &m_currAdmin) == 0) + m_answer = "<" + m_tag + " Result=\"Ok\"/>"; else - answer = "<" + tag + " Result=\"Error. " + m_tariffs.GetStrError() + "\"/>"; + m_answer = "<" + m_tag + " Result=\"Error. " + m_tariffs.GetStrError() + "\"/>"; } int CHG_TARIFF::Start(void *, const char * el, const char ** attr) { - depth++; + m_depth++; - if (depth == 1) + if (m_depth == 1) { - if (strcasecmp(el, tag.c_str()) == 0) + if (strcasecmp(el, m_tag.c_str()) == 0) { td.tariffConf.name = attr[1]; return 0; @@ -280,29 +280,16 @@ int CHG_TARIFF::Start(void *, const char * el, const char ** attr) return -1; } -int CHG_TARIFF::End(void *, const char * el) -{ - if (depth == 1) - { - if (strcasecmp(el, tag.c_str()) != 0) - return -1; - CreateAnswer(); - } - - --depth; - return 0; -} - void CHG_TARIFF::CreateAnswer() { if (!td.tariffConf.name.data().empty()) { TARIFF_DATA tariffData = td.GetData(); - if (m_tariffs.Chg(tariffData, &currAdmin) == 0) - answer = "<" + tag + " Result=\"ok\"/>"; + if (m_tariffs.Chg(tariffData, &m_currAdmin) == 0) + m_answer = "<" + m_tag + " Result=\"ok\"/>"; else - answer = "<" + tag + " Result=\"Change tariff error! " + m_tariffs.GetStrError() + "\"/>"; + m_answer = "<" + m_tag + " Result=\"Change tariff error! " + m_tariffs.GetStrError() + "\"/>"; } else - answer = "<" + tag + " Result=\"Change tariff error!\"/>"; + m_answer = "<" + m_tag + " Result=\"Change tariff error!\"/>"; } diff --git a/projects/stargazer/plugins/configuration/sgconfig/parser_tariffs.h b/projects/stargazer/plugins/configuration/sgconfig/parser_tariffs.h index c96163fe..4e0f4b0b 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/parser_tariffs.h +++ b/projects/stargazer/plugins/configuration/sgconfig/parser_tariffs.h @@ -84,7 +84,6 @@ class CHG_TARIFF: public BASE_PARSER CHG_TARIFF(const ADMIN & admin, TARIFFS & tariffs) : BASE_PARSER(admin, "SetTariff"), m_tariffs(tariffs) {} int Start(void * data, const char * el, const char ** attr); - int End(void * data, const char * el); private: TARIFF_DATA_RES td; diff --git a/projects/stargazer/plugins/configuration/sgconfig/parser_user_info.cpp b/projects/stargazer/plugins/configuration/sgconfig/parser_user_info.cpp index 5a101570..92e1170e 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/parser_user_info.cpp +++ b/projects/stargazer/plugins/configuration/sgconfig/parser_user_info.cpp @@ -30,7 +30,7 @@ using STG::PARSER::USER_INFO; int USER_INFO::Start(void * /*data*/, const char *el, const char **attr) { - if (strcasecmp(el, tag.c_str()) != 0) + if (strcasecmp(el, m_tag.c_str()) != 0) return -1; if (!attr[1]) @@ -45,16 +45,16 @@ void USER_INFO::CreateAnswer() CONST_USER_PTR u; if (m_users.FindByName(m_login, &u)) { - answer = ""; + m_answer = ""; return; } - answer = "GetAuthorizedModificationTime()) + "\"" + + m_answer = "GetAuthorizedModificationTime()) + "\"" + " lastDisconnectTime=\"" + x2str(u->GetConnectedModificationTime()) + "\"" + " connected=\"" + (u->GetConnected() ? "true" : "false") + "\"" + " lastDisconnectReason=\"" + u->GetLastDisconnectReason() + "\">"; std::vector list(u->GetAuthorizers()); for (std::vector::const_iterator it = list.begin(); it != list.end(); ++it) - answer += ""; - answer += ""; + m_answer += ""; + m_answer += ""; } diff --git a/projects/stargazer/plugins/configuration/sgconfig/parser_user_info.h b/projects/stargazer/plugins/configuration/sgconfig/parser_user_info.h index 284b352c..1024983f 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/parser_user_info.h +++ b/projects/stargazer/plugins/configuration/sgconfig/parser_user_info.h @@ -25,6 +25,8 @@ #include +class USERS; + namespace STG { namespace PARSER diff --git a/projects/stargazer/plugins/configuration/sgconfig/parser_users.cpp b/projects/stargazer/plugins/configuration/sgconfig/parser_users.cpp index 2eb92f2b..797b4c46 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/parser_users.cpp +++ b/projects/stargazer/plugins/configuration/sgconfig/parser_users.cpp @@ -169,7 +169,7 @@ std::string UserToXML(const USER & user, bool loginInStart, bool showPass, time_ int GET_USERS::Start(void *, const char * el, const char ** attr) { - if (strcasecmp(el, tag.c_str()) != 0) + if (strcasecmp(el, m_tag.c_str()) != 0) return -1; while (attr && *attr && *(attr + 1)) @@ -188,23 +188,23 @@ void GET_USERS::CreateAnswer() assert(h); if (m_lastUserUpdateTime > 0) - answer = "<" + tag + " LastUpdate=\"" + x2str(time(NULL)) + "\">"; + m_answer = "<" + m_tag + " LastUpdate=\"" + x2str(time(NULL)) + "\">"; else - answer = GetOpenTag(); + m_answer = GetOpenTag(); USER_PTR u; while (m_users.SearchNext(h, &u) == 0) - answer += UserToXML(*u, true, currAdmin.GetPriv()->userConf || currAdmin.GetPriv()->userPasswd, m_lastUserUpdateTime); + m_answer += UserToXML(*u, true, m_currAdmin.GetPriv()->userConf || m_currAdmin.GetPriv()->userPasswd, m_lastUserUpdateTime); m_users.CloseSearch(h); - answer += GetCloseTag(); + m_answer += GetCloseTag(); } int GET_USER::Start(void *, const char * el, const char ** attr) { - if (strcasecmp(el, tag.c_str()) != 0) + if (strcasecmp(el, m_tag.c_str()) != 0) return -1; if (attr[1] == NULL) @@ -219,18 +219,18 @@ void GET_USER::CreateAnswer() CONST_USER_PTR u; if (m_users.FindByName(m_login, &u)) - answer = "<" + tag + " result=\"error\" reason=\"User not found.\"/>"; + m_answer = "<" + m_tag + " result=\"error\" reason=\"User not found.\"/>"; else - answer = UserToXML(*u, false, currAdmin.GetPriv()->userConf || currAdmin.GetPriv()->userPasswd); + m_answer = UserToXML(*u, false, m_currAdmin.GetPriv()->userConf || m_currAdmin.GetPriv()->userPasswd); } int ADD_USER::Start(void *, const char * el, const char ** attr) { - depth++; + m_depth++; - if (depth == 1) + if (m_depth == 1) { - if (strcasecmp(el, tag.c_str()) == 0) + if (strcasecmp(el, m_tag.c_str()) == 0) return 0; } else @@ -244,36 +244,23 @@ int ADD_USER::Start(void *, const char * el, const char ** attr) return -1; } -int ADD_USER::End(void *, const char *el) -{ - if (depth == 1) - { - if (strcasecmp(el, tag.c_str()) == 0) - return -1; - CreateAnswer(); - } - - --depth; - return 0; -} - void ADD_USER::CreateAnswer() { if (m_users.Exists(m_login)) - answer = "<" + tag + " result=\"error\" reason=\"User '" + m_login + "' exists.\"/>"; - else if (m_users.Add(m_login, &currAdmin) == 0) - answer = "<" + tag + " result=\"ok\"/>"; + m_answer = "<" + m_tag + " result=\"error\" reason=\"User '" + m_login + "' exists.\"/>"; + else if (m_users.Add(m_login, &m_currAdmin) == 0) + m_answer = "<" + m_tag + " result=\"ok\"/>"; else - answer = "<" + tag + " result=\"error\" reason=\"Access denied\"/>"; + m_answer = "<" + m_tag + " result=\"error\" reason=\"Access denied\"/>"; } int CHG_USER::Start(void *, const char * el, const char ** attr) { - depth++; + m_depth++; - if (depth == 1) + if (m_depth == 1) { - if (strcasecmp(el, tag.c_str()) == 0) + if (strcasecmp(el, m_tag.c_str()) == 0) return 0; } else @@ -450,26 +437,12 @@ int CHG_USER::Start(void *, const char * el, const char ** attr) return -1; } -int CHG_USER::End(void *, const char *el) -{ - if (depth == 1) - { - if (strcasecmp(el, tag.c_str()) != 0) - return -1; - - CreateAnswer(); - } - - depth--; - return 0; -} - void CHG_USER::CreateAnswer() { if (ApplyChanges() == 0) - answer = "<" + tag + " result=\"ok\"/>"; + m_answer = "<" + m_tag + " result=\"ok\"/>"; else - answer = "<" + tag + " result=\"error\"/>"; + m_answer = "<" + m_tag + " result=\"error\"/>"; } int CHG_USER::ApplyChanges() @@ -497,7 +470,7 @@ int CHG_USER::ApplyChanges() if (check && alwaysOnline && !onlyOneIP) { printfd(__FILE__, "Requested change leads to a forbidden state: AlwaysOnline with multiple IP's\n"); - GetStgLogger()("%s Requested change leads to a forbidden state: AlwaysOnline with multiple IP's", currAdmin.GetLogStr().c_str()); + GetStgLogger()("%s Requested change leads to a forbidden state: AlwaysOnline with multiple IP's", m_currAdmin.GetLogStr().c_str()); return -1; } @@ -508,55 +481,55 @@ int CHG_USER::ApplyChanges() if (m_users.IsIPInUse(ip, m_login, &user)) { printfd(__FILE__, "Trying to assign an IP %s to '%s' that is already in use by '%s'\n", inet_ntostring(ip).c_str(), m_login.c_str(), user->GetLogin().c_str()); - GetStgLogger()("%s trying to assign an IP %s to '%s' that is currently in use by '%s'", currAdmin.GetLogStr().c_str(), inet_ntostring(ip).c_str(), m_login.c_str(), user->GetLogin().c_str()); + GetStgLogger()("%s trying to assign an IP %s to '%s' that is currently in use by '%s'", m_currAdmin.GetLogStr().c_str(), inet_ntostring(ip).c_str(), m_login.c_str(), user->GetLogin().c_str()); return -1; } } if (!m_ucr.ips.empty()) - if (!u->GetProperty().ips.Set(m_ucr.ips.const_data(), &currAdmin, m_login, store)) + if (!u->GetProperty().ips.Set(m_ucr.ips.const_data(), &m_currAdmin, m_login, &m_store)) return -1; if (!m_ucr.alwaysOnline.empty()) if (!u->GetProperty().alwaysOnline.Set(m_ucr.alwaysOnline.const_data(), - &currAdmin, m_login, store)) + &m_currAdmin, m_login, &m_store)) return -1; if (!m_ucr.address.empty()) - if (!u->GetProperty().address.Set(m_ucr.address.const_data(), &currAdmin, m_login, store)) + if (!u->GetProperty().address.Set(m_ucr.address.const_data(), &m_currAdmin, m_login, &m_store)) return -1; if (!m_ucr.creditExpire.empty()) if (!u->GetProperty().creditExpire.Set(m_ucr.creditExpire.const_data(), - &currAdmin, m_login, store)) + &m_currAdmin, m_login, &m_store)) return -1; if (!m_ucr.credit.empty()) - if (!u->GetProperty().credit.Set(m_ucr.credit.const_data(), &currAdmin, m_login, store)) + if (!u->GetProperty().credit.Set(m_ucr.credit.const_data(), &m_currAdmin, m_login, &m_store)) return -1; if (!m_usr.freeMb.empty()) - if (!u->GetProperty().freeMb.Set(m_usr.freeMb.const_data(), &currAdmin, m_login, store)) + if (!u->GetProperty().freeMb.Set(m_usr.freeMb.const_data(), &m_currAdmin, m_login, &m_store)) return -1; if (!m_ucr.disabled.empty()) - if (!u->GetProperty().disabled.Set(m_ucr.disabled.const_data(), &currAdmin, m_login, store)) + if (!u->GetProperty().disabled.Set(m_ucr.disabled.const_data(), &m_currAdmin, m_login, &m_store)) return -1; if (!m_ucr.disabledDetailStat.empty()) - if (!u->GetProperty().disabledDetailStat.Set(m_ucr.disabledDetailStat.const_data(), &currAdmin, m_login, store)) + if (!u->GetProperty().disabledDetailStat.Set(m_ucr.disabledDetailStat.const_data(), &m_currAdmin, m_login, &m_store)) return -1; if (!m_ucr.email.empty()) - if (!u->GetProperty().email.Set(m_ucr.email.const_data(), &currAdmin, m_login, store)) + if (!u->GetProperty().email.Set(m_ucr.email.const_data(), &m_currAdmin, m_login, &m_store)) return -1; if (!m_ucr.group.empty()) - if (!u->GetProperty().group.Set(m_ucr.group.const_data(), &currAdmin, m_login, store)) + if (!u->GetProperty().group.Set(m_ucr.group.const_data(), &m_currAdmin, m_login, &m_store)) return -1; if (!m_ucr.note.empty()) - if (!u->GetProperty().note.Set(m_ucr.note.const_data(), &currAdmin, m_login, store)) + if (!u->GetProperty().note.Set(m_ucr.note.const_data(), &m_currAdmin, m_login, &m_store)) return -1; std::vector *> userdata; @@ -573,23 +546,23 @@ int CHG_USER::ApplyChanges() for (int i = 0; i < (int)userdata.size(); i++) if (!m_ucr.userdata[i].empty()) - if(!userdata[i]->Set(m_ucr.userdata[i].const_data(), &currAdmin, m_login, store)) + if(!userdata[i]->Set(m_ucr.userdata[i].const_data(), &m_currAdmin, m_login, &m_store)) return -1; if (!m_ucr.passive.empty()) - if (!u->GetProperty().passive.Set(m_ucr.passive.const_data(), &currAdmin, m_login, store)) + if (!u->GetProperty().passive.Set(m_ucr.passive.const_data(), &m_currAdmin, m_login, &m_store)) return -1; if (!m_ucr.password.empty()) - if (!u->GetProperty().password.Set(m_ucr.password.const_data(), &currAdmin, m_login, store)) + if (!u->GetProperty().password.Set(m_ucr.password.const_data(), &m_currAdmin, m_login, &m_store)) return -1; if (!m_ucr.phone.empty()) - if (!u->GetProperty().phone.Set(m_ucr.phone.const_data(), &currAdmin, m_login, store)) + if (!u->GetProperty().phone.Set(m_ucr.phone.const_data(), &m_currAdmin, m_login, &m_store)) return -1; if (!m_ucr.realName.empty()) - if (!u->GetProperty().realName.Set(m_ucr.realName.const_data(), &currAdmin, m_login, store)) + if (!u->GetProperty().realName.Set(m_ucr.realName.const_data(), &m_currAdmin, m_login, &m_store)) return -1; @@ -597,13 +570,13 @@ int CHG_USER::ApplyChanges() if (m_cashMustBeAdded) { if (!u->GetProperty().cash.Set(m_usr.cash.const_data() + u->GetProperty().cash, - &currAdmin, + &m_currAdmin, m_login, - store, + &m_store, m_cashMsg)) return -1; else - if (!u->GetProperty().cash.Set(m_usr.cash.const_data(), &currAdmin, m_login, store, m_cashMsg)) + if (!u->GetProperty().cash.Set(m_usr.cash.const_data(), &m_currAdmin, m_login, &m_store, m_cashMsg)) return -1; } @@ -612,7 +585,7 @@ int CHG_USER::ApplyChanges() { if (m_tariffs.FindByName(m_ucr.tariffName.const_data())) { - if (!u->GetProperty().tariffName.Set(m_ucr.tariffName.const_data(), &currAdmin, m_login, store)) + if (!u->GetProperty().tariffName.Set(m_ucr.tariffName.const_data(), &m_currAdmin, m_login, &m_store)) return -1; u->ResetNextTariff(); } @@ -627,7 +600,7 @@ int CHG_USER::ApplyChanges() { if (m_tariffs.FindByName(m_ucr.nextTariff.const_data())) { - if (!u->GetProperty().nextTariff.Set(m_ucr.nextTariff.const_data(), &currAdmin, m_login, store)) + if (!u->GetProperty().nextTariff.Set(m_ucr.nextTariff.const_data(), &m_currAdmin, m_login, &m_store)) return -1; } else @@ -656,11 +629,11 @@ int CHG_USER::ApplyChanges() } if (upCount) - if (!u->GetProperty().up.Set(up, &currAdmin, m_login, store)) + if (!u->GetProperty().up.Set(up, &m_currAdmin, m_login, &m_store)) return -1; if (downCount) - if (!u->GetProperty().down.Set(down, &currAdmin, m_login, store)) + if (!u->GetProperty().down.Set(down, &m_currAdmin, m_login, &m_store)) return -1; u->WriteConf(); @@ -672,7 +645,7 @@ int CHG_USER::ApplyChanges() int DEL_USER::Start(void *, const char *el, const char **attr) { res = 0; - if (strcasecmp(el, tag.c_str()) == 0) + if (strcasecmp(el, m_tag.c_str()) == 0) { if (attr[0] == NULL || attr[1] == NULL) { @@ -695,10 +668,10 @@ int DEL_USER::Start(void *, const char *el, const char **attr) int DEL_USER::End(void *, const char *el) { - if (strcasecmp(el, tag.c_str()) == 0) + if (strcasecmp(el, m_tag.c_str()) == 0) { if (!res) - m_users.Del(u->GetLogin(), &currAdmin); + m_users.Del(u->GetLogin(), &m_currAdmin); return 0; } @@ -708,14 +681,14 @@ int DEL_USER::End(void *, const char *el) void DEL_USER::CreateAnswer() { if (res) - answer = "<" + tag + " value=\"error\" reason=\"User not found\"/>"; + m_answer = "<" + m_tag + " value=\"error\" reason=\"User not found\"/>"; else - answer = "<" + tag + " value=\"ok\"/>"; + m_answer = "<" + m_tag + " value=\"ok\"/>"; } int CHECK_USER::Start(void *, const char *el, const char **attr) { - if (strcasecmp(el, tag.c_str()) == 0) + if (strcasecmp(el, m_tag.c_str()) == 0) { if (attr[0] == NULL || attr[1] == NULL || attr[2] == NULL || attr[3] == NULL) @@ -748,7 +721,7 @@ int CHECK_USER::Start(void *, const char *el, const char **attr) int CHECK_USER::End(void *, const char *el) { - if (strcasecmp(el, tag.c_str()) == 0) + if (strcasecmp(el, m_tag.c_str()) == 0) return 0; return -1; } @@ -756,7 +729,7 @@ int CHECK_USER::End(void *, const char *el) void CHECK_USER::CreateAnswer(const char * error) { if (error) - answer = "<" + tag + " value=\"Err\" reason=\"" + error + "\"/>"; + m_answer = "<" + m_tag + " value=\"Err\" reason=\"" + error + "\"/>"; else - answer = "<" + tag + " value=\"Ok\"/>"; + m_answer = "<" + m_tag + " value=\"Ok\"/>"; } diff --git a/projects/stargazer/plugins/configuration/sgconfig/parser_users.h b/projects/stargazer/plugins/configuration/sgconfig/parser_users.h index 50675bae..bd758f5a 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/parser_users.h +++ b/projects/stargazer/plugins/configuration/sgconfig/parser_users.h @@ -34,6 +34,7 @@ class USERS; class USER; class TARIFFS; class ADMIN; +class STORE; namespace STG { @@ -75,7 +76,6 @@ class ADD_USER: public BASE_PARSER ADD_USER(const ADMIN & admin, USERS & users) : BASE_PARSER(admin, "AddUser"), m_users(users) {} int Start(void * data, const char * el, const char ** attr); - int End(void * data, const char * el); private: USERS & m_users; @@ -87,18 +87,20 @@ class ADD_USER: public BASE_PARSER class CHG_USER: public BASE_PARSER { public: - CHG_USER(const ADMIN & admin, USERS & users, const TARIFFS & tariffs) + CHG_USER(const ADMIN & admin, USERS & users, + STORE & store, const TARIFFS & tariffs) : BASE_PARSER(admin, "SetUser"), m_users(users), + m_store(store), m_tariffs(tariffs), m_cashMustBeAdded(false), m_res(0) {} int Start(void * data, const char * el, const char ** attr); - int End(void * data, const char * el); private: USERS & m_users; + STORE & m_store; const TARIFFS & m_tariffs; USER_STAT_RES m_usr; USER_CONF_RES m_ucr; diff --git a/projects/stargazer/plugins/configuration/sgconfig/stgconfig.h b/projects/stargazer/plugins/configuration/sgconfig/stgconfig.h index 8123899f..31f9b1be 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/stgconfig.h +++ b/projects/stargazer/plugins/configuration/sgconfig/stgconfig.h @@ -47,11 +47,11 @@ public: STG_CONFIG(); virtual ~STG_CONFIG(){} - void SetUsers(USERS * users) { config.SetUsers(users); } - void SetTariffs(TARIFFS * tariffs) { config.SetTariffs(tariffs); } + void SetUsers(USERS *) {} + void SetTariffs(TARIFFS *) {} void SetAdmins(ADMINS * admins) { config.SetAdmins(admins); } - void SetStore(STORE * store) { config.SetStore(store); } - void SetStgSettings(const SETTINGS * settings) { config.SetStgSettings(settings); } + void SetStore(STORE *) {} + void SetStgSettings(const SETTINGS *) {} void SetSettings(const MODULE_SETTINGS & s) { settings = s; } int ParseSettings();