|
|
|
@ -195,7 +195,7 @@ static STRING_HANDLE get_target_iothub_fqdn(const IOTHUBTRANSPORT_CONFIG* config
|
|
|
|
|
|
|
|
|
|
if (config->upperConfig->protocolGatewayHostName == NULL)
|
|
|
|
|
{
|
|
|
|
|
if ((fqdn = STRING_construct_sprintf("%s.%s", config->upperConfig->iotHubName, config->upperConfig->iotHubSuffix)) == NULL)
|
|
|
|
|
if ((fqdn = STRING_construct_sprintf("%s.%s", MU_P_OR_NULL(config->upperConfig->iotHubName), MU_P_OR_NULL(config->upperConfig->iotHubSuffix))) == NULL)
|
|
|
|
|
{
|
|
|
|
|
LogError("Failed to copy iotHubName and iotHubSuffix (STRING_construct_sprintf failed)");
|
|
|
|
|
}
|
|
|
|
@ -495,7 +495,8 @@ static int subscribe_methods(AMQP_TRANSPORT_DEVICE_INSTANCE* deviceState)
|
|
|
|
|
|
|
|
|
|
if ((amqp_connection_get_session_handle(deviceState->transport_instance->amqp_connection, &session_handle)) != RESULT_OK)
|
|
|
|
|
{
|
|
|
|
|
LogError("Device '%s' failed subscribing for methods (failed getting session handle)", STRING_c_str(deviceState->device_id));
|
|
|
|
|
const char* device_id = STRING_c_str(deviceState->device_id); // advoid MU_P_OR_NULL double call
|
|
|
|
|
LogError("Device '%s' failed subscribing for methods (failed getting session handle)", MU_P_OR_NULL(device_id));
|
|
|
|
|
result = MU_FAILURE;
|
|
|
|
|
}
|
|
|
|
|
else if (iothubtransportamqp_methods_subscribe(deviceState->methods_handle, session_handle, on_methods_error, deviceState, on_method_request_received, deviceState, on_methods_unsubscribed, deviceState) != 0)
|
|
|
|
@ -815,7 +816,8 @@ static void prepare_device_for_connection_retry(AMQP_TRANSPORT_DEVICE_INSTANCE*
|
|
|
|
|
{
|
|
|
|
|
if (amqp_device_stop(registered_device->device_handle) != RESULT_OK)
|
|
|
|
|
{
|
|
|
|
|
LogError("Failed preparing device '%s' for connection retry (amqp_device_stop failed)", STRING_c_str(registered_device->device_id));
|
|
|
|
|
const char* device_id = STRING_c_str(registered_device->device_id); // advoid MU_P_OR_NULL double call
|
|
|
|
|
LogError("Failed preparing device '%s' for connection retry (amqp_device_stop failed)", MU_P_OR_NULL(device_id));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -869,7 +871,7 @@ static bool is_device_credential_acceptable(const IOTHUB_DEVICE_CONFIG* device_c
|
|
|
|
|
|
|
|
|
|
if ((device_config->deviceSasToken != NULL) && (device_config->deviceKey != NULL))
|
|
|
|
|
{
|
|
|
|
|
LogError("Credential of device '%s' is not acceptable (must provide EITHER deviceSasToken OR deviceKey)", device_config->deviceId);
|
|
|
|
|
LogError("Credential of device '%s' is not acceptable (must provide EITHER deviceSasToken OR deviceKey)", MU_P_OR_NULL(device_config->deviceId));
|
|
|
|
|
result = false;
|
|
|
|
|
}
|
|
|
|
|
else if (preferred_authentication_mode == AMQP_TRANSPORT_AUTHENTICATION_MODE_NOT_SET)
|
|
|
|
@ -878,12 +880,12 @@ static bool is_device_credential_acceptable(const IOTHUB_DEVICE_CONFIG* device_c
|
|
|
|
|
}
|
|
|
|
|
else if (preferred_authentication_mode == AMQP_TRANSPORT_AUTHENTICATION_MODE_X509 && (device_config->deviceKey != NULL || device_config->deviceSasToken != NULL))
|
|
|
|
|
{
|
|
|
|
|
LogError("Credential of device '%s' is not acceptable (transport is using X509 certificate authentication, but device config contains deviceKey or sasToken)", device_config->deviceId);
|
|
|
|
|
LogError("Credential of device '%s' is not acceptable (transport is using X509 certificate authentication, but device config contains deviceKey or sasToken)", MU_P_OR_NULL(device_config->deviceId));
|
|
|
|
|
result = false;
|
|
|
|
|
}
|
|
|
|
|
else if (preferred_authentication_mode != AMQP_TRANSPORT_AUTHENTICATION_MODE_X509 && (device_config->deviceKey == NULL && device_config->deviceSasToken == NULL))
|
|
|
|
|
{
|
|
|
|
|
LogError("Credential of device '%s' is not acceptable (transport is using CBS authentication, but device config does not contain deviceKey nor sasToken)", device_config->deviceId);
|
|
|
|
|
LogError("Credential of device '%s' is not acceptable (transport is using CBS authentication, but device config does not contain deviceKey nor sasToken)", MU_P_OR_NULL(device_config->deviceId));
|
|
|
|
|
result = false;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
@ -992,7 +994,8 @@ static int send_pending_events(AMQP_TRANSPORT_DEVICE_INSTANCE* device_state)
|
|
|
|
|
{
|
|
|
|
|
if (amqp_device_send_event_async(device_state->device_handle, message, on_event_send_complete, device_state) != RESULT_OK)
|
|
|
|
|
{
|
|
|
|
|
LogError("Device '%s' failed to send message (amqp_device_send_event_async failed)", STRING_c_str(device_state->device_id));
|
|
|
|
|
const char* device_id = STRING_c_str(device_state->device_id); // advoid MU_P_OR_NULL double call
|
|
|
|
|
LogError("Device '%s' failed to send message (amqp_device_send_event_async failed)", MU_P_OR_NULL(device_id));
|
|
|
|
|
result = MU_FAILURE;
|
|
|
|
|
|
|
|
|
|
on_event_send_complete(message, D2C_EVENT_SEND_COMPLETE_RESULT_ERROR_FAIL_SENDING, device_state);
|
|
|
|
@ -1022,18 +1025,21 @@ static int IoTHubTransport_AMQP_Common_Device_DoWork(AMQP_TRANSPORT_DEVICE_INSTA
|
|
|
|
|
|
|
|
|
|
if (amqp_connection_get_session_handle(registered_device->transport_instance->amqp_connection, &session_handle) != RESULT_OK)
|
|
|
|
|
{
|
|
|
|
|
LogError("Failed performing DoWork for device '%s' (failed to get the amqp_connection session_handle)", STRING_c_str(registered_device->device_id));
|
|
|
|
|
const char* device_id = STRING_c_str(registered_device->device_id); // advoid MU_P_OR_NULL double call
|
|
|
|
|
LogError("Failed performing DoWork for device '%s' (failed to get the amqp_connection session_handle)", MU_P_OR_NULL(device_id));
|
|
|
|
|
result = MU_FAILURE;
|
|
|
|
|
}
|
|
|
|
|
else if (registered_device->transport_instance->preferred_authentication_mode == AMQP_TRANSPORT_AUTHENTICATION_MODE_CBS &&
|
|
|
|
|
amqp_connection_get_cbs_handle(registered_device->transport_instance->amqp_connection, &cbs_handle) != RESULT_OK)
|
|
|
|
|
{
|
|
|
|
|
LogError("Failed performing DoWork for device '%s' (failed to get the amqp_connection cbs_handle)", STRING_c_str(registered_device->device_id));
|
|
|
|
|
const char* device_id = STRING_c_str(registered_device->device_id); // advoid MU_P_OR_NULL double call
|
|
|
|
|
LogError("Failed performing DoWork for device '%s' (failed to get the amqp_connection cbs_handle)", MU_P_OR_NULL(device_id));
|
|
|
|
|
result = MU_FAILURE;
|
|
|
|
|
}
|
|
|
|
|
else if (amqp_device_start_async(registered_device->device_handle, session_handle, cbs_handle) != RESULT_OK)
|
|
|
|
|
{
|
|
|
|
|
LogError("Failed performing DoWork for device '%s' (failed to start device)", STRING_c_str(registered_device->device_id));
|
|
|
|
|
const char* device_id = STRING_c_str(registered_device->device_id); // advoid MU_P_OR_NULL double call
|
|
|
|
|
LogError("Failed performing DoWork for device '%s' (failed to start device)", MU_P_OR_NULL(device_id));
|
|
|
|
|
result = MU_FAILURE;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
@ -1047,13 +1053,15 @@ static int IoTHubTransport_AMQP_Common_Device_DoWork(AMQP_TRANSPORT_DEVICE_INSTA
|
|
|
|
|
bool is_timed_out;
|
|
|
|
|
if (is_timeout_reached(registered_device->time_of_last_state_change, registered_device->max_state_change_timeout_secs, &is_timed_out) != RESULT_OK)
|
|
|
|
|
{
|
|
|
|
|
LogError("Failed performing DoWork for device '%s' (failed tracking timeout of device %d state)", STRING_c_str(registered_device->device_id), registered_device->device_state);
|
|
|
|
|
const char* device_id = STRING_c_str(registered_device->device_id); // advoid MU_P_OR_NULL double call
|
|
|
|
|
LogError("Failed performing DoWork for device '%s' (failed tracking timeout of device %d state)", MU_P_OR_NULL(device_id), registered_device->device_state);
|
|
|
|
|
registered_device->device_state = DEVICE_STATE_ERROR_AUTH; // if time could not be calculated, the worst must be assumed.
|
|
|
|
|
result = MU_FAILURE;
|
|
|
|
|
}
|
|
|
|
|
else if (is_timed_out)
|
|
|
|
|
{
|
|
|
|
|
LogError("Failed performing DoWork for device '%s' (device failed to start or stop within expected timeout)", STRING_c_str(registered_device->device_id));
|
|
|
|
|
const char* device_id = STRING_c_str(registered_device->device_id); // advoid MU_P_OR_NULL double call
|
|
|
|
|
LogError("Failed performing DoWork for device '%s' (device failed to start or stop within expected timeout)", MU_P_OR_NULL(device_id));
|
|
|
|
|
registered_device->device_state = DEVICE_STATE_ERROR_AUTH; // this will cause device to be stopped bellow on the next call to this function.
|
|
|
|
|
result = MU_FAILURE;
|
|
|
|
|
}
|
|
|
|
@ -1068,13 +1076,15 @@ static int IoTHubTransport_AMQP_Common_Device_DoWork(AMQP_TRANSPORT_DEVICE_INSTA
|
|
|
|
|
|
|
|
|
|
if (registered_device->number_of_previous_failures >= MAX_NUMBER_OF_DEVICE_FAILURES)
|
|
|
|
|
{
|
|
|
|
|
const char* device_id = STRING_c_str(registered_device->device_id); // advoid MU_P_OR_NULL double call
|
|
|
|
|
LogError("Failed performing DoWork for device '%s' (device reported state %d; number of previous failures: %lu)",
|
|
|
|
|
STRING_c_str(registered_device->device_id), (int)registered_device->device_state, (unsigned long)registered_device->number_of_previous_failures);
|
|
|
|
|
MU_P_OR_NULL(device_id), (int)registered_device->device_state, (unsigned long)registered_device->number_of_previous_failures);
|
|
|
|
|
result = MU_FAILURE;
|
|
|
|
|
}
|
|
|
|
|
else if (amqp_device_delayed_stop(registered_device->device_handle, DEFAULT_DEVICE_STOP_DELAY) != RESULT_OK)
|
|
|
|
|
{
|
|
|
|
|
LogError("Failed to stop reset device '%s' (amqp_device_stop failed)", STRING_c_str(registered_device->device_id));
|
|
|
|
|
const char* device_id = STRING_c_str(registered_device->device_id); // advoid MU_P_OR_NULL double call
|
|
|
|
|
LogError("Failed to stop reset device '%s' (amqp_device_stop failed)", MU_P_OR_NULL(device_id));
|
|
|
|
|
result = MU_FAILURE;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
@ -1087,7 +1097,8 @@ static int IoTHubTransport_AMQP_Common_Device_DoWork(AMQP_TRANSPORT_DEVICE_INSTA
|
|
|
|
|
!registered_device->subscribed_for_methods &&
|
|
|
|
|
subscribe_methods(registered_device) != RESULT_OK)
|
|
|
|
|
{
|
|
|
|
|
LogError("Failed performing DoWork for device '%s' (failed registering for device methods)", STRING_c_str(registered_device->device_id));
|
|
|
|
|
const char* device_id = STRING_c_str(registered_device->device_id); // advoid MU_P_OR_NULL double call
|
|
|
|
|
LogError("Failed performing DoWork for device '%s' (failed registering for device methods)", MU_P_OR_NULL(device_id));
|
|
|
|
|
registered_device->number_of_previous_failures++;
|
|
|
|
|
result = MU_FAILURE;
|
|
|
|
|
}
|
|
|
|
@ -1095,7 +1106,8 @@ static int IoTHubTransport_AMQP_Common_Device_DoWork(AMQP_TRANSPORT_DEVICE_INSTA
|
|
|
|
|
{
|
|
|
|
|
if (send_pending_events(registered_device) != RESULT_OK)
|
|
|
|
|
{
|
|
|
|
|
LogError("Failed performing DoWork for device '%s' (failed sending pending events)", STRING_c_str(registered_device->device_id));
|
|
|
|
|
const char* device_id = STRING_c_str(registered_device->device_id); // advoid MU_P_OR_NULL double call
|
|
|
|
|
LogError("Failed performing DoWork for device '%s' (failed sending pending events)", MU_P_OR_NULL(device_id));
|
|
|
|
|
registered_device->number_of_previous_failures++;
|
|
|
|
|
result = MU_FAILURE;
|
|
|
|
|
}
|
|
|
|
@ -1127,7 +1139,8 @@ static int replicate_device_options_to(AMQP_TRANSPORT_DEVICE_INSTANCE* dev_insta
|
|
|
|
|
DEVICE_OPTION_EVENT_SEND_TIMEOUT_SECS,
|
|
|
|
|
&dev_instance->transport_instance->option_send_event_timeout_secs) != RESULT_OK)
|
|
|
|
|
{
|
|
|
|
|
LogError("Failed to apply option DEVICE_OPTION_EVENT_SEND_TIMEOUT_SECS to device '%s' (amqp_device_set_option failed)", STRING_c_str(dev_instance->device_id));
|
|
|
|
|
const char* device_id = STRING_c_str(dev_instance->device_id); // advoid MU_P_OR_NULL double call
|
|
|
|
|
LogError("Failed to apply option DEVICE_OPTION_EVENT_SEND_TIMEOUT_SECS to device '%s' (amqp_device_set_option failed)", MU_P_OR_NULL(device_id));
|
|
|
|
|
result = MU_FAILURE;
|
|
|
|
|
}
|
|
|
|
|
else if (auth_mode == DEVICE_AUTH_MODE_CBS)
|
|
|
|
@ -1137,7 +1150,8 @@ static int replicate_device_options_to(AMQP_TRANSPORT_DEVICE_INSTANCE* dev_insta
|
|
|
|
|
DEVICE_OPTION_CBS_REQUEST_TIMEOUT_SECS,
|
|
|
|
|
&dev_instance->transport_instance->option_cbs_request_timeout_secs) != RESULT_OK)
|
|
|
|
|
{
|
|
|
|
|
LogError("Failed to apply option DEVICE_OPTION_CBS_REQUEST_TIMEOUT_SECS to device '%s' (amqp_device_set_option failed)", STRING_c_str(dev_instance->device_id));
|
|
|
|
|
const char* device_id = STRING_c_str(dev_instance->device_id); // advoid MU_P_OR_NULL double call
|
|
|
|
|
LogError("Failed to apply option DEVICE_OPTION_CBS_REQUEST_TIMEOUT_SECS to device '%s' (amqp_device_set_option failed)", MU_P_OR_NULL(device_id));
|
|
|
|
|
result = MU_FAILURE;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
@ -1208,8 +1222,9 @@ static int IoTHubTransport_AMQP_Common_Device_SetOption(TRANSPORT_LL_HANDLE hand
|
|
|
|
|
}
|
|
|
|
|
else if (amqp_device_set_option(registered_device->device_handle, device_option, value) != RESULT_OK)
|
|
|
|
|
{
|
|
|
|
|
const char* device_id = STRING_c_str(registered_device->device_id); // advoid MU_P_OR_NULL double call
|
|
|
|
|
LogError("failed setting option '%s' to registered device '%s' (amqp_device_set_option failed)",
|
|
|
|
|
option, STRING_c_str(registered_device->device_id));
|
|
|
|
|
option, MU_P_OR_NULL(device_id));
|
|
|
|
|
result = MU_FAILURE;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
@ -1512,12 +1527,14 @@ int IoTHubTransport_AMQP_Common_Subscribe(IOTHUB_DEVICE_HANDLE handle)
|
|
|
|
|
|
|
|
|
|
if (!is_device_registered(amqp_device_instance))
|
|
|
|
|
{
|
|
|
|
|
LogError("Device '%s' failed subscribing to cloud-to-device messages (device is not registered)", STRING_c_str(amqp_device_instance->device_id));
|
|
|
|
|
const char* device_id = STRING_c_str(amqp_device_instance->device_id); // advoid MU_P_OR_NULL double call
|
|
|
|
|
LogError("Device '%s' failed subscribing to cloud-to-device messages (device is not registered)", MU_P_OR_NULL(device_id));
|
|
|
|
|
result = MU_FAILURE;
|
|
|
|
|
}
|
|
|
|
|
else if (amqp_device_subscribe_message(amqp_device_instance->device_handle, on_message_received, amqp_device_instance) != RESULT_OK)
|
|
|
|
|
{
|
|
|
|
|
LogError("Device '%s' failed subscribing to cloud-to-device messages (amqp_device_subscribe_message failed)", STRING_c_str(amqp_device_instance->device_id));
|
|
|
|
|
const char* device_id = STRING_c_str(amqp_device_instance->device_id); // advoid MU_P_OR_NULL double call
|
|
|
|
|
LogError("Device '%s' failed subscribing to cloud-to-device messages (amqp_device_subscribe_message failed)", MU_P_OR_NULL(device_id));
|
|
|
|
|
result = MU_FAILURE;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
@ -1541,11 +1558,13 @@ void IoTHubTransport_AMQP_Common_Unsubscribe(IOTHUB_DEVICE_HANDLE handle)
|
|
|
|
|
|
|
|
|
|
if (!is_device_registered(amqp_device_instance))
|
|
|
|
|
{
|
|
|
|
|
LogError("Device '%s' failed unsubscribing to cloud-to-device messages (device is not registered)", STRING_c_str(amqp_device_instance->device_id));
|
|
|
|
|
const char* device_id = STRING_c_str(amqp_device_instance->device_id); // advoid MU_P_OR_NULL double call
|
|
|
|
|
LogError("Device '%s' failed unsubscribing to cloud-to-device messages (device is not registered)", MU_P_OR_NULL(device_id));
|
|
|
|
|
}
|
|
|
|
|
else if (amqp_device_unsubscribe_message(amqp_device_instance->device_handle) != RESULT_OK)
|
|
|
|
|
{
|
|
|
|
|
LogError("Device '%s' failed unsubscribing to cloud-to-device messages (amqp_device_unsubscribe_message failed)", STRING_c_str(amqp_device_instance->device_id));
|
|
|
|
|
const char* device_id = STRING_c_str(amqp_device_instance->device_id); // advoid MU_P_OR_NULL double call
|
|
|
|
|
LogError("Device '%s' failed unsubscribing to cloud-to-device messages (amqp_device_unsubscribe_message failed)", MU_P_OR_NULL(device_id));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -2034,12 +2053,12 @@ IOTHUB_DEVICE_HANDLE IoTHubTransport_AMQP_Common_Register(TRANSPORT_LL_HANDLE ha
|
|
|
|
|
|
|
|
|
|
if (is_device_registered_ex(transport_instance->registered_devices, device->deviceId, &list_item))
|
|
|
|
|
{
|
|
|
|
|
LogError("IoTHubTransport_AMQP_Common_Register failed (device '%s' already registered on this transport instance)", device->deviceId);
|
|
|
|
|
LogError("IoTHubTransport_AMQP_Common_Register failed (device '%s' already registered on this transport instance)", MU_P_OR_NULL(device->deviceId));
|
|
|
|
|
result = NULL;
|
|
|
|
|
}
|
|
|
|
|
else if (!is_device_credential_acceptable(device, transport_instance->preferred_authentication_mode))
|
|
|
|
|
{
|
|
|
|
|
LogError("Transport failed to register device '%s' (device credential was not accepted)", device->deviceId);
|
|
|
|
|
LogError("Transport failed to register device '%s' (device credential was not accepted)", MU_P_OR_NULL(device->deviceId));
|
|
|
|
|
result = NULL;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
@ -2048,7 +2067,7 @@ IOTHUB_DEVICE_HANDLE IoTHubTransport_AMQP_Common_Register(TRANSPORT_LL_HANDLE ha
|
|
|
|
|
|
|
|
|
|
if ((amqp_device_instance = (AMQP_TRANSPORT_DEVICE_INSTANCE*)malloc(sizeof(AMQP_TRANSPORT_DEVICE_INSTANCE))) == NULL)
|
|
|
|
|
{
|
|
|
|
|
LogError("Transport failed to register device '%s' (failed to create the device state instance; malloc failed)", device->deviceId);
|
|
|
|
|
LogError("Transport failed to register device '%s' (failed to create the device state instance; malloc failed)", MU_P_OR_NULL(device->deviceId));
|
|
|
|
|
result = NULL;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
@ -2067,7 +2086,7 @@ IOTHUB_DEVICE_HANDLE IoTHubTransport_AMQP_Common_Register(TRANSPORT_LL_HANDLE ha
|
|
|
|
|
|
|
|
|
|
if ((amqp_device_instance->device_id = STRING_construct(device->deviceId)) == NULL)
|
|
|
|
|
{
|
|
|
|
|
LogError("Transport failed to register device '%s' (failed to copy the deviceId)", device->deviceId);
|
|
|
|
|
LogError("Transport failed to register device '%s' (failed to copy the deviceId)", MU_P_OR_NULL(device->deviceId));
|
|
|
|
|
result = NULL;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
@ -2085,7 +2104,7 @@ IOTHUB_DEVICE_HANDLE IoTHubTransport_AMQP_Common_Register(TRANSPORT_LL_HANDLE ha
|
|
|
|
|
|
|
|
|
|
if ((amqp_device_instance->device_handle = amqp_device_create(&device_config)) == NULL)
|
|
|
|
|
{
|
|
|
|
|
LogError("Transport failed to register device '%s' (failed to create the DEVICE_HANDLE instance)", device->deviceId);
|
|
|
|
|
LogError("Transport failed to register device '%s' (failed to create the DEVICE_HANDLE instance)", MU_P_OR_NULL(device->deviceId));
|
|
|
|
|
result = NULL;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
@ -2095,19 +2114,19 @@ IOTHUB_DEVICE_HANDLE IoTHubTransport_AMQP_Common_Register(TRANSPORT_LL_HANDLE ha
|
|
|
|
|
amqp_device_instance->methods_handle = iothubtransportamqp_methods_create(STRING_c_str(transport_instance->iothub_host_fqdn), device->deviceId, device->moduleId);
|
|
|
|
|
if (amqp_device_instance->methods_handle == NULL)
|
|
|
|
|
{
|
|
|
|
|
LogError("Transport failed to register device '%s' (Cannot create the methods module)", device->deviceId);
|
|
|
|
|
LogError("Transport failed to register device '%s' (Cannot create the methods module)", MU_P_OR_NULL(device->deviceId));
|
|
|
|
|
result = NULL;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (replicate_device_options_to(amqp_device_instance, device_config.authentication_mode) != RESULT_OK)
|
|
|
|
|
{
|
|
|
|
|
LogError("Transport failed to register device '%s' (failed to replicate options)", device->deviceId);
|
|
|
|
|
LogError("Transport failed to register device '%s' (failed to replicate options)", MU_P_OR_NULL(device->deviceId));
|
|
|
|
|
result = NULL;
|
|
|
|
|
}
|
|
|
|
|
else if (singlylinkedlist_add(transport_instance->registered_devices, amqp_device_instance) == NULL)
|
|
|
|
|
{
|
|
|
|
|
LogError("Transport failed to register device '%s' (singlylinkedlist_add failed)", device->deviceId);
|
|
|
|
|
LogError("Transport failed to register device '%s' (singlylinkedlist_add failed)", MU_P_OR_NULL(device->deviceId));
|
|
|
|
|
result = NULL;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
@ -2160,18 +2179,18 @@ void IoTHubTransport_AMQP_Common_Unregister(IOTHUB_DEVICE_HANDLE deviceHandle)
|
|
|
|
|
}
|
|
|
|
|
else if (registered_device->transport_instance == NULL)
|
|
|
|
|
{
|
|
|
|
|
LogError("Failed to unregister device '%s' (deviceHandle does not have a transport state associated to).", device_id);
|
|
|
|
|
LogError("Failed to unregister device '%s' (deviceHandle does not have a transport state associated to).", MU_P_OR_NULL(device_id));
|
|
|
|
|
}
|
|
|
|
|
else if (!is_device_registered_ex(registered_device->transport_instance->registered_devices, device_id, &list_item))
|
|
|
|
|
{
|
|
|
|
|
LogError("Failed to unregister device '%s' (device is not registered within this transport).", device_id);
|
|
|
|
|
LogError("Failed to unregister device '%s' (device is not registered within this transport).", MU_P_OR_NULL(device_id));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Removing it first so the race hazard is reduced between this function and DoWork. Best would be to use locks.
|
|
|
|
|
if (singlylinkedlist_remove(registered_device->transport_instance->registered_devices, list_item) != RESULT_OK)
|
|
|
|
|
{
|
|
|
|
|
LogError("Failed to unregister device '%s' (singlylinkedlist_remove failed).", device_id);
|
|
|
|
|
LogError("Failed to unregister device '%s' (singlylinkedlist_remove failed).", MU_P_OR_NULL(device_id));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
@ -2276,7 +2295,8 @@ IOTHUB_CLIENT_RESULT IoTHubTransport_AMQP_Common_SendMessageDisposition(IOTHUB_D
|
|
|
|
|
|
|
|
|
|
if (amqp_device_send_message_disposition(amqp_device_instance->device_handle, (DEVICE_MESSAGE_DISPOSITION_INFO*)device_message_disposition_info, device_disposition_result) != RESULT_OK)
|
|
|
|
|
{
|
|
|
|
|
LogError("Device '%s' failed sending message disposition (amqp_device_send_message_disposition failed)", STRING_c_str(amqp_device_instance->device_id));
|
|
|
|
|
const char* device_id = STRING_c_str(amqp_device_instance->device_id); // advoid MU_P_OR_NULL double call
|
|
|
|
|
LogError("Device '%s' failed sending message disposition (amqp_device_send_message_disposition failed)", MU_P_OR_NULL(device_id));
|
|
|
|
|
result = IOTHUB_CLIENT_ERROR;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|