Fix GET ocresource response for /oic/d
authorHabib Virji <habib.virji@samsung.com>
Tue, 12 Jul 2016 11:11:12 +0000 (12:11 +0100)
committerHabib Virji <habib.virji@samsung.com>
Wed, 13 Jul 2016 09:21:30 +0000 (09:21 +0000)
If an application does not set oic.wk.d, set in savedDeviceInfo to get proper response for GET message.

Change-Id: I028b821ffe29b467d0ecc2add9a7a6ebfff5e72d
Signed-off-by: Habib Virji <habib.virji@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/9309
Reviewed-by: Phil Coval <philippe.coval@osg.samsung.com>
Reviewed-by: Ziran Sun <ziran.sun@samsung.com>
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Dwarkaprasad Dayama <dwarka.dayama@samsung.com>
Reviewed-by: Mushfiqul Islam <i.mushfiq@samsung.com>
resource/csdk/stack/src/ocresource.c

index cc25c77..fbd7bd6 100755 (executable)
@@ -1370,6 +1370,34 @@ static OCStackResult DeepCopyDeviceInfo(OCDeviceInfo info)
     if (info.types)
     {
         savedDeviceInfo.types = CloneOCStringLL(info.types);
+        OCStringLL *type = info.types;
+        bool found = false;
+        while (type)
+        {
+            if (type && type->value && 0 == strcmp(type->value, OC_RSRVD_RESOURCE_TYPE_DEVICE))
+            {
+                found = true;
+            }
+            type = type->next;
+        }
+        if (!found)
+        {
+            // Append the oic.wk.d at the start of rt link parameter value.
+            OCStringLL *dest = (OCStringLL*)OICCalloc (1, sizeof (OCStringLL));
+            if (!dest)
+            {
+                DeleteDeviceInfo();
+                return OC_STACK_NO_MEMORY;
+            }
+            dest->value = OICStrdup (OC_RSRVD_RESOURCE_TYPE_DEVICE);
+            if (!dest->value)
+            {
+                DeleteDeviceInfo();
+                return OC_STACK_NO_MEMORY;
+            }
+            dest->next = savedDeviceInfo.types;
+            savedDeviceInfo.types = dest;
+        }
         if(!savedDeviceInfo.types && info.types)
         {
             DeleteDeviceInfo();