[IOT-1400] Remove multicast presence node list in client side.
authorjihwan.seo <jihwan.seo@samsung.com>
Wed, 12 Oct 2016 01:10:26 +0000 (10:10 +0900)
committerAshok Babu Channa <ashok.channa@samsung.com>
Fri, 4 Nov 2016 05:49:53 +0000 (05:49 +0000)
MCPresenceNode(multicast presence list) never remove.
it causes a big memory leak.
and since checking sequence number not required.
it is better to remove for simple stack logic.

Change-Id: I000772b12c88b30bd771fc759ac2ffaacedd0cc0
Signed-off-by: jihwan.seo <jihwan.seo@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/13119
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: daeken kwon <daeken.kwon@samsung.com>
Reviewed-by: Ashok Babu Channa <ashok.channa@samsung.com>
resource/csdk/stack/include/internal/occlientcb.h
resource/csdk/stack/src/occlientcb.c
resource/csdk/stack/src/ocstack.c

index 90c01b1..2fcdb29 100644 (file)
@@ -53,21 +53,6 @@ typedef struct OCPresence
 } OCPresence;
 
 /**
- * Data structure to hold Multicast node identity for resource discovery.
- */
-typedef struct OCMulticastNode
-{
-    /** URI of new resource.*/
-    char * uri;
-
-    /** URI of new resource that entity handler might create.*/
-    uint32_t nonce;
-
-    /** Linked list; for multicast nodes.*/
-    struct OCMulticastNode * next;
-} OCMulticastNode;
-
-/**
  * Forward declaration of resource type.
  */
 typedef struct resourcetype_t OCResourceType;
@@ -218,29 +203,5 @@ void DeleteClientCBList();
  */
 void FindAndDeleteClientCB(ClientCB * cbNode);
 
-/** @ingroup ocstack
- *
- * This method is used to search a multicast presence node from list.
- *
- * @param[in]  uri   the uri of the request.
- *
- * @return OCMulticastNode
- *              The resulting node from making this call. Null if doesn't exist.
- */
-
-OCMulticastNode* GetMCPresenceNode(const char * uri);
-
-/** @ingroup ocstack
- *
- * This method is used to add a multicast presence node to the list.
- * @param[out] outnode  the resulting node from making this call. Null if out of memory.
- * @param[in] uri       the uri of the server.
- * @param[in] nonce     current nonce for the server
- *
- * @return OC_STACK_OK for Success, otherwise some error value
- */
-
-OCStackResult AddMCPresenceNode(OCMulticastNode** outnode, char* uri, uint32_t nonce);
-
 #endif //OC_CLIENT_CB
 
index 319871a..40912b4 100644 (file)
@@ -39,7 +39,6 @@
 #define TAG "OIC_RI_CLIENTCB"
 
 struct ClientCB *cbList = NULL;
-static OCMulticastNode * mcPresenceNodes = NULL;
 
 OCStackResult
 AddClientCB (ClientCB** clientCB, OCCallbackData* cbData,
@@ -318,40 +317,3 @@ void FindAndDeleteClientCB(ClientCB * cbNode)
         }
     }
 }
