summaryrefslogtreecommitdiff
path: root/protocols/JabberG
diff options
context:
space:
mode:
authorGluzskiy Alexandr <sss@sss.chaoslab.ru>2018-03-27 00:06:33 +0300
committerGluzskiy Alexandr <sss@sss.chaoslab.ru>2018-03-27 00:07:47 +0300
commite7d937cd911e3971060293a66866020333db7590 (patch)
tree85e32f56ca280a7b84c5f8573ea4d71ac7fc5c36 /protocols/JabberG
parente7111b4836e101d0bcd7f0f0d3410ce9a072dd5f (diff)
protocols: jabber: xep-0198
- implemented client to server acks
Diffstat (limited to 'protocols/JabberG')
-rwxr-xr-xprotocols/JabberG/src/jabber_iqid.cpp5
-rwxr-xr-xprotocols/JabberG/src/jabber_opt.cpp2
-rwxr-xr-xprotocols/JabberG/src/jabber_proto.cpp5
-rwxr-xr-xprotocols/JabberG/src/jabber_proto.h7
-rwxr-xr-xprotocols/JabberG/src/jabber_thread.cpp51
5 files changed, 52 insertions, 18 deletions
diff --git a/protocols/JabberG/src/jabber_iqid.cpp b/protocols/JabberG/src/jabber_iqid.cpp
index 1fad5dcebd..83febdd7ed 100755
--- a/protocols/JabberG/src/jabber_iqid.cpp
+++ b/protocols/JabberG/src/jabber_iqid.cpp
@@ -213,6 +213,11 @@ void CJabberProto::OnLoggedIn()
setString("LastLoggedServer", m_ThreadInfo->conn.server);
m_pepServices.ResetPublishAll();
+ if (m_bEnableStreamMgmt)
+ {
+ if (m_bStrmMgmtPendingEnable && !m_bStrmMgmtEnabled)
+ EnableStrmMgmt();
+ }
}
diff --git a/protocols/JabberG/src/jabber_opt.cpp b/protocols/JabberG/src/jabber_opt.cpp
index 0499a5f1d0..32a44d95f9 100755
--- a/protocols/JabberG/src/jabber_opt.cpp
+++ b/protocols/JabberG/src/jabber_opt.cpp
@@ -813,7 +813,7 @@ public:
m_otvOptions.AddOption(LPGENW("Security") L"/" LPGENW("Show information about operating system in version replies"), m_proto->m_bShowOSVersion);
m_otvOptions.AddOption(LPGENW("Security") L"/" LPGENW("Accept only in band incoming filetransfers (don't disclose own IP)"), m_proto->m_bBsOnlyIBB);
m_otvOptions.AddOption(LPGENW("Security") L"/" LPGENW("Accept HTTP Authentication requests (XEP-0070)"), m_proto->m_bAcceptHttpAuth);
- m_otvOptions.AddOption(LPGENW("Security") L"/" LPGENW("Use OMEMO encryption for messages if possible (Basic support, no gui)"), m_proto->m_bUseOMEMO);
+ m_otvOptions.AddOption(LPGENW("Security") L"/" LPGENW("Use OMEMO encryption for messages if possible (XEP-0384) (Basic support, no gui)"), m_proto->m_bUseOMEMO);
}
void OnInitDialog()
diff --git a/protocols/JabberG/src/jabber_proto.cpp b/protocols/JabberG/src/jabber_proto.cpp
index f4de9de9d0..5957cfd772 100755
--- a/protocols/JabberG/src/jabber_proto.cpp
+++ b/protocols/JabberG/src/jabber_proto.cpp
@@ -73,6 +73,8 @@ CJabberProto::CJabberProto(const char *aProtoName, const wchar_t *aUserName) :
m_uEnabledFeatCapsDynamic(0),
m_bStrmMgmtPendingEnable(false),
m_bStrmMgmtEnabled(false),
+ m_bStrmMgmtResumeSupported(false),
+ m_sStrmMgmtResumeId(nullptr),
m_bBsDirect(this, "BsDirect", TRUE),
m_bAllowVersionRequests(this, "m_bAllowVersionRequests", TRUE),
@@ -257,6 +259,9 @@ CJabberProto::~CJabberProto()
mir_free(it->szDescription);
delete it;
}
+
+ if (m_sStrmMgmtResumeId)
+ mir_free(m_sStrmMgmtResumeId);
}
////////////////////////////////////////////////////////////////////////////////////////
diff --git a/protocols/JabberG/src/jabber_proto.h b/protocols/JabberG/src/jabber_proto.h
index b768f75df9..ab44f9f020 100755
--- a/protocols/JabberG/src/jabber_proto.h
+++ b/protocols/JabberG/src/jabber_proto.h
@@ -284,9 +284,10 @@ struct CJabberProto : public PROTO<CJabberProto>, public IJabberInterface
int m_nIqIdRegGetReg;
int m_nIqIdRegSetReg;
- //xep-0198 handled nodes count
- uint32_t m_nStrmMgmtSrvHCount, m_nStrmMgmtLocalHCount, m_nStrmMgmtLocalSCount;
- bool m_bStrmMgmtPendingEnable, m_bStrmMgmtEnabled;
+ //xep-0198 related vars
+ uint32_t m_nStrmMgmtSrvHCount, m_nStrmMgmtLocalHCount, m_nStrmMgmtLocalSCount, m_nStrmMgmtResumeMaxSeconds;
+ bool m_bStrmMgmtPendingEnable, m_bStrmMgmtEnabled, m_bStrmMgmtResumeSupported;
+ wchar_t *m_sStrmMgmtResumeId;
int m_nSDBrowseMode;
DWORD m_dwSDLastRefresh;
diff --git a/protocols/JabberG/src/jabber_thread.cpp b/protocols/JabberG/src/jabber_thread.cpp
index d95fc2f91b..c274d62ed1 100755
--- a/protocols/JabberG/src/jabber_thread.cpp
+++ b/protocols/JabberG/src/jabber_thread.cpp
@@ -519,6 +519,13 @@ recvRest:
m_iDesiredStatus = m_iStatus = ID_STATUS_OFFLINE;
ProtoBroadcastAck(0, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)oldStatus, m_iStatus);
+ //TODO: following should be redone once resumption implemented
+ //reset state of stream management
+ m_bStrmMgmtEnabled = false;
+ m_bStrmMgmtPendingEnable = false;
+ //reset stream management h counters
+ m_nStrmMgmtLocalHCount = m_nStrmMgmtLocalSCount = m_nStrmMgmtSrvHCount = 0;
+
// Set all contacts to offline
debugLogA("1");
for (auto &hContact : AccContacts())
@@ -663,8 +670,6 @@ void CJabberProto::PerformAuthentication(ThreadData *info)
info->send(XmlNode(L"auth", _A2T(request)) << XATTR(L"xmlns", L"urn:ietf:params:xml:ns:xmpp-sasl")
<< XATTR(L"mechanism", _A2T(auth->getName())));
mir_free(request);
- if (m_bEnableStreamMgmt && m_bStrmMgmtPendingEnable)
- EnableStrmMgmt();
}
/////////////////////////////////////////////////////////////////////////////////////////
@@ -742,7 +747,7 @@ void CJabberProto::OnProcessFeatures(HXML node, ThreadData *info)
{
if (!mir_wstrcmp(XmlGetAttrValue(n, L"xmlns"), L"urn:xmpp:sm:3")) //we work only with version 3 or higher of sm
{
- if (!(info->auth))
+ if (!m_bJabberOnline)
m_bStrmMgmtPendingEnable = true;
else
EnableStrmMgmt();
@@ -798,7 +803,18 @@ void CJabberProto::OnProcessEnabled(HXML node, ThreadData * /*info*/)
if (m_bEnableStreamMgmt && !mir_wstrcmp(XmlGetAttrValue(node, L"xmlns"), L"urn:xmpp:sm:3"))
{
m_bStrmMgmtEnabled = true;
- //TODO: handle 'id', 'resume' attrs
+ auto val = XmlGetAttrValue(node, L"max");
+ m_nStrmMgmtResumeMaxSeconds = _wtoi(val);
+ val = XmlGetAttrValue(node, L"resume");
+ if (mir_wstrcmp(val, L"true") || mir_wstrcmp(val, L"1"))
+ m_bStrmMgmtResumeSupported = true;
+
+ if (m_sStrmMgmtResumeId)
+ mir_free(m_sStrmMgmtResumeId);
+ m_sStrmMgmtResumeId = mir_wstrdup(XmlGetAttrValue(node, L"id"));
+ m_nStrmMgmtLocalHCount = 0;
+ m_nStrmMgmtSrvHCount = 0; //?
+ m_nStrmMgmtLocalSCount = 0;
}
}
@@ -806,7 +822,13 @@ void CJabberProto::OnProcessSMa(HXML node, ThreadData * /*info*/)
{
if (!mir_wstrcmp(XmlGetAttrValue(node, L"xmlns"), L"urn:xmpp:sm:3"))
{
- //TODO:
+ auto val = XmlGetAttrValue(node, L"h");
+ uint32_t iVal = _wtoi(val);
+ m_nStrmMgmtSrvHCount = iVal;
+ if ((m_nStrmMgmtLocalSCount - m_nStrmMgmtSrvHCount) > 0)
+ {
+ //TODO: server have not handled some of sent nodes, handle situation
+ }
}
}
@@ -814,7 +836,10 @@ void CJabberProto::OnProcessSMr(HXML node, ThreadData * /*info*/)
{
if (!mir_wstrcmp(XmlGetAttrValue(node, L"xmlns"), L"urn:xmpp:sm:3"))
{
- //TODO: reply with ack with currently handled nodes for session
+ XmlNode enable_sm(L"a");
+ XmlAddAttr(enable_sm, L"xmlns", L"urn:xmpp:sm:3");
+ xmlAddAttrInt(enable_sm, L"h", m_nStrmMgmtLocalHCount);
+ m_ThreadInfo->send(enable_sm);
}
}
@@ -894,7 +919,7 @@ void CJabberProto::OnProcessProtocol(HXML node, ThreadData *info)
{
OnConsoleProcessXml(node, JCPF_IN);
- if (m_bEnableStreamMgmt && m_bStrmMgmtEnabled)
+ if (m_bEnableStreamMgmt && m_bStrmMgmtEnabled && mir_wstrcmp(XmlGetName(node), L"r") && mir_wstrcmp(XmlGetName(node), L"a")) //TODO: something better
m_nStrmMgmtLocalHCount++;
if (!mir_wstrcmp(XmlGetName(node), L"proceed"))
OnProcessProceed(node, info);
@@ -2056,9 +2081,6 @@ void CJabberProto::EnableStrmMgmt()
XmlAddAttr(enable_sm, L"xmlns", L"urn:xmpp:sm:3");
XmlAddAttr(enable_sm, L"resume", L"true"); //enable resumption (most useful part of this xep)
m_ThreadInfo->send(enable_sm);
- m_nStrmMgmtLocalHCount = 0;
- m_nStrmMgmtSrvHCount = 0; //?
- m_nStrmMgmtLocalSCount = 0;
}
@@ -2145,9 +2167,6 @@ int ThreadData::send(char* buf, int bufsize)
ReleaseMutex(iomutex);
- if (proto->m_bEnableStreamMgmt && proto->m_bStrmMgmtEnabled)
- proto->m_nStrmMgmtLocalSCount_incr();
-
return result;
}
@@ -2185,6 +2204,10 @@ int ThreadData::send(HXML node)
xmlFree(str);
if (proto->m_bEnableStreamMgmt && proto->m_bStrmMgmtEnabled)
- proto->m_nStrmMgmtLocalSCount_incr();
+ {
+ auto name = XmlGetName(node);
+ if(mir_wstrcmp(name, L"a") && mir_wstrcmp(name, L"r"))
+ proto->m_nStrmMgmtLocalSCount_incr();
+ }
return result;
}