From 8968b605403abf7c83e7f76b7805adfdb1794b79 Mon Sep 17 00:00:00 2001 From: Rahul Kar Date: Thu, 16 May 2024 22:22:35 +0000 Subject: [PATCH] Disable EXPAND_ONLY_PREDEF in doxygen config file to expand macro --- docs/doxygen/config.doxyfile | 2 +- source/include/sigv4.h | 16 +++-- source/sigv4.c | 122 ++++++++++++++++++----------------- 3 files changed, 74 insertions(+), 66 deletions(-) diff --git a/docs/doxygen/config.doxyfile b/docs/doxygen/config.doxyfile index 6493bc18..71c4205f 100644 --- a/docs/doxygen/config.doxyfile +++ b/docs/doxygen/config.doxyfile @@ -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. diff --git a/source/include/sigv4.h b/source/include/sigv4.h index 98c29da1..9f891723 100644 --- a/source/include/sigv4.h +++ b/source/include/sigv4.h @@ -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. @@ -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 } diff --git a/source/sigv4.c b/source/sigv4.c index 795f5b3f..da22b056 100644 --- a/source/sigv4.c +++ b/source/sigv4.c @@ -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) */ /*-----------------------------------------------------------*/