in source/shadow.c [377:426]
static ShadowStatus_t validateName( const char * pString,
uint16_t stringLength,
uint8_t maxAllowedLength,
uint8_t * pNameLength )
{
uint16_t index = 0U;
ShadowStatus_t returnStatus = SHADOW_FAIL;
uint8_t parsedName = 0U;
for( ; index < stringLength; index++ )
{
/* The name should always be terminated by a forward slash */
if( pString[ index ] == ( char ) '/' )
{
parsedName = 1U;
break;
}
}
if( parsedName == 1U )
{
if( index == 0U )
{
LogDebug( ( "Not a Shadow topic. Unable to find a %s name in the topic.",
( maxAllowedLength == SHADOW_THINGNAME_MAX_LENGTH ) ? "Thing" : "Shadow" ) );
}
else if( index > maxAllowedLength )
{
LogDebug( ( "Not a Shadow topic. Extracted %s name length of %u exceeds maximum allowed length %u.",
( maxAllowedLength == SHADOW_THINGNAME_MAX_LENGTH ) ? "Thing" : "Shadow",
( unsigned int ) index,
( unsigned int ) maxAllowedLength ) );
}
else
{
/* Only accept names of greater than zero length.
* The variable `index` will not exceed the 8 bit integer width here
* since it will be lesser than the 8 bit integer `maxAllowedLength`. */
*pNameLength = ( uint8_t ) index;
returnStatus = SHADOW_SUCCESS;
}
}
else
{
LogDebug( ( "Not a Shadow topic. Unable to find a %s name in the topic.",
( maxAllowedLength == SHADOW_THINGNAME_MAX_LENGTH ) ? "Thing" : "Shadow" ) );
}
return returnStatus;
}