FreeRDP
Loading...
Searching...
No Matches
libfreerdp/core/gateway/http.h
1
20#ifndef FREERDP_LIB_CORE_GATEWAY_HTTP_H
21#define FREERDP_LIB_CORE_GATEWAY_HTTP_H
22
23#include <winpr/stream.h>
24
25#include <freerdp/api.h>
26#include <freerdp/utils/http.h>
27
28#include "../../crypto/tls.h"
29
30typedef enum
31{
32 TransferEncodingUnknown,
33 TransferEncodingIdentity,
34 TransferEncodingChunked
35} TRANSFER_ENCODING;
36
37typedef enum
38{
39 ChunkStateLenghHeader,
40 ChunkStateData,
41 ChunkStateFooter,
42 ChunkStateEnd
43} CHUNK_STATE;
44
45typedef struct
46{
47 size_t nextOffset;
48 size_t headerFooterPos;
49 CHUNK_STATE state;
50 char lenBuffer[11];
52
53/* HTTP context */
54typedef struct s_http_context HttpContext;
55
56FREERDP_LOCAL void http_context_free(HttpContext* context);
57
58WINPR_ATTR_MALLOC(http_context_free, 1)
59WINPR_ATTR_NODISCARD
60FREERDP_LOCAL HttpContext* http_context_new(void);
61
62WINPR_ATTR_NODISCARD
63FREERDP_LOCAL BOOL http_context_set_method(HttpContext* context, const char* Method);
64
65WINPR_ATTR_NODISCARD
66FREERDP_LOCAL const char* http_context_get_uri(HttpContext* context);
67
68WINPR_ATTR_NODISCARD
69FREERDP_LOCAL BOOL http_context_set_uri(HttpContext* context, const char* URI);
70
71WINPR_ATTR_NODISCARD
72FREERDP_LOCAL BOOL http_context_set_user_agent(HttpContext* context, const char* UserAgent);
73
74WINPR_ATTR_NODISCARD
75FREERDP_LOCAL BOOL http_context_set_x_ms_user_agent(HttpContext* context, const char* UserAgent);
76
77WINPR_ATTR_NODISCARD
78FREERDP_LOCAL BOOL http_context_set_host(HttpContext* context, const char* Host);
79
80WINPR_ATTR_NODISCARD
81FREERDP_LOCAL BOOL http_context_set_accept(HttpContext* context, const char* Accept);
82
83WINPR_ATTR_NODISCARD
84FREERDP_LOCAL BOOL http_context_set_cache_control(HttpContext* context, const char* CacheControl);
85
86WINPR_ATTR_NODISCARD
87FREERDP_LOCAL BOOL http_context_set_connection(HttpContext* context, const char* Connection);
88
89WINPR_ATTR_NODISCARD
90FREERDP_LOCAL BOOL http_context_set_pragma(HttpContext* context,
91 WINPR_FORMAT_ARG const char* Pragma, ...);
92
93WINPR_ATTR_NODISCARD
94FREERDP_LOCAL BOOL http_context_append_pragma(HttpContext* context,
95 WINPR_FORMAT_ARG const char* Pragma, ...);
96
97WINPR_ATTR_NODISCARD
98FREERDP_LOCAL BOOL http_context_set_cookie(HttpContext* context, const char* CookieName,
99 const char* CookieValue);
100
101WINPR_ATTR_NODISCARD
102FREERDP_LOCAL BOOL http_context_set_rdg_connection_id(HttpContext* context,
103 const GUID* RdgConnectionId);
104
105WINPR_ATTR_NODISCARD
106FREERDP_LOCAL BOOL http_context_set_rdg_correlation_id(HttpContext* context,
107 const GUID* RdgCorrelationId);
108
109WINPR_ATTR_NODISCARD
110WINPR_ATTR_FORMAT_ARG(3, 4)
111FREERDP_LOCAL BOOL http_context_set_header(HttpContext* context, const char* key,
112 WINPR_FORMAT_ARG const char* value, ...);
113
114WINPR_ATTR_NODISCARD
115WINPR_ATTR_FORMAT_ARG(3, 0)
116FREERDP_LOCAL BOOL http_context_set_header_va(HttpContext* context, const char* key,
117 WINPR_FORMAT_ARG const char* value, va_list ap);
118
119WINPR_ATTR_NODISCARD
120FREERDP_LOCAL BOOL http_context_set_rdg_auth_scheme(HttpContext* context,
121 const char* RdgAuthScheme);
122
123FREERDP_LOCAL BOOL http_context_enable_websocket_upgrade(HttpContext* context, BOOL enable);
124
125WINPR_ATTR_NODISCARD
126FREERDP_LOCAL BOOL http_context_is_websocket_upgrade_enabled(HttpContext* context);
127
128/* HTTP request */
129typedef struct s_http_request HttpRequest;
130
131FREERDP_LOCAL void http_request_free(HttpRequest* request);
132
133WINPR_ATTR_MALLOC(http_request_free, 1)
134WINPR_ATTR_NODISCARD
135FREERDP_LOCAL HttpRequest* http_request_new(void);
136
137WINPR_ATTR_NODISCARD
138FREERDP_LOCAL BOOL http_request_set_method(HttpRequest* request, const char* Method);
139
140WINPR_ATTR_NODISCARD
141FREERDP_LOCAL BOOL http_request_set_content_type(HttpRequest* request, const char* ContentType);
142
143WINPR_ATTR_NODISCARD
144FREERDP_LOCAL SSIZE_T http_request_get_content_length(HttpRequest* request);
145
146WINPR_ATTR_NODISCARD
147FREERDP_LOCAL BOOL http_request_set_content_length(HttpRequest* request, size_t length);
148
149WINPR_ATTR_NODISCARD
150FREERDP_LOCAL const char* http_request_get_uri(HttpRequest* request);
151
152WINPR_ATTR_NODISCARD
153FREERDP_LOCAL BOOL http_request_set_uri(HttpRequest* request, const char* URI);
154
155WINPR_ATTR_NODISCARD
156FREERDP_LOCAL BOOL http_request_set_auth_scheme(HttpRequest* request, const char* AuthScheme);
157
158WINPR_ATTR_NODISCARD
159FREERDP_LOCAL BOOL http_request_set_auth_param(HttpRequest* request, const char* AuthParam);
160
161WINPR_ATTR_NODISCARD
162FREERDP_LOCAL BOOL http_request_set_transfer_encoding(HttpRequest* request,
163 TRANSFER_ENCODING TransferEncoding);
164
165WINPR_ATTR_NODISCARD
166WINPR_ATTR_FORMAT_ARG(3, 4)
167FREERDP_LOCAL BOOL http_request_set_header(HttpRequest* request, const char* key,
168 WINPR_FORMAT_ARG const char* value, ...);
169
170WINPR_ATTR_MALLOC(Stream_Free, 1)
171WINPR_ATTR_NODISCARD
172FREERDP_LOCAL wStream* http_request_write(HttpContext* context, HttpRequest* request);
173
174/* HTTP response */
175typedef struct s_http_response HttpResponse;
176
177FREERDP_LOCAL void http_response_free(HttpResponse* response);
178
179WINPR_ATTR_MALLOC(http_response_free, 1)
180WINPR_ATTR_NODISCARD
181FREERDP_LOCAL HttpResponse* http_response_new(void);
182
183WINPR_ATTR_MALLOC(http_response_free, 1)
184WINPR_ATTR_NODISCARD
185FREERDP_LOCAL HttpResponse* http_response_recv(rdpTls* tls, BOOL readContentLength);
186
187WINPR_ATTR_NODISCARD
188FREERDP_LOCAL UINT16 http_response_get_status_code(const HttpResponse* response);
189
190WINPR_ATTR_NODISCARD
191FREERDP_LOCAL size_t http_response_get_body_length(const HttpResponse* response);
192
193WINPR_ATTR_NODISCARD
194FREERDP_LOCAL const char* http_response_get_body(const HttpResponse* response);
195
196WINPR_ATTR_NODISCARD
197FREERDP_LOCAL const char* http_response_get_auth_token(const HttpResponse* response,
198 const char* method);
199
200WINPR_ATTR_NODISCARD
201FREERDP_LOCAL const char* http_response_get_setcookie(const HttpResponse* response,
202 const char* cookie);
203
204FREERDP_LOCAL BOOL http_response_extract_cookies(const HttpResponse* response,
205 HttpContext* context);
206
207WINPR_ATTR_NODISCARD
208FREERDP_LOCAL TRANSFER_ENCODING http_response_get_transfer_encoding(const HttpResponse* response);
209
210WINPR_ATTR_NODISCARD
211FREERDP_LOCAL BOOL http_response_is_websocket(const HttpContext* http,
212 const HttpResponse* response);
213
214#define http_response_log_error_status(log, level, response) \
215 http_response_log_error_status_((log), (level), (response), __FILE__, __LINE__, __func__)
216FREERDP_LOCAL void http_response_log_error_status_(wLog* log, DWORD level,
217 const HttpResponse* response, const char* file,
218 size_t line, const char* fkt);
219
220/* chunked read helper */
221WINPR_ATTR_NODISCARD
222FREERDP_LOCAL int http_chuncked_read(BIO* bio, BYTE* pBuffer, size_t size,
223 http_encoding_chunked_context* encodingContext);
224
225#endif /* FREERDP_LIB_CORE_GATEWAY_HTTP_H */