]> git.stg.codes - stg.git/commitdiff
Different small fixes plus error logging.
authorMaxim Mamontov <faust.madf@gmail.com>
Sat, 10 Aug 2013 07:51:39 +0000 (10:51 +0300)
committerMaxim Mamontov <faust.madf@gmail.com>
Sat, 10 Aug 2013 07:51:39 +0000 (10:51 +0300)
projects/stargazer/plugins/configuration/sgconfig/parser.cpp
stglibs/common.lib/include/stg/common.h
stglibs/srvconf.lib/netunit.cpp
stglibs/srvconf.lib/parser_get_user.cpp
stglibs/srvconf.lib/servconf.cpp

index b6c491721f78c53a3c01d5edad0b163cc5ef57f3..431d17f31b6c20aaf33757c480748eee4c5024b7 100644 (file)
@@ -289,7 +289,7 @@ answerList->push_back(s);
 s = "<AuthorizedBy>";
 std::vector<std::string> list(u->GetAuthorizers());
 for (std::vector<std::string>::const_iterator it = list.begin(); it != list.end(); ++it)
-    s += "<Auth name=\"" + *it + "\">";
+    s += "<Auth name=\"" + *it + "\"/>";
 s += "</AuthorizedBy>";
 answerList->push_back(s);
 
index 6df89f73a7da67ad0e2347db213f007246e844aa..3b1ea27541020c684d0e79ee88374d1dae704126 100644 (file)
@@ -115,11 +115,11 @@ int str2x(const std::string & str, varT & x);
 template <typename varT>
 const std::string & x2str(varT x, std::string & s);
 template <typename varT>
-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 <typename varT>
 const std::string & unsigned2str(varT x, std::string & s);
 template <typename varT>
-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 <typename varT>
index 9a653d5bf5e76621be46b3b6367a1463dccdf771..eab32e6a12ecda4069d1fb32870c829c0a17ec12 100644 (file)
  */
 
 //---------------------------------------------------------------------------
-#include <netdb.h>
-#include <arpa/inet.h>
-#include <unistd.h>
+
+#include "stg/netunit.h"
+#include "stg/common.h"
 
 #include <cstdio>
+#include <cerrno>
 #include <cstring>
 
-#include "stg/netunit.h"
-#include "stg/common.h"
+#include <netdb.h>
+#include <arpa/inet.h>
+#include <unistd.h>
 
 //---------------------------------------------------------------------------
 
@@ -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;
                 }
             }
index 9ba86c141a9afebea0b0dd1e94120b48ecd138f6..930170380cd3a6ebf53c6641f6b750d07f5cda62 100644 (file)
@@ -70,21 +70,21 @@ PARSER_GET_USER::STAT getValue<PARSER_GET_USER::STAT>(const char ** attr)
 PARSER_GET_USER::STAT value;
 if (!attr)
     return value;
-std::map<std::string, long long &> props;
+std::map<std::string, long long *> props;
 for (size_t i = 0; i < DIR_NUM; ++i)
     {
-    props.insert(std::pair<std::string, long long &>("su" + x2str(i), value.su[i]));
-    props.insert(std::pair<std::string, long long &>("sd" + x2str(i), value.sd[i]));
-    props.insert(std::pair<std::string, long long &>("mu" + x2str(i), value.mu[i]));
-    props.insert(std::pair<std::string, long long &>("md" + x2str(i), value.md[i]));
+    props.insert(std::pair<std::string, long long *>("su" + x2str(i), &value.su[i]));
+    props.insert(std::pair<std::string, long long *>("sd" + x2str(i), &value.sd[i]));
+    props.insert(std::pair<std::string, long long *>("mu" + x2str(i), &value.mu[i]));
+    props.insert(std::pair<std::string, long long *>("md" + x2str(i), &value.md[i]));
     }
 size_t pos = 0;
 while (attr[pos])
     {
         std::string name(ToLower(attr[pos++]));
-        std::map<std::string, long long &>::iterator it(props.find(name));
+        std::map<std::string, long long *>::iterator it(props.find(name));
         if (it != props.end())
-            str2x(attr[pos++], it->second);
+            str2x(attr[pos++], *it->second);
     }
 return value;
 }
index 3d82860b2895556dd2c52e842035f8fa20c26d5c..7848787b61d5769cac85ff67f18c20a1107beeda 100644 (file)
@@ -35,31 +35,23 @@ using namespace std;
 //-----------------------------------------------------------------------------
 int AnsRecv(void * data, list<string> * list1)
 {
-//NODE * node;
-SERVCONF * sc;
-char ans[ENC_MSG_LEN + 1];
-int len, done = 0;
-
-sc = (SERVCONF*)data;
+SERVCONF * sc = static_cast<SERVCONF *>(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<string>::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<int>(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)