diff options
author | Robert Pösel <robyer@seznam.cz> | 2015-05-19 18:51:16 +0000 |
---|---|---|
committer | Robert Pösel <robyer@seznam.cz> | 2015-05-19 18:51:16 +0000 |
commit | bebab62e39e83e698ce5475a73987df01fe3a147 (patch) | |
tree | 13a7210afad01894271c96e6200c908b81aedf25 | |
parent | 331cea6299be141243e89e10755ec4adf5ef5d90 (diff) |
Steam: Fix showing error message on sending message; small cleanup and FIXME note
git-svn-id: http://svn.miranda-ng.org/main/trunk@13701 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rw-r--r-- | protocols/Steam/src/Steam/message.h | 4 | ||||
-rw-r--r-- | protocols/Steam/src/steam_account.cpp | 1 | ||||
-rw-r--r-- | protocols/Steam/src/steam_messages.cpp | 4 | ||||
-rw-r--r-- | protocols/Steam/src/steam_queue.cpp | 381 |
4 files changed, 198 insertions, 192 deletions
diff --git a/protocols/Steam/src/Steam/message.h b/protocols/Steam/src/Steam/message.h index 82cfc0b5ad..ee5b5dcea7 100644 --- a/protocols/Steam/src/Steam/message.h +++ b/protocols/Steam/src/Steam/message.h @@ -68,9 +68,9 @@ namespace SteamWebApi // JSONROOT root(response->pData);
// JSONNODE *node = json_get(root, "error");
- // ptrW error(json_as_string(node));
+ // ptrT error(json_as_string(node));
- // if (lstrcmp(error, L"OK"))
+ // if (mir_tstrcmp(error, _T("OK")))
// return;
// node = json_get(root, "utc_timestamp");
diff --git a/protocols/Steam/src/steam_account.cpp b/protocols/Steam/src/steam_account.cpp index e20c1f51e2..0cdbc95f80 100644 --- a/protocols/Steam/src/steam_account.cpp +++ b/protocols/Steam/src/steam_account.cpp @@ -229,6 +229,7 @@ void CSteamProto::OnLoggedOn(const NETLIBHTTPREQUEST *response, void *) if (response == NULL)
{
// Probably expired TokenSecret
+ // FIXME: no response could be also when there is no internet connection available! and in that case it shouldn't delete the token from db...
HandleTokenExpired();
return;
}
diff --git a/protocols/Steam/src/steam_messages.cpp b/protocols/Steam/src/steam_messages.cpp index 48f59b0ce6..3258613261 100644 --- a/protocols/Steam/src/steam_messages.cpp +++ b/protocols/Steam/src/steam_messages.cpp @@ -38,10 +38,12 @@ void CSteamProto::OnMessageSent(const NETLIBHTTPREQUEST *response, void *arg) else
debugLog(_T("CSteamProto::OnMessageSent: failed to send message for %s (%s)"), steamId, error);
+ ptrA errorA(mir_t2a(error));
+
ProtoBroadcastAck(
param->hContact,
ACKTYPE_MESSAGE,
status,
param->hMessage,
- error);
+ (LPARAM) errorA);
}
\ No newline at end of file diff --git a/protocols/Steam/src/steam_queue.cpp b/protocols/Steam/src/steam_queue.cpp index dd51f4caee..fee24bee64 100644 --- a/protocols/Steam/src/steam_queue.cpp +++ b/protocols/Steam/src/steam_queue.cpp @@ -1,190 +1,193 @@ -#include "stdafx.h"
-
-void CSteamProto::InitQueue()
-{
- debugLogA("%s: entering", __FUNCTION__);
-
- m_evRequestsQueue = CreateEvent(NULL, FALSE, FALSE, NULL);
-
- debugLogA("%s: leaving", __FUNCTION__);
-}
-
-void CSteamProto::UninitQueue()
-{
- debugLogA("%s: entering", __FUNCTION__);
-
- requestsQueue.destroy();
- CloseHandle(m_evRequestsQueue);
-
- debugLogA("%s: leaving", __FUNCTION__);
-}
-
-void CSteamProto::StartQueue()
-{
- debugLogA("%s: entering", __FUNCTION__);
-
- isTerminated = false;
-
- if (m_hQueueThread == NULL)
- {
- ptrA token(getStringA("TokenSecret"));
- if (token && token[0] != '\0')
- {
- PushRequest(
- new SteamWebApi::LogonRequest(token),
- &CSteamProto::OnLoggedOn);
- }
- else
- {
- ptrA username(mir_urlEncode(ptrA(mir_utf8encodeT(getTStringA("Username")))));
- if (username == NULL || username[0] == '\0')
- return;
-
- PushRequest(
- new SteamWebApi::RsaKeyRequest(username),
- &CSteamProto::OnGotRsaKey);
- }
-
- m_hQueueThread = ForkThreadEx(&CSteamProto::QueueThread, 0, NULL);
- }
-
- debugLogA("%s: leaving", __FUNCTION__);
-}
-
-void CSteamProto::StopQueue()
-{
- debugLogA("%s: entering", __FUNCTION__);
-
- isTerminated = true;
-
- {
- mir_cslock lock(requests_queue_lock);
-
- debugLogA("%s: requestsQueue contains %d items", __FUNCTION__, requestsQueue.getCount());
-
- while (requestsQueue.getCount() > 0)
- {
- QueueItem *item = requestsQueue[0];
- requestsQueue.remove(0);
-
- // QueueItem's destructor properly free request and arg
- delete item;
-
- debugLogA("%s: removed item from requestsQueue, %d items remaining", __FUNCTION__, requestsQueue.getCount());
- }
- }
-
- // logoff
- ptrA token(getStringA("TokenSecret"));
- ptrA umqid(getStringA("UMQID"));
-
- SteamWebApi::HttpRequest *request = new SteamWebApi::LogoffRequest(token, umqid);
- NETLIBHTTPREQUEST *response = request->Send(m_hNetlibUser);
- CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)response);
- delete request;
-
- m_hQueueThread = NULL;
-
- debugLogA("%s: leaving", __FUNCTION__);
-}
-
-void CSteamProto::PushRequest(SteamWebApi::HttpRequest *request)
-{
- PushRequest(request, NULL, NULL, ARG_NO_FREE);
-}
-
-void CSteamProto::PushRequest(SteamWebApi::HttpRequest *request, RESPONSE response)
-{
- PushRequest(request, response, NULL, ARG_NO_FREE);
-}
-
-void CSteamProto::PushRequest(SteamWebApi::HttpRequest *request, RESPONSE response, void *arg, ARG_FREE_TYPE arg_free_type)
-{
- debugLogA("%s: entering", __FUNCTION__);
-
- // Always prepare QueueItem so we can use it's destructor to free request and arg
- QueueItem *item = new QueueItem(request, response);
- item->arg = arg;
- item->arg_free_type = arg_free_type;
-
- if (isTerminated)
- {
- debugLogA("%s: leaving (isTerminated)", __FUNCTION__);
-
- // QueueItem's destructor properly free request and arg
- delete item;
- return;
- }
-
- {
- mir_cslock lock(requests_queue_lock);
- requestsQueue.insert(item);
- }
-
- SetEvent(m_evRequestsQueue);
-
- debugLogA("%s: leaving", __FUNCTION__);
-}
-
-void CSteamProto::ExecuteRequest(QueueItem *item)
-{
- debugLogA("%s: entering", __FUNCTION__);
-
- if (isTerminated)
- {
- debugLogA("%s: leaving (isTerminated)", __FUNCTION__);
-
- // QueueItem's destructor properly free request and arg
- delete item;
- return;
- }
-
- NETLIBHTTPREQUEST *response = item->request->Send(m_hNetlibUser);
-
- if (item->responseCallback != NULL)
- (this->*(item->responseCallback))(response, item->arg);
-
- // todo: add succeed and failed handlers if need
- if (response != NULL/* && response->resultCode != 200*/)
- {
- CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)response);
- }
- /*else if (requestItem->responseFailedCallback != NULL)
- {
- (this->*(requestItem->responseFailedCallback))(response);
- }*/
-
- delete item;
-
- debugLogA("%s: leaving", __FUNCTION__);
-}
-
-void CSteamProto::QueueThread(void*)
-{
- debugLogA("%s: entering", __FUNCTION__);
-
- while (!isTerminated)
- {
- WaitForSingleObject(m_evRequestsQueue, 1000);
-
- while (true)
- {
- QueueItem *item = NULL;
-
- {
- mir_cslock lock(requests_queue_lock);
-
- if (requestsQueue.getCount() == 0)
- break;
-
- item = requestsQueue[0];
- requestsQueue.remove(0);
- }
-
- if (item != NULL)
- ExecuteRequest(item);
- }
- }
-
- debugLogA("%s: leaving", __FUNCTION__);
+#include "stdafx.h" + +void CSteamProto::InitQueue() +{ + debugLogA("%s: entering", __FUNCTION__); + + m_evRequestsQueue = CreateEvent(NULL, FALSE, FALSE, NULL); + + debugLogA("%s: leaving", __FUNCTION__); +} + +void CSteamProto::UninitQueue() +{ + debugLogA("%s: entering", __FUNCTION__); + + requestsQueue.destroy(); + CloseHandle(m_evRequestsQueue); + + debugLogA("%s: leaving", __FUNCTION__); +} + +void CSteamProto::StartQueue() +{ + debugLogA("%s: entering", __FUNCTION__); + + isTerminated = false; + + if (m_hQueueThread == NULL) + { + ptrA token(getStringA("TokenSecret")); + if (token && token[0] != '\0') + { + PushRequest( + new SteamWebApi::LogonRequest(token), + &CSteamProto::OnLoggedOn); + } + else + { + ptrA username(mir_urlEncode(ptrA(mir_utf8encodeT(getTStringA("Username"))))); + if (username == NULL || username[0] == '\0') + return; + + PushRequest( + new SteamWebApi::RsaKeyRequest(username), + &CSteamProto::OnGotRsaKey); + } + + m_hQueueThread = ForkThreadEx(&CSteamProto::QueueThread, 0, NULL); + } + + debugLogA("%s: leaving", __FUNCTION__); +} + +void CSteamProto::StopQueue() +{ + debugLogA("%s: entering", __FUNCTION__); + + isTerminated = true; + + { + mir_cslock lock(requests_queue_lock); + + debugLogA("%s: requestsQueue contains %d items", __FUNCTION__, requestsQueue.getCount()); + + while (requestsQueue.getCount() > 0) + { + QueueItem *item = requestsQueue[0]; + requestsQueue.remove(0); + + // QueueItem's destructor properly free request and arg + delete item; + + debugLogA("%s: removed item from requestsQueue, %d items remaining", __FUNCTION__, requestsQueue.getCount()); + } + } + + // logoff + ptrA token(getStringA("TokenSecret")); + ptrA umqid(getStringA("UMQID")); + + SteamWebApi::HttpRequest *request = new SteamWebApi::LogoffRequest(token, umqid); + NETLIBHTTPREQUEST *response = request->Send(m_hNetlibUser); + if (response != NULL) + { + CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)response); + } + delete request; + + m_hQueueThread = NULL; + + debugLogA("%s: leaving", __FUNCTION__); +} + +void CSteamProto::PushRequest(SteamWebApi::HttpRequest *request) +{ + PushRequest(request, NULL, NULL, ARG_NO_FREE); +} + +void CSteamProto::PushRequest(SteamWebApi::HttpRequest *request, RESPONSE response) +{ + PushRequest(request, response, NULL, ARG_NO_FREE); +} + +void CSteamProto::PushRequest(SteamWebApi::HttpRequest *request, RESPONSE response, void *arg, ARG_FREE_TYPE arg_free_type) +{ + debugLogA("%s: entering", __FUNCTION__); + + // Always prepare QueueItem so we can use it's destructor to free request and arg + QueueItem *item = new QueueItem(request, response); + item->arg = arg; + item->arg_free_type = arg_free_type; + + if (isTerminated) + { + debugLogA("%s: leaving (isTerminated)", __FUNCTION__); + + // QueueItem's destructor properly free request and arg + delete item; + return; + } + + { + mir_cslock lock(requests_queue_lock); + requestsQueue.insert(item); + } + + SetEvent(m_evRequestsQueue); + + debugLogA("%s: leaving", __FUNCTION__); +} + +void CSteamProto::ExecuteRequest(QueueItem *item) +{ + debugLogA("%s: entering", __FUNCTION__); + + if (isTerminated) + { + debugLogA("%s: leaving (isTerminated)", __FUNCTION__); + + // QueueItem's destructor properly free request and arg + delete item; + return; + } + + NETLIBHTTPREQUEST *response = item->request->Send(m_hNetlibUser); + + if (item->responseCallback != NULL) + (this->*(item->responseCallback))(response, item->arg); + + // todo: add succeed and failed handlers if need + if (response != NULL/* && response->resultCode != 200*/) + { + CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)response); + } + /*else if (requestItem->responseFailedCallback != NULL) + { + (this->*(requestItem->responseFailedCallback))(response); + }*/ + + delete item; + + debugLogA("%s: leaving", __FUNCTION__); +} + +void CSteamProto::QueueThread(void*) +{ + debugLogA("%s: entering", __FUNCTION__); + + while (!isTerminated) + { + WaitForSingleObject(m_evRequestsQueue, 1000); + + while (true) + { + QueueItem *item = NULL; + + { + mir_cslock lock(requests_queue_lock); + + if (requestsQueue.getCount() == 0) + break; + + item = requestsQueue[0]; + requestsQueue.remove(0); + } + + if (item != NULL) + ExecuteRequest(item); + } + } + + debugLogA("%s: leaving", __FUNCTION__); }
\ No newline at end of file |