From: Erich Keane Date: Mon, 16 Mar 2015 22:03:29 +0000 (-0700) Subject: Fixed InProcClientWrapper's option parameter to OCDoResource X-Git-Tag: 1.2.0+RC1~1855^2~107 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3fceb5300b094ec50ab264de910c4d177b622005;p=platform%2Fupstream%2Fiotivity.git 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 --- diff --git a/resource/include/InProcClientWrapper.h b/resource/include/InProcClientWrapper.h index bf94989..5d9ce54 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 2eb81fb..56c95c3 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; } }