Add logic for extra Information.
authorjaesick.shin <jaesick.shin@samsung.com>
Tue, 20 Sep 2016 09:02:04 +0000 (18:02 +0900)
committerUze Choi <uzchoi@samsung.com>
Thu, 29 Sep 2016 10:32:39 +0000 (10:32 +0000)
This patch include,
1. Add extraInfo field in NSMessage.
2. Modify logic for related sendMessage.

second patch include,
modify setting Message payload.

third and fourth patch include,
add defence code for double free.

Change-Id: I2dcfaa9cf9bc0e42b1c0aaff83de99819433f01e
Signed-off-by: jaesick.shin <jaesick.shin@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/11975
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
(cherry picked from commit 4ef1e3f85db4980d9e4d316c98bef3f2ac67c8e3)
Reviewed-on: https://gerrit.iotivity.org/gerrit/12449

service/notification/include/NSCommon.h
service/notification/src/common/NSUtil.c
service/notification/src/provider/NSProviderNotification.c

index c0ec948..be47df4 100644 (file)
@@ -28,6 +28,7 @@
 #define _NS_COMMON_H_
 
 #include <stdint.h>
+#include <octypes.h>
 
 #define NS_UUID_STRING_SIZE 37
 
@@ -148,6 +149,7 @@ typedef struct
     char * sourceName;
     NSMediaContents * mediaContents;
     char * topic;
+    OCRepPayload * extraInfo;
 
 } NSMessage;
 
index eee3b22..24ce822 100755 (executable)
@@ -97,7 +97,7 @@ NSResult NSFreeMessage(NSMessage * obj)
     NSFreeMalloc(&(obj->sourceName));
     NSFreeMalloc(&(obj->topic));
     NSFreeMediaContents(obj->mediaContents);
-
+    OCRepPayloadDestroy(obj->extraInfo);
     OICFree(obj);
 
     return NS_OK;
@@ -150,6 +150,11 @@ NSMessage * NSDuplicateMessage(NSMessage * copyMsg)
         newMsg->topic = OICStrdup(copyMsg->topic);
     }
 
+    if (copyMsg->extraInfo)
+    {
+        newMsg->extraInfo = OCRepPayloadClone(copyMsg->extraInfo);
+    }
+
     return newMsg;
 }
 
@@ -429,6 +434,7 @@ NSMessage * NSInitializeMessage()
     msg->sourceName = NULL;
     msg->mediaContents = NULL;
     msg->topic = NULL;
+    msg->extraInfo = NULL;
 
     return msg;
 }
index c8a8f50..269fe20 100644 (file)
@@ -24,7 +24,7 @@ NSResult NSSetMessagePayload(NSMessage *msg, OCRepPayload** msgPayload)
 {
     NS_LOG(DEBUG, "NSSetMessagePayload - IN");
 
-    *msgPayload = OCRepPayloadCreate();
+    *msgPayload = msg->extraInfo != NULL ? msg->extraInfo : OCRepPayloadCreate();
 
     if (!*msgPayload)
     {
@@ -43,10 +43,11 @@ NSResult NSSetMessagePayload(NSMessage *msg, OCRepPayload** msgPayload)
     NSDuplicateSetPropertyString(msgPayload, NS_ATTRIBUTE_TEXT, msg->contentText);
     NSDuplicateSetPropertyString(msgPayload, NS_ATTRIBUTE_SOURCE, msg->sourceName);
     NSDuplicateSetPropertyString(msgPayload, NS_ATTRIBUTE_TOPIC_NAME, msg->topic);
-    if(msg->mediaContents)
+
+    if (msg->mediaContents)
     {
-        NSDuplicateSetPropertyString(msgPayload,
-                NS_ATTRIBUTE_ICON_IMAGE, msg->mediaContents->iconImage);
+        NSDuplicateSetPropertyString(msgPayload, NS_ATTRIBUTE_ICON_IMAGE,
+                msg->mediaContents->iconImage);
     }
 
     NS_LOG(DEBUG, "NSSetMessagePayload - OUT");
@@ -178,13 +179,14 @@ NSResult NSSendNotification(NSMessage *msg)
     {
         NS_LOG(ERROR, "fail to send message");
         OCRepPayloadDestroy(payload);
+        msg->extraInfo = NULL;
         return NS_ERROR;
     }
 
     OCRepPayloadDestroy(payload);
+    msg->extraInfo = NULL;
 
     NS_LOG(DEBUG, "NSSendMessage - OUT");
-
     return NS_OK;
 }