| 1 |
#ifndef AWS_HTTP_H2_FRAMES_H |
| 2 |
#define AWS_HTTP_H2_FRAMES_H |
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
#include <aws/http/connection.h> |
| 10 |
#include <aws/http/private/hpack.h> |
| 11 |
#include <aws/http/request_response.h> |
| 12 |
|
| 13 |
#include <aws/common/byte_buf.h> |
| 14 |
|
| 15 |
|
| 16 |
enum aws_h2_frame_type { |
| 17 |
AWS_H2_FRAME_T_DATA = 0x00, |
| 18 |
AWS_H2_FRAME_T_HEADERS = 0x01, |
| 19 |
AWS_H2_FRAME_T_PRIORITY = 0x02, |
| 20 |
AWS_H2_FRAME_T_RST_STREAM = 0x03, |
| 21 |
AWS_H2_FRAME_T_SETTINGS = 0x04, |
| 22 |
AWS_H2_FRAME_T_PUSH_PROMISE = 0x05, |
| 23 |
AWS_H2_FRAME_T_PING = 0x06, |
| 24 |
AWS_H2_FRAME_T_GOAWAY = 0x07, |
| 25 |
AWS_H2_FRAME_T_WINDOW_UPDATE = 0x08, |
| 26 |
AWS_H2_FRAME_T_CONTINUATION = 0x09, |
| 27 |
AWS_H2_FRAME_T_UNKNOWN, |
| 28 |
AWS_H2_FRAME_TYPE_COUNT, |
| 29 |
}; |
| 30 |
|
| 31 |
|
| 32 |
enum aws_h2_frame_flag { |
| 33 |
AWS_H2_FRAME_F_ACK = 0x01, |
| 34 |
AWS_H2_FRAME_F_END_STREAM = 0x01, |
| 35 |
AWS_H2_FRAME_F_END_HEADERS = 0x04, |
| 36 |
AWS_H2_FRAME_F_PADDED = 0x08, |
| 37 |
AWS_H2_FRAME_F_PRIORITY = 0x20, |
| 38 |
}; |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
struct aws_h2err { |
| 48 |
enum aws_http2_error_code h2_code; |
| 49 |
int aws_code; |
| 50 |
}; |
| 51 |
|
| 52 |
#define AWS_H2ERR_SUCCESS \ |
| 53 |
(struct aws_h2err) { \ |
| 54 |
.h2_code = 0, .aws_code = 0 \ |
| 55 |
} |
| 56 |
|
| 57 |
#define AWS_H2_PAYLOAD_MAX (0x00FFFFFF) |
| 58 |
#define AWS_H2_WINDOW_UPDATE_MAX (0x7FFFFFFF) |
| 59 |
#define AWS_H2_STREAM_ID_MAX (0x7FFFFFFF) |
| 60 |
#define AWS_H2_FRAME_PREFIX_SIZE (9) |
| 61 |
#define AWS_H2_INIT_WINDOW_SIZE (65535) |
| 62 |
|
| 63 |
|
| 64 |
extern const uint32_t aws_h2_settings_bounds[AWS_HTTP2_SETTINGS_END_RANGE][2]; |
| 65 |
|
| 66 |
|
| 67 |
AWS_HTTP_API |
| 68 |
extern const uint32_t aws_h2_settings_initial[AWS_HTTP2_SETTINGS_END_RANGE]; |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
AWS_HTTP_API |
| 74 |
extern const struct aws_byte_cursor aws_h2_connection_preface_client_string; |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
struct aws_h2_frame_priority_settings { |
| 87 |
uint32_t stream_dependency; |
| 88 |
bool stream_dependency_exclusive; |
| 89 |
uint8_t weight; |
| 90 |
}; |
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
struct aws_h2_frame { |
| 97 |
const struct aws_h2_frame_vtable *vtable; |
| 98 |
struct aws_allocator *alloc; |
| 99 |
struct aws_linked_list_node node; |
| 100 |
enum aws_h2_frame_type type; |
| 101 |
uint32_t stream_id; |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
bool high_priority; |
| 106 |
}; |
| 107 |
|
| 108 |
|
| 109 |
struct aws_h2_frame_encoder { |
| 110 |
struct aws_allocator *allocator; |
| 111 |
const void *logging_id; |
| 112 |
struct aws_hpack_encoder hpack; |
| 113 |
struct aws_h2_frame *current_frame; |
| 114 |
|
| 115 |
|
| 116 |
struct { |
| 117 |
|
| 118 |
uint32_t max_frame_size; |
| 119 |
} settings; |
| 120 |
|
| 121 |
bool has_errored; |
| 122 |
}; |
| 123 |
|
| 124 |
typedef void aws_h2_frame_destroy_fn(struct aws_h2_frame *frame_base); |
| 125 |
typedef int aws_h2_frame_encode_fn( |
| 126 |
struct aws_h2_frame *frame_base, |
| 127 |
struct aws_h2_frame_encoder *encoder, |
| 128 |
struct aws_byte_buf *output, |
| 129 |
bool *complete); |
| 130 |
|
| 131 |
struct aws_h2_frame_vtable { |
| 132 |
aws_h2_frame_destroy_fn *destroy; |
| 133 |
aws_h2_frame_encode_fn *encode; |
| 134 |
}; |
| 135 |
|
| 136 |
AWS_EXTERN_C_BEGIN |
| 137 |
|
| 138 |
AWS_HTTP_API |
| 139 |
const char *aws_h2_frame_type_to_str(enum aws_h2_frame_type type); |
| 140 |
|
| 141 |
AWS_HTTP_API |
| 142 |
const char *aws_http2_error_code_to_str(enum aws_http2_error_code h2_error_code); |
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
AWS_HTTP_API |
| 150 |
struct aws_h2err aws_h2err_from_h2_code(enum aws_http2_error_code h2_error_code); |
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
AWS_HTTP_API |
| 158 |
struct aws_h2err aws_h2err_from_aws_code(int aws_error_code); |
| 159 |
|
| 160 |
AWS_HTTP_API |
| 161 |
struct aws_h2err aws_h2err_from_last_error(void); |
| 162 |
|
| 163 |
AWS_HTTP_API |
| 164 |
bool aws_h2err_success(struct aws_h2err err); |
| 165 |
|
| 166 |
AWS_HTTP_API |
| 167 |
bool aws_h2err_failed(struct aws_h2err err); |
| 168 |
|
| 169 |
|
| 170 |
AWS_HTTP_API |
| 171 |
int aws_h2_validate_stream_id(uint32_t stream_id); |
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
AWS_HTTP_API |
| 179 |
int aws_h2_frame_encoder_init( |
| 180 |
struct aws_h2_frame_encoder *encoder, |
| 181 |
struct aws_allocator *allocator, |
| 182 |
const void *logging_id); |
| 183 |
|
| 184 |
AWS_HTTP_API |
| 185 |
void aws_h2_frame_encoder_clean_up(struct aws_h2_frame_encoder *encoder); |
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
AWS_HTTP_API |
| 197 |
int aws_h2_encode_frame( |
| 198 |
struct aws_h2_frame_encoder *encoder, |
| 199 |
struct aws_h2_frame *frame, |
| 200 |
struct aws_byte_buf *output, |
| 201 |
bool *frame_complete); |
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
AWS_HTTP_API |
| 217 |
int aws_h2_encode_data_frame( |
| 218 |
struct aws_h2_frame_encoder *encoder, |
| 219 |
uint32_t stream_id, |
| 220 |
struct aws_input_stream *body_stream, |
| 221 |
bool body_ends_stream, |
| 222 |
uint8_t pad_length, |
| 223 |
int32_t *stream_window_size_peer, |
| 224 |
uint32_t *connection_window_size_peer, |
| 225 |
struct aws_byte_buf *output, |
| 226 |
bool *body_complete, |
| 227 |
bool *body_stalled, |
| 228 |
bool *body_failed); |
| 229 |
|
| 230 |
AWS_HTTP_API |
| 231 |
void aws_h2_frame_destroy(struct aws_h2_frame *frame); |
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
AWS_HTTP_API |
| 238 |
struct aws_h2_frame *aws_h2_frame_new_headers( |
| 239 |
struct aws_allocator *allocator, |
| 240 |
uint32_t stream_id, |
| 241 |
const struct aws_http_headers *headers, |
| 242 |
bool end_stream, |
| 243 |
uint8_t pad_length, |
| 244 |
const struct aws_h2_frame_priority_settings *optional_priority); |
| 245 |
|
| 246 |
AWS_HTTP_API |
| 247 |
struct aws_h2_frame *aws_h2_frame_new_priority( |
| 248 |
struct aws_allocator *allocator, |
| 249 |
uint32_t stream_id, |
| 250 |
const struct aws_h2_frame_priority_settings *priority); |
| 251 |
|
| 252 |
AWS_HTTP_API |
| 253 |
struct aws_h2_frame *aws_h2_frame_new_rst_stream( |
| 254 |
struct aws_allocator *allocator, |
| 255 |
uint32_t stream_id, |
| 256 |
uint32_t error_code); |
| 257 |
|
| 258 |
AWS_HTTP_API |
| 259 |
struct aws_h2_frame *aws_h2_frame_new_settings( |
| 260 |
struct aws_allocator *allocator, |
| 261 |
const struct aws_http2_setting *settings_array, |
| 262 |
size_t num_settings, |
| 263 |
bool ack); |
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
AWS_HTTP_API |
| 270 |
struct aws_h2_frame *aws_h2_frame_new_push_promise( |
| 271 |
struct aws_allocator *allocator, |
| 272 |
uint32_t stream_id, |
| 273 |
uint32_t promised_stream_id, |
| 274 |
const struct aws_http_headers *headers, |
| 275 |
uint8_t pad_length); |
| 276 |
|
| 277 |
AWS_HTTP_API |
| 278 |
struct aws_h2_frame *aws_h2_frame_new_ping( |
| 279 |
struct aws_allocator *allocator, |
| 280 |
bool ack, |
| 281 |
const uint8_t opaque_data[AWS_HTTP2_PING_DATA_SIZE]); |
| 282 |
|
| 283 |
AWS_HTTP_API |
| 284 |
struct aws_h2_frame *aws_h2_frame_new_goaway( |
| 285 |
struct aws_allocator *allocator, |
| 286 |
uint32_t last_stream_id, |
| 287 |
uint32_t error_code, |
| 288 |
struct aws_byte_cursor debug_data); |
| 289 |
|
| 290 |
AWS_HTTP_API |
| 291 |
struct aws_h2_frame *aws_h2_frame_new_window_update( |
| 292 |
struct aws_allocator *allocator, |
| 293 |
uint32_t stream_id, |
| 294 |
uint32_t window_size_increment); |
| 295 |
|
| 296 |
AWS_HTTP_API void aws_h2_frame_encoder_set_setting_header_table_size( |
| 297 |
struct aws_h2_frame_encoder *encoder, |
| 298 |
uint32_t data); |
| 299 |
AWS_HTTP_API void aws_h2_frame_encoder_set_setting_max_frame_size(struct aws_h2_frame_encoder *encoder, uint32_t data); |
| 300 |
|
| 301 |
AWS_EXTERN_C_END |
| 302 |
|
| 303 |
#endif |