Debian Codegraph @

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

raw symbols SCIP
1 #ifndef AWS_HTTP_H1_DECODER_H
2 #define AWS_HTTP_H1_DECODER_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/private/http_impl.h>
10 #include <aws/http/private/request_response_impl.h>
11
12 struct aws_h1_decoded_header {
13 /* Name of the header. If the type is `AWS_HTTP_HEADER_NAME_UNKNOWN` then `name_data` must be parsed manually. */
14 enum aws_http_header_name name;
15
16 /* Raw buffer storing the header's name. */
17 struct aws_byte_cursor name_data;
18
19 /* Raw buffer storing the header's value. */
20 struct aws_byte_cursor value_data;
21
22 /* Raw buffer storing the entire header. */
23 struct aws_byte_cursor data;
24 };
25
26 struct aws_h1_decoder_vtable {
27 /**
28 * Called from `aws_h*_decode` when an http header has been received.
29 * All pointers are strictly *read only*; any data that needs to persist must be copied out into user-owned memory.
30 */
31 int (*on_header)(const struct aws_h1_decoded_header *header, void *user_data);
32
33 /**
34 * Called from `aws_h1_decode` when a portion of the http body has been received.
35 * `finished` is true if this is the last section of the http body, and false if more body data is yet to be
36 * received. All pointers are strictly *read only*; any data that needs to persist must be copied out into
37 * user-owned memory.
38 */
39 int (*on_body)(const struct aws_byte_cursor *data, bool finished, void *user_data);
40
41 /* Only needed for requests, can be NULL for responses. */
42 int (*on_request)(
43 enum aws_http_method method_enum,
44 const struct aws_byte_cursor *method_str,
45 const struct aws_byte_cursor *uri,
46 void *user_data);
47
48 /* Only needed for responses, can be NULL for requests. */
49 int (*on_response)(int status_code, void *user_data);
50
51 int (*on_done)(void *user_data);
52 };
53
54 /**
55 * Structure used to initialize an `aws_h1_decoder`.
56 */
57 struct aws_h1_decoder_params {
58 struct aws_allocator *alloc;
59 size_t scratch_space_initial_size;
60 /* Set false if decoding responses */
61 bool is_decoding_requests;
62 void *user_data;
63 struct aws_h1_decoder_vtable vtable;
64 };
65
66 struct aws_h1_decoder;
67
68 AWS_EXTERN_C_BEGIN
69
70 AWS_HTTP_API struct aws_h1_decoder *aws_h1_decoder_new(struct aws_h1_decoder_params *params);
71 AWS_HTTP_API void aws_h1_decoder_destroy(struct aws_h1_decoder *decoder);
72 AWS_HTTP_API int aws_h1_decode(struct aws_h1_decoder *decoder, struct aws_byte_cursor *data);
73
74 AWS_HTTP_API void aws_h1_decoder_set_logging_id(struct aws_h1_decoder *decoder, const void *id);
75 AWS_HTTP_API void aws_h1_decoder_set_body_headers_ignored(struct aws_h1_decoder *decoder, bool body_headers_ignored);
76
77 /* RFC-7230 section 4.2 Message Format */
78 #define AWS_HTTP_TRANSFER_ENCODING_CHUNKED (1 << 0)
79 #define AWS_HTTP_TRANSFER_ENCODING_GZIP (1 << 1)
80 #define AWS_HTTP_TRANSFER_ENCODING_DEFLATE (1 << 2)
81 #define AWS_HTTP_TRANSFER_ENCODING_DEPRECATED_COMPRESS (1 << 3)
82 AWS_HTTP_API int aws_h1_decoder_get_encoding_flags(const struct aws_h1_decoder *decoder);
83
84 AWS_HTTP_API uint64_t aws_h1_decoder_get_content_length(const struct aws_h1_decoder *decoder);
85 AWS_HTTP_API bool aws_h1_decoder_get_body_headers_ignored(const struct aws_h1_decoder *decoder);
86 AWS_HTTP_API enum aws_http_header_block aws_h1_decoder_get_header_block(const struct aws_h1_decoder *decoder);
87
88 AWS_EXTERN_C_END
89
90 #endif /* AWS_HTTP_H1_DECODER_H */