-
-OCStackResult AddMCPresenceNode(OCMulticastNode** outnode, char* uri, uint32_t nonce)
-{
-    if (!outnode)
-    {
-        return OC_STACK_INVALID_PARAM;
-    }
-
-    OCMulticastNode *node = (OCMulticastNode*) OICMalloc(sizeof(*node));
-    if (node)
-    {
-        node->nonce = nonce;
-        node->uri = uri;
-        LL_APPEND(mcPresenceNodes, node);
-        *outnode = node;
-        return OC_STACK_OK;
-    }
-    *outnode = NULL;
-    return OC_STACK_NO_MEMORY;
-}
-
-OCMulticastNode* GetMCPresenceNode(const char * uri)
-{
-    if (uri)
-    {
-        OCMulticastNode* out = NULL;
-        LL_FOREACH(mcPresenceNodes, out)
-        {
-            if (out->uri && strcmp(out->uri, uri) == 0)
-            {
-                return out;
-            }
-        }
-    }
-    OIC_LOG(INFO, TAG, "MulticastNode Not found !!");
-    return NULL;
-}
index 55ee94e..8d64ab5 100644 (file)
@@ -1144,72 +1144,29 @@ OCStackResult HandlePresenceResponse(const CAEndpoint_t *endpoint,
             ResetPresenceTTL(cbNode, maxAge);
 
             cbNode->sequenceNumber = response.sequenceNumber;
-
-            // Ensure that a filter is actually applied.
-            if( resourceTypeName && cbNode->filterResourceType)
-            {
-                if(!findResourceType(cbNode->filterResourceType, resourceTypeName))
-                {
-                    goto exit;
-                }
-            }
         }
     }
     else
     {
         // This is the multicast case
-        OCMulticastNode* mcNode = NULL;
-        mcNode = GetMCPresenceNode(presenceUri);
-
-        if(mcNode != NULL)
-        {
-            if(mcNode->nonce == response.sequenceNumber)
-            {
-                OIC_LOG(INFO, TAG, "No presence change (Multicast)");
-                goto exit;
-            }
-            mcNode->nonce = response.sequenceNumber;
-
-            if(maxAge == 0)
-            {
-                OIC_LOG(INFO, TAG, "Stopping presence");
-                response.result = OC_STACK_PRESENCE_STOPPED;
-            }
-        }
-        else
+        OIC_LOG(INFO, TAG, "this is the multicast presence");
+        if (0 == maxAge)
         {
-            char* uri = OICStrdup(presenceUri);
-            if (!uri)
-            {
-                OIC_LOG(INFO, TAG,
-                    "No Memory for URI to store in the presence node");
-                result = OC_STACK_NO_MEMORY;
-                goto exit;
-            }
-
-            result = AddMCPresenceNode(&mcNode, uri, response.sequenceNumber);
-            if(result == OC_STACK_NO_MEMORY)
-            {
-                OIC_LOG(INFO, TAG,
-                    "No Memory for Multicast Presence Node");
-                OICFree(uri);
-                goto exit;
-            }
-            // presence node now owns uri
+            OIC_LOG(INFO, TAG, "Stopping presence");
+            response.result = OC_STACK_PRESENCE_STOPPED;
         }
+    }
 
-
-
-        // Ensure that a filter is actually applied.
-        if(resourceTypeName && cbNode->filterResourceType)
+    // Ensure that a filter is actually applied.
+    if (resourceTypeName && cbNode->filterResourceType)
+    {
+        OIC_LOG_V(INFO, TAG, "find resource type : %s", resourceTypeName);
+        if(!findResourceType(cbNode->filterResourceType, resourceTypeName))
         {
-            OIC_LOG_V(INFO, TAG, "find resource type : %s", resourceTypeName);
-            if(!findResourceType(cbNode->filterResourceType, resourceTypeName))
-            {
-                goto exit;
-            }
+            goto exit;
         }
     }
+
     OIC_LOG(INFO, TAG, "Callback for presence");
 
     cbResult = cbNode->callBack(cbNode->context, cbNode->handle, &response);
@@ -3148,6 +3105,7 @@ OCStackResult OCProcess()
 #ifdef WITH_PRESENCE
 OCStackResult OCStartPresence(const uint32_t ttl)
 {
+    OIC_LOG(INFO, TAG, "Entering OCStartPresence");
     uint8_t tokenLength = CA_MAX_TOKEN_LEN;
     OCChangeResourceProperty(
             &(((OCResource *)presenceResource.handle)->resourceProperties),
@@ -3199,6 +3157,7 @@ OCStackResult OCStartPresence(const uint32_t ttl)
 
 OCStackResult OCStopPresence()
 {
+    OIC_LOG(INFO, TAG, "Entering OCStopPresence");
     OCStackResult result = OC_STACK_ERROR;
 
     if(presenceResource.handle)
@@ -4007,6 +3966,7 @@ void incrementSequenceNumber(OCResource * resPtr)
 OCStackResult SendPresenceNotification(OCResourceType *resourceType,
         OCPresenceTrigger trigger)
 {
+    OIC_LOG(INFO, TAG, "SendPresenceNotification");
     OCResource *resPtr = NULL;
     OCStackResult result = OC_STACK_ERROR;
     OCMethod method = OC_REST_PRESENCE;
@@ -4030,6 +3990,7 @@ OCStackResult SendPresenceNotification(OCResourceType *resourceType,
 
 OCStackResult SendStopNotification()
 {
+    OIC_LOG(INFO, TAG, "SendStopNotification");
     OCResource *resPtr = NULL;
     OCStackResult result = OC_STACK_ERROR;
     OCMethod method = OC_REST_PRESENCE;