From 54a10a471694273384a0d07a8888c2d40a9daa0b Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Sun, 28 Sep 2014 18:44:26 +0300 Subject: [PATCH 01/16] Removed old InitEncrypt function. --- .../authorization/inetaccess/inetaccess.cpp | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/projects/stargazer/plugins/authorization/inetaccess/inetaccess.cpp b/projects/stargazer/plugins/authorization/inetaccess/inetaccess.cpp index f64211d0..9c8ae1af 100644 --- a/projects/stargazer/plugins/authorization/inetaccess/inetaccess.cpp +++ b/projects/stargazer/plugins/authorization/inetaccess/inetaccess.cpp @@ -55,8 +55,6 @@ extern volatile time_t stgTime; namespace { PLUGIN_CREATOR iac; - -void InitEncrypt(BLOWFISH_CTX * ctx, const std::string & password); } extern "C" PLUGIN * GetPlugin(); @@ -1718,16 +1716,3 @@ ip2user.erase(it); return res; } -namespace -{ -//----------------------------------------------------------------------------- -inline -void InitEncrypt(BLOWFISH_CTX * ctx, const std::string & password) -{ -unsigned char keyL[PASSWD_LEN]; -memset(keyL, 0, PASSWD_LEN); -strncpy((char *)keyL, password.c_str(), PASSWD_LEN); -Blowfish_Init(ctx, keyL, PASSWD_LEN); -} -//----------------------------------------------------------------------------- -} -- 2.44.2 From 458b15bd1de32319a96a909e2797ed2ca3a4aed1 Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Sun, 28 Sep 2014 18:44:45 +0300 Subject: [PATCH 02/16] Removed unused m_res class member. --- .../stargazer/plugins/configuration/sgconfig/parser_users.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/projects/stargazer/plugins/configuration/sgconfig/parser_users.h b/projects/stargazer/plugins/configuration/sgconfig/parser_users.h index 0ef1cb95..c9f72389 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/parser_users.h +++ b/projects/stargazer/plugins/configuration/sgconfig/parser_users.h @@ -150,8 +150,7 @@ class CHG_USER: public BASE_PARSER m_users(users), m_store(store), m_tariffs(tariffs), - m_cashMustBeAdded(false), - m_res(0) {} + m_cashMustBeAdded(false) {} int Start(void * data, const char * el, const char ** attr); @@ -166,7 +165,6 @@ class CHG_USER: public BASE_PARSER std::string m_cashMsg; std::string m_login; bool m_cashMustBeAdded; - int m_res; int ApplyChanges(); void CreateAnswer(); -- 2.44.2 From 9af0b6faad1f5e6ca2206f7cddc02885a08e718c Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Sun, 28 Sep 2014 18:45:07 +0300 Subject: [PATCH 03/16] Removed unused constants. --- stglibs/srvconf.lib/parsers/server_info.cpp | 9 --------- 1 file changed, 9 deletions(-) diff --git a/stglibs/srvconf.lib/parsers/server_info.cpp b/stglibs/srvconf.lib/parsers/server_info.cpp index 50dbb2cc..22a0e43c 100644 --- a/stglibs/srvconf.lib/parsers/server_info.cpp +++ b/stglibs/srvconf.lib/parsers/server_info.cpp @@ -29,15 +29,6 @@ using namespace STG; -namespace -{ - -const size_t UNAME_LEN = 256; -const size_t SERV_VER_LEN = 64; -const size_t DIRNAME_LEN = 16; - -} - SERVER_INFO::PARSER::PARSER(CALLBACK f, void * d, const std::string & e) : callback(f), data(d), -- 2.44.2 From d1d65fe3185a6c2178bbca46e9f409bd8d747c7f Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Sun, 28 Sep 2014 18:46:14 +0300 Subject: [PATCH 04/16] Removed unused constant from netunit.cpp. --- stglibs/srvconf.lib/netunit.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/stglibs/srvconf.lib/netunit.cpp b/stglibs/srvconf.lib/netunit.cpp index 6436e4f9..182d338c 100644 --- a/stglibs/srvconf.lib/netunit.cpp +++ b/stglibs/srvconf.lib/netunit.cpp @@ -45,8 +45,6 @@ using namespace STG; namespace { -const std::string::size_type MAX_XML_CHUNK_LENGTH = 2048; - struct ReadState { bool final; -- 2.44.2 From 86b8aab2752e68ca1844896c54e6083d88cac23b Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Sun, 28 Sep 2014 18:47:51 +0300 Subject: [PATCH 05/16] Removed "alpha" from version. --- projects/sgconf/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/sgconf/main.cpp b/projects/sgconf/main.cpp index a93233f2..82372224 100644 --- a/projects/sgconf/main.cpp +++ b/projects/sgconf/main.cpp @@ -120,7 +120,7 @@ return CONST_METHOD1_ADAPTER(func, obj); void Version(const std::string & self) { -std::cout << self << ", version: 2.0.0-alpha.\n"; +std::cout << self << ", version: 2.0.0.\n"; } void ReadUserConfigFile(SGCONF::OPTION_BLOCK & block) -- 2.44.2 From fa37e48043079fdf1a33c695c75f83706d59e46b Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Sun, 28 Sep 2014 19:07:47 +0300 Subject: [PATCH 06/16] Better error reporting in netunit.cpp. --- stglibs/srvconf.lib/netunit.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stglibs/srvconf.lib/netunit.cpp b/stglibs/srvconf.lib/netunit.cpp index 182d338c..42b301a5 100644 --- a/stglibs/srvconf.lib/netunit.cpp +++ b/stglibs/srvconf.lib/netunit.cpp @@ -122,7 +122,7 @@ if (!localAddress.empty()) struct hostent * phe = gethostbyname(localAddress.c_str()); if (phe == NULL) { - errorMsg = "DNS error.\nCan not reslove " + localAddress; + errorMsg = "Can not reslove '" + localAddress + "'"; return st_dns_err; } @@ -154,7 +154,7 @@ if (ip == INADDR_NONE) struct hostent * phe = gethostbyname(server.c_str()); if (phe == NULL) { - errorMsg = "DNS error.\nCan not reslove " + server; + errorMsg = "Can not reslove '" + server + "'"; return st_dns_err; } -- 2.44.2 From 0347d1faca21404b65dd648033e066029abdebb6 Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Sun, 28 Sep 2014 19:08:03 +0300 Subject: [PATCH 07/16] Register services and corporations within sgconfig plugin. --- .../configuration/sgconfig/configproto.cpp | 11 +++++++ .../configuration/sgconfig/configproto.h | 30 +++++++++++-------- .../configuration/sgconfig/stgconfig.h | 2 ++ 3 files changed, 30 insertions(+), 13 deletions(-) diff --git a/projects/stargazer/plugins/configuration/sgconfig/configproto.cpp b/projects/stargazer/plugins/configuration/sgconfig/configproto.cpp index 9f67f181..f012fa1a 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/configproto.cpp +++ b/projects/stargazer/plugins/configuration/sgconfig/configproto.cpp @@ -27,6 +27,7 @@ #include "parser_admins.h" #include "parser_tariffs.h" #include "parser_users.h" +#include "parser_services.h" #include "parser_message.h" #include "parser_user_info.h" #include "parser_auth_by.h" @@ -54,6 +55,8 @@ CONFIGPROTO::CONFIGPROTO(PLUGIN_LOGGER & l) m_admins(NULL), m_tariffs(NULL), m_users(NULL), + m_services(NULL), + m_corporations(NULL), m_store(NULL), m_port(0), m_bindAddress("0.0.0.0"), @@ -208,6 +211,8 @@ void CONFIGPROTO::RegisterParsers() assert(m_admins != NULL); assert(m_users != NULL); assert(m_tariffs != NULL); + assert(m_services != NULL); + assert(m_corporations != NULL); SP::GET_SERVER_INFO::FACTORY::Register(m_registry, *m_settings, *m_users, *m_tariffs); @@ -228,6 +233,12 @@ void CONFIGPROTO::RegisterParsers() SP::CHG_USER::FACTORY::Register(m_registry, *m_users, *m_store, *m_tariffs); SP::CHECK_USER::FACTORY::Register(m_registry, *m_users); + SP::GET_SERVICES::FACTORY::Register(m_registry, *m_services); + SP::GET_SERVICE::FACTORY::Register(m_registry, *m_services); + SP::ADD_SERVICE::FACTORY::Register(m_registry, *m_services); + SP::DEL_SERVICE::FACTORY::Register(m_registry, *m_services); + SP::CHG_SERVICE::FACTORY::Register(m_registry, *m_services); + SP::SEND_MESSAGE::FACTORY::Register(m_registry, *m_users); SP::AUTH_BY::FACTORY::Register(m_registry, *m_users); diff --git a/projects/stargazer/plugins/configuration/sgconfig/configproto.h b/projects/stargazer/plugins/configuration/sgconfig/configproto.h index 2119bc67..e18ae82e 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/configproto.h +++ b/projects/stargazer/plugins/configuration/sgconfig/configproto.h @@ -38,6 +38,8 @@ class SETTINGS; class ADMINS; class TARIFFS; class USERS; +class SERVICES; +class CORPORATIONS; class STORE; class PLUGIN_LOGGER; @@ -53,18 +55,20 @@ public: CONFIGPROTO(PLUGIN_LOGGER & l); ~CONFIGPROTO(); - void SetPort(uint16_t port) { m_port = port; } - void SetBindAddress(const std::string & address) { m_bindAddress = address; } - void SetSettings(const SETTINGS * settings) { m_settings = settings; } - void SetAdmins(ADMINS * admins) { m_admins = admins; } - void SetTariffs(TARIFFS * tariffs) { m_tariffs = tariffs; } - void SetUsers(USERS * users) { m_users = users; } - void SetStore(STORE * store) { m_store = store; } - - int Prepare(); - int Stop(); + void SetPort(uint16_t port) { m_port = port; } + void SetBindAddress(const std::string & address) { m_bindAddress = address; } + void SetSettings(const SETTINGS * settings) { m_settings = settings; } + void SetAdmins(ADMINS * admins) { m_admins = admins; } + void SetTariffs(TARIFFS * tariffs) { m_tariffs = tariffs; } + void SetUsers(USERS * users) { m_users = users; } + void SetServices(SERVICES * services) { m_services = services; } + void SetCorporations(CORPORATIONS * corporations) { m_corporations = corporations; } + void SetStore(STORE * store) { m_store = store; } + + int Prepare(); + int Stop(); const std::string & GetStrError() const { return m_errorStr; } - void Run(); + void Run(); private: CONFIGPROTO(const CONFIGPROTO & rvalue); @@ -74,6 +78,8 @@ private: ADMINS * m_admins; TARIFFS * m_tariffs; USERS * m_users; + SERVICES * m_services; + CORPORATIONS * m_corporations; STORE * m_store; uint16_t m_port; @@ -97,8 +103,6 @@ private: void CleanupConns(); void HandleEvents(const fd_set & fds); void AcceptConnection(); - - //void WriteLogAccessFailed(uint32_t ip); }; #endif //CONFIGPROTO_H diff --git a/projects/stargazer/plugins/configuration/sgconfig/stgconfig.h b/projects/stargazer/plugins/configuration/sgconfig/stgconfig.h index 287c3813..8902766a 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/stgconfig.h +++ b/projects/stargazer/plugins/configuration/sgconfig/stgconfig.h @@ -53,6 +53,8 @@ class STG_CONFIG : public PLUGIN void SetUsers(USERS * users) { config.SetUsers(users); } void SetTariffs(TARIFFS * tariffs) { config.SetTariffs(tariffs); } void SetAdmins(ADMINS * admins) { config.SetAdmins(admins); } + void SetServices(SERVICES * services) { config.SetServices(services); } + void SetCorporations(CORPORATIONS * corporations) { config.SetCorporations( corporations); } void SetStore(STORE * store) { config.SetStore(store); } void SetStgSettings(const SETTINGS * s) { config.SetSettings(s); } void SetSettings(const MODULE_SETTINGS & s) { settings = s; } -- 2.44.2 From 4f778b02c9e44e65183b96f3c0db3b22deaf69f9 Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Fri, 3 Oct 2014 12:00:24 +0300 Subject: [PATCH 08/16] Format pay day as int rather then char. --- projects/sgconf/services.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/sgconf/services.cpp b/projects/sgconf/services.cpp index 22a64013..e2bf9bf6 100644 --- a/projects/sgconf/services.cpp +++ b/projects/sgconf/services.cpp @@ -28,7 +28,7 @@ void PrintService(const STG::GET_SERVICE::INFO & info, size_t level = 0) { std::cout << Indent(level, true) << "name: " << info.name << "\n" << Indent(level) << "cost: " << info.cost << "\n" - << Indent(level) << "payment day: " << info.payDay << "\n" + << Indent(level) << "payment day: " << static_cast(info.payDay) << "\n" << Indent(level) << "comment: " << info.comment << "\n"; } -- 2.44.2 From 8ea089c181fa66c80f3ad8f933fca1c96a7ba4ae Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Fri, 3 Oct 2014 12:01:13 +0300 Subject: [PATCH 09/16] Set LC_NUMERIC to C, changes service serialization format. --- stglibs/srvconf.lib/servconf.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/stglibs/srvconf.lib/servconf.cpp b/stglibs/srvconf.lib/servconf.cpp index 78db78c8..71d36a7b 100644 --- a/stglibs/srvconf.lib/servconf.cpp +++ b/stglibs/srvconf.lib/servconf.cpp @@ -281,7 +281,7 @@ return pImpl->Exec("", f int SERVCONF::ChgService(const SERVICE_CONF_RES & conf, SIMPLE::CALLBACK f, void * data) { -return pImpl->Exec("SetService", "" + CHG_SERVICE::Serialize(conf, pImpl->Encoding()) + "", f, data); +return pImpl->Exec("SetService", "Encoding()) + "/>", f, data); } int SERVCONF::AddService(const std::string & name, @@ -291,7 +291,7 @@ int SERVCONF::AddService(const std::string & name, int res = pImpl->Exec("AddService", "", f, data); if (res != st_ok) return res; -return pImpl->Exec("SetService", "" + CHG_SERVICE::Serialize(conf, pImpl->Encoding()) + "", f, data); +return pImpl->Exec("SetService", "Encoding()) + "/>", f, data); } int SERVCONF::DelService(const std::string & name, SIMPLE::CALLBACK f, void * data) @@ -342,6 +342,7 @@ SERVCONF::IMPL::IMPL(const std::string & server, uint16_t port, : nt(server, port, login, password) { setlocale(LC_ALL, ""); +setlocale(LC_NUMERIC, "C"); encoding = nl_langinfo(CODESET); parser = XML_ParserCreate(NULL); } @@ -352,6 +353,7 @@ SERVCONF::IMPL::IMPL(const std::string & server, uint16_t port, : nt(server, port, localAddress, localPort, login, password) { setlocale(LC_ALL, ""); +setlocale(LC_NUMERIC, "C"); encoding = nl_langinfo(CODESET); parser = XML_ParserCreate(NULL); } -- 2.44.2 From f8ca79f0620b6738a4714f1ccadf6a1c9ac73947 Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Fri, 3 Oct 2014 12:01:52 +0300 Subject: [PATCH 10/16] Added resetable utils for attributes. --- stglibs/srvconf.lib/parsers/resetable_utils.h | 80 ++++++++++++++++++- 1 file changed, 76 insertions(+), 4 deletions(-) diff --git a/stglibs/srvconf.lib/parsers/resetable_utils.h b/stglibs/srvconf.lib/parsers/resetable_utils.h index 088cb327..6f026adf 100644 --- a/stglibs/srvconf.lib/parsers/resetable_utils.h +++ b/stglibs/srvconf.lib/parsers/resetable_utils.h @@ -32,18 +32,90 @@ namespace STG template inline -void appendResetable(std::ostream & stream, const std::string & name, const T & value) +void appendTag(std::ostream & stream, const std::string & name, const T & value) +{ + stream << "<" << name << " value=\"" << value << "\"/>"; +} + +template +inline +void appendTag(std::ostream & stream, const std::string & name, size_t suffix, const T & value) +{ + stream << "<" << name << suffix << " value=\"" << value << "\"/>"; +} + +template <> +inline +void appendTag(std::ostream & stream, const std::string & name, const uint8_t & value) +{ + stream << "<" << name << " value=\"" << static_cast(value) << "\"/>"; +} + +template <> +inline +void appendTag(std::ostream & stream, const std::string & name, const int8_t & value) +{ + stream << "<" << name << " value=\"" << static_cast(value) << "\"/>"; +} + +template +inline +void appendAttr(std::ostream & stream, const std::string & name, const T & value) +{ + stream << " " << name << "=\"" << value << "\""; +} + +template +inline +void appendAttr(std::ostream & stream, const std::string & name, size_t suffix, const T & value) +{ + stream << " " << name << suffix << "=\"" << value << "\""; +} + +template <> +inline +void appendAttr(std::ostream & stream, const std::string & name, const uint8_t & value) +{ + stream << " " << name << "=\"" << static_cast(value) << "\""; +} + +template <> +inline +void appendAttr(std::ostream & stream, const std::string & name, const int8_t & value) +{ + stream << " " << name << "=\"" << static_cast(value) << "\""; +} + +template +inline +void appendResetableTag(std::ostream & stream, const std::string & name, const T & value) +{ +if (!value.empty()) + appendTag(stream, name, value.const_data()); +} + +template +inline +void appendResetableTag(std::ostream & stream, const std::string & name, size_t suffix, const T & value) +{ +if (!value.empty()) + appendTag(stream, name, suffix, value.const_data()); +} + +template +inline +void appendResetableAttr(std::ostream & stream, const std::string & name, const T & value) { if (!value.empty()) - stream << "<" << name << " value=\"" << value.data() << "\"/>"; + appendAttr(stream, name, value.const_data()); } template inline -void appendResetable(std::ostream & stream, const std::string & name, size_t suffix, const T & value) +void appendResetableAttr(std::ostream & stream, const std::string & name, size_t suffix, const T & value) { if (!value.empty()) - stream << "<" << name << suffix << " value=\"" << value.data() << "\"/>"; + appendAttr(stream, name, suffix, value.const_data()); } inline -- 2.44.2 From be3d58dbca4e5aeb16c15983ca59a1db56b9fd7a Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Fri, 3 Oct 2014 12:02:30 +0300 Subject: [PATCH 11/16] Fixed compilaton errors. --- stglibs/srvconf.lib/parsers/chg_corp.cpp | 4 +-- stglibs/srvconf.lib/parsers/chg_service.cpp | 8 ++--- stglibs/srvconf.lib/parsers/chg_tariff.cpp | 6 ++-- stglibs/srvconf.lib/parsers/chg_user.cpp | 34 ++++++++++----------- stglibs/srvconf.lib/parsers/get_service.cpp | 18 ++++++++--- stglibs/srvconf.lib/parsers/get_service.h | 2 +- 6 files changed, 41 insertions(+), 31 deletions(-) diff --git a/stglibs/srvconf.lib/parsers/chg_corp.cpp b/stglibs/srvconf.lib/parsers/chg_corp.cpp index daa54644..852fe8e1 100644 --- a/stglibs/srvconf.lib/parsers/chg_corp.cpp +++ b/stglibs/srvconf.lib/parsers/chg_corp.cpp @@ -33,8 +33,8 @@ std::string CHG_CORP::Serialize(const CORP_CONF_RES & conf, const std::string & { std::ostringstream stream; -appendResetable(stream, "name", conf.name); -appendResetable(stream, "cash", conf.cash); +appendResetableTag(stream, "name", conf.name); +appendResetableTag(stream, "cash", conf.cash); return stream.str(); } diff --git a/stglibs/srvconf.lib/parsers/chg_service.cpp b/stglibs/srvconf.lib/parsers/chg_service.cpp index 7dac5ba9..6bea7565 100644 --- a/stglibs/srvconf.lib/parsers/chg_service.cpp +++ b/stglibs/srvconf.lib/parsers/chg_service.cpp @@ -33,10 +33,10 @@ std::string CHG_SERVICE::Serialize(const SERVICE_CONF_RES & conf, const std::str { std::ostringstream stream; -appendResetable(stream, "name", conf.name); -appendResetable(stream, "comment", MaybeEncode(conf.comment)); -appendResetable(stream, "cost", conf.cost); -appendResetable(stream, "payDay", conf.payDay); +appendResetableAttr(stream, "name", conf.name); +appendResetableAttr(stream, "comment", MaybeEncode(conf.comment)); +appendResetableAttr(stream, "cost", conf.cost); +appendResetableAttr(stream, "payDay", conf.payDay); return stream.str(); } diff --git a/stglibs/srvconf.lib/parsers/chg_tariff.cpp b/stglibs/srvconf.lib/parsers/chg_tariff.cpp index 8a1c56a4..158e6f89 100644 --- a/stglibs/srvconf.lib/parsers/chg_tariff.cpp +++ b/stglibs/srvconf.lib/parsers/chg_tariff.cpp @@ -55,9 +55,9 @@ std::string CHG_TARIFF::Serialize(const TARIFF_DATA_RES & data, const std::strin { std::ostringstream stream; -appendResetable(stream, "fee", data.tariffConf.fee); -appendResetable(stream, "passiveCost", data.tariffConf.passiveCost); -appendResetable(stream, "free", data.tariffConf.free); +appendResetableTag(stream, "fee", data.tariffConf.fee); +appendResetableTag(stream, "passiveCost", data.tariffConf.passiveCost); +appendResetableTag(stream, "free", data.tariffConf.free); if (!data.tariffConf.traffType.empty()) stream << ""; diff --git a/stglibs/srvconf.lib/parsers/chg_user.cpp b/stglibs/srvconf.lib/parsers/chg_user.cpp index f0027968..e30392f3 100644 --- a/stglibs/srvconf.lib/parsers/chg_user.cpp +++ b/stglibs/srvconf.lib/parsers/chg_user.cpp @@ -78,30 +78,30 @@ std::ostringstream stream; // Conf -appendResetable(stream, "credit", conf.credit); -appendResetable(stream, "creditExpire", conf.creditExpire); -appendResetable(stream, "password", conf.password); -appendResetable(stream, "down", conf.disabled); // TODO: down -> disabled -appendResetable(stream, "passive", conf.passive); -appendResetable(stream, "disableDetailStat", conf.disabledDetailStat); // TODO: disable -> disabled -appendResetable(stream, "aonline", conf.alwaysOnline); // TODO: aonline -> alwaysOnline -appendResetable(stream, "ip", conf.ips); // TODO: ip -> ips +appendResetableTag(stream, "credit", conf.credit); +appendResetableTag(stream, "creditExpire", conf.creditExpire); +appendResetableTag(stream, "password", conf.password); +appendResetableTag(stream, "down", conf.disabled); // TODO: down -> disabled +appendResetableTag(stream, "passive", conf.passive); +appendResetableTag(stream, "disableDetailStat", conf.disabledDetailStat); // TODO: disable -> disabled +appendResetableTag(stream, "aonline", conf.alwaysOnline); // TODO: aonline -> alwaysOnline +appendResetableTag(stream, "ip", conf.ips); // TODO: ip -> ips if (!conf.nextTariff.empty()) stream << ""; else if (!conf.tariffName.empty()) stream << ""; -appendResetable(stream, "note", MaybeEncode(MaybeIconv(conf.note, encoding, "koi8-ru"))); -appendResetable(stream, "name", MaybeEncode(MaybeIconv(conf.realName, encoding, "koi8-ru"))); // TODO: name -> realName -appendResetable(stream, "address", MaybeEncode(MaybeIconv(conf.address, encoding, "koi8-ru"))); -appendResetable(stream, "email", MaybeEncode(MaybeIconv(conf.email, encoding, "koi8-ru"))); -appendResetable(stream, "phone", MaybeEncode(MaybeIconv(conf.phone, encoding, "cp1251"))); -appendResetable(stream, "group", MaybeEncode(MaybeIconv(conf.group, encoding, "koi8-ru"))); -appendResetable(stream, "corp", conf.corp); +appendResetableTag(stream, "note", MaybeEncode(MaybeIconv(conf.note, encoding, "koi8-ru"))); +appendResetableTag(stream, "name", MaybeEncode(MaybeIconv(conf.realName, encoding, "koi8-ru"))); // TODO: name -> realName +appendResetableTag(stream, "address", MaybeEncode(MaybeIconv(conf.address, encoding, "koi8-ru"))); +appendResetableTag(stream, "email", MaybeEncode(MaybeIconv(conf.email, encoding, "koi8-ru"))); +appendResetableTag(stream, "phone", MaybeEncode(MaybeIconv(conf.phone, encoding, "cp1251"))); +appendResetableTag(stream, "group", MaybeEncode(MaybeIconv(conf.group, encoding, "koi8-ru"))); +appendResetableTag(stream, "corp", conf.corp); for (size_t i = 0; i < conf.userdata.size(); ++i) - appendResetable(stream, "userdata", i, MaybeEncode(MaybeIconv(conf.userdata[i], encoding, "koi8-ru"))); + appendResetableTag(stream, "userdata", i, MaybeEncode(MaybeIconv(conf.userdata[i], encoding, "koi8-ru"))); if (!conf.services.empty()) { @@ -118,7 +118,7 @@ if (!stat.cashAdd.empty()) else if (!stat.cashSet.empty()) stream << ""; -appendResetable(stream, "freeMb", stat.freeMb); +appendResetableTag(stream, "freeMb", stat.freeMb); std::ostringstream traff; for (size_t i = 0; i < stat.sessionUp.size(); ++i) diff --git a/stglibs/srvconf.lib/parsers/get_service.cpp b/stglibs/srvconf.lib/parsers/get_service.cpp index 6f98fc23..f6de8e51 100644 --- a/stglibs/srvconf.lib/parsers/get_service.cpp +++ b/stglibs/srvconf.lib/parsers/get_service.cpp @@ -54,8 +54,8 @@ depth++; if (depth == 1) ParseService(el, attr); -if (depth == 2 && parsingAnswer) - ParseServiceParams(el, attr); +/*if (depth == 2 && parsingAnswer) + ParseServiceParams(el, attr);*/ return 0; } @@ -86,15 +86,25 @@ if (strcasecmp(el, "service") == 0) error = "Service not found."; } else + { parsingAnswer = true; + for (const char ** pos = attr; *pos != NULL; pos = pos + 2) + if (!TryParse(propertyParsers, ToLower(*pos), pos, encoding, *pos)) + { + error = std::string("Invalid parameter '") + *pos + "' or value '" + *(pos + 1) + "'."; + break; + } + else + printfd(__FILE__, "Parsed '%s' successfully.\n", *pos); + } } else parsingAnswer = true; } } //----------------------------------------------------------------------------- -void GET_SERVICE::PARSER::ParseServiceParams(const char * el, const char ** attr) +/*void GET_SERVICE::PARSER::ParseServiceParams(const char * el, const char ** attr) { if (!TryParse(propertyParsers, ToLower(el), attr, encoding)) error = "Invalid parameter."; -} +}*/ diff --git a/stglibs/srvconf.lib/parsers/get_service.h b/stglibs/srvconf.lib/parsers/get_service.h index fe29ec09..d8213627 100644 --- a/stglibs/srvconf.lib/parsers/get_service.h +++ b/stglibs/srvconf.lib/parsers/get_service.h @@ -55,7 +55,7 @@ private: std::string error; void ParseService(const char * el, const char ** attr); - void ParseServiceParams(const char * el, const char ** attr); + //void ParseServiceParams(const char * el, const char ** attr); }; } // namespace GET_SERVICE -- 2.44.2 From 5014a9d76df7cbe75b175d635908049ccd702c81 Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Fri, 3 Oct 2014 12:07:02 +0300 Subject: [PATCH 12/16] Fixed tag named, keep old values using Splice. --- .../configuration/sgconfig/parser_services.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/projects/stargazer/plugins/configuration/sgconfig/parser_services.cpp b/projects/stargazer/plugins/configuration/sgconfig/parser_services.cpp index 59e7f03c..0c1e1476 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/parser_services.cpp +++ b/projects/stargazer/plugins/configuration/sgconfig/parser_services.cpp @@ -34,7 +34,7 @@ const char * GET_SERVICES::tag = "GetServices"; const char * GET_SERVICE::tag = "AddService"; const char * ADD_SERVICE::tag = "AddService"; const char * DEL_SERVICE::tag = "DelService"; -const char * CHG_SERVICE::tag = "ChgService"; +const char * CHG_SERVICE::tag = "SetService"; void GET_SERVICES::CreateAnswer() { @@ -133,7 +133,6 @@ int CHG_SERVICE::Start(void *, const char * el, const char ** attr) { for (size_t i = 0; i < 8; i += 2) { - printfd(__FILE__, "PARSER_CHG_SERVICE::attr[%d] = %s\n", i, attr[i]); if (attr[i] == NULL) break; @@ -154,6 +153,8 @@ int CHG_SERVICE::Start(void *, const char * el, const char ** attr) double cost = 0; if (str2x(attr[i + 1], cost) == 0) m_service.cost = cost; + else + printfd(__FILE__, "Bad cast from '%s' to double\n", attr[i + 1]); // TODO: log it continue; } @@ -163,6 +164,8 @@ int CHG_SERVICE::Start(void *, const char * el, const char ** attr) unsigned payDay; if (str2x(attr[i + 1], payDay) == 0) m_service.payDay = payDay; + else + printfd(__FILE__, "Bad cast from '%s' to unsigned\n", attr[i + 1]); // TODO: log it continue; } @@ -190,9 +193,10 @@ void CHG_SERVICE::CreateAnswer() SERVICE_CONF orig; m_services.Find(m_service.name.const_data(), &orig); - m_service.Splice(orig); + SERVICE_CONF_RES conf(orig); + conf.Splice(m_service); - if (m_services.Change(m_service.GetData(), &m_currAdmin) != 0) + if (m_services.Change(conf.GetData(), &m_currAdmin) != 0) m_answer = "<" + m_tag + " result = \"" + m_services.GetStrError() + "\"/>"; else m_answer = "<" + m_tag + " result = \"Ok\"/>"; -- 2.44.2 From d7e2dad86a72fd5a3cd8717a9e1518832c193a3e Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Fri, 3 Oct 2014 12:07:49 +0300 Subject: [PATCH 13/16] Added SERVICES::Find for resetable value. --- include/stg/services.h | 1 + projects/stargazer/services_impl.cpp | 33 +++++++++++++++++++++++----- projects/stargazer/services_impl.h | 1 + 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/include/stg/services.h b/include/stg/services.h index 1fe4dca1..140391d0 100644 --- a/include/stg/services.h +++ b/include/stg/services.h @@ -34,6 +34,7 @@ public: virtual int Del(const std::string & name, const ADMIN * admin) = 0; virtual int Change(const SERVICE_CONF & service, const ADMIN * admin) = 0; virtual bool Find(const std::string & name, SERVICE_CONF * service) const = 0; + virtual bool Find(const std::string & name, SERVICE_CONF_RES * service) const = 0; virtual bool Exists(const std::string & name) const = 0; virtual const std::string & GetStrError() const = 0; virtual size_t Count() const = 0; diff --git a/projects/stargazer/services_impl.cpp b/projects/stargazer/services_impl.cpp index ac856000..bb9fdc1a 100644 --- a/projects/stargazer/services_impl.cpp +++ b/projects/stargazer/services_impl.cpp @@ -54,7 +54,7 @@ if (!priv->serviceChg) return -1; } -iterator si(find(data.begin(), data.end(), service)); +iterator si(std::find(data.begin(), data.end(), service)); if (si != data.end()) { @@ -92,7 +92,7 @@ if (!priv->serviceChg) return -1; } -iterator si(find(data.begin(), data.end(), SERVICE_CONF(name))); +iterator si(std::find(data.begin(), data.end(), SERVICE_CONF(name))); if (si == data.end()) { @@ -136,7 +136,7 @@ if (!priv->serviceChg) return -1; } -iterator si(find(data.begin(), data.end(), service)); +iterator si(std::find(data.begin(), data.end(), service)); if (si == data.end()) { @@ -145,7 +145,9 @@ if (si == data.end()) return -1; } +printfd(__FILE__, "Old cost = %f, old pay day = %d\n", si->cost, (unsigned)si->payDay); *si = service; +printfd(__FILE__, "New cost = %f, New pay day = %d\n", si->cost, (unsigned)si->payDay); if (store->SaveService(service)) { WriteServLog("Cannot write service %s.", service.name.c_str()); @@ -192,7 +194,26 @@ STG_LOCKER lock(&mutex); if (data.empty()) return false; -const_iterator si(find(data.begin(), data.end(), SERVICE_CONF(name))); +const_iterator si(std::find(data.begin(), data.end(), SERVICE_CONF(name))); + +if (si != data.end()) + { + *service = *si; + return false; + } + +return true; +} +//----------------------------------------------------------------------------- +bool SERVICES_IMPL::Find(const std::string & name, SERVICE_CONF_RES * service) const +{ +assert(service != NULL && "Pointer to service is not null"); + +STG_LOCKER lock(&mutex); +if (data.empty()) + return false; + +const_iterator si(std::find(data.begin(), data.end(), SERVICE_CONF(name))); if (si != data.end()) { @@ -208,11 +229,11 @@ bool SERVICES_IMPL::Exists(const std::string & name) const STG_LOCKER lock(&mutex); if (data.empty()) { - printfd(__FILE__, "no admin in system!\n"); + printfd(__FILE__, "No services in the system!\n"); return true; } -const_iterator si(find(data.begin(), data.end(), SERVICE_CONF(name))); +const_iterator si(std::find(data.begin(), data.end(), SERVICE_CONF(name))); if (si != data.end()) return true; diff --git a/projects/stargazer/services_impl.h b/projects/stargazer/services_impl.h index 0415183c..56202c7a 100644 --- a/projects/stargazer/services_impl.h +++ b/projects/stargazer/services_impl.h @@ -45,6 +45,7 @@ public: int Del(const std::string & name, const ADMIN * admin); int Change(const SERVICE_CONF & service, const ADMIN * admin); bool Find(const std::string & name, SERVICE_CONF * service) const; + bool Find(const std::string & name, SERVICE_CONF_RES * service) const; bool Exists(const std::string & name) const; const std::string & GetStrError() const { return strError; } -- 2.44.2 From a89812e5bf8b8628bfc37274326cda6ed2f1a936 Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Fri, 3 Oct 2014 12:16:14 +0300 Subject: [PATCH 14/16] Removed "using namespace std;" from stargazer. --- projects/stargazer/admins_impl.cpp | 22 ++++----- .../store/firebird/firebird_store_admins.cpp | 12 ++--- projects/stargazer/settings_impl.cpp | 46 +++++++++---------- projects/stargazer/tariffs_impl.cpp | 28 ++++++----- 4 files changed, 50 insertions(+), 58 deletions(-) diff --git a/projects/stargazer/admins_impl.cpp b/projects/stargazer/admins_impl.cpp index 08656a49..fb28b6e6 100644 --- a/projects/stargazer/admins_impl.cpp +++ b/projects/stargazer/admins_impl.cpp @@ -36,8 +36,6 @@ #include "admins_impl.h" #include "admin_impl.h" -using namespace std; - //----------------------------------------------------------------------------- ADMINS_IMPL::ADMINS_IMPL(STORE * st) : ADMINS(), @@ -55,14 +53,14 @@ pthread_mutex_init(&mutex, NULL); Read(); } //----------------------------------------------------------------------------- -int ADMINS_IMPL::Add(const string & login, const ADMIN * admin) +int ADMINS_IMPL::Add(const std::string & login, const ADMIN * admin) { STG_LOCKER lock(&mutex); const PRIV * priv = admin->GetPriv(); if (!priv->adminChg) { - string s = admin->GetLogStr() + " Add administrator \'" + login + "\'. Access denied."; + std::string s = admin->GetLogStr() + " Add administrator \'" + login + "\'. Access denied."; strError = "Access denied."; WriteServLog(s.c_str()); return -1; @@ -94,7 +92,7 @@ WriteServLog("%s %s", admin->GetLogStr().c_str(), strError.c_str()); return -1; } //----------------------------------------------------------------------------- -int ADMINS_IMPL::Del(const string & login, const ADMIN * admin) +int ADMINS_IMPL::Del(const std::string & login, const ADMIN * admin) { STG_LOCKER lock(&mutex); ADMIN_IMPL adm(0, login, ""); @@ -102,7 +100,7 @@ const PRIV * priv = admin->GetPriv(); if (!priv->adminChg) { - string s = admin->GetLogStr() + " Delete administrator \'" + login + "\'. Access denied."; + std::string s = admin->GetLogStr() + " Delete administrator \'" + login + "\'. Access denied."; strError = "Access denied."; WriteServLog(s.c_str()); return -1; @@ -117,7 +115,7 @@ if (ai == data.end()) return -1; } -map::iterator si; +std::map::iterator si; si = searchDescriptors.begin(); while (si != searchDescriptors.end()) { @@ -146,7 +144,7 @@ const PRIV * priv = admin->GetPriv(); if (!priv->adminChg) { - string s = admin->GetLogStr() + " Change administrator \'" + ac.login + "\'. Access denied."; + std::string s = admin->GetLogStr() + " Change administrator \'" + ac.login + "\'. Access denied."; strError = "Access denied."; WriteServLog(s.c_str()); return -1; @@ -179,7 +177,7 @@ return 0; int ADMINS_IMPL::Read() { STG_LOCKER lock(&mutex); -vector adminsList; +std::vector adminsList; if (store->GetAdminsList(&adminsList) < 0) { WriteServLog(store->GetStrError().c_str()); @@ -201,7 +199,7 @@ for (unsigned int i = 0; i < adminsList.size(); i++) return 0; } //----------------------------------------------------------------------------- -bool ADMINS_IMPL::Find(const string & l, ADMIN ** admin) +bool ADMINS_IMPL::Find(const std::string & l, ADMIN ** admin) { assert(admin != NULL && "Pointer to admin is not null"); @@ -225,7 +223,7 @@ if (ai != data.end()) return true; } //----------------------------------------------------------------------------- -bool ADMINS_IMPL::Exists(const string & login) const +bool ADMINS_IMPL::Exists(const std::string & login) const { STG_LOCKER lock(&mutex); if (data.empty()) @@ -243,7 +241,7 @@ if (ai != data.end()) return false; } //----------------------------------------------------------------------------- -bool ADMINS_IMPL::Correct(const string & login, const std::string & password, ADMIN ** admin) +bool ADMINS_IMPL::Correct(const std::string & login, const std::string & password, ADMIN ** admin) { STG_LOCKER lock(&mutex); if (data.empty()) diff --git a/projects/stargazer/plugins/store/firebird/firebird_store_admins.cpp b/projects/stargazer/plugins/store/firebird/firebird_store_admins.cpp index fa949281..e794d206 100644 --- a/projects/stargazer/plugins/store/firebird/firebird_store_admins.cpp +++ b/projects/stargazer/plugins/store/firebird/firebird_store_admins.cpp @@ -29,8 +29,6 @@ #include #include -using namespace std; - #include "firebird_store.h" #include "stg/ibpp.h" #include "stg/blowfish.h" @@ -38,14 +36,14 @@ using namespace std; #define adm_enc_passwd "cjeifY8m3" //----------------------------------------------------------------------------- -int FIREBIRD_STORE::GetAdminsList(vector * adminsList) const +int FIREBIRD_STORE::GetAdminsList(std::vector * adminsList) const { STG_LOCKER lock(&mutex); IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amRead, til, tlr); IBPP::Statement st = IBPP::StatementFactory(db, tr); -string login; +std::string login; try { @@ -128,7 +126,7 @@ catch (IBPP::Exception & ex) return 0; } //----------------------------------------------------------------------------- -int FIREBIRD_STORE::RestoreAdmin(ADMIN_CONF * ac, const string & login) const +int FIREBIRD_STORE::RestoreAdmin(ADMIN_CONF * ac, const std::string & login) const { STG_LOCKER lock(&mutex); @@ -191,7 +189,7 @@ ac->password = adminPass; return 0; } //----------------------------------------------------------------------------- -int FIREBIRD_STORE::AddAdmin(const string & login) const +int FIREBIRD_STORE::AddAdmin(const std::string & login) const { STG_LOCKER lock(&mutex); @@ -229,7 +227,7 @@ catch (IBPP::Exception & ex) return 0; } //----------------------------------------------------------------------------- -int FIREBIRD_STORE::DelAdmin(const string & login) const +int FIREBIRD_STORE::DelAdmin(const std::string & login) const { STG_LOCKER lock(&mutex); diff --git a/projects/stargazer/settings_impl.cpp b/projects/stargazer/settings_impl.cpp index 92670cb5..f6a40db3 100644 --- a/projects/stargazer/settings_impl.cpp +++ b/projects/stargazer/settings_impl.cpp @@ -36,8 +36,6 @@ $Author: faust $ #include "stg/dotconfpp.h" #include "settings_impl.h" -using namespace std; - //----------------------------------------------------------------------------- SETTINGS_IMPL::SETTINGS_IMPL() : SETTINGS(), @@ -138,7 +136,7 @@ SETTINGS_IMPL::SETTINGS_IMPL(const SETTINGS_IMPL & rval) { } //----------------------------------------------------------------------------- -int SETTINGS_IMPL::ParseModuleSettings(const DOTCONFDocumentNode * node, vector * params) +int SETTINGS_IMPL::ParseModuleSettings(const DOTCONFDocumentNode * node, std::vector * params) { const DOTCONFDocumentNode * childNode; PARAM_VALUE pv; @@ -148,7 +146,7 @@ pv.param = node->getName(); if (node->getValue(1)) { - strError = "Unexpected value \'" + string(node->getValue(1)) + "\'."; + strError = "Unexpected value \'" + std::string(node->getValue(1)) + "\'."; return -1; } @@ -207,7 +205,7 @@ modulesSettings.clear(); DOTCONFDocument conf(DOTCONFDocument::CASEINSENSITIVE); conf.setErrorCallback(SETTINGS_IMPL::ErrorCallback, this); conf.setRequiredOptionNames(requiredOptions); -string confFile = confDir + "/stargazer.conf"; +std::string confFile = confDir + "/stargazer.conf"; if(conf.setContent(confFile.c_str()) != 0) { @@ -248,7 +246,7 @@ while (node) { if (ParseDetailStatWritePeriod(node->getValue(0)) != 0) { - strError = "Incorrect DetailStatWritePeriod value: \'" + string(node->getValue(0)) + "\'"; + strError = "Incorrect DetailStatWritePeriod value: \'" + std::string(node->getValue(0)) + "\'"; return -1; } } @@ -257,7 +255,7 @@ while (node) { if (ParseUnsignedInRange(node->getValue(0), 1, 1440, &statWritePeriod) != 0) { - strError = "Incorrect StatWritePeriod value: \'" + string(node->getValue(0)) + "\'"; + strError = "Incorrect StatWritePeriod value: \'" + std::string(node->getValue(0)) + "\'"; return -1; } } @@ -266,7 +264,7 @@ while (node) { if (ParseInt(node->getValue(0), &stgExecMsgKey) != 0) { - strError = "Incorrect ExecMsgKey value: \'" + string(node->getValue(0)) + "\'"; + strError = "Incorrect ExecMsgKey value: \'" + std::string(node->getValue(0)) + "\'"; return -1; } } @@ -275,7 +273,7 @@ while (node) { if (ParseUnsignedInRange(node->getValue(0), 1, 1024, &executersNum) != 0) { - strError = "Incorrect ExecutersNum value: \'" + string(node->getValue(0)) + "\'"; + strError = "Incorrect ExecutersNum value: \'" + std::string(node->getValue(0)) + "\'"; return -1; } } @@ -284,7 +282,7 @@ while (node) { if (ParseUnsignedInRange(node->getValue(0), 0, 31, &dayFee) != 0) { - strError = "Incorrect DayFee value: \'" + string(node->getValue(0)) + "\'"; + strError = "Incorrect DayFee value: \'" + std::string(node->getValue(0)) + "\'"; return -1; } } @@ -293,7 +291,7 @@ while (node) { if (ParseYesNo(node->getValue(0), &fullFee) != 0) { - strError = "Incorrect FullFee value: \'" + string(node->getValue(0)) + "\'"; + strError = "Incorrect FullFee value: \'" + std::string(node->getValue(0)) + "\'"; return -1; } } @@ -302,7 +300,7 @@ while (node) { if (ParseUnsignedInRange(node->getValue(0), 0, 31, &dayResetTraff) != 0) { - strError = "Incorrect DayResetTraff value: \'" + string(node->getValue(0)) + "\'"; + strError = "Incorrect DayResetTraff value: \'" + std::string(node->getValue(0)) + "\'"; return -1; } } @@ -311,7 +309,7 @@ while (node) { if (ParseYesNo(node->getValue(0), &spreadFee) != 0) { - strError = "Incorrect SpreadFee value: \'" + string(node->getValue(0)) + "\'"; + strError = "Incorrect SpreadFee value: \'" + std::string(node->getValue(0)) + "\'"; return -1; } } @@ -320,7 +318,7 @@ while (node) { if (ParseYesNo(node->getValue(0), &freeMbAllowInet) != 0) { - strError = "Incorrect FreeMbAllowInet value: \'" + string(node->getValue(0)) + "\'"; + strError = "Incorrect FreeMbAllowInet value: \'" + std::string(node->getValue(0)) + "\'"; return -1; } } @@ -329,7 +327,7 @@ while (node) { if (ParseYesNo(node->getValue(0), &dayFeeIsLastDay) != 0) { - strError = "Incorrect DayFeeIsLastDay value: \'" + string(node->getValue(0)) + "\'"; + strError = "Incorrect DayFeeIsLastDay value: \'" + std::string(node->getValue(0)) + "\'"; return -1; } } @@ -338,7 +336,7 @@ while (node) { if (ParseYesNo(node->getValue(0), &writeFreeMbTraffCost) != 0) { - strError = "Incorrect WriteFreeMbTraffCost value: \'" + string(node->getValue(0)) + "\'"; + strError = "Incorrect WriteFreeMbTraffCost value: \'" + std::string(node->getValue(0)) + "\'"; return -1; } } @@ -347,7 +345,7 @@ while (node) { if (ParseYesNo(node->getValue(0), &showFeeInCash) != 0) { - strError = "Incorrect ShowFeeInCash value: \'" + string(node->getValue(0)) + "\'"; + strError = "Incorrect ShowFeeInCash value: \'" + std::string(node->getValue(0)) + "\'"; return -1; } } @@ -368,7 +366,7 @@ while (node) { if (ParseUnsigned(node->getValue(0), &messageTimeout) != 0) { - strError = "Incorrect MessageTimeout value: \'" + string(node->getValue(0)) + "\'"; + strError = "Incorrect MessageTimeout value: \'" + std::string(node->getValue(0)) + "\'"; return -1; } } @@ -377,7 +375,7 @@ while (node) { if (ParseUnsignedInRange(node->getValue(0), 0, 3, &feeChargeType) != 0) { - strError = "Incorrect FeeChargeType value: \'" + string(node->getValue(0)) + "\'"; + strError = "Incorrect FeeChargeType value: \'" + std::string(node->getValue(0)) + "\'"; return -1; } } @@ -386,7 +384,7 @@ while (node) { if (ParseYesNo(node->getValue(0), &reconnectOnTariffChange) != 0) { - strError = "Incorrect ReconnectOnTariffChange value: \'" + string(node->getValue(0)) + "\'"; + strError = "Incorrect ReconnectOnTariffChange value: \'" + std::string(node->getValue(0)) + "\'"; return -1; } } @@ -415,7 +413,7 @@ while (node) { if (node->getValue(1)) { - strError = "Unexpected \'" + string(node->getValue(1)) + "\'."; + strError = "Unexpected \'" + std::string(node->getValue(1)) + "\'."; return -1; } @@ -434,7 +432,7 @@ while (node) { if (node->getValue(0)) { - strError = "Unexpected \'" + string(node->getValue(0)) + "\'."; + strError = "Unexpected \'" + std::string(node->getValue(0)) + "\'."; return -1; } const DOTCONFDocumentNode * child = node->getChildNode(); @@ -470,7 +468,7 @@ while (node) return 0; } //----------------------------------------------------------------------------- -int SETTINGS_IMPL::ParseDetailStatWritePeriod(const string & detailStatPeriodStr) +int SETTINGS_IMPL::ParseDetailStatWritePeriod(const std::string & detailStatPeriodStr) { if (detailStatPeriodStr == "1") { @@ -495,4 +493,4 @@ else if (detailStatPeriodStr == "1/6") return -1; } -//----------------------------------------------------------------------------- \ No newline at end of file +//----------------------------------------------------------------------------- diff --git a/projects/stargazer/tariffs_impl.cpp b/projects/stargazer/tariffs_impl.cpp index 1a8ea359..d47ecf8f 100644 --- a/projects/stargazer/tariffs_impl.cpp +++ b/projects/stargazer/tariffs_impl.cpp @@ -38,8 +38,6 @@ #include "stg/admin.h" #include "tariffs_impl.h" -using namespace std; - //----------------------------------------------------------------------------- TARIFFS_IMPL::TARIFFS_IMPL(STORE * st) : TARIFFS(), @@ -65,7 +63,7 @@ int TARIFFS_IMPL::ReadTariffs() { STG_LOCKER lock(&mutex); -vector tariffsList; +std::vector tariffsList; if (store->GetTariffsList(&tariffsList)) { WriteServLog("Cannot get tariffs list."); @@ -95,13 +93,13 @@ STG_LOCKER lock(&mutex); return tariffs.size(); } //----------------------------------------------------------------------------- -const TARIFF * TARIFFS_IMPL::FindByName(const string & name) const +const TARIFF * TARIFFS_IMPL::FindByName(const std::string & name) const { if (name == NO_TARIFF_NAME) return &noTariff; STG_LOCKER lock(&mutex); -list::const_iterator ti; +std::list::const_iterator ti; ti = find(tariffs.begin(), tariffs.end(), TARIFF_IMPL(name)); if (ti != tariffs.end()) @@ -116,7 +114,7 @@ const PRIV * priv = admin->GetPriv(); if (!priv->tariffChg) { - string s = admin->GetLogStr() + " Change tariff \'" + std::string s = admin->GetLogStr() + " Change tariff \'" + td.tariffConf.name + "\'. Access denied."; strError = "Access denied."; WriteServLog(s.c_str()); @@ -125,7 +123,7 @@ if (!priv->tariffChg) STG_LOCKER lock(&mutex); -list::iterator ti; +std::list::iterator ti; ti = find(tariffs.begin(), tariffs.end(), TARIFF_IMPL(td.tariffConf.name)); if (ti == tariffs.end()) @@ -139,7 +137,7 @@ if (ti == tariffs.end()) if (store->SaveTariff(td, td.tariffConf.name)) { - string error = "Tariff " + td.tariffConf.name + " writing error. " + store->GetStrError(); + std::string error = "Tariff " + td.tariffConf.name + " writing error. " + store->GetStrError(); WriteServLog(error.c_str()); return -1; } @@ -150,13 +148,13 @@ WriteServLog("%s Tariff \'%s\' changed.", return 0; } //----------------------------------------------------------------------------- -int TARIFFS_IMPL::Del(const string & name, const ADMIN * admin) +int TARIFFS_IMPL::Del(const std::string & name, const ADMIN * admin) { const PRIV * priv = admin->GetPriv(); if (!priv->tariffChg) { - string s = admin->GetLogStr() + " Delete tariff \'" + std::string s = admin->GetLogStr() + " Delete tariff \'" + name + "\'. Access denied."; strError = "Access denied."; WriteServLog(s.c_str()); @@ -168,7 +166,7 @@ TARIFF_DATA td; { STG_LOCKER lock(&mutex); - list::iterator ti; + std::list::iterator ti; ti = find(tariffs.begin(), tariffs.end(), TARIFF_IMPL(name)); if (ti == tariffs.end()) @@ -184,7 +182,7 @@ TARIFF_DATA td; WriteServLog("%s", store->GetStrError().c_str()); return -1; } - + td = ti->GetTariffData(); tariffs.erase(ti); @@ -203,13 +201,13 @@ WriteServLog("%s Tariff \'%s\' deleted.", return 0; } //----------------------------------------------------------------------------- -int TARIFFS_IMPL::Add(const string & name, const ADMIN * admin) +int TARIFFS_IMPL::Add(const std::string & name, const ADMIN * admin) { const PRIV * priv = admin->GetPriv(); if (!priv->tariffChg) { - string s = admin->GetLogStr() + " Add tariff \'" + std::string s = admin->GetLogStr() + " Add tariff \'" + name + "\'. Access denied."; strError = "Access denied."; WriteServLog(s.c_str()); @@ -219,7 +217,7 @@ if (!priv->tariffChg) { STG_LOCKER lock(&mutex); - list::iterator ti; + std::list::iterator ti; ti = find(tariffs.begin(), tariffs.end(), TARIFF_IMPL(name)); if (ti != tariffs.end()) -- 2.44.2 From 79ce57fb1209a4ad02f96aadb0c47e8162b9f007 Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Fri, 3 Oct 2014 12:19:08 +0300 Subject: [PATCH 15/16] Removed "using namespace std;" from parser.cpp. --- projects/sgconf/parser.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/projects/sgconf/parser.cpp b/projects/sgconf/parser.cpp index 9d340e83..16362536 100644 --- a/projects/sgconf/parser.cpp +++ b/projects/sgconf/parser.cpp @@ -37,8 +37,6 @@ #include "stg/netunit.h" #include "stg/request.h" -using namespace std; - int parse_depth = 0; XML_Parser parser; //--------------------------------------------------------------------------- -- 2.44.2 From 6e222d63cfc8894130d9b0cf80bb74294f9f2e75 Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Fri, 3 Oct 2014 12:19:55 +0300 Subject: [PATCH 16/16] Removed parser.cpp. --- projects/sgconf/parser.cpp | 124 ------------------------------------- 1 file changed, 124 deletions(-) delete mode 100644 projects/sgconf/parser.cpp diff --git a/projects/sgconf/parser.cpp b/projects/sgconf/parser.cpp deleted file mode 100644 index 16362536..00000000 --- a/projects/sgconf/parser.cpp +++ /dev/null @@ -1,124 +0,0 @@ -/* - * 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 - */ - - /* - $Author: nobunaga $ - $Revision: 1.4 $ - $Date: 2008/05/11 08:15:07 $ - */ - - -#include -#include -#include -#include - -#include -#include - -#include "stg/common.h" -#include "stg/netunit.h" -#include "stg/request.h" - -int parse_depth = 0; -XML_Parser parser; -//--------------------------------------------------------------------------- -int ParseAns(void * data, const char *el, const char **attr) -{ -if (strcasecmp(attr[1], "ok") == 0) - { - return 0; - } -if (strcasecmp(attr[1], "error") == 0) - { - return 1; - } -if (strcasecmp(attr[1], "err") == 0) - { - return 1; - } -return -1; -} -//--------------------------------------------------------------------------- -void StartElement(void *data, const char *el, const char **attr) -{ -parse_depth++; -if (parse_depth == 1) - { - if (ParseAns(data, el, attr) < 0) - { - printf("Unexpected token\n"); - exit(UNKNOWN_ERR_CODE); - } - if (ParseAns(data, el, attr) == 1) - { - printf("User not found\n"); - exit(USER_NOT_FOUND_ERR_CODE); - } - return; - } -} -//----------------------------------------------------------------------------- -void EndElement(void *data, const char *el) -{ -parse_depth--; -} -//--------------------------------------------------------------------------- -int ParseReply(void * data, list * ans) -{ -int done = 0; - -parse_depth = 0; -parser = XML_ParserCreate(NULL); - -if (!parser) - { - printf("Couldn't allocate memory for parser\n"); - exit(UNKNOWN_ERR_CODE); - } - -XML_ParserReset(parser, NULL); -XML_SetElementHandler(parser, StartElement, EndElement); - -list::iterator n = ans->begin(); -while (n != ans->end()) - { - size_t len = strlen(n->c_str()); - - if (++n == ans->end()) - done = 1; - --n; - - if (XML_Parse(parser, n->c_str(), len, done) == XML_STATUS_ERROR) - { - printf("Parse error at line %d:\n%s\n", - XML_GetCurrentLineNumber(parser), - XML_ErrorString(XML_GetErrorCode(parser))); - exit(UNKNOWN_ERR_CODE); - } - - ++n; - } - -XML_ParserFree(parser); -return 0; -} -//----------------------------------------------------------------------------- - -- 2.44.2