From 6bd4918f85f22955197b200d79972d22159e89d8 Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Fri, 6 Sep 2013 19:31:52 +0300 Subject: [PATCH] [NY Flight] One time protocol initialization. --- projects/sgconf/common_sg.cpp | 32 +++---------- stglibs/srvconf.lib/include/stg/netunit.h | 11 ++--- stglibs/srvconf.lib/include/stg/servconf.h | 11 +---- stglibs/srvconf.lib/netunit.cpp | 28 +++-------- stglibs/srvconf.lib/servconf.cpp | 56 +++++++++------------- 5 files changed, 39 insertions(+), 99 deletions(-) diff --git a/projects/sgconf/common_sg.cpp b/projects/sgconf/common_sg.cpp index a54826df..48eaac35 100644 --- a/projects/sgconf/common_sg.cpp +++ b/projects/sgconf/common_sg.cpp @@ -440,16 +440,11 @@ data->result = true; //----------------------------------------------------------------------------- bool ProcessSetUser(const std::string & server, int port, - const std::string & admLogin, - const std::string & admPasswd, + const std::string & login, + const std::string & password, const std::string & str) { -SERVCONF sc; - -sc.SetServer(server.c_str()); -sc.SetPort(port); -sc.SetAdmLogin(admLogin.c_str()); -sc.SetAdmPassword(admPasswd.c_str()); +SERVCONF sc(server, port, login, password); ResultData data; sc.SetChgUserCallback(RecvSetUserAnswer, &data); @@ -473,12 +468,7 @@ bool ProcessSendMessage(const std::string & server, uint16_t port, const std::string & login, const std::string & password, const std::string & requestString) { -SERVCONF sc; - -sc.SetServer(server.c_str()); -sc.SetPort(port); -sc.SetAdmLogin(login.c_str()); -sc.SetAdmPassword(password.c_str()); +SERVCONF sc(server, port, login, password); ResultData data; sc.SetSendMessageCallback(SendMessageCallback, &data); @@ -505,12 +495,7 @@ bool ProcessGetUser(const std::string &server, const std::string &login, REQUEST & request) { -SERVCONF sc; - -sc.SetServer(server.c_str()); -sc.SetPort(port); -sc.SetAdmLogin(admLogin.c_str()); -sc.SetAdmPassword(admPasswd.c_str()); +SERVCONF sc(server, port, admLogin, admPasswd); GetUserData data(request, false); @@ -537,12 +522,7 @@ bool ProcessAuthBy(const std::string &server, const std::string &admPasswd, const std::string &login) { -SERVCONF sc; - -sc.SetServer(server.c_str()); -sc.SetPort(port); -sc.SetAdmLogin(admLogin.c_str()); -sc.SetAdmPassword(admPasswd.c_str()); +SERVCONF sc(server, port, admLogin, admPasswd); ResultData data; sc.SetAuthByCallback(RecvAuthByData, &data); diff --git a/stglibs/srvconf.lib/include/stg/netunit.h b/stglibs/srvconf.lib/include/stg/netunit.h index d40b4c6a..332670d6 100644 --- a/stglibs/srvconf.lib/include/stg/netunit.h +++ b/stglibs/srvconf.lib/include/stg/netunit.h @@ -78,18 +78,13 @@ confData class NETTRANSACT { public: - NETTRANSACT(); + NETTRANSACT(const std::string & server, uint16_t port, + const std::string & login, const std::string & password); int Transact(const char * data); const std::string & GetError() const; void SetRxCallback(void * data, RxCallback_t); - void SetServer(const char * serverName); - void SetServerPort(short unsigned p); - - void SetLogin(const char * l); - void SetPassword(const char * p); - //////////////////////////////////////////// int Connect(); int Disconnect(); void Reset(); @@ -112,7 +107,7 @@ private: void Decrypt(char * d, const char * s, BLOWFISH_CTX *ctx); std::string server; - short unsigned port; + uint16_t port; std::string login; std::string password; int outerSocket; diff --git a/stglibs/srvconf.lib/include/stg/servconf.h b/stglibs/srvconf.lib/include/stg/servconf.h index b422f708..87a93f89 100644 --- a/stglibs/srvconf.lib/include/stg/servconf.h +++ b/stglibs/srvconf.lib/include/stg/servconf.h @@ -46,9 +46,6 @@ #include -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) @@ -60,12 +57,8 @@ struct ADMINDATA class SERVCONF { public: - SERVCONF(); - void SetServer(const char * server); - void SetPort(uint16_t port); - - void SetAdmLogin(const char * login); - void SetAdmPassword(const char * password); + SERVCONF(const std::string & server, uint16_t port, + const std::string & login, const std::string & password); void SetGetUsersCallback(PARSER_GET_USERS::CALLBACK f, void * data); void SetAuthByCallback(PARSER_AUTH_BY::CALLBACK f, void * data); diff --git a/stglibs/srvconf.lib/netunit.cpp b/stglibs/srvconf.lib/netunit.cpp index aaba3df6..db22a3a0 100644 --- a/stglibs/srvconf.lib/netunit.cpp +++ b/stglibs/srvconf.lib/netunit.cpp @@ -53,8 +53,12 @@ #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) @@ -461,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; diff --git a/stglibs/srvconf.lib/servconf.cpp b/stglibs/srvconf.lib/servconf.cpp index f2498ef5..906277c3 100644 --- a/stglibs/srvconf.lib/servconf.cpp +++ b/stglibs/srvconf.lib/servconf.cpp @@ -25,7 +25,24 @@ #include #include +namespace +{ + +//----------------------------------------------------------------------------- +void Start(void *data, const char *el, const char **attr) +{ +SERVCONF * sc = static_cast(data); +sc->Start(el, attr); +} //----------------------------------------------------------------------------- +void End(void * data, const char * el) +{ +SERVCONF * sc = static_cast(data); +sc->End(el); +} + +} // namespace anonymous + int AnsRecv(void * data, std::list * list1) { SERVCONF * sc = static_cast(data); @@ -60,46 +77,17 @@ while (node != list1->end()) return st_ok; } + //----------------------------------------------------------------------------- -void Start(void *data, const char *el, const char **attr) -{ -SERVCONF * sc = static_cast(data); -sc->Start(el, attr); -} -//----------------------------------------------------------------------------- -void End(void * data, const char * el) -{ -SERVCONF * sc = static_cast(data); -sc->End(el); -} -//----------------------------------------------------------------------------- -SERVCONF::SERVCONF() - : currParser(NULL) +SERVCONF::SERVCONF(const std::string & server, uint16_t port, + const std::string & login, const std::string & password) + : currParser(NULL), + nt( server, port, login, password ) { parser = XML_ParserCreate(NULL); nt.SetRxCallback(this, AnsRecv); } //----------------------------------------------------------------------------- -void SERVCONF::SetServer(const char * server) -{ -nt.SetServer(server); -} -//----------------------------------------------------------------------------- -void SERVCONF::SetPort(uint16_t port) -{ -nt.SetServerPort(port); -} -//----------------------------------------------------------------------------- -void SERVCONF::SetAdmLogin(const char * login) -{ -nt.SetLogin(login); -} -//----------------------------------------------------------------------------- -void SERVCONF::SetAdmPassword(const char * password) -{ -nt.SetPassword(password); -} -//----------------------------------------------------------------------------- int SERVCONF::GetUser(const char * l) { char request[255]; -- 2.43.2