From 196e01a2ca9f8aefbd3ac55eedc955f56d3d6428 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Fri, 13 Oct 2017 00:38:23 +0300 Subject: fixes #987 (more fixes for clients that don't support XEP-0115) --- protocols/JabberG/src/jabber_caps.cpp | 33 ++++++++++++++++++++++++++++----- protocols/JabberG/src/jabber_proto.h | 24 ++++++++++++------------ protocols/JabberG/src/jabber_thread.cpp | 25 ++++++++----------------- 3 files changed, 48 insertions(+), 34 deletions(-) diff --git a/protocols/JabberG/src/jabber_caps.cpp b/protocols/JabberG/src/jabber_caps.cpp index 3c716018a4..baf87bfce2 100755 --- a/protocols/JabberG/src/jabber_caps.cpp +++ b/protocols/JabberG/src/jabber_caps.cpp @@ -299,16 +299,39 @@ JabberCapsBits CJabberProto::GetResourceCapabilites(const wchar_t *jid, bool app return r->m_jcbCachedCaps; case 0: - CJabberIqInfo *pInfo = AddIQ(&CJabberProto::OnIqResultCapsDiscoInfo, JABBER_IQ_TYPE_GET, fullJid, JABBER_IQ_PARSE_FROM | JABBER_IQ_PARSE_CHILD_TAG_NODE); - pInfo->SetTimeout(JABBER_RESOURCE_CAPS_QUERY_TIMEOUT); - r->m_dwDiscoInfoRequestTime = pInfo->GetRequestTime(); - - m_ThreadInfo->send(XmlNodeIq(pInfo) << XQUERY(JABBER_FEAT_DISCO_INFO)); + RequestOldCapsInfo(r, fullJid); break; } return JABBER_RESOURCE_CAPS_IN_PROGRESS; } +void CJabberProto::RequestOldCapsInfo(pResourceStatus &r, const wchar_t *fullJid) +{ + CJabberIqInfo *pInfo = AddIQ(&CJabberProto::OnIqResultCapsDiscoInfo, JABBER_IQ_TYPE_GET, fullJid, JABBER_IQ_PARSE_FROM | JABBER_IQ_PARSE_CHILD_TAG_NODE); + pInfo->SetTimeout(JABBER_RESOURCE_CAPS_QUERY_TIMEOUT); + r->m_dwDiscoInfoRequestTime = pInfo->GetRequestTime(); + + m_ThreadInfo->send(XmlNodeIq(pInfo) << XQUERY(JABBER_FEAT_DISCO_INFO)); +} + +void CJabberProto::GetCachedCaps(const wchar_t *szNode, const wchar_t *szVer, pResourceStatus &r) +{ + CMStringA szName(FORMAT, "%S#%S", szNode, szVer); + ptrA szValue(db_get_sa(0, "JabberCaps", szName)); + if (szValue != 0) { + JSONNode root = JSONNode::parse(szValue); + if (root) { + CMStringW wszCaps = root["c"].as_mstring(); + r->m_pCaps = m_clientCapsManager.SetClientCaps(szNode, szVer, nullptr, _wtoi64(wszCaps)); + r->m_pCaps->m_szOs = mir_wstrdup(root["o"].as_mstring()); + r->m_pCaps->m_szOsVer = mir_wstrdup(root["ov"].as_mstring()); + r->m_pCaps->m_szSoft = mir_wstrdup(root["s"].as_mstring()); + r->m_pCaps->m_szSoftVer = mir_wstrdup(root["sv"].as_mstring()); + r->m_pCaps->m_szSoftMir = mir_wstrdup(root["sm"].as_mstring()); + } + } +} + ///////////////////////////////////////////////////////////////////////////////////////// // CJabberClientPartialCaps class diff --git a/protocols/JabberG/src/jabber_proto.h b/protocols/JabberG/src/jabber_proto.h index b6df7fb40e..ea113f5b3a 100755 --- a/protocols/JabberG/src/jabber_proto.h +++ b/protocols/JabberG/src/jabber_proto.h @@ -297,20 +297,22 @@ struct CJabberProto : public PROTO, public IJabberInterface //---- jabber_byte.c ----------------------------------------------------------------- - void __cdecl ByteSendThread(JABBER_BYTE_TRANSFER *jbt); - void __cdecl ByteReceiveThread(JABBER_BYTE_TRANSFER *jbt); + void __cdecl ByteSendThread(JABBER_BYTE_TRANSFER *jbt); + void __cdecl ByteReceiveThread(JABBER_BYTE_TRANSFER *jbt); - void IqResultProxyDiscovery(HXML iqNode, CJabberIqInfo *pInfo); - void ByteInitiateResult(HXML iqNode, CJabberIqInfo *pInfo); - void ByteSendViaProxy(JABBER_BYTE_TRANSFER *jbt); - int ByteSendParse(HNETLIBCONN hConn, JABBER_BYTE_TRANSFER *jbt, char* buffer, int datalen); - void IqResultStreamActivate(HXML iqNode, CJabberIqInfo *pInfo); - int ByteReceiveParse(HNETLIBCONN hConn, JABBER_BYTE_TRANSFER *jbt, char* buffer, int datalen); - int ByteSendProxyParse(HNETLIBCONN hConn, JABBER_BYTE_TRANSFER *jbt, char* buffer, int datalen); + void IqResultProxyDiscovery(HXML iqNode, CJabberIqInfo *pInfo); + void ByteInitiateResult(HXML iqNode, CJabberIqInfo *pInfo); + void ByteSendViaProxy(JABBER_BYTE_TRANSFER *jbt); + int ByteSendParse(HNETLIBCONN hConn, JABBER_BYTE_TRANSFER *jbt, char* buffer, int datalen); + void IqResultStreamActivate(HXML iqNode, CJabberIqInfo *pInfo); + int ByteReceiveParse(HNETLIBCONN hConn, JABBER_BYTE_TRANSFER *jbt, char* buffer, int datalen); + int ByteSendProxyParse(HNETLIBCONN hConn, JABBER_BYTE_TRANSFER *jbt, char* buffer, int datalen); //---- jabber_caps.cpp --------------------------------------------------------------- - void AddDefaultCaps(); + void AddDefaultCaps(); + void RequestOldCapsInfo(pResourceStatus &r, const wchar_t *fullJid); + void GetCachedCaps(const wchar_t *szNode, const wchar_t *szVer, class pResourceStatus &r); JabberCapsBits GetTotalJidCapabilites(const wchar_t *jid); JabberCapsBits GetResourceCapabilites(const wchar_t *jid, bool appendBestResource); @@ -579,8 +581,6 @@ struct CJabberProto : public PROTO, public IJabberInterface void MenuInit(void); void MenuUpdateSrmmIcon(JABBER_LIST_ITEM *item); - void AuthWorker(MCONTACT hContact, char* authReqType); - void UpdatePriorityMenu(int priority); HGENMENU m_hMenuPriorityRoot; diff --git a/protocols/JabberG/src/jabber_thread.cpp b/protocols/JabberG/src/jabber_thread.cpp index f2518a4e20..e8e0e2c381 100755 --- a/protocols/JabberG/src/jabber_thread.cpp +++ b/protocols/JabberG/src/jabber_thread.cpp @@ -1455,7 +1455,12 @@ void CJabberProto::OnProcessPresenceCapabilites(HXML node, pResourceStatus &r) bin2hexW(hashOut, _countof(hashOut), szHashOut); r->m_pCaps = m_clientCapsManager.GetPartialCaps(szNode, szHashOut); if (r->m_pCaps == nullptr) - r->m_pCaps = m_clientCapsManager.SetClientCaps(szNode, szHashOut, szVer, JABBER_RESOURCE_CAPS_NONE); + GetCachedCaps(szNode, szHashOut, r); + + if (r->m_pCaps == nullptr) { + r->m_pCaps = m_clientCapsManager.SetClientCaps(szNode, szHashOut, szVer, JABBER_RESOURCE_CAPS_UNINIT); + RequestOldCapsInfo(r, from); + } MCONTACT hContact = HContactFromJID(from); if (hContact) @@ -1463,22 +1468,8 @@ void CJabberProto::OnProcessPresenceCapabilites(HXML node, pResourceStatus &r) } else { r->m_pCaps = m_clientCapsManager.GetPartialCaps(szNode, szVer); - if (r->m_pCaps == nullptr) { - CMStringA szName(FORMAT, "%S#%S", szNode, szVer); - ptrA szValue(db_get_sa(0, "JabberCaps", szName)); - if (szValue != 0) { - JSONNode root = JSONNode::parse(szValue); - if (root) { - CMStringW wszCaps = root["c"].as_mstring(); - r->m_pCaps = m_clientCapsManager.SetClientCaps(szNode, szVer, nullptr, _wtoi64(wszCaps)); - r->m_pCaps->m_szOs = mir_wstrdup(root["o"].as_mstring()); - r->m_pCaps->m_szOsVer = mir_wstrdup(root["ov"].as_mstring()); - r->m_pCaps->m_szSoft = mir_wstrdup(root["s"].as_mstring()); - r->m_pCaps->m_szSoftVer = mir_wstrdup(root["sv"].as_mstring()); - r->m_pCaps->m_szSoftMir = mir_wstrdup(root["sm"].as_mstring()); - } - } - } + if (r->m_pCaps == nullptr) + GetCachedCaps(szNode, szVer, r); if (r->m_pCaps == nullptr) { r->m_pCaps = m_clientCapsManager.SetClientCaps(szNode, szVer, L"", JABBER_RESOURCE_CAPS_UNINIT); -- cgit v1.2.3