Skip to content

Commit

Permalink
Fix discovery responses from multi-device servers
Browse files Browse the repository at this point in the history
Signed-off-by: Kishen Maloor <kishen.maloor@intel.com>
  • Loading branch information
kmaloor committed Jan 8, 2020
1 parent f914258 commit 3af1669
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions api/oc_discovery.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

static bool
filter_resource(oc_resource_t *resource, oc_request_t *request,
const char *anchor, CborEncoder *links)
const char *anchor, CborEncoder *links, size_t device_index)
{
if (!oc_filter_resource_by_rt(resource, request)) {
return false;
Expand Down Expand Up @@ -72,7 +72,7 @@ filter_resource(oc_resource_t *resource, oc_request_t *request,

// eps
oc_rep_set_array(link, eps);
oc_endpoint_t *eps = oc_connectivity_get_endpoints(resource->device);
oc_endpoint_t *eps = oc_connectivity_get_endpoints(device_index);
while (eps != NULL) {
/* If this resource has been explicitly tagged as SECURE on the
* application layer, skip all coap:// endpoints, and only include
Expand Down Expand Up @@ -119,72 +119,72 @@ process_device_resources(CborEncoder *links, oc_request_t *request,
oc_concat_strings(&anchor, "ocf://", uuid);

if (filter_resource(oc_core_get_resource_by_index(OCF_P, 0), request,
oc_string(anchor), links))
oc_string(anchor), links, device_index))
matches++;

if (filter_resource(oc_core_get_resource_by_index(OCF_D, device_index),
request, oc_string(anchor), links))
request, oc_string(anchor), links, device_index))
matches++;

if (filter_resource(
oc_core_get_resource_by_index(OCF_INTROSPECTION_WK, device_index),
request, oc_string(anchor), links))
request, oc_string(anchor), links, device_index))
matches++;

if (oc_get_con_res_announced() &&
filter_resource(oc_core_get_resource_by_index(OCF_CON, device_index),
request, oc_string(anchor), links))
request, oc_string(anchor), links, device_index))
matches++;
#ifdef OC_MNT
if (filter_resource(oc_core_get_resource_by_index(OCF_MNT, device_index),
request, oc_string(anchor), links))
request, oc_string(anchor), links, device_index))
matches++;
#endif /* OC_MNT */
#ifdef OC_SOFTWARE_UPDATE
if (filter_resource(
oc_core_get_resource_by_index(OCF_SW_UPDATE, device_index), request,
oc_string(anchor), links))
oc_string(anchor), links, device_index))
matches++;
#endif /* OC_SOFTWARE_UPDATE */

#ifdef OC_SECURITY
if (filter_resource(oc_core_get_resource_by_index(OCF_SEC_DOXM, device_index),
request, oc_string(anchor), links))
request, oc_string(anchor), links, device_index))
matches++;

if (filter_resource(
oc_core_get_resource_by_index(OCF_SEC_PSTAT, device_index), request,
oc_string(anchor), links))
oc_string(anchor), links, device_index))
matches++;

if (filter_resource(oc_core_get_resource_by_index(OCF_SEC_ACL, device_index),
request, oc_string(anchor), links))
request, oc_string(anchor), links, device_index))
matches++;

if (filter_resource(oc_core_get_resource_by_index(OCF_SEC_CRED, device_index),
request, oc_string(anchor), links))
request, oc_string(anchor), links, device_index))
matches++;

if (filter_resource(oc_core_get_resource_by_index(OCF_SEC_SP, device_index),
request, oc_string(anchor), links))
request, oc_string(anchor), links, device_index))
matches++;

#ifdef OC_PKI
if (filter_resource(oc_core_get_resource_by_index(OCF_SEC_CSR, device_index),
request, oc_string(anchor), links))
request, oc_string(anchor), links, device_index))
matches++;

if (filter_resource(
oc_core_get_resource_by_index(OCF_SEC_ROLES, device_index), request,
oc_string(anchor), links))
oc_string(anchor), links, device_index))
matches++;
#endif /* OC_PKI */
#endif /* OC_SECURITY */

#if defined(OC_CLIENT) && defined(OC_SERVER) && defined(OC_CLOUD)
if (filter_resource(
oc_core_get_resource_by_index(OCF_COAPCLOUDCONF, device_index), request,
oc_string(anchor), links))
oc_string(anchor), links, device_index))
matches++;
#endif /* OC_CLIENT && OC_SERVER && OC_CLOUD */

Expand All @@ -195,7 +195,8 @@ process_device_resources(CborEncoder *links, oc_request_t *request,
!(resource->properties & OC_DISCOVERABLE))
continue;

if (filter_resource(resource, request, oc_string(anchor), links))
if (filter_resource(resource, request, oc_string(anchor), links,
device_index))
matches++;
}

Expand All @@ -207,7 +208,7 @@ process_device_resources(CborEncoder *links, oc_request_t *request,
continue;

if (filter_resource((oc_resource_t *)collection, request, oc_string(anchor),
links))
links, device_index))
matches++;
}
#endif /* OC_COLLECTIONS */
Expand Down

0 comments on commit 3af1669

Please sign in to comment.