]> git.stg.codes - stg.git/blobdiff - stglibs/srvconf.lib/netunit.cpp
[NY Flight] One time protocol initialization.
[stg.git] / stglibs / srvconf.lib / netunit.cpp
index 9a653d5bf5e76621be46b3b6367a1463dccdf771..db22a3a0ee27fb0bd136759fcae241d393144994 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>
 
 //---------------------------------------------------------------------------
 
 #define RECV_HEADER_ANSWER_ERROR    "Recv header answer error!"
 
 //---------------------------------------------------------------------------
-NETTRANSACT::NETTRANSACT()
-    : port(0),
+NETTRANSACT::NETTRANSACT(const std::string & s, uint16_t p,
+                         const std::string & l, const std::string & pwd)
+    : server(s),
+      port(p),
+      login(l),
+      password(pwd),
       outerSocket(-1),
       RxCallBack(NULL),
       dataRxCallBack(NULL)
@@ -212,6 +218,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 +268,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 +326,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 +434,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;
@@ -436,17 +446,18 @@ while (1)
         Decrypt(buffer, bufferS, &ctx);
         buffer[ENC_MSG_LEN] = 0;
 
+        printf("%s", buffer);
+
         answerList.push_back(buffer);
 
         for (int j = 0; j < ENC_MSG_LEN; j++)
             {
             if (buffer[j] == 0)
                 {
+                printf("\n");
                 if (RxCallBack)
                     if (st_ok != RxCallBack(dataRxCallBack, &answerList))
-                        {
                         return st_xml_parse_error;
-                        }
                 return st_ok;
                 }
             }
@@ -454,26 +465,6 @@ while (1)
     }
 }
 //---------------------------------------------------------------------------
-void NETTRANSACT::SetLogin(const char * l)
-{
-login = l;
-}
-//---------------------------------------------------------------------------
-void NETTRANSACT::SetPassword(const char * p)
-{
-password = p;
-}
-//---------------------------------------------------------------------------
-void NETTRANSACT::SetServer(const char * serverName)
-{
-server = serverName;
-}
-//---------------------------------------------------------------------------
-void NETTRANSACT::SetServerPort(short unsigned p)
-{
-port = p;
-}
-//---------------------------------------------------------------------------
 void NETTRANSACT::SetRxCallback(void * data, RxCallback_t cb)
 {
 RxCallBack = cb;