coreHTTP  v2.0.2
HTTP/1.1 Client Library
core_http_client_private.h
Go to the documentation of this file.
1 /*
2  * coreHTTP v2.0.2
3  * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a copy of
6  * this software and associated documentation files (the "Software"), to deal in
7  * the Software without restriction, including without limitation the rights to
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9  * the Software, and to permit persons to whom the Software is furnished to do so,
10  * subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in all
13  * copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21  */
22 
28 #ifndef CORE_HTTP_CLIENT_PRIVATE_H_
29 #define CORE_HTTP_CLIENT_PRIVATE_H_
30 
31 /* Third-party http-parser include. */
32 #include "http_parser.h"
33 
34 /* *INDENT-OFF* */
35 #ifdef __cplusplus
36  extern "C" {
37 #endif
38 /* *INDENT-ON* */
39 
43 #define HTTP_PROTOCOL_VERSION "HTTP/1.1"
44 #define HTTP_PROTOCOL_VERSION_LEN ( sizeof( HTTP_PROTOCOL_VERSION ) - 1U )
49 #define HTTP_EMPTY_PATH "/"
50 #define HTTP_EMPTY_PATH_LEN ( sizeof( HTTP_EMPTY_PATH ) - 1U )
52 /* Constants for HTTP header formatting. */
53 #define HTTP_HEADER_LINE_SEPARATOR "\r\n"
54 #define HTTP_HEADER_LINE_SEPARATOR_LEN ( sizeof( HTTP_HEADER_LINE_SEPARATOR ) - 1U )
55 #define HTTP_HEADER_END_INDICATOR "\r\n\r\n"
56 #define HTTP_HEADER_END_INDICATOR_LEN ( sizeof( HTTP_HEADER_END_INDICATOR ) - 1U )
57 #define HTTP_HEADER_FIELD_SEPARATOR ": "
58 #define HTTP_HEADER_FIELD_SEPARATOR_LEN ( sizeof( HTTP_HEADER_FIELD_SEPARATOR ) - 1U )
59 #define SPACE_CHARACTER ' '
60 #define SPACE_CHARACTER_LEN ( 1U )
61 #define DASH_CHARACTER '-'
62 #define DASH_CHARACTER_LEN ( 1U )
64 /* Constants for HTTP header copy checks. */
65 #define CARRIAGE_RETURN_CHARACTER '\r'
66 #define LINEFEED_CHARACTER '\n'
67 #define COLON_CHARACTER ':'
73 #define HTTP_HEADER_STRNCPY_IS_VALUE 0U
74 
79 #define HTTP_HEADER_STRNCPY_IS_FIELD 1U
80 
81 /* Constants for header fields added automatically during the request
82  * initialization. */
83 #define HTTP_USER_AGENT_FIELD "User-Agent"
84 #define HTTP_USER_AGENT_FIELD_LEN ( sizeof( HTTP_USER_AGENT_FIELD ) - 1U )
85 #define HTTP_HOST_FIELD "Host"
86 #define HTTP_HOST_FIELD_LEN ( sizeof( HTTP_HOST_FIELD ) - 1U )
87 #define HTTP_USER_AGENT_VALUE_LEN ( sizeof( HTTP_USER_AGENT_VALUE ) - 1U )
89 /* Constants for header fields added based on flags. */
90 #define HTTP_CONNECTION_FIELD "Connection"
91 #define HTTP_CONNECTION_FIELD_LEN ( sizeof( HTTP_CONNECTION_FIELD ) - 1U )
92 #define HTTP_CONTENT_LENGTH_FIELD "Content-Length"
93 #define HTTP_CONTENT_LENGTH_FIELD_LEN ( sizeof( HTTP_CONTENT_LENGTH_FIELD ) - 1U )
95 /* Constants for header values added based on flags. */
96 
97 /* MISRA Rule 5.4 flags the following macro's name as ambiguous from the
98  * one postfixed with _LEN. This rule is suppressed for naming consistency with
99  * other HTTP header field and value string and length macros in this file.*/
100 /* coverity[other_declaration] */
101 #define HTTP_CONNECTION_KEEP_ALIVE_VALUE "keep-alive"
103 /* MISRA Rule 5.4 flags the following macro's name as ambiguous from the one
104  * above it. This rule is suppressed for naming consistency with other HTTP
105  * header field and value string and length macros in this file.*/
106 /* coverity[misra_c_2012_rule_5_4_violation] */
107 #define HTTP_CONNECTION_KEEP_ALIVE_VALUE_LEN ( sizeof( HTTP_CONNECTION_KEEP_ALIVE_VALUE ) - 1U )
109 /* Constants relating to Range Requests. */
110 
111 /* MISRA Rule 5.4 flags the following macro's name as ambiguous from the
112  * one postfixed with _LEN. This rule is suppressed for naming consistency with
113  * other HTTP header field and value string and length macros in this file.*/
114 /* coverity[other_declaration] */
115 #define HTTP_RANGE_REQUEST_HEADER_FIELD "Range"
117 /* MISRA Rule 5.4 flags the following macro's name as ambiguous from the one
118  * above it. This rule is suppressed for naming consistency with other HTTP
119  * header field and value string and length macros in this file.*/
120 /* coverity[misra_c_2012_rule_5_4_violation] */
121 #define HTTP_RANGE_REQUEST_HEADER_FIELD_LEN ( sizeof( HTTP_RANGE_REQUEST_HEADER_FIELD ) - 1U )
123 /* MISRA Rule 5.4 flags the following macro's name as ambiguous from the
124  * one postfixed with _LEN. This rule is suppressed for naming consistency with
125  * other HTTP header field and value string and length macros in this file.*/
126 /* coverity[other_declaration] */
127 #define HTTP_RANGE_REQUEST_HEADER_VALUE_PREFIX "bytes="
129 /* MISRA Rule 5.4 flags the following macro's name as ambiguous from the one
130  * above it. This rule is suppressed for naming consistency with other HTTP
131  * header field and value string and length macros in this file.*/
132 /* coverity[misra_c_2012_rule_5_4_violation] */
133 #define HTTP_RANGE_REQUEST_HEADER_VALUE_PREFIX_LEN ( sizeof( HTTP_RANGE_REQUEST_HEADER_VALUE_PREFIX ) - 1U )
140 #define MAX_INT32_NO_OF_DECIMAL_DIGITS 10U
141 
148 #define HTTP_MAX_RANGE_REQUEST_VALUE_LEN \
149  ( HTTP_RANGE_REQUEST_HEADER_VALUE_PREFIX_LEN + MAX_INT32_NO_OF_DECIMAL_DIGITS + \
150  1U /* Dash character '-' */ + MAX_INT32_NO_OF_DECIMAL_DIGITS )
151 
156 #define HTTP_PARSER_STOP_PARSING 1
157 
162 #define HTTP_PARSER_CONTINUE_PARSING 0
163 
178 #define HTTP_MINIMUM_REQUEST_LINE_LENGTH 16u
179 
184 typedef enum HTTPParsingState_t
185 {
190 
196 typedef struct findHeaderContext
197 {
198  const char * pField;
199  size_t fieldLen;
200  const char ** pValueLoc;
201  size_t * pValueLen;
202  uint8_t fieldFound;
203  uint8_t valueFound;
205 
262 typedef struct HTTPParsingContext
263 {
264  http_parser httpParser;
267  uint8_t isHeadResponse;
269  const char * pBufferCur;
270  const char * pLastHeaderField;
272  const char * pLastHeaderValue;
275 
276 /* *INDENT-OFF* */
277 #ifdef __cplusplus
278  }
279 #endif
280 /* *INDENT-ON* */
281 
282 #endif /* ifndef CORE_HTTP_CLIENT_PRIVATE_H_ */
findHeaderContext_t::fieldLen
size_t fieldLen
Definition: core_http_client_private.h:199
HTTPParsingContext_t::lastHeaderValueLen
size_t lastHeaderValueLen
Definition: core_http_client_private.h:273
HTTP_PARSING_INCOMPLETE
@ HTTP_PARSING_INCOMPLETE
Definition: core_http_client_private.h:187
findHeaderContext_t::fieldFound
uint8_t fieldFound
Definition: core_http_client_private.h:202
findHeaderContext_t::pField
const char * pField
Definition: core_http_client_private.h:198
HTTP_PARSING_NONE
@ HTTP_PARSING_NONE
Definition: core_http_client_private.h:186
findHeaderContext_t::pValueLen
size_t * pValueLen
Definition: core_http_client_private.h:201
findHeaderContext_t::pValueLoc
const char ** pValueLoc
Definition: core_http_client_private.h:200
HTTPParsingContext_t::pBufferCur
const char * pBufferCur
Definition: core_http_client_private.h:269
HTTPParsingContext_t::isHeadResponse
uint8_t isHeadResponse
Definition: core_http_client_private.h:267
HTTPParsingContext_t
The HTTP response parsing context for a response fresh from the server. This context is passed into t...
Definition: core_http_client_private.h:263
HTTP_PARSING_COMPLETE
@ HTTP_PARSING_COMPLETE
Definition: core_http_client_private.h:188
HTTPParsingContext_t::pLastHeaderValue
const char * pLastHeaderValue
Definition: core_http_client_private.h:272
HTTPParsingContext_t::pLastHeaderField
const char * pLastHeaderField
Definition: core_http_client_private.h:270
HTTPParsingContext_t::pResponse
HTTPResponse_t * pResponse
Definition: core_http_client_private.h:266
HTTPResponse_t
Represents an HTTP response.
Definition: core_http_client.h:434
HTTPParsingContext_t::httpParser
http_parser httpParser
Definition: core_http_client_private.h:264
findHeaderContext_t
An aggregator that represents the user-provided parameters to the HTTPClient_ReadHeader API function....
Definition: core_http_client_private.h:197
findHeaderContext_t::valueFound
uint8_t valueFound
Definition: core_http_client_private.h:203
HTTPParsingState_t
HTTPParsingState_t
The state of the response message parsed after function parseHttpResponse returns.
Definition: core_http_client_private.h:185
HTTPParsingContext_t::lastHeaderFieldLen
size_t lastHeaderFieldLen
Definition: core_http_client_private.h:271
HTTPParsingContext_t::state
HTTPParsingState_t state
Definition: core_http_client_private.h:265