diff options
Diffstat (limited to 'protocols/CloudFile/src/http_request.h')
-rw-r--r-- | protocols/CloudFile/src/http_request.h | 82 |
1 files changed, 6 insertions, 76 deletions
diff --git a/protocols/CloudFile/src/http_request.h b/protocols/CloudFile/src/http_request.h index 68be404921..214ecea761 100644 --- a/protocols/CloudFile/src/http_request.h +++ b/protocols/CloudFile/src/http_request.h @@ -17,7 +17,7 @@ public: } }; -class HttpRequest : protected NETLIBHTTPREQUEST +class HttpRequest : public MHttpRequest { private: CMStringA m_szUrl; @@ -26,28 +26,11 @@ private: { requestType = type; flags = NLHRF_HTTP11 | NLHRF_SSL | NLHRF_NODUMP; - 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[headersCount].szName = mir_strdup(szName); - headers[headersCount].szValue = mir_strdup(szValue); - headersCount++; - } - void AddBasicAuthHeader(LPCSTR szLogin, LPCSTR szPassword) { size_t length = mir_strlen(szLogin) + mir_strlen(szPassword) + 1; @@ -60,47 +43,17 @@ protected: szPassword); ptrA ePair(mir_base64_encode(cPair, length)); - - length = mir_strlen(ePair) + 7; - char *value = (char*)mir_calloc(length + 1); - mir_snprintf(value, length, "Basic %s", ePair.get()); - - headers = (NETLIBHTTPHEADER*)mir_realloc(headers, sizeof(NETLIBHTTPHEADER)*(headersCount + 1)); - headers[headersCount].szName = mir_strdup("Authorization"); - headers[headersCount].szValue = value; - headersCount++; + AddHeader("Authorization", CMStringA(FORMAT, "Basic %s", ePair.get())); } void AddBearerAuthHeader(LPCSTR szValue) { - size_t length = mir_strlen(szValue) + 8; - char *value = (char*)mir_calloc(length + 1); - mir_snprintf( - value, - length, - "Bearer %s", - szValue); - - headers = (NETLIBHTTPHEADER*)mir_realloc(headers, sizeof(NETLIBHTTPHEADER)*(headersCount + 1)); - headers[headersCount].szName = mir_strdup("Authorization"); - headers[headersCount].szValue = value; - headersCount++; + AddHeader("Authorization", CMStringA(FORMAT, "Bearer %s", szValue)); } void AddOAuthHeader(LPCSTR szValue) { - size_t length = mir_strlen(szValue) + 7; - char *value = (char*)mir_calloc(length + 1); - mir_snprintf( - value, - length, - "OAuth %s", - szValue); - - headers = (NETLIBHTTPHEADER*)mir_realloc(headers, sizeof(NETLIBHTTPHEADER)*(headersCount + 1)); - headers[headersCount].szName = mir_strdup("Authorization"); - headers[headersCount].szValue = value; - headersCount++; + AddHeader("Authorization", CMStringA(FORMAT, "OAuth %s", szValue)); } void AddUrlParameter(const char *urlFormat, ...) @@ -124,16 +77,6 @@ protected: va_end(valueArgs); } - void SetData(const char *data, size_t size) - { - if (pData != NULL) - mir_free(pData); - - dataLength = (int)size; - pData = (char*)mir_alloc(size); - memcpy(pData, data, size); - } - public: HttpRequest(int type, LPCSTR url) { @@ -142,7 +85,7 @@ public: m_szUrl = url; } - HttpRequest(int type, HttpRequestUrlFormat, LPCSTR urlFormat, ...) + HttpRequest(int type, CMStringDataFormat, LPCSTR urlFormat, ...) { Init(type); @@ -152,22 +95,9 @@ public: 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) - mir_free(pData); - } - - NETLIBHTTPREQUEST* Send(HNETLIBUSER hConnection) + MHttpResponse* Send(HNETLIBUSER hConnection) { m_szUrl.Replace('\\', '/'); - szUrl = m_szUrl.GetBuffer(); return Netlib_HttpTransaction(hConnection, this); } }; |