From 198f8204d13f3f0661233d910f474775a68a7337 Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Sat, 10 Aug 2013 10:51:39 +0300 Subject: [PATCH] Different small fixes plus error logging. --- .../plugins/configuration/sgconfig/parser.cpp | 2 +- stglibs/common.lib/include/stg/common.h | 4 ++-- stglibs/srvconf.lib/netunit.cpp | 18 +++++++++++------- stglibs/srvconf.lib/parser_get_user.cpp | 14 +++++++------- stglibs/srvconf.lib/servconf.cpp | 19 ++++++------------- 5 files changed, 27 insertions(+), 30 deletions(-) diff --git a/projects/stargazer/plugins/configuration/sgconfig/parser.cpp b/projects/stargazer/plugins/configuration/sgconfig/parser.cpp index b6c49172..431d17f3 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/parser.cpp +++ b/projects/stargazer/plugins/configuration/sgconfig/parser.cpp @@ -289,7 +289,7 @@ answerList->push_back(s); s = ""; std::vector list(u->GetAuthorizers()); for (std::vector::const_iterator it = list.begin(); it != list.end(); ++it) - s += ""; + s += ""; s += ""; answerList->push_back(s); diff --git a/stglibs/common.lib/include/stg/common.h b/stglibs/common.lib/include/stg/common.h index 6df89f73..3b1ea275 100644 --- a/stglibs/common.lib/include/stg/common.h +++ b/stglibs/common.lib/include/stg/common.h @@ -115,11 +115,11 @@ int str2x(const std::string & str, varT & x); template const std::string & x2str(varT x, std::string & s); template -const std::string & x2str(varT x) { std::string s; return x2str(x, s); } +std::string x2str(varT x) { std::string s; return x2str(x, s); } template const std::string & unsigned2str(varT x, std::string & s); template -const std::string & unsigned2str(varT x) { std::string s; return unsigned2str(x, s); } +std::string unsigned2str(varT x) { std::string s; return unsigned2str(x, s); } //----------------------------------------------------------------------------- template diff --git a/stglibs/srvconf.lib/netunit.cpp b/stglibs/srvconf.lib/netunit.cpp index 9a653d5b..eab32e6a 100644 --- a/stglibs/srvconf.lib/netunit.cpp +++ b/stglibs/srvconf.lib/netunit.cpp @@ -25,15 +25,17 @@ */ //--------------------------------------------------------------------------- -#include -#include -#include + +#include "stg/netunit.h" +#include "stg/common.h" #include +#include #include -#include "stg/netunit.h" -#include "stg/common.h" +#include +#include +#include //--------------------------------------------------------------------------- @@ -212,6 +214,7 @@ int ret; ret = recv(outerSocket, buffer, strlen(OK_HEADER), 0); if (ret <= 0) { + printf("Receive header answer error: '%s'\n", strerror(errno)); errorMsg = RECV_HEADER_ANSWER_ERROR; return st_recv_fail; } @@ -261,6 +264,7 @@ int ret; ret = recv(outerSocket, buffer, strlen(OK_LOGIN), 0); if (ret <= 0) { + printf("Receive login answer error: '%s'\n", strerror(errno)); errorMsg = RECV_LOGIN_ANSWER_ERROR; return st_recv_fail; } @@ -318,6 +322,7 @@ int ret; ret = recv(outerSocket, buffer, strlen(OK_LOGINS), 0); if (ret <= 0) { + printf("Receive secret login answer error: '%s'\n", strerror(errno)); errorMsg = RECV_LOGIN_ANSWER_ERROR; return st_recv_fail; } @@ -425,6 +430,7 @@ while (1) ret = recv(outerSocket, &bufferS[n++], 1, 0); if (ret <= 0) { + printf("Receive data error: '%s'\n", strerror(errno)); close(outerSocket); errorMsg = RECV_DATA_ANSWER_ERROR; return st_recv_fail; @@ -444,9 +450,7 @@ while (1) { if (RxCallBack) if (st_ok != RxCallBack(dataRxCallBack, &answerList)) - { return st_xml_parse_error; - } return st_ok; } } diff --git a/stglibs/srvconf.lib/parser_get_user.cpp b/stglibs/srvconf.lib/parser_get_user.cpp index 9ba86c14..93017038 100644 --- a/stglibs/srvconf.lib/parser_get_user.cpp +++ b/stglibs/srvconf.lib/parser_get_user.cpp @@ -70,21 +70,21 @@ PARSER_GET_USER::STAT getValue(const char ** attr) PARSER_GET_USER::STAT value; if (!attr) return value; -std::map props; +std::map props; for (size_t i = 0; i < DIR_NUM; ++i) { - props.insert(std::pair("su" + x2str(i), value.su[i])); - props.insert(std::pair("sd" + x2str(i), value.sd[i])); - props.insert(std::pair("mu" + x2str(i), value.mu[i])); - props.insert(std::pair("md" + x2str(i), value.md[i])); + props.insert(std::pair("su" + x2str(i), &value.su[i])); + props.insert(std::pair("sd" + x2str(i), &value.sd[i])); + props.insert(std::pair("mu" + x2str(i), &value.mu[i])); + props.insert(std::pair("md" + x2str(i), &value.md[i])); } size_t pos = 0; while (attr[pos]) { std::string name(ToLower(attr[pos++])); - std::map::iterator it(props.find(name)); + std::map::iterator it(props.find(name)); if (it != props.end()) - str2x(attr[pos++], it->second); + str2x(attr[pos++], *it->second); } return value; } diff --git a/stglibs/srvconf.lib/servconf.cpp b/stglibs/srvconf.lib/servconf.cpp index 3d82860b..7848787b 100644 --- a/stglibs/srvconf.lib/servconf.cpp +++ b/stglibs/srvconf.lib/servconf.cpp @@ -35,31 +35,23 @@ using namespace std; //----------------------------------------------------------------------------- int AnsRecv(void * data, list * list1) { -//NODE * node; -SERVCONF * sc; -char ans[ENC_MSG_LEN + 1]; -int len, done = 0; - -sc = (SERVCONF*)data; +SERVCONF * sc = static_cast(data); XML_ParserReset(sc->parser, NULL); XML_SetElementHandler(sc->parser, Start, End); XML_SetUserData(sc->parser, data); +char ans[ENC_MSG_LEN + 1]; +int len, done = 0; + //loop parsing list::iterator node; node = list1->begin(); -if (node == list1->end()) - { - return st_ok; - } - while (node != list1->end()) { strncpy(ans, node->c_str(), ENC_MSG_LEN); ans[ENC_MSG_LEN] = 0; - //printf("---> %s\n", ans); len = strlen(ans); if (XML_Parse(sc->parser, ans, len, done) == XML_STATUS_ERROR) @@ -67,13 +59,14 @@ while (node != list1->end()) strprintf(&sc->errorMsg, "XML parse error at line %d: %s", static_cast(XML_GetCurrentLineNumber(sc->parser)), XML_ErrorString(XML_GetErrorCode(sc->parser))); + printf("%s\n", sc->errorMsg.c_str()); return st_xml_parse_error; } ++node; } -return 0; +return st_ok; } //----------------------------------------------------------------------------- void Start(void *data, const char *el, const char **attr) -- 2.43.2