20#ifndef FREERDP_LIB_CORE_GATEWAY_HTTP_H
21#define FREERDP_LIB_CORE_GATEWAY_HTTP_H
23#include <winpr/stream.h>
25#include <freerdp/api.h>
26#include <freerdp/utils/http.h>
28#include "../../crypto/tls.h"
32 TransferEncodingUnknown,
33 TransferEncodingIdentity,
34 TransferEncodingChunked
39 ChunkStateLenghHeader,
48 size_t headerFooterPos;
54typedef struct s_http_context HttpContext;
56FREERDP_LOCAL
void http_context_free(HttpContext* context);
58WINPR_ATTR_MALLOC(http_context_free, 1)
60FREERDP_LOCAL HttpContext* http_context_new(
void);
62FREERDP_LOCAL BOOL http_context_set_method(HttpContext* context, const
char* Method);
63FREERDP_LOCAL const
char* http_context_get_uri(HttpContext* context);
64FREERDP_LOCAL BOOL http_context_set_uri(HttpContext* context, const
char* URI);
65FREERDP_LOCAL BOOL http_context_set_user_agent(HttpContext* context, const
char* UserAgent);
66FREERDP_LOCAL BOOL http_context_set_x_ms_user_agent(HttpContext* context, const
char* UserAgent);
67FREERDP_LOCAL BOOL http_context_set_host(HttpContext* context, const
char* Host);
68FREERDP_LOCAL BOOL http_context_set_accept(HttpContext* context, const
char* Accept);
69FREERDP_LOCAL BOOL http_context_set_cache_control(HttpContext* context, const
char* CacheControl);
70FREERDP_LOCAL BOOL http_context_set_connection(HttpContext* context, const
char* Connection);
71FREERDP_LOCAL BOOL http_context_set_pragma(HttpContext* context,
72 WINPR_FORMAT_ARG const
char* Pragma, ...);
73FREERDP_LOCAL BOOL http_context_append_pragma(HttpContext* context,
74 WINPR_FORMAT_ARG const
char* Pragma, ...);
75FREERDP_LOCAL BOOL http_context_set_cookie(HttpContext* context, const
char* CookieName,
76 const
char* CookieValue);
77FREERDP_LOCAL BOOL http_context_set_rdg_connection_id(HttpContext* context,
78 const GUID* RdgConnectionId);
79FREERDP_LOCAL BOOL http_context_set_rdg_correlation_id(HttpContext* context,
80 const GUID* RdgConnectionId);
82WINPR_ATTR_FORMAT_ARG(3, 4)
83FREERDP_LOCAL BOOL http_context_set_header(HttpContext* context, const
char* key,
84 WINPR_FORMAT_ARG const
char* value, ...);
85WINPR_ATTR_FORMAT_ARG(3, 0)
86FREERDP_LOCAL BOOL http_context_set_header_va(HttpContext* context, const
char* key,
87 WINPR_FORMAT_ARG const
char* value, va_list ap);
89FREERDP_LOCAL BOOL http_context_set_rdg_auth_scheme(HttpContext* context,
90 const
char* RdgAuthScheme);
91FREERDP_LOCAL BOOL http_context_enable_websocket_upgrade(HttpContext* context, BOOL enable);
92FREERDP_LOCAL BOOL http_context_is_websocket_upgrade_enabled(HttpContext* context);
95typedef struct s_http_request HttpRequest;
97FREERDP_LOCAL
void http_request_free(HttpRequest* request);
99WINPR_ATTR_MALLOC(http_request_free, 1)
101FREERDP_LOCAL HttpRequest* http_request_new(
void);
103FREERDP_LOCAL BOOL http_request_set_method(HttpRequest* request, const
char* Method);
104FREERDP_LOCAL BOOL http_request_set_content_type(HttpRequest* request, const
char* ContentType);
105FREERDP_LOCAL SSIZE_T http_request_get_content_length(HttpRequest* request);
106FREERDP_LOCAL BOOL http_request_set_content_length(HttpRequest* request,
size_t length);
108FREERDP_LOCAL const
char* http_request_get_uri(HttpRequest* request);
109FREERDP_LOCAL BOOL http_request_set_uri(HttpRequest* request, const
char* URI);
110FREERDP_LOCAL BOOL http_request_set_auth_scheme(HttpRequest* request, const
char* AuthScheme);
111FREERDP_LOCAL BOOL http_request_set_auth_param(HttpRequest* request, const
char* AuthParam);
112FREERDP_LOCAL BOOL http_request_set_transfer_encoding(HttpRequest* request,
113 TRANSFER_ENCODING TransferEncoding);
115WINPR_ATTR_FORMAT_ARG(3, 4)
116FREERDP_LOCAL BOOL http_request_set_header(HttpRequest* request, const
char* key,
117 WINPR_FORMAT_ARG const
char* value, ...);
118FREERDP_LOCAL
wStream* http_request_write(HttpContext* context, HttpRequest* request);
121typedef struct s_http_response HttpResponse;
123FREERDP_LOCAL
void http_response_free(HttpResponse* response);
125WINPR_ATTR_MALLOC(http_response_free, 1)
127FREERDP_LOCAL HttpResponse* http_response_new(
void);
129WINPR_ATTR_MALLOC(http_response_free, 1)
131FREERDP_LOCAL HttpResponse* http_response_recv(rdpTls* tls, BOOL readContentLength);
133FREERDP_LOCAL UINT16 http_response_get_status_code(const HttpResponse* response);
134FREERDP_LOCAL
size_t http_response_get_body_length(const HttpResponse* response);
135FREERDP_LOCAL const
char* http_response_get_body(const HttpResponse* response);
136FREERDP_LOCAL const
char* http_response_get_auth_token(const HttpResponse* response,
138FREERDP_LOCAL const
char* http_response_get_setcookie(const HttpResponse* response,
140FREERDP_LOCAL BOOL http_response_extract_cookies(const HttpResponse* response,
141 HttpContext* context);
142FREERDP_LOCAL TRANSFER_ENCODING http_response_get_transfer_encoding(const HttpResponse* response);
143FREERDP_LOCAL BOOL http_response_is_websocket(const HttpContext* http,
144 const HttpResponse* response);
146#define http_response_log_error_status(log, level, response) \
147 http_response_log_error_status_((log), (level), (response), __FILE__, __LINE__, __func__)
148FREERDP_LOCAL
void http_response_log_error_status_(wLog* log, DWORD level,
149 const HttpResponse* response,
const char* file,
150 size_t line,
const char* fkt);
153FREERDP_LOCAL
int http_chuncked_read(BIO* bio, BYTE* pBuffer,
size_t size,