Reconnected immediately to the XMPP whenever it closes the connection
This commit is contained in:
@@ -167,6 +167,11 @@ void XmppComponent::on_remote_stream_close(const XmlNode& node)
|
||||
this->doc_open = false;
|
||||
}
|
||||
|
||||
void XmppComponent::reset()
|
||||
{
|
||||
this->parser.reset();
|
||||
}
|
||||
|
||||
void XmppComponent::on_stanza(const Stanza& stanza)
|
||||
{
|
||||
log_debug("XMPP RECEIVING: " << stanza.to_string());
|
||||
|
||||
@@ -41,6 +41,10 @@ public:
|
||||
* Connect to the XMPP server.
|
||||
*/
|
||||
void start();
|
||||
/**
|
||||
* Reset the component so we can use the component on a new XMPP stream
|
||||
*/
|
||||
void reset();
|
||||
/**
|
||||
* Serialize the stanza and add it to the out_buf to be sent to the
|
||||
* server.
|
||||
|
||||
@@ -30,6 +30,11 @@ static void character_data_handler(void *user_data, const XML_Char *s, int len)
|
||||
XmppParser::XmppParser():
|
||||
level(0),
|
||||
current_node(nullptr)
|
||||
{
|
||||
this->init_xml_parser();
|
||||
}
|
||||
|
||||
void XmppParser::init_xml_parser()
|
||||
{
|
||||
// Create the expat parser
|
||||
this->parser = XML_ParserCreateNS("UTF-8", ':');
|
||||
@@ -65,6 +70,16 @@ int XmppParser::parse(const int len, const bool is_final)
|
||||
return res;
|
||||
}
|
||||
|
||||
void XmppParser::reset()
|
||||
{
|
||||
XML_ParserFree(this->parser);
|
||||
this->init_xml_parser();
|
||||
if (this->current_node)
|
||||
delete this->current_node;
|
||||
this->current_node = nullptr;
|
||||
this->level = 0;
|
||||
}
|
||||
|
||||
void* XmppParser::get_buffer(const size_t size) const
|
||||
{
|
||||
return XML_GetBuffer(this->parser, static_cast<int>(size));
|
||||
|
||||
@@ -34,6 +34,10 @@ public:
|
||||
~XmppParser();
|
||||
|
||||
public:
|
||||
/**
|
||||
* Init the XML parser and install the callbacks
|
||||
*/
|
||||
void init_xml_parser();
|
||||
/**
|
||||
* Feed the parser with some XML data
|
||||
*/
|
||||
@@ -42,6 +46,10 @@ public:
|
||||
* Parse the data placed in the parser buffer
|
||||
*/
|
||||
int parse(const int size, const bool is_final);
|
||||
/**
|
||||
* Reset the parser, so it can be used from scratch afterward
|
||||
*/
|
||||
void reset();
|
||||
/**
|
||||
* Get a buffer provided by the xml parser.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user