FreeRDP
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 
30 typedef enum
31 {
32  TransferEncodingUnknown,
33  TransferEncodingIdentity,
34  TransferEncodingChunked
35 } TRANSFER_ENCODING;
36 
37 typedef enum
38 {
39  ChunkStateLenghHeader,
40  ChunkStateData,
41  ChunkStateFooter,
42  ChunkStateEnd
43 } CHUNK_STATE;
44 
45 typedef struct
46 {
47  size_t nextOffset;
48  size_t headerFooterPos;
49  CHUNK_STATE state;
50  char lenBuffer[11];
52 
53 /* HTTP context */
54 typedef struct s_http_context HttpContext;
55 
56 FREERDP_LOCAL void http_context_free(HttpContext* context);
57 
58 WINPR_ATTR_MALLOC(http_context_free, 1)
59 FREERDP_LOCAL HttpContext* http_context_new(void);
60 
61 FREERDP_LOCAL BOOL http_context_set_method(HttpContext* context, const char* Method);
62 FREERDP_LOCAL const char* http_context_get_uri(HttpContext* context);
63 FREERDP_LOCAL BOOL http_context_set_uri(HttpContext* context, const char* URI);
64 FREERDP_LOCAL BOOL http_context_set_user_agent(HttpContext* context, const char* UserAgent);
65 FREERDP_LOCAL BOOL http_context_set_x_ms_user_agent(HttpContext* context, const char* UserAgent);
66 FREERDP_LOCAL BOOL http_context_set_host(HttpContext* context, const char* Host);
67 FREERDP_LOCAL BOOL http_context_set_accept(HttpContext* context, const char* Accept);
68 FREERDP_LOCAL BOOL http_context_set_cache_control(HttpContext* context, const char* CacheControl);
69 FREERDP_LOCAL BOOL http_context_set_connection(HttpContext* context, const char* Connection);
70 FREERDP_LOCAL BOOL http_context_set_pragma(HttpContext* context,
71  WINPR_FORMAT_ARG const char* Pragma, ...);
72 FREERDP_LOCAL BOOL http_context_append_pragma(HttpContext* context,
73  WINPR_FORMAT_ARG const char* Pragma, ...);
74 FREERDP_LOCAL BOOL http_context_set_cookie(HttpContext* context, const char* CookieName,
75  const char* CookieValue);
76 FREERDP_LOCAL BOOL http_context_set_rdg_connection_id(HttpContext* context,
77  const GUID* RdgConnectionId);
78 FREERDP_LOCAL BOOL http_context_set_rdg_correlation_id(HttpContext* context,
79  const GUID* RdgConnectionId);
80 FREERDP_LOCAL BOOL http_context_set_rdg_auth_scheme(HttpContext* context,
81  const char* RdgAuthScheme);
82 FREERDP_LOCAL BOOL http_context_enable_websocket_upgrade(HttpContext* context, BOOL enable);
83 FREERDP_LOCAL BOOL http_context_is_websocket_upgrade_enabled(HttpContext* context);
84 
85 /* HTTP request */
86 typedef struct s_http_request HttpRequest;
87 
88 FREERDP_LOCAL void http_request_free(HttpRequest* request);
89 
90 WINPR_ATTR_MALLOC(http_request_free, 1)
91 FREERDP_LOCAL HttpRequest* http_request_new(void);
92 
93 FREERDP_LOCAL BOOL http_request_set_method(HttpRequest* request, const char* Method);
94 FREERDP_LOCAL BOOL http_request_set_content_type(HttpRequest* request, const char* ContentType);
95 FREERDP_LOCAL SSIZE_T http_request_get_content_length(HttpRequest* request);
96 FREERDP_LOCAL BOOL http_request_set_content_length(HttpRequest* request, size_t length);
97 
98 FREERDP_LOCAL const char* http_request_get_uri(HttpRequest* request);
99 FREERDP_LOCAL BOOL http_request_set_uri(HttpRequest* request, const char* URI);
100 FREERDP_LOCAL BOOL http_request_set_auth_scheme(HttpRequest* request, const char* AuthScheme);
101 FREERDP_LOCAL BOOL http_request_set_auth_param(HttpRequest* request, const char* AuthParam);
102 FREERDP_LOCAL BOOL http_request_set_transfer_encoding(HttpRequest* request,
103  TRANSFER_ENCODING TransferEncoding);
104 
105 FREERDP_LOCAL wStream* http_request_write(HttpContext* context, HttpRequest* request);
106 
107 /* HTTP response */
108 typedef struct s_http_response HttpResponse;
109 
110 FREERDP_LOCAL void http_response_free(HttpResponse* response);
111 
112 WINPR_ATTR_MALLOC(http_response_free, 1)
113 FREERDP_LOCAL HttpResponse* http_response_new(void);
114 
115 FREERDP_LOCAL HttpResponse* http_response_recv(rdpTls* tls, BOOL readContentLength);
116 
117 FREERDP_LOCAL INT16 http_response_get_status_code(const HttpResponse* response);
118 FREERDP_LOCAL size_t http_response_get_body_length(const HttpResponse* response);
119 FREERDP_LOCAL const BYTE* http_response_get_body(const HttpResponse* response);
120 FREERDP_LOCAL const char* http_response_get_auth_token(const HttpResponse* response,
121  const char* method);
122 FREERDP_LOCAL const char* http_response_get_setcookie(const HttpResponse* response,
123  const char* cookie);
124 FREERDP_LOCAL TRANSFER_ENCODING http_response_get_transfer_encoding(const HttpResponse* response);
125 FREERDP_LOCAL BOOL http_response_is_websocket(const HttpContext* http,
126  const HttpResponse* response);
127 
128 FREERDP_LOCAL void http_response_log_error_status(wLog* log, DWORD level,
129  const HttpResponse* response);
130 
131 /* chunked read helper */
132 FREERDP_LOCAL int http_chuncked_read(BIO* bio, BYTE* pBuffer, size_t size,
133  http_encoding_chunked_context* encodingContext);
134 
135 #endif /* FREERDP_LIB_CORE_GATEWAY_HTTP_H */