summaryrefslogtreecommitdiff
path: root/plugins/Dropbox/src/http_request.h
diff options
context:
space:
mode:
authorAlexander Lantsev <aunsane@gmail.com>2015-05-13 14:29:47 +0000
committerAlexander Lantsev <aunsane@gmail.com>2015-05-13 14:29:47 +0000
commit71846c4e387e27164ffde6b2e8a188b3bc21b2eb (patch)
tree0651eb829e128942cb0fe361862f93436fdb7a23 /plugins/Dropbox/src/http_request.h
parentf112b278674402d2ea5428307f84de193695a07c (diff)
Dropbox: refactoring of http requests
git-svn-id: http://svn.miranda-ng.org/main/trunk@13570 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/Dropbox/src/http_request.h')
-rw-r--r--plugins/Dropbox/src/http_request.h104
1 files changed, 83 insertions, 21 deletions
diff --git a/plugins/Dropbox/src/http_request.h b/plugins/Dropbox/src/http_request.h
index 3b41344776..79f6c09a65 100644
--- a/plugins/Dropbox/src/http_request.h
+++ b/plugins/Dropbox/src/http_request.h
@@ -15,33 +15,50 @@ enum HTTP_STATUS
HTTP_STATUS_INSUFICIENTE_STORAGE = 507
};
-class HttpRequest : public NETLIBHTTPREQUEST, public MZeroedObject
+class HttpRequestException
{
+ CMStringA message;
+
public:
- HttpRequest(HANDLE hNetlibConnection, int requestType, LPCSTR url)
+ HttpRequestException(const char *message) :
+ message(message)
{
- cbSize = sizeof(NETLIBHTTPREQUEST);
- flags = NLHRF_HTTP11;
- this->requestType = requestType;
+ }
- m_hNetlibConnection = hNetlibConnection;
- m_szUrl = mir_strdup(url);
+ const char* what() const throw()
+ {
+ return message.c_str();
}
+};
- ~HttpRequest()
+class HttpRequest : protected NETLIBHTTPREQUEST//, public MZeroedObject
+{
+private:
+ CMStringA m_szUrl;
+ va_list formatArgs;
+
+ void Init(int type)
{
- for (int i = 0; i < headersCount; i++) {
- mir_free(headers[i].szName);
- mir_free(headers[i].szValue);
- }
- mir_free(headers);
- mir_free(pData);
+ cbSize = sizeof(NETLIBHTTPREQUEST);
+ requestType = type;
+ flags = NLHRF_HTTP11 | NLHRF_SSL | NLHRF_NODUMPSEND | NLHRF_DUMPASTEXT;
+ szUrl = NULL;
+ headers = NULL;
+ headersCount = 0;
+ pData = NULL;
+ dataLength = 0;
+ resultCode = 0;
+ szResultDescr = NULL;
+ nlc = NULL;
+ timeout = 0;
}
+protected:
+ enum HttpRequestUrlFormat { FORMAT };
void AddHeader(LPCSTR szName, LPCSTR szValue)
{
- headers = (NETLIBHTTPHEADER*)mir_realloc(headers, sizeof(NETLIBHTTPHEADER)*(headersCount + 1));
+ headers = (NETLIBHTTPHEADER*)mir_realloc(headers, sizeof(NETLIBHTTPHEADER) * (headersCount + 1));
headers[headersCount].szName = mir_strdup(szName);
headers[headersCount].szValue = mir_strdup(szValue);
headersCount++;
@@ -89,15 +106,60 @@ public:
headersCount++;
}
- NETLIBHTTPREQUEST *Send()
+ void AddUrlParameter(const char *urlFormat, ...)
{
- szUrl = m_szUrl.GetBuffer();
- return (NETLIBHTTPREQUEST*)CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)m_hNetlibConnection, (LPARAM)this);
+ va_list urlArgs;
+ va_start(urlArgs, urlFormat);
+ m_szUrl += m_szUrl.Find('?') == -1 ? '?' : '&';
+ m_szUrl.AppendFormatV(urlFormat, urlArgs);
+ va_end(urlArgs);
}
-private:
- CMStringA m_szUrl;
- HANDLE m_hNetlibConnection;
+ /*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_szUrl = url;
+ }
+
+ HttpRequest(int type, HttpRequestUrlFormat, LPCSTR urlFormat, ...)
+ {
+ Init(type);
+
+ va_list formatArgs;
+ va_start(formatArgs, urlFormat);
+ m_szUrl.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);
+ }
+
+ NETLIBHTTPREQUEST* Send(HANDLE hNetlibConnection)
+ {
+ m_szUrl.Replace('\\', '/');
+ szUrl = m_szUrl.GetBuffer();
+ return (NETLIBHTTPREQUEST*)CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)hNetlibConnection, (LPARAM)this);
+ }
};
#endif //_HTTP_REQUEST_H_ \ No newline at end of file