Skip to content

Commit

Permalink
Disable EXPAND_ONLY_PREDEF in doxygen config file to expand macro
Browse files Browse the repository at this point in the history
  • Loading branch information
kar-rahul-aws committed May 16, 2024
1 parent 47878db commit 8968b60
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 66 deletions.
2 changes: 1 addition & 1 deletion docs/doxygen/config.doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -2257,7 +2257,7 @@ MACRO_EXPANSION = YES
# The default value is: NO.
# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.

EXPAND_ONLY_PREDEF = YES
EXPAND_ONLY_PREDEF = NO

# If the SEARCH_INCLUDES tag is set to YES, the include files in the
# INCLUDE_PATH will be searched if a #include is found.
Expand Down
16 changes: 10 additions & 6 deletions source/include/sigv4.h
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,8 @@ SigV4Status_t SigV4_AwsIotDateToIso8601( const char * pDate,
size_t dateISO8601Len );
/* @[declare_sigV4_awsIotDateToIso8601_function] */

#if ( SIGV4_USE_CANONICAL_SUPPORT == 1 )

/**
* @brief Normalize a URI string according to RFC 3986 and fill destination
* buffer with the formatted string.
Expand All @@ -592,14 +594,16 @@ SigV4Status_t SigV4_AwsIotDateToIso8601( const char * pDate,
* @return #SigV4Success code if successful, error code otherwise.
*/
/* @[declare_sigV4_encodeURI_function] */
SigV4Status_t SigV4_EncodeURI( const char * pUri,
size_t uriLen,
char * pCanonicalURI,
size_t * canonicalURILen,
bool encodeSlash,
bool doubleEncodeEquals );
SigV4Status_t SigV4_EncodeURI( const char * pUri,
size_t uriLen,
char * pCanonicalURI,
size_t * canonicalURILen,
bool encodeSlash,
bool doubleEncodeEquals );
/* @[declare_sigV4_encodeURI_function] */

#endif /* #if (SIGV4_USE_CANONICAL_SUPPORT == 1) */

