diff options
-rw-r--r-- | protocols/Icq10/src/http.cpp | 17 | ||||
-rw-r--r-- | protocols/Icq10/src/http.h | 3 | ||||
-rw-r--r-- | protocols/Icq10/src/proto.h | 1 | ||||
-rw-r--r-- | protocols/Icq10/src/server.cpp | 24 |
4 files changed, 28 insertions, 17 deletions
diff --git a/protocols/Icq10/src/http.cpp b/protocols/Icq10/src/http.cpp index 294fbda1e9..e538450ee5 100644 --- a/protocols/Icq10/src/http.cpp +++ b/protocols/Icq10/src/http.cpp @@ -34,21 +34,7 @@ void __cdecl CIcqProto::ServerThread(void*) } debugLogA("CIcqProto::WorkerThread: %s", "entering"); - { - char mirVer[100]; - Miranda_GetVersionText(mirVer, _countof(mirVer)); - - m_szAToken = getMStringA("AToken"); - m_szSessionKey = getMStringA("SessionKey"); - if (m_szAToken.IsEmpty() || m_szSessionKey.IsEmpty()) { - auto *pReq = new AsyncHttpRequest(CONN_MAIN, REQUEST_POST, "https://api.login.icq.net/auth/clientLogin", &CIcqProto::OnCheckPassword); - pReq << CHAR_PARAM("clientName", "Miranda NG") << CHAR_PARAM("clientVersion", mirVer) << CHAR_PARAM("devId", ICQ_APP_ID) - << CHAR_PARAM("f", "json") << CHAR_PARAM("tokenType", "longTerm") << INT_PARAM("s", m_dwUin) << WCHAR_PARAM("pwd", m_szPassword); - pReq->flags |= NLHRF_NODUMPSEND; - Push(pReq); - } - else StartSession(); - } + CheckPassword(); while (true) { WaitForSingleObject(m_evRequestsQueue, 1000); @@ -193,6 +179,7 @@ JsonReply::JsonReply(NETLIBHTTPREQUEST *pReply) JSONNode &response = (*m_root)["response"]; m_errorCode = response["statusCode"].as_int(); + m_detailCode = response["statusDetailCode"].as_int(); m_data = &response["data"]; } diff --git a/protocols/Icq10/src/http.h b/protocols/Icq10/src/http.h index 374836ad7c..d5173404b7 100644 --- a/protocols/Icq10/src/http.h +++ b/protocols/Icq10/src/http.h @@ -19,7 +19,7 @@ struct AsyncHttpRequest : public MTHttpRequest<CIcqProto> class JsonReply { JSONNode *m_root = nullptr; - int m_errorCode = 0; + int m_errorCode = 0, m_detailCode = 0; JSONNode* m_data = nullptr; public: @@ -28,4 +28,5 @@ public: __forceinline JSONNode& data() const { return *m_data; } __forceinline int error() const { return m_errorCode; } + __forceinline int detail() const { return m_detailCode; } }; diff --git a/protocols/Icq10/src/proto.h b/protocols/Icq10/src/proto.h index 85b78d044d..49832997fa 100644 --- a/protocols/Icq10/src/proto.h +++ b/protocols/Icq10/src/proto.h @@ -64,6 +64,7 @@ struct IcqOwnMessage class CIcqProto : public PROTO<CIcqProto> { bool m_bOnline = false, m_bTerminated = false; + void CheckPassword(void); void ConnectionFailed(int iReason); void OnLoggedIn(void); void OnLoggedOut(void); diff --git a/protocols/Icq10/src/server.cpp b/protocols/Icq10/src/server.cpp index be3e9941dd..93603815bd 100644 --- a/protocols/Icq10/src/server.cpp +++ b/protocols/Icq10/src/server.cpp @@ -22,6 +22,23 @@ #pragma comment(lib, "libeay32.lib") +void CIcqProto::CheckPassword() +{ + char mirVer[100]; + Miranda_GetVersionText(mirVer, _countof(mirVer)); + + m_szAToken = getMStringA("AToken"); + m_szSessionKey = getMStringA("SessionKey"); + if (m_szAToken.IsEmpty() || m_szSessionKey.IsEmpty()) { + auto *pReq = new AsyncHttpRequest(CONN_MAIN, REQUEST_POST, "https://api.login.icq.net/auth/clientLogin", &CIcqProto::OnCheckPassword); + pReq << CHAR_PARAM("clientName", "Miranda NG") << CHAR_PARAM("clientVersion", mirVer) << CHAR_PARAM("devId", ICQ_APP_ID) + << CHAR_PARAM("f", "json") << CHAR_PARAM("tokenType", "longTerm") << INT_PARAM("s", m_dwUin) << WCHAR_PARAM("pwd", m_szPassword); + pReq->flags |= NLHRF_NODUMPSEND; + Push(pReq); + } + else StartSession(); +} + void CIcqProto::ConnectionFailed(int iReason) { debugLogA("ConnectionFailed -> reason %d", iReason); @@ -160,7 +177,12 @@ void CIcqProto::OnStartSession(NETLIBHTTPREQUEST *pReply, AsyncHttpRequest*) break; case 401: - ConnectionFailed(LOGINERR_WRONGPASSWORD); + if (root.detail() == 1002) { // session expired + delSetting("AToken"); + delSetting("SessionKey"); + CheckPassword(); + } + else ConnectionFailed(LOGINERR_WRONGPASSWORD); return; default: |