summaryrefslogtreecommitdiff
path: root/protocols/Steam
diff options
context:
space:
mode:
authorRobert Pösel <robyer@seznam.cz>2014-11-28 12:58:45 +0000
committerRobert Pösel <robyer@seznam.cz>2014-11-28 12:58:45 +0000
commit2de6603f69b343c3245043ab4c05292a617bd9ba (patch)
treea0930902daee55144d130a6bc77f8a22fedca4cc /protocols/Steam
parent8817909629b3e0881672a7b7324fc7c583c331ad (diff)
Use JSONROOT everywhere to simplify code and fix memleaks (in Dropbox and Steam)
git-svn-id: http://svn.miranda-ng.org/main/trunk@11130 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/Steam')
-rw-r--r--protocols/Steam/src/Steam/crypto.h4
-rw-r--r--protocols/Steam/src/Steam/message.h4
-rw-r--r--protocols/Steam/src/steam_account.cpp35
-rw-r--r--protocols/Steam/src/steam_contacts.cpp76
-rw-r--r--protocols/Steam/src/steam_messages.cpp7
-rw-r--r--protocols/Steam/src/steam_pooling.cpp6
6 files changed, 52 insertions, 80 deletions
diff --git a/protocols/Steam/src/Steam/crypto.h b/protocols/Steam/src/Steam/crypto.h
index 553e311cf7..729dc2a591 100644
--- a/protocols/Steam/src/Steam/crypto.h
+++ b/protocols/Steam/src/Steam/crypto.h
@@ -99,10 +99,10 @@ namespace SteamWebApi
if (!response || response->resultCode != HTTP_STATUS_OK)
return;
- JSONNODE *root = json_parse(response->pData), *node;
+ JSONROOT root(response->pData);
if (!root) return;
- node = json_get(root, "success");
+ JSONNODE *node = json_get(root, "success");
if (!json_as_bool(node)) return;
node = json_get(root, "publickey_mod");
diff --git a/protocols/Steam/src/Steam/message.h b/protocols/Steam/src/Steam/message.h
index b75d2f7965..b14dff4446 100644
--- a/protocols/Steam/src/Steam/message.h
+++ b/protocols/Steam/src/Steam/message.h
@@ -65,9 +65,9 @@ namespace SteamWebApi
// if ((sendResult->status = (HTTP_STATUS)response->resultCode) != HTTP_STATUS_OK)
// return;
- // JSONNODE *root = json_parse(response->pData), *node;
+ // JSONROOT root(response->pData);
- // node = json_get(root, "error");
+ // JSONNODE *node = json_get(root, "error");
// ptrW error(json_as_string(node));
// if (lstrcmp(error, L"OK"))
diff --git a/protocols/Steam/src/steam_account.cpp b/protocols/Steam/src/steam_account.cpp
index fa4cdf1804..b428896fcc 100644
--- a/protocols/Steam/src/steam_account.cpp
+++ b/protocols/Steam/src/steam_account.cpp
@@ -20,13 +20,12 @@ void CSteamProto::OnGotRsaKey(const NETLIBHTTPREQUEST *response, void *arg)
return;
// load rsa key parts
- JSONNODE *root = json_parse(response->pData), *node;
+ JSONROOT root(response->pData);
if (!root)
return;
- node = json_get(root, "success");
+ JSONNODE *node = json_get(root, "success");
if (!json_as_bool(node)) {
- json_delete(root);
return;
}
@@ -45,8 +44,6 @@ void CSteamProto::OnGotRsaKey(const NETLIBHTTPREQUEST *response, void *arg)
ptrA base64RsaEncryptedPassword;
ptrA password(getStringA("Password"));
- json_delete(root);
-
DWORD error = 0;
DWORD encryptedSize = 0;
DWORD passwordSize = (DWORD)strlen(password);
@@ -83,9 +80,9 @@ void CSteamProto::OnAuthorization(const NETLIBHTTPREQUEST *response, void *arg)
return;
}
- JSONNODE *root = json_parse(response->pData), *node;
+ JSONROOT root(response->pData);
- node = json_get(root, "success");
+ JSONNODE *node = json_get(root, "success");
if (json_as_bool(node) == 0)
{
node = json_get(root, "message");
@@ -94,7 +91,6 @@ void CSteamProto::OnAuthorization(const NETLIBHTTPREQUEST *response, void *arg)
{
ShowNotification(TranslateTS(message));
SetStatus(ID_STATUS_OFFLINE);
- json_delete(root);
return;
}
@@ -110,13 +106,7 @@ void CSteamProto::OnAuthorization(const NETLIBHTTPREQUEST *response, void *arg)
GuardParam guard;
lstrcpyA(guard.domain, emailDomain);
- if (DialogBoxParam(
- g_hInstance,
- MAKEINTRESOURCE(IDD_GUARD),
- NULL,
- CSteamProto::GuardProc,
- (LPARAM)&guard) != 1) {
- json_delete(root);
+ if (DialogBoxParam(g_hInstance, MAKEINTRESOURCE(IDD_GUARD), NULL, CSteamProto::GuardProc, (LPARAM)&guard) != 1) {
return;
}
@@ -162,7 +152,6 @@ void CSteamProto::OnAuthorization(const NETLIBHTTPREQUEST *response, void *arg)
if (res != 1)
{
SetStatus(ID_STATUS_OFFLINE);
- json_delete(root);
return;
}
@@ -175,7 +164,6 @@ void CSteamProto::OnAuthorization(const NETLIBHTTPREQUEST *response, void *arg)
&CSteamProto::OnAuthorization);
}
- json_delete(root);
return;
}
@@ -183,12 +171,11 @@ void CSteamProto::OnAuthorization(const NETLIBHTTPREQUEST *response, void *arg)
if (!json_as_bool(node))
{
SetStatus(ID_STATUS_OFFLINE);
- json_delete(root);
return;
}
node = json_get(root, "oauth");
- JSONNODE *nroot = json_parse(ptrA(mir_u2a(json_as_string(node))));
+ JSONROOT nroot(ptrA(mir_u2a(json_as_string(node))));
node = json_get(nroot, "steamid");
ptrA steamId(mir_u2a(json_as_string(node)));
@@ -204,9 +191,6 @@ void CSteamProto::OnAuthorization(const NETLIBHTTPREQUEST *response, void *arg)
delSetting("Timestamp");
delSetting("EncryptedPassword");
- json_delete(nroot);
- json_delete(root);
-
PushRequest(
new SteamWebApi::GetSessionRequest(token, steamId, cookie),
&CSteamProto::OnGotSession);
@@ -244,9 +228,9 @@ void CSteamProto::OnLoggedOn(const NETLIBHTTPREQUEST *response, void *arg)
return;
}
- JSONNODE *root = json_parse(response->pData), *node;
+ JSONROOT root(response->pData);
- node = json_get(root, "error");
+ JSONNODE *node = json_get(root, "error");
ptrW error(json_as_string(node));
if (lstrcmpi(error, L"OK")/* || response->resultCode == HTTP_STATUS_UNAUTHORIZED*/)
{
@@ -256,7 +240,6 @@ void CSteamProto::OnLoggedOn(const NETLIBHTTPREQUEST *response, void *arg)
// set status to offline
m_iStatus = m_iDesiredStatus = ID_STATUS_OFFLINE;
ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)ID_STATUS_CONNECTING, ID_STATUS_OFFLINE);
- json_delete(root);
return;
}
@@ -266,8 +249,6 @@ void CSteamProto::OnLoggedOn(const NETLIBHTTPREQUEST *response, void *arg)
node = json_get(root, "message");
setDword("MessageID", json_as_int(node));
- json_delete(root);
-
// load contact list
ptrA token(getStringA("TokenSecret"));
ptrA steamId(getStringA("SteamID"));
diff --git a/protocols/Steam/src/steam_contacts.cpp b/protocols/Steam/src/steam_contacts.cpp
index 797ae0e166..884c1f9c59 100644
--- a/protocols/Steam/src/steam_contacts.cpp
+++ b/protocols/Steam/src/steam_contacts.cpp
@@ -185,20 +185,19 @@ void CSteamProto::OnGotFriendList(const NETLIBHTTPREQUEST *response, void *arg)
if (response == NULL)
return;
- JSONNODE *root = json_parse(response->pData), *node, *child;
-
+ JSONROOT root(response->pData);
if (root == NULL)
return;
std::string steamIds;
- node = json_get(root, "friends");
- root = json_as_array(node);
- if (root != NULL)
+ JSONNODE *node = json_get(root, "friends");
+ JSONNODE *nroot = json_as_array(node);
+ if (nroot != NULL)
{
- for (size_t i = 0; i < json_size(root); i++)
+ for (size_t i = 0; i < json_size(nroot); i++)
{
- child = json_at(root, i);
+ JSONNODE *child = json_at(nroot, i);
if (child == NULL)
break;
@@ -236,8 +235,6 @@ void CSteamProto::OnGotFriendList(const NETLIBHTTPREQUEST *response, void *arg)
}
}
- json_delete(root);
-
if (!steamIds.empty())
{
steamIds.pop_back();
@@ -254,20 +251,19 @@ void CSteamProto::OnGotBlockList(const NETLIBHTTPREQUEST *response, void *arg)
if (response == NULL)
return;
- JSONNODE *root = json_parse(response->pData), *node, *child;
-
+ JSONROOT root(response->pData);
if (root == NULL)
return;
//std::string steamIds;
- node = json_get(root, "friends");
+ JSONNODE *node = json_get(root, "friends");
JSONNODE *nroot = json_as_array(node);
if (nroot != NULL)
{
for (size_t i = 0; i < json_size(nroot); i++)
{
- child = json_at(nroot, i);
+ JSONNODE *child = json_at(nroot, i);
if (child == NULL)
break;
@@ -291,8 +287,6 @@ void CSteamProto::OnGotBlockList(const NETLIBHTTPREQUEST *response, void *arg)
else continue;
}
}
-
- json_delete(root);
}
void CSteamProto::OnGotUserSummaries(const NETLIBHTTPREQUEST *response, void *arg)
@@ -300,15 +294,17 @@ void CSteamProto::OnGotUserSummaries(const NETLIBHTTPREQUEST *response, void *ar
if (response == NULL)
return;
- JSONNODE *root = json_parse(response->pData), *node, *item;
-
- node = json_get(root, "players");
+ JSONROOT root(response->pData);
+ if (root == NULL)
+ return;
+
+ JSONNODE *node = json_get(root, "players");
JSONNODE *nroot = json_as_array(node);
if (nroot != NULL)
{
for (size_t i = 0; i < json_size(nroot); i++)
{
- item = json_at(nroot, i);
+ JSONNODE *item = json_at(nroot, i);
if (item == NULL)
break;
@@ -322,8 +318,6 @@ void CSteamProto::OnGotUserSummaries(const NETLIBHTTPREQUEST *response, void *ar
UpdateContact(hContact, item);
}
}
-
- json_delete(root);
}
void CSteamProto::OnGotAvatar(const NETLIBHTTPREQUEST *response, void *arg)
@@ -400,9 +394,11 @@ void CSteamProto::OnAuthRequested(const NETLIBHTTPREQUEST *response, void *arg)
return;
}
- JSONNODE *root = json_parse(response->pData), *node;
+ JSONROOT root(response->pData);
+ if (root == NULL)
+ return;
- node = json_get(root, "players");
+ JSONNODE *node = json_get(root, "players");
JSONNODE *nroot = json_at(json_as_array(node), 0);
if (nroot != NULL)
{
@@ -448,8 +444,6 @@ void CSteamProto::OnAuthRequested(const NETLIBHTTPREQUEST *response, void *arg)
AddDBEvent(hContact, EVENTTYPE_AUTHREQUEST, time(NULL), DBEF_UTF, cbBlob, pBlob);
}
-
- json_delete(root);
}
void CSteamProto::OnPendingApproved(const NETLIBHTTPREQUEST *response, void *arg)
@@ -460,16 +454,16 @@ void CSteamProto::OnPendingApproved(const NETLIBHTTPREQUEST *response, void *arg
return;
}
- JSONNODE *root = json_parse(response->pData), *node;
+ JSONROOT root(response->pData);
+ if (root == NULL)
+ return;
- node = json_get(root, "success");
+ JSONNODE *node = json_get(root, "success");
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(json_as_string(node))));
}
-
- json_delete(root);
}
void CSteamProto::OnPendingIgnoreded(const NETLIBHTTPREQUEST *response, void *arg)
@@ -480,16 +474,16 @@ void CSteamProto::OnPendingIgnoreded(const NETLIBHTTPREQUEST *response, void *ar
return;
}
- JSONNODE *root = json_parse(response->pData), *node;
+ JSONROOT root(response->pData);
+ if (root == NULL)
+ return;
- node = json_get(root, "success");
+ JSONNODE *node = json_get(root, "success");
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(json_as_string(node))));
}
-
- json_delete(root);
}
void CSteamProto::OnSearchByIdEnded(const NETLIBHTTPREQUEST *response, void *arg)
@@ -501,11 +495,13 @@ void CSteamProto::OnSearchByIdEnded(const NETLIBHTTPREQUEST *response, void *arg
return;
}
- JSONNODE *root = json_parse(response->pData), *node;
+ JSONROOT root(response->pData);
+ if (root == NULL)
+ return;
- node = json_get(root, "players");
- root = json_at(json_as_array(node), 0);
- if (root != NULL)
+ JSONNODE *node = json_get(root, "players");
+ JSONNODE *nroot = json_at(json_as_array(node), 0);
+ if (nroot != NULL)
{
STEAM_SEARCH_RESULT ssr = { 0 };
ssr.hdr.cbSize = sizeof(STEAM_SEARCH_RESULT);
@@ -513,10 +509,10 @@ void CSteamProto::OnSearchByIdEnded(const NETLIBHTTPREQUEST *response, void *arg
ssr.hdr.id = (wchar_t*)arg;
- node = json_get(root, "personaname");
+ node = json_get(nroot, "personaname");
ssr.hdr.nick = mir_wstrdup(json_as_string(node));
- node = json_get(root, "realname");
+ node = json_get(nroot, "realname");
if (node != NULL)
{
std::wstring realname = json_as_string(node);
@@ -534,7 +530,7 @@ void CSteamProto::OnSearchByIdEnded(const NETLIBHTTPREQUEST *response, void *arg
}
//ssr.contact = contact;
- ssr.data = json_copy(root);
+ ssr.data = json_copy(nroot);
ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_DATA, (HANDLE)STEAM_SEARCH_BYID, (LPARAM)&ssr);
ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, (HANDLE)STEAM_SEARCH_BYID, 0);
diff --git a/protocols/Steam/src/steam_messages.cpp b/protocols/Steam/src/steam_messages.cpp
index 9cd76f3b0f..7e6e07c315 100644
--- a/protocols/Steam/src/steam_messages.cpp
+++ b/protocols/Steam/src/steam_messages.cpp
@@ -23,16 +23,13 @@ void CSteamProto::OnMessageSent(const NETLIBHTTPREQUEST *response, void *arg)
if (response != NULL && response->resultCode == HTTP_STATUS_OK)
{
- JSONNODE *root = json_parse(response->pData), *node;
-
- node = json_get(root, "error");
+ JSONROOT root(response->pData);
+ JSONNODE *node = json_get(root, "error");
ptrA error(mir_utf8encodeW(json_as_string(node)));
if (lstrcmpiA(error, "OK") == 0)
result = true;
else
debugLogA("CSteamProto::OnMessageSent: failed to send message for %s (%s)", steamId, error);
-
- json_delete(root);
}
else
debugLogA("CSteamProto::OnMessageSent: failed to send message for %s", steamId);
diff --git a/protocols/Steam/src/steam_pooling.cpp b/protocols/Steam/src/steam_pooling.cpp
index 2c07872fe3..78ac23e53c 100644
--- a/protocols/Steam/src/steam_pooling.cpp
+++ b/protocols/Steam/src/steam_pooling.cpp
@@ -188,8 +188,8 @@ void CSteamProto::PollingThread(void*)
if (response == NULL || response->resultCode != HTTP_STATUS_OK)
return;
- JSONNODE *root = json_parse(response->pData), *node;
- node = json_get(root, "error");
+ JSONROOT root(response->pData);
+ JSONNODE *node = json_get(root, "error");
ptrW error(json_as_string(node));
if (!lstrcmpi(error, L"OK"))
@@ -207,7 +207,6 @@ void CSteamProto::PollingThread(void*)
}
else if (!lstrcmpi(error, L"Timeout"))
{
- json_delete(root);
continue;
}
/*else if (!lstrcmpi(error, L"Not Logged On")) // 'else' below will handle this error, we don't need this particular check right now
@@ -234,7 +233,6 @@ void CSteamProto::PollingThread(void*)
breaked = true;
}
- json_delete(root);
CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)response);
}