From 75b344c4c8b4148602279b51bc2cc5d45b03c324 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Fri, 10 Nov 2017 12:26:50 +0300 Subject: more strict version of caps reading --- protocols/JabberG/src/jabber_caps.cpp | 92 +++++++++++++++++----------------- protocols/JabberG/src/jabber_misc.cpp | 21 ++++---- protocols/JabberG/src/jabber_proto.cpp | 2 +- protocols/JabberG/src/jabber_proto.h | 5 +- protocols/JabberG/src/jabber_util.cpp | 12 ++++- 5 files changed, 68 insertions(+), 64 deletions(-) (limited to 'protocols/JabberG') diff --git a/protocols/JabberG/src/jabber_caps.cpp b/protocols/JabberG/src/jabber_caps.cpp index 801d8dacd7..f238b075b8 100755 --- a/protocols/JabberG/src/jabber_caps.cpp +++ b/protocols/JabberG/src/jabber_caps.cpp @@ -119,7 +119,9 @@ void CJabberProto::AddDefaultCaps() void CJabberProto::OnIqResultCapsDiscoInfo(HXML, CJabberIqInfo *pInfo) { - pResourceStatus r((JABBER_RESOURCE_STATUS*)pInfo->GetUserData()); + pResourceStatus r(ResourceInfoFromJID(pInfo->GetFrom())); + if (r == nullptr) + return; HXML query = pInfo->GetChildNode(); if (pInfo->GetIqType() == JABBER_IQ_TYPE_RESULT && query) { @@ -139,60 +141,56 @@ void CJabberProto::OnIqResultCapsDiscoInfo(HXML, CJabberIqInfo *pInfo) } } - // no XEP-0115 support? - if (r) { - CJabberClientPartialCaps *pCaps = r->m_pCaps; - if (pCaps == nullptr) { - r->m_jcbCachedCaps = jcbCaps; - r->m_dwDiscoInfoRequestTime = -1; - return; - } + // no XEP-0115 support? store info & exit + CJabberClientPartialCaps *pCaps = r->m_pCaps; + if (pCaps == nullptr) { + r->m_jcbCachedCaps = jcbCaps; + r->m_dwDiscoInfoRequestTime = -1; + return; + } - HXML identity; - for (int i = 1; (identity = XmlGetNthChild(query, L"identity", i)) != nullptr; i++) { - const wchar_t *identityName = XmlGetAttrValue(identity, L"name"); - if (identityName) - pCaps->SetVer(identityName); - } + HXML identity; + for (int i = 1; (identity = XmlGetNthChild(query, L"identity", i)) != nullptr; i++) { + const wchar_t *identityName = XmlGetAttrValue(identity, L"name"); + if (identityName) + pCaps->SetVer(identityName); + } - HXML xform; - for (int i = 1; (xform = XmlGetNthChild(query, L"x", i)) != nullptr; i++) { - wchar_t *szFormTypeValue = XPath(xform, L"field[@var='FORM_TYPE']/value"); - if (!mir_wstrcmp(szFormTypeValue, L"urn:xmpp:dataforms:softwareinfo")) { - JSONNode root; - if (pCaps->m_szOs = mir_wstrdup(XPath(xform, L"field[@var='os']/value"))) - root.push_back(JSONNode("o", _T2A(pCaps->m_szOs).get())); - if (pCaps->m_szOsVer = mir_wstrdup(XPath(xform, L"field[@var='os_version']/value"))) - root.push_back(JSONNode("ov", _T2A(pCaps->m_szOsVer).get())); - if (pCaps->m_szSoft = mir_wstrdup(XPath(xform, L"field[@var='software']/value"))) - root.push_back(JSONNode("s", _T2A(pCaps->m_szSoft).get())); - if (pCaps->m_szSoftVer = mir_wstrdup(XPath(xform, L"field[@var='software_version']/value"))) - root.push_back(JSONNode("sv", _T2A(pCaps->m_szSoftVer).get())); - if (pCaps->m_szSoftMir = mir_wstrdup(XPath(xform, L"field[@var='x-miranda-core-version']/value"))) - root.push_back(JSONNode("sm", _T2A(pCaps->m_szSoftMir).get())); - root.push_back(JSONNode("c", CMStringA(FORMAT, "%lld", jcbCaps))); - - CMStringA szName(FORMAT, "%S#%S", pCaps->GetNode(), pCaps->GetHash()); - json_string szValue = root.write(); - db_set_s(0, "JabberCaps", szName, szValue.c_str()); - } + HXML xform; + for (int i = 1; (xform = XmlGetNthChild(query, L"x", i)) != nullptr; i++) { + wchar_t *szFormTypeValue = XPath(xform, L"field[@var='FORM_TYPE']/value"); + if (!mir_wstrcmp(szFormTypeValue, L"urn:xmpp:dataforms:softwareinfo")) { + JSONNode root; + if (pCaps->m_szOs = mir_wstrdup(XPath(xform, L"field[@var='os']/value"))) + root.push_back(JSONNode("o", _T2A(pCaps->m_szOs).get())); + if (pCaps->m_szOsVer = mir_wstrdup(XPath(xform, L"field[@var='os_version']/value"))) + root.push_back(JSONNode("ov", _T2A(pCaps->m_szOsVer).get())); + if (pCaps->m_szSoft = mir_wstrdup(XPath(xform, L"field[@var='software']/value"))) + root.push_back(JSONNode("s", _T2A(pCaps->m_szSoft).get())); + if (pCaps->m_szSoftVer = mir_wstrdup(XPath(xform, L"field[@var='software_version']/value"))) + root.push_back(JSONNode("sv", _T2A(pCaps->m_szSoftVer).get())); + if (pCaps->m_szSoftMir = mir_wstrdup(XPath(xform, L"field[@var='x-miranda-core-version']/value"))) + root.push_back(JSONNode("sm", _T2A(pCaps->m_szSoftMir).get())); + root.push_back(JSONNode("c", CMStringA(FORMAT, "%lld", jcbCaps))); + + CMStringA szName(FORMAT, "%S#%S", pCaps->GetNode(), pCaps->GetHash()); + json_string szValue = root.write(); + db_set_s(0, "JabberCaps", szName, szValue.c_str()); } + } - pCaps->SetCaps(jcbCaps, pInfo->GetIqId()); + pCaps->SetCaps(jcbCaps, pInfo->GetIqId()); - UpdateMirVer(pInfo->GetHContact(), r); - } + UpdateMirVer(pInfo->GetHContact(), r); JabberUserInfoUpdate(pInfo->GetHContact()); } else { - if (r) { - if (!r->m_pCaps) { // no XEP-0115 support? - r->m_jcbCachedCaps = JABBER_RESOURCE_CAPS_NONE; - r->m_dwDiscoInfoRequestTime = -1; - } - else r->m_pCaps->SetCaps(JABBER_RESOURCE_CAPS_ERROR); + if (!r->m_pCaps) { // no XEP-0115 support? + r->m_jcbCachedCaps = JABBER_RESOURCE_CAPS_NONE; + r->m_dwDiscoInfoRequestTime = -1; } + else r->m_pCaps->SetCaps(JABBER_RESOURCE_CAPS_ERROR); } } @@ -257,7 +255,7 @@ JabberCapsBits CJabberProto::GetResourceCapabilities(const wchar_t *jid, pResour if (jcbMainCaps == JABBER_RESOURCE_CAPS_UNINIT) { // send disco#info query - CJabberIqInfo *pInfo = AddIQ(&CJabberProto::OnIqResultCapsDiscoInfo, JABBER_IQ_TYPE_GET, jid, JABBER_IQ_PARSE_FROM | JABBER_IQ_PARSE_CHILD_TAG_NODE, -1, r); + CJabberIqInfo *pInfo = AddIQ(&CJabberProto::OnIqResultCapsDiscoInfo, JABBER_IQ_TYPE_GET, jid, JABBER_IQ_PARSE_FROM | JABBER_IQ_PARSE_CHILD_TAG_NODE); pInfo->SetTimeout(JABBER_RESOURCE_CAPS_QUERY_TIMEOUT); pCaps->SetCaps(JABBER_RESOURCE_CAPS_IN_PROGRESS, pInfo->GetIqId()); r->m_dwDiscoInfoRequestTime = pInfo->GetRequestTime(); @@ -311,7 +309,7 @@ JabberCapsBits CJabberProto::GetResourceCapabilities(const wchar_t *jid, pResour 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, -1, r); + 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(); diff --git a/protocols/JabberG/src/jabber_misc.cpp b/protocols/JabberG/src/jabber_misc.cpp index 7ade567dec..91d7955c7e 100755 --- a/protocols/JabberG/src/jabber_misc.cpp +++ b/protocols/JabberG/src/jabber_misc.cpp @@ -277,17 +277,13 @@ void CJabberProto::UpdateMirVer(JABBER_LIST_ITEM *item) debugLogW(L"JabberUpdateMirVer: for jid %s", item->jid); - pResourceStatus p(nullptr); if (item->resourceMode == RSMODE_LASTSEEN) - p = item->m_pLastSeenResource; + UpdateMirVer(hContact, pResourceStatus(item->m_pLastSeenResource)); else if (item->resourceMode == RSMODE_MANUAL) - p = item->m_pManualResource; - - if (p) - UpdateMirVer(hContact, p); + UpdateMirVer(hContact, pResourceStatus(item->m_pManualResource)); } -void CJabberProto::FormatMirVer(pResourceStatus &resource, CMStringW &res) +void CJabberProto::FormatMirVer(const pResourceStatus &resource, CMStringW &res) { res.Empty(); if (resource == nullptr) @@ -338,10 +334,13 @@ void CJabberProto::FormatMirVer(pResourceStatus &resource, CMStringW &res) res.AppendFormat(L" [%s]", resource->m_tszResourceName); } -void CJabberProto::UpdateMirVer(MCONTACT hContact, pResourceStatus &resource) +void CJabberProto::UpdateMirVer(MCONTACT hContact, const pResourceStatus &r) { + if (r == nullptr) + return; + CMStringW tszMirVer; - FormatMirVer(resource, tszMirVer); + FormatMirVer(r, tszMirVer); if (!tszMirVer.IsEmpty()) setWString(hContact, "MirVer", tszMirVer); @@ -350,8 +349,8 @@ void CJabberProto::UpdateMirVer(MCONTACT hContact, pResourceStatus &resource) return; wchar_t szFullJid[JABBER_MAX_JID_LEN]; - if (resource->m_tszResourceName && !wcschr(jid, '/')) - mir_snwprintf(szFullJid, L"%s/%s", jid, resource->m_tszResourceName); + if (r->m_tszResourceName && !wcschr(jid, '/')) + mir_snwprintf(szFullJid, L"%s/%s", jid, r->m_tszResourceName); else mir_wstrncpy(szFullJid, jid, _countof(szFullJid)); setWString(hContact, DBSETTING_DISPLAY_UID, szFullJid); diff --git a/protocols/JabberG/src/jabber_proto.cpp b/protocols/JabberG/src/jabber_proto.cpp index 47823f8003..6b6c5b9adc 100755 --- a/protocols/JabberG/src/jabber_proto.cpp +++ b/protocols/JabberG/src/jabber_proto.cpp @@ -598,7 +598,7 @@ int __cdecl CJabberProto::GetInfo(MCONTACT hContact, int /*infoType*/) mir_snwprintf(tmp, L"%s/%s", szBareJid, r->m_tszResourceName); if (r->m_jcbCachedCaps & JABBER_CAPS_DISCO_INFO) { - XmlNodeIq iq5(AddIQ(&CJabberProto::OnIqResultCapsDiscoInfo, JABBER_IQ_TYPE_GET, tmp, JABBER_IQ_PARSE_FROM | JABBER_IQ_PARSE_CHILD_TAG_NODE | JABBER_IQ_PARSE_HCONTACT, -1, r)); + XmlNodeIq iq5(AddIQ(&CJabberProto::OnIqResultCapsDiscoInfo, JABBER_IQ_TYPE_GET, tmp, JABBER_IQ_PARSE_FROM | JABBER_IQ_PARSE_CHILD_TAG_NODE | JABBER_IQ_PARSE_HCONTACT)); iq5 << XQUERY(JABBER_FEAT_DISCO_INFO); m_ThreadInfo->send(iq5); } diff --git a/protocols/JabberG/src/jabber_proto.h b/protocols/JabberG/src/jabber_proto.h index 963a385232..4149f80080 100755 --- a/protocols/JabberG/src/jabber_proto.h +++ b/protocols/JabberG/src/jabber_proto.h @@ -124,7 +124,6 @@ struct CJabberProto : public PROTO, public IJabberInterface int __cdecl OnOptionsInit(WPARAM, LPARAM); int __cdecl OnPreShutdown(WPARAM, LPARAM); int __cdecl OnPrebuildContactMenu(WPARAM, LPARAM); - int __cdecl OnMsgUserTyping(WPARAM, LPARAM); int __cdecl OnProcessSrmmIconClick(WPARAM, LPARAM); int __cdecl OnProcessSrmmEvent(WPARAM, LPARAM); int __cdecl OnReloadIcons(WPARAM, LPARAM); @@ -592,9 +591,9 @@ struct CJabberProto : public PROTO, public IJabberInterface void GetAvatarFileName(MCONTACT hContact, wchar_t* pszDest, size_t cbLen); void ResolveTransportNicks(const wchar_t *jid); void SetServerStatus(int iNewStatus); - void FormatMirVer(pResourceStatus &resource, CMStringW&); + void FormatMirVer(const pResourceStatus &resource, CMStringW&); void UpdateMirVer(JABBER_LIST_ITEM *item); - void UpdateMirVer(MCONTACT hContact, pResourceStatus &resource); + void UpdateMirVer(MCONTACT hContact, const pResourceStatus&); void UpdateSubscriptionInfo(MCONTACT hContact, JABBER_LIST_ITEM *item); void SetContactOfflineStatus(MCONTACT hContact); void InitPopups(void); diff --git a/protocols/JabberG/src/jabber_util.cpp b/protocols/JabberG/src/jabber_util.cpp index 38b4d0bcc4..2ec6c71e85 100755 --- a/protocols/JabberG/src/jabber_util.cpp +++ b/protocols/JabberG/src/jabber_util.cpp @@ -83,13 +83,21 @@ pResourceStatus CJabberProto::ResourceInfoFromJID(const wchar_t *jid) if (jid == nullptr) return nullptr; - JABBER_LIST_ITEM *item = ListGetItemPtr(LIST_VCARD_TEMP, jid); + const wchar_t *p = wcschr(jid, '/'); + + JABBER_LIST_ITEM *item = nullptr; + if (p) { + wchar_t szJid[JABBER_MAX_JID_LEN]; + JabberStripJid(jid, szJid, _countof(szJid)); + item = ListGetItemPtr(LIST_CHATROOM, szJid); + } + if (item == nullptr) + item = ListGetItemPtr(LIST_VCARD_TEMP, jid); if (item == nullptr) item = ListGetItemPtr(LIST_ROSTER, jid); if (item == nullptr) return nullptr; - const wchar_t *p = wcschr(jid, '/'); if (p == nullptr) return item->getTemp(); -- cgit v1.2.3