From 3562b7632f2f567d5da082438460b953a36ec46b Mon Sep 17 00:00:00 2001 From: George Hazan Date: Mon, 23 Jul 2018 15:19:44 +0300 Subject: Jabber: - unused function JabberGetPictureType inlined; - fixes #1509 (Miranda receive duplicate incoming messages if contact is not in roster Jabber); - code cleaning; --- protocols/JabberG/src/jabber_byte.cpp | 2 +- protocols/JabberG/src/jabber_chat.cpp | 7 ++++--- protocols/JabberG/src/jabber_iqid.cpp | 9 ++++++++- protocols/JabberG/src/jabber_thread.cpp | 27 +++++++++++++++++---------- protocols/JabberG/src/jabber_util.cpp | 12 ------------ protocols/JabberG/src/stdafx.h | 32 +++++++++++++++----------------- 6 files changed, 45 insertions(+), 44 deletions(-) (limited to 'protocols') diff --git a/protocols/JabberG/src/jabber_byte.cpp b/protocols/JabberG/src/jabber_byte.cpp index edba68b505..c192613346 100644 --- a/protocols/JabberG/src/jabber_byte.cpp +++ b/protocols/JabberG/src/jabber_byte.cpp @@ -219,7 +219,7 @@ void CJabberProto::ByteSendThread(JABBER_BYTE_TRANSFER *jbt) jbt->hSendEvent = CreateEvent(nullptr, FALSE, FALSE, nullptr); query << XCHILD(L"streamhost") << XATTR(L"jid", m_ThreadInfo->fullJID) << XATTR(L"host", _A2T(localAddr)) << XATTRI(L"port", nlb.wPort); - NETLIBIPLIST* ihaddr = Netlib_GetMyIp(true); + NETLIBIPLIST *ihaddr = Netlib_GetMyIp(true); for (unsigned i=0; i < ihaddr->cbNum; i++) if (mir_strcmp(localAddr, ihaddr->szIp[i])) query << XCHILD(L"streamhost") << XATTR(L"jid", m_ThreadInfo->fullJID) << XATTR(L"host", _A2T(ihaddr->szIp[i])) << XATTRI(L"port", nlb.wPort); diff --git a/protocols/JabberG/src/jabber_chat.cpp b/protocols/JabberG/src/jabber_chat.cpp index d587c3a03b..8869d206db 100644 --- a/protocols/JabberG/src/jabber_chat.cpp +++ b/protocols/JabberG/src/jabber_chat.cpp @@ -68,13 +68,14 @@ struct TRoleOrAffiliationInfo if (me->m_affiliation == AFFILIATION_OWNER) return TRUE; if (me == him) return FALSE; if (me->m_affiliation <= him->m_affiliation) return FALSE; - if (me->m_role < this->min_role) return FALSE; - if (me->m_affiliation < this->min_affiliation) return FALSE; + if (me->m_role < min_role) return FALSE; + if (me->m_affiliation < min_affiliation) return FALSE; return TRUE; } + void translate() { - this->title = TranslateW(this->title_en); + title = TranslateW(title_en); } }; diff --git a/protocols/JabberG/src/jabber_iqid.cpp b/protocols/JabberG/src/jabber_iqid.cpp index 099b8b8d7f..af2f459959 100755 --- a/protocols/JabberG/src/jabber_iqid.cpp +++ b/protocols/JabberG/src/jabber_iqid.cpp @@ -598,7 +598,14 @@ void CJabberProto::OnIqResultGetVcardPhoto(HXML n, MCONTACT hContact, bool &hasP if (buffer == nullptr) return; - const wchar_t *szPicType = JabberGetPictureType(n, buffer); + const wchar_t *szPicType = nullptr; + if (const wchar_t *ptszType = XmlGetText(XmlGetChild(n, "TYPE"))) + if (ProtoGetAvatarFormatByMimeType(ptszType) != PA_FORMAT_UNKNOWN) + szPicType = ptszType; + + if (szPicType == nullptr) + szPicType = ProtoGetAvatarMimeType(ProtoGetBufferFormat(buffer)); + if (szPicType == nullptr) return; diff --git a/protocols/JabberG/src/jabber_thread.cpp b/protocols/JabberG/src/jabber_thread.cpp index 955ec35500..de4f25f910 100755 --- a/protocols/JabberG/src/jabber_thread.cpp +++ b/protocols/JabberG/src/jabber_thread.cpp @@ -1065,15 +1065,20 @@ MCONTACT CJabberProto::CreateTemporaryContact(const wchar_t *szJid, JABBER_LIST_ void CJabberProto::OnProcessMessage(HXML node, ThreadData *info) { - HXML xNode, n; - if (!XmlGetName(node) || mir_wstrcmp(XmlGetName(node), L"message")) return; - const wchar_t *from, *type = XmlGetAttrValue(node, L"type"); + const wchar_t *from, *to, *type = XmlGetAttrValue(node, L"type"); if ((from = XmlGetAttrValue(node, L"from")) == nullptr) return; + if ((to = XmlGetAttrValue(node, L"to")) == nullptr) + return; + if (mir_wstrcmpi(to, m_szJabberJID) && mir_wstrcmpi(to, info->fullJID)) { + debugLogA("message sent to wrong addressee: %S", to); + return; + } + const wchar_t *idStr = XmlGetAttrValue(node, L"id"); pResourceStatus pFromResource(ResourceInfoFromJID(from)); @@ -1090,10 +1095,10 @@ void CJabberProto::OnProcessMessage(HXML node, ThreadData *info) if (m_messageManager.HandleMessagePermanent(node, info)) return; - //Handle carbons. The message MUST be coming from our bare JID. + // Handle carbons. The message MUST be coming from our bare JID. HXML carbon = nullptr; bool carbonSent = false; //2 cases: received or sent. - if (this->IsMyOwnJID(from)) { + if (IsMyOwnJID(from)) { carbon = XmlGetChildByTag(node, "received", "xmlns", JABBER_FEAT_CARBONS); if (!carbon) { carbon = XmlGetChildByTag(node, "sent", "xmlns", JABBER_FEAT_CARBONS); @@ -1101,13 +1106,13 @@ void CJabberProto::OnProcessMessage(HXML node, ThreadData *info) carbonSent = true; } if (carbon) { - //If carbons are disabled in options, we should ignore occasional carbons sent to us by server + // If carbons are disabled in options, we should ignore occasional carbons sent to us by server if (!m_bEnableCarbons) return; HXML forwarded = nullptr; HXML message = nullptr; - //Carbons MUST have forwarded/message content + // Carbons MUST have forwarded/message content if (!(forwarded = XmlGetChildByTag(carbon, "forwarded", "xmlns", JABBER_XMLNS_FORWARD)) || !(message = XmlGetChild(forwarded, "message"))) return; @@ -1117,13 +1122,13 @@ void CJabberProto::OnProcessMessage(HXML node, ThreadData *info) type = XmlGetAttrValue(node, L"type"); if (!carbonSent) { - //Received should just be treated like incoming messages, except maybe not flash the flasher. Simply unwrap. + // Received should just be treated like incoming messages, except maybe not flash the flasher. Simply unwrap. from = XmlGetAttrValue(node, L"from"); if (from == nullptr) return; } else { - //Sent should set SENT flag and invert from/to. + // Sent should set SENT flag and invert from/to. from = XmlGetAttrValue(node, L"to"); if (from == nullptr) return; @@ -1162,6 +1167,7 @@ void CJabberProto::OnProcessMessage(HXML node, ThreadData *info) szMessage = szTmp; } + HXML n; if (szMessage && (n = XmlGetChildByTag(node, "addresses", "xmlns", JABBER_FEAT_EXT_ADDRESSING))) { HXML addressNode = XmlGetChildByTag(n, "address", "type", L"ofrom"); if (addressNode) { @@ -1268,6 +1274,7 @@ void CJabberProto::OnProcessMessage(HXML node, ThreadData *info) } // parsing extensions + HXML xNode; for (int i = 0; (xNode = XmlGetChild(node, i)) != nullptr; i++) { if (m_bUseOMEMO) { @@ -1288,8 +1295,8 @@ void CJabberProto::OnProcessMessage(HXML node, ThreadData *info) } } } + } - } if ((xNode = XmlGetNthChild(node, L"x", i + 1)) == nullptr) continue; diff --git a/protocols/JabberG/src/jabber_util.cpp b/protocols/JabberG/src/jabber_util.cpp index b4b4537de5..3e3e393d05 100755 --- a/protocols/JabberG/src/jabber_util.cpp +++ b/protocols/JabberG/src/jabber_util.cpp @@ -587,18 +587,6 @@ wchar_t* __stdcall JabberStripJid(const wchar_t *jid, wchar_t *dest, size_t dest return dest; } -///////////////////////////////////////////////////////////////////////////////////////// -// JabberGetPictureType - tries to autodetect the picture type from the buffer - -const wchar_t *__stdcall JabberGetPictureType(HXML node, const char *picBuf) -{ - if (const wchar_t *ptszType = XmlGetText(XmlGetChild(node, "TYPE"))) - if (ProtoGetAvatarFormatByMimeType(ptszType) != PA_FORMAT_UNKNOWN) - return ptszType; - - return ProtoGetAvatarMimeType(ProtoGetBufferFormat(picBuf)); -} - ///////////////////////////////////////////////////////////////////////////////////////// // TStringPairs class members diff --git a/protocols/JabberG/src/stdafx.h b/protocols/JabberG/src/stdafx.h index 614dd0dcb7..7120057218 100755 --- a/protocols/JabberG/src/stdafx.h +++ b/protocols/JabberG/src/stdafx.h @@ -716,26 +716,24 @@ struct TStringPairs typedef char JabberShaStrBuf[2*MIR_SHA1_HASH_SIZE + 1]; -wchar_t* __stdcall JabberNickFromJID(const wchar_t *jid); -wchar_t* JabberPrepareJid(const wchar_t *jid); -void __stdcall JabberUrlDecodeW(WCHAR *str); -char* __stdcall JabberSha1(const char *str, JabberShaStrBuf buf); -wchar_t* __stdcall JabberStrFixLines(const wchar_t *str); -void __stdcall JabberHttpUrlDecode(wchar_t *str); -int __stdcall JabberCombineStatus(int status1, int status2); -wchar_t* __stdcall JabberErrorStr(int errorCode); -wchar_t* __stdcall JabberErrorMsg(HXML errorNode, int *errorCode = nullptr); -time_t __stdcall JabberIsoToUnixTime(const wchar_t *stamp); -wchar_t* __stdcall JabberStripJid(const wchar_t *jid, wchar_t *dest, size_t destLen); -int __stdcall JabberGetPacketID(HXML n); -wchar_t* __stdcall JabberId2string(int id); - -const wchar_t * __stdcall JabberGetPictureType(HXML node, const char *picBuf); +wchar_t* __stdcall JabberNickFromJID(const wchar_t *jid); +wchar_t* JabberPrepareJid(const wchar_t *jid); +void __stdcall JabberUrlDecodeW(WCHAR *str); +char* __stdcall JabberSha1(const char *str, JabberShaStrBuf buf); +wchar_t* __stdcall JabberStrFixLines(const wchar_t *str); +void __stdcall JabberHttpUrlDecode(wchar_t *str); +int __stdcall JabberCombineStatus(int status1, int status2); +wchar_t* __stdcall JabberErrorStr(int errorCode); +wchar_t* __stdcall JabberErrorMsg(HXML errorNode, int *errorCode = nullptr); +time_t __stdcall JabberIsoToUnixTime(const wchar_t *stamp); +wchar_t* __stdcall JabberStripJid(const wchar_t *jid, wchar_t *dest, size_t destLen); +int __stdcall JabberGetPacketID(HXML n); +wchar_t* __stdcall JabberId2string(int id); wchar_t* time2str(time_t _time, wchar_t *buf, size_t bufLen); -time_t str2time(const wchar_t*); +time_t str2time(const wchar_t*); -const wchar_t* JabberStrIStr(const wchar_t *str, const wchar_t *substr); +const wchar_t* JabberStrIStr(const wchar_t *str, const wchar_t *substr); void JabberCopyText(HWND hwnd, const wchar_t *text); CJabberProto* JabberChooseInstance(bool bIsLink=false); -- cgit v1.2.3