From 71445cc324f6c23eb6ac7ac07d78a54cd6fac803 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Thu, 24 Oct 2013 18:39:52 +0000 Subject: VK: fix for a broken login calls chain git-svn-id: http://svn.miranda-ng.org/main/trunk@6612 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/VKontakte/src/vk_proto.h | 28 +++++++++++++++------------- protocols/VKontakte/src/vk_queue.cpp | 9 ++++----- protocols/VKontakte/src/vk_thread.cpp | 14 +++++++++++--- 3 files changed, 30 insertions(+), 21 deletions(-) (limited to 'protocols') diff --git a/protocols/VKontakte/src/vk_proto.h b/protocols/VKontakte/src/vk_proto.h index 204694bd56..1c2582ccaa 100644 --- a/protocols/VKontakte/src/vk_proto.h +++ b/protocols/VKontakte/src/vk_proto.h @@ -16,7 +16,7 @@ along with this program. If not, see . */ struct CVkProto; -typedef void (CVkProto::*VK_REQUEST_HANDLER)(NETLIBHTTPREQUEST*, struct AsyncHttpRequest *pReq); +typedef void (CVkProto::*VK_REQUEST_HANDLER)(NETLIBHTTPREQUEST*, struct AsyncHttpRequest*); struct AsyncHttpRequest : public NETLIBHTTPREQUEST, public MZeroedObject { @@ -91,10 +91,9 @@ struct CVkProto : public PROTO int __cdecl OnOptionsInit(WPARAM, LPARAM); int __cdecl OnPreShutdown(WPARAM, LPARAM); - void OnOAuthAuthorize(NETLIBHTTPREQUEST*, AsyncHttpRequest *pReq); - void OnReceiveMyInfo(NETLIBHTTPREQUEST*, AsyncHttpRequest *pReq); - void OnReceiveAvatar(NETLIBHTTPREQUEST*, AsyncHttpRequest *pReq); - void OnReceiveSmth(NETLIBHTTPREQUEST*, AsyncHttpRequest *pReq); + void OnOAuthAuthorize(NETLIBHTTPREQUEST*, AsyncHttpRequest*); + void OnReceiveAvatar(NETLIBHTTPREQUEST*, AsyncHttpRequest*); + void OnReceiveSmth(NETLIBHTTPREQUEST*, AsyncHttpRequest*); //==== Services ====================================================================== @@ -106,23 +105,26 @@ struct CVkProto : public PROTO TCHAR* GetUserStoredPassword(void); + void RetrieveMyInfo(void); + void OnReceiveMyInfo(NETLIBHTTPREQUEST*, AsyncHttpRequest*); + void RetrieveUserInfo(LONG userId); - void OnReceiveUserInfo(NETLIBHTTPREQUEST*, AsyncHttpRequest *pReq); + void OnReceiveUserInfo(NETLIBHTTPREQUEST*, AsyncHttpRequest*); void RetrieveFriends(); - void OnReceiveFriends(NETLIBHTTPREQUEST*, AsyncHttpRequest *pReq); + void OnReceiveFriends(NETLIBHTTPREQUEST*, AsyncHttpRequest*); void RetrieveUnreadMessages(); - void OnReceiveMessages(NETLIBHTTPREQUEST*, AsyncHttpRequest *pReq); - void OnSendMessage(NETLIBHTTPREQUEST*, AsyncHttpRequest *pReq); + void OnReceiveMessages(NETLIBHTTPREQUEST*, AsyncHttpRequest*); + void OnSendMessage(NETLIBHTTPREQUEST*, AsyncHttpRequest*); void RetrievePollingInfo(); - void OnReceivePollingInfo(NETLIBHTTPREQUEST*, AsyncHttpRequest *pReq); + void OnReceivePollingInfo(NETLIBHTTPREQUEST*, AsyncHttpRequest*); void __cdecl PollingThread(void*); int PollServer(); void PollUpdates(JSONNODE*); - void OnReceivePolling(NETLIBHTTPREQUEST*, AsyncHttpRequest *pReq); + void OnReceivePolling(NETLIBHTTPREQUEST*, AsyncHttpRequest*); void SetServerStatus(int); @@ -148,11 +150,11 @@ private: }; OBJLIST m_cookies; void GrabCookies(NETLIBHTTPREQUEST *nhr); - void ApplyCookies(AsyncHttpRequest *pReq); + void ApplyCookies(AsyncHttpRequest*); void InitQueue(); void UninitQueue(); - void ExecuteRequest(AsyncHttpRequest *pReq); + void ExecuteRequest(AsyncHttpRequest*); bool PushAsyncHttpRequest(int iRequestType, LPCSTR szUrl, bool bSecure, VK_REQUEST_HANDLER pFunc, int nParams = 0, HttpParam *pParams = 0, int iTimeout = 10000); bool PushAsyncHttpRequest(AsyncHttpRequest*, int iTimeout = 10000); void __cdecl WorkerThread(void*); diff --git a/protocols/VKontakte/src/vk_queue.cpp b/protocols/VKontakte/src/vk_queue.cpp index 782906ce6f..60d115b84b 100644 --- a/protocols/VKontakte/src/vk_queue.cpp +++ b/protocols/VKontakte/src/vk_queue.cpp @@ -101,12 +101,11 @@ void CVkProto::WorkerThread(void*) debugLogA("CVkProto::WorkerThread: entering"); m_bTerminated = m_prevError = false; m_szAccessToken = getStringA("AccessToken"); - if (m_szAccessToken != NULL) { + if (m_szAccessToken != NULL) // try to receive a response from server - HttpParam param = { "access_token", m_szAccessToken }; - PushAsyncHttpRequest(REQUEST_GET, "/method/getUserInfoEx.json", true, &CVkProto::OnReceiveMyInfo, 1, ¶m); - } - else { // Initialize new OAuth session + RetrieveMyInfo(); + else { + // Initialize new OAuth session HttpParam params[] = { { "client_id", VK_APP_ID }, { "scope", "friends,photos,audio,video,wall,messages,offline" }, diff --git a/protocols/VKontakte/src/vk_thread.cpp b/protocols/VKontakte/src/vk_thread.cpp index 06098e56eb..78b078bd08 100644 --- a/protocols/VKontakte/src/vk_thread.cpp +++ b/protocols/VKontakte/src/vk_thread.cpp @@ -112,10 +112,12 @@ void CVkProto::OnOAuthAuthorize(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq if (m_szAccessToken == NULL) m_szAccessToken = mir_strdup(p); setString("AccessToken", m_szAccessToken); + RetrieveMyInfo(); + } + else { + delSetting("AccessToken"); + ConnectionFailed(LOGINERR_NOSERVER); } - else delSetting("AccessToken"); - - OnLoggedIn(); } else { AsyncHttpRequest *pReq = new AsyncHttpRequest(); @@ -176,6 +178,12 @@ LBL_NoForm: ///////////////////////////////////////////////////////////////////////////////////////// +void CVkProto::RetrieveMyInfo() +{ + HttpParam param = { "access_token", m_szAccessToken }; + PushAsyncHttpRequest(REQUEST_GET, "/method/getUserInfoEx.json", true, &CVkProto::OnReceiveMyInfo, 1, ¶m); +} + void CVkProto::OnReceiveMyInfo(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq) { debugLogA("CVkProto::OnReceiveMyInfo %d", reply->resultCode); -- cgit v1.2.3