static SntpStatus_t validateContext()

in source/core_sntp_client.c [198:248]


static SntpStatus_t validateContext( const SntpContext_t * pContext )
{
    SntpStatus_t status = SntpSuccess;

    /* Check if the context parameter is invalid. */
    if( pContext == NULL )
    {
        status = SntpErrorBadParameter;
        LogError( ( "Invalid context parameter: Context is NULL" ) );
    }

    /* Validate pointer parameters are not NULL. */
    else if( ( pContext->pTimeServers == NULL ) || ( pContext->pNetworkBuffer == NULL ) ||
             ( pContext->resolveDnsFunc == NULL ) ||
             ( pContext->getTimeFunc == NULL ) || ( pContext->setTimeFunc == NULL ) )
    {
        status = SntpErrorContextNotInitialized;
    }

    /* Validate the size of the configured servers list, network buffer size and the state
     * variable for the SNTP packet size.*/
    else if( ( pContext->numOfServers == 0U ) || ( pContext->bufferSize < SNTP_PACKET_BASE_SIZE ) ||
             ( pContext->sntpPacketSize < SNTP_PACKET_BASE_SIZE ) )
    {
        status = SntpErrorContextNotInitialized;
    }
    /* Validate that the UDP transport interface functions are valid. */
    else if( ( pContext->networkIntf.recvFrom == NULL ) || ( pContext->networkIntf.sendTo == NULL ) )
    {
        status = SntpErrorContextNotInitialized;
    }

    /* If an authentication interface is provided, validate that both its function pointer
     * members are valid. */
    else if( ( ( pContext->authIntf.generateClientAuth != NULL ) && ( pContext->authIntf.validateServerAuth == NULL ) ) ||
             ( ( pContext->authIntf.generateClientAuth == NULL ) && ( pContext->authIntf.validateServerAuth != NULL ) ) )
    {
        status = SntpErrorContextNotInitialized;
    }
    else
    {
        status = SntpSuccess;
    }

    if( status == SntpErrorContextNotInitialized )
    {
        LogError( ( "Invalid context parameter: Context is not initialized with Sntp_Init" ) );
    }

    return status;
}