X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/cdd6c43fceeb5a37867ae902bb71429abad7fa64..e19d853bbf16b7ba8c58c71c1da488b9034e0fb3:/stglibs/srvconf.lib/parser.cpp?ds=sidebyside diff --git a/stglibs/srvconf.lib/parser.cpp b/stglibs/srvconf.lib/parser.cpp index 139c91bc..bd6bb62e 100644 --- a/stglibs/srvconf.lib/parser.cpp +++ b/stglibs/srvconf.lib/parser.cpp @@ -33,10 +33,9 @@ #include #include -#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; @@ -46,6 +45,7 @@ using namespace std; PARSER_GET_USERS::PARSER_GET_USERS() : RecvUserDataCb(NULL), userDataCb(NULL), + user(), depth(0), error(false) { @@ -165,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) @@ -379,6 +387,7 @@ userDataCb = data; PARSER_GET_USER::PARSER_GET_USER() : RecvUserDataCb(NULL), userDataCb(NULL), + user(), depth(0), error(false) { @@ -518,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; @@ -645,165 +662,6 @@ userDataCb = data; //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- -PARSER_GET_SERVER_INFO::PARSER_GET_SERVER_INFO() - : RecvServerInfoDataCb(NULL), - serverInfoDataCb(NULL), - depth(0), - error(false) -{ -} -//----------------------------------------------------------------------------- -int PARSER_GET_SERVER_INFO::ParseStart(const char *el, const char **attr) -{ -depth++; -if (depth == 1) - { - if (strcasecmp(el, "ServerInfo") != 0) - { - //printf("%s\n", el); - } - } -else - { - if (depth == 2) - { - if (strcasecmp(el, "uname") == 0) - { - ParseUname(attr); - return 0; - } - if (strcasecmp(el, "version") == 0) - { - ParseServerVersion(attr); - return 0; - } - if (strcasecmp(el, "tariff") == 0) - { - ParseTariffType(attr); - return 0; - } - if (strcasecmp(el, "dir_num") == 0) - { - ParseDirNum(attr); - return 0; - } - if (strcasecmp(el, "users_num") == 0) - { - ParseUsersNum(attr); - return 0; - } - if (strcasecmp(el, "tariff_num") == 0) - { - ParseTariffsNum(attr); - return 0; - } - - for (int j = 0; j < DIR_NUM; j++) - { - char str[16]; - sprintf(str, "dir_name_%d", j); - if (strcasecmp(el, str) == 0) - { - ParseDirName(attr, j); - } - } - - } - } -return 0; -} -//----------------------------------------------------------------------------- -void PARSER_GET_SERVER_INFO::ParseEnd(const char *) -{ -depth--; -if (depth == 0) - { - RecvServerInfoDataCb(&serverInfo, serverInfoDataCb); - } -} -//----------------------------------------------------------------------------- -/*void PARSER_GET_SERVER_INFO::ParseServerInfo(const char * el, const char ** attr) - { - }*/ -//----------------------------------------------------------------------------- -void PARSER_GET_SERVER_INFO::SetServerInfoRecvCb(RecvServerInfoDataCb_t f, void * data) -{ -RecvServerInfoDataCb = f; -serverInfoDataCb = data; -} -//----------------------------------------------------------------------------- -void PARSER_GET_SERVER_INFO::ParseUname(const char ** attr) -{ -if (strcmp(*attr, "value") == 0) - serverInfo.uname = attr[1]; -} -//----------------------------------------------------------------------------- -void PARSER_GET_SERVER_INFO::ParseServerVersion(const char ** attr) -{ -if (strcmp(*attr, "value") == 0) - serverInfo.version = attr[1]; -} -//----------------------------------------------------------------------------- -void PARSER_GET_SERVER_INFO::ParseUsersNum(const char ** attr) -{ -if (strcmp(*attr, "value") == 0) - { - if (str2x(attr[1], serverInfo.usersNum) < 0) - { - serverInfo.usersNum = -1; - return; - } - } -} -//----------------------------------------------------------------------------- -void PARSER_GET_SERVER_INFO::ParseTariffsNum(const char ** attr) -{ -if (strcmp(*attr, "value") == 0) - { - if (str2x(attr[1], serverInfo.tariffNum) < 0) - { - serverInfo.tariffNum = -1; - return; - } - } -} -//----------------------------------------------------------------------------- -void PARSER_GET_SERVER_INFO::ParseTariffType(const char ** attr) -{ -if (strcmp(*attr, "value") == 0) - { - if (str2x(attr[1], serverInfo.tariffType) < 0) - { - serverInfo.tariffType = -1; - return; - } - } -} -//----------------------------------------------------------------------------- -void PARSER_GET_SERVER_INFO::ParseDirNum(const char **attr) -{ -if (strcasecmp(*attr, "value") == 0) - { - if (str2x(attr[1], serverInfo.dirNum) < 0) - { - serverInfo.dirNum = -1; - return; - } - } -} -//----------------------------------------------------------------------------- -void PARSER_GET_SERVER_INFO::ParseDirName(const char **attr, int d) -{ -if (strcmp(attr[0], "value") == 0) - { - char str[2*DIRNAME_LEN + 1]; - Decode21(str, attr[1]); - serverInfo.dirName[d] = str; - } -} -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- PARSER_CHG_USER::PARSER_CHG_USER() : RecvChgUserCb(NULL), chgUserCbData(NULL), @@ -854,49 +712,6 @@ chgUserCbData = data; //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- -PARSER_CHECK_USER::PARSER_CHECK_USER() - : RecvCheckUserCb(NULL), - checkUserCbData(NULL), - depth(0), - error(false) -{ -} -//----------------------------------------------------------------------------- -int PARSER_CHECK_USER::ParseStart(const char *el, const char **attr) -{ -depth++; -if (depth == 1) - { - if (strcasecmp(el, "CheckUser") == 0) - { - //printf("el=%s attr[0]=%s attr[1]=%s\n", el, attr[0], attr[1]); - ParseAnswer(el, attr); - } - } -return 0; -} -//----------------------------------------------------------------------------- -void PARSER_CHECK_USER::ParseEnd(const char *) -{ -depth--; -} -//----------------------------------------------------------------------------- -void PARSER_CHECK_USER::ParseAnswer(const char *, const char **attr) -{ -if (RecvCheckUserCb) - { - RecvCheckUserCb(attr[1], checkUserCbData); - } -} -//----------------------------------------------------------------------------- -void PARSER_CHECK_USER::SetCheckUserRecvCb(RecvCheckUserCb_t f, void * data) -{ -RecvCheckUserCb = f; -checkUserCbData = data; -} -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- PARSER_SEND_MESSAGE::PARSER_SEND_MESSAGE() : RecvSendMessageCb(NULL), sendMessageCbData(NULL),