diff options
author | George Hazan <ghazan@miranda.im> | 2019-01-07 20:07:09 +0200 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2019-01-07 20:07:09 +0200 |
commit | 961e087318eb6de88c03a2eef1b2c1056c25d94c (patch) | |
tree | 96dfe72edd17fcaebcadf5fbbbbdb337e47aed06 /protocols | |
parent | dc2267b1fb5bc6e43914f7a0709fbe48bf4b9a09 (diff) |
ICQ10:
- DB_KEY_RTOKEN isn't stored in a database anymore;
- ExecuteRequest code slightly reordered not to create a bunch of additional connections to rapi.icq.net
Diffstat (limited to 'protocols')
-rw-r--r-- | protocols/Icq10/src/http.cpp | 31 | ||||
-rw-r--r-- | protocols/Icq10/src/server.cpp | 7 | ||||
-rw-r--r-- | protocols/Icq10/src/stdafx.h | 1 |
3 files changed, 18 insertions, 21 deletions
diff --git a/protocols/Icq10/src/http.cpp b/protocols/Icq10/src/http.cpp index 51ad947e26..cf508f8ef7 100644 --- a/protocols/Icq10/src/http.cpp +++ b/protocols/Icq10/src/http.cpp @@ -34,8 +34,8 @@ void __cdecl CIcqProto::ServerThread(void*) if (m_bTerminated) break; - AsyncHttpRequest *pReq; while (true) { + AsyncHttpRequest *pReq; { mir_cslock lck(m_csHttpQueue); if (m_arHttpQueue.getCount() == 0) @@ -134,12 +134,25 @@ void CIcqProto::ExecuteRequest(AsyncHttpRequest *pReq) NETLIBHTTPREQUEST *reply = Netlib_HttpTransaction(m_hNetlibUser, pReq); if (reply != nullptr) { + if (pReq->m_conn != CONN_NONE) { + auto &conn = m_ConnPool[pReq->m_conn]; + conn.s = reply->nlc; + conn.timeout = 0; + for (int i = 0; i < reply->headersCount; i++) { + if (!mir_strcmp(reply->headers[i].szName, "Keep-Alive")) { + int timeout; + if (1 == sscanf(reply->headers[i].szValue, "timeout=%d", &timeout)) + conn.timeout = timeout; + break; + } + } + } + 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(); - delSetting(DB_KEY_RTOKEN); // if token refresh succeeded, replace it in the query and push request back if (RefreshRobustToken()) { @@ -156,20 +169,6 @@ void CIcqProto::ExecuteRequest(AsyncHttpRequest *pReq) if (pReq->m_pFunc != nullptr) (this->*(pReq->m_pFunc))(reply, pReq); - if (pReq->m_conn != CONN_NONE) { - auto &conn = m_ConnPool[pReq->m_conn]; - conn.s = reply->nlc; - conn.timeout = 0; - for (int i = 0; i < reply->headersCount; i++) { - if (!mir_strcmp(reply->headers[i].szName, "Keep-Alive")) { - int timeout; - if (1 == sscanf(reply->headers[i].szValue, "timeout=%d", &timeout)) - conn.timeout = timeout; - break; - } - } - } - Netlib_FreeHttpRequest(reply); } else { diff --git a/protocols/Icq10/src/server.cpp b/protocols/Icq10/src/server.cpp index 1d5bda5521..d46e41ec70 100644 --- a/protocols/Icq10/src/server.cpp +++ b/protocols/Icq10/src/server.cpp @@ -75,7 +75,6 @@ void CIcqProto::CheckPassword() Miranda_GetVersionText(mirVer, _countof(mirVer)); m_szAToken = getMStringA(DB_KEY_ATOKEN); - m_szRToken = getMStringA(DB_KEY_RTOKEN); m_iRClientId = getDword(DB_KEY_RCLIENTID); m_szSessionKey = getMStringA(DB_KEY_SESSIONKEY); if (m_szAToken.IsEmpty() || m_szSessionKey.IsEmpty()) { @@ -241,13 +240,13 @@ bool CIcqProto::RefreshRobustToken() tmp->AddHeader("User-Agent", szAgent); NETLIBHTTPREQUEST *reply = Netlib_HttpTransaction(m_hNetlibUser, tmp); - m_ConnPool[CONN_RAPI].s = nullptr; if (reply != nullptr) { + m_ConnPool[CONN_RAPI].s = reply->nlc; + RobustReply result(reply); if (result.error() == 20000) { const JSONNode &results = result.results(); m_szRToken = results["authToken"].as_mstring(); - setString(DB_KEY_RTOKEN, m_szRToken); // now add this token auto *add = new AsyncHttpRequest(CONN_RAPI, REQUEST_POST, ICQ_ROBUST_SERVER, &CIcqProto::OnAddClient); @@ -258,9 +257,9 @@ bool CIcqProto::RefreshRobustToken() ExecuteRequest(add); } - m_ConnPool[CONN_RAPI].s = reply->nlc; Netlib_FreeHttpRequest(reply); } + else m_ConnPool[CONN_RAPI].s = nullptr; delete tmp; return bRet; diff --git a/protocols/Icq10/src/stdafx.h b/protocols/Icq10/src/stdafx.h index a6636ebf84..b9770142f0 100644 --- a/protocols/Icq10/src/stdafx.h +++ b/protocols/Icq10/src/stdafx.h @@ -80,7 +80,6 @@ #define DB_KEY_UIN "UIN" #define DB_KEY_ATOKEN "AToken" -#define DB_KEY_RTOKEN "RToken" #define DB_KEY_RCLIENTID "RClientID" #define DB_KEY_LASTMSGID "LastMsgId" #define DB_KEY_SESSIONKEY "SessionKey" |