diff options
author | George Hazan <george.hazan@gmail.com> | 2013-10-11 14:01:25 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2013-10-11 14:01:25 +0000 |
commit | 773421e8ba17637d994088c393d406226b516a30 (patch) | |
tree | 130c0bf529e30f493ae4f2abbe1230d31fecdeed /protocols/VKontakte | |
parent | 3fc8b6f686262e8a595fc10b2bd947526ca77bdc (diff) |
- m_hNetlibUser moved to PROTO_INTERFACE;
- unified protocol loggers
git-svn-id: http://svn.miranda-ng.org/main/trunk@6435 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/VKontakte')
-rw-r--r-- | protocols/VKontakte/src/vk_proto.h | 12 | ||||
-rw-r--r-- | protocols/VKontakte/src/vk_queue.cpp | 15 | ||||
-rw-r--r-- | protocols/VKontakte/src/vk_thread.cpp | 81 |
3 files changed, 100 insertions, 8 deletions
diff --git a/protocols/VKontakte/src/vk_proto.h b/protocols/VKontakte/src/vk_proto.h index d6a6a3259e..23e3144b81 100644 --- a/protocols/VKontakte/src/vk_proto.h +++ b/protocols/VKontakte/src/vk_proto.h @@ -98,6 +98,13 @@ struct CVkProto : public PROTO<CVkProto> void RetrieveFriends();
void OnReceiveFriends(NETLIBHTTPREQUEST*, void*);
+ void RetrievePollingInfo();
+ void OnReceivePollingInfo(NETLIBHTTPREQUEST*, void*);
+
+ void __cdecl PollingThread(void*);
+ void PollServer();
+ void OnReceivePolling(NETLIBHTTPREQUEST*, void*);
+
int SetServerStatus(int);
__forceinline bool IsOnline() const { return m_bOnline; }
@@ -144,8 +151,11 @@ private: bool m_bOnline;
- HANDLE m_hNetlibUser, m_hNetlibConn;
+ HANDLE m_hNetlibConn;
ptrA m_szAccessToken, m_myUserId;
ptrT m_defaultGroup;
UINT_PTR m_timer;
+
+ ptrA m_pollingServer, m_pollingKey, m_pollingTs;
+ HANDLE m_pollingConn;
};
diff --git a/protocols/VKontakte/src/vk_queue.cpp b/protocols/VKontakte/src/vk_queue.cpp index e81bc61b0c..0e204109f2 100644 --- a/protocols/VKontakte/src/vk_queue.cpp +++ b/protocols/VKontakte/src/vk_queue.cpp @@ -72,21 +72,22 @@ bool CVkProto::PushAsyncHttpRequest(int iRequestType, LPCSTR szUrl, bool bSecure pReq->flags |= NLHRF_SSL;
CMStringA url;
- if (nParams > 0) {
+ if (*szUrl == '/') {
url = VK_API_URL;
url += szUrl;
- for (int i=0; i < nParams; i++) {
- url.AppendChar((i == 0) ? '?' : '&');
- url += pParams[i].szName;
- url.AppendChar('=');
- url += ptrA( mir_urlEncode(pParams[i].szValue));
- }
pReq->nlc = m_hNetlibConn;
}
else {
url = szUrl;
pReq->flags |= NLHRF_REMOVEHOST | NLHRF_SMARTREMOVEHOST;
}
+
+ for (int i=0; i < nParams; i++) {
+ url.AppendChar((i == 0) ? '?' : '&');
+ url += pParams[i].szName;
+ url.AppendChar('=');
+ url += ptrA( mir_urlEncode(pParams[i].szValue));
+ }
pReq->requestType = iRequestType;
pReq->szUrl = mir_strdup(url);
diff --git a/protocols/VKontakte/src/vk_thread.cpp b/protocols/VKontakte/src/vk_thread.cpp index 4ef6be5c89..d191f70b2c 100644 --- a/protocols/VKontakte/src/vk_thread.cpp +++ b/protocols/VKontakte/src/vk_thread.cpp @@ -207,6 +207,7 @@ void CVkProto::OnReceiveMyInfo(NETLIBHTTPREQUEST *reply, void*) RetrieveUserInfo(m_myUserId);
RetrieveFriends();
+ RetrievePollingInfo();
}
/////////////////////////////////////////////////////////////////////////////////////////
@@ -315,3 +316,83 @@ void CVkProto::OnReceiveFriends(NETLIBHTTPREQUEST *reply, void*) if (szValue && *szValue) setTString(hContact, "Phone1", szValue);
}
}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
+void CVkProto::RetrievePollingInfo()
+{
+ Netlib_Logf(m_hNetlibUser, "CVkProto::RetrievePollingInfo");
+
+ HttpParam param = { "access_token", m_szAccessToken };
+ PushAsyncHttpRequest(REQUEST_GET, "/method/messages.getLongPollServer.json", true, &CVkProto::OnReceivePollingInfo, 1, ¶m);
+}
+
+void CVkProto::OnReceivePollingInfo(NETLIBHTTPREQUEST *reply, void*)
+{
+ Netlib_Logf(m_hNetlibUser, "CVkProto::OnReceivePollingInfo %d", reply->resultCode);
+ if (reply->resultCode != 200)
+ return;
+
+ JSONROOT pRoot(reply->pData);
+ if ( !CheckJsonResult(pRoot))
+ return;
+
+ JSONNODE *pResponse = json_get(pRoot, "response");
+ if (pResponse == NULL)
+ return;
+
+ m_pollingTs = mir_t2a( ptrT( json_as_string( json_get(pResponse, "ts"))));
+ m_pollingKey = mir_t2a( ptrT( json_as_string( json_get(pResponse, "key"))));
+ m_pollingServer = mir_t2a( ptrT( json_as_string( json_get(pResponse, "server"))));
+ if (m_pollingTs != NULL && m_pollingKey != NULL && m_pollingServer != NULL)
+ ForkThread(&CVkProto::PollingThread, 0);
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
+void CVkProto::PollServer()
+{
+ Netlib_Logf(m_hNetlibUser, "CVkProto::PollServer");
+
+ HttpParam params[] = {
+ { "act", "a_check" },
+ { "key", m_pollingKey },
+ { "ts", m_pollingTs },
+ { "wait", "25" },
+ { "access_token", m_szAccessToken }
+ };
+ PushAsyncHttpRequest(REQUEST_GET, m_pollingServer, true, &CVkProto::OnReceivePolling, SIZEOF(params), params);
+}
+
+void CVkProto::OnReceivePolling(NETLIBHTTPREQUEST *reply, void*)
+{
+ Netlib_Logf(m_hNetlibUser, "CVkProto::OnReceivePolling %d", reply->resultCode);
+ if (reply->resultCode != 200)
+ return;
+
+ JSONROOT pRoot(reply->pData);
+ if ( !CheckJsonResult(pRoot))
+ return;
+
+ JSONNODE *pResponse = json_get(pRoot, "response");
+ if (pResponse != NULL)
+ m_pollingTs = mir_t2a( ptrT( json_as_string( json_get(pResponse, "ts"))));
+}
+
+void CVkProto::PollingThread(void*)
+{
+ NETLIBOPENCONNECTION nloc = { sizeof(nloc) };
+ nloc.flags = NLOCF_SSL | NLOCF_HTTP | NLOCF_V2;
+ nloc.szHost = VK_API_URL;
+ nloc.wPort = 443;
+ nloc.timeout = 60*1000;
+ m_pollingConn = (HANDLE)CallService(MS_NETLIB_OPENCONNECTION, (WPARAM)m_hNetlibUser, (LPARAM)&nloc);
+ if (m_pollingConn == NULL)
+ return;
+
+ while (!m_bTerminated)
+ PollServer();
+
+ CallService(MS_NETLIB_CLOSEHANDLE, (WPARAM)m_pollingConn, 0);
+ m_pollingConn = NULL;
+}
|