bool Jobs_IsJobUpdateStatus()

in source/jobs.c [929:961]


bool Jobs_IsJobUpdateStatus( const char * topic,
                             const size_t topicLength,
                             const char * jobId,
                             const size_t jobIdLength,
                             const char * thingName,
                             const size_t thingNameLength,
                             JobUpdateStatus_t expectedStatus )
{
    static const char * const jobUpdateStatusString[] =
    {
        "accepted",
        "rejected"
    };

    static const size_t jobUpdateStatusStringLengths[] =
    {
        CONST_STRLEN( "accepted" ),
        CONST_STRLEN( "rejected" )
    };

    assert( ( ( size_t ) expectedStatus ) < ARRAY_LENGTH( jobUpdateStatusString ) );

    /* Max suffix size = max topic size - "$aws/<thingname>" prefix */
    size_t suffixBufferLength = ( TOPIC_BUFFER_SIZE - CONST_STRLEN( "$aws/<thingname>" ) );
    char suffixBuffer[ TOPIC_BUFFER_SIZE - CONST_STRLEN( "$aws/<thingname>" ) ] = { '\0' };
    size_t start = 0U;

    ( void ) strnAppend( suffixBuffer, &start, suffixBufferLength, jobId, jobIdLength );
    ( void ) strnAppend( suffixBuffer, &start, suffixBufferLength, "/update/", ( CONST_STRLEN( "/update/" ) ) );
    ( void ) strnAppend( suffixBuffer, &start, suffixBufferLength, jobUpdateStatusString[ expectedStatus ], jobUpdateStatusStringLengths[ expectedStatus ] );

    return isThingnameTopicMatch( topic, topicLength, suffixBuffer, strnlen( suffixBuffer, suffixBufferLength ), thingName, thingNameLength );
}