Skip to content

Commit

Permalink
Add CONST_STRLEN preprocessor macro.
Browse files Browse the repository at this point in the history
  • Loading branch information
paulbartell committed Aug 2, 2022
1 parent dddff43 commit e82a892
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
24 changes: 11 additions & 13 deletions source/core_http_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -1015,8 +1015,7 @@ static void initializeParsingContextForFirstResponse( HTTPParsingContext_t * pPa
* indicated to stop by returning a 1 from httpParserOnHeadersCompleteCallback().
* If this is not done, the parser will not indicate the message is complete. */
if( strncmp( ( const char * ) ( pRequestHeaders->pBuffer ),
HTTP_METHOD_HEAD,
sizeof( HTTP_METHOD_HEAD ) - 1U ) == 0 )
HTTP_METHOD_HEAD, CONST_STRLEN( HTTP_METHOD_HEAD ) ) == 0 )
{
pParsingContext->isHeadResponse = 1U;
}
Expand Down Expand Up @@ -1414,7 +1413,7 @@ static HTTPStatus_t addRangeHeader( HTTPRequestHeaders_t * pRequestHeaders,
/* Write the range value prefix in the buffer. */
( void ) strcpy( rangeValueBuffer, "bytes=" );

rangeValueLength += sizeof( "bytes=" ) - 1U;
rangeValueLength += CONST_STRLEN( "bytes=" );

/* Write the range start value in the buffer. */
rangeValueLength += convertInt32ToAscii( rangeStartOrlastNbytes,
Expand Down Expand Up @@ -1450,7 +1449,7 @@ static HTTPStatus_t addRangeHeader( HTTPRequestHeaders_t * pRequestHeaders,
/* Add the Range Request header field and value to the buffer. */
returnStatus = addHeader( pRequestHeaders,
"Range",
sizeof( "Range" ) - 1U,
CONST_STRLEN( "Range" ),
rangeValueBuffer,
rangeValueLength );

Expand Down Expand Up @@ -1485,8 +1484,7 @@ static HTTPStatus_t writeRequestLine( HTTPRequestHeaders_t * pRequestHeaders,
toAddLen = methodLen + 1U + pathLen + 1U;
}

/* "HTTP/1.1\r\n" */
toAddLen += sizeof( "HTTP/1.1" ) - 1U + 2U;
toAddLen += CONST_STRLEN( "HTTP/1.1\r\n" );

pBufferCur = ( char * ) ( pRequestHeaders->pBuffer );

Expand Down Expand Up @@ -1520,7 +1518,7 @@ static HTTPStatus_t writeRequestLine( HTTPRequestHeaders_t * pRequestHeaders,
pBufferCur += 1U;

( void ) strcpy( pBufferCur, "HTTP/1.1\r\n" );
pBufferCur += sizeof( "HTTP/1.1\r\n" ) - 1U;
pBufferCur += CONST_STRLEN( "HTTP/1.1\r\n" );

pRequestHeaders->headersLen = toAddLen;
}
Expand Down Expand Up @@ -1594,17 +1592,17 @@ HTTPStatus_t HTTPClient_InitializeRequestHeaders( HTTPRequestHeaders_t * pReques
/* Write "User-Agent: <Value>". */
returnStatus = addHeader( pRequestHeaders,
"User-Agent",
sizeof( "User-Agent" ) - 1U,
CONST_STRLEN( "User-Agent" ),
HTTP_USER_AGENT_VALUE,
sizeof( HTTP_USER_AGENT_VALUE ) - 1U );
CONST_STRLEN( HTTP_USER_AGENT_VALUE ) );
}

if( returnStatus == HTTPSuccess )
{
/* Write "Host: <Value>". */
returnStatus = addHeader( pRequestHeaders,
"Host",
sizeof( "Host" ) - 1U,
CONST_STRLEN( "Host" ),
pRequestInfo->pHost,
pRequestInfo->hostLen );
}
Expand All @@ -1616,9 +1614,9 @@ HTTPStatus_t HTTPClient_InitializeRequestHeaders( HTTPRequestHeaders_t * pReques
/* Write "Connection: keep-alive". */
returnStatus = addHeader( pRequestHeaders,
"Connection",
sizeof( "Connection" ) - 1U,
CONST_STRLEN( "Connection" ),
"keep-alive",
sizeof( "keep-alive" ) - 1U );
CONST_STRLEN( "keep-alive" ) );
}
}

Expand Down Expand Up @@ -1848,7 +1846,7 @@ static HTTPStatus_t addContentLengthHeader( HTTPRequestHeaders_t * pRequestHeade

returnStatus = addHeader( pRequestHeaders,
"Content-Length",
sizeof( "Content-Length" ) - 1U,
CONST_STRLEN( "Content-Length" ),
pContentLengthValue,
contentLengthValueNumBytes );

Expand Down
7 changes: 7 additions & 0 deletions source/include/core_http_client_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@
#endif
/* *INDENT-ON* */

/**
* @brief Preprocessor macro to calculate the length of a const char * string.
* @note It is intended that this function-like macro be evaluated by the c
* preprocessor to the actual length of the constant string argument.
*/
#define CONST_STRLEN( string ) ( sizeof( string ) - 1U )

/**
* @brief Indicator for function #httpHeaderStrncpy that the pSrc parameter is a
* header value.
Expand Down

0 comments on commit e82a892

Please sign in to comment.