From 6554d7ede333f078f286f866b3162866fdcc91e0 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sun, 6 Oct 2013 21:18:23 +0000 Subject: VK: own info parser git-svn-id: http://svn.miranda-ng.org/main/trunk@6381 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/VKontakte/src/stdafx.h | 3 +++ protocols/VKontakte/src/vk_proto.h | 3 +-- protocols/VKontakte/src/vk_thread.cpp | 41 +++++++++++++++++++++++++++++++++-- 3 files changed, 43 insertions(+), 4 deletions(-) (limited to 'protocols/VKontakte/src') diff --git a/protocols/VKontakte/src/stdafx.h b/protocols/VKontakte/src/stdafx.h index adf0de846a..1cd26ecd8d 100644 --- a/protocols/VKontakte/src/stdafx.h +++ b/protocols/VKontakte/src/stdafx.h @@ -28,6 +28,8 @@ along with this program. If not, see . #include #include +#include + #include #include #include @@ -42,6 +44,7 @@ along with this program. If not, see . #include #include #include +#include #include #include #include diff --git a/protocols/VKontakte/src/vk_proto.h b/protocols/VKontakte/src/vk_proto.h index ceece84e38..63cfb05cb9 100644 --- a/protocols/VKontakte/src/vk_proto.h +++ b/protocols/VKontakte/src/vk_proto.h @@ -79,6 +79,7 @@ struct CVkProto : public PROTO int __cdecl OnPreShutdown(WPARAM, LPARAM); void OnOAuthAuthorize(NETLIBHTTPREQUEST*); + void OnReceiveMyInfo(NETLIBHTTPREQUEST*); //==== Services ====================================================================== @@ -90,8 +91,6 @@ struct CVkProto : public PROTO __forceinline bool IsOnline() const { return m_bOnline; } - void RequestMyInfo(); - private: struct AsyncHttpRequest : public NETLIBHTTPREQUEST, public MZeroedObject { diff --git a/protocols/VKontakte/src/vk_thread.cpp b/protocols/VKontakte/src/vk_thread.cpp index 23ef63165a..d894506ed6 100644 --- a/protocols/VKontakte/src/vk_thread.cpp +++ b/protocols/VKontakte/src/vk_thread.cpp @@ -43,7 +43,8 @@ void CVkProto::OnLoggedIn() ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)m_iStatus, m_iDesiredStatus); m_iStatus = m_iDesiredStatus; - RequestMyInfo(); + HttpParam param = { "access_token", m_szAccessToken }; + PushAsyncHttpRequest(REQUEST_GET, "/method/getUserInfoEx.json", true, &CVkProto::OnReceiveMyInfo, 1, ¶m); } void CVkProto::OnLoggedOut() @@ -136,6 +137,42 @@ LBL_NoForm: PushAsyncHttpRequest(pReq); } -void CVkProto::RequestMyInfo() +///////////////////////////////////////////////////////////////////////////////////////// + +void CVkProto::OnReceiveMyInfo(NETLIBHTTPREQUEST *reply) { + if (reply->resultCode != 200) { + ConnectionFailed(LOGINERR_WRONGPASSWORD); + return; + } + + JSONNODE *pRoot = json_parse(reply->pData); + if (pRoot == NULL) + return; + + JSONNODE *pResponse = json_get(pRoot, "response"); + if (pResponse == NULL) + return; + + for (size_t i = 0; i < json_size(pResponse); i++) { + JSONNODE *it = json_at(pResponse, i); + LPCSTR id = json_name(it); + if ( !_stricmp(id, "user_id")) + setString("ID", json_as_pstring(it).c_str()); + else if ( !_stricmp(id, "user_name")) + setTString("Nick", ptrT( mir_utf8decodeT( json_as_pstring(it).c_str()))); + else if ( !_stricmp(id, "user_sex")) + setByte("Gender", json_as_int(it) == 2 ? 'M' : 'F'); + else if ( !_stricmp(id, "user_bdate")) { + std::string date = json_as_pstring(it); + int d, m, y; + if ( sscanf(date.c_str(), "%d.%d.%d", &d, &m, &y) == 3) { + setByte("BirthDay", d); + setByte("BirthMonth", m); + setByte("BirthYear", y); + } + } + else if ( !_stricmp(id, "user_photo")) + setString("Photo", json_as_pstring(it).c_str()); + } } -- cgit v1.2.3