From 9e0332954d779d114d9efb407ba6280a6a0d7395 Mon Sep 17 00:00:00 2001 From: Dane Walton Date: Fri, 1 Oct 2021 09:21:26 -0700 Subject: [PATCH 1/2] add empty json with null payload --- iothub_client/src/iothub_client_core.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/iothub_client/src/iothub_client_core.c b/iothub_client/src/iothub_client_core.c index 8f4c0df433..f95c96cbd6 100644 --- a/iothub_client/src/iothub_client_core.c +++ b/iothub_client/src/iothub_client_core.c @@ -26,6 +26,7 @@ #define DO_WORK_FREQ_DEFAULT 1 #define DO_WORK_MAXIMUM_ALLOWED_FREQUENCY 100 +#define CLIENT_CORE_METHOD_EMPTY_PAYLOAD "{}" struct IOTHUB_QUEUE_CONTEXT_TAG; @@ -385,6 +386,13 @@ static int iothub_ll_device_method_callback(const char* method_name, const unsig USER_CALLBACK_INFO queue_cb_info; queue_cb_info.type = CALLBACK_TYPE_DEVICE_METHOD; + // A NULL payload was sent from the service. Use empty JSON to signal to the user no payload. + if(size == 0) + { + payload = (const unsigned char*) CLIENT_CORE_METHOD_EMPTY_PAYLOAD; + size = strlen(CLIENT_CORE_METHOD_EMPTY_PAYLOAD); + } + result = make_method_calback_queue_context(&queue_cb_info, method_name, payload, size, method_id, queue_context); if (result != 0) { From 7ad3ff73b32e2034f79aa05b36c9d0f899c6bdb9 Mon Sep 17 00:00:00 2001 From: Dane Walton Date: Fri, 1 Oct 2021 10:52:09 -0700 Subject: [PATCH 2/2] pr comments --- iothub_client/src/iothub_client_core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iothub_client/src/iothub_client_core.c b/iothub_client/src/iothub_client_core.c index f95c96cbd6..ad7ef1d331 100644 --- a/iothub_client/src/iothub_client_core.c +++ b/iothub_client/src/iothub_client_core.c @@ -387,10 +387,10 @@ static int iothub_ll_device_method_callback(const char* method_name, const unsig queue_cb_info.type = CALLBACK_TYPE_DEVICE_METHOD; // A NULL payload was sent from the service. Use empty JSON to signal to the user no payload. - if(size == 0) + if (size == 0) { payload = (const unsigned char*) CLIENT_CORE_METHOD_EMPTY_PAYLOAD; - size = strlen(CLIENT_CORE_METHOD_EMPTY_PAYLOAD); + size = sizeof(CLIENT_CORE_METHOD_EMPTY_PAYLOAD) - 1; } result = make_method_calback_queue_context(&queue_cb_info, method_name, payload, size, method_id, queue_context);