From 3fceb5300b094ec50ab264de910c4d177b622005 Mon Sep 17 00:00:00 2001 From: Erich Keane Date: Mon, 16 Mar 2015 15:03:29 -0700 Subject: [PATCH] Fixed InProcClientWrapper's option parameter to OCDoResource InProcClientWrapper was calling OCDoResource with the option parameter set to a valid value despite the numOptions being 0. This commit ensures that it will send a nullptr in that event, preventing confusion during debugging in the future. Change-Id: Ided75e1c90a971ea205e9e04bf170a5144e8206d Signed-off-by: Erich Keane Reviewed-on: https://gerrit.iotivity.org/gerrit/485 Tested-by: jenkins-iotivity Reviewed-by: Sudarshan Prasad Reviewed-by: Sashi Penta --- resource/include/InProcClientWrapper.h | 4 +-- resource/src/InProcClientWrapper.cpp | 42 +++++++++++++++----------- 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/resource/include/InProcClientWrapper.h b/resource/include/InProcClientWrapper.h index bf9498924..5d9ce54bc 100644 --- a/resource/include/InProcClientWrapper.h +++ b/resource/include/InProcClientWrapper.h @@ -128,8 +128,8 @@ namespace OC void listeningFunc(); std::string assembleSetResourceUri(std::string uri, const QueryParamsMap& queryParams); std::string assembleSetResourcePayload(const OCRepresentation& attributes); - void assembleHeaderOptions(OCHeaderOption options[], - const HeaderOptions& headerOptions); + OCHeaderOption* assembleHeaderOptions(OCHeaderOption options[], + const HeaderOptions& headerOptions); std::thread m_listeningThread; bool m_threadRun; std::weak_ptr m_csdkLock; diff --git a/resource/src/InProcClientWrapper.cpp b/resource/src/InProcClientWrapper.cpp index 2eb81fb76..56c95c3ee 100644 --- a/resource/src/InProcClientWrapper.cpp +++ b/resource/src/InProcClientWrapper.cpp @@ -214,7 +214,7 @@ namespace OC nullptr, nullptr, connectivityType, static_cast(QoS), &cbdata, - NULL, 0); + nullptr, 0); } else { @@ -269,7 +269,7 @@ namespace OC nullptr, nullptr, connectivityType, static_cast(QoS), &cbdata, - NULL, 0); + nullptr, 0); } else { @@ -356,13 +356,12 @@ namespace OC std::lock_guard lock(*cLock); OCHeaderOption options[MAX_HEADER_OPTIONS]; - assembleHeaderOptions(options, headerOptions); - result = OCDoResource(nullptr, OC_REST_GET, os.str().c_str(), nullptr, nullptr, connectivityType, static_cast(QoS), &cbdata, - options, headerOptions.size()); + assembleHeaderOptions(options, headerOptions), + headerOptions.size()); } else { @@ -464,12 +463,13 @@ namespace OC std::lock_guard lock(*cLock); OCHeaderOption options[MAX_HEADER_OPTIONS]; - assembleHeaderOptions(options, headerOptions); result = OCDoResource(nullptr, OC_REST_POST, os.str().c_str(), nullptr, assembleSetResourcePayload(rep).c_str(), connectivityType, static_cast(QoS), - &cbdata, options, headerOptions.size()); + &cbdata, + assembleHeaderOptions(options, headerOptions), + headerOptions.size()); } else { @@ -507,13 +507,13 @@ namespace OC OCDoHandle handle; OCHeaderOption options[MAX_HEADER_OPTIONS]; - assembleHeaderOptions(options, headerOptions); result = OCDoResource(&handle, OC_REST_PUT, os.str().c_str(), nullptr, assembleSetResourcePayload(rep).c_str(), connectivityType, static_cast(QoS), &cbdata, - options, headerOptions.size()); + assembleHeaderOptions(options, headerOptions), + headerOptions.size()); } else { @@ -562,15 +562,15 @@ namespace OC { OCHeaderOption options[MAX_HEADER_OPTIONS]; - assembleHeaderOptions(options, headerOptions); - std::lock_guard lock(*cLock); result = OCDoResource(nullptr, OC_REST_DELETE, os.str().c_str(), nullptr, nullptr, connectivityType, static_cast(m_cfg.QoS), - &cbdata, options, headerOptions.size()); + &cbdata, + assembleHeaderOptions(options, headerOptions), + headerOptions.size()); } else { @@ -650,13 +650,13 @@ namespace OC std::lock_guard lock(*cLock); OCHeaderOption options[MAX_HEADER_OPTIONS]; - assembleHeaderOptions(options, headerOptions); result = OCDoResource(handle, method, os.str().c_str(), nullptr, nullptr, connectivityType, static_cast(QoS), &cbdata, - options, headerOptions.size()); + assembleHeaderOptions(options, headerOptions), + headerOptions.size()); } else { @@ -679,8 +679,9 @@ namespace OC std::lock_guard lock(*cLock); OCHeaderOption options[MAX_HEADER_OPTIONS]; - assembleHeaderOptions(options, headerOptions); - result = OCCancel(handle, static_cast(QoS), options, + result = OCCancel(handle, + static_cast(QoS), + assembleHeaderOptions(options, headerOptions), headerOptions.size()); } else @@ -780,11 +781,16 @@ namespace OC return OC_STACK_OK; } - void InProcClientWrapper::assembleHeaderOptions(OCHeaderOption options[], + OCHeaderOption* InProcClientWrapper::assembleHeaderOptions(OCHeaderOption options[], const HeaderOptions& headerOptions) { int i = 0; + if( headerOptions.size() == 0) + { + return nullptr; + } + for (auto it=headerOptions.begin(); it != headerOptions.end(); ++it) { options[i].protocolID = OC_COAP_ID; @@ -794,5 +800,7 @@ namespace OC (it->getOptionData()).length() + 1); i++; } + + return options; } } -- 2.34.1