diff options
author | Alexander Lantsev <aunsane@gmail.com> | 2015-06-24 09:19:27 +0000 |
---|---|---|
committer | Alexander Lantsev <aunsane@gmail.com> | 2015-06-24 09:19:27 +0000 |
commit | a2ae51e943d855748962f4738dd9f87b96ad00b0 (patch) | |
tree | c847b6c22b05105f65f3a981e1e90302d9b95957 /protocols/Steam/src | |
parent | 799f5807fe6c3797787768b385e7e7c22a26a6c2 (diff) |
Steam: code cleanup
git-svn-id: http://svn.miranda-ng.org/main/trunk@14358 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/Steam/src')
-rw-r--r-- | protocols/Steam/src/request_queue.cpp | 5 | ||||
-rw-r--r-- | protocols/Steam/src/stdafx.h | 1 | ||||
-rw-r--r-- | protocols/Steam/src/steam_contacts.cpp | 16 | ||||
-rw-r--r-- | protocols/Steam/src/steam_login.cpp | 2 | ||||
-rw-r--r-- | protocols/Steam/src/steam_messages.cpp | 75 | ||||
-rw-r--r-- | protocols/Steam/src/steam_pooling.cpp | 4 | ||||
-rw-r--r-- | protocols/Steam/src/steam_proto.cpp | 17 | ||||
-rw-r--r-- | protocols/Steam/src/steam_proto.h | 30 | ||||
-rw-r--r-- | protocols/Steam/src/steam_request.cpp | 15 |
9 files changed, 66 insertions, 99 deletions
diff --git a/protocols/Steam/src/request_queue.cpp b/protocols/Steam/src/request_queue.cpp index 4e343a5118..c419ffbd26 100644 --- a/protocols/Steam/src/request_queue.cpp +++ b/protocols/Steam/src/request_queue.cpp @@ -78,16 +78,15 @@ void RequestQueue::Execute(RequestQueueItem *item) CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)response);
if (item->finallyCallback != NULL)
item->finallyCallback(item->arg);
- requests.remove(item);
delete item;
}
unsigned int RequestQueue::AsyncSendThread(void *owner, void *arg)
{
- RequestQueue *that = (RequestQueue*)owner;
+ RequestQueue *queue = (RequestQueue*)owner;
RequestQueueItem *item = (RequestQueueItem*)arg;
- that->Execute(item);
+ queue->Execute(item);
return 0;
}
diff --git a/protocols/Steam/src/stdafx.h b/protocols/Steam/src/stdafx.h index 7aecea533b..e0a3b694a6 100644 --- a/protocols/Steam/src/stdafx.h +++ b/protocols/Steam/src/stdafx.h @@ -29,6 +29,7 @@ #include <m_xstatus.h>
#include <m_extraicons.h>
#include <m_gui.h>
+#include <m_http.h>
#include <map>
#include <vector>
diff --git a/protocols/Steam/src/steam_contacts.cpp b/protocols/Steam/src/steam_contacts.cpp index 4c87e79575..117ae8bbe4 100644 --- a/protocols/Steam/src/steam_contacts.cpp +++ b/protocols/Steam/src/steam_contacts.cpp @@ -524,7 +524,7 @@ void CSteamProto::OnGotAvatar(const NETLIBHTTPREQUEST *response, void *arg) ai.hContact = (MCONTACT)arg; GetDbAvatarInfo(ai); - if (response == NULL || response->resultCode != HTTP_STATUS_OK) + if (response == NULL || response->resultCode != HTTP_CODE_OK) { ptrA steamId(getStringA(ai.hContact, "SteamID")); debugLogA("CSteamProto::OnGotAvatar: failed to get avatar %s", steamId); @@ -551,7 +551,7 @@ void CSteamProto::OnFriendAdded(const NETLIBHTTPREQUEST *response, void *arg) { SendAuthParam *param = (SendAuthParam*)arg; - if (response == NULL || response->resultCode != HTTP_STATUS_OK || lstrcmpiA(response->pData, "true")) + if (response == NULL || response->resultCode != HTTP_CODE_OK || lstrcmpiA(response->pData, "true")) { ptrA steamId(getStringA(param->hContact, "SteamID")); debugLogA("CSteamProto::OnFriendAdded: failed to add friend %s", steamId); @@ -570,7 +570,7 @@ void CSteamProto::OnFriendAdded(const NETLIBHTTPREQUEST *response, void *arg) void CSteamProto::OnFriendBlocked(const NETLIBHTTPREQUEST *response, void *arg) { - if (response == NULL || response->resultCode != HTTP_STATUS_OK || lstrcmpiA(response->pData, "true")) + if (response == NULL || response->resultCode != HTTP_CODE_OK || lstrcmpiA(response->pData, "true")) { debugLogA("CSteamProto::OnFriendIgnored: failed to ignore friend %s", (char*)arg); return; @@ -579,7 +579,7 @@ void CSteamProto::OnFriendBlocked(const NETLIBHTTPREQUEST *response, void *arg) void CSteamProto::OnFriendRemoved(const NETLIBHTTPREQUEST *response, void *arg) { - if (response == NULL || response->resultCode != HTTP_STATUS_OK || lstrcmpiA(response->pData, "true")) + if (response == NULL || response->resultCode != HTTP_CODE_OK || lstrcmpiA(response->pData, "true")) { MCONTACT hContact = (MCONTACT)arg; ptrA who(getStringA(hContact, "SteamID")); @@ -591,7 +591,7 @@ void CSteamProto::OnFriendRemoved(const NETLIBHTTPREQUEST *response, void *arg) void CSteamProto::OnAuthRequested(const NETLIBHTTPREQUEST *response, void *arg) { - if (response == NULL || response->resultCode != HTTP_STATUS_OK) + if (response == NULL || response->resultCode != HTTP_CODE_OK) { debugLogA("CSteamProto::OnAuthRequested: failed to request info for %s", (char*)arg); return; @@ -655,7 +655,7 @@ void CSteamProto::OnAuthRequested(const NETLIBHTTPREQUEST *response, void *arg) void CSteamProto::OnPendingApproved(const NETLIBHTTPREQUEST *response, void *arg) { - if (response == NULL || response->resultCode != HTTP_STATUS_OK) + if (response == NULL || response->resultCode != HTTP_CODE_OK) { debugLogA("CSteamProto::OnPendingApproved: failed to approve pending from %s", (char*)arg); return; @@ -675,7 +675,7 @@ void CSteamProto::OnPendingApproved(const NETLIBHTTPREQUEST *response, void *arg void CSteamProto::OnPendingIgnoreded(const NETLIBHTTPREQUEST *response, void *arg) { - if (response == NULL || response->resultCode != HTTP_STATUS_OK) + if (response == NULL || response->resultCode != HTTP_CODE_OK) { debugLogA("CSteamProto::OnPendingApproved: failed to ignore pending from %s", (char*)arg); return; @@ -695,7 +695,7 @@ void CSteamProto::OnPendingIgnoreded(const NETLIBHTTPREQUEST *response, void *ar void CSteamProto::OnSearchByIdEnded(const NETLIBHTTPREQUEST *response, void *arg) { - if (response == NULL || response->resultCode != HTTP_STATUS_OK) + if (response == NULL || response->resultCode != HTTP_CODE_OK) { ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_FAILED, (HANDLE)STEAM_SEARCH_BYID, 0); debugLogA("CSteamProto::OnSearchByIdEnded: failed to get summaries for %s", (char*)arg); diff --git a/protocols/Steam/src/steam_login.cpp b/protocols/Steam/src/steam_login.cpp index 6128428dbe..e52455a4d5 100644 --- a/protocols/Steam/src/steam_login.cpp +++ b/protocols/Steam/src/steam_login.cpp @@ -271,7 +271,7 @@ void CSteamProto::OnLoggedOn(const NETLIBHTTPREQUEST *response) JSONNode *node = json_get(root, "error");
ptrT error(json_as_string(node));
- if (mir_tstrcmpi(error, _T("OK")) || response->resultCode == HTTP_STATUS_UNAUTHORIZED)
+ if (mir_tstrcmpi(error, _T("OK")) || response->resultCode == HTTP_CODE_UNAUTHORIZED)
{
// Probably expired TokenSecret
HandleTokenExpired();
diff --git a/protocols/Steam/src/steam_messages.cpp b/protocols/Steam/src/steam_messages.cpp index 563923c919..fc49c7b0e8 100644 --- a/protocols/Steam/src/steam_messages.cpp +++ b/protocols/Steam/src/steam_messages.cpp @@ -1,17 +1,38 @@ #include "stdafx.h"
-//void CSteamProto::SendTypingThread(void *arg)
-//{
-// MCONTACT hContact = (MCONTACT)arg;
-//
-// ptrA token(getStringA("TokenSecret"));
-// ptrA umqId(getStringA("UMQID"));
-// ptrA steamId(getStringA(hContact, "SteamID"));
-//
-// MessageApi::SendResult sendResult;
-// debugLogA("CSteamProto::SendTypingThread: call PollApi::MessageApi::SendMessage");
-// MessageApi::SendTyping(m_hNetlibUser, token, umqId, steamId, &sendResult);
-//}
+struct SendMessageParam
+{
+ MCONTACT hContact;
+ HANDLE hMessage;
+ char *message;
+};
+
+void MessageParamFree(void *arg)
+{
+ SendMessageParam *param = (SendMessageParam*)arg;
+ mir_free(param->message);
+ mir_free(param);
+}
+
+int CSteamProto::OnSendMessage(MCONTACT hContact, const char* message)
+{
+ UINT hMessage = InterlockedIncrement(&hMessageProcess); + + SendMessageParam *param = (SendMessageParam*)mir_calloc(sizeof(SendMessageParam)); + param->hContact = hContact; + param->hMessage = (HANDLE)hMessage; + param->message = mir_strdup(message); + + ptrA token(getStringA("TokenSecret")); + ptrA umqid(getStringA("UMQID")); + ptrA steamId(getStringA(hContact, "SteamID")); + PushRequest( + new SendMessageRequest(token, umqid, steamId, message), + &CSteamProto::OnMessageSent, + param, MessageParamFree); + + return hMessage;
+}
void CSteamProto::OnMessageSent(const NETLIBHTTPREQUEST *response, void *arg)
{
@@ -20,7 +41,7 @@ void CSteamProto::OnMessageSent(const NETLIBHTTPREQUEST *response, void *arg) ptrT error(mir_tstrdup(TranslateT("Unknown error")));
ptrT steamId(getTStringA(param->hContact, "SteamID"));
- if (response != NULL && response->resultCode == HTTP_STATUS_OK)
+ if (response != NULL && response->resultCode == HTTP_CODE_OK)
{
JSONROOT root(response->pData);
JSONNode *node = json_get(root, "error");
@@ -28,29 +49,13 @@ void CSteamProto::OnMessageSent(const NETLIBHTTPREQUEST *response, void *arg) error = json_as_string(node);
}
- int status = ACKRESULT_FAILED;
-
- if (!mir_tstrcmpi(error, _T("OK")))
+ if (mir_tstrcmpi(error, _T("OK")) != 0)
{
- status = ACKRESULT_SUCCESS;
- error = NULL;
+ ptrA errorA(mir_t2a(error));
+ debugLogA("CSteamProto::OnMessageSent: failed to send message for %s (%s)", steamId, errorA);
+ ProtoBroadcastAck(param->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, param->hMessage, (LPARAM)errorA);
+ return;
}
- 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,
- (LPARAM) errorA);
-}
-void CSteamProto::MessageParamFree(void *arg)
-{
- SendMessageParam *param = (SendMessageParam*)arg;
- mir_free(param->message);
- mir_free(param);
+ ProtoBroadcastAck(param->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, param->hMessage, 0);
}
\ No newline at end of file diff --git a/protocols/Steam/src/steam_pooling.cpp b/protocols/Steam/src/steam_pooling.cpp index 71d1b20f0e..1233c9a7a0 100644 --- a/protocols/Steam/src/steam_pooling.cpp +++ b/protocols/Steam/src/steam_pooling.cpp @@ -180,7 +180,7 @@ void CSteamProto::PollingThread(void*) NETLIBHTTPREQUEST *response = request->Send(m_hNetlibUser); delete request; - if (response == NULL || response->resultCode != HTTP_STATUS_OK) + if (response == NULL || response->resultCode != HTTP_CODE_OK) { if (response != NULL) CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)response); @@ -233,7 +233,7 @@ void CSteamProto::PollingThread(void*) debugLog(_T("CSteamProto::PollingThread: %s (%d)"), error, response->resultCode); // token has expired - if (response->resultCode == HTTP_STATUS_UNAUTHORIZED) + if (response->resultCode == HTTP_CODE_UNAUTHORIZED) delSetting("TokenSecret"); // too low timeout? diff --git a/protocols/Steam/src/steam_proto.cpp b/protocols/Steam/src/steam_proto.cpp index c2e342e53f..2a626f5020 100644 --- a/protocols/Steam/src/steam_proto.cpp +++ b/protocols/Steam/src/steam_proto.cpp @@ -254,22 +254,7 @@ int CSteamProto::SendMsg(MCONTACT hContact, int, const char *message) return 0; } - UINT hMessage = InterlockedIncrement(&hMessageProcess); - - SendMessageParam *param = (SendMessageParam*)mir_calloc(sizeof(SendMessageParam)); - param->hContact = hContact; - param->hMessage = (HANDLE)hMessage; - param->message = mir_strdup(message); - - ptrA token(getStringA("TokenSecret")); - ptrA umqid(getStringA("UMQID")); - ptrA steamId(getStringA(hContact, "SteamID")); - PushRequest( - new SendMessageRequest(token, umqid, steamId, message), - &CSteamProto::OnMessageSent, - param, MessageParamFree); - - return hMessage; + return OnSendMessage(hContact, message); } int CSteamProto::SetStatus(int new_status) diff --git a/protocols/Steam/src/steam_proto.h b/protocols/Steam/src/steam_proto.h index 4b4dcaa40a..eed74c5c42 100644 --- a/protocols/Steam/src/steam_proto.h +++ b/protocols/Steam/src/steam_proto.h @@ -5,25 +5,12 @@ #define STEAM_SEARCH_BYNAME 1002
#define STEAM_TYPING_TIME 10
-struct PasswordParam
-{
- char password[513];
- char timestamp[16];
-};
-
struct SendAuthParam
{
MCONTACT hContact;
HANDLE hAuth;
};
-struct SendMessageParam
-{
- MCONTACT hContact;
- HANDLE hMessage;
- char *message;
-};
-
struct STEAM_SEARCH_RESULT
{
PROTOSEARCHRESULT hdr;
@@ -41,21 +28,6 @@ enum CMI_MAX // this item shall be the last one
};
-enum HTTP_STATUS
-{
- HTTP_STATUS_NONE = 0,
- HTTP_STATUS_OK = 200,
- HTTP_STATUS_FOUND = 302,
- HTTP_STATUS_BAD_REQUEST = 400,
- HTTP_STATUS_UNAUTHORIZED = 401,
- HTTP_STATUS_FORBIDDEN = 403,
- HTTP_STATUS_NOT_FOUND = 404,
- HTTP_STATUS_METHOD_NOT_ALLOWED = 405,
- HTTP_STATUS_TOO_MANY_REQUESTS = 429,
- HTTP_STATUS_SERVICE_UNAVAILABLE = 503,
- HTTP_STATUS_INSUFICIENTE_STORAGE = 507
-};
-
typedef void(CSteamProto::*SteamResponseCallback)(const NETLIBHTTPREQUEST *response);
typedef void(CSteamProto::*SteamResponseWithArgCallback)(const NETLIBHTTPREQUEST *response, void *arg);
@@ -183,8 +155,8 @@ protected: void OnSearchByNameFinished(const NETLIBHTTPREQUEST *response, void *arg);
// messages
+ int OnSendMessage(MCONTACT hContact, const char* message);
void OnMessageSent(const NETLIBHTTPREQUEST *response, void *arg);
- static void MessageParamFree(void *arg);
// menus
HGENMENU m_hMenuRoot;
diff --git a/protocols/Steam/src/steam_request.cpp b/protocols/Steam/src/steam_request.cpp index 05a7b235b1..c480628151 100644 --- a/protocols/Steam/src/steam_request.cpp +++ b/protocols/Steam/src/steam_request.cpp @@ -35,6 +35,11 @@ static void SteamHttpResponse(const NETLIBHTTPREQUEST *response, void *arg) {
SteamResponseDelegate *delegate = (SteamResponseDelegate*)arg;
delegate->Invoke(response);
+}
+
+void SteamResponseDelegateFree(void *arg)
+{
+ SteamResponseDelegate *delegate = (SteamResponseDelegate*)arg;
delete delegate;
}
@@ -46,28 +51,28 @@ void CSteamProto::PushRequest(HttpRequest *request) void CSteamProto::PushRequest(HttpRequest *request, SteamResponseCallback response)
{
SteamResponseDelegate *delegate = new SteamResponseDelegate(this, response);
- requestQueue->Push(request, SteamHttpResponse, delegate);
+ requestQueue->Push(request, SteamHttpResponse, delegate, SteamResponseDelegateFree);
}
void CSteamProto::PushRequest(HttpRequest *request, SteamResponseWithArgCallback response, void *arg, HttpFinallyCallback last)
{
SteamResponseDelegate *delegate = new SteamResponseDelegate(this, response, arg, last);
- requestQueue->Push(request, SteamHttpResponse, delegate);
+ requestQueue->Push(request, SteamHttpResponse, delegate, SteamResponseDelegateFree);
}
void CSteamProto::SendRequest(HttpRequest *request)
{
- requestQueue->Send(request, NULL, NULL);
+ requestQueue->Send(request);
}
void CSteamProto::SendRequest(HttpRequest *request, SteamResponseCallback response)
{
SteamResponseDelegate *delegate = new SteamResponseDelegate(this, response);
- requestQueue->Send(request, SteamHttpResponse, delegate);
+ requestQueue->Send(request, SteamHttpResponse, delegate, SteamResponseDelegateFree);
}
void CSteamProto::SendRequest(HttpRequest *request, SteamResponseWithArgCallback response, void *arg, HttpFinallyCallback last)
{
SteamResponseDelegate *delegate = new SteamResponseDelegate(this, response, arg, last);
- requestQueue->Send(request, SteamHttpResponse, delegate);
+ requestQueue->Send(request, SteamHttpResponse, delegate, SteamResponseDelegateFree);
}
|