diff options
Diffstat (limited to 'protocols/SkypeWeb/src/http_request.h')
-rw-r--r-- | protocols/SkypeWeb/src/http_request.h | 170 |
1 files changed, 58 insertions, 112 deletions
diff --git a/protocols/SkypeWeb/src/http_request.h b/protocols/SkypeWeb/src/http_request.h index a7d9eb8937..e39bdf3032 100644 --- a/protocols/SkypeWeb/src/http_request.h +++ b/protocols/SkypeWeb/src/http_request.h @@ -34,52 +34,56 @@ struct FORMAT_VALUE : public VALUE }
};
-class HttpRequest : protected NETLIBHTTPREQUEST, public MZeroedObject
+class HttpRequest : private NETLIBHTTPREQUEST, public MZeroedObject
{
+private:
+ va_list formatArgs;
+ CMStringA url;
+
protected:
+ enum HttpRequestUrlFormat { FORMAT };
+
class HttpRequestUrl
{
friend HttpRequest;
private:
- CMStringA content;
+ HttpRequest &request;
- void AppendSeparator()
+ HttpRequestUrl(HttpRequest &request, const char *url) : request(request)
{
- if (!content.IsEmpty())
- {
- if (content.Find("?") == -1)
- content.AppendChar('?');
- else
- content.AppendChar('&');
- }
+ request.url = url;
+ request.szUrl = request.url.GetBuffer();
+ }
+
+ HttpRequestUrl(HttpRequest &request, const char *urlFormat, va_list args) : request(request)
+ {
+ request.url.AppendFormatV(urlFormat, args);
+ request.szUrl = request.url.GetBuffer();
}
public:
- HttpRequestUrl & operator<<(const VALUE ¶m)
+ HttpRequestUrl &operator<<(const VALUE ¶m)
{
- AppendSeparator();
- content.Append(param.szName);
+ request.AddUrlParameter(param.szName);
return *this;
}
- HttpRequestUrl & operator<<(const INT_VALUE ¶m)
+ HttpRequestUrl &operator<<(const INT_VALUE ¶m)
{
- AppendSeparator();
- content.AppendFormat("%s=%i", param.szName, param.iValue);
+ request.AddUrlParameter("%s=%i", param.szName, param.iValue);
return *this;
}
- HttpRequestUrl & operator<<(const CHAR_VALUE ¶m)
+ HttpRequestUrl &operator<<(const CHAR_VALUE ¶m)
{
- AppendSeparator();
- content.AppendFormat("%s=%s", param.szName, param.szValue);
+ request.AddUrlParameter("%s=%s", param.szName, param.szValue);
return *this;
}
- char * ToString()
+ char *ToString()
{
- return content.GetBuffer();
+ return request.url.GetBuffer();
}
};
@@ -116,6 +120,12 @@ protected: Add(param.szName, param.szValue);
return *this;
}
+
+ HttpRequestHeaders & operator<<(const FORMAT_VALUE ¶m)
+ {
+ Add(param.szName, param.szValue);
+ return *this;
+ }
};
class HttpRequestBody
@@ -168,17 +178,18 @@ protected: }
};
- HttpRequest() : Headers(*this)
+ void AddUrlParameter(const char *fmt, ...)
{
- cbSize = sizeof(NETLIBHTTPREQUEST);
- flags = NLHRF_HTTP11 | NLHRF_NODUMPSEND | NLHRF_DUMPASTEXT;
- }
+ va_list args;
+ va_start(args, fmt);
+ if (url.Find('?') == -1)
+ url += '?';
+ else
+ url += '&';
+ url.AppendFormatV(fmt, args);
+ va_end(args);
- HttpRequest(int httpMethod, LPCSTR urlFormat, va_list args)
- : Headers(*this)
- {
- requestType = httpMethod;
- Url.content.AppendFormatV(urlFormat, args);
+ szUrl = url.GetBuffer();
}
public:
@@ -186,13 +197,21 @@ public: HttpRequestHeaders Headers;
HttpRequestBody Body;
- HttpRequest(int type, LPCSTR urlFormat, ...)
- : Headers(*this)
+ HttpRequest(int type, LPCSTR url)
+ : Url(*this, url), Headers(*this)
{
- va_list args;
- va_start(args, urlFormat);
- this->HttpRequest::HttpRequest(type, urlFormat, args);
- va_end(args);
+ cbSize = sizeof(NETLIBHTTPREQUEST);
+ flags = NLHRF_HTTP11 | NLHRF_SSL | NLHRF_NODUMPSEND | NLHRF_DUMPASTEXT;
+ requestType = type;
+ }
+
+ HttpRequest(int type, HttpRequestUrlFormat format, LPCSTR urlFormat, ...)
+ : Url(*this, urlFormat, (va_start(formatArgs, urlFormat), formatArgs)), Headers(*this)
+ {
+ cbSize = sizeof(NETLIBHTTPREQUEST);
+ flags = NLHRF_HTTP11 | NLHRF_SSL | NLHRF_NODUMPSEND | NLHRF_DUMPASTEXT;
+ requestType = type;
+ va_end(formatArgs);
}
~HttpRequest()
@@ -203,14 +222,13 @@ public: mir_free(headers[i].szValue);
}
mir_free(headers);
- //mir_free(pData);
}
NETLIBHTTPREQUEST * Send(HANDLE hConnection)
{
- if (Url.content.Find("://") == -1)
- Url.content.Insert(0, flags & NLHRF_SSL ? "https://" : "http://");
- szUrl = Url.ToString();
+ if (url.Find("://") == -1)
+ url.Insert(0, flags & NLHRF_SSL ? "https://" : "http://");
+ szUrl = url.GetBuffer();
pData = Body.ToString();
dataLength = mir_strlen(pData);
@@ -223,76 +241,4 @@ public: }
};
-class HttpGetRequest : public HttpRequest
-{
-public:
- HttpGetRequest(LPCSTR urlFormat, ...)
- {
- va_list args;
- va_start(args, urlFormat);
- this->HttpRequest::HttpRequest(REQUEST_GET, urlFormat, args);
- va_end(args);
- }
-};
-
-class HttpPostRequest : public HttpRequest
-{
-public:
- HttpPostRequest(LPCSTR urlFormat, ...)
- {
- va_list args;
- va_start(args, urlFormat);
- this->HttpRequest::HttpRequest(REQUEST_POST, urlFormat, args);
- va_end(args);
-
- //Headers << CHAR_VALUE("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
- }
-};
-
-class HttpsRequest : public HttpRequest
-{
-protected:
- HttpsRequest() : HttpRequest()
- {
- flags = NLHRF_HTTP11 | NLHRF_SSL | NLHRF_NODUMPSEND | NLHRF_DUMPASTEXT;
- }
-
-public:
- HttpsRequest(int type, LPCSTR urlFormat, ...)
- {
- va_list args;
- va_start(args, urlFormat);
- this->HttpRequest::HttpRequest(type, urlFormat, args);
- va_end(args);
-
- flags = NLHRF_HTTP11 | NLHRF_SSL | NLHRF_NODUMPSEND | NLHRF_DUMPASTEXT;
- }
-};
-
-class HttpsGetRequest : public HttpsRequest
-{
-public:
- HttpsGetRequest(LPCSTR urlFormat, ...)
- {
- va_list args;
- va_start(args, urlFormat);
- this->HttpRequest::HttpRequest(REQUEST_GET, urlFormat, args);
- va_end(args);
- }
-};
-
-class HttpsPostRequest : public HttpsRequest
-{
-public:
- HttpsPostRequest(LPCSTR urlFormat, ...)
- {
- va_list args;
- va_start(args, urlFormat);
- this->HttpRequest::HttpRequest(REQUEST_POST, urlFormat, args);
- va_end(args);
-
- //Headers << CHAR_VALUE("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
- }
-};
-
#endif //_HTTP_REQUEST_H_
\ No newline at end of file |