diff options
author | George Hazan <ghazan@miranda.im> | 2019-01-08 17:32:30 +0200 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2019-01-08 17:32:30 +0200 |
commit | d7a89e57b6d9c8270eb8ff68970629a0f2a16683 (patch) | |
tree | 1dfa7ce85ab6185b91fa8e72050702f80257d4b9 /protocols | |
parent | 5e286c0c950c3a68359fa639e04305f113a23225 (diff) |
shall fix #1728 forever
Diffstat (limited to 'protocols')
-rw-r--r-- | protocols/Icq10/src/http.cpp | 31 | ||||
-rw-r--r-- | protocols/Icq10/src/http.h | 2 |
2 files changed, 25 insertions, 8 deletions
diff --git a/protocols/Icq10/src/http.cpp b/protocols/Icq10/src/http.cpp index 034bc47a3c..a040fffdc9 100644 --- a/protocols/Icq10/src/http.cpp +++ b/protocols/Icq10/src/http.cpp @@ -97,6 +97,27 @@ AsyncHttpRequest::AsyncHttpRequest(IcqConnection conn, int iType, const char *sz } } +void AsyncHttpRequest::ReplaceJsonParam(const char *paramName, const char *newValue) +{ + 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); + + replaceStr(pData, nullptr); + dataLength = 0; +} + void CIcqProto::ExecuteRequest(AsyncHttpRequest *pReq) { CMStringA str; @@ -123,10 +144,7 @@ void CIcqProto::ExecuteRequest(AsyncHttpRequest *pReq) return; } - replaceStr(pReq->pData, nullptr); - - CMStringA szNewToken(FORMAT, "\"authToken\":\"%s\"", m_szRToken.c_str()); - pReq->m_szParam.Replace("\"authToken\":\"\"", szNewToken); + pReq->ReplaceJsonParam("authToken", m_szRToken); pReq->dataLength = pReq->m_szParam.GetLength(); pReq->pData = mir_strdup(pReq->m_szParam); } @@ -159,14 +177,11 @@ void CIcqProto::ExecuteRequest(AsyncHttpRequest *pReq) if (pReq->m_conn == CONN_RAPI && reply->pData && strstr(reply->pData, "\"code\": 40201")) { RobustReply r(reply); if (r.error() == 40201) { // robust token expired - CMStringA oldToken = m_szRToken; m_szRToken.Empty(); // if token refresh succeeded, replace it in the query and push request back if (RefreshRobustToken()) { - replaceStr(pReq->pData, nullptr); - pReq->dataLength = 0; - pReq->m_szParam.Replace(oldToken, m_szRToken); + pReq->ReplaceJsonParam("authToken", m_szRToken); Push(pReq); } else delete pReq; diff --git a/protocols/Icq10/src/http.h b/protocols/Icq10/src/http.h index 05dfa9ef99..58dbba4060 100644 --- a/protocols/Icq10/src/http.h +++ b/protocols/Icq10/src/http.h @@ -12,6 +12,8 @@ struct AsyncHttpRequest : public MTHttpRequest<CIcqProto> char m_reqId[50]; AsyncHttpRequest(IcqConnection, int type, const char *szUrl, MTHttpRequestHandler pFunc = nullptr); + + void ReplaceJsonParam(const char *paramName, const char *newValue); }; ///////////////////////////////////////////////////////////////////////////////////////// |