summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Pösel <robyer@seznam.cz>2014-12-20 19:10:28 +0000
committerRobert Pösel <robyer@seznam.cz>2014-12-20 19:10:28 +0000
commitc913257a1eb9b0fdcac33c1b45b309261048f761 (patch)
treecabe9ffbcceb441dba46626257eb463be03e002a
parentc85f29701349a22dadca357c770296b7e8475db1 (diff)
Steam: Various code improvements (as reported by Coverity analyser); version bump
git-svn-id: http://svn.miranda-ng.org/main/trunk@11544 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rw-r--r--plugins/Libs/bz2/BLOCKS~1.OBJbin11771 -> 0 bytes
-rw-r--r--plugins/Libs/bz2/DECOMP~1.OBJbin15653 -> 0 bytes
-rw-r--r--protocols/Steam/src/Steam/message.h2
-rw-r--r--protocols/Steam/src/steam_account.cpp35
-rw-r--r--protocols/Steam/src/steam_contacts.cpp73
-rw-r--r--protocols/Steam/src/steam_menus.cpp2
-rw-r--r--protocols/Steam/src/steam_messages.cpp2
-rw-r--r--protocols/Steam/src/steam_pooling.cpp13
-rw-r--r--protocols/Steam/src/steam_proto.cpp15
-rw-r--r--protocols/Steam/src/steam_utils.cpp57
-rw-r--r--protocols/Steam/src/version.h2
11 files changed, 122 insertions, 79 deletions
diff --git a/plugins/Libs/bz2/BLOCKS~1.OBJ b/plugins/Libs/bz2/BLOCKS~1.OBJ
deleted file mode 100644
index df6ef1bdb7..0000000000
--- a/plugins/Libs/bz2/BLOCKS~1.OBJ
+++ /dev/null
Binary files differ
diff --git a/plugins/Libs/bz2/DECOMP~1.OBJ b/plugins/Libs/bz2/DECOMP~1.OBJ
deleted file mode 100644
index 989a17da81..0000000000
--- a/plugins/Libs/bz2/DECOMP~1.OBJ
+++ /dev/null
Binary files differ
diff --git a/protocols/Steam/src/Steam/message.h b/protocols/Steam/src/Steam/message.h
index c5bac75aff..82cfc0b5ad 100644
--- a/protocols/Steam/src/Steam/message.h
+++ b/protocols/Steam/src/Steam/message.h
@@ -74,7 +74,7 @@ namespace SteamWebApi
// return;
// node = json_get(root, "utc_timestamp");
- // sendResult->timestamp = atol(ptrA(mir_u2a(json_as_string(node))));
+ // sendResult->timestamp = atol(ptrA(mir_u2a(ptrT(json_as_string(node)))));
// sendResult->success = true;
// }
diff --git a/protocols/Steam/src/steam_account.cpp b/protocols/Steam/src/steam_account.cpp
index e1316a2521..7e16e5b850 100644
--- a/protocols/Steam/src/steam_account.cpp
+++ b/protocols/Steam/src/steam_account.cpp
@@ -30,14 +30,14 @@ void CSteamProto::OnGotRsaKey(const NETLIBHTTPREQUEST *response, void *arg)
}
node = json_get(root, "publickey_mod");
- ptrA modulus(mir_u2a(json_as_string(node)));
+ ptrA modulus(mir_u2a(ptrT(json_as_string(node))));
// exponent "010001" is used as constant in CSteamProto::RsaEncrypt
/*node = json_get(root, "publickey_exp");
- ptrA exponent(mir_u2a(json_as_string(node)));*/
+ ptrA exponent(mir_u2a(ptrT(json_as_string(node))));*/
node = json_get(root, "timestamp");
- ptrA timestamp(mir_u2a(json_as_string(node)));
+ ptrA timestamp(mir_u2a(ptrT(json_as_string(node))));
setString("Timestamp", timestamp);
// encrcrypt password
@@ -86,8 +86,8 @@ void CSteamProto::OnAuthorization(const NETLIBHTTPREQUEST *response, void *arg)
if (json_as_bool(node) == 0)
{
node = json_get(root, "message");
- const wchar_t *message = json_as_string(node);
- if (!lstrcmpi(json_as_string(node), L"Incorrect login"))
+ ptrT message(json_as_string(node));
+ if (!lstrcmpi(message, L"Incorrect login"))
{
ShowNotification(TranslateTS(message));
SetStatus(ID_STATUS_OFFLINE);
@@ -98,13 +98,13 @@ void CSteamProto::OnAuthorization(const NETLIBHTTPREQUEST *response, void *arg)
if (json_as_bool(node) > 0)
{
node = json_get(root, "emailsteamid");
- ptrA guardId(mir_u2a(json_as_string(node)));
+ ptrA guardId(mir_u2a(ptrT(json_as_string(node))));
node = json_get(root, "emaildomain");
- ptrA emailDomain(mir_utf8encodeW(json_as_string(node)));
+ ptrA emailDomain(mir_utf8encodeW(ptrT(json_as_string(node))));
GuardParam guard;
- lstrcpyA(guard.domain, emailDomain);
+ mir_strncpy(guard.domain, emailDomain, SIZEOF(guard.domain));
if (DialogBoxParam(g_hInstance, MAKEINTRESOURCE(IDD_GUARD), NULL, CSteamProto::GuardProc, (LPARAM)&guard) != 1) {
return;
@@ -123,7 +123,7 @@ void CSteamProto::OnAuthorization(const NETLIBHTTPREQUEST *response, void *arg)
if (json_as_bool(node) > 0)
{
node = json_get(root, "captcha_gid");
- ptrA captchaId(mir_u2a(json_as_string(node)));
+ ptrA captchaId(mir_u2a(ptrT(json_as_string(node))));
char url[MAX_PATH];
mir_snprintf(url, SIZEOF(url), STEAM_COM_URL "/public/captcha.php?gid=%s", captchaId);
@@ -175,18 +175,18 @@ void CSteamProto::OnAuthorization(const NETLIBHTTPREQUEST *response, void *arg)
}
node = json_get(root, "oauth");
- JSONROOT nroot(ptrA(mir_u2a(json_as_string(node))));
+ JSONROOT nroot(_T2A(ptrT(json_as_string(node))));
node = json_get(nroot, "steamid");
- ptrA steamId(mir_u2a(json_as_string(node)));
+ ptrA steamId(mir_u2a(ptrT(json_as_string(node))));
setString("SteamID", steamId);
node = json_get(nroot, "oauth_token");
- ptrA token(mir_u2a(json_as_string(node)));
+ ptrA token(mir_u2a(ptrT(json_as_string(node))));
setString("TokenSecret", token);
node = json_get(nroot, "webcookie");
- ptrA cookie(mir_u2a(json_as_string(node)));
+ ptrA cookie(mir_u2a(ptrT(json_as_string(node))));
delSetting("Timestamp");
delSetting("EncryptedPassword");
@@ -223,9 +223,7 @@ void CSteamProto::OnLoggedOn(const NETLIBHTTPREQUEST *response, void *arg)
{
if (response == NULL)
{
- // set status to offline
- m_iStatus = m_iDesiredStatus = ID_STATUS_OFFLINE;
- ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)ID_STATUS_CONNECTING, ID_STATUS_OFFLINE);
+ SetStatus(ID_STATUS_OFFLINE);
return;
}
@@ -239,13 +237,12 @@ void CSteamProto::OnLoggedOn(const NETLIBHTTPREQUEST *response, void *arg)
//delSetting("Cookie");
// set status to offline
- m_iStatus = m_iDesiredStatus = ID_STATUS_OFFLINE;
- ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)ID_STATUS_CONNECTING, ID_STATUS_OFFLINE);
+ SetStatus(ID_STATUS_OFFLINE);
return;
}
node = json_get(root, "umqid");
- setString("UMQID", ptrA(mir_u2a(json_as_string(node))));
+ setString("UMQID", ptrA(mir_u2a(ptrT(json_as_string(node)))));
node = json_get(root, "message");
setDword("MessageID", json_as_int(node));
diff --git a/protocols/Steam/src/steam_contacts.cpp b/protocols/Steam/src/steam_contacts.cpp
index c1705f8ebb..d952d7991e 100644
--- a/protocols/Steam/src/steam_contacts.cpp
+++ b/protocols/Steam/src/steam_contacts.cpp
@@ -102,19 +102,19 @@ void CSteamProto::UpdateContact(MCONTACT hContact, JSONNODE *data)
// set common data
node = json_get(data, "personaname");
- setTString(hContact, "Nick", json_as_string(node));
+ setTString(hContact, "Nick", ptrT(json_as_string(node)));
node = json_get(data, "profileurl");
- setString(hContact, "Homepage", _T2A(json_as_string(node)));
+ setString(hContact, "Homepage", _T2A(ptrT(json_as_string(node))));
node = json_get(data, "primaryclanid");
- setString(hContact, "PrimaryClanID", _T2A(json_as_string(node)));
+ setString(hContact, "PrimaryClanID", _T2A(ptrT(json_as_string(node))));
// set name
node = json_get(data, "realname");
if (node != NULL)
{
- std::wstring realname = json_as_string(node);
+ std::wstring realname = ptrT(json_as_string(node));
if (!realname.empty())
{
size_t pos = realname.find(L' ', 1);
@@ -139,14 +139,14 @@ void CSteamProto::UpdateContact(MCONTACT hContact, JSONNODE *data)
// avatar
bool biggerAvatars = getBool("UseBigAvatars", false);
node = json_get(data, biggerAvatars ? "avatarfull" : "avatarmedium");
- std::string avatarUrl = _T2A(json_as_string(node));
+ std::string avatarUrl = _T2A(ptrT(json_as_string(node)));
CheckAvatarChange(hContact, avatarUrl);
// set country
node = json_get(data, "loccountrycode");
if (node != NULL)
{
- const char *iso = ptrA(mir_u2a(json_as_string(node)));
+ const char *iso = ptrA(mir_u2a(ptrT(json_as_string(node))));
char *country = (char *)CallService(MS_UTILS_GETCOUNTRYBYISOCODE, (WPARAM)iso, 0);
setString(hContact, "Country", country);
}
@@ -211,17 +211,17 @@ void CSteamProto::UpdateContact(MCONTACT hContact, JSONNODE *data)
// playing game
node = json_get(data, "gameid");
- DWORD gameId = node ? atol(_T2A(json_as_string(node))) : 0;
+ DWORD gameId = node ? atol(_T2A(ptrT(json_as_string(node)))) : 0;
if (gameId > 0)
{
node = json_get(data, "gameextrainfo");
- const TCHAR *gameInfo = json_as_string(node);
+ ptrT gameInfo(json_as_string(node));
node = json_get(data, "gameserverip");
- const TCHAR *serverIP = json_as_string(node);
+ ptrT serverIP(json_as_string(node));
node = json_get(data, "gameserversteamid");
- const TCHAR *serverID = json_as_string(node);
+ ptrT serverID (json_as_string(node));
setDword(hContact, "GameID", gameId);
setString(hContact, "ServerIP", _T2A(serverIP));
@@ -331,10 +331,14 @@ void CSteamProto::ProcessContact(std::map<std::string, JSONNODE*>::iterator *it,
hContact = AddContact(steamId.c_str());
JSONNODE *node = json_get(child, "friend_since");
- db_set_dw(hContact, "UserInfo", "ContactAddTime", json_as_int(node));
+ if (node)
+ db_set_dw(hContact, "UserInfo", "ContactAddTime", json_as_int(node));
node = json_get(child, "relationship");
- ptrA relationship(mir_u2a(json_as_string(node)));
+ if (node == NULL)
+ return;
+
+ ptrA relationship(mir_u2a(ptrT(json_as_string(node))));
if (!lstrcmpiA(relationship, "friend"))
{
ContactIsFriend(hContact);
@@ -378,9 +382,9 @@ void CSteamProto::OnGotFriendList(const NETLIBHTTPREQUEST *response, void *arg)
if (node == NULL)
continue;
- std::string steamId = _T2A(json_as_string(node));
+ std::string steamId = _T2A(ptrT(json_as_string(node)));
friends.insert(std::make_pair(steamId, child));
- }
+ }
}
// Check and update contacts in database
@@ -421,6 +425,9 @@ void CSteamProto::OnGotFriendList(const NETLIBHTTPREQUEST *response, void *arg)
}
friends.clear();
+ // We need to delete nroot here at the end, because we had references to JSONNODE objects stored in friends map
+ json_delete(nroot);
+
if (!steamIds.empty())
{
//steamIds.pop_back();
@@ -454,7 +461,7 @@ void CSteamProto::OnGotBlockList(const NETLIBHTTPREQUEST *response, void *arg)
break;
node = json_get(child, "steamid");
- ptrA steamId(mir_u2a(json_as_string(node)));
+ ptrA steamId(mir_u2a(ptrT(json_as_string(node))));
/*MCONTACT hContact = FindContact(steamId);
if (!hContact)
@@ -464,7 +471,7 @@ void CSteamProto::OnGotBlockList(const NETLIBHTTPREQUEST *response, void *arg)
}*/
node = json_get(child, "relationship");
- ptrA relationship(mir_u2a(json_as_string(node)));
+ ptrA relationship(mir_u2a(ptrT(json_as_string(node))));
if (!lstrcmpiA(relationship, "ignoredfriend"))
{
@@ -472,6 +479,7 @@ void CSteamProto::OnGotBlockList(const NETLIBHTTPREQUEST *response, void *arg)
}
else continue;
}
+ json_delete(nroot);
}
}
@@ -495,7 +503,7 @@ void CSteamProto::OnGotUserSummaries(const NETLIBHTTPREQUEST *response, void *ar
break;
node = json_get(item, "steamid");
- ptrA steamId(mir_u2a(json_as_string(node)));
+ ptrA steamId(mir_u2a(ptrT(json_as_string(node))));
MCONTACT hContact = NULL;
if (!IsMe(steamId)) {
@@ -506,6 +514,7 @@ void CSteamProto::OnGotUserSummaries(const NETLIBHTTPREQUEST *response, void *ar
UpdateContact(hContact, item);
}
+ json_delete(nroot);
}
}
@@ -593,11 +602,13 @@ void CSteamProto::OnAuthRequested(const NETLIBHTTPREQUEST *response, void *arg)
return;
JSONNODE *node = json_get(root, "players");
- JSONNODE *nroot = json_at(json_as_array(node), 0);
+ JSONNODE *nodes = json_as_array(node);
+ JSONNODE *nroot = json_at(nodes, 0);
+
if (nroot != NULL)
{
node = json_get(nroot, "steamid");
- ptrA steamId(mir_u2a(json_as_string(node)));
+ ptrA steamId(mir_u2a(ptrT(json_as_string(node))));
MCONTACT hContact = FindContact(steamId);
if (!hContact)
@@ -605,11 +616,11 @@ void CSteamProto::OnAuthRequested(const NETLIBHTTPREQUEST *response, void *arg)
UpdateContact(hContact, nroot);
- char *nickName = getStringA(hContact, "Nick");
- char *firstName = getStringA(hContact, "FirstName");
+ ptrA nickName(getStringA(hContact, "Nick"));
+ ptrA firstName(getStringA(hContact, "FirstName"));
if (firstName == NULL)
firstName = mir_strdup("");
- char *lastName = getStringA(hContact, "LastName");
+ ptrA lastName(getStringA(hContact, "LastName"));
if (lastName == NULL)
lastName = mir_strdup("");
@@ -634,10 +645,12 @@ void CSteamProto::OnAuthRequested(const NETLIBHTTPREQUEST *response, void *arg)
pCurBlob += lstrlenA(lastName) + 1;
strcpy((char*)pCurBlob, steamId);
pCurBlob += lstrlenA(steamId) + 1;
- strcpy((char*)pCurBlob, mir_strdup(reason));
+ strcpy((char*)pCurBlob, reason);
AddDBEvent(hContact, EVENTTYPE_AUTHREQUEST, time(NULL), DBEF_UTF, cbBlob, pBlob);
}
+
+ json_delete(nodes);
}
void CSteamProto::OnPendingApproved(const NETLIBHTTPREQUEST *response, void *arg)
@@ -656,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(json_as_string(node))));
+ debugLogA("CSteamProto::OnPendingApproved: failed to approve pending from %s (%s)", ptrA((char*)arg), ptrA(mir_utf8encodeW(ptrT(json_as_string(node)))));
}
}
@@ -676,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(json_as_string(node))));
+ debugLogA("CSteamProto::OnPendingApproved: failed to ignore pending from %s (%s)", ptrA((char*)arg), ptrA(mir_utf8encodeW(ptrT(json_as_string(node)))));
}
}
@@ -694,7 +707,9 @@ void CSteamProto::OnSearchByIdEnded(const NETLIBHTTPREQUEST *response, void *arg
return;
JSONNODE *node = json_get(root, "players");
- JSONNODE *nroot = json_at(json_as_array(node), 0);
+ JSONNODE *nodes = json_as_array(node);
+ JSONNODE *nroot = json_at(nodes, 0);
+
if (nroot != NULL)
{
STEAM_SEARCH_RESULT ssr = { 0 };
@@ -704,12 +719,12 @@ void CSteamProto::OnSearchByIdEnded(const NETLIBHTTPREQUEST *response, void *arg
ssr.hdr.id = (wchar_t*)arg;
node = json_get(nroot, "personaname");
- ssr.hdr.nick = mir_wstrdup(json_as_string(node));
+ ssr.hdr.nick = mir_wstrdup(ptrT(json_as_string(node)));
node = json_get(nroot, "realname");
if (node != NULL)
{
- std::wstring realname = json_as_string(node);
+ std::wstring realname = ptrT(json_as_string(node));
if (!realname.empty())
{
size_t pos = realname.find(' ', 1);
@@ -729,6 +744,8 @@ void CSteamProto::OnSearchByIdEnded(const NETLIBHTTPREQUEST *response, void *arg
ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_DATA, (HANDLE)STEAM_SEARCH_BYID, (LPARAM)&ssr);
ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, (HANDLE)STEAM_SEARCH_BYID, 0);
}
+
+ json_delete(nodes);
}
void CSteamProto::OnSearchByNameStarted(const NETLIBHTTPREQUEST *response, void *arg)
diff --git a/protocols/Steam/src/steam_menus.cpp b/protocols/Steam/src/steam_menus.cpp
index 0a962707e5..44c058b4f2 100644
--- a/protocols/Steam/src/steam_menus.cpp
+++ b/protocols/Steam/src/steam_menus.cpp
@@ -97,7 +97,7 @@ int CSteamProto::PrebuildContactMenu(WPARAM wParam, LPARAM lParam)
void CSteamProto::OnInitStatusMenu()
{
char text[200];
- strcpy(text, m_szModuleName);
+ mir_strncpy(text, m_szModuleName, 100);
char* tDest = text + strlen(text);
CLISTMENUITEM mi = { sizeof(mi) };
diff --git a/protocols/Steam/src/steam_messages.cpp b/protocols/Steam/src/steam_messages.cpp
index 7e6e07c315..f330e5a3ab 100644
--- a/protocols/Steam/src/steam_messages.cpp
+++ b/protocols/Steam/src/steam_messages.cpp
@@ -25,7 +25,7 @@ void CSteamProto::OnMessageSent(const NETLIBHTTPREQUEST *response, void *arg)
{
JSONROOT root(response->pData);
JSONNODE *node = json_get(root, "error");
- ptrA error(mir_utf8encodeW(json_as_string(node)));
+ ptrA error(mir_utf8encodeW(ptrT(json_as_string(node))));
if (lstrcmpiA(error, "OK") == 0)
result = true;
else
diff --git a/protocols/Steam/src/steam_pooling.cpp b/protocols/Steam/src/steam_pooling.cpp
index efdd6514f3..e126f7c7d3 100644
--- a/protocols/Steam/src/steam_pooling.cpp
+++ b/protocols/Steam/src/steam_pooling.cpp
@@ -14,10 +14,10 @@ void CSteamProto::ParsePollData(JSONNODE *data)
break;
node = json_get(item, "steamid_from");
- ptrA steamId(mir_t2a(json_as_string(node)));
+ ptrA steamId(mir_t2a(ptrT(json_as_string(node))));
node = json_get(item, "utc_timestamp");
- time_t timestamp = atol(ptrA(mir_t2a(json_as_string(node))));
+ time_t timestamp = atol(ptrA(mir_t2a(ptrT(json_as_string(node)))));
node = json_get(item, "type");
ptrT type(json_as_string(node));
@@ -25,7 +25,7 @@ void CSteamProto::ParsePollData(JSONNODE *data)
!lstrcmpi(type, _T("my_saytext")) || !lstrcmpi(type, _T("my_emote")))
{
node = json_get(item, "text");
- const TCHAR *text = json_as_string(node);
+ ptrT text(json_as_string(node));
if (_tcsstr(type, _T("my_")) == NULL)
{
@@ -64,7 +64,7 @@ void CSteamProto::ParsePollData(JSONNODE *data)
if (IsMe(steamId))
{
node = json_get(item, "persona_name");
- setTString("Nick", json_as_string(node));
+ setTString("Nick", ptrT(json_as_string(node)));
if (status == ID_STATUS_OFFLINE)
continue;
@@ -87,7 +87,7 @@ void CSteamProto::ParsePollData(JSONNODE *data)
SetContactStatus(hContact, status);
node = json_get(item, "persona_name");
- setTString(hContact, "Nick", json_as_string(node));
+ setTString(hContact, "Nick", ptrT(json_as_string(node)));
// todo: find difference between state changing and info changing
steamIds.append(steamId).append(",");
@@ -208,7 +208,10 @@ void CSteamProto::PollingThread(void*)
JSONNODE *nroot = json_as_array(node);
if (nroot != NULL)
+ {
ParsePollData(nroot);
+ json_delete(nroot);
+ }
m_pollingConnection = response->nlc;
}
diff --git a/protocols/Steam/src/steam_proto.cpp b/protocols/Steam/src/steam_proto.cpp
index 952e74b4e2..a2d609dd20 100644
--- a/protocols/Steam/src/steam_proto.cpp
+++ b/protocols/Steam/src/steam_proto.cpp
@@ -14,6 +14,11 @@ CSteamProto::CSteamProto(const char* protoName, const TCHAR* userName) :
InitQueue();
m_idleTS = 0;
+ isTerminated = false;
+ m_hQueueThread = NULL;
+ m_pollingConnection = NULL;
+ m_hPollingThread = NULL;
+ m_hMenuRoot = NULL;
// icons
wchar_t filePath[MAX_PATH];
@@ -274,7 +279,7 @@ HANDLE __cdecl CSteamProto::SearchByName(const TCHAR* nick, const TCHAR* firstNa
//if (!this->IsOnline())
return 0;
- ptrA token(getStringA("TokenSecret"));
+ /*ptrA token(getStringA("TokenSecret"));
CMString keywords;
keywords.AppendFormat(L" %s", nick);
@@ -287,7 +292,7 @@ HANDLE __cdecl CSteamProto::SearchByName(const TCHAR* nick, const TCHAR* firstNa
new SteamWebApi::SearchRequest(token, mir_utf8encodeW(keywords)),
&CSteamProto::OnSearchByNameStarted);
- return (HANDLE)STEAM_SEARCH_BYNAME;
+ return (HANDLE)STEAM_SEARCH_BYNAME;*/
}
HWND __cdecl CSteamProto::SearchAdvanced( HWND owner ) { return 0; }
@@ -325,20 +330,18 @@ int __cdecl CSteamProto::SendMsg(MCONTACT hContact, int flags, const char *msg)
{
UINT hMessage = InterlockedIncrement(&hMessageProcess);
- if (flags & PREF_UNICODE)
- msg = mir_utf8encode(msg); // FIXME: Token from FacebookRM. Is it needed? Usually we get PREF_UTF8 flag instead. And does it cause memory leak?
+ CMStringA message = (flags & PREF_UNICODE) ? ptrA(mir_utf8encode(msg)) : msg; // TODO: mir_utf8encode check taken from FacebookRM, is it needed? Usually we get PREF_UTF8 flag instead.
SendMessageParam *param = (SendMessageParam*)mir_calloc(sizeof(SendMessageParam));
param->hContact = hContact;
param->hMessage = (HANDLE)hMessage;
-
ptrA token(getStringA("TokenSecret"));
ptrA umqid(getStringA("UMQID"));
ptrA steamId(getStringA(hContact, "SteamID"));
PushRequest(
- new SteamWebApi::SendMessageRequest(token, umqid, steamId, msg),
+ new SteamWebApi::SendMessageRequest(token, umqid, steamId, message),
&CSteamProto::OnMessageSent,
param);
diff --git a/protocols/Steam/src/steam_utils.cpp b/protocols/Steam/src/steam_utils.cpp
index 7c5888645f..85aef0a715 100644
--- a/protocols/Steam/src/steam_utils.cpp
+++ b/protocols/Steam/src/steam_utils.cpp
@@ -49,16 +49,27 @@ int CSteamProto::MirandaToSteamState(int status)
int CSteamProto::RsaEncrypt(const char *pszModulus, const char *data, BYTE *encryptedData, DWORD &encryptedSize)
{
DWORD cchModulus = (DWORD)strlen(pszModulus);
+ int result = 0;
+ BYTE *pbBuffer = 0;
+ BYTE *pKeyBlob = 0;
+ HCRYPTKEY phKey = 0;
+ HCRYPTPROV hCSP = 0;
// convert hex string to byte array
DWORD cbLen = 0, dwSkip = 0, dwFlags = 0;
if (!CryptStringToBinaryA(pszModulus, cchModulus, CRYPT_STRING_HEX, NULL, &cbLen, &dwSkip, &dwFlags))
- return GetLastError();
+ {
+ result = GetLastError();
+ goto exit;
+ }
// allocate a new buffer.
- BYTE *pbBuffer = (BYTE*)malloc(cbLen);
+ pbBuffer = (BYTE*)malloc(cbLen);
if (!CryptStringToBinaryA(pszModulus, cchModulus, CRYPT_STRING_HEX, pbBuffer, &cbLen, &dwSkip, &dwFlags))
- return GetLastError();
+ {
+ result = GetLastError();
+ goto exit;
+ }
// reverse byte array, because of microsoft
for (int i = 0; i < (int)(cbLen / 2); ++i)
@@ -67,15 +78,17 @@ int CSteamProto::RsaEncrypt(const char *pszModulus, const char *data, BYTE *encr
pbBuffer[cbLen - i - 1] = pbBuffer[i];
pbBuffer[i] = temp;
}
-
- HCRYPTPROV hCSP = 0;
+
if (!CryptAcquireContext(&hCSP, NULL, NULL, PROV_RSA_AES, CRYPT_SILENT) &&
!CryptAcquireContext(&hCSP, NULL, NULL, PROV_RSA_AES, CRYPT_SILENT | CRYPT_NEWKEYSET))
- return GetLastError();
+ {
+ result = GetLastError();
+ goto exit;
+ }
// Move the key into the key container.
DWORD cbKeyBlob = sizeof(PUBLICKEYSTRUC) + sizeof(RSAPUBKEY) + cbLen;
- BYTE *pKeyBlob = (BYTE*)malloc(cbKeyBlob);
+ pKeyBlob = (BYTE*)malloc(cbKeyBlob);
// Fill in the data.
PUBLICKEYSTRUC *pPublicKey = (PUBLICKEYSTRUC*)pKeyBlob;
@@ -96,10 +109,12 @@ int CSteamProto::RsaEncrypt(const char *pszModulus, const char *data, BYTE *encr
//pKeyBlob + sizeof(BLOBHEADER)+ sizeof(RSAPUBKEY);
memcpy(pKey, pbBuffer, cbLen);
- // Now import public key
- HCRYPTKEY phKey = 0;
+ // Now import public key
if (!CryptImportKey(hCSP, pKeyBlob, cbKeyBlob, 0, 0, &phKey))
- return GetLastError();
+ {
+ result = GetLastError();
+ goto exit;
+ }
DWORD dataSize = strlen(data);
@@ -108,14 +123,17 @@ int CSteamProto::RsaEncrypt(const char *pszModulus, const char *data, BYTE *encr
{
// get length of encrypted data
if (!CryptEncrypt(phKey, 0, TRUE, 0, NULL, &encryptedSize, dataSize))
- return GetLastError();
- return 0;
+ result = GetLastError();
+ goto exit;
}
// encrypt password
memcpy(encryptedData, data, dataSize);
if (!CryptEncrypt(phKey, 0, TRUE, 0, encryptedData, &dataSize, encryptedSize))
- return GetLastError();
+ {
+ result = GetLastError();
+ goto exit;
+ }
// reverse byte array again
for (int i = 0; i < (int)(encryptedSize / 2); ++i)
@@ -125,11 +143,16 @@ int CSteamProto::RsaEncrypt(const char *pszModulus, const char *data, BYTE *encr
encryptedData[i] = temp;
}
- free(pKeyBlob);
- CryptDestroyKey(phKey);
+exit:
+ if (pKeyBlob)
+ free(pKeyBlob);
+ if (phKey)
+ CryptDestroyKey(phKey);
- free(pbBuffer);
- CryptReleaseContext(hCSP, 0);
+ if (pbBuffer)
+ free(pbBuffer);
+ if (hCSP)
+ CryptReleaseContext(hCSP, 0);
return 0;
}
diff --git a/protocols/Steam/src/version.h b/protocols/Steam/src/version.h
index 56078b3f6d..c0bd9cbfe8 100644
--- a/protocols/Steam/src/version.h
+++ b/protocols/Steam/src/version.h
@@ -1,7 +1,7 @@
#define __MAJOR_VERSION 0
#define __MINOR_VERSION 11
#define __RELEASE_NUM 2
-#define __BUILD_NUM 0
+#define __BUILD_NUM 1
#include <stdver.h>