From cad325f5f0516da6b1d1d44c509ce194e2f08f46 Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Sat, 19 Oct 2013 00:26:35 +0300 Subject: [PATCH] Added RawXML method and related stuff. --- stglibs/srvconf.lib/include/stg/servconf.h | 2 + .../srvconf.lib/include/stg/servconf_types.h | 7 +++ stglibs/srvconf.lib/netunit.h | 1 + stglibs/srvconf.lib/servconf.cpp | 50 +++++++++++++++++-- 4 files changed, 57 insertions(+), 3 deletions(-) diff --git a/stglibs/srvconf.lib/include/stg/servconf.h b/stglibs/srvconf.lib/include/stg/servconf.h index 9c9acb7a..b3bb7523 100644 --- a/stglibs/srvconf.lib/include/stg/servconf.h +++ b/stglibs/srvconf.lib/include/stg/servconf.h @@ -49,6 +49,8 @@ public: int ServerInfo(SERVER_INFO::CALLBACK f, void * data); + int RawXML(const std::string & request, RAW_XML::CALLBACK f, void * data); + int GetAdmins(GET_ADMINS::CALLBACK f, void * data); int GetAdmin(const std::string & login, GET_ADMIN::CALLBACK f, void * data); int ChgAdmin(const ADMIN_CONF_RES & conf, SIMPLE::CALLBACK f, void * data); diff --git a/stglibs/srvconf.lib/include/stg/servconf_types.h b/stglibs/srvconf.lib/include/stg/servconf_types.h index f46aadb5..86df8e95 100644 --- a/stglibs/srvconf.lib/include/stg/servconf_types.h +++ b/stglibs/srvconf.lib/include/stg/servconf_types.h @@ -99,6 +99,13 @@ typedef void (* CALLBACK)(bool result, const std::string & reason, const INFO & } // namespace SERVER_INFO +namespace RAW_XML +{ + +typedef void (* CALLBACK)(bool result, const std::string & reason, const std::string & response, void * data); + +} + namespace GET_USER { diff --git a/stglibs/srvconf.lib/netunit.h b/stglibs/srvconf.lib/netunit.h index fb2a1e28..6b6cef53 100644 --- a/stglibs/srvconf.lib/netunit.h +++ b/stglibs/srvconf.lib/netunit.h @@ -43,6 +43,7 @@ public: const std::string & GetError() const { return errorMsg; } void SetRxCallback(void * data, RxCallback_t cb); + RxCallback_t GetRxCallback() const { return dataRxCallBack; } int Connect(); int Disconnect(); diff --git a/stglibs/srvconf.lib/servconf.cpp b/stglibs/srvconf.lib/servconf.cpp index 7aea7e19..01f21790 100644 --- a/stglibs/srvconf.lib/servconf.cpp +++ b/stglibs/srvconf.lib/servconf.cpp @@ -56,6 +56,8 @@ public: static void Start(void * data, const char * el, const char ** attr); static void End(void * data, const char * el); + int RawXML(const std::string & request, RAW_XML::CALLBACK f, void * data); + template int Exec(const std::string & request, C callback, void * data) { @@ -76,11 +78,12 @@ private: std::string errorMsg; XML_Parser parser; - static bool AnsRecv(void * data, const std::string & chunk, bool final); + static bool ParserRecv(void * data, const std::string & chunk, bool final); + static bool SimpleRecv(void * data, const std::string & chunk, bool final); int ExecImpl(const std::string & request, PARSER & cp); }; -bool SERVCONF::IMPL::AnsRecv(void * data, const std::string & chunk, bool final) +bool SERVCONF::IMPL::ParserRecv(void * data, const std::string & chunk, bool final) { SERVCONF::IMPL * sc = static_cast(data); @@ -96,6 +99,12 @@ if (XML_Parse(sc->parser, chunk.c_str(), chunk.length(), final) == XML_STATUS_ER return true; } +bool SERVCONF::IMPL::SimpleRecv(void * data, const std::string & chunk, bool final) +{ +*static_cast(data) += chunk; +return true; +} + SERVCONF::SERVCONF(const std::string & server, uint16_t port, const std::string & login, const std::string & password) : pImpl(new IMPL(server, port, login, password)) @@ -112,6 +121,10 @@ int SERVCONF::ServerInfo(SERVER_INFO::CALLBACK f, void * data) return pImpl->Exec("", f, data); } +int SERVCONF::RawXML(const std::string & request, RAW_XML::CALLBACK f, void * data) +{ +} + // -- Admins -- int SERVCONF::GetAdmins(GET_ADMINS::CALLBACK f, void * data) @@ -200,7 +213,7 @@ SERVCONF::IMPL::IMPL(const std::string & server, uint16_t port, : nt( server, port, login, password ) { parser = XML_ParserCreate(NULL); -nt.SetRxCallback(this, AnsRecv); +nt.SetRxCallback(this, ParserRecv); } //----------------------------------------------------------------------------- void SERVCONF::IMPL::Start(void * data, const char * el, const char ** attr) @@ -245,3 +258,34 @@ if ((ret = nt.Disconnect()) != st_ok) return st_ok; } + +int SERVCONF::RawXML(const std::string & request, RAW_XML::CALLBACK f, void * data) +{ +std::string response; +nt.SetRxCallback(&response, SimpleRecv); +int ret = 0; +if ((ret = nt.Connect()) != st_ok) + { + nt.SetRxCallback(this, ParserRecv); + errorMsg = nt.GetError(); + f(false, errorMsg, "", data); + return ret; + } +if ((ret = nt.Transact(request.c_str())) != st_ok) + { + nt.SetRxCallback(this, ParserRecv); + errorMsg = nt.GetError(); + f(false, errorMsg, "", data); + return ret; + } +if ((ret = nt.Disconnect()) != st_ok) + { + nt.SetRxCallback(this, ParserRecv); + errorMsg = nt.GetError(); + f(false, errorMsg, "", data); + return ret; + } +nt.SetRxCallback(this, ParserRecv); +f(true, "", response, data); +return st_ok; +} -- 2.44.2