VERIFY_PARAM_NON_NULL(TAG, size, "size parameter is NULL");
OIC_LOG_V(INFO, TAG, "Converting payload of type %d", payload->type);
-
- out = (uint8_t *)OICCalloc(1, curSize);
- VERIFY_PARAM_NON_NULL(TAG, out, "Failed to allocate payload");
+ if (PAYLOAD_TYPE_SECURITY == payload->type)
+ {
+ size_t securityPayloadSize = ((OCSecurityPayload *)payload)->payloadSize;
+ if (securityPayloadSize > 0)
+ {
+ out = (uint8_t *)OICCalloc(1, ((OCSecurityPayload *)payload)->payloadSize);
+ VERIFY_PARAM_NON_NULL(TAG, out, "Failed to allocate security payload");
+ }
+ }
+ if (out == NULL)
+ {
+ out = (uint8_t *)OICCalloc(1, curSize);
+ VERIFY_PARAM_NON_NULL(TAG, out, "Failed to allocate payload");
+ }
err = OCConvertPayloadHelper(payload, out, &curSize);
ret = OC_STACK_NO_MEMORY;
*size = curSize;
*outPayload = out;
- OIC_LOG_V(DEBUG, TAG, "Payload Size: %zd Payload : %s \n", *size, *outPayload);
+ OIC_LOG_V(DEBUG, TAG, "Payload Size: %zd Payload : ", *size);
+ OIC_LOG_BUFFER(DEBUG, TAG, *outPayload, *size);
return OC_STACK_OK;
}
static int64_t OCConvertSecurityPayload(OCSecurityPayload* payload, uint8_t* outPayload,
size_t* size)
{
- if (*size < payload->payloadSize)
- {
- uint8_t *out2 = (uint8_t *)OICRealloc(outPayload, payload->payloadSize);
- if (!out2)
- {
- OICFree(outPayload);
- return CborErrorOutOfMemory;
- }
- outPayload = out2;
- }
-
memcpy(outPayload, payload->securityData1, payload->payloadSize);
*size = payload->payloadSize;
VERIFY_PARAM_NON_NULL(TAG, outPayload, "Conversion of outPayload failed");
VERIFY_PARAM_NON_NULL(TAG, payload, "Invalid cbor payload value");
- OIC_LOG_V(INFO, TAG, "CBOR Parsing size: %zu", payloadSize);
+ OIC_LOG_V(INFO, TAG, "CBOR Parsing size: %zu of Payload Type: %d, Payload:",
+ payloadSize, payloadType);
+ OIC_LOG_BUFFER(DEBUG, TAG, payload, payloadSize);
CborParser parser;
CborValue rootValue;