From c7a3130ae7ec34ccde004c1bead5f0a1bb9cbb26 Mon Sep 17 00:00:00 2001 From: Sachin Agrawal Date: Thu, 9 Jul 2015 17:27:59 -0700 Subject: [PATCH] Updated Secure Sample for new resource discovery response Resource Discovery response was udpated to be compliance with OIC Specification. This change is to correctly parse the discovery response. Change-Id: I3c16f0ed827f5f993def01e7741c592b1ad1926b Signed-off-by: Sachin Agrawal Reviewed-on: https://gerrit.iotivity.org/gerrit/1614 Tested-by: jenkins-iotivity Reviewed-by: Mandeep Shetty Reviewed-by: Sakthivel Samidurai --- .../samples/linux/secure/occlientbasicops.cpp | 27 ++++++++++++++++------ 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/resource/csdk/stack/samples/linux/secure/occlientbasicops.cpp b/resource/csdk/stack/samples/linux/secure/occlientbasicops.cpp index a2097ce..32a423b 100644 --- a/resource/csdk/stack/samples/linux/secure/occlientbasicops.cpp +++ b/resource/csdk/stack/samples/linux/secure/occlientbasicops.cpp @@ -416,17 +416,32 @@ int parseClientResponse(OCClientResponse * clientResponse) } oc = cJSON_GetObjectItem(root,"oic"); - if (!oc) + if (!oc || oc->type != cJSON_Array) { + cJSON_Delete(root); return -1; } - if (oc->type == cJSON_Array) + cJSON * firstDevice = cJSON_GetArrayItem(oc, 0); + if (!firstDevice) { - int numRsrcs = cJSON_GetArraySize(oc); + cJSON_Delete(root); + return -1; + } + + cJSON * links = cJSON_GetObjectItem(firstDevice,"links"); + if (!links) + { + cJSON_Delete(root); + return -1; + } + + if (links->type == cJSON_Array) + { + int numRsrcs = cJSON_GetArraySize(links); for(int i = 0; i < numRsrcs; i++) { - cJSON * resource = cJSON_GetArrayItem(oc, i); + cJSON * resource = cJSON_GetArrayItem(links, i); if (cJSON_GetObjectItem(resource, "href")) { coapServerResource.assign(cJSON_GetObjectItem(resource, "href")->valuestring); @@ -437,10 +452,8 @@ int parseClientResponse(OCClientResponse * clientResponse) } OC_LOG_V(INFO, TAG, "Uri -- %s", coapServerResource.c_str()); - cJSON * prop = cJSON_GetObjectItem(resource,"prop"); - if (prop) { - cJSON * policy = cJSON_GetObjectItem(prop,"p"); + cJSON * policy = cJSON_GetObjectItem(resource,"p"); if (policy) { // If this is a secure resource, the info about the port at which the -- 2.7.4