in source/sigv4.c [2095:2168]
static SigV4Status_t writeCanonicalQueryParameters( CanonicalContext_t * pCanonicalRequest,
size_t numberOfParameters )
{
SigV4Status_t returnStatus = SigV4Success;
char * pBufLoc = NULL;
size_t encodedLen = 0U, remainingLen = 0U, paramsIndex = 0U;
assert( pCanonicalRequest != NULL );
assert( pCanonicalRequest->pBufCur != NULL );
assert( pCanonicalRequest->pQueryLoc != NULL );
pBufLoc = pCanonicalRequest->pBufCur;
remainingLen = pCanonicalRequest->bufRemaining;
for( paramsIndex = 0U; paramsIndex < numberOfParameters; paramsIndex++ )
{
assert( pCanonicalRequest->pQueryLoc[ paramsIndex ].key.pData != NULL );
assert( pCanonicalRequest->pQueryLoc[ paramsIndex ].key.dataLen > 0U );
encodedLen = remainingLen;
returnStatus = encodeURI( pCanonicalRequest->pQueryLoc[ paramsIndex ].key.pData,
pCanonicalRequest->pQueryLoc[ paramsIndex ].key.dataLen,
pBufLoc,
&encodedLen,
true /* Encode slash (/) */,
false /* Do not encode '='. */ );
if( returnStatus == SigV4Success )
{
pBufLoc += encodedLen;
remainingLen -= encodedLen;
assert( pCanonicalRequest->pQueryLoc[ paramsIndex ].value.pData != NULL );
returnStatus = writeValueInCanonicalizedQueryString( pBufLoc,
remainingLen,
pCanonicalRequest->pQueryLoc[ paramsIndex ].value.pData,
pCanonicalRequest->pQueryLoc[ paramsIndex ].value.dataLen,
&encodedLen );
pBufLoc += encodedLen;
remainingLen -= encodedLen;
}
/* If there is a succeeding query parameter, add the '&' separator in the canonical query. */
if( ( returnStatus == SigV4Success ) && ( ( paramsIndex + 1U ) != numberOfParameters ) )
{
/* Before adding the '&' for the next query parameter, check that there is
* space in the buffer. */
if( remainingLen > 0U )
{
*pBufLoc = '&';
++pBufLoc;
remainingLen--;
}
/* There is at least another query parameter entry to encode
* but no space in the buffer. */
else
{
returnStatus = SigV4InsufficientMemory;
LOG_INSUFFICIENT_MEMORY_ERROR( "write query parameter separator, '&'", 1U );
break;
}
}
}
/* Update the context state if canonical query generation was successful. */
if( returnStatus == SigV4Success )
{
pCanonicalRequest->pBufCur = pBufLoc;
pCanonicalRequest->bufRemaining = remainingLen;
}
return returnStatus;
}