From: Sakthivel Samidurai Date: Tue, 20 Jan 2015 12:38:57 +0000 (-0300) Subject: Remove the magic number X-Git-Tag: 1.2.0+RC1~1855^2~270 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4a62e7413bd85837d0fab756c01be603ca31596b;p=platform%2Fupstream%2Fiotivity.git Remove the magic number Remove the magic number 4 in the CA branch code. Change-Id: I6fdc81e5a06a2ebdca5245bbf056f5a3d6f36ed4 Signed-off-by: Sakthivel Samidurai Reviewed-on: https://gerrit.iotivity.org/gerrit/162 Tested-by: jenkins-iotivity Reviewed-by: Sashi Penta Reviewed-by: Sudarshan Prasad --- diff --git a/resource/csdk/stack/src/ocobserve.c b/resource/csdk/stack/src/ocobserve.c index 2a6d9ffa7..2b3ea19f8 100644 --- a/resource/csdk/stack/src/ocobserve.c +++ b/resource/csdk/stack/src/ocobserve.c @@ -537,8 +537,7 @@ CreateObserveHeaderOption (CAHeaderOption_t **caHdrOpt, // TODO-CA: COAP_OPTION_OBSERVE is defined in CoAP header files which will be abstracted // from resource model. We have to define a new macro for this in the stack layer. tmpHdrOpt[0].optionID = COAP_OPTION_OBSERVE; - // Length is one byte - tmpHdrOpt[0].optionLength = 1; + tmpHdrOpt[0].optionLength = sizeof(uint32_t); tmpHdrOpt[0].optionData[0] = observeFlag; for (uint8_t i = 0; i < numOptions; i++) { diff --git a/resource/csdk/stack/src/ocserverrequest.c b/resource/csdk/stack/src/ocserverrequest.c index 9b6a5932b..493a67096 100644 --- a/resource/csdk/stack/src/ocserverrequest.c +++ b/resource/csdk/stack/src/ocserverrequest.c @@ -440,9 +440,9 @@ OCStackResult HandleSingleResponse(OCEntityHandlerResponse * ehResponse) { responseInfo.info.options[0].protocolID = CA_COAP_ID; responseInfo.info.options[0].optionID = COAP_OPTION_OBSERVE; - // TODO-CA Remove the magic number 4 - responseInfo.info.options[0].optionLength = 4; - memcpy(responseInfo.info.options[0].optionData, &(serverRequest->observationOption), 4); + responseInfo.info.options[0].optionLength = sizeof(uint32_t); + memcpy(responseInfo.info.options[0].optionData, + &(serverRequest->observationOption), sizeof(uint32_t)); // Point to the next header option before copying vender specific header options optionsPointer += 1; diff --git a/resource/csdk/stack/src/ocstack.c b/resource/csdk/stack/src/ocstack.c index 5db05bc95..d03bcebf5 100644 --- a/resource/csdk/stack/src/ocstack.c +++ b/resource/csdk/stack/src/ocstack.c @@ -588,11 +588,11 @@ void HandleCAResponses(const CARemoteEndpoint_t* endPoint, const CAResponseInfo_ if(responseInfo->info.numOptions > 0) { int start = 0; - //First option alwas with option ID COAP_OPTION_OBSERVE if it is availbale + //First option always with option ID is COAP_OPTION_OBSERVE if it is available. if(responseInfo->info.options[0].optionID == COAP_OPTION_OBSERVE) { memcpy (&(response.sequenceNumber), - &(responseInfo->info.options[0].optionData), 4); + &(responseInfo->info.options[0].optionData), sizeof(uint32_t)); response.numRcvdVendorSpecificHeaderOptions = responseInfo->info.numOptions - 1; start = 1; }