From 3e34adae711d9ddf79b4959143a696b6a403a522 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Wed, 28 Dec 2016 20:30:46 +0300 Subject: first version that logs in successfully --- protocols/Discord/src/http.cpp | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) (limited to 'protocols/Discord/src/http.cpp') diff --git a/protocols/Discord/src/http.cpp b/protocols/Discord/src/http.cpp index 5333d87a65..3e513ee8d0 100644 --- a/protocols/Discord/src/http.cpp +++ b/protocols/Discord/src/http.cpp @@ -35,27 +35,32 @@ static LONG g_reqNum = 0; AsyncHttpRequest::AsyncHttpRequest() { cbSize = sizeof(NETLIBHTTPREQUEST); - AddHeader("Connection", "keep-alive"); - pUserInfo = NULL; - m_iErrorCode = 0; - m_pCallback = NULL; m_iReqNum = ::InterlockedIncrement(&g_reqNum); } -AsyncHttpRequest::AsyncHttpRequest(CDiscordProto *ppro, int iRequestType, LPCSTR _url, HttpCallback pFunc) +AsyncHttpRequest::AsyncHttpRequest(CDiscordProto *ppro, int iRequestType, LPCSTR _url, HttpCallback pFunc, JSONNode *pRoot) { cbSize = sizeof(NETLIBHTTPREQUEST); - AddHeader("Connection", "keep-alive"); - + if (*_url == '/') { // relative url leads to a site - m_szUrl = "https://discardapp.com"; + m_szUrl = "https://discordapp.com/api"; m_szUrl += _url; } else m_szUrl = _url; - flags = NLHRF_DUMPASTEXT | NLHRF_HTTP11 | NLHRF_REDIRECT | NLHRF_SSL; - if (ppro->m_szAccessToken != NULL) - this << CHAR_PARAM("access_token", ppro->m_szAccessToken); + flags = NLHRF_HTTP11 | NLHRF_REDIRECT | NLHRF_SSL; + if (ppro->m_szAccessToken == NULL) + flags |= NLHRF_NODUMPSEND; + else + flags |= NLHRF_DUMPASTEXT; + + if (pRoot != NULL) { + ptrW text(json_write(pRoot)); + pData = mir_utf8encodeW(text); + dataLength = (int)mir_strlen(pData); + + AddHeader("Content-Type", "application/json"); + } requestType = iRequestType; m_pCallback = pFunc; -- cgit v1.2.3