From 49b8c2baa48ff1ccc82b5b2341ab435644742bd9 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Mon, 17 Oct 2022 15:22:50 +0300 Subject: Jabber: code cleaning, useless code removed --- protocols/JabberG/src/jabber_chat.cpp | 2 +- protocols/JabberG/src/jabber_ft.cpp | 30 ++++++++++++++++-------------- protocols/JabberG/src/jabber_groupchat.cpp | 14 -------------- protocols/JabberG/src/jabber_omemo.cpp | 11 +++++------ protocols/JabberG/src/jabber_proto.cpp | 16 ++++++++++------ protocols/JabberG/src/jabber_proto.h | 4 ++-- 6 files changed, 34 insertions(+), 43 deletions(-) (limited to 'protocols/JabberG/src') diff --git a/protocols/JabberG/src/jabber_chat.cpp b/protocols/JabberG/src/jabber_chat.cpp index 550a81bc00..2ebf696113 100644 --- a/protocols/JabberG/src/jabber_chat.cpp +++ b/protocols/JabberG/src/jabber_chat.cpp @@ -1352,7 +1352,7 @@ int CJabberProto::JabberGcEventHook(WPARAM, LPARAM lParam) if (gch->ptszText && mir_wstrlen(gch->ptszText) > 0) { rtrimw(gch->ptszText); Chat_UnescapeTags(gch->ptszText); - GroupchatSendMsg(item, T2Utf(gch->ptszText)); + SendMsg(item->hContact, 0, T2Utf(gch->ptszText)); } break; diff --git a/protocols/JabberG/src/jabber_ft.cpp b/protocols/JabberG/src/jabber_ft.cpp index 60faeb53c4..096351d713 100644 --- a/protocols/JabberG/src/jabber_ft.cpp +++ b/protocols/JabberG/src/jabber_ft.cpp @@ -707,11 +707,11 @@ LBL_Fail: int tmp_len = 0, outl; //EVP_EncryptUpdate(ctx, nullptr, &outl, aad, _countof(aad)); - unsigned char *out = (unsigned char*)mir_alloc(_filelength(fileId) + _countof(key) - 1 + _countof(tag)); - unsigned char *in = (unsigned char*)mir_alloc(1024 * 1024); + unsigned char *out = (unsigned char *)mir_alloc(_filelength(fileId) + _countof(key) - 1 + _countof(tag)); + unsigned char *in = (unsigned char *)mir_alloc(128 * 1024); for (;;) { - int inl = _read(fileId, in, 1024 * 1024); - if(inl == 0) + int inl = _read(fileId, in, 128 * 1024); + if (inl == 0) break; EVP_EncryptUpdate(ctx, out + tmp_len, &outl, in, inl); tmp_len += outl; @@ -725,8 +725,9 @@ LBL_Fail: memcpy(out + tmp_len, tag, _countof(tag)); nlhr.dataLength = tmp_len + _countof(tag); - nlhr.pData = (char*)out; - } else { + nlhr.pData = (char *)out; + } + else { nlhr.dataLength = _filelength(fileId); nlhr.pData = new char[nlhr.dataLength]; _read(fileId, nlhr.pData, nlhr.dataLength); @@ -738,7 +739,7 @@ LBL_Fail: debugLogA("error uploading file %S", pwszFileName); goto LBL_Fail; } - + switch (res->resultCode) { case 200: // ok case 201: // created @@ -754,11 +755,12 @@ LBL_Fail: // this parameter is optional, if not specified we simply use upload URL CMStringA szMessage; - if (auto *szGetUrl = version ? XmlGetChildText(slotNode, "get") : XmlGetAttr(XmlFirstChild(slotNode, "get"), "url")) + if (auto *szGetUrl = version ? XmlGetChildText(slotNode, "get") : XmlGetAttr(XmlFirstChild(slotNode, "get"), "url")) szMessage = szGetUrl; else szMessage = szUrl; + XmlNode m("message"); if (enOmemo) { int i = szMessage.Find("://"); char szIv[2*_countof(iv) + 1], szKey[2*_countof(key) + 1]; @@ -766,15 +768,15 @@ LBL_Fail: bin2hex(key, _countof(key), szKey); szMessage.Format("aesgcm%s#%s%s", szMessage.Mid(i).c_str(), szIv, szKey); } + else m << XCHILDNS("x", JABBER_FEAT_OOB2) << XCHILD("url", szMessage.c_str()); if (m_bEmbraceUrls && ProtoGetAvatarFormat(_A2T(szMessage)) != PA_FORMAT_UNKNOWN) { szMessage.Insert(0, "[img]"); szMessage.Append("[/img]"); } - if (isChatRoom(ft->std.hContact)) - GroupchatSendMsg(ft->pItem, ptrA(mir_utf8encode(szMessage))); - else if (ProtoChainSend(ft->std.hContact, PSS_MESSAGE, 0, (LPARAM)szMessage.c_str()) != -1) { + int ret = SendMsgEx(ft->std.hContact, szMessage.c_str(), m); + if (ret != -1 && !isChatRoom(ft->std.hContact)) { PROTORECVEVENT recv = {}; recv.flags = PREF_CREATEREAD | PREF_SENT; recv.szMessage = szMessage.GetBuffer(); @@ -857,7 +859,7 @@ bool CJabberProto::FtTryInlineFile(filetransfer *ft) m << XCHILDNS("request", JABBER_FEAT_MESSAGE_RECEIPTS); m << XCHILDNS("markable", JABBER_FEAT_CHAT_MARKERS); } - + m_ThreadInfo->send(m); // emulate a message for us @@ -879,7 +881,7 @@ bool CJabberProto::FtHandleCidRequest(const TiXmlElement*, CJabberIqInfo *pInfo) const char *cid = XmlGetAttr(pChild, "cid"); if (cid == nullptr) { - LBL_Error: +LBL_Error: XmlNodeIq iq("error", pInfo); TiXmlElement *error = iq << XCHILD("error") << XATTRI("code", 400) << XATTR("type", "cancel"); error << XCHILDNS("bad-request", "urn:ietf:params:xml:ns:xmpp-stanzas"); @@ -898,7 +900,7 @@ bool CJabberProto::FtHandleCidRequest(const TiXmlElement*, CJabberIqInfo *pInfo) HANDLE hFind = FindFirstFileW(wszFileMask, &data); if (hFind == nullptr) goto LBL_Error; - + FindClose(hFind); int fileFormat = ProtoGetAvatarFormat(data.cFileName); diff --git a/protocols/JabberG/src/jabber_groupchat.cpp b/protocols/JabberG/src/jabber_groupchat.cpp index 838c0f8d71..b4361422df 100644 --- a/protocols/JabberG/src/jabber_groupchat.cpp +++ b/protocols/JabberG/src/jabber_groupchat.cpp @@ -1177,17 +1177,3 @@ void CJabberProto::AcceptGroupchatInvite(const char *roomJid, const char *reason char *server = strtok(nullptr, "@"); GroupchatJoinRoom(server, p, reason, password); } - -void CJabberProto::GroupchatSendMsg(JABBER_LIST_ITEM *pItem, const char *msg) -{ - if (!m_bJabberOnline) - return; - - char szId[100]; - int64_t id = (_time64(nullptr) << 16) + (GetTickCount() & 0xFFFF); - _i64toa(id, szId, 36); - - m_ThreadInfo->send( - XmlNode("message") << XATTR("id", szId) << XATTR("to", pItem->jid) << XATTR("type", "groupchat") - << XCHILD("body", msg)); -} diff --git a/protocols/JabberG/src/jabber_omemo.cpp b/protocols/JabberG/src/jabber_omemo.cpp index b8042b0a55..e5edb53d57 100644 --- a/protocols/JabberG/src/jabber_omemo.cpp +++ b/protocols/JabberG/src/jabber_omemo.cpp @@ -354,14 +354,13 @@ complete: struct outgoing_message { - outgoing_message(MCONTACT h, int u, char* p) + outgoing_message(MCONTACT h, char* p) { hContact = h; - unused_unknown = u; pszSrc = p; } + MCONTACT hContact; - int unused_unknown; char* pszSrc; }; @@ -1338,10 +1337,10 @@ void CJabberProto::OmemoInitDevice() m_omemo.RefreshDevice(); } -void CJabberProto::OmemoPutMessageToOutgoingQueue(MCONTACT hContact, int unused_unknown, const char* pszSrc) +void CJabberProto::OmemoPutMessageToOutgoingQueue(MCONTACT hContact, const char* pszSrc) { char *msg = mir_strdup(pszSrc); - m_omemo.outgoing_messages.push_back(omemo::outgoing_message(hContact, unused_unknown, msg)); + m_omemo.outgoing_messages.push_back(omemo::outgoing_message(hContact, msg)); } void CJabberProto::OmemoPutMessageToIncommingQueue(const TiXmlElement *node, const char *jid, time_t msgTime) @@ -1353,7 +1352,7 @@ void CJabberProto::OmemoPutMessageToIncommingQueue(const TiXmlElement *node, con void CJabberProto::OmemoHandleMessageQueue() { for (auto &i : m_omemo.outgoing_messages) { - SendMsg(i.hContact, i.unused_unknown, i.pszSrc); + SendMsg(i.hContact, 0, i.pszSrc); mir_free(i.pszSrc); } m_omemo.outgoing_messages.clear(); diff --git a/protocols/JabberG/src/jabber_proto.cpp b/protocols/JabberG/src/jabber_proto.cpp index 1807da713f..8e2f349cb6 100644 --- a/protocols/JabberG/src/jabber_proto.cpp +++ b/protocols/JabberG/src/jabber_proto.cpp @@ -915,17 +915,23 @@ HANDLE CJabberProto::SendFile(MCONTACT hContact, const wchar_t *szDescription, w //////////////////////////////////////////////////////////////////////////////////////// // JabberSendMessage - sends a message -int CJabberProto::SendMsg(MCONTACT hContact, int unused_unknown, const char *pszSrc) +int CJabberProto::SendMsg(MCONTACT hContact, int /*flags*/, const char *pszSrc) +{ + XmlNode m("message"); + return SendMsgEx(hContact, pszSrc, m); +} + +int CJabberProto::SendMsgEx(MCONTACT hContact, const char *pszSrc, XmlNode &m) { char szClientJid[JABBER_MAX_JID_LEN]; if (!m_bJabberOnline || !GetClientJID(hContact, szClientJid, _countof(szClientJid))) { ProtoBroadcastAsync(hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, 0, (LPARAM)TranslateT("Protocol is offline or no JID")); - return 1; + return -1; } if (m_bUseOMEMO && OmemoIsEnabled(hContact)) { if (!OmemoCheckSession(hContact)) { - OmemoPutMessageToOutgoingQueue(hContact, unused_unknown, pszSrc); + OmemoPutMessageToOutgoingQueue(hContact, pszSrc); int id = SerialNext(); ProtoBroadcastAsync(hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, (HANDLE)id); return id; @@ -949,7 +955,6 @@ int CJabberProto::SendMsg(MCONTACT hContact, int unused_unknown, const char *psz msgType = "groupchat"; else msgType = "chat"; - XmlNode m("message"); // omemo enabled in options, omemo enabled for contact if (m_bUseOMEMO && OmemoIsEnabled(hContact) && !mir_strcmp(msgType, "chat")) { @@ -992,8 +997,7 @@ int CJabberProto::SendMsg(MCONTACT hContact, int unused_unknown, const char *psz // if message sent to groupchat !mir_strcmp(msgType, "groupchat") || // if message delivery check disabled in settings - !bSendReceipt) - { + !bSendReceipt) { if (mir_strcmp(msgType, "groupchat")) XmlAddAttrID(m, id); diff --git a/protocols/JabberG/src/jabber_proto.h b/protocols/JabberG/src/jabber_proto.h index 48c2316d3b..29b05e25c0 100644 --- a/protocols/JabberG/src/jabber_proto.h +++ b/protocols/JabberG/src/jabber_proto.h @@ -138,6 +138,7 @@ struct CJabberProto : public PROTO, public IJabberInterface int SendContacts(MCONTACT hContact, int flags, int nContacts, MCONTACT *hContactsList) override; HANDLE SendFile(MCONTACT hContact, const wchar_t *szDescription, wchar_t **ppszFiles) override; int SendMsg(MCONTACT hContact, int flags, const char *msg) override; + int SendMsgEx(MCONTACT hContact, const char *msg, XmlNode &m); int SetApparentMode(MCONTACT hContact, int mode) override; int SetStatus(int iNewStatus) override; @@ -525,7 +526,6 @@ struct CJabberProto : public PROTO, public IJabberInterface void GroupchatProcessPresence(const TiXmlElement *node); void GroupchatProcessMessage(const TiXmlElement *node); void GroupchatProcessInvite(const char *roomJid, const char *from, const char *reason, const char *password); - void GroupchatSendMsg(JABBER_LIST_ITEM *pItem, const char *msg); void OnIqResultDiscovery(const TiXmlElement *iqNode, CJabberIqInfo *pInfo); //---- jabber_icolib.cpp ------------------------------------------------------------- @@ -716,7 +716,7 @@ struct CJabberProto : public PROTO, public IJabberInterface //---- jabber_omemo.cpp -------------------------------------------------------------- bool OmemoHandleMessage(const TiXmlElement *node, const char *jid, time_t msgTime); - void OmemoPutMessageToOutgoingQueue(MCONTACT hContact, int, const char *pszSrc); + void OmemoPutMessageToOutgoingQueue(MCONTACT hContact, const char *pszSrc); void OmemoPutMessageToIncommingQueue(const TiXmlElement *node, const char *jid, time_t msgTime); void OmemoHandleMessageQueue(); bool OmemoHandleDeviceList(const char *from, const TiXmlElement *node); -- cgit v1.2.3