]> git.stg.codes - stg.git/blobdiff - stglibs/srvconf.lib/parser.cpp
Fixed tests.
[stg.git] / stglibs / srvconf.lib / parser.cpp
index 7c96b2ed442c4422c502049f8b75dc5e864dc476..284e1127e5f83da67bb6f04de36f92bd6a6f34f3 100644 (file)
 #include <arpa/inet.h>
 #include <string>
 
-#include "common.h"
-//#include "srvconf_common.h"
-#include "stg_const.h"
-#include "servconf.h"
+#include "stg/common.h"
+#include "stg/const.h"
+#include "stg/servconf.h"
 
 using namespace std;
 
-//-----------------------------------------------------------------------------
-PARSER::PARSER()
-{
-}
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 PARSER_GET_USERS::PARSER_GET_USERS()
+    : RecvUserDataCb(NULL),
+      userDataCb(NULL),
+      user(),
+      depth(0),
+      error(false)
 {
-depth = 0;
-error = false;
-RecvUserDataCb = NULL;
-}
-//-----------------------------------------------------------------------------
-void PARSER_GET_USERS::Reset()
-{
-
 }
 //-----------------------------------------------------------------------------
 int PARSER_GET_USERS::ParseStart(const char *el, const char **attr)
@@ -173,6 +165,14 @@ if (strcasecmp(el, "credit") == 0)
         }
     }
 
+if (strcasecmp(el, "creditExpire") == 0)
+    {
+    if (str2x(attr[1], user.creditExpire) < 0)
+        {
+        return;
+        }
+    }
+
 /*if (strcasecmp(el, "freemb") == 0)
     {
     if (strtodouble2(attr[1], user.freeMb) < 0)
@@ -385,15 +385,12 @@ userDataCb = data;
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 PARSER_GET_USER::PARSER_GET_USER()
+    : RecvUserDataCb(NULL),
+      userDataCb(NULL),
+      user(),
+      depth(0),
+      error(false)
 {
-depth = 0;
-error = false;
-RecvUserDataCb = NULL;
-}
-//-----------------------------------------------------------------------------
-void PARSER_GET_USER::Reset()
-{
-
 }
 //-----------------------------------------------------------------------------
 int PARSER_GET_USER::ParseStart(const char *el, const char **attr)
@@ -530,6 +527,14 @@ if (strcasecmp(el, "currip") == 0)
     user.ip = inet_addr(attr[1]);
     }
 
+if (strcasecmp(el, "creditExpire") == 0)
+    {
+    if (str2x(attr[1], user.creditExpire) < 0)
+        {
+        return;
+        }
+    }
+
 for (int i = 0; i < USERDATA_NUM; i++)
     {
     string num;
@@ -658,15 +663,12 @@ userDataCb = data;
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 PARSER_GET_SERVER_INFO::PARSER_GET_SERVER_INFO()
+    : RecvServerInfoDataCb(NULL),
+      serverInfoDataCb(NULL),
+      depth(0),
+      error(false),
+      serverInfo()
 {
-depth = 0;
-error = false;
-RecvServerInfoDataCb = NULL;
-}
-//-----------------------------------------------------------------------------
-void PARSER_GET_SERVER_INFO::Reset()
-{
-
 }
 //-----------------------------------------------------------------------------
 int PARSER_GET_SERVER_INFO::ParseStart(const char *el, const char **attr)
@@ -820,11 +822,64 @@ if (strcmp(attr[0], "value") == 0)
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
+PARSER_AUTH_BY::PARSER_AUTH_BY()
+    : RecvAuthByDataCb(NULL),
+      authByDataCb(NULL),
+      depth(0),
+      error(false),
+      list()
+{
+}
+//-----------------------------------------------------------------------------
+int PARSER_AUTH_BY::ParseStart(const char *el, const char **attr)
+{
+depth++;
+if (depth == 1)
+    {
+    if (strcasecmp(el, "AuthorizedBy") != 0)
+        {
+        list.erase(list.begin(), list.end());
+        //printf("%s\n", el);
+        }
+    }
+else
+    {
+    if (depth == 2)
+        {
+        if (strcasecmp(el, "Auth") == 0)
+            {
+            if (attr && attr[0] && attr[1])
+                list.push_back(attr[1]);
+            return 0;
+            }
+        }
+    }
+return 0;
+}
+//-----------------------------------------------------------------------------
+void PARSER_AUTH_BY::ParseEnd(const char *)
+{
+depth--;
+if (depth == 0)
+    {
+    RecvAuthByDataCb(list, authByDataCb);
+    }
+}
+//-----------------------------------------------------------------------------
+void PARSER_AUTH_BY::SetRecvCb(RecvAuthByDataCb_t f, void * data)
+{
+RecvAuthByDataCb = f;
+authByDataCb = data;
+}
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
 PARSER_CHG_USER::PARSER_CHG_USER()
+    : RecvChgUserCb(NULL),
+      chgUserCbData(NULL),
+      depth(0),
+      error(false)
 {
-depth = 0;
-error = false;
-RecvChgUserCb = NULL;
 }
 //-----------------------------------------------------------------------------
 int PARSER_CHG_USER::ParseStart(const char *el, const char **attr)
@@ -851,11 +906,6 @@ return 0;
 void PARSER_CHG_USER::ParseEnd(const char *)
 {
 depth--;
-}
-//-----------------------------------------------------------------------------
-void PARSER_CHG_USER::Reset()
-{
-
 }
 //-----------------------------------------------------------------------------
 void PARSER_CHG_USER::ParseAnswer(const char *, const char **attr)
@@ -875,10 +925,11 @@ chgUserCbData = data;
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 PARSER_CHECK_USER::PARSER_CHECK_USER()
+    : RecvCheckUserCb(NULL),
+      checkUserCbData(NULL),
+      depth(0),
+      error(false)
 {
-depth = 0;
-error = false;
-RecvCheckUserCb = NULL;
 }
 //-----------------------------------------------------------------------------
 int PARSER_CHECK_USER::ParseStart(const char *el, const char **attr)
@@ -917,10 +968,11 @@ checkUserCbData = data;
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 PARSER_SEND_MESSAGE::PARSER_SEND_MESSAGE()
+    : RecvSendMessageCb(NULL),
+      sendMessageCbData(NULL),
+      depth(0),
+      error(false)
 {
-depth = 0;
-error = false;
-RecvSendMessageCb = NULL;
 }
 //-----------------------------------------------------------------------------
 int  PARSER_SEND_MESSAGE::ParseStart(const char *el, const char **attr)
@@ -939,11 +991,6 @@ return 0;
 void PARSER_SEND_MESSAGE::ParseEnd(const char *)
 {
 depth--;
-}
-//-----------------------------------------------------------------------------
-void PARSER_SEND_MESSAGE::Reset()
-{
-
 }
 //-----------------------------------------------------------------------------
 void PARSER_SEND_MESSAGE::ParseAnswer(const char *, const char **attr)
@@ -958,4 +1005,3 @@ RecvSendMessageCb = f;
 sendMessageCbData = data;
 }
 //-----------------------------------------------------------------------------
-