diff options
-rw-r--r-- | protocols/Steam/src/steam_avatars.cpp | 3 | ||||
-rw-r--r-- | protocols/Steam/src/steam_contacts.cpp | 16 | ||||
-rw-r--r-- | protocols/Steam/src/steam_menus.cpp | 3 | ||||
-rw-r--r-- | protocols/Steam/src/steam_messages.cpp | 2 | ||||
-rw-r--r-- | protocols/Steam/src/steam_pooling.cpp | 3 | ||||
-rw-r--r-- | protocols/Steam/src/steam_proto.cpp | 28 | ||||
-rw-r--r-- | protocols/Steam/src/steam_proto.h | 28 | ||||
-rw-r--r-- | protocols/Steam/src/steam_queue.cpp | 37 |
8 files changed, 74 insertions, 46 deletions
diff --git a/protocols/Steam/src/steam_avatars.cpp b/protocols/Steam/src/steam_avatars.cpp index 22b80f1f26..b0d2cb0bbc 100644 --- a/protocols/Steam/src/steam_avatars.cpp +++ b/protocols/Steam/src/steam_avatars.cpp @@ -81,7 +81,8 @@ INT_PTR CSteamProto::GetAvatarInfo(WPARAM wParam, LPARAM lParam) PushRequest(
new SteamWebApi::GetAvatarRequest(avatarUrl),
&CSteamProto::OnGotAvatar,
- (void*)pai->hContact);
+ (void*)pai->hContact,
+ ARG_NO_FREE);
return GAIR_WAITFOR;
}
diff --git a/protocols/Steam/src/steam_contacts.cpp b/protocols/Steam/src/steam_contacts.cpp index 1ab84505ee..0bd0ddd959 100644 --- a/protocols/Steam/src/steam_contacts.cpp +++ b/protocols/Steam/src/steam_contacts.cpp @@ -572,7 +572,7 @@ void CSteamProto::OnFriendBlocked(const NETLIBHTTPREQUEST *response, void *arg) { if (response == NULL || response->resultCode != HTTP_STATUS_OK || lstrcmpiA(response->pData, "true")) { - debugLogA("CSteamProto::OnFriendIgnored: failed to ignore friend %s", ptrA((char*)arg)); + debugLogA("CSteamProto::OnFriendIgnored: failed to ignore friend %s", (char*)arg); return; } } @@ -593,7 +593,7 @@ void CSteamProto::OnAuthRequested(const NETLIBHTTPREQUEST *response, void *arg) { if (response == NULL || response->resultCode != HTTP_STATUS_OK) { - debugLogA("CSteamProto::OnAuthRequested: failed to request info for %s", ptrA((char*)arg)); + debugLogA("CSteamProto::OnAuthRequested: failed to request info for %s", (char*)arg); return; } @@ -657,7 +657,7 @@ void CSteamProto::OnPendingApproved(const NETLIBHTTPREQUEST *response, void *arg { if (response == NULL || response->resultCode != HTTP_STATUS_OK) { - debugLogA("CSteamProto::OnPendingApproved: failed to approve pending from %s", ptrA((char*)arg)); + debugLogA("CSteamProto::OnPendingApproved: failed to approve pending from %s", (char*)arg); return; } @@ -669,7 +669,7 @@ void CSteamProto::OnPendingApproved(const NETLIBHTTPREQUEST *response, void *arg if (json_as_int(node) == 0) { node = json_get(root, "error_text"); - debugLogA("CSteamProto::OnPendingApproved: failed to approve pending from %s (%s)", ptrA((char*)arg), ptrA(mir_utf8encodeW(ptrT(json_as_string(node))))); + debugLogA("CSteamProto::OnPendingApproved: failed to approve pending from %s (%s)", (char*)arg, ptrA(mir_utf8encodeW(ptrT(json_as_string(node))))); } } @@ -677,7 +677,7 @@ void CSteamProto::OnPendingIgnoreded(const NETLIBHTTPREQUEST *response, void *ar { if (response == NULL || response->resultCode != HTTP_STATUS_OK) { - debugLogA("CSteamProto::OnPendingApproved: failed to ignore pending from %s", ptrA((char*)arg)); + debugLogA("CSteamProto::OnPendingApproved: failed to ignore pending from %s", (char*)arg); return; } @@ -689,7 +689,7 @@ void CSteamProto::OnPendingIgnoreded(const NETLIBHTTPREQUEST *response, void *ar if (json_as_int(node) == 0) { node = json_get(root, "error_text"); - debugLogA("CSteamProto::OnPendingApproved: failed to ignore pending from %s (%s)", ptrA((char*)arg), ptrA(mir_utf8encodeW(ptrT(json_as_string(node))))); + debugLogA("CSteamProto::OnPendingApproved: failed to ignore pending from %s (%s)", (char*)arg, ptrA(mir_utf8encodeW(ptrT(json_as_string(node))))); } } @@ -698,7 +698,7 @@ void CSteamProto::OnSearchByIdEnded(const NETLIBHTTPREQUEST *response, void *arg if (response == NULL || response->resultCode != HTTP_STATUS_OK) { ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_FAILED, (HANDLE)STEAM_SEARCH_BYID, 0); - debugLogA("CSteamProto::OnSearchByIdEnded: failed to get summaries for %s", ptrA((char*)arg)); + debugLogA("CSteamProto::OnSearchByIdEnded: failed to get summaries for %s", (char*)arg); return; } @@ -716,7 +716,7 @@ void CSteamProto::OnSearchByIdEnded(const NETLIBHTTPREQUEST *response, void *arg ssr.hdr.cbSize = sizeof(STEAM_SEARCH_RESULT); ssr.hdr.flags = PSR_TCHAR; - ssr.hdr.id = (wchar_t*)arg; + ssr.hdr.id = (TCHAR*)arg; node = json_get(nroot, "personaname"); ssr.hdr.nick = mir_wstrdup(ptrT(json_as_string(node))); diff --git a/protocols/Steam/src/steam_menus.cpp b/protocols/Steam/src/steam_menus.cpp index 44c058b4f2..4ec5f32339 100644 --- a/protocols/Steam/src/steam_menus.cpp +++ b/protocols/Steam/src/steam_menus.cpp @@ -35,7 +35,8 @@ int CSteamProto::BlockCommand(WPARAM hContact, LPARAM) PushRequest(
new SteamWebApi::BlockFriendRequest(token, sessionId, steamId, who),
&CSteamProto::OnFriendBlocked,
- who);
+ who,
+ ARG_MIR_FREE);
return 0;
}
diff --git a/protocols/Steam/src/steam_messages.cpp b/protocols/Steam/src/steam_messages.cpp index ba6a98649e..418d57d814 100644 --- a/protocols/Steam/src/steam_messages.cpp +++ b/protocols/Steam/src/steam_messages.cpp @@ -48,6 +48,4 @@ void CSteamProto::OnMessageSent(const NETLIBHTTPREQUEST *response, void *arg) status,
param->hMessage,
error);
-
- mir_free(param);
}
\ No newline at end of file diff --git a/protocols/Steam/src/steam_pooling.cpp b/protocols/Steam/src/steam_pooling.cpp index 8eaef3baee..374ccc4caa 100644 --- a/protocols/Steam/src/steam_pooling.cpp +++ b/protocols/Steam/src/steam_pooling.cpp @@ -131,7 +131,8 @@ void CSteamProto::ParsePollData(JSONNODE *data) PushRequest( new SteamWebApi::GetUserSummariesRequest(token, steamId), &CSteamProto::OnAuthRequested, - mir_strdup(steamId)); + mir_strdup(steamId), + ARG_MIR_FREE); } break; diff --git a/protocols/Steam/src/steam_proto.cpp b/protocols/Steam/src/steam_proto.cpp index 5e796d06eb..1867187985 100644 --- a/protocols/Steam/src/steam_proto.cpp +++ b/protocols/Steam/src/steam_proto.cpp @@ -128,7 +128,8 @@ int __cdecl CSteamProto::Authorize(MEVENT hDbEvent) PushRequest( new SteamWebApi::ApprovePendingRequest(token, sessionId, steamId, who), &CSteamProto::OnPendingApproved, - who); + who, + ARG_MIR_FREE); return 0; } @@ -154,7 +155,8 @@ int __cdecl CSteamProto::AuthDeny(MEVENT hDbEvent, const TCHAR* szReason) PushRequest( new SteamWebApi::IgnorePendingRequest(token, sessionId, steamId, who), &CSteamProto::OnPendingIgnoreded, - who); + who, + ARG_MIR_FREE); return 0; } @@ -198,7 +200,8 @@ int __cdecl CSteamProto::AuthRequest(MCONTACT hContact, const TCHAR* szMessage) PushRequest( new SteamWebApi::AddFriendRequest(token, sessionId, steamId, who), &CSteamProto::OnFriendAdded, - param); + param, + ARG_MIR_FREE); return hAuth; } @@ -259,12 +262,13 @@ HANDLE __cdecl CSteamProto::SearchBasic(const TCHAR* id) //ForkThread(&CSteamProto::SearchByIdThread, mir_wstrdup(id)); ptrA token(getStringA("TokenSecret")); - ptrA steamId(mir_u2a(id)); + ptrA steamId(mir_t2a(id)); PushRequest( new SteamWebApi::GetUserSummariesRequest(token, steamId), &CSteamProto::OnSearchByIdEnded, - mir_wstrdup(id)); + mir_tstrdup(id), + ARG_MIR_FREE); return (HANDLE)STEAM_SEARCH_BYID; } @@ -287,9 +291,9 @@ HANDLE __cdecl CSteamProto::SearchByName(const TCHAR* nick, const TCHAR* firstNa keywords.AppendFormat(L" %s", lastName); keywords.Trim(); - //ForkThread(&CSteamProto::SearchByNameThread, mir_wstrdup(keywords)); + //ForkThread(&CSteamProto::SearchByNameThread, ptrT(mir_tstrdup(keywords))); PushRequest( - new SteamWebApi::SearchRequest(token, mir_utf8encodeW(keywords)), + new SteamWebApi::SearchRequest(token, ptrT(mir_utf8encodeT(keywords))), &CSteamProto::OnSearchByNameStarted); return (HANDLE)STEAM_SEARCH_BYNAME;*/ @@ -343,7 +347,8 @@ int __cdecl CSteamProto::SendMsg(MCONTACT hContact, int flags, const char *msg) PushRequest( new SteamWebApi::SendMessageRequest(token, umqid, steamId, message), &CSteamProto::OnMessageSent, - param); + param, + ARG_MIR_FREE); return hMessage; } @@ -377,9 +382,6 @@ int CSteamProto::SetStatus(int new_status) if (new_status == ID_STATUS_OFFLINE) { - //isTerminated = true; - //ForkThread(&CSteamProto::LogOutThread, NULL); - m_iStatus = m_iDesiredStatus = ID_STATUS_OFFLINE; ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)old_status, m_iStatus); @@ -393,7 +395,6 @@ int CSteamProto::SetStatus(int new_status) m_iStatus = ID_STATUS_CONNECTING; ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)old_status, m_iStatus); - //ForkThread(&CSteamProto::LogInThread, NULL); StartQueue(); } @@ -438,7 +439,8 @@ int __cdecl CSteamProto::OnEvent(PROTOEVENTTYPE eventType, WPARAM wParam, LPARAM PushRequest( new SteamWebApi::RemoveFriendRequest(token, sessionId, steamId, who), &CSteamProto::OnFriendRemoved, - (void*)hContact); + (void*)hContact, + ARG_NO_FREE); } return 0; diff --git a/protocols/Steam/src/steam_proto.h b/protocols/Steam/src/steam_proto.h index 705b2e080b..1ed62dff5c 100644 --- a/protocols/Steam/src/steam_proto.h +++ b/protocols/Steam/src/steam_proto.h @@ -62,12 +62,19 @@ enum HTTP_STATUS HTTP_STATUS_INSUFICIENTE_STORAGE = 507 }; +enum ARG_FREE_TYPE +{ + ARG_NO_FREE, + ARG_MIR_FREE +}; + typedef void (CSteamProto::*RESPONSE)(const NETLIBHTTPREQUEST *response, void *arg); struct QueueItem { SteamWebApi::HttpRequest *request; void *arg; + ARG_FREE_TYPE arg_free_type; RESPONSE responseCallback; //RESPONSE responseFailedCallback; @@ -80,7 +87,24 @@ struct QueueItem //QueueItem(SteamWebApi::HttpRequest *request, RESPONSE response, RESPONSE responseFailedCallback) : // request(request), arg(NULL), responseCallback(response), responseFailedCallback(responseFailedCallback) { } - ~QueueItem() { delete request; responseCallback = NULL; } + ~QueueItem() { + // Free request + delete request; + + // Free argument + switch (arg_free_type) + { + case ARG_NO_FREE: + break; + case ARG_MIR_FREE: + mir_free(arg); + default: + break; + } + + responseCallback = NULL; + //responseFailedCallback = NULL; + } }; class CSteamProto : public PROTO<CSteamProto> @@ -170,7 +194,7 @@ protected: void PushRequest(SteamWebApi::HttpRequest *request); void PushRequest(SteamWebApi::HttpRequest *request, RESPONSE response); - void PushRequest(SteamWebApi::HttpRequest *request, RESPONSE response, void *arg); + void PushRequest(SteamWebApi::HttpRequest *request, RESPONSE response, void *arg, ARG_FREE_TYPE arg_free_type); void ExecuteRequest(QueueItem *requestItem); diff --git a/protocols/Steam/src/steam_queue.cpp b/protocols/Steam/src/steam_queue.cpp index 54cb2de4fc..ff61da24a7 100644 --- a/protocols/Steam/src/steam_queue.cpp +++ b/protocols/Steam/src/steam_queue.cpp @@ -28,10 +28,13 @@ void CSteamProto::StartQueue() }
else
{
- ptrA username(mir_urlEncode(ptrA(mir_utf8encodeW(getWStringA("Username")))));
+ ptrA username(mir_urlEncode(ptrA(mir_utf8encodeT(getTStringA("Username")))));
if (username == NULL || username[0] == '\0')
return;
- PushRequest(new SteamWebApi::RsaKeyRequest(username), (RESPONSE)&CSteamProto::OnGotRsaKey);
+
+ PushRequest(
+ new SteamWebApi::RsaKeyRequest(username),
+ &CSteamProto::OnGotRsaKey);
}
m_hQueueThread = ForkThreadEx(&CSteamProto::QueueThread, 0, NULL);
@@ -50,9 +53,8 @@ void CSteamProto::StopQueue() QueueItem *item = requestsQueue[0];
requestsQueue.remove(0);
- // We call ExecuteRequest() but as we have set isTerminated=true it will only run callback to behave correctly (free arguments, raise errors, etc.)
- if (item != NULL)
- ExecuteRequest(item);
+ // QueueItem's destructor properly free request and arg
+ delete item;
}
}
@@ -72,29 +74,30 @@ void CSteamProto::StopQueue() void CSteamProto::PushRequest(SteamWebApi::HttpRequest *request)
{
- PushRequest(request, NULL, NULL);
+ PushRequest(request, NULL, NULL, ARG_NO_FREE);
}
void CSteamProto::PushRequest(SteamWebApi::HttpRequest *request, RESPONSE response)
{
- PushRequest(request, response, NULL);
+ PushRequest(request, response, NULL, ARG_NO_FREE);
}
-void CSteamProto::PushRequest(SteamWebApi::HttpRequest *request, RESPONSE response, void *arg)
+void CSteamProto::PushRequest(SteamWebApi::HttpRequest *request, RESPONSE response, void *arg, ARG_FREE_TYPE arg_free_type)
{
+ // 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)
{
- // Call response callback so it can react properly (free arguments, raise errors, etc.)
- if (response != NULL)
- (this->*(response))(NULL, arg);
-
+ // QueueItem's destructor properly free request and arg
+ delete item;
return;
}
{
mir_cslock lock(requests_queue_lock);
- QueueItem *item = new QueueItem(request, response);
- item->arg = arg;
requestsQueue.insert(item);
}
@@ -105,10 +108,8 @@ void CSteamProto::ExecuteRequest(QueueItem *item) {
if (isTerminated)
{
- // Call response callback so it can react properly (free arguments, raise errors, etc.)
- if (item->responseCallback != NULL)
- (this->*(item->responseCallback))(NULL, item->arg);
-
+ // QueueItem's destructor properly free request and arg
+ delete item;
return;
}
|