From: Maxim Mamontov Date: Sat, 10 Aug 2013 20:35:00 +0000 (+0300) Subject: Fixed compilation issues. X-Git-Url: https://git.stg.codes/stg.git/commitdiff_plain/6d5f129aad1a6cbaf4d1441c68398e00fa949185 Fixed compilation issues. --- diff --git a/projects/sgconf/common_sg.cpp b/projects/sgconf/common_sg.cpp index 2901832a..ca1aa50c 100644 --- a/projects/sgconf/common_sg.cpp +++ b/projects/sgconf/common_sg.cpp @@ -419,13 +419,10 @@ int ProcessSetUser(const std::string &server, const std::string &admLogin, const std::string &admPasswd, const std::string &str, - void * data, bool isMessage) { SERVCONF sc; -bool result = false; - sc.SetServer(server.c_str()); sc.SetPort(port); sc.SetAdmLogin(admLogin.c_str()); @@ -434,18 +431,19 @@ sc.SetAdmPassword(admPasswd.c_str()); REQUEST request; GetUserData cbdata(request, false); +int res = 0; if (isMessage) { sc.SetSendMessageCb(RecvSetUserAnswer, &cbdata); - sc.MsgUser(str.c_str()); + res = sc.MsgUser(str.c_str()); } else { - sc.SetChgUserCb(RecvSetUserAnswer, &cbdata); - sc.ChgUser(str.c_str()); + sc.SetChgUserCallback(RecvSetUserAnswer, &cbdata); + res = sc.ChgUser(str.c_str()); } -if (result) +if (res && cbdata.result) { printf("Ok\n"); return 0; @@ -477,9 +475,9 @@ sc.SetAdmPassword(admPasswd.c_str()); GetUserData data(request, false); sc.SetGetUserCallback(GetUserCallback, &data); -sc.GetUser(login.c_str()); +bool res = (sc.GetUser(login.c_str()) == st_ok); -if (data.result) +if (res && data.result) { printf("Ok\n"); return 0; @@ -497,8 +495,7 @@ int ProcessAuthBy(const std::string &server, int port, const std::string &admLogin, const std::string &admPasswd, - const std::string &login, - REQUEST & request) + const std::string &login) { SERVCONF sc; @@ -508,9 +505,9 @@ sc.SetAdmLogin(admLogin.c_str()); sc.SetAdmPassword(admPasswd.c_str()); sc.SetAuthByCallback(RecvAuthByData, NULL); -sc.AuthBy(login.c_str()); +bool res = (sc.AuthBy(login.c_str()) == st_ok); -if (sc.GetError()) +if (!res) { printf("Error\n"); return -1; diff --git a/projects/sgconf/common_sg.h b/projects/sgconf/common_sg.h index 47069eae..ca7eb36c 100644 --- a/projects/sgconf/common_sg.h +++ b/projects/sgconf/common_sg.h @@ -56,15 +56,13 @@ int ProcessAuthBy(const std::string &server, int port, const std::string &admLogin, const std::string &admPasswd, - const std::string &login, - REQUEST & request); + const std::string &login); int ProcessSetUser(const std::string &server, int port, const std::string &admLogin, const std::string &admPasswd, const std::string &str, - void * data, bool isMessage = false); #endif diff --git a/projects/sgconf/main.cpp b/projects/sgconf/main.cpp index 507abaa5..f8a394d4 100644 --- a/projects/sgconf/main.cpp +++ b/projects/sgconf/main.cpp @@ -885,7 +885,7 @@ if (missedOptionArg || !CheckParametersGet(&req)) } if (req.authBy) - return ProcessAuthBy(req.server, req.port, req.admLogin, req.admPasswd, req.login, req); + return ProcessAuthBy(req.server, req.port, req.admLogin, req.admPasswd, req.login); else return ProcessGetUser(req.server, req.port, req.admLogin, req.admPasswd, req.login, req); } @@ -1087,7 +1087,7 @@ char rstr[rLen]; memset(rstr, 0, rLen); CreateRequestSet(&req, rstr); -return ProcessSetUser(req.server, req.port, req.admLogin, req.admPasswd, rstr, NULL, isMessage); +return ProcessSetUser(req.server, req.port, req.admLogin, req.admPasswd, rstr, isMessage); } //----------------------------------------------------------------------------- int main(int argc, char **argv) diff --git a/stglibs/crypto.lib/include/stg/blowfish.h b/stglibs/crypto.lib/include/stg/blowfish.h index a8800d75..c9983340 100644 --- a/stglibs/crypto.lib/include/stg/blowfish.h +++ b/stglibs/crypto.lib/include/stg/blowfish.h @@ -13,7 +13,10 @@ #define MAXKEYBYTES 56 /* 448 bits */ #ifdef __cplusplus +#include // size_t extern "C" { +#else +#include // size_t #endif typedef struct { diff --git a/stglibs/srvconf.lib/Makefile b/stglibs/srvconf.lib/Makefile index 7e9d90e0..45f3899d 100644 --- a/stglibs/srvconf.lib/Makefile +++ b/stglibs/srvconf.lib/Makefile @@ -15,6 +15,7 @@ SRCS = netunit.cpp \ parser_check_user.cpp \ parser_get_user.cpp \ parser_get_users.cpp \ + parser_chg_user.cpp \ servconf.cpp INCS = servconf.h \ diff --git a/stglibs/srvconf.lib/include/stg/netunit.h b/stglibs/srvconf.lib/include/stg/netunit.h index e288df86..d40b4c6a 100644 --- a/stglibs/srvconf.lib/include/stg/netunit.h +++ b/stglibs/srvconf.lib/include/stg/netunit.h @@ -27,14 +27,14 @@ #ifndef NetUnitH #define NetUnitH -#include -#include -#include +#include "stg/blowfish.h" #include #include -#include "stg/blowfish.h" +#include +#include +#include #define STG_HEADER "SG04" #define OK_HEADER "OKHD" diff --git a/stglibs/srvconf.lib/include/stg/parser_chg_user.h b/stglibs/srvconf.lib/include/stg/parser_chg_user.h index 3191f370..d8920cde 100644 --- a/stglibs/srvconf.lib/include/stg/parser_chg_user.h +++ b/stglibs/srvconf.lib/include/stg/parser_chg_user.h @@ -27,16 +27,18 @@ class PARSER_CHG_USER: public PARSER { public: + typedef int (* CALLBACK)(const char * asnwer, void * data); + PARSER_CHG_USER(); - int ParseStart(const char *el, const char **attr); - void ParseEnd(const char *el); - void ParseAnswer(const char *el, const char **attr); - void SetChgUserRecvCb(RecvChgUserCb_t, void * data); + int ParseStart(const char * el, const char ** attr); + void ParseEnd(const char * el); + void SetCallback(CALLBACK f, void * data); private: - RecvChgUserCb_t RecvChgUserCb; - void * chgUserCbData; + CALLBACK callback; + void * data; int depth; - bool error; + + 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 index ce7a70ae..5adb2abb 100644 --- a/stglibs/srvconf.lib/include/stg/parser_server_info.h +++ b/stglibs/srvconf.lib/include/stg/parser_server_info.h @@ -22,7 +22,7 @@ #ifndef __STG_STGLIBS_SRVCONF_PARSER_SERVER_INFO_H__ #define __STG_STGLIBS_SRVCONF_PARSER_SERVER_INFO_H__ -#include "/parser.h" +#include "parser.h" #include "stg/const.h" diff --git a/stglibs/srvconf.lib/include/stg/servconf.h b/stglibs/srvconf.lib/include/stg/servconf.h index fddbcf7a..c62161be 100644 --- a/stglibs/srvconf.lib/include/stg/servconf.h +++ b/stglibs/srvconf.lib/include/stg/servconf.h @@ -34,6 +34,7 @@ #include "stg/parser_check_user.h" #include "stg/parser_get_user.h" #include "stg/parser_get_users.h" +#include "stg/parser_chg_user.h" #include "stg/os_int.h" #include "stg/const.h" @@ -44,14 +45,13 @@ #include -void Start(void *data, const char *el, const char **attr); -void End(void *data, const char *el); +void Start(void * data, const char * el, const char ** attr); +void End(void * data, const char * el); #define MAX_ERR_STR_LEN (64) #define IP_STRING_LEN (255) //----------------------------------------------------------------------------- -typedef int(*RecvChgUserCb_t)(const char * asnwer, void * data); -typedef int(*RecvSendMessageCb_t)(const char * answer, void * data); +typedef int (* RecvSendMessageCb_t)(const char * answer, void * data); //----------------------------------------------------------------------------- struct ADMINDATA { @@ -62,15 +62,14 @@ class PARSER_SEND_MESSAGE: public PARSER { public: PARSER_SEND_MESSAGE(); - int ParseStart(const char *el, const char **attr); - void ParseEnd(const char *el); - void ParseAnswer(const char *el, const char **attr); + int ParseStart(const char * el, const char ** attr); + void ParseEnd(const char * el); + void ParseAnswer(const char * el, const char ** attr); void SetSendMessageRecvCb(RecvSendMessageCb_t, void * data); private: RecvSendMessageCb_t RecvSendMessageCb; void * sendMessageCbData; int depth; - bool error; }; //----------------------------------------------------------------------------- class SERVCONF @@ -86,7 +85,7 @@ public: void SetGetUsersCallback(PARSER_GET_USERS::CALLBACK f, void * data); void SetAuthByCallback(PARSER_AUTH_BY::CALLBACK f, void * data); void SetServerInfoCallback(PARSER_SERVER_INFO::CALLBACK f, void * data); - void SetChgUserCb(RecvChgUserCb_t, void * data); + void SetChgUserCallback(PARSER_CHG_USER::CALLBACK f, void * data); void SetCheckUserCallback(PARSER_CHECK_USER::CALLBACK f, void * data); void SetGetUserCallback(PARSER_GET_USER::CALLBACK f, void * data); void SetSendMessageCb(RecvSendMessageCb_t, void * data); @@ -102,9 +101,8 @@ public: int CheckUser(const char * login, const char * password); const std::string & GetStrError() const; - int GetError(); - int Start(const char *el, const char **attr); - void End(const char *el); + int Start(const char * el, const char ** attr); + void End(const char * el); private: PARSER * currParser; @@ -118,28 +116,16 @@ private: PARSER_SEND_MESSAGE parserSendMessage; NETTRANSACT nt; - int parseDepth; std::string errorMsg; - int error; XML_Parser parser; - PARSER_GET_USERS::CALLBACK getUsersCallback; - PARSER_GET_USER::CALLBACK getUserCallback; - PARSER_AUTH_BY::CALLBACK authByCallback; - PARSER_SERVER_INFO::CALLBACK serverInfoCallback; - RecvChgUserCb_t RecvChgUserCb; - PARSER_CHECK_USER::CALLBACK checkUserCallback; RecvSendMessageCb_t RecvSendMessageCb; - void * getUsersData; - void * getUserData; - void * authByData; - void * serverInfoData; - void * chgUserDataCb; - void * checkUserData; void * sendMessageDataCb; + int Exec(const char * request); + friend int AnsRecv(void * data, std::list * list); }; //----------------------------------------------------------------------------- diff --git a/stglibs/srvconf.lib/parser.cpp b/stglibs/srvconf.lib/parser.cpp index f259f581..78247f48 100644 --- a/stglibs/srvconf.lib/parser.cpp +++ b/stglibs/srvconf.lib/parser.cpp @@ -39,64 +39,13 @@ using namespace std; -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -PARSER_CHG_USER::PARSER_CHG_USER() - : RecvChgUserCb(NULL), - chgUserCbData(NULL), - depth(0), - error(false) -{ -} -//----------------------------------------------------------------------------- -int PARSER_CHG_USER::ParseStart(const char *el, const char **attr) -{ -depth++; -if (depth == 1) - { - if (strcasecmp(el, "SetUser") == 0) - { - ParseAnswer(el, attr); - } - else if (strcasecmp(el, "DelUser") == 0) - { - ParseAnswer(el, attr); - } - else if (strcasecmp(el, "AddUser") == 0) - { - ParseAnswer(el, attr); - } - } -return 0; -} -//----------------------------------------------------------------------------- -void PARSER_CHG_USER::ParseEnd(const char *) -{ -depth--; -} -//----------------------------------------------------------------------------- -void PARSER_CHG_USER::ParseAnswer(const char *, const char **attr) -{ -if (RecvChgUserCb) - { - RecvChgUserCb(attr[1], chgUserCbData); - } -} -//----------------------------------------------------------------------------- -void PARSER_CHG_USER::SetChgUserRecvCb(RecvChgUserCb_t f, void * data) -{ -RecvChgUserCb = f; -chgUserCbData = data; -} //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- PARSER_SEND_MESSAGE::PARSER_SEND_MESSAGE() : RecvSendMessageCb(NULL), sendMessageCbData(NULL), - depth(0), - error(false) + depth(0) { } //----------------------------------------------------------------------------- diff --git a/stglibs/srvconf.lib/parser_chg_user.cpp b/stglibs/srvconf.lib/parser_chg_user.cpp index bf48e648..90d78f6c 100644 --- a/stglibs/srvconf.lib/parser_chg_user.cpp +++ b/stglibs/srvconf.lib/parser_chg_user.cpp @@ -19,3 +19,48 @@ * Author : Maxim Mamontov */ +#include "stg/parser_chg_user.h" + +#include + +#include + +PARSER_CHG_USER::PARSER_CHG_USER() + : callback(NULL), + data(NULL), + depth(0) +{ +} +//----------------------------------------------------------------------------- +int PARSER_CHG_USER::ParseStart(const char *el, const char **attr) +{ +depth++; +if (depth == 1) + { + if (strcasecmp(el, "SetUser") == 0) + ParseAnswer(el, attr); + else if (strcasecmp(el, "DelUser") == 0) + ParseAnswer(el, attr); + else if (strcasecmp(el, "AddUser") == 0) + ParseAnswer(el, attr); + } +return 0; +} +//----------------------------------------------------------------------------- +void PARSER_CHG_USER::ParseEnd(const char *) +{ +depth--; +} +//----------------------------------------------------------------------------- +void PARSER_CHG_USER::ParseAnswer(const char * /*el*/, const char ** attr) +{ +if (attr && attr[0] && attr[1]) + if (callback) + callback(attr[1], data); +} +//----------------------------------------------------------------------------- +void PARSER_CHG_USER::SetCallback(CALLBACK f, void * d) +{ +callback = f; +data = d; +} diff --git a/stglibs/srvconf.lib/servconf.cpp b/stglibs/srvconf.lib/servconf.cpp index 7848787b..b8507098 100644 --- a/stglibs/srvconf.lib/servconf.cpp +++ b/stglibs/srvconf.lib/servconf.cpp @@ -24,11 +24,12 @@ $Author: faust $ */ -#include -#include +#include "stg/servconf.h" #include "stg/common.h" -#include "stg/servconf.h" + +#include +#include using namespace std; @@ -85,24 +86,11 @@ sc->End(el); //----------------------------------------------------------------------------- SERVCONF::SERVCONF() : currParser(NULL), - parseDepth(0), - error(0), - getUsersCallback(NULL), - getUserCallback(NULL), - authByCallback(NULL), - serverInfoCallback(NULL), - RecvChgUserCb(NULL), - checkUserCallback(NULL), RecvSendMessageCb(NULL), - getUsersData(NULL), - getUserData(NULL), - authByData(NULL), - serverInfoData(NULL), - chgUserDataCb(NULL), - checkUserData(NULL), sendMessageDataCb(NULL) { parser = XML_ParserCreate(NULL); +nt.SetRxCallback(this, AnsRecv); } //----------------------------------------------------------------------------- void SERVCONF::SetServer(const char * server) @@ -129,31 +117,10 @@ int SERVCONF::GetUser(const char * l) { char request[255]; snprintf(request, 255, "", l); -int ret; currParser = &parserGetUser; -((PARSER_GET_USER*)currParser)->SetCallback(getUserCallback, getUserData); - -nt.Reset(); -nt.SetRxCallback(this, AnsRecv); - -if ((ret = nt.Connect()) != st_ok) - { - errorMsg = nt.GetError(); - return ret; - } -if ((ret = nt.Transact(request)) != st_ok) - { - errorMsg = nt.GetError(); - return ret; - } -if ((ret = nt.Disconnect()) != st_ok) - { - errorMsg = nt.GetError(); - return ret; - } -return st_ok; +return Exec(request); } //----------------------------------------------------------------------------- int SERVCONF::AuthBy(const char * l) @@ -162,59 +129,17 @@ char request[255]; snprintf(request, 255, "", l); currParser = &parserAuthBy; -((PARSER_AUTH_BY*)currParser)->SetCallback(authByCallback, authByData); - -nt.Reset(); -nt.SetRxCallback(this, AnsRecv); - -int ret; -if ((ret = nt.Connect()) != st_ok) - { - errorMsg = nt.GetError(); - return ret; - } -if ((ret = nt.Transact(request)) != st_ok) - { - errorMsg = nt.GetError(); - return ret; - } -if ((ret = nt.Disconnect()) != st_ok) - { - errorMsg = nt.GetError(); - return ret; - } -return st_ok; +return Exec(request); } //----------------------------------------------------------------------------- int SERVCONF::GetUsers() { char request[] = ""; -int ret; currParser = &parserGetUsers; -((PARSER_GET_USERS*)currParser)->SetCallback(getUsersCallback, getUsersData); -nt.Reset(); -nt.SetRxCallback(this, AnsRecv); - -if ((ret = nt.Connect()) != st_ok) - { - errorMsg = nt.GetError(); - return ret; - } -if ((ret = nt.Transact(request)) != st_ok) - { - errorMsg = nt.GetError(); - return ret; - } -if ((ret = nt.Disconnect()) != st_ok) - { - errorMsg = nt.GetError(); - return ret; - } - -return st_ok; +return Exec(request); } //----------------------------------------------------------------------------- int SERVCONF::SendMessage(const char * login, const char * message, int prio) @@ -223,152 +148,47 @@ char request[1000]; char msg[500]; Encode12(msg, message, strlen(message)); snprintf(request, 1000, "", login, prio, msg); -int ret; currParser = &parserSendMessage; parserSendMessage.SetSendMessageRecvCb(RecvSendMessageCb, sendMessageDataCb); -nt.Reset(); -nt.SetRxCallback(this, AnsRecv); - -if ((ret = nt.Connect()) != st_ok) - { - errorMsg = nt.GetError(); - return ret; - } -if ((ret = nt.Transact(request)) != st_ok) - { - errorMsg = nt.GetError(); - return ret; - } -if ((ret = nt.Disconnect()) != st_ok) - { - errorMsg = nt.GetError(); - return ret; - } - -return st_ok; +return Exec(request); } //----------------------------------------------------------------------------- int SERVCONF::ServerInfo() { char request[] = ""; -int ret; currParser = &parserServerInfo; -((PARSER_SERVER_INFO*)currParser)->SetCallback(serverInfoCallback, serverInfoData); - -nt.Reset(); -nt.SetRxCallback(this, AnsRecv); - -if ((ret = nt.Connect()) != st_ok) - { - errorMsg = nt.GetError(); - return ret; - } -if ((ret = nt.Transact(request)) != st_ok) - { - errorMsg = nt.GetError(); - return ret; - } -if ((ret = nt.Disconnect()) != st_ok) - { - errorMsg = nt.GetError(); - return ret; - } -return st_ok; +return Exec(request); } //----------------------------------------------------------------------------- int SERVCONF::ChgUser(const char * request) { -int ret; - currParser = &parserChgUser; -((PARSER_CHG_USER*)currParser)->SetChgUserRecvCb(RecvChgUserCb, chgUserDataCb); - -nt.Reset(); -nt.SetRxCallback(this, AnsRecv); - -if ((ret = nt.Connect()) != st_ok) - { - errorMsg = nt.GetError(); - return ret; - } -if ((ret = nt.Transact(request)) != st_ok) - { - errorMsg = nt.GetError(); - return ret; - } -if ((ret = nt.Disconnect()) != st_ok) - { - errorMsg = nt.GetError(); - return ret; - } -return st_ok; +return Exec(request); } //----------------------------------------------------------------------------- // TODO: remove this shit! //----------------------------------------------------------------------------- int SERVCONF::MsgUser(const char * request) { -int ret; - currParser = &parserSendMessage; parserSendMessage.SetSendMessageRecvCb(RecvSendMessageCb, sendMessageDataCb); -nt.Reset(); -nt.SetRxCallback(this, AnsRecv); - -if ((ret = nt.Connect()) != st_ok) - { - errorMsg = nt.GetError(); - return ret; - } -if ((ret = nt.Transact(request)) != st_ok) - { - errorMsg = nt.GetError(); - return ret; - } -if ((ret = nt.Disconnect()) != st_ok) - { - errorMsg = nt.GetError(); - return ret; - } - -return st_ok; +return Exec(request); } //----------------------------------------------------------------------------- int SERVCONF::CheckUser(const char * login, const char * password) { char request[255]; snprintf(request, 255, "", login, password); -int ret; currParser = &parserCheckUser; -((PARSER_CHECK_USER*)currParser)->SetCallback(checkUserCallback, checkUserData); - -nt.Reset(); -nt.SetRxCallback(this, AnsRecv); -if ((ret = nt.Connect()) != st_ok) - { - errorMsg = nt.GetError(); - return ret; - } -if ((ret = nt.Transact(request)) != st_ok) - { - errorMsg = nt.GetError(); - return ret; - } -if ((ret = nt.Disconnect()) != st_ok) - { - errorMsg = nt.GetError(); - return ret; - } - -return st_ok; +return Exec(request); } //----------------------------------------------------------------------------- int SERVCONF::Start(const char *el, const char **attr) @@ -384,38 +204,32 @@ currParser->ParseEnd(el); //----------------------------------------------------------------------------- void SERVCONF::SetGetUsersCallback(PARSER_GET_USERS::CALLBACK f, void * data) { -getUsersCallback = f; -getUsersData = data; +parserGetUsers.SetCallback(f, data); } //----------------------------------------------------------------------------- void SERVCONF::SetGetUserCallback(PARSER_GET_USER::CALLBACK f, void * data) { -getUserCallback = f; -getUserData = data; +parserGetUser.SetCallback(f, data); } //----------------------------------------------------------------------------- void SERVCONF::SetAuthByCallback(PARSER_AUTH_BY::CALLBACK f, void * data) { -authByCallback = f; -authByData = data; +parserAuthBy.SetCallback(f, data); } //----------------------------------------------------------------------------- void SERVCONF::SetServerInfoCallback(PARSER_SERVER_INFO::CALLBACK f, void * data) { -serverInfoCallback = f; -serverInfoData = data; +parserServerInfo.SetCallback(f, data); } //----------------------------------------------------------------------------- -void SERVCONF::SetChgUserCb(RecvChgUserCb_t f, void * data) +void SERVCONF::SetChgUserCallback(PARSER_CHG_USER::CALLBACK f, void * data) { -RecvChgUserCb = f; -chgUserDataCb = data; +parserChgUser.SetCallback(f, data); } //----------------------------------------------------------------------------- void SERVCONF::SetCheckUserCallback(PARSER_CHECK_USER::CALLBACK f, void * data) { -checkUserCallback = f; -checkUserData = data; +parserCheckUser.SetCallback(f, data); } //----------------------------------------------------------------------------- void SERVCONF::SetSendMessageCb(RecvSendMessageCb_t f, void * data) @@ -429,10 +243,26 @@ const std::string & SERVCONF::GetStrError() const return errorMsg; } //----------------------------------------------------------------------------- -int SERVCONF::GetError() +int SERVCONF::Exec(const char * request) { -int e = error; -error = 0; -return e; +nt.Reset(); + +int ret = 0; +if ((ret = nt.Connect()) != st_ok) + { + errorMsg = nt.GetError(); + return ret; + } +if ((ret = nt.Transact(request)) != st_ok) + { + errorMsg = nt.GetError(); + return ret; + } +if ((ret = nt.Disconnect()) != st_ok) + { + errorMsg = nt.GetError(); + return ret; + } + +return st_ok; } -//-----------------------------------------------------------------------------