summaryrefslogtreecommitdiff
path: root/protocols/Discord/src
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2017-06-05 15:16:22 +0300
committerGeorge Hazan <ghazan@miranda.im>2017-06-05 15:16:22 +0300
commita988d6727c150db41c5bfb222190d147b98f3b68 (patch)
tree43d202eaafa4536d8ba6aa3382903472e1268be8 /protocols/Discord/src
parent9a80a756aa3bee92b85e09466b234c4c26c744b4 (diff)
Discord: attempt to fix problems with unauthorized http requests
Diffstat (limited to 'protocols/Discord/src')
-rw-r--r--protocols/Discord/src/connection.cpp5
-rw-r--r--protocols/Discord/src/proto.cpp6
-rw-r--r--protocols/Discord/src/proto.h2
-rw-r--r--protocols/Discord/src/server.cpp13
-rw-r--r--protocols/Discord/src/version.h2
5 files changed, 19 insertions, 9 deletions
diff --git a/protocols/Discord/src/connection.cpp b/protocols/Discord/src/connection.cpp
index ae8da49d97..3d1ad8e83a 100644
--- a/protocols/Discord/src/connection.cpp
+++ b/protocols/Discord/src/connection.cpp
@@ -36,6 +36,8 @@ void CDiscordProto::ExecuteRequest(AsyncHttpRequest *pReq)
if (pReq->m_bMainSite) {
pReq->flags |= NLHRF_PERSISTENT;
pReq->nlc = m_hAPIConnection;
+ if (m_szAccessCookie)
+ pReq->AddHeader("Cookie", m_szAccessCookie);
}
debugLogA("Executing request #%d:\n%s", pReq->m_iReqNum, pReq->szUrl);
@@ -44,7 +46,8 @@ void CDiscordProto::ExecuteRequest(AsyncHttpRequest *pReq)
if (pReq->m_pCallback != nullptr)
(this->*(pReq->m_pCallback))(reply, pReq);
- m_hAPIConnection = reply->nlc;
+ if (pReq->m_bMainSite)
+ m_hAPIConnection = reply->nlc;
Netlib_FreeHttpRequest(reply);
}
diff --git a/protocols/Discord/src/proto.cpp b/protocols/Discord/src/proto.cpp
index 484657d7a5..70d666ac3e 100644
--- a/protocols/Discord/src/proto.cpp
+++ b/protocols/Discord/src/proto.cpp
@@ -83,14 +83,14 @@ CDiscordProto::CDiscordProto(const char *proto_name, const wchar_t *username) :
NETLIBUSER nlu = {};
nlu.szSettingsModule = m_szModuleName;
- nlu.flags = NUF_INCOMING | NUF_OUTGOING | NUF_HTTPCONNS | NUF_UNICODE;
+ nlu.flags = NUF_OUTGOING | NUF_HTTPCONNS | NUF_UNICODE;
descr.Format(TranslateT("%s server connection"), m_tszUserName);
nlu.szDescriptiveName.w = descr.GetBuffer();
m_hNetlibUser = Netlib_RegisterUser(&nlu);
CMStringA module(FORMAT, "%s.Gateway", m_szModuleName);
nlu.szSettingsModule = module.GetBuffer();
- nlu.flags = NUF_INCOMING | NUF_OUTGOING | NUF_UNICODE;
+ nlu.flags = NUF_OUTGOING | NUF_UNICODE;
descr.Format(TranslateT("%s gateway connection"), m_tszUserName);
nlu.szDescriptiveName.w = descr.GetBuffer();
m_hGatewayNetlibUser = Netlib_RegisterUser(&nlu);
@@ -346,7 +346,7 @@ int CDiscordProto::RecvMsg(MCONTACT hContact, PROTORECVEVENT *evt)
void __cdecl CDiscordProto::SendMessageAckThread(void *param)
{
Sleep(100);
- ProtoBroadcastAck((MCONTACT)param, ACKTYPE_MESSAGE, ACKRESULT_FAILED, (HANDLE)1, (LPARAM)Translate("Protocol is offline or user isn't authorized yet"));
+ ProtoBroadcastAck((UINT_PTR)param, ACKTYPE_MESSAGE, ACKRESULT_FAILED, (HANDLE)1, (LPARAM)Translate("Protocol is offline or user isn't authorized yet"));
}
int CDiscordProto::SendMsg(MCONTACT hContact, int /*flags*/, const char *pszSrc)
diff --git a/protocols/Discord/src/proto.h b/protocols/Discord/src/proto.h
index 67b0b52442..bf21c76b62 100644
--- a/protocols/Discord/src/proto.h
+++ b/protocols/Discord/src/proto.h
@@ -184,7 +184,7 @@ class CDiscordProto : public PROTO<CDiscordProto>
void ConnectionFailed(int iReason);
void ShutdownSession(void);
- ptrA m_szAccessToken;
+ ptrA m_szAccessToken, m_szAccessCookie;
mir_cs m_csHttpQueue;
HANDLE m_evRequestsQueue;
diff --git a/protocols/Discord/src/server.cpp b/protocols/Discord/src/server.cpp
index b19def5787..9b86b13fb5 100644
--- a/protocols/Discord/src/server.cpp
+++ b/protocols/Discord/src/server.cpp
@@ -159,7 +159,7 @@ void CDiscordProto::RetrieveUserInfo(MCONTACT hContact)
void CDiscordProto::OnReceiveUserInfo(NETLIBHTTPREQUEST *pReply, AsyncHttpRequest *pReq)
{
- MCONTACT hContact = (MCONTACT)pReq->pUserInfo;
+ MCONTACT hContact = (UINT_PTR)pReq->pUserInfo;
if (pReply->resultCode != 200) {
if (hContact == 0)
ConnectionFailed(LOGINERR_WRONGPASSWORD);
@@ -183,6 +183,13 @@ void CDiscordProto::OnReceiveUserInfo(NETLIBHTTPREQUEST *pReply, AsyncHttpReques
if (hContact == 0) {
m_ownId = id;
+ for (int i=0; i < pReply->headersCount; i++)
+ if (!strcmp(pReply->headers[i].szName, "Set-Cookie")) {
+ char *p = strchr(pReply->headers[i].szValue, ';');
+ if (p) *p = 0;
+ m_szAccessCookie = mir_strdup(pReply->headers[i].szValue);
+ }
+
OnLoggedIn();
}
else {
@@ -245,7 +252,7 @@ void CDiscordProto::SetServerStatus(int iStatus)
void CDiscordProto::OnReceiveAuth(NETLIBHTTPREQUEST *pReply, AsyncHttpRequest *pReq)
{
- MCONTACT hContact = (MCONTACT)pReq->pUserInfo;
+ MCONTACT hContact = (UINT_PTR)pReq->pUserInfo;
if (pReply->resultCode == 204)
RetrieveUserInfo(hContact);
}
@@ -267,7 +274,7 @@ void CDiscordProto::OnReceiveCreateChannel(NETLIBHTTPREQUEST *pReply, AsyncHttpR
void CDiscordProto::OnReceiveMessage(NETLIBHTTPREQUEST *pReply, AsyncHttpRequest *pReq)
{
- MCONTACT hContact = (MCONTACT)pReq->pUserInfo;
+ MCONTACT hContact = (UINT_PTR)pReq->pUserInfo;
bool bSucceeded = true;
if (pReply->resultCode != 200 && pReply->resultCode != 204)
diff --git a/protocols/Discord/src/version.h b/protocols/Discord/src/version.h
index e8f77f39b4..9a7de6bed8 100644
--- a/protocols/Discord/src/version.h
+++ b/protocols/Discord/src/version.h
@@ -1,7 +1,7 @@
#define __MAJOR_VERSION 0
#define __MINOR_VERSION 5
#define __RELEASE_NUM 0
-#define __BUILD_NUM 1
+#define __BUILD_NUM 2
#include <stdver.h>