Fix for multiple discovery paylod in response.
authorKIM JungYong <jyong2.kim@samsung.com>
Tue, 17 Jan 2017 05:21:45 +0000 (14:21 +0900)
committerUze Choi <uzchoi@samsung.com>
Thu, 19 Jan 2017 11:14:00 +0000 (11:14 +0000)
When consumer do discovery request to cloud,
cloud server can response on multiple device's result by one of response.
consumer service does not handle multiple discovery payload befour.

When applying this changes, consumer service can handle
multiple discovery payloads.

Change-Id: I516ac933daf435b436158ae4983f0ffedefe32c0
Signed-off-by: KIM JungYong <jyong2.kim@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/16469
Tested-by: jenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
service/notification/src/consumer/NSConsumerDiscovery.c

index baed182..5b6a070 100644 (file)
@@ -107,32 +107,38 @@ OCStackApplicationResult NSProviderDiscoverListener(
         return OC_STACK_DELETE_TRANSACTION;
     }
 
-    OCResourcePayload * resource = ((OCDiscoveryPayload *)clientResponse->payload)->resources;
-    NS_LOG_V(DEBUG, "Discovered resource uri : %s",
-                        resource->uri);
-    while (resource)
+    OCDiscoveryPayload * discoveryPayload = (OCDiscoveryPayload *)clientResponse->payload;
+
+    while (discoveryPayload)
     {
-        NS_VERIFY_NOT_NULL(resource->uri, OC_STACK_KEEP_TRANSACTION);
-        if (strstr(resource->uri, NS_RESOURCE_URI))
+        OCResourcePayload * resource = discoveryPayload->resources;
+        NS_LOG_V(DEBUG, "Discovered resource uri : %s", resource->uri);
+        while (resource)
         {
-            OCConnectivityType type = CT_DEFAULT;
-            if (clientResponse->addr->adapter == OC_ADAPTER_TCP)
+            NS_VERIFY_NOT_NULL(resource->uri, OC_STACK_KEEP_TRANSACTION);
+            if (strstr(resource->uri, NS_RESOURCE_URI))
             {
-                type = CT_ADAPTER_TCP;
+                NS_LOG_V(DEBUG, "Request GET to provider : %s", resource->uri);
+                OCConnectivityType type = CT_DEFAULT;
+                if (clientResponse->addr->adapter == OC_ADAPTER_TCP)
+                {
+                    type = CT_ADAPTER_TCP;
+                }
+
+                OCDevAddr * addr = clientResponse->addr;
+                if (resource->secure)
+                {
+                    addr->port = resource->port;
+                    addr->flags |= OC_FLAG_SECURE;
+                }
+
+                NSInvokeRequest(NULL, OC_REST_GET, addr,
+                        resource->uri, NULL, NSIntrospectProvider, ctx,
+                        NULL, type);
             }
-
-            OCDevAddr * addr = clientResponse->addr;
-            if (resource->secure)
-            {
-                addr->port = resource->port;
-                addr->flags |= OC_FLAG_SECURE;
-            }
-
-            NSInvokeRequest(NULL, OC_REST_GET, addr,
-                    resource->uri, NULL, NSIntrospectProvider, ctx,
-                    NULL, type);
+            resource = resource->next;
         }
-        resource = resource->next;
+        discoveryPayload = discoveryPayload->next;
     }
 
     return OC_STACK_KEEP_TRANSACTION;