[IOT-914] Change format of the device id as text string
authorHabib Virji <habib.virji@samsung.com>
Thu, 10 Mar 2016 17:59:51 +0000 (17:59 +0000)
committerHabib Virji <habib.virji@samsung.com>
Fri, 11 Mar 2016 19:05:35 +0000 (19:05 +0000)
DI field was being sent as a byte string over ther wire.

This patch update it to be sent as a string.

ocpayloadparse.c can handle both byte string and text string.
But ocpayloadconvert.c will be sending in text string.

Jira Issue: IOT-914
Signed-off-by: Habib Virji <habib.virji@samsung.com>
Change-Id: I049bf4cff5f2b390e589eb5cf55966e8034838b1
Reviewed-on: https://gerrit.iotivity.org/gerrit/5691
Reviewed-by: Dwarkaprasad Dayama <dwarka.dayama@samsung.com>
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
12 files changed:
resource/csdk/stack/include/internal/ocstackinternal.h
resource/csdk/stack/include/ocpayload.h
resource/csdk/stack/include/octypes.h
resource/csdk/stack/include/payload_logging.h
resource/csdk/stack/src/ocpayload.c
resource/csdk/stack/src/ocpayloadconvert.c
resource/csdk/stack/src/ocpayloadparse.c
resource/csdk/stack/src/ocresource.c
resource/csdk/stack/src/ocstack.c
resource/include/OCSerialization.h
resource/src/OCRepresentation.cpp
resource/unittests/OCRepresentationEncodingTest.cpp