/* *INDENT-OFF* */
#ifdef __cplusplus
}
Expand Down
122 changes: 63 additions & 59 deletions source/sigv4.c
Original file line number Diff line number Diff line change
Expand Up @@ -3227,83 +3227,87 @@ SigV4Status_t SigV4_GenerateHTTPAuthorization( const SigV4Parameters_t * pParams

/*-----------------------------------------------------------*/

SigV4Status_t SigV4_EncodeURI( const char * pUri,
size_t uriLen,
char * pCanonicalURI,
size_t * canonicalURILen,
bool encodeSlash,
bool doubleEncodeEquals )
{
size_t uriIndex = 0U, bytesConsumed = 0U;
size_t bufferLen = 0U;
SigV4Status_t returnStatus = SigV4Success;
#if ( SIGV4_USE_CANONICAL_SUPPORT == 1 )

assert( pUri != NULL );
assert( pCanonicalURI != NULL );
assert( canonicalURILen != NULL );
SigV4Status_t SigV4_EncodeURI( const char * pUri,
size_t uriLen,
char * pCanonicalURI,
size_t * canonicalURILen,
bool encodeSlash,
bool doubleEncodeEquals )
{
size_t uriIndex = 0U, bytesConsumed = 0U;
size_t bufferLen = 0U;
SigV4Status_t returnStatus = SigV4Success;

bufferLen = *canonicalURILen;
assert( pUri != NULL );
assert( pCanonicalURI != NULL );
assert( canonicalURILen != NULL );

while( ( uriIndex < uriLen ) && ( returnStatus == SigV4Success ) )
{
if( doubleEncodeEquals && ( pUri[ uriIndex ] == '=' ) )
bufferLen = *canonicalURILen;

while( ( uriIndex < uriLen ) && ( returnStatus == SigV4Success ) )
{
if( ( bufferLen - bytesConsumed ) < URI_DOUBLE_ENCODED_EQUALS_CHAR_SIZE )
if( doubleEncodeEquals && ( pUri[ uriIndex ] == '=' ) )
{
returnStatus = SigV4InsufficientMemory;
LOG_INSUFFICIENT_MEMORY_ERROR( "double encode '=' character in canonical query",
( bytesConsumed + URI_DOUBLE_ENCODED_EQUALS_CHAR_SIZE - bufferLen ) );
if( ( bufferLen - bytesConsumed ) < URI_DOUBLE_ENCODED_EQUALS_CHAR_SIZE )
{
returnStatus = SigV4InsufficientMemory;
LOG_INSUFFICIENT_MEMORY_ERROR( "double encode '=' character in canonical query",
( bytesConsumed + URI_DOUBLE_ENCODED_EQUALS_CHAR_SIZE - bufferLen ) );
}
else
{
bytesConsumed += writeDoubleEncodedEquals( &( pCanonicalURI[ bytesConsumed ] ), bufferLen - bytesConsumed );
}
}
else
else if( isAllowedChar( pUri[ uriIndex ], encodeSlash ) )
{
bytesConsumed += writeDoubleEncodedEquals( &( pCanonicalURI[ bytesConsumed ] ), bufferLen - bytesConsumed );
/* If the output buffer has space, add the character as-is in URI encoding as it
* is neither a special character nor an '=' character requiring double encoding. */
if( bytesConsumed < bufferLen )
{
pCanonicalURI[ bytesConsumed ] = pUri[ uriIndex ];
++bytesConsumed;
}
else
{
returnStatus = SigV4InsufficientMemory;
LogError( ( "Failed to encode URI in buffer due to insufficient memory" ) );
}
}
}
else if( isAllowedChar( pUri[ uriIndex ], encodeSlash ) )
{
/* If the output buffer has space, add the character as-is in URI encoding as it
* is neither a special character nor an '=' character requiring double encoding. */
if( bytesConsumed < bufferLen )
else if( pUri[ uriIndex ] == '\0' )
{
pCanonicalURI[ bytesConsumed ] = pUri[ uriIndex ];
++bytesConsumed;
/* The URI path beyond the NULL terminator is not encoded. */
uriIndex = uriLen;
}
else
{
returnStatus = SigV4InsufficientMemory;
LogError( ( "Failed to encode URI in buffer due to insufficient memory" ) );
if( ( bufferLen - bytesConsumed ) < URI_ENCODED_SPECIAL_CHAR_SIZE )
{
returnStatus = SigV4InsufficientMemory;
LOG_INSUFFICIENT_MEMORY_ERROR( "encode special character in canonical URI",
( bytesConsumed + URI_ENCODED_SPECIAL_CHAR_SIZE - bufferLen ) );
}
else
{
bytesConsumed += writeHexCodeOfChar( &( pCanonicalURI[ bytesConsumed ] ), bufferLen - bytesConsumed, pUri[ uriIndex ] );
}
}

uriIndex++;
}
else if( pUri[ uriIndex ] == '\0' )

if( returnStatus == SigV4Success )
{
/* The URI path beyond the NULL terminator is not encoded. */
uriIndex = uriLen;
/* Set the output parameter of the number of URI encoded bytes written
* to the buffer. */
*canonicalURILen = bytesConsumed;
}
else
{
if( ( bufferLen - bytesConsumed ) < URI_ENCODED_SPECIAL_CHAR_SIZE )
{
returnStatus = SigV4InsufficientMemory;
LOG_INSUFFICIENT_MEMORY_ERROR( "encode special character in canonical URI",
( bytesConsumed + URI_ENCODED_SPECIAL_CHAR_SIZE - bufferLen ) );
}
else
{
bytesConsumed += writeHexCodeOfChar( &( pCanonicalURI[ bytesConsumed ] ), bufferLen - bytesConsumed, pUri[ uriIndex ] );
}
}

uriIndex++;
}

if( returnStatus == SigV4Success )
{
/* Set the output parameter of the number of URI encoded bytes written
* to the buffer. */
*canonicalURILen = bytesConsumed;
return returnStatus;
}

return returnStatus;
}
#endif /* #if (SIGV4_USE_CANONICAL_SUPPORT == 1) */

/*-----------------------------------------------------------*/

0 comments on commit 8968b60

Please sign in to comment.