Revert "[IOT-2068] EP payload creation function" 53/21353/3
authorUze Choi <uzchoi@samsung.com>
Tue, 11 Jul 2017 00:42:29 +0000 (00:42 +0000)
committerUze Choi <uzchoi@samsung.com>
Tue, 11 Jul 2017 02:12:45 +0000 (02:12 +0000)
This reverts commit d4353319adbaa5f93c558b4ac3f68a01b3e21bc0.

It seems this patch breaks discovery (in provisioning via UDP)

Change-Id: I026e8a9f3988e0b09d2b9b9422ed7843a32db8df
Reviewed-on: https://gerrit.iotivity.org/gerrit/21353
Reviewed-by: Jongmin Choi <jminl.choi@samsung.com>
Tested-by: jenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
Tested-by: Uze Choi <uzchoi@samsung.com>
resource/csdk/stack/include/internal/ocstackinternal.h
resource/csdk/stack/src/ocpayload.c

index a86a2de..cf3bb27 100644 (file)
@@ -364,23 +364,6 @@ void OCDiscoveryPayloadAddResourceWithEps(OCDiscoveryPayload *payload, const OCR
 /* This method will retrieve the tcp port */
 OCStackResult GetTCPPortInfo(OCDevAddr *endpoint, uint16_t *port, bool secured);
 #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
 }
 #endif // __cplusplus
index 134342d..7eb6832 100644 (file)
@@ -1799,87 +1799,6 @@ 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,
                                          CAEndpoint_t *networkInfo, size_t infoSize,
                                          const OCDevAddr *devAddr
@@ -1895,14 +1814,89 @@ static OCResourcePayload* OCCopyResource(const OCResource* res, uint16_t secureP
         return NULL;
     }
 
+    bool includeSecure = res->resourceProperties & OC_SECURE;
+    bool includeNonsecure = res->resourceProperties & OC_NONSECURE;
     OCEndpointPayload *selfEp = NULL;
     if (networkInfo && infoSize && devAddr)
     {
         OCEndpointPayload *lastNode = pl->eps;
-
-        if(!CreateEndpointPayloadList(res->endpointType, devAddr, networkInfo, infoSize, &lastNode))
+        if ((OC_ADAPTER_IP | OC_ADAPTER_TCP) & (devAddr->adapter))
         {
-            return NULL;
+            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 (((res->endpointType) & matchedTps) &&
+                            ((isSecure && includeSecure) || (!isSecure && includeNonsecure)))
+                    {
+                        // 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;
+                        }
+                    }
+                }
+            }
         }
     }