index 3dfc8ce..bef3e98 100644 (file)
@@ -266,19 +266,6 @@ OCStackResult BindResourceTypeToResource(OCResource* resource,
 OCStackResult CAResultToOCResult(CAResult_t caResult);
 
 /**
- * Get a byte representation of the server instance ID.
- * The memory is managed internal to this function, so freeing it externally will
- * result in a runtime error.
- *
- * Note: This will NOT seed the RNG, so it must be called after the RNG is seeded.
- * This is done automatically during the OCInit process,
- * so ensure that this call is done after that.
- *
- * @return A uint8_t representation the server instance ID.
- */
-const OicUuid_t* OCGetServerInstanceID(void);
-
-/**
  * Map OCQualityOfService to CAMessageType.
  *
  * @param qos Input qos.
index 5b68fa4..789d5d7 100755 (executable)
@@ -234,7 +234,7 @@ void OCDiscoveryResourceDestroy(OCResourcePayload* payload);
 void OCDiscoveryPayloadDestroy(OCDiscoveryPayload* payload);
 
 // Device Payload
-OCDevicePayload* OCDevicePayloadCreate(const uint8_t* sid, const char* dname,
+OCDevicePayload* OCDevicePayloadCreate(const char* sid, const char* dname,
         const char* specVer, const char* dmVer);
 void OCDevicePayloadDestroy(OCDevicePayload* payload);
 
index 8ccb3a9..7445b44 100644 (file)
@@ -1136,7 +1136,7 @@ typedef struct
 {
     OCPayload base;
 
-    uint8_t* sid;
+    char *sid;
 
     /** A special case for handling RD address. */
     char* baseURI;
@@ -1174,7 +1174,7 @@ typedef struct
 typedef struct
 {
     OCPayload base;
-    uint8_t* sid;
+    char* sid;
     char* deviceName;
     char* specVersion;
     char* dataModelVersion;
index 6a6bb24..f94500a 100644 (file)
@@ -174,8 +174,7 @@ static inline void OCPayloadLogDiscovery(LogLevel level, OCDiscoveryPayload* pay
         OIC_LOG(level, PL_TAG, "\tNO Resources");
         return;
     }
-    OIC_LOG(level, PL_TAG, "\tSID:");
-    OIC_LOG_BUFFER(level, PL_TAG, payload->sid, UUID_SIZE);
+    OIC_LOG_V(level, PL_TAG, "\tSID: %s", payload->sid);
     OCResourcePayload* res = payload->resources;
 
     while(res)
@@ -209,8 +208,7 @@ static inline void OCPayloadLogDiscovery(LogLevel level, OCDiscoveryPayload* pay
 static inline void OCPayloadLogDevice(LogLevel level, OCDevicePayload* payload)
 {
     OIC_LOG(level, PL_TAG, "Payload Type: Device");
-    OIC_LOG(level, PL_TAG, "\tSID:");
-    OIC_LOG_BUFFER(level, PL_TAG, payload->sid, UUID_SIZE);
+    OIC_LOG_V(level, PL_TAG, "\tSID:%s", payload->sid);
     OIC_LOG_V(level, PL_TAG, "\tDevice Name:%s", payload->deviceName);
     OIC_LOG_V(level, PL_TAG, "\tSpec Version%s", payload->specVersion);
     OIC_LOG_V(level, PL_TAG, "\tData Model Version:%s", payload->dataModelVersion);
index 67b70e8..8719abb 100755 (executable)
@@ -1526,7 +1526,7 @@ void OCDiscoveryPayloadDestroy(OCDiscoveryPayload* payload)
     OICFree(payload);
 }
 
-OCDevicePayload* OCDevicePayloadCreate(const uint8_t* sid, const char* dname,
+OCDevicePayload* OCDevicePayloadCreate(const char* sid, const char* dname,
         const char* specVer, const char* dmVer)
 {
 
@@ -1538,15 +1538,10 @@ OCDevicePayload* OCDevicePayloadCreate(const uint8_t* sid, const char* dname,
     }
 
     payload->base.type = PAYLOAD_TYPE_DEVICE;
-
-    if (sid)
+    payload->sid = OICStrdup(sid);
+    if (sid && !payload->sid)
     {
-        payload->sid = (uint8_t*)OICMalloc(UUID_SIZE);
-        if (!payload->sid)
-        {
-            goto exit;
-        }
-        memcpy(payload->sid, sid, UUID_SIZE);
+        goto exit;
     }
 
     payload->deviceName = OICStrdup(dname);
index 18459ab..a03f9e6 100644 (file)
@@ -269,10 +269,8 @@ static int64_t OCConvertDiscoveryPayload(OCDiscoveryPayload *payload, uint8_t *o
         VERIFY_CBOR_SUCCESS(TAG, err, "Failed creating discovery map");
 
         // Insert Device ID into the root map
-        err |= cbor_encode_text_string(&rootMap, OC_RSRVD_DEVICE_ID, sizeof(OC_RSRVD_DEVICE_ID) - 1);
-        VERIFY_CBOR_SUCCESS(TAG, err, "Failed setting tag device id");
-        err |= cbor_encode_byte_string(&rootMap, payload->sid, UUID_SIZE);
-        VERIFY_CBOR_SUCCESS(TAG, err, "Failed setting value of device id");
+        err |= AddTextStringToMap(&rootMap, OC_RSRVD_DEVICE_ID, sizeof(OC_RSRVD_DEVICE_ID) - 1, payload->sid);
+        VERIFY_CBOR_SUCCESS(TAG, err, "Failed setting device id");
 
         // Insert baseURI if present
         err |= ConditionalAddTextStringToMap(&rootMap, OC_RSRVD_BASE_URI,
@@ -392,10 +390,8 @@ static int64_t OCConvertDevicePayload(OCDevicePayload *payload, uint8_t *outPayl
     VERIFY_CBOR_SUCCESS(TAG, err, "Failed creating device map");
 
     // Device ID
-    err |= cbor_encode_text_string(&repMap, OC_RSRVD_DEVICE_ID, sizeof(OC_RSRVD_DEVICE_ID) - 1);
-    VERIFY_CBOR_SUCCESS(TAG, err, "Failed adding device id tag");
-    err |= cbor_encode_byte_string(&repMap, payload->sid, UUID_SIZE);
-    VERIFY_CBOR_SUCCESS(TAG, err, "Failed adding data device id");
+    err |= AddTextStringToMap(&repMap, OC_RSRVD_DEVICE_ID, sizeof(OC_RSRVD_DEVICE_ID) - 1 , payload->sid);
+    VERIFY_CBOR_SUCCESS(TAG, err, "Failed adding device id");
 
     // Device Name
     err |= ConditionalAddTextStringToMap(&repMap, OC_RSRVD_DEVICE_NAME,
index 8a64a2c..ba6bf5b 100755 (executable)
@@ -220,9 +220,18 @@ static OCStackResult OCParseDiscoveryPayload(OCPayload **outPayload, CborValue *
     CborValue curVal;
     err = cbor_value_map_find_value(&rootMap, OC_RSRVD_DEVICE_ID, &curVal);
     VERIFY_CBOR_SUCCESS(TAG, err, "to find device id tag");
+    if (cbor_value_is_valid(&curVal))
     {
-        err = cbor_value_dup_byte_string(&curVal, &(out->sid), &len, NULL);
-        VERIFY_CBOR_SUCCESS(TAG, err, "to copy device id value");
+        if (cbor_value_is_byte_string(&curVal))
+        {
+            err = cbor_value_dup_byte_string(&curVal, (uint8_t **)&(out->sid), &len, NULL);
+            VERIFY_CBOR_SUCCESS(TAG, err, "to copy device id value");
+        }
+        else if (cbor_value_is_text_string(&curVal))
+        {
+            err = cbor_value_dup_text_string(&curVal, &(out->sid), &len, NULL);
+            VERIFY_CBOR_SUCCESS(TAG, err, "to copy device id value");
+        }
     }
 
     // BaseURI - Not a mandatory field
@@ -331,8 +340,16 @@ static OCStackResult OCParseDevicePayload(OCPayload **outPayload, CborValue *roo
         err = cbor_value_map_find_value(rootValue, OC_RSRVD_DEVICE_ID, &curVal);
         if (cbor_value_is_valid(&curVal))
         {
-            err = cbor_value_dup_byte_string(&curVal, &out->sid, &len, NULL);
-            VERIFY_CBOR_SUCCESS(TAG, err, "to find device id in device payload");
+            if (cbor_value_is_byte_string(&curVal))
+            {
+                err = cbor_value_dup_byte_string(&curVal, (uint8_t **)&out->sid, &len, NULL);
+                VERIFY_CBOR_SUCCESS(TAG, err, "to find device id in device payload");
+            }
+            else if (cbor_value_is_text_string(&curVal))
+            {
+                err = cbor_value_dup_text_string(&curVal, &out->sid, &len, NULL);
+                VERIFY_CBOR_SUCCESS(TAG, err, "to find device id in device payload");
+            }
         }
         // Device Name
         err = cbor_value_map_find_value(rootValue, OC_RSRVD_DEVICE_NAME, &curVal);
index adef7db..f4d0698 100755 (executable)
@@ -681,12 +681,13 @@ static OCStackResult HandleVirtualResource (OCServerRequest *request, OCResource
 
         if (discoveryResult == OC_STACK_OK)
         {
-            payload = (OCPayload*)OCDiscoveryPayloadCreate();
+            payload = (OCPayload *)OCDiscoveryPayloadCreate();
 
             if(payload)
             {
-                ((OCDiscoveryPayload*)payload)->sid = (uint8_t*)OICCalloc(1, UUID_SIZE);
-                memcpy(((OCDiscoveryPayload*)payload)->sid, OCGetServerInstanceID(), UUID_SIZE);
+                ((OCDiscoveryPayload*)payload)->sid = (char *)OICCalloc(1, UUID_STRING_SIZE);
+                VERIFY_NON_NULL(((OCDiscoveryPayload*)payload)->sid, ERROR, OC_STACK_NO_MEMORY);
+                memcpy(((OCDiscoveryPayload*)payload)->sid, OCGetServerInstanceIDString(), UUID_STRING_SIZE);
 
                 bool foundResourceAtRD = false;
                 for(;resource && discoveryResult == OC_STACK_OK; resource = resource->next)
@@ -737,14 +738,14 @@ static OCStackResult HandleVirtualResource (OCServerRequest *request, OCResource
     }
     else if (virtualUriInRequest == OC_DEVICE_URI)
     {
-        const OicUuid_t* deviceId = OCGetServerInstanceID();
+        const char* deviceId = OCGetServerInstanceIDString();
         if (!deviceId)
         {
             discoveryResult = OC_STACK_ERROR;
         }
         else
         {
-            payload = (OCPayload*) OCDevicePayloadCreate((const uint8_t*) &deviceId->id, savedDeviceInfo.deviceName,
+            payload = (OCPayload*) OCDevicePayloadCreate(deviceId, savedDeviceInfo.deviceName,
                     OC_SPEC_VERSION, OC_DATA_MODEL_VERSION);
             if (!payload)
             {
@@ -1235,7 +1236,7 @@ OCStackResult SaveDeviceInfo(OCDeviceInfo info)
 
     VERIFY_SUCCESS(res, OC_STACK_OK);
 
-    if(OCGetServerInstanceID() == NULL)
+    if (OCGetServerInstanceIDString() == NULL)
     {
         OIC_LOG(INFO, TAG, "Device ID generation failed");
         res =  OC_STACK_ERROR;
index dca4363..65aaa22 100644 (file)
@@ -4420,7 +4420,7 @@ OCStackResult getQueryFromUri(const char * uri, char** query, char ** uriWithout
         return OC_STACK_NO_MEMORY;
 }
 
-const OicUuid_t* OCGetServerInstanceID(void)
+static const OicUuid_t* OCGetServerInstanceID(void)
 {
     static bool generated = false;
     static OicUuid_t sid;
@@ -4429,7 +4429,7 @@ const OicUuid_t* OCGetServerInstanceID(void)
         return &sid;
     }
 
-    if (GetDoxmDeviceID(&sid) != OC_STACK_OK)
+    if (RAND_UUID_OK != OCGenerateUuid(sid.id))
     {
         OIC_LOG(FATAL, TAG, "Generate UUID for Server Instance failed!");
         return NULL;
@@ -4448,8 +4448,7 @@ const char* OCGetServerInstanceIDString(void)
         return sidStr;
     }
 
-    const OicUuid_t* sid = OCGetServerInstanceID();
-
+    const OicUuid_t *sid = OCGetServerInstanceID();
     if(OCConvertUuidToString(sid->id, sidStr) != RAND_UUID_OK)
     {
         OIC_LOG(FATAL, TAG, "Generate UUID String for Server Instance failed!");
index be044bf..c9526f1 100644 (file)
@@ -49,12 +49,6 @@ namespace OC
                 {
                     while(res)
                     {
-                        char uuidString[UUID_STRING_SIZE];
-                        if(OCConvertUuidToString(payload->sid, uuidString) != RAND_UUID_OK)
-                        {
-                            uuidString[0]= '\0';
-                        }
-
                         if (res->secure)
                         {
                             m_devAddr.flags =
@@ -73,7 +67,7 @@ namespace OC
                             m_resources.push_back(std::shared_ptr<OC::OCResource>(
                                         new OC::OCResource(m_clientWrapper, rdPubAddr,
                                             std::string(res->uri),
-                                            std::string((char*)uuidString),
+                                            std::string(payload->sid),
                                             (res->bitmap & OC_OBSERVABLE) == OC_OBSERVABLE,
                                             StringLLToVector(res->types),
                                             StringLLToVector(res->interfaces)
@@ -84,7 +78,7 @@ namespace OC
                             m_resources.push_back(std::shared_ptr<OC::OCResource>(
                                     new OC::OCResource(m_clientWrapper, m_devAddr,
                                         std::string(res->uri),
-                                        std::string(uuidString),
+                                        std::string(payload->sid),
                                         (res->bitmap & OC_OBSERVABLE) == OC_OBSERVABLE,
                                         StringLLToVector(res->types),
                                         StringLLToVector(res->interfaces)
index 0de857c..051c0cc 100644 (file)
@@ -73,15 +73,9 @@ namespace OC
         }
 
         OCRepresentation rep;
-        char uuidString[UUID_STRING_SIZE];
-        if (payload->sid && RAND_UUID_OK == OCConvertUuidToString(payload->sid, uuidString))
-        {
-            rep[OC_RSRVD_DEVICE_ID] = std::string(uuidString);
-        }
-        else
-        {
-            rep[OC_RSRVD_DEVICE_ID] = std::string();
-        }
+        rep[OC_RSRVD_DEVICE_ID] = (payload->sid) ?
+            std::string(payload->sid) :
+            std::string();
         rep[OC_RSRVD_DEVICE_NAME] = payload->deviceName ?
             std::string(payload->deviceName) :
             std::string();
index 8df8d0f..e3e50ee 100644 (file)
@@ -22,6 +22,7 @@
 #include <OCApi.h>
 #include <OCRepresentation.h>
 #include <octypes.h>
+#include <ocstack.h>
 #include <ocpayload.h>
 #include <ocpayloadcbor.h>
 #include <oic_malloc.h>
@@ -48,7 +49,7 @@ namespace OC
 // CBOR->OCPayload and OCPayload->OCRepresentation conversions
 namespace OCRepresentationEncodingTest
 {
-    static const uint8_t sid1[] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16};
+    static const char *sid1 = OCGetServerInstanceIDString();
     static const char devicename1[] = "device name";
     static const char specver1[] = "spec version";
     static const char dmver1[] = "data model version";
@@ -60,17 +61,12 @@ namespace OCRepresentationEncodingTest
                 devicename1,
                 specver1,
                 dmver1);
-
+        EXPECT_STREQ(sid1, device->sid);
         EXPECT_STREQ(devicename1, device->deviceName);
         EXPECT_STREQ(specver1, device->specVersion);
         EXPECT_STREQ(dmver1, device->dataModelVersion);
         EXPECT_EQ(PAYLOAD_TYPE_DEVICE, ((OCPayload*)device)->type);
 
-        for (uint8_t i = 1; i <= sizeof(sid1); ++i)
-        {
-            EXPECT_EQ(i, sid1[i - 1]);
-        }
-
         uint8_t* cborData;
         size_t cborSize;
         OCPayload* parsedDevice;
@@ -79,6 +75,7 @@ namespace OCRepresentationEncodingTest
                     cborData, cborSize));
         OICFree(cborData);
 
+        EXPECT_STREQ(device->sid, ((OCDevicePayload*)parsedDevice)->sid);
         EXPECT_STREQ(device->deviceName, ((OCDevicePayload*)parsedDevice)->deviceName);
         EXPECT_STREQ(device->specVersion, ((OCDevicePayload*)parsedDevice)->specVersion);
         EXPECT_STREQ(device->dataModelVersion, ((OCDevicePayload*)parsedDevice)->dataModelVersion);
@@ -90,6 +87,7 @@ namespace OCRepresentationEncodingTest
         mc.setPayload(parsedDevice);
         EXPECT_EQ(1u, mc.representations().size());
         const OC::OCRepresentation& r = mc.representations()[0];
+        EXPECT_STREQ(sid1, r.getValue<std::string>(OC_RSRVD_DEVICE_ID).c_str());
         EXPECT_STREQ(devicename1, r.getValue<std::string>(OC_RSRVD_DEVICE_NAME).c_str());
         EXPECT_STREQ(specver1, r.getValue<std::string>(OC_RSRVD_SPEC_VERSION).c_str());
         EXPECT_STREQ(dmver1, r.getValue<std::string>(OC_RSRVD_DATA_MODEL_VERSION).c_str());
@@ -680,7 +678,7 @@ namespace OCRepresentationEncodingTest
     {
         OCDiscoveryPayload* payload = OCDiscoveryPayloadCreate();
         OCResourcePayload* resource = (OCResourcePayload*)OICCalloc(1, sizeof(OCResourcePayload));
-        payload->sid = (uint8_t*)OICMalloc(16);
+        payload->sid = OICStrdup(sid1);
         payload->resources = resource;
 
         EXPECT_TRUE(OCResourcePayloadAddStringLL(&resource->types, "rt.singleitem"));
@@ -699,6 +697,7 @@ namespace OCRepresentationEncodingTest
         EXPECT_EQ(1u, OCDiscoveryPayloadGetResourceCount((OCDiscoveryPayload*)cparsed));
         OCResourcePayload* parsedResource = ((OCDiscoveryPayload*)cparsed)->resources;
 
+        EXPECT_STREQ(sid1, ((OCDiscoveryPayload*)cparsed)->sid);
         EXPECT_EQ(NULL, parsedResource->next);
         EXPECT_STREQ("rt.singleitem", parsedResource->types->value);
         EXPECT_EQ(NULL, parsedResource->types->next);
@@ -713,7 +712,7 @@ namespace OCRepresentationEncodingTest
     TEST(DiscoveryRTandIF, SingleItemFrontTrim)
     {
         OCDiscoveryPayload* payload = OCDiscoveryPayloadCreate();
-        payload->sid = (uint8_t*)OICMalloc(16);
+        payload->sid = OICStrdup(sid1);
         OCResourcePayload* resource = (OCResourcePayload*)OICCalloc(1, sizeof(OCResourcePayload));
         payload->resources = resource;
 
@@ -733,7 +732,7 @@ namespace OCRepresentationEncodingTest
         OCResourcePayload* parsedResource = ((OCDiscoveryPayload*)cparsed)->resources;
 
         EXPECT_EQ(NULL, parsedResource->next);
-
+        EXPECT_STREQ(sid1, ((OCDiscoveryPayload*)cparsed)->sid);
         EXPECT_EQ(NULL, parsedResource->types->next);
         EXPECT_STREQ("rt.singleitem", parsedResource->types->value);
         EXPECT_EQ(NULL, parsedResource->interfaces->next);
@@ -747,7 +746,7 @@ namespace OCRepresentationEncodingTest
     TEST(DiscoveryRTandIF, SingleItemBackTrim)
     {
         OCDiscoveryPayload* payload = OCDiscoveryPayloadCreate();
-        payload->sid = (uint8_t*)OICMalloc(16);
+        payload->sid = OICStrdup(sid1);
         OCResourcePayload* resource = (OCResourcePayload*)OICCalloc(1, sizeof(OCResourcePayload));
         payload->resources = resource;
 
@@ -767,7 +766,7 @@ namespace OCRepresentationEncodingTest
         OCResourcePayload* parsedResource = ((OCDiscoveryPayload*)cparsed)->resources;
 
         EXPECT_EQ(NULL, parsedResource->next);
-
+        EXPECT_STREQ(sid1, ((OCDiscoveryPayload*)cparsed)->sid);
         EXPECT_EQ(NULL, parsedResource->types->next);
         EXPECT_STREQ("rt.singleitem", parsedResource->types->value);
         EXPECT_EQ(NULL, parsedResource->interfaces->next);
@@ -780,7 +779,7 @@ namespace OCRepresentationEncodingTest
     TEST(DiscoveryRTandIF, SingleItemBothTrim)
     {
         OCDiscoveryPayload* payload = OCDiscoveryPayloadCreate();
-        payload->sid = (uint8_t*)OICMalloc(16);
+        payload->sid = OICStrdup(sid1);
         OCResourcePayload* resource = (OCResourcePayload*)OICCalloc(1, sizeof(OCResourcePayload));
         payload->resources = resource;
 
@@ -800,7 +799,7 @@ namespace OCRepresentationEncodingTest
         OCResourcePayload* parsedResource = ((OCDiscoveryPayload*)cparsed)->resources;
 
         EXPECT_EQ(NULL, parsedResource->next);
-
+        EXPECT_STREQ(sid1, ((OCDiscoveryPayload*)cparsed)->sid);
         EXPECT_EQ(NULL, parsedResource->types->next);
         EXPECT_STREQ("rt.singleitem", parsedResource->types->value);
         EXPECT_EQ(NULL, parsedResource->interfaces->next);
@@ -813,7 +812,7 @@ namespace OCRepresentationEncodingTest
     TEST(DiscoveryRTandIF, MultiItemsNormal)
     {
         OCDiscoveryPayload* payload = OCDiscoveryPayloadCreate();
-        payload->sid = (uint8_t*)OICMalloc(16);
+        payload->sid = OICStrdup(sid1);
         OCResourcePayload* resource = (OCResourcePayload*)OICCalloc(1, sizeof(OCResourcePayload));
         payload->resources = resource;
 
@@ -835,7 +834,7 @@ namespace OCRepresentationEncodingTest
         OCResourcePayload* parsedResource = ((OCDiscoveryPayload*)cparsed)->resources;
 
         EXPECT_EQ(NULL, parsedResource->next);
-
+        EXPECT_STREQ(sid1, ((OCDiscoveryPayload*)cparsed)->sid);
         EXPECT_EQ(NULL, parsedResource->types->next->next);
         EXPECT_STREQ("rt.firstitem", parsedResource->types->value);
         EXPECT_STREQ("rt.seconditem", parsedResource->types->next->value);
@@ -850,7 +849,7 @@ namespace OCRepresentationEncodingTest
     TEST(DiscoveryRTandIF, MultiItemExtraLeadSpaces)
     {
         OCDiscoveryPayload* payload = OCDiscoveryPayloadCreate();
-        payload->sid = (uint8_t*)OICMalloc(16);
+        payload->sid = OICStrdup(sid1);
         OCResourcePayload* resource = (OCResourcePayload*)OICCalloc(1, sizeof(OCResourcePayload));
         payload->resources = resource;
 
@@ -872,7 +871,7 @@ namespace OCRepresentationEncodingTest
         OCResourcePayload* parsedResource = ((OCDiscoveryPayload*)cparsed)->resources;
 
         EXPECT_EQ(NULL, parsedResource->next);
-
+        EXPECT_STREQ(sid1, ((OCDiscoveryPayload*)cparsed)->sid);
         EXPECT_EQ(NULL, parsedResource->types->next->next);
         EXPECT_STREQ("rt.firstitem", parsedResource->types->value);
         EXPECT_STREQ("rt.seconditem", parsedResource->types->next->value);
@@ -887,7 +886,7 @@ namespace OCRepresentationEncodingTest
     TEST(DiscoveryRTandIF, MultiItemExtraTrailSpaces)
     {
         OCDiscoveryPayload* payload = OCDiscoveryPayloadCreate();
-        payload->sid = (uint8_t*)OICMalloc(16);
+        payload->sid = OICStrdup(sid1);
         OCResourcePayload* resource = (OCResourcePayload*)OICCalloc(1, sizeof(OCResourcePayload));
         payload->resources = resource;
 
@@ -909,7 +908,7 @@ namespace OCRepresentationEncodingTest
         OCResourcePayload* parsedResource = ((OCDiscoveryPayload*)cparsed)->resources;
 
         EXPECT_EQ(NULL, parsedResource->next);
-
+        EXPECT_STREQ(sid1, ((OCDiscoveryPayload*)cparsed)->sid);
         EXPECT_EQ(NULL, parsedResource->types->next->next);
         EXPECT_STREQ("rt.firstitem", parsedResource->types->value);
         EXPECT_STREQ("rt.seconditem", parsedResource->types->next->value);
@@ -924,7 +923,7 @@ namespace OCRepresentationEncodingTest
     TEST(DiscoveryRTandIF, MultiItemBothSpaces)
     {
         OCDiscoveryPayload* payload = OCDiscoveryPayloadCreate();
-        payload->sid = (uint8_t*)OICMalloc(16);
+        payload->sid = OICStrdup(sid1);
         OCResourcePayload* resource = (OCResourcePayload*)OICCalloc(1, sizeof(OCResourcePayload));
         payload->resources = resource;
 
@@ -946,7 +945,7 @@ namespace OCRepresentationEncodingTest
         OCResourcePayload* parsedResource = ((OCDiscoveryPayload*)cparsed)->resources;
 
         EXPECT_EQ(NULL, parsedResource->next);
-
+        EXPECT_STREQ(sid1, ((OCDiscoveryPayload*)cparsed)->sid);
         EXPECT_EQ(NULL, parsedResource->types->next->next);
         EXPECT_STREQ("rt.firstitem", parsedResource->types->value);
         EXPECT_STREQ("rt.seconditem", parsedResource->types->next->value);