From d29d84149a36d3fb5c4baa045d0398e87f79eba8 Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Mon, 5 Aug 2013 20:41:55 +0300 Subject: [PATCH] Some refactoring. --- .../configuration/sgconfig/configproto.cpp | 50 ++----------------- .../configuration/sgconfig/configproto.h | 18 ++++--- .../configuration/sgconfig/parser_user_info.h | 4 +- .../plugins/configuration/sgconfig/rsconf.cpp | 28 ++++------- 4 files changed, 27 insertions(+), 73 deletions(-) diff --git a/projects/stargazer/plugins/configuration/sgconfig/configproto.cpp b/projects/stargazer/plugins/configuration/sgconfig/configproto.cpp index 015c2460..ec3e3ee3 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/configproto.cpp +++ b/projects/stargazer/plugins/configuration/sgconfig/configproto.cpp @@ -28,11 +28,10 @@ $Author: faust $ */ +#include "configproto.h" #include -#include "configproto.h" - //----------------------------------------------------------------------------- void ParseXMLStart(void *data, const char *el, const char **attr) { @@ -87,40 +86,15 @@ else } //----------------------------------------------------------------------------- CONFIGPROTO::CONFIGPROTO(PLUGIN_LOGGER & l) - : answerList(), - requestList(), - adminIP(0), - adminLogin(), - adminPassword(), + : adminIP(0), port(0), - thrReciveSendConf(), nonstop(true), state(0), currAdmin(NULL), logger(l), listenSocket(-1), - parserGetServInfo(), - parserGetUsers(), - parserGetUser(), - parserChgUser(), - parserAddUser(), - parserDelUser(), - parserCheckUser(), - parserSendMessage(), - parserAuthBy(), - parserGetAdmins(), - parserAddAdmin(), - parserDelAdmin(), - parserChgAdmin(), - parserGetTariffs(), - parserAddTariff(), - parserDelTariff(), - parserChgTariff(), admins(NULL), - currParser(NULL), - dataParser(), - xmlParser(), - errorStr() + currParser(NULL) { dataParser.push_back(&parserGetServInfo); @@ -132,6 +106,7 @@ dataParser.push_back(&parserDelUser); dataParser.push_back(&parserCheckUser); dataParser.push_back(&parserSendMessage); dataParser.push_back(&parserAuthBy); +dataParser.push_back(&parserUserInfo); dataParser.push_back(&parserGetTariffs); dataParser.push_back(&parserAddTariff); @@ -212,51 +187,34 @@ while(nonstop) return 0; } //----------------------------------------------------------------------------- -void CONFIGPROTO::SetPort(uint16_t p) -{ -port = p; -} -//----------------------------------------------------------------------------- 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 ccb8a4d7..4adba097 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/configproto.h +++ b/projects/stargazer/plugins/configuration/sgconfig/configproto.h @@ -28,12 +28,8 @@ #ifndef CONFIGPROTO_H #define CONFIGPROTO_H -#include -#include -#include - -#include -#include +#include "parser_auth_by.h" +#include "parser_user_info.h" #include "stg/users.h" #include "stg/admins.h" @@ -41,7 +37,12 @@ #include "stg/logger.h" #include "parser.h" -#include "parser_auth_by.h" +#include +#include + +#include +#include +#include #define STG_HEADER "SG04" #define OK_HEADER "OKHD" @@ -57,7 +58,7 @@ public: CONFIGPROTO(PLUGIN_LOGGER & l); ~CONFIGPROTO(); - void SetPort(uint16_t port); + void SetPort(uint16_t p) { port = p; } void SetAdmins(ADMINS * a); void SetUsers(USERS * u); void SetTariffs(TARIFFS * t); @@ -110,6 +111,7 @@ private: PARSER_CHECK_USER parserCheckUser; PARSER_SEND_MESSAGE parserSendMessage; PARSER_AUTH_BY parserAuthBy; + PARSER_USER_INFO parserUserInfo; PARSER_GET_ADMINS parserGetAdmins; PARSER_ADD_ADMIN parserAddAdmin; diff --git a/projects/stargazer/plugins/configuration/sgconfig/parser_user_info.h b/projects/stargazer/plugins/configuration/sgconfig/parser_user_info.h index 91b022f1..ccd1d94e 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/parser_user_info.h +++ b/projects/stargazer/plugins/configuration/sgconfig/parser_user_info.h @@ -21,10 +21,10 @@ #ifndef __STG_PARSER_USER_INFO_H__ #define __STG_PARSER_USER_INFO_H__ -#include - #include "parser.h" +#include + class PARSER_USER_INFO : public BASE_PARSER { public: int ParseStart(void *data, const char *el, const char **attr); diff --git a/projects/stargazer/plugins/configuration/sgconfig/rsconf.cpp b/projects/stargazer/plugins/configuration/sgconfig/rsconf.cpp index 9b448f6c..6ca2b3da 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/rsconf.cpp +++ b/projects/stargazer/plugins/configuration/sgconfig/rsconf.cpp @@ -26,14 +26,15 @@ * *******************************************************************/ -#include // close +#include "configproto.h" + +#include "stg/blowfish.h" #include #include #include // snprintf -#include "stg/blowfish.h" -#include "configproto.h" +#include // close #ifndef ENODATA // FreeBSD 4.* - suxx @@ -147,13 +148,11 @@ while (nonstop) &outerAddrLen); if (!nonstop) - { break; - } if (outerSocket < 0) { - logger("accept error: %s", strerror(errno)); + logger("accept error: %s", strerror(errno)); printfd(__FILE__, "accept failed\n"); continue; } @@ -256,8 +255,8 @@ while (pos < stgHdrLen) ssize_t ret = recv(sock, &buf[pos], static_cast(stgHdrLen) - static_cast(pos), 0); if (ret <= 0) { - if (ret < 0) - logger("recv error: %s", strerror(errno)); + if (ret < 0) + logger("recv error: %s", strerror(errno)); state = confHdr; return -1; } @@ -319,7 +318,7 @@ while (pos < ADM_LOGIN_LEN) { if (ret <= 0) { // Error in network - logger("recv error: %s", strerror(errno)); + logger("recv error: %s", strerror(errno)); state = confHdr; return ENODATA; } @@ -370,7 +369,7 @@ while (pos < ADM_LOGIN_LEN) { // Network error printfd(__FILE__, "recv error: '%s'\n", strerror(errno)); - logger("recv error: %s", strerror(errno)); + logger("recv error: %s", strerror(errno)); state = confHdr; return ENODATA; } @@ -389,9 +388,7 @@ EnDecodeInit(currAdmin->GetPassword().c_str(), ADM_PASSWD_LEN, &ctx); char login[ADM_LOGIN_LEN + 1]; for (size_t i = 0; i < ADM_LOGIN_LEN / 8; i++) - { DecodeString(login + i * 8, loginS + i * 8, &ctx); - } if (currAdmin == admins->GetNoAdmin()) { @@ -456,7 +453,7 @@ while (1) if (ret < 0) { // Network error - logger("recv error: %s", strerror(errno)); + logger("recv error: %s", strerror(errno)); printfd(__FILE__, "recv error: '%s'\n", strerror(errno)); return -1; } @@ -514,11 +511,8 @@ while (li != answerList.end()) if (n % 8 == 0) { EncodeString(buffS, buff, &ctx); - int ret = static_cast(send(sock, buffS, 8, 0)); - if (ret < 0) - { + if (send(sock, buffS, 8, 0) < 0) return -1; - } } } k = 0;// new node -- 2.44.2