From dbc713b6a5308cd964def21eec6913177754bbd2 Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Fri, 6 Apr 2018 09:56:43 +0300 Subject: protocols: jabber: xep-0198 - a bit improoved logic - implemented "keep-alive" like ack request (currently sema logick as ping, should also work with ping disabled, ping is not necessary if strm_mgmt enabled) --- protocols/JabberG/src/jabber_strm_mgmt.cpp | 26 +++++++++++++++----------- protocols/JabberG/src/jabber_strm_mgmt.h | 1 + protocols/JabberG/src/jabber_thread.cpp | 23 +++++++++++++++-------- 3 files changed, 31 insertions(+), 19 deletions(-) diff --git a/protocols/JabberG/src/jabber_strm_mgmt.cpp b/protocols/JabberG/src/jabber_strm_mgmt.cpp index b05b0b3cbb..d2a591f4ea 100755 --- a/protocols/JabberG/src/jabber_strm_mgmt.cpp +++ b/protocols/JabberG/src/jabber_strm_mgmt.cpp @@ -150,11 +150,9 @@ void strm_mgmt::OnProcessFailed(HXML node, ThreadData * /*info*/) //used failed if (!mir_wstrcmp(XmlGetAttrValue(node, L"xmlns"), L"urn:xmpp:sm:3")) { m_bStrmMgmtEnabled = false; - if (XmlGetChild(node, L"item-not-found")) //session timeout - { - bSessionResumed = false; - EnableStrmMgmt(); //resume failed, try to enable strm_mgmt instead - } + bSessionResumed = false; + m_sStrmMgmtResumeId.clear(); + EnableStrmMgmt(); //resume failed, try to enable strm_mgmt instead } } @@ -186,11 +184,7 @@ void strm_mgmt::HandleOutgoingNode(HXML node) m_nStrmMgmtLocalSCount++; NodeCache.push_back(xmlCopyNode(node)); if ((m_nStrmMgmtLocalSCount - m_nStrmMgmtSrvHCount) >= m_nStrmMgmtCacheSize) - { - XmlNode enable_sm(L"r"); - XmlAddAttr(enable_sm, L"xmlns", L"urn:xmpp:sm:3"); - proto->m_ThreadInfo->send_no_strm_mgmt(enable_sm); - } + RequestAck(); } void strm_mgmt::OnDisconnect() @@ -223,7 +217,7 @@ void strm_mgmt::EnableStrmMgmt() proto->m_ThreadInfo->send(enable_sm); m_nStrmMgmtLocalSCount = 1; //TODO: this MUST be 0, i have bug somewhere. } - else + else //resume session { XmlNode enable_sm(L"resume"); XmlAddAttr(enable_sm, L"xmlns", L"urn:xmpp:sm:3"); @@ -243,6 +237,16 @@ void strm_mgmt::SendAck() proto->m_ThreadInfo->send_no_strm_mgmt(enable_sm); } +void strm_mgmt::RequestAck() +{ + if (m_bStrmMgmtEnabled) + { + XmlNode enable_sm(L"r"); + XmlAddAttr(enable_sm, L"xmlns", L"urn:xmpp:sm:3"); + proto->m_ThreadInfo->send_no_strm_mgmt(enable_sm); + } +} + bool strm_mgmt::IsSessionResumed() { return bSessionResumed; diff --git a/protocols/JabberG/src/jabber_strm_mgmt.h b/protocols/JabberG/src/jabber_strm_mgmt.h index b59e3a332b..1791afd8eb 100755 --- a/protocols/JabberG/src/jabber_strm_mgmt.h +++ b/protocols/JabberG/src/jabber_strm_mgmt.h @@ -53,6 +53,7 @@ public: void CheckState(); void OnDisconnect(); void SendAck(); + void RequestAck(); bool IsSessionResumed(); }; diff --git a/protocols/JabberG/src/jabber_thread.cpp b/protocols/JabberG/src/jabber_thread.cpp index 243eb3e39f..7199b5181c 100755 --- a/protocols/JabberG/src/jabber_thread.cpp +++ b/protocols/JabberG/src/jabber_thread.cpp @@ -421,15 +421,22 @@ LBL_FatalError: int nSelRes = Netlib_Select(&nls); if (nSelRes == -1) // error break; - else if (nSelRes == 0 && m_bSendKeepAlive) { - if (info.jabberServerCaps & JABBER_CAPS_PING) { - CJabberIqInfo *pInfo = AddIQ(&CJabberProto::OnPingReply, JABBER_IQ_TYPE_GET, nullptr, 0, -1, this); - pInfo->SetTimeout(m_iConnectionKeepAliveTimeout); - info.send(XmlNodeIq(pInfo) << XATTR(L"from", info.fullJID) << XCHILDNS(L"ping", JABBER_FEAT_PING)); + else if (nSelRes == 0) + { + if (m_bSendKeepAlive) + { + if (info.jabberServerCaps & JABBER_CAPS_PING) { + CJabberIqInfo *pInfo = AddIQ(&CJabberProto::OnPingReply, JABBER_IQ_TYPE_GET, nullptr, 0, -1, this); + pInfo->SetTimeout(m_iConnectionKeepAliveTimeout); + info.send(XmlNodeIq(pInfo) << XATTR(L"from", info.fullJID) << XCHILDNS(L"ping", JABBER_FEAT_PING)); + } } - else info.send(" \t "); - continue; - } } + else + info.send(" \t "); //TODO: why do we need this ? + if (m_bEnableStreamMgmt) + m_StrmMgmt.RequestAck(); + } + } int recvResult = info.recv(info.buffer + datalen, jabberNetworkBufferSize - datalen); debugLogA("recvResult = %d", recvResult); -- cgit v1.2.3