From 3bdc51bd4129d15d4176f193b7ad47999e66ff25 Mon Sep 17 00:00:00 2001 From: Habib Virji Date: Thu, 24 Nov 2016 12:30:48 +0000 Subject: [PATCH] Fix query handling for /oic/res 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 Reviewed-on: https://gerrit.iotivity.org/gerrit/14759 Reviewed-by: Mushfiqul Islam Tested-by: jenkins-iotivity Reviewed-by: Phil Coval --- resource/csdk/stack/src/ocresource.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/resource/csdk/stack/src/ocresource.c b/resource/csdk/stack/src/ocresource.c index ddd7dc4..53509ed 100755 --- a/resource/csdk/stack/src/ocresource.c +++ b/resource/csdk/stack/src/ocresource.c @@ -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 { -- 2.7.4