port(p),
login(l),
password(pwd),
- outerSocket(-1),
- RxCallBack(NULL),
- dataRxCallBack(NULL)
+ outerSocket(-1)
{
}
//---------------------------------------------------------------------------
return st_ok;
}
//---------------------------------------------------------------------------
-int NETTRANSACT::Disconnect()
+void NETTRANSACT::Disconnect()
{
close(outerSocket);
-return 0;
}
//---------------------------------------------------------------------------
-int NETTRANSACT::Transact(const char * data)
+int NETTRANSACT::Transact(const char * request, CALLBACK callback, void * data)
{
int ret;
if ((ret = TxHeader()) != st_ok)
return ret;
}
-if ((ret = TxData(data)) != st_ok)
+if ((ret = TxData(request)) != st_ok)
{
Disconnect();
return ret;
}
-if ((ret = RxDataAnswer()) != st_ok)
+if ((ret = RxDataAnswer(callback, data)) != st_ok)
{
Disconnect();
return ret;
return 0;
}
//---------------------------------------------------------------------------
-int NETTRANSACT::RxDataAnswer()
+int NETTRANSACT::RxDataAnswer(CALLBACK callback, void * data)
{
BLOWFISH_CTX ctx;
EnDecodeInit(password.c_str(), PASSWD_LEN, &ctx);
if (chunk.length() > MAX_XML_CHUNK_LENGTH || final)
{
- if (RxCallBack != NULL)
- if (!RxCallBack(dataRxCallBack, chunk, final))
+ if (callback)
+ if (!callback(chunk, final, data))
return st_xml_parse_error;
chunk.clear();
}
return st_ok;
}
}
-//---------------------------------------------------------------------------
-void NETTRANSACT::SetRxCallback(void * data, RxCallback_t cb)
-{
-RxCallBack = cb;
-dataRxCallBack = data;
-}
#include <string>
-typedef bool (* RxCallback_t)(void *, const std::string &, bool);
-
//---------------------------------------------------------------------------
class NETTRANSACT
{
public:
+ typedef bool (* CALLBACK)(const std::string &, bool, void *);
+
NETTRANSACT(const std::string & server, uint16_t port,
const std::string & login, const std::string & password);
- int Transact(const char * data);
+ int Transact(const char * request, CALLBACK f, void * data);
const std::string & GetError() const { return errorMsg; }
- void SetRxCallback(void * data, RxCallback_t cb);
-
int Connect();
- int Disconnect();
+ void Disconnect();
private:
int TxHeader();
int RxHeaderAnswer();
int TxData(const char * text);
int TxData(char * data);
- int RxDataAnswer();
+ int RxDataAnswer(CALLBACK f, void * data);
std::string server;
uint16_t port;
std::string login;
std::string password;
int outerSocket;
- RxCallback_t RxCallBack;
- void * dataRxCallBack;
std::string errorMsg;
};
//---------------------------------------------------------------------------
std::string errorMsg;
XML_Parser parser;
- static bool ParserRecv(void * data, const std::string & chunk, bool final);
- static bool SimpleRecv(void * data, const std::string & chunk, bool final);
+ static bool ParserRecv(const std::string & chunk, bool final, void * data);
+ static bool SimpleRecv(const std::string & chunk, bool final, void * data);
int ExecImpl(const std::string & request, PARSER & cp);
};
-bool SERVCONF::IMPL::ParserRecv(void * data, const std::string & chunk, bool final)
+bool SERVCONF::IMPL::ParserRecv(const std::string & chunk, bool final, void * data)
{
SERVCONF::IMPL * sc = static_cast<SERVCONF::IMPL *>(data);
return true;
}
-bool SERVCONF::IMPL::SimpleRecv(void * data, const std::string & chunk, bool /*final*/)
+bool SERVCONF::IMPL::SimpleRecv(const std::string & chunk, bool /*final*/, void * data)
{
*static_cast<std::string *>(data) += chunk;
return true;
: nt( server, port, login, password )
{
parser = XML_ParserCreate(NULL);
-nt.SetRxCallback(this, ParserRecv);
}
//-----------------------------------------------------------------------------
void SERVCONF::IMPL::Start(void * data, const char * el, const char ** attr)
errorMsg = nt.GetError();
return ret;
}
-if ((ret = nt.Transact(request.c_str())) != st_ok)
- {
- errorMsg = nt.GetError();
- return ret;
- }
-if ((ret = nt.Disconnect()) != st_ok)
+if ((ret = nt.Transact(request.c_str(), ParserRecv, this)) != st_ok)
{
errorMsg = nt.GetError();
return ret;
}
+nt.Disconnect();
return st_ok;
}
-int SERVCONF::IMPL::RawXML(const std::string & request, RAW_XML::CALLBACK f, void * data)
+int SERVCONF::IMPL::RawXML(const std::string & request, RAW_XML::CALLBACK callback, 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);
+ callback(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)
+std::string response;
+if ((ret = nt.Transact(request.c_str(), SimpleRecv, &response)) != st_ok)
{
- nt.SetRxCallback(this, ParserRecv);
errorMsg = nt.GetError();
- f(false, errorMsg, "", data);
+ callback(false, errorMsg, "", data);
return ret;
}
-nt.SetRxCallback(this, ParserRecv);
-f(true, "", response, data);
+
+nt.Disconnect();
+callback(true, "", response, data);
return st_ok;
}