Fix query handling for /oic/res
authorHabib Virji <habib.virji@samsung.com>
Thu, 24 Nov 2016 12:30:48 +0000 (12:30 +0000)
committerPhil Coval <philippe.coval@osg.samsung.com>
Thu, 24 Nov 2016 18:09:05 +0000 (18:09 +0000)
There was a mix up when query was supplied, it was only working if the interfaceQuery passed too. With just rt supplied,
it was returning all the resource. This patch fixes up the issue.

Change-Id: I980f0dd73fafdadd3d1dabae5edf024ac256f95c
Signed-off-by: Habib Virji <habib.virji@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/14759
Reviewed-by: Mushfiqul Islam <i.mushfiq@samsung.com>
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Phil Coval <philippe.coval@osg.samsung.com>
resource/csdk/stack/src/ocresource.c

index ddd7dc4..53509ed 100755 (executable)
@@ -796,7 +796,6 @@ static OCStackResult addDiscoveryBaselineCommonProperties(OCDiscoveryPayload *di
     VERIFY_PARAM_NON_NULL(TAG, discPayload->uri, "Failed adding href to discovery payload.");
 
     OCGetPropertyValue(PAYLOAD_TYPE_DEVICE, "deviceName", (void **)&discPayload->name);
-    VERIFY_PARAM_NON_NULL(TAG, discPayload->name, "Failed adding name to discovery payload.");
 
     discPayload->type = (OCStringLL*)OICCalloc(1, sizeof(OCStringLL));
     VERIFY_PARAM_NON_NULL(TAG, discPayload->type, "Failed adding rt to discovery payload.");
@@ -855,7 +854,7 @@ static OCStackResult HandleVirtualResource (OCServerRequest *request, OCResource
         }
 
         bool baselineQuery = false;
-        if (interfaceQuery && 0 != strcmp(interfaceQuery, OC_RSRVD_INTERFACE_LL))
+        if (interfaceQuery && 0 == strcmp(interfaceQuery, OC_RSRVD_INTERFACE_DEFAULT))
         {
             baselineQuery = true;
         }
@@ -883,12 +882,14 @@ static OCStackResult HandleVirtualResource (OCServerRequest *request, OCResource
 #endif
             if (OC_STACK_NO_RESOURCE == discoveryResult)
             {
-                if ((!baselineQuery && (resource->resourceProperties & prop)) ||
-                    (baselineQuery && (includeThisResourceInResponse(resource, interfaceQuery,
-                                                                     resourceTypeQuery))))
+                // This case will handle when no resource type and it is oic.if.ll.
+                if (!resourceTypeQuery && !baselineQuery && (resource->resourceProperties & prop))
                 {
-                    discoveryResult = BuildVirtualResourceResponse(resource, discPayload,
-                        &request->devAddr);
+                    discoveryResult = BuildVirtualResourceResponse(resource, discPayload, &request->devAddr);
+                }
+                else if (includeThisResourceInResponse(resource, interfaceQuery, resourceTypeQuery))
+                {
+                    discoveryResult = BuildVirtualResourceResponse(resource, discPayload, &request->devAddr);
                 }
                 else
                 {