summaryrefslogtreecommitdiff
path: root/protocols/WhatsAppWeb/src/utils.cpp
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2022-10-01 15:44:39 +0300
committerGeorge Hazan <ghazan@miranda.im>2022-10-01 15:44:39 +0300
commit4599390ee98712d05550b9a49c4f02e5acebf31e (patch)
tree49345f93fa27124c27574a8d8e8b274b3ed9900b /protocols/WhatsAppWeb/src/utils.cpp
parent87ff6ba67d4df0b4c0ae3db86220b816ec6a1e75 (diff)
WhatsApp: keep-alive packets
Diffstat (limited to 'protocols/WhatsAppWeb/src/utils.cpp')
-rw-r--r--protocols/WhatsAppWeb/src/utils.cpp22
1 files changed, 16 insertions, 6 deletions
diff --git a/protocols/WhatsAppWeb/src/utils.cpp b/protocols/WhatsAppWeb/src/utils.cpp
index 7e45d65ea2..885393a354 100644
--- a/protocols/WhatsAppWeb/src/utils.cpp
+++ b/protocols/WhatsAppWeb/src/utils.cpp
@@ -87,16 +87,19 @@ WAUser* WhatsAppProto::AddUser(const char *szId, bool bTemporary)
WA_PKT_HANDLER WhatsAppProto::FindPersistentHandler(const WANode &pNode)
{
auto *pChild = pNode.getFirstChild();
- CMStringA szTitle = (pChild) ? pChild->title : "";
- CMStringA szType = pNode.title;
+ CMStringA szChild = (pChild) ? pChild->title : "";
+ CMStringA szTitle = pNode.title;
+ CMStringA szType = pNode.getAttr("type");
CMStringA szXmlns = pNode.getAttr("xmlns");
for (auto &it : m_arPersistent) {
+ if (it->pszTitle && szTitle != it->pszTitle)
+ continue;
if (it->pszType && szType != it->pszType)
continue;
if (it->pszXmlns && szXmlns != it->pszXmlns)
continue;
- if (it->pszNode && szTitle != it->pszNode)
+ if (it->pszChild && szChild != it->pszChild)
continue;
return it->pHandler;
}
@@ -106,6 +109,13 @@ WA_PKT_HANDLER WhatsAppProto::FindPersistentHandler(const WANode &pNode)
/////////////////////////////////////////////////////////////////////////////////////////
+CMStringA WhatsAppProto::generateMessageId()
+{
+ return CMStringA(FORMAT, "%d.%d-%d", m_wMsgPrefix[0], m_wMsgPrefix[1], m_iPacketId++);
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
MBinBuffer WhatsAppProto::getBlob(const char *szSetting)
{
MBinBuffer buf;
@@ -125,12 +135,12 @@ int WhatsAppProto::WSSend(const MessageLite &msg)
if (m_hServerConn == nullptr)
return -1;
- // debugLogA("Sending packet: %s", msg..DebugString().c_str());
-
int cbLen = msg.ByteSize();
ptrA protoBuf((char *)mir_alloc(cbLen));
msg.SerializeToArray(protoBuf, cbLen);
+ Netlib_Dump(m_hServerConn, protoBuf, cbLen, true, 0);
+
MBinBuffer payload = m_noise->encodeFrame(protoBuf, cbLen);
WebSocket_SendBinary(m_hServerConn, payload.data(), payload.length());
return 0;
@@ -154,7 +164,7 @@ int WhatsAppProto::WSSendNode(WANode &node, WA_PKT_HANDLER pHandler)
if (pHandler != nullptr) {
mir_cslock lck(m_csPacketQueue);
- m_arPacketQueue.insert(new WARequest(pHandler));
+ m_arPacketQueue.insert(new WARequest(node.getAttr("id"), pHandler));
}
MBinBuffer encData = m_noise->encrypt(writer.body.data(), writer.body.length());