summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--resource/csdk/stack/include/internal/ocstackinternal.h8
-rw-r--r--resource/csdk/stack/src/ocpayload.c191
-rwxr-xr-xresource/csdk/stack/src/ocpayloadconvert.c43
-rwxr-xr-xresource/csdk/stack/src/ocresource.c4
4 files changed, 132 insertions, 114 deletions
diff --git a/resource/csdk/stack/include/internal/ocstackinternal.h b/resource/csdk/stack/include/internal/ocstackinternal.h
index 293de85b5..9efb21c07 100644
--- a/resource/csdk/stack/include/internal/ocstackinternal.h
+++ b/resource/csdk/stack/include/internal/ocstackinternal.h
@@ -338,14 +338,12 @@ void OCDeleteResourceAttributes(OCAttribute *rsrcAttributes);
* @param payload Pointer to discovery payload.
* @param res Pointer to OCresource structure.
* @param securePort Secure port number.
- * @param isVirtual true: virtual resource (e.g., oic/res), false: resource.
* @param networkInfo List of CAEndpoint_t.
* @param infoSize Size of CAEndpoint_t list.
* @param devAddr Pointer to OCDevAddr structure.
*/
void OCDiscoveryPayloadAddResourceWithEps(OCDiscoveryPayload *payload, const OCResource *res,
- uint16_t securePort, bool isVirtual,
- void *networkInfo, size_t infoSize,
+ uint16_t securePort, void *networkInfo, size_t infoSize,
const OCDevAddr *devAddr);
#else
/**
@@ -354,15 +352,13 @@ void OCDiscoveryPayloadAddResourceWithEps(OCDiscoveryPayload *payload, const OCR
* @param payload Pointer to discovery payload.
* @param res Pointer to OCresource structure.
* @param securePort Secure port number.
- * @param isVirtual true: virtual resource (e.g., oic/res, oic/d), false: resource.
* @param networkInfo List of CAEndpoint_t.
* @param infoSize Size of CAEndpoint_t list.
* @param devAddr Pointer to OCDevAddr structure.
* @param tcpPort TCP port number.
*/
void OCDiscoveryPayloadAddResourceWithEps(OCDiscoveryPayload *payload, const OCResource *res,
- uint16_t securePort, bool isVirtual,
- void *networkInfo, size_t infoSize,
+ uint16_t securePort, void *networkInfo, size_t infoSize,
const OCDevAddr *devAddr, uint16_t tcpPort);
#endif
#ifdef __cplusplus
diff --git a/resource/csdk/stack/src/ocpayload.c b/resource/csdk/stack/src/ocpayload.c
index 6551d41e0..47cbb0201 100644
--- a/resource/csdk/stack/src/ocpayload.c
+++ b/resource/csdk/stack/src/ocpayload.c
@@ -36,6 +36,7 @@
#define TAG "OIC_RI_PAYLOAD"
#define CSV_SEPARATOR ','
+#define MASK_SECURE_FAMS (OC_FLAG_SECURE | OC_MASK_FAMS)
static void OCFreeRepPayloadValueContents(OCRepPayloadValue* val);
@@ -1761,8 +1762,8 @@ void OCResourcePayloadAddNewEndpoint(OCResourcePayload* payload, OCEndpointPaylo
}
static OCResourcePayload* OCCopyResource(const OCResource* res, uint16_t securePort,
- bool isVirtual, CAEndpoint_t *networkInfo,
- size_t infoSize, const OCDevAddr *devAddr
+ CAEndpoint_t *networkInfo, size_t infoSize,
+ const OCDevAddr *devAddr
#ifndef TCP_ADAPTER
)
#else
@@ -1775,8 +1776,86 @@ static OCResourcePayload* OCCopyResource(const OCResource* res, uint16_t secureP
return NULL;
}
- pl->uri = OICStrdup(res->uri);
+ OCEndpointPayload *selfEp = NULL;
+ if (networkInfo && infoSize && devAddr)
+ {
+ OCEndpointPayload *lastNode = pl->eps;
+ if ((OC_ADAPTER_IP | OC_ADAPTER_TCP) & (devAddr->adapter))
+ {
+ for (size_t i = 0; i < infoSize; i++)
+ {
+ CAEndpoint_t *info = networkInfo + i;
+
+ if (((CA_ADAPTER_IP | CA_ADAPTER_TCP) & info->adapter &&
+ info->ifindex == devAddr->ifindex) ||
+ info->adapter == CA_ADAPTER_RFCOMM_BTEDR)
+ {
+ OCTpsSchemeFlags matchedTps = OC_NO_TPS;
+ if (OC_STACK_OK != OCGetMatchedTpsFlags(info->adapter,
+ info->flags,
+ &matchedTps))
+ {
+ return NULL;
+ }
+
+ if ((res->endpointType) & matchedTps)
+ {
+ // create payload
+ OCEndpointPayload* tmpNode = (OCEndpointPayload*)
+ OICCalloc(1, sizeof(OCEndpointPayload));
+ if (!tmpNode)
+ {
+ return NULL;
+ }
+
+ OCStackResult ret = OCConvertTpsToString(matchedTps, &(tmpNode->tps));
+ if (ret != OC_STACK_OK)
+ {
+ OCDiscoveryEndpointDestroy(tmpNode);
+ OCDiscoveryResourceDestroy(pl);
+ return NULL;
+ }
+
+ tmpNode->addr = (char*)OICCalloc(MAX_ADDR_STR_SIZE, sizeof(char));
+ if (!tmpNode->addr)
+ {
+ OCDiscoveryEndpointDestroy(tmpNode);
+ OCDiscoveryResourceDestroy(pl);
+ return NULL;
+ }
+
+ memcpy(tmpNode->addr, info->addr, sizeof(info->addr));
+ tmpNode->family = (OCTransportFlags)(info->flags);
+ tmpNode->port = info->port;
+ tmpNode->pri = 1;
+ tmpNode->next = NULL;
+
+ // remember endpoint that matches devAddr for use in anchor.
+ OCTransportFlags infoFlagsSecureFams = (OCTransportFlags)
+ (info->flags & MASK_SECURE_FAMS);
+ if ((infoFlagsSecureFams & devAddr->flags) == infoFlagsSecureFams)
+ {
+ selfEp = tmpNode;
+ }
+
+ // store in list
+ if (!pl->eps)
+ {
+ pl->eps = tmpNode;
+ lastNode = tmpNode;
+ }
+ else
+ {
+ lastNode->next = tmpNode;
+ lastNode = tmpNode;
+ }
+ }
+ }
+ }
+ }
+ }
+ pl->uri = OICStrdup(res->uri);
if (!pl->uri)
{
OCDiscoveryResourceDestroy(pl);
@@ -1787,7 +1866,6 @@ static OCResourcePayload* OCCopyResource(const OCResource* res, uint16_t secureP
if (0 == strcmp(res->uri, OC_RSRVD_WELL_KNOWN_URI))
{
pl->rel = OICStrdup("self");
-
if (!pl->rel)
{
OCDiscoveryResourceDestroy(pl);
@@ -1795,6 +1873,17 @@ static OCResourcePayload* OCCopyResource(const OCResource* res, uint16_t secureP
}
}
+ // anchor
+ char *anchor = OCCreateEndpointString(selfEp);
+ if (anchor)
+ {
+ pl->anchor = anchor;
+ }
+ else
+ {
+ OIC_LOG(ERROR, TAG, "Can't determine anchor");
+ }
+
// types
OCResourceType* typePtr = res->rsrcType;
@@ -1883,83 +1972,6 @@ static OCResourcePayload* OCCopyResource(const OCResource* res, uint16_t secureP
pl->tcpPort = tcpPort;
#endif
- if (isVirtual || !networkInfo || infoSize == 0 || !devAddr)
- {
- pl->eps = NULL;
- }
- else
- {
- OCEndpointPayload *lastNode = pl->eps;
- if ((OC_ADAPTER_IP | OC_ADAPTER_TCP) & (devAddr->adapter))
- {
- for (size_t i = 0; i < infoSize; i++)
- {
- CAEndpoint_t *info = networkInfo + i;
-
- if (info)
- {
- if (((CA_ADAPTER_IP | CA_ADAPTER_TCP) & info->adapter &&
- info->ifindex == devAddr->ifindex) ||
- info->adapter == CA_ADAPTER_RFCOMM_BTEDR)
- {
- OCTpsSchemeFlags matchedTps = OC_NO_TPS;
- if (OC_STACK_OK != OCGetMatchedTpsFlags(info->adapter,
- info->flags,
- &matchedTps))
- {
- return NULL;
- }
-
- if ((res->endpointType) & matchedTps)
- {
- // create payload
- OCEndpointPayload* tmpNode = (OCEndpointPayload*)
- OICCalloc(1, sizeof(OCEndpointPayload));
- if (!tmpNode)
- {
- return NULL;
- }
-
- OCStackResult ret = OCConvertTpsToString(matchedTps, &(tmpNode->tps));
- if (ret != OC_STACK_OK)
- {
- OCDiscoveryEndpointDestroy(tmpNode);
- OCDiscoveryResourceDestroy(pl);
- return NULL;
- }
-
- tmpNode->addr = (char*)OICCalloc(MAX_ADDR_STR_SIZE, sizeof(char));
- if (!tmpNode->addr)
- {
- OCDiscoveryEndpointDestroy(tmpNode);
- OCDiscoveryResourceDestroy(pl);
- return NULL;
- }
-
- memcpy(tmpNode->addr, info->addr, sizeof(info->addr));
- tmpNode->family = (OCTransportFlags)(info->flags);
- tmpNode->port = info->port;
- tmpNode->pri = 1;
- tmpNode->next = NULL;
-
- // store in list
- if (!pl->eps)
- {
- pl->eps = tmpNode;
- lastNode = tmpNode;
- }
- else
- {
- lastNode->next = tmpNode;
- lastNode = tmpNode;
- }
- }
- }
- }
- }
- }
- }
-
return pl;
}
@@ -1967,36 +1979,33 @@ static OCResourcePayload* OCCopyResource(const OCResource* res, uint16_t secureP
void OCDiscoveryPayloadAddResource(OCDiscoveryPayload* payload, const OCResource* res,
uint16_t securePort)
{
- OCDiscoveryPayloadAddNewResource(payload, OCCopyResource(res, securePort, false, NULL, 0, NULL));
+ OCDiscoveryPayloadAddNewResource(payload, OCCopyResource(res, securePort, NULL, 0, NULL));
}
#else
void OCDiscoveryPayloadAddResource(OCDiscoveryPayload* payload, const OCResource* res,
uint16_t securePort, uint16_t tcpPort)
{
- OCDiscoveryPayloadAddNewResource(payload, OCCopyResource(res, securePort, false, NULL, 0, NULL, tcpPort));
+ OCDiscoveryPayloadAddNewResource(payload, OCCopyResource(res, securePort, NULL, 0, NULL,
+ tcpPort));
}
#endif
#ifndef TCP_ADAPTER
void OCDiscoveryPayloadAddResourceWithEps(OCDiscoveryPayload* payload, const OCResource* res,
- uint16_t securePort, bool isVirtual,
- void *networkInfo, size_t infoSize,
+ uint16_t securePort, void *networkInfo, size_t infoSize,
const OCDevAddr *devAddr)
{
OCDiscoveryPayloadAddNewResource(payload,
- OCCopyResource(res, securePort, isVirtual,
- (CAEndpoint_t *)networkInfo,
+ OCCopyResource(res, securePort, (CAEndpoint_t *)networkInfo,
infoSize, devAddr));
}
#else
void OCDiscoveryPayloadAddResourceWithEps(OCDiscoveryPayload* payload, const OCResource* res,
- uint16_t securePort, bool isVirtual,
- void *networkInfo, size_t infoSize,
+ uint16_t securePort, void *networkInfo, size_t infoSize,
const OCDevAddr *devAddr, uint16_t tcpPort)
{
OCDiscoveryPayloadAddNewResource(payload,
- OCCopyResource(res, securePort, isVirtual,
- (CAEndpoint_t *)networkInfo,
+ OCCopyResource(res, securePort, (CAEndpoint_t *)networkInfo,
infoSize, devAddr, tcpPort));
}
#endif
diff --git a/resource/csdk/stack/src/ocpayloadconvert.c b/resource/csdk/stack/src/ocpayloadconvert.c
index f9f5e3b6a..0e76b306e 100755
--- a/resource/csdk/stack/src/ocpayloadconvert.c
+++ b/resource/csdk/stack/src/ocpayloadconvert.c
@@ -241,6 +241,16 @@ static int64_t OCConvertResourcePayloadCbor(CborEncoder *linkArray, OCResourcePa
err |= AddTextStringToMap(&linkMap, OC_RSRVD_HREF, sizeof(OC_RSRVD_HREF) - 1,
uri);
}
+ else if (!strstr(resource->uri, OC_ENDPOINT_TPS_TOKEN) &&
+ resource->rel && !strcmp(resource->rel, "self") &&
+ resource->anchor)
+ {
+ char uri[MAX_URI_LENGTH];
+ snprintf(uri, MAX_URI_LENGTH, "%s%s", resource->anchor, resource->uri);
+
+ err |= AddTextStringToMap(&linkMap, OC_RSRVD_HREF, sizeof(OC_RSRVD_HREF) - 1,
+ uri);
+ }
else
{
err |= AddTextStringToMap(&linkMap, OC_RSRVD_HREF, sizeof(OC_RSRVD_HREF) - 1,
@@ -527,8 +537,20 @@ static int64_t OCConvertDiscoveryPayloadVndOcfCbor(OCDiscoveryPayload *payload,
VERIFY_CBOR_SUCCESS(TAG, err, "Failed creating discovery map");
// Uri
- err |= AddTextStringToMap(&linkMap, OC_RSRVD_HREF, sizeof(OC_RSRVD_HREF) - 1,
- resource->uri);
+ if (!strstr(resource->uri, OC_ENDPOINT_TPS_TOKEN) &&
+ resource->rel && !strcmp(resource->rel, "self"))
+ {
+ char uri[MAX_URI_LENGTH];
+ snprintf(uri, MAX_URI_LENGTH, "ocf://%s%s", payload->sid, resource->uri);
+
+ err |= AddTextStringToMap(&linkMap, OC_RSRVD_HREF, sizeof(OC_RSRVD_HREF) - 1,
+ uri);
+ }
+ else
+ {
+ err |= AddTextStringToMap(&linkMap, OC_RSRVD_HREF, sizeof(OC_RSRVD_HREF) - 1,
+ resource->uri);
+ }
VERIFY_CBOR_SUCCESS(TAG, err, "Failed adding uri to links map");
// Rel - Not a mandatory field
@@ -536,19 +558,10 @@ static int64_t OCConvertDiscoveryPayloadVndOcfCbor(OCDiscoveryPayload *payload,
resource->rel);
VERIFY_CBOR_SUCCESS(TAG, err, "Failed adding rel to links map");
- // Anchor - Not a mandatory field
- if (resource->anchor)
- {
- err |= AddTextStringToMap(&linkMap, OC_RSRVD_URI, sizeof(OC_RSRVD_URI) - 1,
- resource->anchor);
- }
- else
- {
- char anchor[MAX_URI_LENGTH];
- snprintf(anchor, MAX_URI_LENGTH, "ocf://%s", payload->sid);
- err |= AddTextStringToMap(&linkMap, OC_RSRVD_URI, sizeof(OC_RSRVD_URI) - 1,
- anchor);
- }
+ // Anchor
+ char anchor[MAX_URI_LENGTH];
+ snprintf(anchor, MAX_URI_LENGTH, "ocf://%s", payload->sid);
+ err |= AddTextStringToMap(&linkMap, OC_RSRVD_URI, sizeof(OC_RSRVD_URI) - 1, anchor);
VERIFY_CBOR_SUCCESS(TAG, err, "Failed adding anchor to links map");
// Resource Type
diff --git a/resource/csdk/stack/src/ocresource.c b/resource/csdk/stack/src/ocresource.c
index 1e0d4e937..0a77f79fb 100755
--- a/resource/csdk/stack/src/ocresource.c
+++ b/resource/csdk/stack/src/ocresource.c
@@ -1321,10 +1321,10 @@ OCStackResult BuildVirtualResourceResponse(const OCResource *resourcePtr,
GetTCPPortInfo(devAddr, &tcpPort, (resourcePtr->resourceProperties & OC_SECURE));
OCDiscoveryPayloadAddResourceWithEps(payload, resourcePtr, securePort,
- isVirtual, networkInfo, infoSize, devAddr, tcpPort);
+ networkInfo, infoSize, devAddr, tcpPort);
#else
OCDiscoveryPayloadAddResourceWithEps(payload, resourcePtr, securePort,
- isVirtual, networkInfo, infoSize, devAddr);
+ networkInfo, infoSize, devAddr);
#endif
return OC_STACK_OK;