in source/azure_iot_provisioning_client.c [353:434]
static void prvProvClientParseResponse( AzureIoTProvisioningClient_t * pxAzureProvClient )
{
az_result xCoreResult;
az_span xTopic = az_span_create( pxAzureProvClient->_internal.ucProvisioningLastResponse,
( int32_t ) pxAzureProvClient->_internal.usLastResponseTopicLength );
az_span xPayload = az_span_create( pxAzureProvClient->_internal.ucProvisioningLastResponse +
pxAzureProvClient->_internal.usLastResponseTopicLength,
( int32_t ) pxAzureProvClient->_internal.xLastResponsePayloadLength );
/* Check the state. */
if( pxAzureProvClient->_internal.ulWorkflowState != azureiotprovisioningWF_STATE_RESPONSE )
{
AZLogWarn( ( "AzureIoTProvisioning parse response action called in wrong state: [%u]",
( uint16_t ) pxAzureProvClient->_internal.ulWorkflowState ) );
return;
}
if( ( pxAzureProvClient->_internal.usLastResponseTopicLength == 0 ) ||
( pxAzureProvClient->_internal.xLastResponsePayloadLength == 0 ) )
{
AZLogError( ( "AzureIoTProvisioning client failed with invalid server response" ) );
prvProvClientUpdateState( pxAzureProvClient, eAzureIoTErrorInvalidResponse );
return;
}
xCoreResult =
az_iot_provisioning_client_parse_received_topic_and_payload( &pxAzureProvClient->_internal.xProvisioningClientCore,
xTopic, xPayload, &pxAzureProvClient->_internal.xRegisterResponse );
if( xCoreResult == AZ_ERROR_IOT_TOPIC_NO_MATCH )
{
AZLogInfo( ( "AzureIoTProvisioning ignoring unknown topic." ) );
/* Maintaining the same state. */
return;
}
else if( az_result_failed( xCoreResult ) )
{
AZLogError( ( "AzureIoTProvisioning client failed to parse packet: core error=0x%08x", ( uint16_t ) xCoreResult ) );
prvProvClientUpdateState( pxAzureProvClient, eAzureIoTErrorFailed );
return;
}
if( az_iot_provisioning_client_operation_complete( pxAzureProvClient->_internal.xRegisterResponse.operation_status ) )
{
switch( pxAzureProvClient->_internal.xRegisterResponse.operation_status )
{
case AZ_IOT_PROVISIONING_STATUS_ASSIGNED:
prvProvClientUpdateState( pxAzureProvClient, eAzureIoTSuccess );
break;
case AZ_IOT_PROVISIONING_STATUS_FAILED:
AZLogError( ( "AzureIoTProvisioning client registration failed with error %u: TrackingID: [%.*s] \"%.*s\"",
( uint16_t ) pxAzureProvClient->_internal.xRegisterResponse.registration_state.extended_error_code,
( int16_t ) az_span_size( pxAzureProvClient->_internal.xRegisterResponse.registration_state.error_tracking_id ),
az_span_ptr( pxAzureProvClient->_internal.xRegisterResponse.registration_state.error_tracking_id ),
( int16_t ) az_span_size( pxAzureProvClient->_internal.xRegisterResponse.registration_state.error_message ),
az_span_ptr( pxAzureProvClient->_internal.xRegisterResponse.registration_state.error_message ) ) );
prvProvClientUpdateState( pxAzureProvClient, eAzureIoTErrorServerError );
break;
case AZ_IOT_PROVISIONING_STATUS_DISABLED:
AZLogError( ( "AzureIoTProvisioning client: device is disabled." ) );
prvProvClientUpdateState( pxAzureProvClient, eAzureIoTErrorServerError );
break;
default:
AZLogError( ( "AzureIoTProvisioning unexpected operation status %d", pxAzureProvClient->_internal.xRegisterResponse.operation_status ) );
}
}
else /* Operation is not complete. */
{
if( pxAzureProvClient->_internal.xRegisterResponse.retry_after_seconds == 0 )
{
pxAzureProvClient->_internal.xRegisterResponse.retry_after_seconds = azureiotconfigPROVISIONING_POLLING_INTERVAL_S;
}
pxAzureProvClient->_internal.ullRetryAfter =
pxAzureProvClient->_internal.xGetTimeFunction() +
pxAzureProvClient->_internal.xRegisterResponse.retry_after_seconds;
prvProvClientUpdateState( pxAzureProvClient, eAzureIoTErrorPending );
}
}