Modify CAGeneratePDUImpl to take the payload size as a parameter
authorThiago Macieira <thiago.macieira@intel.com>
Tue, 12 May 2015 07:23:14 +0000 (16:23 +0900)
committerErich Keane <erich.keane@intel.com>
Tue, 12 May 2015 16:54:34 +0000 (16:54 +0000)
This is required to send binary payloads, like CBOR is. It's also a good
idea so we don't have to do strlen all the time.

Change-Id: I66a35ce5f88941f29aa6ffff13dd68b7b06f7fe2
Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/966
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Erich Keane <erich.keane@intel.com>
resource/csdk/connectivity/inc/caprotocolmessage.h
resource/csdk/connectivity/src/caprotocolmessage.c

index fde84dd..76b4dd0 100644 (file)
@@ -84,7 +84,7 @@ CAResult_t CAGetResponseInfoFromPDU(const coap_pdu_t *pdu, CAResponseInfo_t *out
  * @return  generated pdu
  */
 coap_pdu_t *CAGeneratePDUImpl(code_t code, coap_list_t *options, const CAInfo_t info,
-                              const char *payload);
+                              const char *payload, size_t payloadSize);
 
 /**
  * @brief   parse the URI and creates the options
index ab9bbe4..c45dc02 100644 (file)
@@ -114,7 +114,7 @@ coap_pdu_t *CAGeneratePDU(const char *uri, uint32_t code, const CAInfo_t info)
     if (CA_MSG_RESET == info.type || (CA_EMPTY == code && CA_MSG_ACKNOWLEDGE == info.type))
     {
         OIC_LOG(DEBUG, TAG, "code is empty");
-        if (!(pdu = CAGeneratePDUImpl((code_t) code, NULL, info, NULL)))
+        if (!(pdu = CAGeneratePDUImpl((code_t) code, NULL, info, NULL, 0)))
         {
             OIC_LOG(ERROR, TAG, "pdu NULL");
             return NULL;
@@ -171,7 +171,7 @@ coap_pdu_t *CAGeneratePDU(const char *uri, uint32_t code, const CAInfo_t info)
             return NULL;
         }
 
-        pdu = CAGeneratePDUImpl((code_t) code, optlist, info, info.payload);
+        pdu = CAGeneratePDUImpl((code_t) code, optlist, info, info.payload, strlen(info.payload));
         if (NULL == pdu)
         {
             OIC_LOG(ERROR, TAG, "pdu NULL");
@@ -222,7 +222,7 @@ coap_pdu_t *CAParsePDU(const char *data, uint32_t length, uint32_t *outCode)
 }
 
 coap_pdu_t *CAGeneratePDUImpl(code_t code, coap_list_t *options, const CAInfo_t info,
-                              const char *payload)
+                              const char *payload, size_t payloadSize)
 {
     OIC_LOG(DEBUG, TAG, "IN");
 
@@ -281,9 +281,8 @@ coap_pdu_t *CAGeneratePDUImpl(code_t code, coap_list_t *options, const CAInfo_t
 
     if (NULL != payload)
     {
-        uint32_t len = strlen(payload);
         OIC_LOG_V(DEBUG, TAG, "add data, payload:%s", payload);
-        coap_add_data(pdu, len, (const unsigned char *) payload);
+        coap_add_data(pdu, payloadSize, (const unsigned char *) payload);
     }
 
     OIC_LOG(DEBUG, TAG, "OUT");