From: Maxim Mamontov Date: Mon, 5 Aug 2013 19:22:45 +0000 (+0300) Subject: srvconf refactoring: auth_by, server_info and check_user. X-Git-Url: https://git.stg.codes/stg.git/commitdiff_plain/e19d853bbf16b7ba8c58c71c1da488b9034e0fb3 srvconf refactoring: auth_by, server_info and check_user. --- diff --git a/projects/sgconf/common_sg.cpp b/projects/sgconf/common_sg.cpp index b73a79c8..a15f7588 100644 --- a/projects/sgconf/common_sg.cpp +++ b/projects/sgconf/common_sg.cpp @@ -84,7 +84,7 @@ HelpParams hp[] = {"set credit expire", "get credit expire", "-E", ""}, {"set password", "get password", "-o", ""}, {"set prepaid traffic", "get prepaid traffic", "-e", ""}, - {"set IP-addresses", "get IP-addresses", "-I", "<*|ip_addr[,ip_addr...]>"}, + {"set IP-addresses", "get IP-addresses", "-I", "<*|ip_addr[,ip_addr...]>"}, {"set name", "get name", "-A", ""}, {"set note", "get note", "-N", ""}, {"set street address", "get street address", "-D", "
"}, @@ -398,7 +398,7 @@ StringReqParams strReqParams[] = {"group", req->group, &ud->group}, {"tariff", req->tariff, &ud->tariff}, {"password", req->usrPasswd, &ud->password}, - {"ip", req->ips, &ud->ips} // IP-address of user + {"ip", req->ips, &ud->ips} // IP-address of user }; for (unsigned i = 0; i < sizeof(strReqParams) / sizeof(StringReqParams); i++) { diff --git a/stglibs/srvconf.lib/Makefile b/stglibs/srvconf.lib/Makefile index ab170663..a2b0dc4a 100644 --- a/stglibs/srvconf.lib/Makefile +++ b/stglibs/srvconf.lib/Makefile @@ -11,6 +11,8 @@ LIBS = -lexpat SRCS = netunit.cpp \ parser.cpp \ parser_auth_by.cpp \ + parser_server_info.cpp \ + parser_check_user.cpp \ servconf.cpp INCS = servconf.h \ diff --git a/stglibs/srvconf.lib/include/stg/parser_auth_by.h b/stglibs/srvconf.lib/include/stg/parser_auth_by.h index 3ef1d00c..b9f33cf3 100644 --- a/stglibs/srvconf.lib/include/stg/parser_auth_by.h +++ b/stglibs/srvconf.lib/include/stg/parser_auth_by.h @@ -1,3 +1,23 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* + * Author : Maxim Mamontov + */ + #ifndef __STG_STGLIBS_SRVCONF_PARSER_AUTH_BY_H__ #define __STG_STGLIBS_SRVCONF_PARSER_AUTH_BY_H__ diff --git a/stglibs/srvconf.lib/include/stg/parser_check_user.h b/stglibs/srvconf.lib/include/stg/parser_check_user.h new file mode 100644 index 00000000..55d5531e --- /dev/null +++ b/stglibs/srvconf.lib/include/stg/parser_check_user.h @@ -0,0 +1,44 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* + * Author : Boris Mikhailenko + * Author : Maxim Mamontov + */ + +#ifndef __STG_STGLIBS_SRVCONF_PARSER_CHECK_USER_H__ +#define __STG_STGLIBS_SRVCONF_PARSER_CHECK_USER_H__ + +#include "stg/parser.h" + +class PARSER_CHECK_USER: public PARSER +{ +public: + typedef int (* CALLBACK)(const char * answer, void * data); + + PARSER_CHECK_USER(); + int ParseStart(const char *el, const char **attr); + void ParseEnd(const char *el); + void SetCallback(CALLBACK f, void * data); +private: + CALLBACK callback; + void * data; + int depth; + + void ParseAnswer(const char *el, const char **attr); +}; + +#endif diff --git a/stglibs/srvconf.lib/include/stg/parser_server_info.h b/stglibs/srvconf.lib/include/stg/parser_server_info.h new file mode 100644 index 00000000..38e87186 --- /dev/null +++ b/stglibs/srvconf.lib/include/stg/parser_server_info.h @@ -0,0 +1,59 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* + * Author : Boris Mikhailenko + * Author : Maxim Mamontov + */ + +#ifndef __STG_STGLIBS_SRVCONF_PARSER_SERVER_INFO_H__ +#define __STG_STGLIBS_SRVCONF_PARSER_SERVER_INFO_H__ + +#include "stg/parser.h" + +#include "stg/const.h" + +#include + +class PARSER_SERVER_INFO: public PARSER +{ +public: + struct INFO + { + std::string version; + int tariffNum; + int tariffType; + int usersNum; + std::string uname; + int dirNum; + std::string dirName[DIR_NUM]; + }; + typedef void (* CALLBACK)(const INFO & info, void * data); + + PARSER_SERVER_INFO(); + int ParseStart(const char *el, const char **attr); + void ParseEnd(const char *el); + void SetCallback(CALLBACK f, void * data); +private: + void ParseDirName(const char **attr, int d); + + CALLBACK callback; + void * data; + int depth; + INFO info; +}; + +#endif diff --git a/stglibs/srvconf.lib/include/stg/servconf.h b/stglibs/srvconf.lib/include/stg/servconf.h index b9705851..69513d08 100644 --- a/stglibs/srvconf.lib/include/stg/servconf.h +++ b/stglibs/srvconf.lib/include/stg/servconf.h @@ -30,6 +30,9 @@ #include "netunit.h" #include "stg/parser_auth_by.h" +#include "stg/parser_server_info.h" +#include "stg/parser_check_user.h" + #include "stg/os_int.h" #include "stg/const.h" @@ -44,9 +47,6 @@ void End(void *data, const char *el); #define MAX_ERR_STR_LEN (64) #define IP_STRING_LEN (255) -#define UNAME_LEN (256) -#define SERV_VER_LEN (64) -#define DIRNAME_LEN (16) //----------------------------------------------------------------------------- struct STAT @@ -58,17 +58,6 @@ struct STAT double freeMb; }; //----------------------------------------------------------------------------- -struct SERVERINFO -{ - std::string version; - int tariffNum; - int tariffType; - int usersNum; - std::string uname; - int dirNum; - std::string dirName[DIR_NUM]; -}; -//----------------------------------------------------------------------------- struct USERDATA { std::string login; @@ -100,9 +89,7 @@ struct USERDATA }; //----------------------------------------------------------------------------- typedef void(*RecvUserDataCb_t)(USERDATA * ud, void * data); -typedef void(*RecvServerInfoDataCb_t)(SERVERINFO * si, void * data); typedef int(*RecvChgUserCb_t)(const char * asnwer, void * data); -typedef int(*RecvCheckUserCb_t)(const char * answer, void * data); typedef int(*RecvSendMessageCb_t)(const char * answer, void * data); //----------------------------------------------------------------------------- struct ADMINDATA @@ -125,21 +112,6 @@ private: bool error; }; //----------------------------------------------------------------------------- -class PARSER_CHECK_USER: public PARSER -{ -public: - PARSER_CHECK_USER(); - int ParseStart(const char *el, const char **attr); - void ParseEnd(const char *el); - void ParseAnswer(const char *el, const char **attr); - void SetCheckUserRecvCb(RecvCheckUserCb_t, void * data); -private: - RecvCheckUserCb_t RecvCheckUserCb; - void * checkUserCbData; - int depth; - bool error; -}; -//----------------------------------------------------------------------------- class PARSER_GET_USERS: public PARSER { public: @@ -178,31 +150,6 @@ private: bool error; }; //----------------------------------------------------------------------------- -class PARSER_GET_SERVER_INFO: public PARSER -{ -public: - PARSER_GET_SERVER_INFO(); - int ParseStart(const char *el, const char **attr); - void ParseEnd(const char *el); - void ParseServerInfo(const char *el, const char **attr); - bool GetError(); - void SetServerInfoRecvCb(RecvServerInfoDataCb_t, void * data); -private: - void ParseUname(const char ** attr); - void ParseServerVersion(const char ** attr); - void ParseUsersNum(const char ** attr); - void ParseTariffsNum(const char ** attr); - void ParseTariffType(const char ** attr); - void ParseDirNum(const char **attr); - void ParseDirName(const char **attr, int d); - - RecvServerInfoDataCb_t RecvServerInfoDataCb; - void * serverInfoDataCb; - int depth; - bool error; - SERVERINFO serverInfo; -}; -//----------------------------------------------------------------------------- class PARSER_SEND_MESSAGE: public PARSER { public: @@ -230,9 +177,9 @@ public: void SetUserDataRecvCb(RecvUserDataCb_t, void * data); void SetAuthByCallback(PARSER_AUTH_BY::CALLBACK f, void * data); - void SetServerInfoRecvCb(RecvServerInfoDataCb_t, void * data); + void SetServerInfoCallback(PARSER_SERVER_INFO::CALLBACK f, void * data); void SetChgUserCb(RecvChgUserCb_t, void * data); - void SetCheckUserCb(RecvCheckUserCb_t, void * data); + void SetCheckUserCallback(PARSER_CHECK_USER::CALLBACK f, void * data); void SetGetUserDataRecvCb(RecvUserDataCb_t, void * data); void SetSendMessageCb(RecvSendMessageCb_t, void * data); @@ -243,7 +190,7 @@ public: // TODO: Remove this shit! int MsgUser(const char * request); int SendMessage(const char * login, const char * message, int prio); - int GetServerInfo(); + int ServerInfo(); int CheckUser(const char * login, const char * password); const std::string & GetStrError() const; @@ -257,7 +204,7 @@ private: PARSER_GET_USERS parserGetUsers; PARSER_GET_USER parserGetUser; PARSER_AUTH_BY parserAuthBy; - PARSER_GET_SERVER_INFO parserServerInfo; + PARSER_SERVER_INFO parserServerInfo; PARSER_CHG_USER parserChgUser; PARSER_CHECK_USER parserCheckUser; PARSER_SEND_MESSAGE parserSendMessage; @@ -272,17 +219,17 @@ private: RecvUserDataCb_t RecvUserDataCb; RecvUserDataCb_t RecvGetUserDataCb; PARSER_AUTH_BY::CALLBACK authByCallback; - RecvServerInfoDataCb_t RecvServerInfoDataCb; + PARSER_SERVER_INFO::CALLBACK serverInfoCallback; RecvChgUserCb_t RecvChgUserCb; - RecvCheckUserCb_t RecvCheckUserCb; + PARSER_CHECK_USER::CALLBACK checkUserCallback; RecvSendMessageCb_t RecvSendMessageCb; void * getUserDataDataCb; void * authByData; void * getUsersDataDataCb; - void * getServerInfoDataCb; + void * serverInfoData; void * chgUserDataCb; - void * checkUserDataCb; + void * checkUserData; void * sendMessageDataCb; friend int AnsRecv(void * data, std::list * list); diff --git a/stglibs/srvconf.lib/parser.cpp b/stglibs/srvconf.lib/parser.cpp index a87266eb..bd6bb62e 100644 --- a/stglibs/srvconf.lib/parser.cpp +++ b/stglibs/srvconf.lib/parser.cpp @@ -662,166 +662,6 @@ userDataCb = data; //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- -PARSER_GET_SERVER_INFO::PARSER_GET_SERVER_INFO() - : RecvServerInfoDataCb(NULL), - serverInfoDataCb(NULL), - depth(0), - error(false), - serverInfo() -{ -} -//----------------------------------------------------------------------------- -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), @@ -872,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), diff --git a/stglibs/srvconf.lib/parser_auth_by.cpp b/stglibs/srvconf.lib/parser_auth_by.cpp index 63c23a09..5af3f1e4 100644 --- a/stglibs/srvconf.lib/parser_auth_by.cpp +++ b/stglibs/srvconf.lib/parser_auth_by.cpp @@ -1,3 +1,23 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* + * Author : Maxim Mamontov + */ + #include "stg/parser_auth_by.h" #include // strcasecmp @@ -35,12 +55,12 @@ return 0; void PARSER_AUTH_BY::ParseEnd(const char * /*el*/) { depth--; -if (depth == 0) +if (depth == 0 && callback) callback(info, data); } //----------------------------------------------------------------------------- -void PARSER_AUTH_BY::SetCallback(CALLBACK f, void * data) +void PARSER_AUTH_BY::SetCallback(CALLBACK f, void * d) { callback = f; -data = data; +data = d; } diff --git a/stglibs/srvconf.lib/parser_check_user.cpp b/stglibs/srvconf.lib/parser_check_user.cpp new file mode 100644 index 00000000..66db6cff --- /dev/null +++ b/stglibs/srvconf.lib/parser_check_user.cpp @@ -0,0 +1,58 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* + * Author : Boris Mikhailenko + * Author : Maxim Mamontov + */ + +#include "stg/parser_check_user.h" + +#include + +PARSER_CHECK_USER::PARSER_CHECK_USER() + : callback(NULL), + data(NULL), + depth(0) +{ +} +//----------------------------------------------------------------------------- +int PARSER_CHECK_USER::ParseStart(const char *el, const char **attr) +{ +depth++; +if (depth == 1) + if (strcasecmp(el, "CheckUser") == 0) + ParseAnswer(el, attr); +return 0; +} +//----------------------------------------------------------------------------- +void PARSER_CHECK_USER::ParseEnd(const char *) +{ +depth--; +} +//----------------------------------------------------------------------------- +void PARSER_CHECK_USER::ParseAnswer(const char *, const char **attr) +{ +if (attr && attr[0] && attr[1] && strcasecmp(attr[0], "value") == 0) + if (callback) + callback(attr[1], data); +} +//----------------------------------------------------------------------------- +void PARSER_CHECK_USER::SetCallback(CALLBACK f, void * d) +{ +callback = f; +data = d; +} diff --git a/stglibs/srvconf.lib/parser_server_info.cpp b/stglibs/srvconf.lib/parser_server_info.cpp new file mode 100644 index 00000000..8726c743 --- /dev/null +++ b/stglibs/srvconf.lib/parser_server_info.cpp @@ -0,0 +1,146 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* + * Author : Boris Mikhailenko + * Author : Maxim Mamontov + */ + +#include "stg/parser_server_info.h" + +#include "stg/common.h" + +#include // sprintf + +#include + +namespace +{ + +const size_t UNAME_LEN = 256; +const size_t SERV_VER_LEN = 64; +const size_t DIRNAME_LEN = 16; + +bool checkValue(const char ** attr) +{ +return attr && attr[0] && attr[1] && strcasecmp(attr[0], "value") == 0; +} + +int getIntValue(const char ** attr) +{ +int value = -1; +if (checkValue(attr)) + if (str2x(attr[1], value) < 0) + return -1; +return value; +} + +std::string getStringValue(const char ** attr) +{ +if (checkValue(attr)) + return attr[1]; +return ""; +} + +} + +PARSER_SERVER_INFO::PARSER_SERVER_INFO() + : callback(NULL), + data(NULL), + depth(0) +{ +} +//----------------------------------------------------------------------------- +int PARSER_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) + { + info.uname = getStringValue(attr); + return 0; + } + if (strcasecmp(el, "version") == 0) + { + info.version = getStringValue(attr); + return 0; + } + if (strcasecmp(el, "tariff") == 0) + { + info.tariffType = getIntValue(attr); + return 0; + } + if (strcasecmp(el, "dir_num") == 0) + { + info.dirNum = getIntValue(attr); + return 0; + } + if (strcasecmp(el, "users_num") == 0) + { + info.usersNum = getIntValue(attr); + return 0; + } + if (strcasecmp(el, "tariff_num") == 0) + { + info.tariffNum = getIntValue(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_SERVER_INFO::ParseEnd(const char * /*el*/) +{ +depth--; +if (depth == 0 && callback) + callback(info, data); +} +//----------------------------------------------------------------------------- +void PARSER_SERVER_INFO::SetCallback(CALLBACK f, void * d) +{ +callback = f; +data = d; +} +//----------------------------------------------------------------------------- +void PARSER_SERVER_INFO::ParseDirName(const char **attr, int d) +{ +if (checkValue(attr)) + { + char str[2 * DIRNAME_LEN + 1]; + Decode21(str, attr[1]); + info.dirName[d] = str; + } +} diff --git a/stglibs/srvconf.lib/servconf.cpp b/stglibs/srvconf.lib/servconf.cpp index d7df4704..9d7e35f2 100644 --- a/stglibs/srvconf.lib/servconf.cpp +++ b/stglibs/srvconf.lib/servconf.cpp @@ -97,16 +97,16 @@ SERVCONF::SERVCONF() RecvUserDataCb(NULL), RecvGetUserDataCb(NULL), authByCallback(NULL), - RecvServerInfoDataCb(NULL), + serverInfoCallback(NULL), RecvChgUserCb(NULL), - RecvCheckUserCb(NULL), + checkUserCallback(NULL), RecvSendMessageCb(NULL), getUserDataDataCb(NULL), authByData(NULL), getUsersDataDataCb(NULL), - getServerInfoDataCb(NULL), + serverInfoData(NULL), chgUserDataCb(NULL), - checkUserDataCb(NULL), + checkUserData(NULL), sendMessageDataCb(NULL) { parser = XML_ParserCreate(NULL); @@ -257,13 +257,13 @@ if ((ret = nt.Disconnect()) != st_ok) return st_ok; } //----------------------------------------------------------------------------- -int SERVCONF::GetServerInfo() +int SERVCONF::ServerInfo() { char request[] = ""; int ret; currParser = &parserServerInfo; -((PARSER_GET_SERVER_INFO*)currParser)->SetServerInfoRecvCb(RecvServerInfoDataCb, getServerInfoDataCb); +((PARSER_SERVER_INFO*)currParser)->SetCallback(serverInfoCallback, serverInfoData); nt.Reset(); nt.SetRxCallback(this, AnsRecv); @@ -354,7 +354,7 @@ snprintf(request, 255, "", login, passw int ret; currParser = &parserCheckUser; -((PARSER_CHECK_USER*)currParser)->SetCheckUserRecvCb(RecvCheckUserCb, checkUserDataCb); +((PARSER_CHECK_USER*)currParser)->SetCallback(checkUserCallback, checkUserData); nt.Reset(); nt.SetRxCallback(this, AnsRecv); @@ -407,10 +407,10 @@ authByCallback = f; authByData = data; } //----------------------------------------------------------------------------- -void SERVCONF::SetServerInfoRecvCb(RecvServerInfoDataCb_t f, void * data) +void SERVCONF::SetServerInfoCallback(PARSER_SERVER_INFO::CALLBACK f, void * data) { -RecvServerInfoDataCb = f; -getServerInfoDataCb = data; +serverInfoCallback = f; +serverInfoData = data; } //----------------------------------------------------------------------------- void SERVCONF::SetChgUserCb(RecvChgUserCb_t f, void * data) @@ -419,10 +419,10 @@ RecvChgUserCb = f; chgUserDataCb = data; } //----------------------------------------------------------------------------- -void SERVCONF::SetCheckUserCb(RecvCheckUserCb_t f, void * data) +void SERVCONF::SetCheckUserCallback(PARSER_CHECK_USER::CALLBACK f, void * data) { -RecvCheckUserCb = f; -checkUserDataCb = data; +checkUserCallback = f; +checkUserData = data; } //----------------------------------------------------------------------------- void SERVCONF::SetSendMessageCb(RecvSendMessageCb_t f, void * data)