Debian Codegraph @

crt/aws-c-http/include/aws/http/private/websocket_impl.h

raw symbols SCIP
1 #ifndef AWS_HTTP_WEBSOCKET_IMPL_H
2 #define AWS_HTTP_WEBSOCKET_IMPL_H
3
4 /**
5 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
6 * SPDX-License-Identifier: Apache-2.0.
7 */
8
9 #include <aws/http/websocket.h>
10
11 struct aws_http_client_connection_options;
12 struct aws_http_connection;
13 struct aws_http_make_request_options;
14
15 /* RFC-6455 Section 5.2 Base Framing Protocol
16 * Payload length: 7 bits, 7+16 bits, or 7+64 bits
17 *
18 * The length of the "Payload data", in bytes: if 0-125, that is the
19 * payload length. If 126, the following 2 bytes interpreted as a
20 * 16-bit unsigned integer are the payload length. If 127, the
21 * following 8 bytes interpreted as a 64-bit unsigned integer (the
22 * most significant bit MUST be 0) are the payload length. Multibyte
23 * length quantities are expressed in network byte order. Note that
24 * in all cases, the minimal number of bytes MUST be used to encode
25 * the length, for example, the length of a 124-byte-long string
26 * can't be encoded as the sequence 126, 0, 124. The payload length
27 * is the length of the "Extension data" + the length of the
28 * "Application data". The length of the "Extension data" may be
29 * zero, in which case the payload length is the length of the
30 * "Application data".
31 */
32 #define AWS_WEBSOCKET_7BIT_VALUE_FOR_2BYTE_EXTENDED_LENGTH 126
33 #define AWS_WEBSOCKET_7BIT_VALUE_FOR_8BYTE_EXTENDED_LENGTH 127
34
35 #define AWS_WEBSOCKET_2BYTE_EXTENDED_LENGTH_MIN_VALUE AWS_WEBSOCKET_7BIT_VALUE_FOR_2BYTE_EXTENDED_LENGTH
36 #define AWS_WEBSOCKET_2BYTE_EXTENDED_LENGTH_MAX_VALUE 0x000000000000FFFF
37
38 #define AWS_WEBSOCKET_8BYTE_EXTENDED_LENGTH_MIN_VALUE 0x0000000000010000
39 #define AWS_WEBSOCKET_8BYTE_EXTENDED_LENGTH_MAX_VALUE 0x7FFFFFFFFFFFFFFF
40
41 /* Max bytes necessary to send non-payload parts of a frame */
42 #define AWS_WEBSOCKET_MAX_FRAME_OVERHEAD (2 + 8 + 4) /* base + extended-length + masking-key */
43
44 /**
45 * Full contents of a websocket frame, excluding the payload.
46 */
47 struct aws_websocket_frame {
48 bool fin;
49 bool rsv[3];
50 bool masked;
51 uint8_t opcode;
52 uint64_t payload_length;
53 uint8_t masking_key[4];
54 };
55
56 struct aws_websocket_handler_options {
57 struct aws_allocator *allocator;
58 struct aws_channel *channel;
59 size_t initial_window_size;
60
61 void *user_data;
62 aws_websocket_on_incoming_frame_begin_fn *on_incoming_frame_begin;
63 aws_websocket_on_incoming_frame_payload_fn *on_incoming_frame_payload;
64 aws_websocket_on_incoming_frame_complete_fn *on_incoming_frame_complete;
65
66 bool is_server;
67 bool manual_window_update;
68 };
69
70 struct aws_websocket_client_bootstrap_system_vtable {
71 int (*aws_http_client_connect)(const struct aws_http_client_connection_options *options);
72 void (*aws_http_connection_release)(struct aws_http_connection *connection);
73 void (*aws_http_connection_close)(struct aws_http_connection *connection);
74 struct aws_channel *(*aws_http_connection_get_channel)(struct aws_http_connection *connection);
75 struct aws_http_stream *(*aws_http_connection_make_request)(
76 struct aws_http_connection *client_connection,
77 const struct aws_http_make_request_options *options);
78 int (*aws_http_stream_activate)(struct aws_http_stream *stream);
79 void (*aws_http_stream_release)(struct aws_http_stream *stream);
80 struct aws_http_connection *(*aws_http_stream_get_connection)(const struct aws_http_stream *stream);
81 void (*aws_http_stream_update_window)(struct aws_http_stream *stream, size_t increment_size);
82 int (*aws_http_stream_get_incoming_response_status)(const struct aws_http_stream *stream, int *out_status);
83 struct aws_websocket *(*aws_websocket_handler_new)(const struct aws_websocket_handler_options *options);
84 };
85
86 AWS_EXTERN_C_BEGIN
87
88 /**
89 * Returns printable name for opcode as c-string.
90 */
91 AWS_HTTP_API
92 const char *aws_websocket_opcode_str(uint8_t opcode);
93
94 /**
95 * Return total number of bytes needed to encode frame and its payload
96 */
97 AWS_HTTP_API
98 uint64_t aws_websocket_frame_encoded_size(const struct aws_websocket_frame *frame);
99
100 /**
101 * Create a websocket channel-handler and insert it into the channel.
102 */
103 AWS_HTTP_API
104 struct aws_websocket *aws_websocket_handler_new(const struct aws_websocket_handler_options *options);
105
106 /**
107 * Override the functions that websocket bootstrap uses to interact with external systems.
108 * Used for unit testing.
109 */
110 AWS_HTTP_API
111 void aws_websocket_client_bootstrap_set_system_vtable(
112 const struct aws_websocket_client_bootstrap_system_vtable *system_vtable);
113
114 AWS_EXTERN_C_END
115 #endif /* AWS_HTTP_WEBSOCKET_IMPL_H */