From dd3d0e59dcd34beb222fcf612a51d3fee82c0e43 Mon Sep 17 00:00:00 2001 From: Alexander Lantsev Date: Tue, 17 Mar 2015 20:33:47 +0000 Subject: SkypeWeb: initial commit git-svn-id: http://svn.miranda-ng.org/main/trunk@12424 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/SkypeWeb/src/http_request.h | 83 +++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 protocols/SkypeWeb/src/http_request.h (limited to 'protocols/SkypeWeb/src/http_request.h') diff --git a/protocols/SkypeWeb/src/http_request.h b/protocols/SkypeWeb/src/http_request.h new file mode 100644 index 0000000000..40edf6895d --- /dev/null +++ b/protocols/SkypeWeb/src/http_request.h @@ -0,0 +1,83 @@ +#ifndef _HTTP_REQUEST_H_ +#define _HTTP_REQUEST_H_ + +class HttpRequest : protected NETLIBHTTPREQUEST, public MZeroedObject +{ +protected: + CMStringA url; + + HttpRequest() + { + cbSize = sizeof(NETLIBHTTPREQUEST); + } + + HttpRequest(int httpMethod, LPCSTR urlFormat, va_list args) + { + this->HttpRequest::HttpRequest(); + + requestType = httpMethod; + flags = NLHRF_HTTP11 | NLHRF_NODUMPSEND | NLHRF_DUMPASTEXT; + + url.AppendFormatV(urlFormat, args); + szUrl = url.GetBuffer(); + } + + 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 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 urlFormat, ...) + { + va_list args; + va_start(args, urlFormat); + this->HttpRequest::HttpRequest(type, urlFormat, args); + va_end(args); + } + + ~HttpRequest() + { + for (int i = 0; i < headersCount; i++) + { + mir_free(headers[i].szName); + mir_free(headers[i].szValue); + } + mir_free(headers); + mir_free(pData); + } + + void SetCookie(LPCSTR szValue) + { + AddHeader("Set-Cookie", szValue); + } + + NETLIBHTTPREQUEST * Send(HANDLE hConnection) + { + if (url.Find("http", 0) != 0) + url.Insert(0, flags & NLHRF_SSL ? "https://" : "http://"); + szUrl = url.GetBuffer(); + + char message[1024]; + mir_snprintf(message, SIZEOF(message), "Send request to %s", szUrl); + CallService(MS_NETLIB_LOG, (WPARAM)hConnection, (LPARAM)&message); + + return (NETLIBHTTPREQUEST*)CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)hConnection, (LPARAM)this); + } +}; + +#endif //_HTTP_REQUEST_H_ \ No newline at end of file -- cgit v1.2.3