summaryrefslogtreecommitdiff
path: root/protocols/Steam/src/http_request.h
diff options
context:
space:
mode:
authorAlexander Lantsev <aunsane@gmail.com>2014-03-30 11:03:57 +0000
committerAlexander Lantsev <aunsane@gmail.com>2014-03-30 11:03:57 +0000
commitf1b2e090d9a10b4fc6dc7326856cb5be81a1d4d8 (patch)
tree7bcea5fac7674bfbe0e9c3cfac31d073ee01dbb0 /protocols/Steam/src/http_request.h
parentd3fc664a564c8864eca2b2cd19396940e45f4dca (diff)
Steam: init commit
git-svn-id: http://svn.miranda-ng.org/main/trunk@8790 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/Steam/src/http_request.h')
-rw-r--r--protocols/Steam/src/http_request.h151
1 files changed, 151 insertions, 0 deletions
diff --git a/protocols/Steam/src/http_request.h b/protocols/Steam/src/http_request.h
new file mode 100644
index 0000000000..6d142bdc73
--- /dev/null
+++ b/protocols/Steam/src/http_request.h
@@ -0,0 +1,151 @@
+#ifndef _HTTP_REQUEST_H_
+#define _HTTP_REQUEST_H_
+
+#include "steam.h"
+
+enum HTTP_STATUS
+{
+ HTTP_STATUS_OK = 200/*,
+ HTTP_STATUS_BAD_REQUEST = 400,
+ HTTP_STATUS_UNAUTHORIZED = 401,
+ HTTP_STATUS_FORBIDDEN = 403,
+ HTTP_STATUS_NOT_FOUND = 404,
+ HTTP_STATUS_METHOD_NOT_ALLOWED = 405,
+ HTTP_STATUS_TOO_MANY_REQUESTS = 429,
+ HTTP_STATUS_SERVICE_UNAVAILABLE = 503,
+ HTTP_STATUS_INSUFICIENTE_STORAGE = 507*/
+};
+
+class HttpRequest : private NETLIBHTTPREQUEST//, public MZeroedObject
+{
+public:
+ HttpRequest(HANDLE hNetlibUser, int request, LPCSTR url)
+ {
+ cbSize = sizeof(NETLIBHTTPREQUEST);
+ pData = NULL;
+ szUrl = NULL;
+ headers = NULL;
+ dataLength = 0;
+ headersCount = 0;
+ szResultDescr = NULL;
+ flags = NLHRF_HTTP11;
+ requestType = request;
+
+ m_hNetlibUser = hNetlibUser;
+ m_szUrl = mir_strdup(url);
+ }
+
+ ~HttpRequest()
+ {
+ if (headers != NULL)
+ {
+ 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);
+ }
+
+
+ void AddHeader(LPCSTR szName, LPCSTR szValue)
+ {
+ if (headers == NULL)
+ headers = (NETLIBHTTPHEADER*)mir_alloc(sizeof(NETLIBHTTPHEADER));
+ else
+ headers = (NETLIBHTTPHEADER*)mir_realloc(headers, sizeof(NETLIBHTTPHEADER) * (headersCount + 1));
+ headers[headersCount].szName = mir_strdup(szName);
+ headers[headersCount].szValue = mir_strdup(szValue);
+ headersCount++;
+ }
+
+ void SetData(const char *data, size_t size)
+ {
+ if (pData != NULL)
+ mir_free(pData);
+
+ dataLength = size;
+ pData = (char*)mir_alloc(size);
+ memcpy(pData, data, size);
+ }
+
+ /*void AddBasicAuthHeader(LPCSTR szLogin, LPCSTR szPassword)
+ {
+ char cPair[128];
+ mir_snprintf(
+ cPair,
+ SIZEOF(cPair),
+ "%s:%s",
+ szLogin,
+ szPassword);
+
+ char *ePair = (char *)mir_base64_encode((BYTE*)cPair, (UINT)strlen(cPair));
+
+ char value[128];
+ mir_snprintf(
+ value,
+ SIZEOF(value),
+ "Basic %s",
+ ePair);
+
+ mir_free(ePair);
+
+ headers = (NETLIBHTTPHEADER*)mir_realloc(headers, sizeof(NETLIBHTTPHEADER)*(headersCount+1));
+ headers[headersCount].szName = mir_strdup("Authorization");
+ headers[headersCount].szValue = mir_strdup(value);
+ headersCount++;
+ }
+
+ void AddBearerAuthHeader(LPCSTR szValue)
+ {
+ char value[128];
+ mir_snprintf(
+ value,
+ SIZEOF(value),
+ "Bearer %s",
+ szValue);
+
+ headers = (NETLIBHTTPHEADER*)mir_realloc(headers, sizeof(NETLIBHTTPHEADER)*(headersCount+1));
+ headers[headersCount].szName = mir_strdup("Authorization");
+ headers[headersCount].szValue = mir_strdup(value);
+ headersCount++;
+ }*/
+
+ void AddUrlPart(LPCSTR szPart)
+ {
+ m_szUrl += szPart;
+ }
+
+ void AddParameter(LPCSTR szName, LPCSTR szValue)
+ {
+ if (m_szUrl.Find('?') == -1)
+ m_szUrl.AppendFormat("?%s=%s", szName, szValue);
+ else
+ m_szUrl.AppendFormat("&%s=%s", szName, szValue);
+ }
+
+ /*void AddParameter(LPCSTR szName, int value)
+ {
+ if (m_szUrl.Find('?') == -1)
+ m_szUrl.AppendFormat("?%s=%i", szName, value);
+ else
+ m_szUrl.AppendFormat("&%s=%i", szName, value);
+ }*/
+
+ NETLIBHTTPREQUEST *Send()
+ {
+ szUrl = m_szUrl.GetBuffer();
+ /*CMStringA message; message.AppendFormat("Send request to %s", szUrl);
+ CallService(MS_NETLIB_LOG, (WPARAM)m_hNetlibUser, (LPARAM)message.GetBuffer());*/
+ return (NETLIBHTTPREQUEST*)CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)m_hNetlibUser, (LPARAM)this);
+ }
+
+private:
+ CMStringA m_szUrl;
+ HANDLE m_hNetlibUser;
+};
+
+#endif //_HTTP_REQUEST_H_ \ No newline at end of file