- memcpy(discPayload->sid, uid, UUID_STRING_SIZE);
- }
-
- if (!resourceTypeQuery && interfaceQuery && (0 == strcmp(interfaceQuery, OC_RSRVD_INTERFACE_LL)))
- {
- for (; resource && discoveryResult == OC_STACK_OK; resource = resource->next)
- {
- bool result = false;
- if (resource->resourceProperties & OC_DISCOVERABLE)
- {
- result = true;
- }
-
- if (result)
- {
- discoveryResult = BuildVirtualResourceResponse(resource,
- discPayload, &request->devAddr, false);
- }
- }
- }
- else
- {
- if (interfaceQuery && (0 != strcmp(interfaceQuery, OC_RSRVD_INTERFACE_LL)))
- {
- discPayload->uri = OICStrdup(OC_RSRVD_WELL_KNOWN_URI);
- VERIFY_NON_NULL(discPayload->uri, ERROR, OC_STACK_NO_MEMORY);
- if (savedDeviceInfo.deviceName)
- {
- discPayload->name = OICStrdup(savedDeviceInfo.deviceName);
- VERIFY_NON_NULL(discPayload->name, ERROR, OC_STACK_NO_MEMORY);
- }
- discPayload->type = (OCStringLL*)OICCalloc(1, sizeof(OCStringLL));
- VERIFY_NON_NULL(discPayload->type, ERROR, OC_STACK_NO_MEMORY);
- discPayload->type->value = OICStrdup(OC_RSRVD_RESOURCE_TYPE_RES);
- VERIFY_NON_NULL(discPayload->type->value, ERROR, OC_STACK_NO_MEMORY);
- OCResourcePayloadAddStringLL(&discPayload->iface, OC_RSRVD_INTERFACE_LL);
- OCResourcePayloadAddStringLL(&discPayload->iface, OC_RSRVD_INTERFACE_DEFAULT);
- VERIFY_NON_NULL(discPayload->iface, ERROR, OC_STACK_NO_MEMORY);
- }
- bool foundResourceAtRD = false;
- for (;resource && discoveryResult == OC_STACK_OK; resource = resource->next)
- {
-#ifdef WITH_RD
- if (strcmp(resource->uri, OC_RSRVD_RD_URI) == 0)
- {
- OCResource *resource1 = NULL;
- OCDevAddr devAddr;
- discoveryResult = checkResourceExistsAtRD(interfaceQuery,
- resourceTypeQuery, &resource1, &devAddr);
- if (discoveryResult != OC_STACK_OK)
- {
- break;
- }
- discoveryResult = BuildVirtualResourceResponse(resource1,
- discPayload, &devAddr, true);
- if (payload)
- {
- discPayload->baseURI = OICStrdup(devAddr.addr);
- }
- OICFree(resource1->uri);
- for (OCResourceType *rsrcRt = resource1->rsrcType, *rsrcRtNext = NULL; rsrcRt; )
- {
- rsrcRtNext = rsrcRt->next;
- OICFree(rsrcRt->resourcetypename);
- OICFree(rsrcRt);
- rsrcRt = rsrcRtNext;
- }
-
- for (OCResourceInterface *rsrcPtr = resource1->rsrcInterface, *rsrcNext = NULL; rsrcPtr; )
- {
- rsrcNext = rsrcPtr->next;
- OICFree(rsrcPtr->name);
- OICFree(rsrcPtr);
- rsrcPtr = rsrcNext;
- }
- foundResourceAtRD = true;
- }
-#endif
- if (!foundResourceAtRD && includeThisResourceInResponse(resource, interfaceQuery, resourceTypeQuery))
- {
- discoveryResult = BuildVirtualResourceResponse(resource,
- discPayload, &request->devAddr, false);
- }
- }
- // Set discoveryResult appropriately if no 'valid' resources are available
- if (discPayload->resources == NULL && !foundResourceAtRD)
- {
- discoveryResult = OC_STACK_NO_RESOURCE;
- }