static JobsStatus_t matchIdApi()

in source/jobs.c [398:452]


static JobsStatus_t matchIdApi( char * topic,
                                size_t topicLength,
                                JobsTopic_t * outApi,
                                char ** outJobId,
                                uint16_t * outJobIdLength )
{
    JobsStatus_t ret = JobsNoMatch;
    size_t i;
    char * p = topic;
    size_t length = topicLength;
    char * jobId = NULL;
    uint16_t jobIdLength = 0U;

    assert( ( topic != NULL ) && ( outApi != NULL ) &&
            ( outJobId != NULL ) && ( outJobIdLength != NULL ) );

    for( i = 0U; i < length; i++ )
    {
        if( ( i > 0U ) && ( p[ i ] == '/' ) )
        {
            /* Save the leading job ID and its length. */
            jobId = p;
            jobIdLength = ( uint16_t ) i;
            break;
        }
    }

    /* Advance p to after the '/' and reduce buffer length
     * for the remaining API search. */
    p = &p[ jobIdLength + 1U ];
    length = length - jobIdLength - 1U;

    if( ( isNextJobId( jobId, jobIdLength ) == true ) ||
        ( isValidJobId( jobId, jobIdLength ) == true ) )
    {
        JobsTopic_t api;

        /* The api variable is bounded within contiguous values of the enum type. */
        /* coverity[misra_c_2012_rule_10_1_violation] */
        for( api = JobsDescribeSuccess; api < JobsMaxTopic; api++ )
        {
            ret = strnnEq( p, length, apiTopic[ api ], apiTopicLength[ api ] );

            if( ret == JobsSuccess )
            {
                *outApi = api;
                *outJobId = jobId;
                *outJobIdLength = jobIdLength;
                break;
            }
        }
    }

    return ret;
}