26 #ifndef IOT_HTTPS_INTERNAL_H_
27 #define IOT_HTTPS_INTERNAL_H_
30 #include "iot_config.h"
39 #include "http_parser.h"
45 #include "iot_taskpool.h"
48 #include "iot_linear_containers.h"
51 #include "types/iot_taskpool_types.h"
58 #include "private/iot_error.h"
67 #define HTTPS_SUCCEEDED( x ) ( ( x ) == IOT_HTTPS_OK )
72 #define HTTPS_FAILED( x ) ( ( x ) != IOT_HTTPS_OK )
77 #define HTTPS_FUNCTION_ENTRY( result ) IOT_FUNCTION_ENTRY( IotHttpsReturnCode_t, result )
82 #define HTTPS_GOTO_CLEANUP() IOT_GOTO_CLEANUP()
87 #define HTTPS_SET_AND_GOTO_CLEANUP( statusValue ) IOT_SET_AND_GOTO_CLEANUP( statusValue )
92 #define HTTPS_FUNCTION_CLEANUP_BEGIN() IOT_FUNCTION_CLEANUP_BEGIN()
97 #define HTTPS_FUNCTION_CLEANUP_END() IOT_FUNCTION_CLEANUP_END()
102 #define HTTPS_FUNCTION_EXIT_NO_CLEANUP() IOT_FUNCTION_EXIT_NO_CLEANUP()
107 #define HTTPS_ON_NULL_ARG_GOTO_CLEANUP( ptr ) \
108 if( ( ptr == NULL ) ) \
110 IotLogError( # ptr " was NULL." ); \
111 IOT_SET_AND_GOTO_CLEANUP( IOT_HTTPS_INVALID_PARAMETER ); \
117 #define HTTPS_ON_ARG_ERROR_GOTO_CLEANUP( expr ) \
118 if( ( expr ) == false ) \
120 IotLogError( # expr " must be true." ); \
121 IOT_SET_AND_GOTO_CLEANUP( IOT_HTTPS_INVALID_PARAMETER ); \
127 #define HTTPS_ON_ARG_ERROR_MSG_GOTO_CLEANUP( expr, statusValue, ... ) \
128 if( ( expr ) == false ) \
130 IotLogError( __VA_ARGS__ ); \
131 IOT_SET_AND_GOTO_CLEANUP( statusValue ); \
135 #ifdef IOT_LOG_LEVEL_HTTPS
136 #define LIBRARY_LOG_LEVEL IOT_LOG_LEVEL_HTTPS
138 #ifdef IOT_LOG_LEVEL_GLOBAL
139 #define LIBRARY_LOG_LEVEL IOT_LOG_LEVEL_GLOBAL
141 #define LIBRARY_LOG_LEVEL IOT_LOG_NONE
145 #define LIBRARY_LOG_NAME ( "HTTPS Client" )
146 #include "iot_logging_setup.h"
152 #if IOT_STATIC_MEMORY_ONLY == 1
153 #include "private/iot_static_memory.h"
162 #ifndef AWS_IOT_HTTPS_ENABLE_METRICS
163 #define AWS_IOT_HTTPS_ENABLE_METRICS ( 1 )
165 #ifndef IOT_HTTPS_USER_AGENT
166 #define IOT_HTTPS_USER_AGENT "amazon-freertos"
168 #ifndef IOT_HTTPS_MAX_FLUSH_BUFFER_SIZE
169 #define IOT_HTTPS_MAX_FLUSH_BUFFER_SIZE ( 1024 )
171 #ifndef IOT_HTTPS_RESPONSE_WAIT_MS
172 #define IOT_HTTPS_RESPONSE_WAIT_MS ( 1000 )
174 #ifndef IOT_HTTPS_MAX_HOST_NAME_LENGTH
175 #define IOT_HTTPS_MAX_HOST_NAME_LENGTH ( 255 )
177 #ifndef IOT_HTTPS_MAX_ALPN_PROTOCOLS_LENGTH
178 #define IOT_HTTPS_MAX_ALPN_PROTOCOLS_LENGTH ( 255 )
186 #define HTTPS_PROTOCOL_VERSION "HTTP/1.1"
191 #define HTTPS_EMPTY_PATH "/"
196 #define HTTPS_CONNECT_METHOD "CONNECT"
205 #define HTTPS_CONNECTION_KEEP_ALIVE_HEADER_VALUE "keep-alive"
206 #define HTTPS_CONNECTION_CLOSE_HEADER_VALUE "close"
213 #define HTTPS_HEADER_FIELD_SEPARATOR ": "
214 #define HTTPS_HEADER_FIELD_SEPARATOR_LENGTH ( 2 )
215 #define COLON_CHARACTER ':'
216 #define SPACE_CHARACTER ' '
223 #define HTTPS_END_OF_HEADER_LINES_INDICATOR "\r\n"
224 #define HTTPS_END_OF_HEADER_LINES_INDICATOR_LENGTH ( 2 )
225 #define CARRIAGE_RETURN_CHARACTER '\r'
226 #define NEWLINE_CHARACTER '\n'
231 #define HTTPS_USER_AGENT_HEADER "User-Agent"
232 #define HTTPS_HOST_HEADER "Host"
237 #define HTTPS_CONTENT_LENGTH_HEADER "Content-Length"
238 #define HTTPS_CONNECTION_HEADER "Connection"
248 #define HTTPS_MAX_CONTENT_LENGTH_LINE_LENGTH ( 26 )
256 #define FAST_MACRO_STRLEN( x ) ( ( sizeof( x ) / sizeof( char ) ) - 1 )
303 typedef enum IotHttpsResponseParserState
305 PARSER_STATE_NONE = 0,
306 PARSER_STATE_IN_HEADERS,
307 PARSER_STATE_HEADERS_COMPLETE,
308 PARSER_STATE_IN_BODY,
309 PARSER_STATE_BODY_COMPLETE
310 } IotHttpsResponseParserState_t;
358 typedef enum IotHttpsResponseBufferState
360 PROCESSING_STATE_NONE,
361 PROCESSING_STATE_FILLING_HEADER_BUFFER,
362 PROCESSING_STATE_FILLING_BODY_BUFFER,
363 PROCESSING_STATE_FINISHED,
364 PROCESSING_STATE_SEARCHING_HEADER_BUFFER
365 } IotHttpsResponseBufferState_t;
372 typedef struct _httpsConnection
403 typedef struct _httpParserInfo
406 size_t ( * parseFunc )( http_parser * parser,
407 const http_parser_settings * settings,
416 typedef struct _httpsResponse
462 typedef struct _httpsRequest
bool isNonPersistent
Non-persistent flag to indicate closing the connection immediately after receiving the response.
Definition: iot_https_internal.h:456
const IotNetworkInterface_t * pNetworkInterface
Network interface with calls for connect, disconnect, send, and receive.
Definition: iot_https_internal.h:374
IotHttpsReturnCode_t bodyRxStatus
The status of network receiving the HTTPS body to be returned during the IotHttpsClientCallbacks_t....
Definition: iot_https_internal.h:441
struct _httpsResponse * pHttpsResponse
Response associated with request. This is initialized during IotHttpsClient_InitializeRequest(),...
Definition: iot_https_internal.h:472
bool isAsync
This is set to true if this request is to be sent asynchronously. Set to false otherwise.
Definition: iot_https_internal.h:475
Third party library http-parser information.
Definition: iot_https_internal.h:404
uint16_t status
The HTTP response status code of this response.
Definition: iot_https_internal.h:426
bool cancelled
Set this to true to stop the response processing in the asynchronous workflow.
Definition: iot_https_internal.h:478
uint8_t * pHeadersEnd
Pointer to the end of the headers buffer.
Definition: iot_https_internal.h:466
IotHttpsReturnCode_t syncStatus
The status of the synchronous response.
Definition: iot_https_internal.h:444
char * pReadHeaderField
Header field that we want to read from the headers buffer when IotHttpsClient_ReadHeader() is called.
Definition: iot_https_internal.h:430
Represents and HTTP request.
Definition: iot_https_internal.h:463
http_parser readHeaderParser
http_parser state information for parsing the header buffer for reading a header.
Definition: iot_https_internal.h:410
IotHttpsResponseParserState_t parserState
The current state of the parser. See #IotHttpsResponseParserState_t documentation for more details.
Definition: iot_https_internal.h:428
const char * _pHttpsMethodStrings[]
Definition of HTTP method enum to strings array.
Definition: iot_https_client.c:102
void * pNetworkConnection
Pointer to the network connection to use pNetworkInterface calls on.
Definition: iot_https_internal.h:375
uint8_t * pBodyCurInHeaderBuf
Pointer to the next location to write body data during processing of the header buffer....
Definition: iot_https_internal.h:440
bool isDestroyed
true if the connection is already destroyed and we should call anymore
Definition: iot_https_internal.h:387
HTTPS Client library callbacks for asynchronous requests.
Definition: iot_https_types.h:529
uint32_t timeout
Timeout for a connection and waiting for a response from the network.
Definition: iot_https_internal.h:376
uint32_t bodyLength
Length of request body buffer.
Definition: iot_https_internal.h:469
struct _httpsConnection * pHttpsConnection
Connection associated with response. This is set during IotHttpsClient_SendAsync()....
Definition: iot_https_internal.h:437
void * pUserPrivData
User private data to hand back in the asynchronous callbacks for context.
Definition: iot_https_internal.h:476
IotLink_t link
The link to insert the job in the connection's reqQ.
Definition: iot_https_internal.h:464
uint8_t * pHeaders
Pointer to the start of the headers buffer.
Definition: iot_https_internal.h:419
IotHttpsClientCallbacks_t * pCallbacks
Pointer to the asynchronous request callbacks.
Definition: iot_https_internal.h:477
IotMutex_t connectionMutex
Mutex protecting operations on this entire connection context.
Definition: iot_https_internal.h:388
uint8_t * pHeadersEnd
Pointer to the end of the headers buffer.
Definition: iot_https_internal.h:420
char * pReadHeaderValue
Header value that we read from the headers buffer when IotHttpsClient_ReadHeader() is called.
Definition: iot_https_internal.h:432
void * pUserPrivData
User private data to hand back in the asynchronous callbacks for context.
Definition: iot_https_internal.h:455
IotHttpsMethod_t
Types of HTTP methods.
Definition: iot_https_types.h:449
uint8_t * pBodyEnd
Pointer to the end of the body buffer.
Definition: iot_https_internal.h:423
IotHttpsClientCallbacks_t * pCallbacks
Pointer to the asynchronous request callbacks.
Definition: iot_https_internal.h:454
Represents an HTTP response.
Definition: iot_https_internal.h:417
IotSemaphore_t respFinishedSem
This is for synchronous response to post that is finished being received. It is better to use a task ...
Definition: iot_https_internal.h:443
_httpParserInfo_t httpParserInfo
Third party http-parser information.
Definition: iot_https_internal.h:425
uint8_t * pBodyCur
Pointer to the next location to write in the body buffer.
Definition: iot_https_internal.h:424
IotDeQueue_t reqQ
The queue for the requests that are not finished yet.
Definition: iot_https_internal.h:389
size_t readHeaderFieldLength
Length of pReadHeaderField.
Definition: iot_https_internal.h:431
IotDeQueue_t respQ
The queue for the responses that are waiting to be processed.
Definition: iot_https_internal.h:390
uint8_t * pBody
Pointer to the start of the body buffer.
Definition: iot_https_internal.h:468
bool cancelled
This is set to true to stop the request/response processing in the asynchronous request workflow.
Definition: iot_https_internal.h:442
uint8_t * pBodyInHeaderBuf
Pointer to the start of body inside the header buffer for copying to a body buffer provided later by ...
Definition: iot_https_internal.h:439
struct _httpsConnection * pHttpsConnection
Connection associated with request. This is set during IotHttpsClient_SendAsync()....
Definition: iot_https_internal.h:473
uint8_t * pBody
Pointer to the start of the body buffer.
Definition: iot_https_internal.h:422
IotHttpsMethod_t method
The method of the originating request.
Definition: iot_https_internal.h:470
size_t readHeaderValueLength
Length of pReadHeaderValue.
Definition: iot_https_internal.h:433
IotLink_t link
The link to insert the job in the connection's respQ.
Definition: iot_https_internal.h:418
IotHttpsConnectionInfo_t * pConnInfo
Connection info associated with this request. For an implicit connection.
Definition: iot_https_internal.h:471
IotHttpsResponseBufferState_t bufferProcessingState
Which buffer is currently being processed and for what. See #IotHttpsResponseBufferState_t documentat...
Definition: iot_https_internal.h:429
bool isNonPersistent
Non-persistent flag to indicate closing the connection immediately after receiving the response.
Definition: iot_https_internal.h:474
bool foundHeaderField
State to use during parsing to let us know when we found the header field in the https-parser callbac...
Definition: iot_https_internal.h:434
uint8_t * pHeadersCur
Pointer to the next location to write in the headers buffer.
Definition: iot_https_internal.h:421
User-facing functions of the FreeRTOS HTTPS Client library.
bool reqFinishedSending
This is set to true to when the request is finished being sent on the network.
Definition: iot_https_internal.h:453
uint8_t * pHeaders
Pointer to the start of the headers buffer.
Definition: iot_https_internal.h:465
IotHttpsMethod_t method
The method of the originating request.
Definition: iot_https_internal.h:427
IotTaskPoolJob_t taskPoolJob
The task pool job identifier for an asynchronous request.
Definition: iot_https_internal.h:392
IotHttpsReturnCode_t bodyTxStatus
The status of network sending the HTTPS body to be returned during the IotHttpsClientCallbacks_t....
Definition: iot_https_internal.h:479
bool isConnected
true if a connection was successful most recently on this context
Definition: iot_https_internal.h:386
IotHttpsReturnCode_t
Return codes of HTTPS Client functions.
Definition: iot_https_types.h:294
bool isAsync
This is set to true if this response is to be retrieved asynchronously. Set to false otherwise.
Definition: iot_https_internal.h:438
HTTP connection configuration.
Definition: iot_https_types.h:721
IotTaskPoolJobStorage_t taskPoolJobStorage
An asynchronous operation requires storage for the task pool job.
Definition: iot_https_internal.h:391
uint8_t * pHeadersCur
Pointer to the next location to write in the headers buffer.
Definition: iot_https_internal.h:467
http_parser responseParser
http_parser state information for parsing the response.
Definition: iot_https_internal.h:405
bool scheduled
Set to true when this request has already been scheduled to the task pool.
Definition: iot_https_internal.h:480
Represents an HTTP connection.
Definition: iot_https_internal.h:373