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)
59FREERDP_LOCAL HttpContext* http_context_new(void);
60
61FREERDP_LOCAL BOOL http_context_set_method(HttpContext* context, const char* Method);
62FREERDP_LOCAL const char* http_context_get_uri(HttpContext* context);
63FREERDP_LOCAL BOOL http_context_set_uri(HttpContext* context, const char* URI);
64FREERDP_LOCAL BOOL http_context_set_user_agent(HttpContext* context, const char* UserAgent);
65FREERDP_LOCAL BOOL http_context_set_x_ms_user_agent(HttpContext* context, const char* UserAgent);
66FREERDP_LOCAL BOOL http_context_set_host(HttpContext* context, const char* Host);
67FREERDP_LOCAL BOOL http_context_set_accept(HttpContext* context, const char* Accept);
68FREERDP_LOCAL BOOL http_context_set_cache_control(HttpContext* context, const char* CacheControl);
69FREERDP_LOCAL BOOL http_context_set_connection(HttpContext* context, const char* Connection);
70FREERDP_LOCAL BOOL http_context_set_pragma(HttpContext* context,
71 WINPR_FORMAT_ARG const char* Pragma, ...);
72FREERDP_LOCAL BOOL http_context_append_pragma(HttpContext* context,
73 WINPR_FORMAT_ARG const char* Pragma, ...);
74FREERDP_LOCAL BOOL http_context_set_cookie(HttpContext* context, const char* CookieName,
75 const char* CookieValue);
76FREERDP_LOCAL BOOL http_context_set_rdg_connection_id(HttpContext* context,
77 const GUID* RdgConnectionId);
78FREERDP_LOCAL BOOL http_context_set_rdg_correlation_id(HttpContext* context,
79 const GUID* RdgConnectionId);
80
81WINPR_ATTR_FORMAT_ARG(3, 4)
82FREERDP_LOCAL BOOL http_context_set_header(HttpContext* context, const char* key,
83 WINPR_FORMAT_ARG const char* value, ...);
84WINPR_ATTR_FORMAT_ARG(3, 0)
85FREERDP_LOCAL BOOL http_context_set_header_va(HttpContext* context, const char* key,
86 WINPR_FORMAT_ARG const char* value, va_list ap);
87
88FREERDP_LOCAL BOOL http_context_set_rdg_auth_scheme(HttpContext* context,
89 const char* RdgAuthScheme);
90FREERDP_LOCAL BOOL http_context_enable_websocket_upgrade(HttpContext* context, BOOL enable);
91FREERDP_LOCAL BOOL http_context_is_websocket_upgrade_enabled(HttpContext* context);
92
93/* HTTP request */
94typedef struct s_http_request HttpRequest;
95
96FREERDP_LOCAL void http_request_free(HttpRequest* request);
97
98WINPR_ATTR_MALLOC(http_request_free, 1)
99FREERDP_LOCAL HttpRequest* http_request_new(void);
100
101FREERDP_LOCAL BOOL http_request_set_method(HttpRequest* request, const char* Method);
102FREERDP_LOCAL BOOL http_request_set_content_type(HttpRequest* request, const char* ContentType);
103FREERDP_LOCAL SSIZE_T http_request_get_content_length(HttpRequest* request);
104FREERDP_LOCAL BOOL http_request_set_content_length(HttpRequest* request, size_t length);
105
106FREERDP_LOCAL const char* http_request_get_uri(HttpRequest* request);
107FREERDP_LOCAL BOOL http_request_set_uri(HttpRequest* request, const char* URI);
108FREERDP_LOCAL BOOL http_request_set_auth_scheme(HttpRequest* request, const char* AuthScheme);
109FREERDP_LOCAL BOOL http_request_set_auth_param(HttpRequest* request, const char* AuthParam);
110FREERDP_LOCAL BOOL http_request_set_transfer_encoding(HttpRequest* request,
111 TRANSFER_ENCODING TransferEncoding);
112
113WINPR_ATTR_FORMAT_ARG(3, 4)
114FREERDP_LOCAL BOOL http_request_set_header(HttpRequest* request, const char* key,
115 WINPR_FORMAT_ARG const char* value, ...);
116FREERDP_LOCAL wStream* http_request_write(HttpContext* context, HttpRequest* request);
117
118/* HTTP response */
119typedef struct s_http_response HttpResponse;
120
121FREERDP_LOCAL void http_response_free(HttpResponse* response);
122
123WINPR_ATTR_MALLOC(http_response_free, 1)
124FREERDP_LOCAL HttpResponse* http_response_new(void);
125
126WINPR_ATTR_MALLOC(http_response_free, 1)
127FREERDP_LOCAL HttpResponse* http_response_recv(rdpTls* tls, BOOL readContentLength);
128
129FREERDP_LOCAL UINT16 http_response_get_status_code(const HttpResponse* response);
130FREERDP_LOCAL size_t http_response_get_body_length(const HttpResponse* response);
131FREERDP_LOCAL const char* http_response_get_body(const HttpResponse* response);
132FREERDP_LOCAL const char* http_response_get_auth_token(const HttpResponse* response,
133 const char* method);
134FREERDP_LOCAL const char* http_response_get_setcookie(const HttpResponse* response,
135 const char* cookie);
136FREERDP_LOCAL BOOL http_response_extract_cookies(const HttpResponse* response,
137 HttpContext* context);
138FREERDP_LOCAL TRANSFER_ENCODING http_response_get_transfer_encoding(const HttpResponse* response);
139FREERDP_LOCAL BOOL http_response_is_websocket(const HttpContext* http,
140 const HttpResponse* response);
141
142#define http_response_log_error_status(log, level, response) \
143 http_response_log_error_status_((log), (level), (response), __FILE__, __LINE__, __func__)
144FREERDP_LOCAL void http_response_log_error_status_(wLog* log, DWORD level,
145 const HttpResponse* response, const char* file,
146 size_t line, const char* fkt);
147
148/* chunked read helper */
149FREERDP_LOCAL int http_chuncked_read(BIO* bio, BYTE* pBuffer, size_t size,
150 http_encoding_chunked_context* encodingContext);
151
152#endif /* FREERDP_LIB_CORE_GATEWAY_HTTP_H */