in src/source/Common/AwsV4Signer.c [785:845]
STATUS getCanonicalUri(PCHAR pUrl, UINT32 len, PCHAR* ppStart, PCHAR* ppEnd, PBOOL pDefault)
{
STATUS retStatus = STATUS_SUCCESS;
PCHAR pStart = NULL, pEnd = NULL, pCur;
UINT32 urlLen;
BOOL iterate = TRUE, defaultPath = FALSE;
CHK(pUrl != NULL && ppStart != NULL && ppEnd != NULL && pDefault != NULL, STATUS_NULL_ARG);
// We know for sure url is NULL terminated
urlLen = (len != 0) ? len : (UINT32) STRLEN(pUrl);
// Start from the schema delimiter
pCur = STRSTR(pUrl, SCHEMA_DELIMITER_STRING);
CHK(pCur != NULL, STATUS_INVALID_ARG);
// Advance the pCur past the delimiter
pCur += STRLEN(SCHEMA_DELIMITER_STRING);
// Ensure we are not past the string
pEnd = pUrl + urlLen;
CHK(pEnd > pCur, STATUS_INVALID_ARG);
// Check if we have the host delimiter which is slash or a question mark - whichever is first
while (iterate && pCur < pEnd && *pCur != '\0') {
if (*pCur == '?') {
// This is the case of the empty path with query params
pEnd = pCur;
pStart = DEFAULT_CANONICAL_URI_STRING;
defaultPath = TRUE;
iterate = FALSE;
} else if (*pCur == '/') {
// This is the case of the path which we find
pStart = pCur;
pEnd = STRNCHR(pCur, urlLen - (UINT32)(pCur - pUrl), '?');
iterate = FALSE;
}
pCur++;
}
if (pEnd == NULL) {
pEnd = pUrl + urlLen;
}
CleanUp:
if (ppStart != NULL) {
*ppStart = pStart;
}
if (ppEnd != NULL) {
*ppEnd = pEnd;
}
if (pDefault != NULL) {
*pDefault = defaultPath;
}
return retStatus;
}