Remove the magic number
authorSakthivel Samidurai <sakthivel.samidurai@intel.com>
Tue, 20 Jan 2015 12:38:57 +0000 (09:38 -0300)
committerSudarshan Prasad <sudarshan.prasad@intel.com>
Tue, 20 Jan 2015 22:19:47 +0000 (22:19 +0000)
Remove the magic number 4 in the CA branch code.

Change-Id: I6fdc81e5a06a2ebdca5245bbf056f5a3d6f36ed4
Signed-off-by: Sakthivel Samidurai <sakthivel.samidurai@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/162
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Sashi Penta <sashi.kumar.penta@intel.com>
Reviewed-by: Sudarshan Prasad <sudarshan.prasad@intel.com>
resource/csdk/stack/src/ocobserve.c
resource/csdk/stack/src/ocserverrequest.c
resource/csdk/stack/src/ocstack.c

index 2a6d9ffa79d2772d288175f53f25f2b20da46e7c..2b3ea19f8d7e4bad6f8792ebca064767caa69ca6 100644 (file)
@@ -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++)
     {
index 9b6a5932bc36f0bf3246d15e14dcc74f8b56bc49..493a67096699ecd7d01ef95aec9ebb94f97ee99f 100644 (file)
@@ -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;
index 5db05bc9524958ea0a9e82510780c858522470d4..d03bcebf5f86487318be5d23aab87c18b0904480 100644 (file)
@@ -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;
             }