Commit d4353319 authored by uzchoi's avatar uzchoi Committed by Ashok Babu Channa

[IOT-2068] EP payload creation function

This is internal function which can be used to other function.

Change-Id: I6e1f70a801bca14bd9651395a0e29c9ba0fa6ce2
Signed-off-by: default avataruzchoi <uzchoi@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/20981Tested-by: default avatarjenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: default avatarPhil Coval <philippe.coval@osg.samsung.com>
Reviewed-by: default avatarAshok Babu Channa <ashok.channa@samsung.com>
parent ba21914d
...@@ -364,6 +364,23 @@ void OCDiscoveryPayloadAddResourceWithEps(OCDiscoveryPayload *payload, const OCR ...@@ -364,6 +364,23 @@ void OCDiscoveryPayloadAddResourceWithEps(OCDiscoveryPayload *payload, const OCR
/* This method will retrieve the tcp port */ /* This method will retrieve the tcp port */
OCStackResult GetTCPPortInfo(OCDevAddr *endpoint, uint16_t *port, bool secured); OCStackResult GetTCPPortInfo(OCDevAddr *endpoint, uint16_t *port, bool secured);
#endif #endif
/**
* This function creates list of OCEndpointPayload structure,
* which matches with endpointType from list of CAEndpoint_t.
*
* @param[in] endpointType Bit combination of type for Endpoint.
* @param[in] devAddr devAddr Structure pointing to the address.
* @param[in] networkInfo array of CAEndpoint_t
* @param[in] infoSize size of array
* @param[in] listHead pointer to HeadNode pointer
*
* @return if success return pointer else NULL
*/
OCEndpointPayload* CreateEndpointPayloadList(OCTpsSchemeFlags endpointType,
const OCDevAddr *devAddr, CAEndpoint_t *networkInfo,
size_t infoSize, OCEndpointPayload **listHead);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif // __cplusplus #endif // __cplusplus
......
...@@ -1799,6 +1799,87 @@ void OC_CALL OCResourcePayloadAddNewEndpoint(OCResourcePayload* payload, OCEndpo ...@@ -1799,6 +1799,87 @@ void OC_CALL OCResourcePayloadAddNewEndpoint(OCResourcePayload* payload, OCEndpo
} }
} }
OCEndpointPayload* CreateEndpointPayloadList(OCTpsSchemeFlags endpointType,
const OCDevAddr *devAddr, CAEndpoint_t *networkInfo,
size_t infoSize, OCEndpointPayload **listHead)
{
OCEndpointPayload *headNode = NULL;
OCEndpointPayload *lastNode = NULL;
VERIFY_PARAM_NON_NULL(TAG, devAddr, "Invalid devAddr parameter");
VERIFY_PARAM_NON_NULL(TAG, networkInfo, "Invalid networkInfo parameter");
VERIFY_PARAM_NON_NULL(TAG, listHead, "Invalid listHead parameter");
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))
{
goto exit;
}
if ((endpointType) & matchedTps)
{
OCEndpointPayload* tmpNode = (OCEndpointPayload*)
OICCalloc(1, sizeof(OCEndpointPayload));
if (!tmpNode)
{
goto exit;
}
OCStackResult ret = OCConvertTpsToString(matchedTps, &(tmpNode->tps));
if (ret != OC_STACK_OK)
{
OCDiscoveryEndpointDestroy(tmpNode);
goto exit;
}
tmpNode->addr = (char*)OICCalloc(MAX_ADDR_STR_SIZE, sizeof(char));
if (!tmpNode->addr)
{
OCDiscoveryEndpointDestroy(tmpNode);
goto exit;
}
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 (!headNode)
{
headNode = tmpNode;
lastNode = tmpNode;
}
else
{
lastNode->next = tmpNode;
lastNode = tmpNode;
}
}
}
}
}
*listHead = headNode;
return headNode;
exit:
OCDiscoveryEndpointDestroy(headNode);
return NULL;
}
static OCResourcePayload* OCCopyResource(const OCResource* res, uint16_t securePort, static OCResourcePayload* OCCopyResource(const OCResource* res, uint16_t securePort,
CAEndpoint_t *networkInfo, size_t infoSize, CAEndpoint_t *networkInfo, size_t infoSize,
const OCDevAddr *devAddr const OCDevAddr *devAddr
...@@ -1814,89 +1895,14 @@ static OCResourcePayload* OCCopyResource(const OCResource* res, uint16_t secureP ...@@ -1814,89 +1895,14 @@ static OCResourcePayload* OCCopyResource(const OCResource* res, uint16_t secureP
return NULL; return NULL;
} }
bool includeSecure = res->resourceProperties & OC_SECURE;
bool includeNonsecure = res->resourceProperties & OC_NONSECURE;
OCEndpointPayload *selfEp = NULL; OCEndpointPayload *selfEp = NULL;
if (networkInfo && infoSize && devAddr) if (networkInfo && infoSize && devAddr)
{ {
OCEndpointPayload *lastNode = pl->eps; 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->port) ||
info->adapter == CA_ADAPTER_RFCOMM_BTEDR)
{
OCTpsSchemeFlags matchedTps = OC_NO_TPS;
if (OC_STACK_OK != OCGetMatchedTpsFlags(info->adapter,
info->flags,
&matchedTps))
{
OCDiscoveryResourceDestroy(pl);
return NULL;
}
bool isSecure = (info->flags & OC_FLAG_SECURE); if(!CreateEndpointPayloadList(res->endpointType, devAddr, networkInfo, infoSize, &lastNode))
if (((res->endpointType) & matchedTps) && {
((isSecure && includeSecure) || (!isSecure && includeNonsecure))) return NULL;
{
// create payload
OCEndpointPayload* tmpNode = (OCEndpointPayload*)
OICCalloc(1, sizeof(OCEndpointPayload));
if (!tmpNode)
{
OCDiscoveryResourceDestroy(pl);
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;
}
}
}
}
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment