diff options
author | George Hazan <george.hazan@gmail.com> | 2013-10-06 21:18:23 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2013-10-06 21:18:23 +0000 |
commit | 6554d7ede333f078f286f866b3162866fdcc91e0 (patch) | |
tree | 3148b8275fb1b26d9b30929c96419e147b1a1c69 | |
parent | ef3a12230d1adc2084d0bc68ac57c00d84fa6275 (diff) |
VK: own info parser
git-svn-id: http://svn.miranda-ng.org/main/trunk@6381 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rw-r--r-- | protocols/VKontakte/src/stdafx.h | 3 | ||||
-rw-r--r-- | protocols/VKontakte/src/vk_proto.h | 3 | ||||
-rw-r--r-- | protocols/VKontakte/src/vk_thread.cpp | 41 |
3 files changed, 43 insertions, 4 deletions
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 <http://www.gnu.org/licenses/>. #include <tchar.h>
#include <time.h>
+#include <string>
+
#include <newpluginapi.h>
#include <m_system.h>
#include <m_system_cpp.h>
@@ -42,6 +44,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #include <m_hotkeys.h>
#include <m_icolib.h>
#include <m_idle.h>
+#include <m_json.h>
#include <m_langpack.h>
#include <m_message.h>
#include <m_netlib.h>
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<CVkProto> int __cdecl OnPreShutdown(WPARAM, LPARAM);
void OnOAuthAuthorize(NETLIBHTTPREQUEST*);
+ void OnReceiveMyInfo(NETLIBHTTPREQUEST*);
//==== Services ======================================================================
@@ -90,8 +91,6 @@ struct CVkProto : public PROTO<CVkProto> __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());
+ }
}
|