summaryrefslogtreecommitdiff
path: root/protocols
diff options
context:
space:
mode:
Diffstat (limited to 'protocols')
-rw-r--r--protocols/Steam/Steam.vcxproj2
-rw-r--r--protocols/Steam/Steam.vcxproj.filters11
-rw-r--r--protocols/Steam/src/Junk/steam_thread.cpp171
-rw-r--r--protocols/Steam/src/Steam/authorization.h59
-rw-r--r--protocols/Steam/src/Steam/avatar.h18
-rw-r--r--protocols/Steam/src/Steam/captcha.h18
-rw-r--r--protocols/Steam/src/Steam/crypto.h123
-rw-r--r--protocols/Steam/src/Steam/friend.h18
-rw-r--r--protocols/Steam/src/Steam/friend_list.h88
-rw-r--r--protocols/Steam/src/Steam/login.h33
-rw-r--r--protocols/Steam/src/Steam/message.h126
-rw-r--r--protocols/Steam/src/Steam/pending.h67
-rw-r--r--protocols/Steam/src/Steam/poll.h30
-rw-r--r--protocols/Steam/src/Steam/rsa_key.h19
-rw-r--r--protocols/Steam/src/Steam/search.h20
-rw-r--r--protocols/Steam/src/Steam/session.h26
-rw-r--r--protocols/Steam/src/Steam/steam.h185
-rw-r--r--protocols/Steam/src/api/authorization.h59
-rw-r--r--protocols/Steam/src/api/avatar.h14
-rw-r--r--protocols/Steam/src/api/captcha.h14
-rw-r--r--protocols/Steam/src/api/friend.h15
-rw-r--r--protocols/Steam/src/api/friend_list.h88
-rw-r--r--protocols/Steam/src/api/login.h32
-rw-r--r--protocols/Steam/src/api/message.h22
-rw-r--r--protocols/Steam/src/api/pending.h67
-rw-r--r--protocols/Steam/src/api/poll.h28
-rw-r--r--protocols/Steam/src/api/rsa_key.h16
-rw-r--r--protocols/Steam/src/api/search.h17
-rw-r--r--protocols/Steam/src/api/session.h24
-rw-r--r--protocols/Steam/src/http_request.h96
-rw-r--r--protocols/Steam/src/request_queue.cpp121
-rw-r--r--protocols/Steam/src/request_queue.h59
-rw-r--r--protocols/Steam/src/stdafx.h130
-rw-r--r--protocols/Steam/src/steam_account.cpp27
-rw-r--r--protocols/Steam/src/steam_avatars.cpp5
-rw-r--r--protocols/Steam/src/steam_contacts.cpp24
-rw-r--r--protocols/Steam/src/steam_events.cpp4
-rw-r--r--protocols/Steam/src/steam_menus.cpp6
-rw-r--r--protocols/Steam/src/steam_messages.cpp13
-rw-r--r--protocols/Steam/src/steam_pooling.cpp10
-rw-r--r--protocols/Steam/src/steam_proto.cpp113
-rw-r--r--protocols/Steam/src/steam_proto.h85
-rw-r--r--protocols/Steam/src/steam_queue.cpp193
-rw-r--r--protocols/Steam/src/steam_request.cpp73
-rw-r--r--protocols/Steam/src/version.h4
45 files changed, 951 insertions, 1422 deletions
diff --git a/protocols/Steam/Steam.vcxproj b/protocols/Steam/Steam.vcxproj
index 31586f4d5d..34d9a391f9 100644
--- a/protocols/Steam/Steam.vcxproj
+++ b/protocols/Steam/Steam.vcxproj
@@ -26,7 +26,7 @@
<Import Project="$(ProjectDir)..\..\build\vc.common\common.props" />
</ImportGroup>
<ItemGroup>
- <ClInclude Include="src\Steam\*.h" />
+ <ClInclude Include="src\api\*.h" />
<None Include="res\*.ico" />
</ItemGroup>
<ItemDefinitionGroup>
diff --git a/protocols/Steam/Steam.vcxproj.filters b/protocols/Steam/Steam.vcxproj.filters
index bb7c608603..a8ab01c0e5 100644
--- a/protocols/Steam/Steam.vcxproj.filters
+++ b/protocols/Steam/Steam.vcxproj.filters
@@ -1,15 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(ProjectDir)..\..\build\vc.common\common.filters" />
- <ItemGroup>
- <Filter Include="Header Files\Steam">
- <UniqueIdentifier>{B3578338-70BD-4763-97DF-B800D979C2B6}</UniqueIdentifier>
- <Extensions>h</Extensions>
- </Filter>
- </ItemGroup>
- <ItemGroup>
- <ClInclude Include="src\Steam\*.h">
- <Filter>Header Files\Steam</Filter>
- </ClInclude>
- </ItemGroup>
</Project>
diff --git a/protocols/Steam/src/Junk/steam_thread.cpp b/protocols/Steam/src/Junk/steam_thread.cpp
deleted file mode 100644
index f07541c6d3..0000000000
--- a/protocols/Steam/src/Junk/steam_thread.cpp
+++ /dev/null
@@ -1,171 +0,0 @@
-#include "stdafx.h"
-
-void CSteamProto::PollServer(const char *token, const char *umqId, UINT32 messageId, SteamWebApi::PollApi::PollResult *pollResult)
-{
- debugLogA("CSteamProto::PollServer: call SteamWebApi::PollApi::Poll");
- SteamWebApi::PollApi::Poll(m_hNetlibUser, token, umqId, messageId, pollResult);
-
- if (!pollResult->IsSuccess())
- return;
-
- CMStringA updatedIds;
- for (size_t i = 0; i < pollResult->GetItemCount(); i++)
- {
- const SteamWebApi::PollApi::PoolItem *item = pollResult->GetAt(i);
- switch (item->GetType())
- {
- case SteamWebApi::PollApi::POOL_TYPE_TYPING:
- break;
-
- case SteamWebApi::PollApi::POOL_TYPE_MESSAGE:
- {
- SteamWebApi::PollApi::Message *message = (SteamWebApi::PollApi::Message*)item;
-
- MCONTACT hContact = FindContact(message->GetSteamId());
- if (hContact)
- {
- const wchar_t *text = message->GetText();
-
- PROTORECVEVENT recv = { 0 };
- recv.flags = PREF_UTF;
- recv.timestamp = message->GetTimestamp();
- recv.szMessage = mir_utf8encodeW(text);
-
- ProtoChainRecvMsg(hContact, &recv);
- }
- }
- break;
-
- case SteamWebApi::PollApi::POOL_TYPE_MYMESSAGE:
- {
- SteamWebApi::PollApi::Message *message = (SteamWebApi::PollApi::Message*)item;
-
- MCONTACT hContact = FindContact(message->GetSteamId());
- if (hContact)
- {
- const wchar_t *text = message->GetText();
-
- AddDBEvent(hContact, EVENTTYPE_MESSAGE, time(NULL), DBEF_UTF | DBEF_SENT, mir_tstrlen(text), (BYTE*)mir_utf8encodeW(text));
- }
- }
- break;
-
- case SteamWebApi::PollApi::POOL_TYPE_STATE:
- {
- SteamWebApi::PollApi::State *state = (SteamWebApi::PollApi::State*)item;
-
- WORD status = CSteamProto::SteamToMirandaStatus(state->GetStatus());
- const char *steamId = state->GetSteamId();
- const wchar_t *nickname = state->GetNickname();
-
- if (IsMe(steamId))
- {
- if (status == ID_STATUS_OFFLINE)
- continue;
-
- if (status != m_iStatus)
- {
- debugLogA("Change own status to %i", status);
- WORD oldStatus = m_iStatus;
- m_iStatus = m_iDesiredStatus = status;
- ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)oldStatus, m_iStatus);
- }
- }
- /*else
- {
- MCONTACT hContact = FindContact(steamId);
- if (hContact)
- SetContactStatus(hContact, status);
- }*/
-
- if (updatedIds.IsEmpty())
- updatedIds.Append(steamId);
- else
- updatedIds.AppendFormat(",%s", steamId);
- }
- break;
-
- case SteamWebApi::PollApi::POOL_TYPE_CONTACT_ADD:
- {
- SteamWebApi::PollApi::Relationship *crs = (SteamWebApi::PollApi::Relationship*)item;
-
- const char *steamId = crs->GetSteamId();
- if (updatedIds.IsEmpty())
- updatedIds.Append(steamId);
- else
- updatedIds.AppendFormat(",%s", steamId);
- }
- break;
-
- case SteamWebApi::PollApi::POOL_TYPE_CONTACT_REMOVE:
- {
- SteamWebApi::PollApi::Relationship *crs = (SteamWebApi::PollApi::Relationship*)item;
-
- const char *steamId = crs->GetSteamId();
- MCONTACT hContact = FindContact(steamId);
- if (hContact)
- CallService(MS_DB_CONTACT_DELETE, hContact, 0);
- }
- break;
-
- case SteamWebApi::PollApi::POOL_TYPE_CONTACT_REQUEST:
- {
- SteamWebApi::PollApi::Relationship *crs = (SteamWebApi::PollApi::Relationship*)item;
-
- const char *steamId = crs->GetSteamId();
-
- MCONTACT hContact = FindContact(steamId);
- if (!hContact)
- hContact = AddContact(steamId, true);
-
- RaiseAuthRequestThread((void*)hContact);
- }
- break;
- }
- }
-
- if (!updatedIds.IsEmpty())
- UpdateContactsThread(mir_strdup(updatedIds));
-}
-
-void CSteamProto::PollingThread(void*)
-{
- debugLogA("CSteamProto::PollingThread: entering");
-
- ptrA token(getStringA("TokenSecret"));
- ptrA umqId(getStringA("UMQID"));
- UINT32 messageId = getDword("MessageID", 0);
-
- SteamWebApi::PollApi::PollResult pollResult;
- while (!m_bTerminated)
- {
- PollServer(token, umqId, messageId, &pollResult);
-
- if (pollResult.IsNeedRelogin())
- {
- debugLogA("CSteamProto::PollingThread: need to relogin");
- SetStatus(ID_STATUS_OFFLINE);
- }
-
- if (!pollResult.IsSuccess())
- {
- debugLogA("CSteamProto::PollServer: call SteamWebApi::PollApi::Poll");
- SetStatus(ID_STATUS_OFFLINE);
-
- // token has expired
- if (pollResult.GetStatus() == HTTP_STATUS_UNAUTHORIZED)
- {
- delSetting("TokenSecret");
- //delSetting("Cookie");
- }
-
- break;
- }
-
- messageId = pollResult.GetMessageId();
- setDword("MessageID", messageId);
- }
-
- m_hPollingThread = NULL;
- debugLogA("CSteamProto::PollingThread: leaving");
-} \ No newline at end of file
diff --git a/protocols/Steam/src/Steam/authorization.h b/protocols/Steam/src/Steam/authorization.h
deleted file mode 100644
index 57401f91c5..0000000000
--- a/protocols/Steam/src/Steam/authorization.h
+++ /dev/null
@@ -1,59 +0,0 @@
-#ifndef _STEAM_AUTHORIZATION_H_
-#define _STEAM_AUTHORIZATION_H_
-
-namespace SteamWebApi
-{
- class AuthorizationRequest : public HttpsPostRequest
- {
- public:
- AuthorizationRequest(const char *username, const char *password, const char *timestamp) :
- HttpsPostRequest(STEAM_WEB_URL "/mobilelogin/dologin")
- {
- flags = NLHRF_HTTP11 | NLHRF_SSL | NLHRF_NODUMP;
-
- char data[1024];
- mir_snprintf(data, SIZEOF(data),
- "username=%s&password=%s&oauth_client_id=3638BFB1&oauth_scope=read_profile write_profile read_client write_client&captchagid=-1&rsatimestamp=%s",
- ptrA(mir_urlEncode(username)),
- ptrA(mir_urlEncode(password)),
- timestamp);
-
- SetData(data, mir_strlen(data));
- }
-
- AuthorizationRequest(const char *username, const char *password, const char *timestamp, const char *guardCode) :
- HttpsPostRequest(STEAM_WEB_URL "/mobilelogin/dologin")
- {
- flags = NLHRF_HTTP11 | NLHRF_SSL | NLHRF_NODUMP;
-
- char data[1024];
- mir_snprintf(data, SIZEOF(data),
- "username=%s&password=%s&emailauth=%s&loginfriendlyname=MirandaNG&oauth_client_id=3638BFB1&oauth_scope=read_profile write_profile read_client write_client&captchagid=-1&rsatimestamp=%s",
- ptrA(mir_urlEncode(username)),
- ptrA(mir_urlEncode(password)),
- guardCode,
- timestamp);
-
- SetData(data, mir_strlen(data));
- }
-
- AuthorizationRequest(const char *username, const char *password, const char *timestamp, const char *captchaId, const char *captchaText) :
- HttpsPostRequest(STEAM_WEB_URL "/mobilelogin/dologin")
- {
- flags = NLHRF_HTTP11 | NLHRF_SSL | NLHRF_NODUMP;
-
- char data[1024];
- mir_snprintf(data, SIZEOF(data),
- "username=%s&password=%s&emailauth=&captchagid=%s&captcha_text=%s&oauth_client_id=3638BFB1&oauth_scope=read_profile write_profile read_client write_client&rsatimestamp=%s",
- ptrA(mir_urlEncode(username)),
- ptrA(mir_urlEncode(password)),
- captchaId,
- ptrA(mir_urlEncode(captchaText)),
- timestamp);
-
- SetData(data, mir_strlen(data));
- }
- };
-}
-
-#endif //_STEAM_AUTHORIZATION_H_ \ No newline at end of file
diff --git a/protocols/Steam/src/Steam/avatar.h b/protocols/Steam/src/Steam/avatar.h
deleted file mode 100644
index e306b7dfb8..0000000000
--- a/protocols/Steam/src/Steam/avatar.h
+++ /dev/null
@@ -1,18 +0,0 @@
-#ifndef _STEAM_AVATAR_H_
-#define _STEAM_AVATAR_H_
-
-namespace SteamWebApi
-{
- class GetAvatarRequest : public HttpGetRequest
- {
- public:
- GetAvatarRequest(const char *url) :
- HttpGetRequest(url)
- {
- flags = NLHRF_HTTP11 | NLHRF_NODUMP;
- }
- };
-}
-
-
-#endif //_STEAM_AVATAR_H_ \ No newline at end of file
diff --git a/protocols/Steam/src/Steam/captcha.h b/protocols/Steam/src/Steam/captcha.h
deleted file mode 100644
index 6ad01048ca..0000000000
--- a/protocols/Steam/src/Steam/captcha.h
+++ /dev/null
@@ -1,18 +0,0 @@
-#ifndef _STEAM_CAPTCHA_H_
-#define _STEAM_CAPTCHA_H_
-
-namespace SteamWebApi
-{
- class GetCaptchaRequest : public HttpGetRequest
- {
- public:
- GetCaptchaRequest(const char *captchaId) :
- HttpGetRequest(STEAM_WEB_URL "/public/captcha.php?gid=%s", captchaId)
- {
- flags = NLHRF_HTTP11 | NLHRF_NODUMP;
- }
- };
-}
-
-
-#endif //_STEAM_CAPTCHA_H_ \ No newline at end of file
diff --git a/protocols/Steam/src/Steam/crypto.h b/protocols/Steam/src/Steam/crypto.h
deleted file mode 100644
index 729dc2a591..0000000000
--- a/protocols/Steam/src/Steam/crypto.h
+++ /dev/null
@@ -1,123 +0,0 @@
-#ifndef _STEAM_CRYPTO_H_
-#define _STEAM_CRYPTO_H_
-
-#include <openssl/rsa.h>
-#include <openssl/bio.h>
-#include <openssl/bn.h>
-#include <openssl/err.h>
-#include <openssl/evp.h>
-#include <openssl/rand.h>
-#include <openssl/engine.h>
-
-namespace SteamWebApi
-{
- class CryptoApi : public BaseApi
- {
- public:
-
- class RsaKey : public Result
- {
- friend CryptoApi;
-
- private:
- std::string modulus;
- std::string exponent;
- time_t timestamp;
-
- public:
- RsaKey() : timestamp(0) { }
-
- const char * GetModulus() const
- {
- return modulus.c_str();
- }
-
- const char * GetExponent() const
- {
- return exponent.c_str();
- }
-
- time_t GetTimestamp() const
- {
- return timestamp;
- }
-
- int GetEncryptedSize() const
- {
- BIGNUM *n = BN_new();
- if (!BN_hex2bn(&n, modulus.c_str()))
- return NULL;
-
- BIGNUM *e = BN_new();
- if (!BN_hex2bn(&e, exponent.c_str()))
- return NULL;
-
- RSA *rsa = RSA_new();
- rsa->n = n;
- rsa->e = e;
-
- int size = RSA_size(rsa);
-
- RSA_free(rsa);
-
- return size;
- }
-
- int Encrypt(BYTE *data, int dataSize, BYTE *encrypted) const
- {
- BIGNUM *n = BN_new();
- if (!BN_hex2bn(&n, modulus.c_str()))
- return NULL;
-
- BIGNUM *e = BN_new();
- if (!BN_hex2bn(&e, exponent.c_str()))
- return NULL;
-
- RSA *rsa = RSA_new();
- rsa->n = n;
- rsa->e = e;
-
- if (RSA_public_encrypt(dataSize, data, encrypted, rsa, RSA_PKCS1_PADDING) < 0)
- {
- RSA_free(rsa);
- return 1;
- }
-
- RSA_free(rsa);
- return 0;
- }
- };
-
- static void GetRsaKey(HANDLE hConnection, const char *username, RsaKey *rsaKey)
- {
- rsaKey->success = false;
-
- HttpRequest request(hConnection, REQUEST_GET, STEAM_COMMUNITY_URL "/mobilelogin/getrsakey");
- request.AddParameter("username", username);
-
- mir_ptr<NETLIBHTTPREQUEST> response(request.Send());
- if (!response || response->resultCode != HTTP_STATUS_OK)
- return;
-
- JSONROOT root(response->pData);
- if (!root) return;
-
- JSONNODE *node = json_get(root, "success");
- if (!json_as_bool(node)) return;
-
- node = json_get(root, "publickey_mod");
- rsaKey->modulus = ptrA(mir_u2a(json_as_string(node)));
-
- node = json_get(root, "publickey_exp");
- rsaKey->exponent = ptrA(mir_u2a(json_as_string(node)));
-
- node = json_get(root, "timestamp");
- rsaKey->timestamp = _atoi64(ptrA(mir_u2a(json_as_string(node))));
-
- rsaKey->success = true;
- }
- };
-}
-
-
-#endif //_STEAM_CRYPTO_H_ \ No newline at end of file
diff --git a/protocols/Steam/src/Steam/friend.h b/protocols/Steam/src/Steam/friend.h
deleted file mode 100644
index 14c5250c97..0000000000
--- a/protocols/Steam/src/Steam/friend.h
+++ /dev/null
@@ -1,18 +0,0 @@
-#ifndef _STEAM_FRIEND_H_
-#define _STEAM_FRIEND_H_
-
-namespace SteamWebApi
-{
- class GetUserSummariesRequest : public HttpsGetRequest
- {
- public:
- GetUserSummariesRequest(const char *token, const char *steamIds) :
- HttpsGetRequest(STEAM_API_URL "/ISteamUserOAuth/GetUserSummaries/v0001")
- {
- AddParameter("access_token", token);
- AddParameter("steamids", steamIds);
- }
- };
-}
-
-#endif //_STEAM_FRIEND_H_ \ No newline at end of file
diff --git a/protocols/Steam/src/Steam/friend_list.h b/protocols/Steam/src/Steam/friend_list.h
deleted file mode 100644
index cfa383c533..0000000000
--- a/protocols/Steam/src/Steam/friend_list.h
+++ /dev/null
@@ -1,88 +0,0 @@
-#ifndef _STEAM_FRIEND_LIST_H_
-#define _STEAM_FRIEND_LIST_H_
-
-namespace SteamWebApi
-{
- class GetFriendListRequest : public HttpsGetRequest
- {
- public:
- GetFriendListRequest(const char *token, const char *steamId, const char *relationship = "friend,ignoredfriend,requestrecipient") :
- HttpsGetRequest(STEAM_API_URL "/ISteamUserOAuth/GetFriendList/v0001")
- {
- AddParameter("access_token", token);
- AddParameter("steamid", steamId);
- AddParameter("relationship", relationship);
- }
- };
-
- class AddFriendRequest : public HttpsPostRequest
- {
- public:
- AddFriendRequest(const char *token, const char *sessionId, const char *steamId, const char *who) :
- HttpsPostRequest(STEAM_WEB_URL "/actions/AddFriendAjax")
- {
- char login[MAX_PATH];
- mir_snprintf(login, SIZEOF(login), "%s||oauth:%s", steamId, token);
-
- char cookie[MAX_PATH];
- mir_snprintf(cookie, SIZEOF(cookie), "steamLogin=%s;sessionid=%s;forceMobile=1", login, sessionId);
-
- char data[128];
- mir_snprintf(data, SIZEOF(data),
- "sessionID=%s&steamid=%s",
- sessionId,
- who);
-
- SetData(data, mir_strlen(data));
- AddHeader("Cookie", cookie);
- }
- };
-
- class BlockFriendRequest : public HttpsPostRequest
- {
- public:
- BlockFriendRequest(const char *token, const char *sessionId, const char *steamId, const char *who) :
- HttpsPostRequest(STEAM_WEB_URL "/actions/BlockUserAjax")
- {
- char login[MAX_PATH];
- mir_snprintf(login, SIZEOF(login), "%s||oauth:%s", steamId, token);
-
- char cookie[MAX_PATH];
- mir_snprintf(cookie, SIZEOF(cookie), "steamLogin=%s;sessionid=%s;forceMobile=1", login, sessionId);
-
- char data[128];
- mir_snprintf(data, SIZEOF(data),
- "sessionID=%s&action=ignore&steamid=%s",
- sessionId,
- who);
-
- SetData(data, mir_strlen(data));
- AddHeader("Cookie", cookie);
- }
- };
-
- class RemoveFriendRequest : public HttpsPostRequest
- {
- public:
- RemoveFriendRequest(const char *token, const char *sessionId, const char *steamId, const char *who) :
- HttpsPostRequest(STEAM_WEB_URL "/actions/RemoveFriendAjax")
- {
- char login[MAX_PATH];
- mir_snprintf(login, SIZEOF(login), "%s||oauth:%s", steamId, token);
-
- char cookie[MAX_PATH];
- mir_snprintf(cookie, SIZEOF(cookie), "steamLogin=%s;sessionid=%s;forceMobile=1", login, sessionId);
-
- char data[128];
- mir_snprintf(data, SIZEOF(data),
- "sessionID=%s&steamid=%s",
- sessionId,
- who);
-
- SetData(data, mir_strlen(data));
- AddHeader("Cookie", cookie);
- }
- };
-}
-
-#endif //_STEAM_FRIEND_LIST_H_ \ No newline at end of file
diff --git a/protocols/Steam/src/Steam/login.h b/protocols/Steam/src/Steam/login.h
deleted file mode 100644
index e2b9b41a81..0000000000
--- a/protocols/Steam/src/Steam/login.h
+++ /dev/null
@@ -1,33 +0,0 @@
-#ifndef _STEAM_LOGIN_H_
-#define _STEAM_LOGIN_H_
-
-namespace SteamWebApi
-{
- class LogonRequest : public HttpsPostRequest
- {
- public:
- LogonRequest(const char *token) :
- HttpsPostRequest(STEAM_API_URL "/ISteamWebUserPresenceOAuth/Logon/v0001")
- {
- char data[256];
- mir_snprintf(data, SIZEOF(data), "access_token=%s&ui_mode=web", token);
-
- SetData(data, mir_strlen(data));
- }
- };
-
- class LogoffRequest : public HttpsPostRequest
- {
- public:
- LogoffRequest(const char *token, const char *umqId) :
- HttpsPostRequest(STEAM_API_URL "/ISteamWebUserPresenceOAuth/Logoff/v0001")
- {
- char data[256];
- mir_snprintf(data, SIZEOF(data), "access_token=%s&umqid=%s", token, umqId);
-
- SetData(data, mir_strlen(data));
- }
- };
-}
-
-#endif //_STEAM_LOGIN_H_ \ No newline at end of file
diff --git a/protocols/Steam/src/Steam/message.h b/protocols/Steam/src/Steam/message.h
deleted file mode 100644
index bf0cb78b3d..0000000000
--- a/protocols/Steam/src/Steam/message.h
+++ /dev/null
@@ -1,126 +0,0 @@
-#ifndef _STEAM_MESSAGE_H_
-#define _STEAM_MESSAGE_H_
-
-namespace SteamWebApi
-{
- //class MessageApi : public BaseApi
- //{
- //public:
- // class SendResult : public Result
- // {
- // friend MessageApi;
-
- // private:
- // DWORD timestamp;
-
- // public:
- // SendResult() : timestamp(0) { }
-
- // const DWORD GetTimestamp() const { return timestamp; }
- // };
-
- // static void SendStatus(HANDLE hConnection, const char *token, const char *umqId, int state, SendResult *sendResult)
- // {
- // sendResult->success = false;
-
- // char data[256];
- // mir_snprintf(data, SIZEOF(data),
- // "access_token=%s&umqid=%s&type=personastate&persona_state=%i",
- // token,
- // umqId,
- // state);
-
- // SecureHttpPostRequest request(hConnection, STEAM_API_URL "/ISteamWebUserPresenceOAuth/Message/v0001");
- // request.SetData(data, mir_strlen(data));
-
- // mir_ptr<NETLIBHTTPREQUEST> response(request.Send());
- // if (!response)
- // return;
-
- // if ((sendResult->status = (HTTP_STATUS)response->resultCode) != HTTP_STATUS_OK)
- // return;
-
- // sendResult->success = true;
- // }
-
- // static void SendMessage(HANDLE hConnection, const char *token, const char *umqId, const char *steamId, const char *text, SendResult *sendResult)
- // {
- // sendResult->success = false;
-
- // char data[1024];
- // mir_snprintf(data, SIZEOF(data),
- // "access_token=%s&umqid=%s&steamid_dst=%s&type=saytext&text=%s",
- // token,
- // umqId,
- // steamId,
- // ptrA(mir_urlEncode(text)));
-
- // SecureHttpPostRequest request(hConnection, STEAM_API_URL "/ISteamWebUserPresenceOAuth/Message/v0001");
- // request.SetData(data, mir_strlen(data));
-
- // mir_ptr<NETLIBHTTPREQUEST> response(request.Send());
- // if (!response)
- // return;
-
- // if ((sendResult->status = (HTTP_STATUS)response->resultCode) != HTTP_STATUS_OK)
- // return;
-
- // JSONROOT root(response->pData);
-
- // JSONNODE *node = json_get(root, "error");
- // ptrT error(json_as_string(node));
-
- // if (mir_tstrcmp(error, _T("OK")))
- // return;
-
- // node = json_get(root, "utc_timestamp");
- // sendResult->timestamp = atol(ptrA(mir_u2a(ptrT(json_as_string(node)))));
-
- // sendResult->success = true;
- // }
-
- // static void SendTyping(HANDLE hConnection, const char *token, const char *umqId, const char *steamId, SendResult *sendResult)
- // {
- // sendResult->success = false;
-
- // char data[256];
- // mir_snprintf(data, SIZEOF(data),
- // "access_token=%s&umqid=%s&steamid_dst=%s&type=typing",
- // token,
- // umqId,
- // steamId);
-
- // SecureHttpPostRequest request(hConnection, STEAM_API_URL "/ISteamWebUserPresenceOAuth/Message/v0001");
- // request.SetData(data, mir_strlen(data));
-
- // mir_ptr<NETLIBHTTPREQUEST> response(request.Send());
- // if (!response)
- // return;
-
- // if ((sendResult->status = (HTTP_STATUS)response->resultCode) != HTTP_STATUS_OK)
- // return;
-
- // sendResult->success = true;
- // }
- //};
-
- class SendMessageRequest : public HttpsPostRequest
- {
- public:
- SendMessageRequest(const char *token, const char *umqId, const char *steamId, const char *text) :
- HttpsPostRequest(STEAM_API_URL "/ISteamWebUserPresenceOAuth/Message/v0001")
- {
- CMStringA data;
- data.AppendFormat("access_token=%s&umqid=%s&steamid_dst=%s&type=saytext&text=%s",
- token,
- umqId,
- steamId,
- ptrA(mir_urlEncode(text)));
-
- SetData(data, data.GetLength());
- }
- };
-}
-
-
-#endif //_STEAM_MESSAGE_H_ \ No newline at end of file
diff --git a/protocols/Steam/src/Steam/pending.h b/protocols/Steam/src/Steam/pending.h
deleted file mode 100644
index 65a72d25d4..0000000000
--- a/protocols/Steam/src/Steam/pending.h
+++ /dev/null
@@ -1,67 +0,0 @@
-#ifndef _STEAM_PENDING_H_
-#define _STEAM_PENDING_H_
-
-namespace SteamWebApi
-{
- class ApprovePendingRequest : public HttpsPostRequest
- {
- public:
- ApprovePendingRequest(const char *token, const char *sessionId, const char *steamId, const char *who) :
- HttpsPostRequest(STEAM_WEB_URL "/profiles/%s/home_process", steamId)
- {
- char login[MAX_PATH];
- mir_snprintf(login, SIZEOF(login), "%s||oauth:%s", steamId, token);
-
- char cookie[MAX_PATH];
- mir_snprintf(cookie, SIZEOF(cookie), "steamLogin=%s;sessionid=%s;forceMobile=1", login, sessionId);
-
- char data[MAX_PATH];
- mir_snprintf(data, SIZEOF(data), "sessionID=%s&id=%s&perform=accept&action=approvePending&itype=friend&json=1&xml=0", sessionId, who);
-
- SetData(data, mir_strlen(data));
- AddHeader("Cookie", cookie);
- }
- };
-
- class IgnorePendingRequest : public HttpsPostRequest
- {
- public:
- IgnorePendingRequest(const char *token, const char *sessionId, const char *steamId, const char *who) :
- HttpsPostRequest(STEAM_WEB_URL "/profiles/%s/home_process", steamId)
- {
- char login[MAX_PATH];
- mir_snprintf(login, SIZEOF(login), "%s||oauth:%s", steamId, token);
-
- char cookie[MAX_PATH];
- mir_snprintf(cookie, SIZEOF(cookie), "steamLogin=%s;sessionid=%s;forceMobile=1", login, sessionId);
-
- char data[MAX_PATH];
- mir_snprintf(data, SIZEOF(data), "sessionID=%s&id=%s&perform=ignore&action=approvePending&itype=friend&json=1&xml=0", sessionId, who);
-
- SetData(data, mir_strlen(data));
- AddHeader("Cookie", cookie);
- }
- };
-
- class BlockPendingRequest : public HttpsPostRequest
- {
- public:
- BlockPendingRequest(const char *token, const char *sessionId, const char *steamId, const char *who) :
- HttpsPostRequest(STEAM_WEB_URL "/profiles/%s/home_process", steamId)
- {
- char login[MAX_PATH];
- mir_snprintf(login, SIZEOF(login), "%s||oauth:%s", steamId, token);
-
- char cookie[MAX_PATH];
- mir_snprintf(cookie, SIZEOF(cookie), "steamLogin=%s;sessionid=%s;forceMobile=1", login, sessionId);
-
- char data[MAX_PATH];
- mir_snprintf(data, SIZEOF(data), "sessionID=%s&id=%s&perform=block&action=approvePending&itype=friend&json=1&xml=0", sessionId, who);
-
- SetData(data, mir_strlen(data));
- AddHeader("Cookie", cookie);
- }
- };
-}
-
-#endif //_STEAM_PENDING_H_ \ No newline at end of file
diff --git a/protocols/Steam/src/Steam/poll.h b/protocols/Steam/src/Steam/poll.h
deleted file mode 100644
index 33ffe6dce5..0000000000
--- a/protocols/Steam/src/Steam/poll.h
+++ /dev/null
@@ -1,30 +0,0 @@
-#ifndef _STEAM_POLL_H_
-#define _STEAM_POLL_H_
-
-namespace SteamWebApi
-{
- class PollRequest : public HttpsPostRequest
- {
- public:
- PollRequest(const char *token, const char *umqId, UINT32 messageId, int idleSeconds) :
- HttpsPostRequest(STEAM_API_URL "/ISteamWebUserPresenceOAuth/Poll/v0001")
- {
- timeout = (STEAM_API_TIMEOUT + 5) * 1000;
- flags |= NLHRF_PERSISTENT;
-
- CMStringA data;
- data.AppendFormat("access_token=%s&umqid=%s&message=%u&secidletime=%d&sectimeout=%d",
- token,
- umqId,
- messageId,
- idleSeconds,
- STEAM_API_TIMEOUT);
-
- SetData(data, data.GetLength());
-
- AddHeader("Connection", "keep-alive");
- }
- };
-}
-
-#endif //_STEAM_POLL_H_ \ No newline at end of file
diff --git a/protocols/Steam/src/Steam/rsa_key.h b/protocols/Steam/src/Steam/rsa_key.h
deleted file mode 100644
index be7d7ac79c..0000000000
--- a/protocols/Steam/src/Steam/rsa_key.h
+++ /dev/null
@@ -1,19 +0,0 @@
-#ifndef _STEAM_RSA_KEY_H_
-#define _STEAM_RSA_KEY_H_
-
-namespace SteamWebApi
-{
- class RsaKeyRequest : public HttpsGetRequest
- {
- public:
- RsaKeyRequest(const char *username) :
- HttpsGetRequest(STEAM_WEB_URL "/mobilelogin/getrsakey")
- {
- flags = NLHRF_HTTP11 | NLHRF_SSL | NLHRF_NODUMP;
-
- AddParameter("username", (char*)username);
- }
- };
-}
-
-#endif //_STEAM_RSA_KEY_H_ \ No newline at end of file
diff --git a/protocols/Steam/src/Steam/search.h b/protocols/Steam/src/Steam/search.h
deleted file mode 100644
index 4cdd4179e0..0000000000
--- a/protocols/Steam/src/Steam/search.h
+++ /dev/null
@@ -1,20 +0,0 @@
-#ifndef _STEAM_SEARCH_H_
-#define _STEAM_SEARCH_H_
-
-namespace SteamWebApi
-{
- class SearchRequest : public HttpsGetRequest
- {
- public:
- SearchRequest(const char *token, const char *text) :
- HttpsGetRequest(STEAM_API_URL "/ISteamUserOAuth/Search/v0001")
- {
- AddParameter("access_token", token);
- AddParameter("keywords", ptrA(mir_urlEncode(text)));
- // todo: may need to load all results (15 first at now)
- AddParameter("offset=0&count=15&targets=users&fields=all");
- }
- };
-}
-
-#endif //_STEAM_SEARCH_H_ \ No newline at end of file
diff --git a/protocols/Steam/src/Steam/session.h b/protocols/Steam/src/Steam/session.h
deleted file mode 100644
index 20a5d7db53..0000000000
--- a/protocols/Steam/src/Steam/session.h
+++ /dev/null
@@ -1,26 +0,0 @@
-#ifndef _STEAM_SESSION_H_
-#define _STEAM_SESSION_H_
-
-namespace SteamWebApi
-{
- class GetSessionRequest : public HttpsPostRequest
- {
- public:
- GetSessionRequest(const char *token, const char *steamId, const char *cookie) :
- HttpsPostRequest(STEAM_WEB_URL "/mobileloginsucceeded")
- {
- flags = NLHRF_HTTP11 | NLHRF_SSL | NLHRF_NODUMP;
-
- char data[512];
- mir_snprintf(data, SIZEOF(data),
- "oauth_token=%s&steamid=%s&webcookie=%s",
- token,
- steamId,
- cookie);
-
- SetData(data, mir_strlen(data));
- }
- };
-}
-
-#endif //_STEAM_SESSION_H_ \ No newline at end of file
diff --git a/protocols/Steam/src/Steam/steam.h b/protocols/Steam/src/Steam/steam.h
deleted file mode 100644
index a2a373a3d3..0000000000
--- a/protocols/Steam/src/Steam/steam.h
+++ /dev/null
@@ -1,185 +0,0 @@
-#ifndef _STEAM_H_
-#define _STEAM_H_
-
-namespace SteamWebApi
-{
- #define STEAM_API_URL "https://api.steampowered.com"
- #define STEAM_WEB_URL "https://steamcommunity.com"
-
- class HttpRequest : public NETLIBHTTPREQUEST, public MZeroedObject
- {
- private:
- CMStringA url;
-
- protected:
- HttpRequest()
- {
- cbSize = sizeof(NETLIBHTTPREQUEST);
-
- AddHeader("user-agent", "Steam 1.2.0 / iPhone");
- }
-
- HttpRequest(int type, LPCSTR urlFormat, va_list args)
- {
- this->HttpRequest::HttpRequest();
-
- requestType = type;
- //timeout = 0;
- flags = NLHRF_HTTP11 | NLHRF_NODUMPSEND | NLHRF_DUMPASTEXT;
-
- url.AppendFormatV(urlFormat, args);
- szUrl = url.GetBuffer();
- }
-
- void AddHeader(LPCSTR szName, LPCSTR szValue)
- {
- headers = (NETLIBHTTPHEADER*)mir_realloc(headers, sizeof(NETLIBHTTPHEADER)*(headersCount + 1));
- headers[headersCount].szName = mir_strdup(szName);
- headers[headersCount].szValue = mir_strdup(szValue);
- headersCount++;
- }
-
- void AddParameter(const char *fmt, ...)
- {
- va_list args;
- va_start(args, fmt);
- if (url.Find('?') == -1)
- url += '?';
- else
- url += '&';
- url.AppendFormatV(fmt, args);
- va_end(args);
-
- szUrl = url.GetBuffer();
- }
-
- void AddParameter(LPCSTR name, LPCSTR value)
- {
- AddParameter("%s=%s", name, value);
- }
-
- void SetData(const char *data, size_t size)
- {
- if (pData != NULL)
- mir_free(pData);
-
- dataLength = (int)size;
- pData = (char*)mir_alloc(size + 1);
- memcpy(pData, data, size);
- pData[size] = 0;
- }
-
- public:
- HttpRequest(int type, LPCSTR urlFormat, ...)
- {
- va_list args;
- va_start(args, urlFormat);
- this->HttpRequest::HttpRequest(type, urlFormat, args);
- va_end(args);
- }
-
- ~HttpRequest()
- {
- for (int i = 0; i < headersCount; i++)
- {
- mir_free(headers[i].szName);
- mir_free(headers[i].szValue);
- }
- mir_free(headers);
- mir_free(pData);
- }
-
- NETLIBHTTPREQUEST * Send(HANDLE hConnection)
- {
- char message[1024];
- mir_snprintf(message, SIZEOF(message), "Send request to %s", szUrl);
- CallService(MS_NETLIB_LOG, (WPARAM)hConnection, (LPARAM)&message);
-
- return (NETLIBHTTPREQUEST*)CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)hConnection, (LPARAM)this);
- }
- };
-
- class HttpGetRequest : public HttpRequest
- {
- public:
- HttpGetRequest(LPCSTR urlFormat, ...) : HttpRequest()
- {
- va_list args;
- va_start(args, urlFormat);
- this->HttpRequest::HttpRequest(REQUEST_GET, urlFormat, args);
- va_end(args);
- }
- };
-
- class HttpPostRequest : public HttpRequest
- {
- public:
- HttpPostRequest(LPCSTR urlFormat, ...) : HttpRequest()
- {
- va_list args;
- va_start(args, urlFormat);
- this->HttpRequest::HttpRequest(REQUEST_POST, urlFormat, args);
- va_end(args);
-
- AddHeader("Content-Type", "application/x-www-form-urlencoded");
- }
- };
-
- class HttpsRequest : public HttpRequest
- {
- protected:
- HttpsRequest() : HttpRequest() { }
-
- public:
- HttpsRequest(int type, LPCSTR urlFormat, ...) : HttpRequest()
- {
- va_list args;
- va_start(args, urlFormat);
- this->HttpRequest::HttpRequest(type, urlFormat, args);
- va_end(args);
-
- flags = NLHRF_HTTP11 | NLHRF_SSL | NLHRF_NODUMPSEND | NLHRF_DUMPASTEXT;
- }
- };
-
- class HttpsGetRequest : public HttpsRequest
- {
- public:
- HttpsGetRequest(LPCSTR urlFormat, ...) : HttpsRequest()
- {
- va_list args;
- va_start(args, urlFormat);
- this->HttpRequest::HttpRequest(REQUEST_GET, urlFormat, args);
- va_end(args);
- }
- };
-
- class HttpsPostRequest : public HttpsRequest
- {
- public:
- HttpsPostRequest(LPCSTR urlFormat, ...) : HttpsRequest()
- {
- va_list args;
- va_start(args, urlFormat);
- this->HttpRequest::HttpRequest(REQUEST_POST, urlFormat, args);
- va_end(args);
-
- AddHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
- }
- };
-}
-
-#include "Steam\rsa_key.h"
-#include "Steam\authorization.h"
-#include "Steam\login.h"
-#include "Steam\session.h"
-#include "Steam\friend_list.h"
-#include "Steam\pending.h"
-#include "Steam\friend.h"
-#include "Steam\poll.h"
-#include "Steam\message.h"
-#include "Steam\search.h"
-#include "Steam\avatar.h"
-#include "Steam\captcha.h"
-
-#endif //_STEAM_H_ \ No newline at end of file
diff --git a/protocols/Steam/src/api/authorization.h b/protocols/Steam/src/api/authorization.h
new file mode 100644
index 0000000000..e7b2ee8c39
--- /dev/null
+++ b/protocols/Steam/src/api/authorization.h
@@ -0,0 +1,59 @@
+#ifndef _STEAM_REQUEST_AUTHORIZATION_H_
+#define _STEAM_REQUEST_AUTHORIZATION_H_
+
+class AuthorizationRequest : public HttpRequest
+{
+public:
+ AuthorizationRequest(const char *username, const char *password, const char *timestamp) :
+ HttpRequest(REQUEST_POST, STEAM_WEB_URL "/mobilelogin/dologin")
+ {
+ flags = NLHRF_HTTP11 | NLHRF_SSL | NLHRF_NODUMP;
+
+ char data[1024];
+ mir_snprintf(data, SIZEOF(data),
+ "username=%s&password=%s&oauth_client_id=3638BFB1&oauth_scope=read_profile write_profile read_client write_client&captchagid=-1&rsatimestamp=%s",
+ ptrA(mir_urlEncode(username)),
+ ptrA(mir_urlEncode(password)),
+ timestamp);
+
+ SetData(data, strlen(data));
+ AddHeader("Content-Type", "application/x-www-form-urlencoded");
+ }
+
+ AuthorizationRequest(const char *username, const char *password, const char *timestamp, const char *guardCode) :
+ HttpRequest(REQUEST_POST, STEAM_WEB_URL "/mobilelogin/dologin")
+ {
+ flags = NLHRF_HTTP11 | NLHRF_SSL | NLHRF_NODUMP;
+
+ char data[1024];
+ mir_snprintf(data, SIZEOF(data),
+ "username=%s&password=%s&emailauth=%s&loginfriendlyname=MirandaNG&oauth_client_id=3638BFB1&oauth_scope=read_profile write_profile read_client write_client&captchagid=-1&rsatimestamp=%s",
+ ptrA(mir_urlEncode(username)),
+ ptrA(mir_urlEncode(password)),
+ guardCode,
+ timestamp);
+
+ SetData(data, strlen(data));
+ AddHeader("Content-Type", "application/x-www-form-urlencoded");
+ }
+
+ AuthorizationRequest(const char *username, const char *password, const char *timestamp, const char *captchaId, const char *captchaText) :
+ HttpRequest(REQUEST_POST, STEAM_WEB_URL "/mobilelogin/dologin")
+ {
+ flags = NLHRF_HTTP11 | NLHRF_SSL | NLHRF_NODUMP;
+
+ char data[1024];
+ mir_snprintf(data, SIZEOF(data),
+ "username=%s&password=%s&emailauth=&captchagid=%s&captcha_text=%s&oauth_client_id=3638BFB1&oauth_scope=read_profile write_profile read_client write_client&rsatimestamp=%s",
+ ptrA(mir_urlEncode(username)),
+ ptrA(mir_urlEncode(password)),
+ captchaId,
+ ptrA(mir_urlEncode(captchaText)),
+ timestamp);
+
+ SetData(data, strlen(data));
+ AddHeader("Content-Type", "application/x-www-form-urlencoded");
+ }
+};
+
+#endif //_STEAM_REQUEST_AUTHORIZATION_H_
diff --git a/protocols/Steam/src/api/avatar.h b/protocols/Steam/src/api/avatar.h
new file mode 100644
index 0000000000..ef4fcdfcf5
--- /dev/null
+++ b/protocols/Steam/src/api/avatar.h
@@ -0,0 +1,14 @@
+#ifndef _STEAM_REQUEST_AVATAR_H_
+#define _STEAM_REQUEST_AVATAR_H_
+
+class GetAvatarRequest : public HttpRequest
+{
+public:
+ GetAvatarRequest(const char *url) :
+ HttpRequest(REQUEST_GET, url)
+ {
+ flags = NLHRF_HTTP11 | NLHRF_NODUMP;
+ }
+};
+
+#endif //_STEAM_REQUEST_AVATAR_H_
diff --git a/protocols/Steam/src/api/captcha.h b/protocols/Steam/src/api/captcha.h
new file mode 100644
index 0000000000..b61dca89d6
--- /dev/null
+++ b/protocols/Steam/src/api/captcha.h
@@ -0,0 +1,14 @@
+#ifndef _STEAM_REQUEST_CAPTCHA_H_
+#define _STEAM_REQUEST_CAPTCHA_H_
+
+class GetCaptchaRequest : public HttpRequest
+{
+public:
+ GetCaptchaRequest(const char *captchaId) :
+ HttpRequest(REQUEST_GET, FORMAT, STEAM_WEB_URL "/public/captcha.php?gid=%s", captchaId)
+ {
+ flags = NLHRF_HTTP11 | NLHRF_NODUMP;
+ }
+};
+
+#endif //_STEAM_REQUEST_CAPTCHA_H_
diff --git a/protocols/Steam/src/api/friend.h b/protocols/Steam/src/api/friend.h
new file mode 100644
index 0000000000..d0fd70fa22
--- /dev/null
+++ b/protocols/Steam/src/api/friend.h
@@ -0,0 +1,15 @@
+#ifndef _STEAM_REQUEST_FRIEND_H_
+#define _STEAM_REQUEST_FRIEND_H_
+
+class GetUserSummariesRequest : public HttpRequest
+{
+public:
+ GetUserSummariesRequest(const char *token, const char *steamIds) :
+ HttpRequest(REQUEST_GET, STEAM_API_URL "/ISteamUserOAuth/GetUserSummaries/v0001")
+ {
+ AddParameter("access_token", token);
+ AddParameter("steamids", steamIds);
+ }
+};
+
+#endif //_STEAM_REQUEST_FRIEND_H_
diff --git a/protocols/Steam/src/api/friend_list.h b/protocols/Steam/src/api/friend_list.h
new file mode 100644
index 0000000000..4c1d6f8ef2
--- /dev/null
+++ b/protocols/Steam/src/api/friend_list.h
@@ -0,0 +1,88 @@
+#ifndef _STEAM_REQUEST_FRIEND_LIST_H_
+#define _STEAM_REQUEST_FRIEND_LIST_H_
+
+class GetFriendListRequest : public HttpRequest
+{
+public:
+ GetFriendListRequest(const char *token, const char *steamId, const char *relationship = "friend,ignoredfriend,requestrecipient") :
+ HttpRequest(REQUEST_GET, STEAM_API_URL "/ISteamUserOAuth/GetFriendList/v0001")
+ {
+ AddParameter("access_token", token);
+ AddParameter("steamid", steamId);
+ AddParameter("relationship", relationship);
+ }
+};
+
+class AddFriendRequest : public HttpRequest
+{
+public:
+ AddFriendRequest(const char *token, const char *sessionId, const char *steamId, const char *who) :
+ HttpRequest(REQUEST_POST, STEAM_WEB_URL "/actions/AddFriendAjax")
+ {
+ char login[MAX_PATH];
+ mir_snprintf(login, SIZEOF(login), "%s||oauth:%s", steamId, token);
+
+ char cookie[MAX_PATH];
+ mir_snprintf(cookie, SIZEOF(cookie), "steamLogin=%s;sessionid=%s;forceMobile=1", login, sessionId);
+
+ char data[128];
+ mir_snprintf(data, SIZEOF(data),
+ "sessionID=%s&steamid=%s",
+ sessionId,
+ who);
+
+ SetData(data, strlen(data));
+ AddHeader("Cookie", cookie);
+ AddHeader("Content-Type", "application/x-www-form-urlencoded");
+ }
+};
+
+class BlockFriendRequest : public HttpRequest
+{
+public:
+ BlockFriendRequest(const char *token, const char *sessionId, const char *steamId, const char *who) :
+ HttpRequest(REQUEST_POST, STEAM_WEB_URL "/actions/BlockUserAjax")
+ {
+ char login[MAX_PATH];
+ mir_snprintf(login, SIZEOF(login), "%s||oauth:%s", steamId, token);
+
+ char cookie[MAX_PATH];
+ mir_snprintf(cookie, SIZEOF(cookie), "steamLogin=%s;sessionid=%s;forceMobile=1", login, sessionId);
+
+ char data[128];
+ mir_snprintf(data, SIZEOF(data),
+ "sessionID=%s&action=ignore&steamid=%s",
+ sessionId,
+ who);
+
+ SetData(data, strlen(data));
+ AddHeader("Cookie", cookie);
+ AddHeader("Content-Type", "application/x-www-form-urlencoded");
+ }
+};
+
+class RemoveFriendRequest : public HttpRequest
+{
+public:
+ RemoveFriendRequest(const char *token, const char *sessionId, const char *steamId, const char *who) :
+ HttpRequest(REQUEST_POST, STEAM_WEB_URL "/actions/RemoveFriendAjax")
+ {
+ char login[MAX_PATH];
+ mir_snprintf(login, SIZEOF(login), "%s||oauth:%s", steamId, token);
+
+ char cookie[MAX_PATH];
+ mir_snprintf(cookie, SIZEOF(cookie), "steamLogin=%s;sessionid=%s;forceMobile=1", login, sessionId);
+
+ char data[128];
+ mir_snprintf(data, SIZEOF(data),
+ "sessionID=%s&steamid=%s",
+ sessionId,
+ who);
+
+ SetData(data, strlen(data));
+ AddHeader("Cookie", cookie);
+ AddHeader("Content-Type", "application/x-www-form-urlencoded");
+ }
+};
+
+#endif //_STEAM_REQUEST_FRIEND_LIST_H_
diff --git a/protocols/Steam/src/api/login.h b/protocols/Steam/src/api/login.h
new file mode 100644
index 0000000000..64b41f07cb
--- /dev/null
+++ b/protocols/Steam/src/api/login.h
@@ -0,0 +1,32 @@
+#ifndef _STEAM_REQUEST_LOGIN_H_
+#define _STEAM_REQUEST_LOGIN_H_
+
+class LogonRequest : public HttpRequest
+{
+public:
+ LogonRequest(const char *token) :
+ HttpRequest(REQUEST_POST, STEAM_API_URL "/ISteamWebUserPresenceOAuth/Logon/v0001")
+ {
+ char data[256];
+ mir_snprintf(data, SIZEOF(data), "access_token=%s&ui_mode=web", token);
+
+ SetData(data, strlen(data));
+ AddHeader("Content-Type", "application/x-www-form-urlencoded");
+ }
+};
+
+class LogoffRequest : public HttpRequest
+{
+public:
+ LogoffRequest(const char *token, const char *umqId) :
+ HttpRequest(REQUEST_POST, STEAM_API_URL "/ISteamWebUserPresenceOAuth/Logoff/v0001")
+ {
+ char data[256];
+ mir_snprintf(data, SIZEOF(data), "access_token=%s&umqid=%s", token, umqId);
+
+ SetData(data, strlen(data));
+ AddHeader("Content-Type", "application/x-www-form-urlencoded");
+ }
+};
+
+#endif //_STEAM_REQUEST_LOGIN_H_
diff --git a/protocols/Steam/src/api/message.h b/protocols/Steam/src/api/message.h
new file mode 100644
index 0000000000..cb3a1f0590
--- /dev/null
+++ b/protocols/Steam/src/api/message.h
@@ -0,0 +1,22 @@
+#ifndef _STEAM_REQUEST_MESSAGE_H_
+#define _STEAM_REQUEST_MESSAGE_H_
+
+class SendMessageRequest : public HttpRequest
+{
+public:
+ SendMessageRequest(const char *token, const char *umqId, const char *steamId, const char *text) :
+ HttpRequest(REQUEST_POST, STEAM_API_URL "/ISteamWebUserPresenceOAuth/Message/v0001")
+ {
+ CMStringA data;
+ data.AppendFormat("access_token=%s&umqid=%s&steamid_dst=%s&type=saytext&text=%s",
+ token,
+ umqId,
+ steamId,
+ ptrA(mir_urlEncode(text)));
+
+ SetData(data, data.GetLength());
+ AddHeader("Content-Type", "application/x-www-form-urlencoded");
+ }
+};
+
+#endif //_STEAM_REQUEST_MESSAGE_H_
diff --git a/protocols/Steam/src/api/pending.h b/protocols/Steam/src/api/pending.h
new file mode 100644
index 0000000000..f9965d341f
--- /dev/null
+++ b/protocols/Steam/src/api/pending.h
@@ -0,0 +1,67 @@
+#ifndef _STEAM_REQUEST_PENDING_H_
+#define _STEAM_REQUEST_PENDING_H_
+
+class ApprovePendingRequest : public HttpRequest
+{
+public:
+ ApprovePendingRequest(const char *token, const char *sessionId, const char *steamId, const char *who) :
+ HttpRequest(REQUEST_POST, FORMAT, STEAM_WEB_URL "/profiles/%s/home_process", steamId)
+ {
+ char login[MAX_PATH];
+ mir_snprintf(login, SIZEOF(login), "%s||oauth:%s", steamId, token);
+
+ char cookie[MAX_PATH];
+ mir_snprintf(cookie, SIZEOF(cookie), "steamLogin=%s;sessionid=%s;forceMobile=1", login, sessionId);
+
+ char data[MAX_PATH];
+ mir_snprintf(data, SIZEOF(data), "sessionID=%s&id=%s&perform=accept&action=approvePending&itype=friend&json=1&xml=0", sessionId, who);
+
+ SetData(data, strlen(data));
+ AddHeader("Cookie", cookie);
+ AddHeader("Content-Type", "application/x-www-form-urlencoded");
+ }
+};
+
+class IgnorePendingRequest : public HttpRequest
+{
+public:
+ IgnorePendingRequest(const char *token, const char *sessionId, const char *steamId, const char *who) :
+ HttpRequest(REQUEST_POST, FORMAT, STEAM_WEB_URL "/profiles/%s/home_process", steamId)
+ {
+ char login[MAX_PATH];
+ mir_snprintf(login, SIZEOF(login), "%s||oauth:%s", steamId, token);
+
+ char cookie[MAX_PATH];
+ mir_snprintf(cookie, SIZEOF(cookie), "steamLogin=%s;sessionid=%s;forceMobile=1", login, sessionId);
+
+ char data[MAX_PATH];
+ mir_snprintf(data, SIZEOF(data), "sessionID=%s&id=%s&perform=ignore&action=approvePending&itype=friend&json=1&xml=0", sessionId, who);
+
+ SetData(data, strlen(data));
+ AddHeader("Cookie", cookie);
+ AddHeader("Content-Type", "application/x-www-form-urlencoded");
+ }
+};
+
+class BlockPendingRequest : public HttpRequest
+{
+public:
+ BlockPendingRequest(const char *token, const char *sessionId, const char *steamId, const char *who) :
+ HttpRequest(REQUEST_POST, FORMAT, STEAM_WEB_URL "/profiles/%s/home_process", steamId)
+ {
+ char login[MAX_PATH];
+ mir_snprintf(login, SIZEOF(login), "%s||oauth:%s", steamId, token);
+
+ char cookie[MAX_PATH];
+ mir_snprintf(cookie, SIZEOF(cookie), "steamLogin=%s;sessionid=%s;forceMobile=1", login, sessionId);
+
+ char data[MAX_PATH];
+ mir_snprintf(data, SIZEOF(data), "sessionID=%s&id=%s&perform=block&action=approvePending&itype=friend&json=1&xml=0", sessionId, who);
+
+ SetData(data, strlen(data));
+ AddHeader("Cookie", cookie);
+ AddHeader("Content-Type", "application/x-www-form-urlencoded");
+ }
+};
+
+#endif //_STEAM_REQUEST_PENDING_H_
diff --git a/protocols/Steam/src/api/poll.h b/protocols/Steam/src/api/poll.h
new file mode 100644
index 0000000000..fec71c98e4
--- /dev/null
+++ b/protocols/Steam/src/api/poll.h
@@ -0,0 +1,28 @@
+#ifndef _STEAM_REQUEST_POLL_H_
+#define _STEAM_REQUEST_POLL_H_
+
+class PollRequest : public HttpRequest
+{
+public:
+ PollRequest(const char *token, const char *umqId, UINT32 messageId, int idleSeconds) :
+ HttpRequest(REQUEST_POST, STEAM_API_URL "/ISteamWebUserPresenceOAuth/Poll/v0001")
+ {
+ timeout = (STEAM_API_TIMEOUT + 5) * 1000;
+ flags |= NLHRF_PERSISTENT;
+
+ CMStringA data;
+ data.AppendFormat("access_token=%s&umqid=%s&message=%u&secidletime=%d&sectimeout=%d",
+ token,
+ umqId,
+ messageId,
+ idleSeconds,
+ STEAM_API_TIMEOUT);
+
+ SetData(data, data.GetLength());
+
+ AddHeader("Connection", "keep-alive");
+ AddHeader("Content-Type", "application/x-www-form-urlencoded");
+ }
+};
+
+#endif //_STEAM_REQUEST_POLL_H_
diff --git a/protocols/Steam/src/api/rsa_key.h b/protocols/Steam/src/api/rsa_key.h
new file mode 100644
index 0000000000..6b938a48ef
--- /dev/null
+++ b/protocols/Steam/src/api/rsa_key.h
@@ -0,0 +1,16 @@
+#ifndef _STEAM_REQUEST_RSA_KEY_H_
+#define _STEAM_REQUEST_RSA_KEY_H_
+
+class RsaKeyRequest : public HttpRequest
+{
+public:
+ RsaKeyRequest(const char *username) :
+ HttpRequest(REQUEST_GET, STEAM_WEB_URL "/mobilelogin/getrsakey")
+ {
+ flags = NLHRF_HTTP11 | NLHRF_SSL | NLHRF_NODUMP;
+
+ AddParameter("username", (char*)username);
+ }
+};
+
+#endif //_STEAM_REQUEST_RSA_KEY_H_
diff --git a/protocols/Steam/src/api/search.h b/protocols/Steam/src/api/search.h
new file mode 100644
index 0000000000..ed1b0420eb
--- /dev/null
+++ b/protocols/Steam/src/api/search.h
@@ -0,0 +1,17 @@
+#ifndef _STEAM_REQUEST_SEARCH_H_
+#define _STEAM_REQUEST_SEARCH_H_
+
+class SearchRequest : public HttpRequest
+{
+public:
+ SearchRequest(const char *token, const char *text) :
+ HttpRequest(REQUEST_GET, STEAM_API_URL "/ISteamUserOAuth/Search/v0001")
+ {
+ AddParameter("access_token", token);
+ AddParameter("keywords", ptrA(mir_urlEncode(text)));
+ // todo: may need to load all results (15 first at now)
+ AddParameter("offset=0&count=15&targets=users&fields=all");
+ }
+};
+
+#endif //_STEAM_REQUEST_SEARCH_H_
diff --git a/protocols/Steam/src/api/session.h b/protocols/Steam/src/api/session.h
new file mode 100644
index 0000000000..3e13a2e418
--- /dev/null
+++ b/protocols/Steam/src/api/session.h
@@ -0,0 +1,24 @@
+#ifndef _STEAM_REQUEST_SESSION_H_
+#define _STEAM_REQUEST_SESSION_H_
+
+class GetSessionRequest : public HttpRequest
+{
+public:
+ GetSessionRequest(const char *token, const char *steamId, const char *cookie) :
+ HttpRequest(REQUEST_POST, STEAM_WEB_URL "/mobileloginsucceeded")
+ {
+ flags = NLHRF_HTTP11 | NLHRF_SSL | NLHRF_NODUMP;
+
+ char data[512];
+ mir_snprintf(data, SIZEOF(data),
+ "oauth_token=%s&steamid=%s&webcookie=%s",
+ token,
+ steamId,
+ cookie);
+
+ SetData(data, strlen(data));
+ AddHeader("Content-Type", "application/x-www-form-urlencoded");
+ }
+};
+
+#endif //_STEAM_REQUEST_SESSION_H_
diff --git a/protocols/Steam/src/http_request.h b/protocols/Steam/src/http_request.h
new file mode 100644
index 0000000000..aa14d9037d
--- /dev/null
+++ b/protocols/Steam/src/http_request.h
@@ -0,0 +1,96 @@
+#ifndef _HTTP_REQUEST_H_
+#define _HTTP_REQUEST_H_
+
+class HttpRequest : public NETLIBHTTPREQUEST, public MZeroedObject
+{
+private:
+ CMStringA m_url;
+
+protected:
+ enum HttpRequestUrlFormat { FORMAT };
+
+ void Init(int type)
+ {
+ cbSize = sizeof(NETLIBHTTPREQUEST);
+ requestType = type;
+ flags = NLHRF_HTTP11 | NLHRF_SSL | NLHRF_NODUMPSEND | NLHRF_DUMPASTEXT;
+ AddHeader("user-agent", "Steam 1.2.0 / iPhone");
+ }
+
+ void AddHeader(LPCSTR szName, LPCSTR szValue)
+ {
+ headers = (NETLIBHTTPHEADER*)mir_realloc(headers, sizeof(NETLIBHTTPHEADER)*(headersCount + 1));
+ headers[headersCount].szName = mir_strdup(szName);
+ headers[headersCount].szValue = mir_strdup(szValue);
+ headersCount++;
+ }
+
+ void AddParameter(const char *fmt, ...)
+ {
+ va_list args;
+ va_start(args, fmt);
+ m_url += m_url.Find('?') == -1 ? '?' : '&';
+ m_url.AppendFormatV(fmt, args);
+ va_end(args);
+ }
+
+ void AddParameter(LPCSTR name, LPCSTR value)
+ {
+ AddParameter("%s=%s", name, value);
+ }
+
+ void SetData(const char *data, size_t size)
+ {
+ if (pData != NULL)
+ mir_free(pData);
+
+ dataLength = (int)size;
+ pData = (char*)mir_alloc(size + 1);
+ memcpy(pData, data, size);
+ pData[size] = 0;
+ }
+
+public:
+ HttpRequest(int type, LPCSTR url)
+ {
+ Init(type);
+
+ m_url = url;
+ }
+
+ HttpRequest(int type, HttpRequestUrlFormat, LPCSTR urlFormat, ...)
+ {
+ Init(type);
+
+ va_list formatArgs;
+ va_start(formatArgs, urlFormat);
+ m_url.AppendFormatV(urlFormat, formatArgs);
+ va_end(formatArgs);
+ }
+
+ ~HttpRequest()
+ {
+ for (int i = 0; i < headersCount; i++)
+ {
+ mir_free(headers[i].szName);
+ mir_free(headers[i].szValue);
+ }
+ mir_free(headers);
+
+ if (pData != NULL)
+ mir_free(pData);
+ }
+
+ NETLIBHTTPREQUEST* Send(HANDLE hConnection)
+ {
+ szUrl = m_url.GetBuffer();
+
+ char message[1024];
+ mir_snprintf(message, SIZEOF(message), "Send request to %s", szUrl);
+ CallService(MS_NETLIB_LOG, (WPARAM)hConnection, (LPARAM)&message);
+
+ return (NETLIBHTTPREQUEST*)CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)hConnection, (LPARAM)this);
+ }
+};
+
+#endif //_HTTP_REQUEST_H_ \ No newline at end of file
diff --git a/protocols/Steam/src/request_queue.cpp b/protocols/Steam/src/request_queue.cpp
new file mode 100644
index 0000000000..4e343a5118
--- /dev/null
+++ b/protocols/Steam/src/request_queue.cpp
@@ -0,0 +1,121 @@
+/*
+Copyright (c) 2015 Miranda NG project (http://miranda-ng.org)
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation version 2
+of the License.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "stdafx.h"
+
+RequestQueue::RequestQueue(HANDLE hConnection) :
+ hConnection(hConnection), requests(1)
+{
+ isTerminated = true;
+ hRequestQueueThread = NULL;
+ hRequestQueueEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
+}
+
+RequestQueue::~RequestQueue()
+{
+ requests.destroy();
+ CloseHandle(hRequestQueueEvent);
+}
+
+void RequestQueue::Start()
+{
+ if (!isTerminated)
+ return;
+
+ isTerminated = false;
+ if (hRequestQueueThread == NULL)
+ hRequestQueueThread = mir_forkthread((pThreadFunc)&RequestQueue::WorkerThread, this);
+}
+
+void RequestQueue::Stop()
+{
+ if (isTerminated)
+ return;
+
+ isTerminated = true;
+ SetEvent(hRequestQueueEvent);
+}
+
+void RequestQueue::Push(HttpRequest *request, HttpResponseCallback response, void *arg, HttpFinallyCallback last)
+{
+ if (isTerminated)
+ return;
+
+ RequestQueueItem *item = new RequestQueueItem(request, response, arg, last);
+ {
+ mir_cslock lock(requestQueueLock);
+
+ requests.insert(item);
+ }
+ SetEvent(hRequestQueueEvent);
+}
+
+void RequestQueue::Send(HttpRequest *request, HttpResponseCallback response, void *arg, HttpFinallyCallback last)
+{
+ RequestQueueItem *item = new RequestQueueItem(request, response, arg, last);
+ mir_forkthreadowner((pThreadFuncOwner)&RequestQueue::AsyncSendThread, this, item, 0);
+}
+
+void RequestQueue::Execute(RequestQueueItem *item)
+{
+ NETLIBHTTPREQUEST *response = item->request->Send(hConnection);
+ if (item->responseCallback != NULL)
+ item->responseCallback(response, item->arg);
+ 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;
+ RequestQueueItem *item = (RequestQueueItem*)arg;
+
+ that->Execute(item);
+
+ return 0;
+}
+
+unsigned int RequestQueue::WorkerThread(void *arg)
+{
+ RequestQueue *queue = (RequestQueue*)arg;
+
+ while (!queue->isTerminated)
+ {
+ WaitForSingleObject(queue->hRequestQueueEvent, INFINITE);
+ while (true)
+ {
+ RequestQueueItem *item = NULL;
+ {
+ mir_cslock lock(queue->requestQueueLock);
+
+ if (queue->requests.getCount() == 0)
+ break;
+
+ item = queue->requests[0];
+ queue->requests.remove(0);
+ }
+ if (item != NULL)
+ queue->Execute(item);
+ }
+ }
+
+ queue->hRequestQueueThread = NULL;
+ return 0;
+} \ No newline at end of file
diff --git a/protocols/Steam/src/request_queue.h b/protocols/Steam/src/request_queue.h
new file mode 100644
index 0000000000..3a213be0bf
--- /dev/null
+++ b/protocols/Steam/src/request_queue.h
@@ -0,0 +1,59 @@
+#ifndef _REQUEST_QUEUE_H_
+#define _REQUEST_QUEUE_H_
+
+typedef void(*HttpResponseCallback)(const NETLIBHTTPREQUEST *response, void *arg);
+typedef void(*HttpFinallyCallback)(void *arg);
+
+struct RequestQueueItem
+{
+ void *arg;
+ HttpRequest *request;
+ HttpResponseCallback responseCallback;
+ HttpFinallyCallback finallyCallback;
+
+ RequestQueueItem(HttpRequest *request, void *arg, HttpFinallyCallback finallyCallback) :
+ request(request), responseCallback(NULL), arg(arg), finallyCallback(finallyCallback)
+ {
+ }
+
+ RequestQueueItem(HttpRequest *request, HttpResponseCallback response, void *arg, HttpFinallyCallback finallyCallback) :
+ request(request), responseCallback(response), arg(arg), finallyCallback(finallyCallback)
+ {
+ }
+
+ ~RequestQueueItem()
+ {
+ delete request;
+ request = NULL;
+ responseCallback = NULL;
+ finallyCallback = NULL;
+ }
+};
+
+class RequestQueue
+{
+private:
+ bool isTerminated;
+ HANDLE hConnection;
+ mir_cs requestQueueLock;
+ LIST<RequestQueueItem> requests;
+ HANDLE hRequestQueueEvent, hRequestQueueThread;
+
+ void Execute(RequestQueueItem *item);
+
+ static unsigned int __cdecl AsyncSendThread(void*, void*);
+ static unsigned int __cdecl WorkerThread(void*);
+
+public:
+ RequestQueue(HANDLE hConnection);
+ ~RequestQueue();
+
+ void Start();
+ void Stop();
+
+ void Push(HttpRequest *request, HttpResponseCallback response = NULL, void *arg = NULL, HttpFinallyCallback last = NULL);
+ void Send(HttpRequest *request, HttpResponseCallback response = NULL, void *arg = NULL, HttpFinallyCallback last = NULL);
+
+};
+
+#endif //_REQUEST_QUEUE_H_ \ No newline at end of file
diff --git a/protocols/Steam/src/stdafx.h b/protocols/Steam/src/stdafx.h
index d39881dbd2..489c994784 100644
--- a/protocols/Steam/src/stdafx.h
+++ b/protocols/Steam/src/stdafx.h
@@ -1,58 +1,74 @@
-#ifndef _COMMON_H_
-#define _COMMON_H_
-
-#include <windows.h>
-#include <commctrl.h>
-#include <malloc.h>
-#include <time.h>
-
-#include <newpluginapi.h>
-#include <m_database.h>
-#include <m_langpack.h>
-#include <m_message.h>
-#include <m_netlib.h>
-#include <m_options.h>
-#include <m_popup.h>
-#include <m_json.h>
-#include <m_avatars.h>
-#include <m_icolib.h>
-#include <m_skin.h>
-#include <m_clist.h>
-#include <m_genmenu.h>
-#include <m_string.h>
-#include <m_freeimage.h>
-#include <m_imgsrvc.h>
-#include <m_protocols.h>
-#include <m_protomod.h>
-#include <m_protosvc.h>
-#include <m_protoint.h>
-#include <m_idle.h>
-#include <m_xstatus.h>
-#include <m_extraicons.h>
-#include <m_gui.h>
-
-#include <map>
-#include <vector>
-#include <string>
-#include <algorithm>
-
-#include "resource.h"
-#include "version.h"
-
-#define MODULE "Steam"
-
-#define STEAM_API_TIMEOUT 30
-#define STEAM_API_IDLEOUT_AWAY 600
-#define STEAM_API_IDLEOUT_SNOOZE 8000
-
-class CSteamProto;
-extern HINSTANCE g_hInstance;
-
-extern HANDLE hExtraXStatus;
-
-#include "Steam\steam.h"
-
-#include "steam_dialogs.h"
-#include "steam_proto.h"
-
+#ifndef _COMMON_H_
+#define _COMMON_H_
+
+#include <windows.h>
+#include <commctrl.h>
+#include <malloc.h>
+#include <time.h>
+
+#include <newpluginapi.h>
+#include <m_database.h>
+#include <m_langpack.h>
+#include <m_message.h>
+#include <m_netlib.h>
+#include <m_options.h>
+#include <m_popup.h>
+#include <m_json.h>
+#include <m_avatars.h>
+#include <m_icolib.h>
+#include <m_skin.h>
+#include <m_clist.h>
+#include <m_genmenu.h>
+#include <m_string.h>
+#include <m_freeimage.h>
+#include <m_imgsrvc.h>
+#include <m_protocols.h>
+#include <m_protomod.h>
+#include <m_protosvc.h>
+#include <m_protoint.h>
+#include <m_idle.h>
+#include <m_xstatus.h>
+#include <m_extraicons.h>
+#include <m_gui.h>
+
+#include <map>
+#include <vector>
+#include <string>
+#include <algorithm>
+
+#include "resource.h"
+#include "version.h"
+
+#define MODULE "Steam"
+
+#define STEAM_API_TIMEOUT 30
+#define STEAM_API_IDLEOUT_AWAY 600
+#define STEAM_API_IDLEOUT_SNOOZE 8000
+
+class CSteamProto;
+extern HINSTANCE g_hInstance;
+
+extern HANDLE hExtraXStatus;
+
+#define STEAM_API_URL "https://api.steampowered.com"
+#define STEAM_WEB_URL "https://steamcommunity.com"
+
+#include "steam_dialogs.h"
+#include "http_request.h"
+#include "request_queue.h"
+#include "api\authorization.h"
+#include "api\authorization.h"
+#include "api\avatar.h"
+#include "api\captcha.h"
+#include "api\friend.h"
+#include "api\friend_list.h"
+#include "api\login.h"
+#include "api\message.h"
+#include "api\pending.h"
+#include "api\poll.h"
+#include "api\rsa_key.h"
+#include "api\search.h"
+#include "api\session.h"
+#include "steam_proto.h"
+
#endif //_COMMON_H_ \ No newline at end of file
diff --git a/protocols/Steam/src/steam_account.cpp b/protocols/Steam/src/steam_account.cpp
index 942095d150..bbf144fc61 100644
--- a/protocols/Steam/src/steam_account.cpp
+++ b/protocols/Steam/src/steam_account.cpp
@@ -14,7 +14,7 @@ bool CSteamProto::IsMe(const char *steamId)
return false;
}
-void CSteamProto::OnGotRsaKey(const NETLIBHTTPREQUEST *response, void *)
+void CSteamProto::OnGotRsaKey(const NETLIBHTTPREQUEST *response)
{
if (response == NULL)
return;
@@ -69,13 +69,14 @@ void CSteamProto::OnGotRsaKey(const NETLIBHTTPREQUEST *response, void *)
ptrA username(mir_utf8encodeW(getWStringA("Username")));
PushRequest(
- new SteamWebApi::AuthorizationRequest(username, base64RsaEncryptedPassword, timestamp),
+ new AuthorizationRequest(username, base64RsaEncryptedPassword, timestamp),
&CSteamProto::OnAuthorization);
}
-void CSteamProto::OnAuthorization(const NETLIBHTTPREQUEST *response, void *)
+void CSteamProto::OnAuthorization(const NETLIBHTTPREQUEST *response)
{
- if (response == NULL) {
+ if (response == NULL)
+ {
SetStatus(ID_STATUS_OFFLINE);
return;
}
@@ -109,16 +110,14 @@ void CSteamProto::OnAuthorization(const NETLIBHTTPREQUEST *response, void *)
CSteamGuardDialog guardDialog(this, emailDomain);
if (!guardDialog.DoModal())
- {
return;
- }
ptrA username(mir_utf8encodeW(getWStringA("Username")));
ptrA password(getStringA("EncryptedPassword"));
ptrA timestamp(getStringA("RsaTimestamp"));
PushRequest(
- new SteamWebApi::AuthorizationRequest(username, password, timestamp, guardDialog.GetGuardCode()),
+ new AuthorizationRequest(username, password, timestamp, guardDialog.GetGuardCode()),
&CSteamProto::OnAuthorization);
return;
}
@@ -129,7 +128,7 @@ void CSteamProto::OnAuthorization(const NETLIBHTTPREQUEST *response, void *)
node = json_get(root, "captcha_gid");
ptrA captchaId(mir_u2a(ptrT(json_as_string(node))));
- SteamWebApi::GetCaptchaRequest *request = new SteamWebApi::GetCaptchaRequest(captchaId);
+ GetCaptchaRequest *request = new GetCaptchaRequest(captchaId);
NETLIBHTTPREQUEST *response = request->Send(m_hNetlibUser);
delete request;
@@ -146,7 +145,7 @@ void CSteamProto::OnAuthorization(const NETLIBHTTPREQUEST *response, void *)
ptrA timestamp(getStringA("RsaTimestamp"));
PushRequest(
- new SteamWebApi::AuthorizationRequest(username, password, timestamp, captchaId, captchaDialog.GetCaptchaText()),
+ new AuthorizationRequest(username, password, timestamp, captchaId, captchaDialog.GetCaptchaText()),
&CSteamProto::OnAuthorization);
return;
}
@@ -185,15 +184,15 @@ void CSteamProto::OnAuthorization(const NETLIBHTTPREQUEST *response, void *)
delSetting("EncryptedPassword");
PushRequest(
- new SteamWebApi::GetSessionRequest(token, steamId, cookie),
+ new GetSessionRequest(token, steamId, cookie),
&CSteamProto::OnGotSession);
PushRequest(
- new SteamWebApi::LogonRequest(token),
+ new LogonRequest(token),
&CSteamProto::OnLoggedOn);
}
-void CSteamProto::OnGotSession(const NETLIBHTTPREQUEST *response, void *)
+void CSteamProto::OnGotSession(const NETLIBHTTPREQUEST *response)
{
if(response == NULL)
return;
@@ -224,7 +223,7 @@ void CSteamProto::HandleTokenExpired()
SetStatus(ID_STATUS_OFFLINE);
}
-void CSteamProto::OnLoggedOn(const NETLIBHTTPREQUEST *response, void *)
+void CSteamProto::OnLoggedOn(const NETLIBHTTPREQUEST *response)
{
if (response == NULL)
{
@@ -255,7 +254,7 @@ void CSteamProto::OnLoggedOn(const NETLIBHTTPREQUEST *response, void *)
ptrA steamId(getStringA("SteamID"));
PushRequest(
- new SteamWebApi::GetFriendListRequest(token, steamId),
+ new GetFriendListRequest(token, steamId),
&CSteamProto::OnGotFriendList);
// start polling thread
diff --git a/protocols/Steam/src/steam_avatars.cpp b/protocols/Steam/src/steam_avatars.cpp
index ec2694b878..053a526134 100644
--- a/protocols/Steam/src/steam_avatars.cpp
+++ b/protocols/Steam/src/steam_avatars.cpp
@@ -79,10 +79,9 @@ INT_PTR CSteamProto::GetAvatarInfo(WPARAM wParam, LPARAM lParam)
if (needLoad)
{
PushRequest(
- new SteamWebApi::GetAvatarRequest(avatarUrl),
+ new GetAvatarRequest(avatarUrl),
&CSteamProto::OnGotAvatar,
- (void*)pai->hContact,
- ARG_NO_FREE);
+ (void*)pai->hContact);
return GAIR_WAITFOR;
}
diff --git a/protocols/Steam/src/steam_contacts.cpp b/protocols/Steam/src/steam_contacts.cpp
index c15a839e85..655c0814f2 100644
--- a/protocols/Steam/src/steam_contacts.cpp
+++ b/protocols/Steam/src/steam_contacts.cpp
@@ -354,7 +354,7 @@ void CSteamProto::ProcessContact(std::map<std::string, JSONNODE*>::iterator *it,
}
}
-void CSteamProto::OnGotFriendList(const NETLIBHTTPREQUEST *response, void *)
+void CSteamProto::OnGotFriendList(const NETLIBHTTPREQUEST *response)
{
if (response == NULL)
return;
@@ -434,12 +434,12 @@ void CSteamProto::OnGotFriendList(const NETLIBHTTPREQUEST *response, void *)
ptrA token(getStringA("TokenSecret"));
PushRequest(
- new SteamWebApi::GetUserSummariesRequest(token, steamIds.c_str()),
+ new GetUserSummariesRequest(token, steamIds.c_str()),
&CSteamProto::OnGotUserSummaries);
}
}
-void CSteamProto::OnGotBlockList(const NETLIBHTTPREQUEST *response, void *)
+void CSteamProto::OnGotBlockList(const NETLIBHTTPREQUEST *response)
{
if (response == NULL)
return;
@@ -483,7 +483,7 @@ void CSteamProto::OnGotBlockList(const NETLIBHTTPREQUEST *response, void *)
}
}
-void CSteamProto::OnGotUserSummaries(const NETLIBHTTPREQUEST *response, void *)
+void CSteamProto::OnGotUserSummaries(const NETLIBHTTPREQUEST *response)
{
if (response == NULL)
return;
@@ -759,9 +759,9 @@ void CSteamProto::OnSearchByNameStarted(const NETLIBHTTPREQUEST *, void *)
//
// ptrA token(getStringA("TokenSecret"));
//
-// SteamWebApi::SearchApi::SearchResult searchResult;
-// debugLogA("CSteamProto::SearchByNameThread: call SteamWebApi::SearchApi::Search");
-// SteamWebApi::SearchApi::Search(m_hNetlibUser, token, keywords, &searchResult);
+// SearchApi::SearchResult searchResult;
+// debugLogA("CSteamProto::SearchByNameThread: call SearchApi::Search");
+// SearchApi::Search(m_hNetlibUser, token, keywords, &searchResult);
//
// if (!searchResult.IsSuccess())
// {
@@ -772,16 +772,16 @@ void CSteamProto::OnSearchByNameStarted(const NETLIBHTTPREQUEST *, void *)
// CMStringA steamIds;
// for (int i = 0; i < searchResult.GetItemCount(); i++)
// {
-// const SteamWebApi::SearchApi::SearchItem *item = searchResult.GetAt(i);
+// const SearchApi::SearchItem *item = searchResult.GetAt(i);
// if (steamIds.IsEmpty())
// steamIds.Append(item->GetSteamId());
// else
// steamIds.AppendFormat(",%s", item->GetSteamId());
// }
//
-// SteamWebApi::FriendApi::Summaries summarues;
-// debugLogA("CSteamProto::SearchByNameThread: call SteamWebApi::FriendApi::LoadSummaries");
-// SteamWebApi::FriendApi::LoadSummaries(m_hNetlibUser, token, steamIds, &summarues);
+// FriendApi::Summaries summarues;
+// debugLogA("CSteamProto::SearchByNameThread: call FriendApi::LoadSummaries");
+// FriendApi::LoadSummaries(m_hNetlibUser, token, steamIds, &summarues);
//
// if (!summarues.IsSuccess())
// {
@@ -791,7 +791,7 @@ void CSteamProto::OnSearchByNameStarted(const NETLIBHTTPREQUEST *, void *)
//
// for (size_t i = 0; i < summarues.GetItemCount(); i++)
// {
-// const SteamWebApi::FriendApi::Summary *contact = summarues.GetAt(i);
+// const FriendApi::Summary *contact = summarues.GetAt(i);
//
// STEAM_SEARCH_RESULT ssr = { 0 };
// ssr.hdr.cbSize = sizeof(STEAM_SEARCH_RESULT);
diff --git a/protocols/Steam/src/steam_events.cpp b/protocols/Steam/src/steam_events.cpp
index 434eaed925..cbaf2302ae 100644
--- a/protocols/Steam/src/steam_events.cpp
+++ b/protocols/Steam/src/steam_events.cpp
@@ -14,6 +14,8 @@ int CSteamProto::OnModulesLoaded(WPARAM, LPARAM)
nlu.szSettingsModule = m_szModuleName;
m_hNetlibUser = (HANDLE)CallService(MS_NETLIB_REGISTERUSER, 0, (LPARAM)&nlu);
+ requestQueue = new RequestQueue(m_hNetlibUser);
+
HookEvent(ME_CLIST_PREBUILDCONTACTMENU, &CSteamProto::PrebuildContactMenu);
return 0;
@@ -21,7 +23,7 @@ int CSteamProto::OnModulesLoaded(WPARAM, LPARAM)
int CSteamProto::OnPreShutdown(WPARAM, LPARAM)
{
- //SetStatus(ID_STATUS_OFFLINE);
+ delete requestQueue;
Netlib_CloseHandle(this->m_hNetlibUser);
this->m_hNetlibUser = NULL;
diff --git a/protocols/Steam/src/steam_menus.cpp b/protocols/Steam/src/steam_menus.cpp
index b18e6862aa..08a5ca7c03 100644
--- a/protocols/Steam/src/steam_menus.cpp
+++ b/protocols/Steam/src/steam_menus.cpp
@@ -33,10 +33,10 @@ int CSteamProto::BlockCommand(WPARAM hContact, LPARAM)
char *who = getStringA(hContact, "SteamID");
PushRequest(
- new SteamWebApi::BlockFriendRequest(token, sessionId, steamId, who),
+ new BlockFriendRequest(token, sessionId, steamId, who),
&CSteamProto::OnFriendBlocked,
who,
- ARG_MIR_FREE);
+ MirFreeArg);
return 0;
}
@@ -57,7 +57,7 @@ INT_PTR CSteamProto::OpenBlockListCommand(WPARAM, LPARAM)
ptrA steamId(getStringA("SteamID"));
PushRequest(
- new SteamWebApi::GetFriendListRequest(token, steamId, "ignoredfriend"),
+ new GetFriendListRequest(token, steamId, "ignoredfriend"),
&CSteamProto::OnGotBlockList);
return 0;
diff --git a/protocols/Steam/src/steam_messages.cpp b/protocols/Steam/src/steam_messages.cpp
index 3258613261..5a55919a07 100644
--- a/protocols/Steam/src/steam_messages.cpp
+++ b/protocols/Steam/src/steam_messages.cpp
@@ -8,9 +8,9 @@
// ptrA umqId(getStringA("UMQID"));
// ptrA steamId(getStringA(hContact, "SteamID"));
//
-// SteamWebApi::MessageApi::SendResult sendResult;
-// debugLogA("CSteamProto::SendTypingThread: call SteamWebApi::PollApi::SteamWebApi::MessageApi::SendMessage");
-// SteamWebApi::MessageApi::SendTyping(m_hNetlibUser, token, umqId, steamId, &sendResult);
+// MessageApi::SendResult sendResult;
+// debugLogA("CSteamProto::SendTypingThread: call PollApi::MessageApi::SendMessage");
+// MessageApi::SendTyping(m_hNetlibUser, token, umqId, steamId, &sendResult);
//}
void CSteamProto::OnMessageSent(const NETLIBHTTPREQUEST *response, void *arg)
@@ -46,4 +46,11 @@ void CSteamProto::OnMessageSent(const NETLIBHTTPREQUEST *response, void *arg)
status,
param->hMessage,
(LPARAM) errorA);
+}
+
+void CSteamProto::MessageParamFree(void *arg)
+{
+ SendMessageParam *param = (SendMessageParam*)arg;
+ mir_free(param->message);
+ 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 4ea31428e8..89768c1a81 100644
--- a/protocols/Steam/src/steam_pooling.cpp
+++ b/protocols/Steam/src/steam_pooling.cpp
@@ -127,10 +127,10 @@ void CSteamProto::ParsePollData(JSONNODE *data)
ptrA token(getStringA("TokenSecret"));
PushRequest(
- new SteamWebApi::GetUserSummariesRequest(token, steamId),
+ new GetUserSummariesRequest(token, steamId),
&CSteamProto::OnAuthRequested,
mir_strdup(steamId),
- ARG_MIR_FREE);
+ MirFreeArg);
}
break;
@@ -157,7 +157,7 @@ void CSteamProto::ParsePollData(JSONNODE *data)
ptrA token(getStringA("TokenSecret"));
PushRequest(
- new SteamWebApi::GetUserSummariesRequest(token, steamIds.c_str()),
+ new GetUserSummariesRequest(token, steamIds.c_str()),
&CSteamProto::OnGotUserSummaries);
}
}
@@ -170,12 +170,12 @@ void CSteamProto::PollingThread(void*)
ptrA umqId(getStringA("UMQID"));
UINT32 messageId = getDword("MessageID", 0);
- //SteamWebApi::PollApi::PollResult pollResult;
+ //PollApi::PollResult pollResult;
int errors = 0;
bool breaked = false;
while (!isTerminated && !breaked && errors < POLLING_ERRORS_LIMIT)
{
- SteamWebApi::PollRequest *request = new SteamWebApi::PollRequest(token, umqId, messageId, IdleSeconds());
+ PollRequest *request = new PollRequest(token, umqId, messageId, IdleSeconds());
//request->nlc = m_pollingConnection;
NETLIBHTTPREQUEST *response = request->Send(m_hNetlibUser);
delete request;
diff --git a/protocols/Steam/src/steam_proto.cpp b/protocols/Steam/src/steam_proto.cpp
index 2844492aa6..af5a3e677f 100644
--- a/protocols/Steam/src/steam_proto.cpp
+++ b/protocols/Steam/src/steam_proto.cpp
@@ -3,13 +3,10 @@
CSteamProto::CSteamProto(const char* protoName, const TCHAR* userName) :
PROTO<CSteamProto>(protoName, userName),
hAuthProcess(1),
- hMessageProcess(1),
- requestsQueue(1)
+ hMessageProcess(1)
{
CreateProtoService(PS_CREATEACCMGRUI, &CSteamProto::OnAccountManagerInit);
- InitQueue();
-
m_idleTS = 0;
isTerminated = false;
m_hQueueThread = NULL;
@@ -68,10 +65,9 @@ CSteamProto::CSteamProto(const char* protoName, const TCHAR* userName) :
CSteamProto::~CSteamProto()
{
- UninitQueue();
}
-MCONTACT __cdecl CSteamProto::AddToList(int, PROTOSEARCHRESULT* psr)
+MCONTACT CSteamProto::AddToList(int, PROTOSEARCHRESULT* psr)
{
MCONTACT hContact = NULL;
ptrA steamId(mir_u2a(psr->id));
@@ -85,7 +81,7 @@ MCONTACT __cdecl CSteamProto::AddToList(int, PROTOSEARCHRESULT* psr)
ptrA token(getStringA("TokenSecret"));
PushRequest(
- new SteamWebApi::GetUserSummariesRequest(token, steamId),
+ new GetUserSummariesRequest(token, steamId),
&CSteamProto::OnGotUserSummaries);
}
}
@@ -99,7 +95,7 @@ MCONTACT __cdecl CSteamProto::AddToList(int, PROTOSEARCHRESULT* psr)
return hContact;
}
-int __cdecl CSteamProto::Authorize(MEVENT hDbEvent)
+int CSteamProto::Authorize(MEVENT hDbEvent)
{
if (IsOnline() && hDbEvent)
{
@@ -115,10 +111,9 @@ int __cdecl CSteamProto::Authorize(MEVENT hDbEvent)
char *who = getStringA(hContact, "SteamID");
PushRequest(
- new SteamWebApi::ApprovePendingRequest(token, sessionId, steamId, who),
+ new ApprovePendingRequest(token, sessionId, steamId, who),
&CSteamProto::OnPendingApproved,
- who,
- ARG_MIR_FREE);
+ who, MirFreeArg);
return 0;
}
@@ -126,7 +121,7 @@ int __cdecl CSteamProto::Authorize(MEVENT hDbEvent)
return 1;
}
-int __cdecl CSteamProto::AuthDeny(MEVENT hDbEvent, const TCHAR*)
+int CSteamProto::AuthDeny(MEVENT hDbEvent, const TCHAR*)
{
if (IsOnline() && hDbEvent)
{
@@ -142,10 +137,9 @@ int __cdecl CSteamProto::AuthDeny(MEVENT hDbEvent, const TCHAR*)
char *who = getStringA(hContact, "SteamID");
PushRequest(
- new SteamWebApi::IgnorePendingRequest(token, sessionId, steamId, who),
+ new IgnorePendingRequest(token, sessionId, steamId, who),
&CSteamProto::OnPendingIgnoreded,
- who,
- ARG_MIR_FREE);
+ who, MirFreeArg);
return 0;
}
@@ -153,7 +147,7 @@ int __cdecl CSteamProto::AuthDeny(MEVENT hDbEvent, const TCHAR*)
return 1;
}
-int __cdecl CSteamProto::AuthRequest(MCONTACT hContact, const TCHAR*)
+int CSteamProto::AuthRequest(MCONTACT hContact, const TCHAR*)
{
if (IsOnline() && hContact)
{
@@ -182,10 +176,9 @@ int __cdecl CSteamProto::AuthRequest(MCONTACT hContact, const TCHAR*)
*/
PushRequest(
- new SteamWebApi::AddFriendRequest(token, sessionId, steamId, who),
+ new AddFriendRequest(token, sessionId, steamId, who),
&CSteamProto::OnFriendAdded,
- param,
- ARG_MIR_FREE);
+ param);
return hAuth;
}
@@ -193,7 +186,7 @@ int __cdecl CSteamProto::AuthRequest(MCONTACT hContact, const TCHAR*)
return 1;
}
-DWORD_PTR __cdecl CSteamProto:: GetCaps(int type, MCONTACT)
+DWORD_PTR CSteamProto:: GetCaps(int type, MCONTACT)
{
switch(type)
{
@@ -216,7 +209,7 @@ DWORD_PTR __cdecl CSteamProto:: GetCaps(int type, MCONTACT)
}
}
-HANDLE __cdecl CSteamProto::SearchBasic(const TCHAR* id)
+HANDLE CSteamProto::SearchBasic(const TCHAR* id)
{
if (!this->IsOnline())
return 0;
@@ -227,51 +220,43 @@ HANDLE __cdecl CSteamProto::SearchBasic(const TCHAR* id)
ptrA steamId(mir_t2a(id));
PushRequest(
- new SteamWebApi::GetUserSummariesRequest(token, steamId),
+ new GetUserSummariesRequest(token, steamId),
&CSteamProto::OnSearchByIdEnded,
mir_tstrdup(id),
- ARG_MIR_FREE);
+ MirFreeArg);
return (HANDLE)STEAM_SEARCH_BYID;
}
-int __cdecl CSteamProto::RecvMsg(MCONTACT hContact, PROTORECVEVENT* pre)
+int CSteamProto::RecvMsg(MCONTACT hContact, PROTORECVEVENT* pre)
{
return (INT_PTR)AddDBEvent(hContact, EVENTTYPE_MESSAGE, pre->timestamp, DBEF_UTF, mir_strlen(pre->szMessage), (BYTE*)pre->szMessage);
}
-int __cdecl CSteamProto::SendMsg(MCONTACT hContact, int, const char *msg)
+int CSteamProto::SendMsg(MCONTACT hContact, int flags, const char *message)
{
+ if (!IsOnline())
+ {
+ ProtoBroadcastAck(hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, NULL, (LPARAM)Translate("You cannot send messages when you are offline."));
+ return 0;
+ }
+
UINT hMessage = InterlockedIncrement(&hMessageProcess);
SendMessageParam *param = (SendMessageParam*)mir_calloc(sizeof(SendMessageParam));
param->hContact = hContact;
param->hMessage = (HANDLE)hMessage;
- param->msg = msg;
- ForkThread(&CSteamProto::SendMsgThread, (void*)param);
- return hMessage;
-}
-
-void __cdecl CSteamProto::SendMsgThread(void *arg)
-{
- SendMessageParam *param = (SendMessageParam*)arg;
-
- if (!IsOnline())
- {
- ProtoBroadcastAck(param->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, param->hMessage, (LPARAM)Translate("You cannot send messages when you are offline."));
- mir_free(param);
- return;
- }
+ param->message = mir_strdup(message);
ptrA token(getStringA("TokenSecret"));
ptrA umqid(getStringA("UMQID"));
- ptrA steamId(getStringA(param->hContact, "SteamID"));
-
+ ptrA steamId(getStringA(hContact, "SteamID"));
PushRequest(
- new SteamWebApi::SendMessageRequest(token, umqid, steamId, param->msg),
+ new SendMessageRequest(token, umqid, steamId, message),
&CSteamProto::OnMessageSent,
- param,
- ARG_MIR_FREE);
+ param, MessageParamFree);
+
+ return hMessage;
}
int CSteamProto::SetStatus(int new_status)
@@ -311,7 +296,11 @@ int CSteamProto::SetStatus(int new_status)
m_iStatus = m_iDesiredStatus = ID_STATUS_OFFLINE;
ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)old_status, m_iStatus);
- StopQueue();
+ ptrA token(getStringA("TokenSecret"));
+ ptrA umqid(getStringA("UMQID"));
+ SendRequest(new LogoffRequest(token, umqid));
+
+ requestQueue->Stop();
if (!Miranda_Terminated())
SetAllContactsStatus(ID_STATUS_OFFLINE);
@@ -321,7 +310,29 @@ int CSteamProto::SetStatus(int new_status)
m_iStatus = ID_STATUS_CONNECTING;
ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)old_status, m_iStatus);
- StartQueue();
+ requestQueue->Start();
+
+ ptrA token(getStringA("TokenSecret"));
+ if (mir_strlen(token) > 0)
+ {
+ PushRequest(
+ new LogonRequest(token),
+ &CSteamProto::OnLoggedOn);
+ }
+ else
+ {
+ ptrA username(mir_urlEncode(ptrA(mir_utf8encodeT(getTStringA("Username")))));
+ if (username == NULL || username[0] == '\0')
+ {
+ m_iStatus = m_iDesiredStatus = ID_STATUS_OFFLINE;
+ ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)ID_STATUS_CONNECTING, m_iStatus);
+ return 0;
+ }
+
+ PushRequest(
+ new RsaKeyRequest(username),
+ &CSteamProto::OnGotRsaKey);
+ }
}
else
{
@@ -334,7 +345,8 @@ int CSteamProto::SetStatus(int new_status)
int __cdecl CSteamProto::OnEvent(PROTOEVENTTYPE eventType, WPARAM wParam, LPARAM lParam)
{
- switch (eventType) {
+ switch (eventType)
+ {
case EV_PROTO_ONLOAD:
return this->OnModulesLoaded(wParam, lParam);
@@ -359,10 +371,9 @@ int __cdecl CSteamProto::OnEvent(PROTOEVENTTYPE eventType, WPARAM wParam, LPARAM
return 0;
PushRequest(
- new SteamWebApi::RemoveFriendRequest(token, sessionId, steamId, who),
+ new RemoveFriendRequest(token, sessionId, steamId, who),
&CSteamProto::OnFriendRemoved,
- (void*)hContact,
- ARG_NO_FREE);
+ (void*)hContact);
}
return 0;
diff --git a/protocols/Steam/src/steam_proto.h b/protocols/Steam/src/steam_proto.h
index 157fb71a8b..1f607ffd77 100644
--- a/protocols/Steam/src/steam_proto.h
+++ b/protocols/Steam/src/steam_proto.h
@@ -21,7 +21,7 @@ struct SendMessageParam
{
MCONTACT hContact;
HANDLE hMessage;
- const char *msg;
+ char *message;
};
struct STEAM_SEARCH_RESULT
@@ -56,50 +56,8 @@ 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;
-
- QueueItem(SteamWebApi::HttpRequest *request) :
- request(request), arg(NULL), responseCallback(NULL)/*, responseFailedCallback(NULL)*/ { }
-
- QueueItem(SteamWebApi::HttpRequest *request, RESPONSE response) :
- request(request), arg(NULL), responseCallback(response)/*, responseFailedCallback(NULL)*/ { }
-
- //QueueItem(SteamWebApi::HttpRequest *request, RESPONSE response, RESPONSE responseFailedCallback) :
- // request(request), arg(NULL), responseCallback(response), responseFailedCallback(responseFailedCallback) { }
-
- ~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;
- }
-};
+typedef void(CSteamProto::*SteamResponseCallback)(const NETLIBHTTPREQUEST *response);
+typedef void(CSteamProto::*SteamResponseWithArgCallback)(const NETLIBHTTPREQUEST *response, void *arg);
class CSteamProto : public PROTO<CSteamProto>
{
@@ -152,27 +110,23 @@ protected:
mir_cs contact_search_lock;
mir_cs requests_queue_lock;
mir_cs set_status_lock;
- LIST<QueueItem> requestsQueue;
// instances
static LIST<CSteamProto> InstanceList;
static int CompareProtos(const CSteamProto *p1, const CSteamProto *p2);
- // queue
- void InitQueue();
- void UninitQueue();
-
- void StartQueue();
- void StopQueue();
+ // requests
+ RequestQueue *requestQueue;
- void PushRequest(SteamWebApi::HttpRequest *request);
- void PushRequest(SteamWebApi::HttpRequest *request, RESPONSE response);
- void PushRequest(SteamWebApi::HttpRequest *request, RESPONSE response, void *arg, ARG_FREE_TYPE arg_free_type);
+ void PushRequest(HttpRequest *request);
+ void PushRequest(HttpRequest *request, SteamResponseCallback response);
+ void PushRequest(HttpRequest *request, SteamResponseWithArgCallback response, void *arg, HttpFinallyCallback last = NULL);
- void ExecuteRequest(QueueItem *requestItem);
+ void SendRequest(HttpRequest *request);
+ void SendRequest(HttpRequest *request, SteamResponseCallback response);
+ void SendRequest(HttpRequest *request, SteamResponseWithArgCallback response, void *arg, HttpFinallyCallback last = NULL);
- void __cdecl SendMsgThread(void*);
- void __cdecl QueueThread(void*);
+ static void MirFreeArg(void *arg) { mir_free(arg); }
// pooling thread
void ParsePollData(JSONNODE *data);
@@ -182,12 +136,12 @@ protected:
bool IsOnline();
bool IsMe(const char *steamId);
- void OnGotRsaKey(const NETLIBHTTPREQUEST *response, void *arg);
+ void OnGotRsaKey(const NETLIBHTTPREQUEST *response);
- void OnAuthorization(const NETLIBHTTPREQUEST *response, void *arg);
- void OnGotSession(const NETLIBHTTPREQUEST *response, void *arg);
+ void OnAuthorization(const NETLIBHTTPREQUEST *response);
+ void OnGotSession(const NETLIBHTTPREQUEST *response);
- void OnLoggedOn(const NETLIBHTTPREQUEST *response, void *arg);
+ void OnLoggedOn(const NETLIBHTTPREQUEST *response);
void HandleTokenExpired();
@@ -207,9 +161,9 @@ protected:
MCONTACT FindContact(const char *steamId);
MCONTACT AddContact(const char *steamId, bool isTemporary = false);
- void OnGotFriendList(const NETLIBHTTPREQUEST *response, void *arg);
- void OnGotBlockList(const NETLIBHTTPREQUEST *response, void *arg);
- void OnGotUserSummaries(const NETLIBHTTPREQUEST *response, void *arg);
+ void OnGotFriendList(const NETLIBHTTPREQUEST *response);
+ void OnGotBlockList(const NETLIBHTTPREQUEST *response);
+ void OnGotUserSummaries(const NETLIBHTTPREQUEST *response);
void OnGotAvatar(const NETLIBHTTPREQUEST *response, void *arg);
void OnFriendAdded(const NETLIBHTTPREQUEST *response, void *arg);
@@ -228,6 +182,7 @@ protected:
// messages
void OnMessageSent(const NETLIBHTTPREQUEST *response, void *arg);
+ static void MessageParamFree(void *arg);
// menus
HGENMENU m_hMenuRoot;
diff --git a/protocols/Steam/src/steam_queue.cpp b/protocols/Steam/src/steam_queue.cpp
deleted file mode 100644
index c838b91294..0000000000
--- a/protocols/Steam/src/steam_queue.cpp
+++ /dev/null
@@ -1,193 +0,0 @@
-#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(T2Utf(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
diff --git a/protocols/Steam/src/steam_request.cpp b/protocols/Steam/src/steam_request.cpp
new file mode 100644
index 0000000000..05a7b235b1
--- /dev/null
+++ b/protocols/Steam/src/steam_request.cpp
@@ -0,0 +1,73 @@
+#include "stdafx.h"
+
+class SteamResponseDelegate
+{
+private:
+ CSteamProto *proto;
+ SteamResponseCallback responseCallback;
+ SteamResponseWithArgCallback responseWithArgCallback;
+ HttpFinallyCallback httpFinallyCallback;
+
+ void *arg;
+ bool hasArg;
+
+public:
+ SteamResponseDelegate(CSteamProto *proto, SteamResponseCallback responseCallback)
+ : proto(proto), responseCallback(responseCallback), responseWithArgCallback(NULL), arg(NULL), httpFinallyCallback(NULL), hasArg(false) {}
+
+ SteamResponseDelegate(CSteamProto *proto, SteamResponseWithArgCallback responseCallback, void *arg, HttpFinallyCallback httpFinallyCallback)
+ : proto(proto), responseCallback(NULL), responseWithArgCallback(responseCallback), arg(arg), httpFinallyCallback(httpFinallyCallback), hasArg(true) { }
+
+ void Invoke(const NETLIBHTTPREQUEST *response)
+ {
+ if (hasArg)
+ {
+ (proto->*(responseWithArgCallback))(response, arg);
+ if (httpFinallyCallback != NULL)
+ httpFinallyCallback(arg);
+ }
+ else
+ (proto->*(responseCallback))(response);
+ }
+};
+
+static void SteamHttpResponse(const NETLIBHTTPREQUEST *response, void *arg)
+{
+ SteamResponseDelegate *delegate = (SteamResponseDelegate*)arg;
+ delegate->Invoke(response);
+ delete delegate;
+}
+
+void CSteamProto::PushRequest(HttpRequest *request)
+{
+ requestQueue->Push(request);
+}
+
+void CSteamProto::PushRequest(HttpRequest *request, SteamResponseCallback response)
+{
+ SteamResponseDelegate *delegate = new SteamResponseDelegate(this, response);
+ requestQueue->Push(request, SteamHttpResponse, delegate);
+}
+
+void CSteamProto::PushRequest(HttpRequest *request, SteamResponseWithArgCallback response, void *arg, HttpFinallyCallback last)
+{
+ SteamResponseDelegate *delegate = new SteamResponseDelegate(this, response, arg, last);
+ requestQueue->Push(request, SteamHttpResponse, delegate);
+}
+
+void CSteamProto::SendRequest(HttpRequest *request)
+{
+ requestQueue->Send(request, NULL, NULL);
+}
+
+void CSteamProto::SendRequest(HttpRequest *request, SteamResponseCallback response)
+{
+ SteamResponseDelegate *delegate = new SteamResponseDelegate(this, response);
+ requestQueue->Send(request, SteamHttpResponse, delegate);
+}
+
+void CSteamProto::SendRequest(HttpRequest *request, SteamResponseWithArgCallback response, void *arg, HttpFinallyCallback last)
+{
+ SteamResponseDelegate *delegate = new SteamResponseDelegate(this, response, arg, last);
+ requestQueue->Send(request, SteamHttpResponse, delegate);
+}
diff --git a/protocols/Steam/src/version.h b/protocols/Steam/src/version.h
index 8dff6cd310..5d504039c5 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 3
-#define __BUILD_NUM 3
+#define __RELEASE_NUM 4
+#define __BUILD_NUM 0
#include <stdver.h>