in sdk/src/azure/iot/az_iot_provisioning_client.c [547:596]
AZ_NODISCARD az_result az_iot_provisioning_client_parse_received_topic_and_payload(
az_iot_provisioning_client const* client,
az_span received_topic,
az_span received_payload,
az_iot_provisioning_client_register_response* out_response)
{
(void)client;
_az_PRECONDITION_NOT_NULL(client);
_az_PRECONDITION_VALID_SPAN(client->_internal.global_device_endpoint, 1, false);
_az_PRECONDITION_VALID_SPAN(received_topic, 1, false);
_az_PRECONDITION_VALID_SPAN(received_payload, 1, false);
_az_PRECONDITION_NOT_NULL(out_response);
az_span str_dps_registrations_res = _az_iot_provisioning_get_dps_registrations_res();
int32_t idx = az_span_find(received_topic, str_dps_registrations_res);
if (idx != 0)
{
return AZ_ERROR_IOT_TOPIC_NO_MATCH;
}
_az_LOG_WRITE(AZ_LOG_MQTT_RECEIVED_TOPIC, received_topic);
_az_LOG_WRITE(AZ_LOG_MQTT_RECEIVED_PAYLOAD, received_payload);
// Parse the status.
az_span remainder = az_span_slice_to_end(received_topic, az_span_size(str_dps_registrations_res));
int32_t index = 0;
az_span int_slice = _az_span_token(remainder, AZ_SPAN_FROM_STR("/"), &remainder, &index);
_az_RETURN_IF_FAILED(az_span_atou32(int_slice, (uint32_t*)(&out_response->status)));
// Parse the optional retry-after= field.
az_span retry_after = AZ_SPAN_FROM_STR("retry-after=");
idx = az_span_find(remainder, retry_after);
if (idx != -1)
{
remainder = az_span_slice_to_end(remainder, idx + az_span_size(retry_after));
int_slice = _az_span_token(remainder, AZ_SPAN_FROM_STR("&"), &remainder, &index);
_az_RETURN_IF_FAILED(az_span_atou32(int_slice, &out_response->retry_after_seconds));
}
else
{
out_response->retry_after_seconds = 0;
}
_az_RETURN_IF_FAILED(az_iot_provisioning_client_parse_payload(received_payload, out_response));
return AZ_OK;
}