]> git.stg.codes - stg.git/blobdiff - stglibs/srvconf.lib/netunit.cpp
[NY] Implemented SERVCONF using PIMPL.
[stg.git] / stglibs / srvconf.lib / netunit.cpp
index 670c452242a00d565b57c5a3636a7ec813224c81..68d64678e5b7d33528475cda68dd3afc89ef72ad 100644 (file)
@@ -27,6 +27,7 @@
 //---------------------------------------------------------------------------
 
 #include "stg/netunit.h"
+#include "stg/servconf_types.h"
 #include "stg/common.h"
 #include "stg/blowfish.h"
 
 #include <arpa/inet.h>
 #include <unistd.h>
 
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+
+namespace
+{
+
+const std::string::size_type MAX_XML_CHUNK_LENGTH = 2048;
+
+}
+
 //---------------------------------------------------------------------------
 
 #define SEND_DATA_ERROR             "Send data error!"
@@ -400,6 +412,7 @@ int NETTRANSACT::RxDataAnswer()
 BLOWFISH_CTX ctx;
 EnDecodeInit(password.c_str(), PASSWD_LEN, &ctx);
 
+std::string chunk;
 while (true)
     {
     char bufferS[ENC_MSG_LEN];
@@ -417,22 +430,28 @@ while (true)
         toRead -= ret;
         }
 
-    char buffer[ENC_MSG_LEN + 1];
+    char buffer[ENC_MSG_LEN];
     DecodeString(buffer, bufferS, &ctx);
-    buffer[ENC_MSG_LEN] = 0;
 
-    answerList.push_back(buffer);
+    bool final = false;
+    size_t pos = 0;
+    for (; pos < ENC_MSG_LEN && buffer[pos] != 0; pos++);
+    if (pos < ENC_MSG_LEN && buffer[pos] == 0)
+        final = true;
+
+    if (pos > 0)
+        chunk.append(&buffer[0], &buffer[pos]);
 
-    for (size_t i = 0; i < ENC_MSG_LEN; i++)
+    if (chunk.length() > MAX_XML_CHUNK_LENGTH || final)
         {
-        if (buffer[i] == 0)
-            {
-            if (RxCallBack)
-                if (st_ok != RxCallBack(dataRxCallBack, &answerList))
-                    return st_xml_parse_error;
-            return st_ok;
-            }
+        if (RxCallBack != NULL)
+            if (!RxCallBack(dataRxCallBack, chunk, final))
+                return st_xml_parse_error;
+        chunk.clear();
         }
+
+    if (final)
+        return st_ok;
     }
 }
 //---------------------------------------------------------------------------
@@ -447,8 +466,3 @@ const std::string & NETTRANSACT::GetError() const
 return errorMsg;
 }
 //---------------------------------------------------------------------------
-void NETTRANSACT::Reset()
-{
-answerList.clear();
-}
-//---------------------------------------------------------------------------