From a9dcf740f4290fa9e6b0c957adb09f954500016e Mon Sep 17 00:00:00 2001 From: George Hazan Date: Tue, 5 Mar 2019 15:42:01 +0300 Subject: fixes #1878 (if a user wipes all sessions from a browser, Miranda can't read incoming messages for about 30 minutes) --- protocols/ICQ-WIM/src/http.cpp | 27 +++++++-------------------- protocols/ICQ-WIM/src/http.h | 2 +- protocols/ICQ-WIM/src/poll.cpp | 11 ++++++++++- protocols/ICQ-WIM/src/proto.h | 1 + 4 files changed, 19 insertions(+), 22 deletions(-) diff --git a/protocols/ICQ-WIM/src/http.cpp b/protocols/ICQ-WIM/src/http.cpp index 47929fbc69..abcedca18a 100644 --- a/protocols/ICQ-WIM/src/http.cpp +++ b/protocols/ICQ-WIM/src/http.cpp @@ -106,22 +106,11 @@ AsyncHttpRequest::AsyncHttpRequest(IcqConnection conn, int iType, const char *sz } } -void AsyncHttpRequest::ReplaceJsonParam(const char *paramName, const char *newValue) +void AsyncHttpRequest::ReplaceJsonParam(const JSONNode &n) { - CMStringA szOldValue(FORMAT, "\"%s\":\"", paramName); - int idx = m_szParam.Find(szOldValue); - if (idx == -1) - return; - - idx += szOldValue.GetLength(); - int iEnd = m_szParam.Find("\"", idx); - if (iEnd == -1) - return; - - szOldValue += m_szParam.Mid(idx, iEnd + 1 - idx); - - CMStringA szNewValue(FORMAT, "\"%s\":\"%s\"", paramName, newValue); - m_szParam.Replace(szOldValue, szNewValue); + JSONNode root = JSONNode::parse(m_szParam); + root[n.name()] = n; + m_szParam = root.write().c_str(); replaceStr(pData, nullptr); dataLength = 0; @@ -153,10 +142,8 @@ void CIcqProto::ExecuteRequest(AsyncHttpRequest *pReq) return; } - char buf[40]; - _itoa_s(m_iRClientId, buf, 10); - pReq->ReplaceJsonParam("clientId", buf); - pReq->ReplaceJsonParam("authToken", m_szRToken); + pReq->ReplaceJsonParam(JSONNode("clientId", m_iRClientId)); + pReq->ReplaceJsonParam(JSONNode("authToken", m_szRToken)); pReq->dataLength = pReq->m_szParam.GetLength(); pReq->pData = mir_strdup(pReq->m_szParam); } @@ -193,7 +180,7 @@ void CIcqProto::ExecuteRequest(AsyncHttpRequest *pReq) // if token refresh succeeded, replace it in the query and push request back if (RefreshRobustToken()) { - pReq->ReplaceJsonParam("authToken", m_szRToken); + pReq->ReplaceJsonParam(JSONNode("authToken", m_szRToken)); Push(pReq); } else delete pReq; diff --git a/protocols/ICQ-WIM/src/http.h b/protocols/ICQ-WIM/src/http.h index 0152e41ff4..296abb2045 100644 --- a/protocols/ICQ-WIM/src/http.h +++ b/protocols/ICQ-WIM/src/http.h @@ -14,7 +14,7 @@ struct AsyncHttpRequest : public MTHttpRequest AsyncHttpRequest(IcqConnection, int type, const char *szUrl, MTHttpRequestHandler pFunc = nullptr); - void ReplaceJsonParam(const char *paramName, const char *newValue); + void ReplaceJsonParam(const JSONNode&); }; ///////////////////////////////////////////////////////////////////////////////////////// diff --git a/protocols/ICQ-WIM/src/poll.cpp b/protocols/ICQ-WIM/src/poll.cpp index d04d7184bb..5ff5cdbb16 100644 --- a/protocols/ICQ-WIM/src/poll.cpp +++ b/protocols/ICQ-WIM/src/poll.cpp @@ -115,7 +115,7 @@ void CIcqProto::ProcessEvent(const JSONNode &ev) else if (szType == L"presence") ProcessPresence(pData); else if (szType == L"sessionEnded") - ShutdownSession(); + ProcessSessionEnd(pData); else if (szType == L"typing") ProcessTyping(pData); } @@ -262,6 +262,15 @@ void CIcqProto::ProcessPresence(const JSONNode &ev) } } +void CIcqProto::ProcessSessionEnd(const JSONNode&) +{ + m_szRToken.Empty(); + m_iRClientId = 0; + delSetting(DB_KEY_RCLIENTID); + + ShutdownSession(); +} + void CIcqProto::ProcessTyping(const JSONNode &ev) { CMStringW aimId = ev["aimId"].as_mstring(); diff --git a/protocols/ICQ-WIM/src/proto.h b/protocols/ICQ-WIM/src/proto.h index 4dd0801e7b..cfaf780fd0 100644 --- a/protocols/ICQ-WIM/src/proto.h +++ b/protocols/ICQ-WIM/src/proto.h @@ -221,6 +221,7 @@ class CIcqProto : public PROTO void ProcessNotification(const JSONNode&); void ProcessPermissions(const JSONNode&); void ProcessPresence(const JSONNode&); + void ProcessSessionEnd(const JSONNode&); void ProcessTyping(const JSONNode&); IcqConn m_ConnPool[CONN_LAST]; -- cgit v1.2.3