Fixes for build errors hit by some versions of Visual Studio
[platform/upstream/iotivity.git] / resource / csdk / stack / src / ocpayload.c
index 0ac5e2d..80e9e06 100644 (file)
@@ -21,6 +21,7 @@
 // Required for strok_r
 #define _POSIX_C_SOURCE 200112L
 
+#include "iotivity_config.h"
 #include <stdio.h>
 #include "ocpayload.h"
 #include "octypes.h"
@@ -64,9 +65,11 @@ void OCPayloadDestroy(OCPayload* payload)
         case PAYLOAD_TYPE_SECURITY:
             OCSecurityPayloadDestroy((OCSecurityPayload*)payload);
             break;
+#if defined(RD_CLIENT) || defined(RD_SERVER)
         case PAYLOAD_TYPE_RD:
            OCRDPayloadDestroy((OCRDPayload*)payload);
            break;
+#endif
         default:
             OIC_LOG_V(ERROR, TAG, "Unsupported payload type in destroy: %d", payload->type);
             OICFree(payload);
@@ -485,7 +488,7 @@ bool OCRepPayloadIsNull(const OCRepPayload* payload, const char* name)
 
     if (!val)
     {
-        return false;
+        return true;
     }
 
     return val->type == OCREP_PROP_NULL;
@@ -1330,34 +1333,49 @@ exit:
 
 char* OCCreateString(const OCStringLL* ll)
 {
+    if (!ll)
+    {
+        return NULL;
+    }
+
     char *str = NULL;
     char *pos = NULL;
     size_t len = 0;
     size_t sublen = 0;
     int count = 0;
 
-    if (!ll) return NULL;
-
-    for (const OCStringLL *it = ll; it ; it = it->next )
+    for (const OCStringLL *it = ll; it; it = it->next)
     {
         len += strlen(it->value) + 1;
     }
+    len--; // renove trailing separator (just added above)
     str = (char*) malloc(len + 1);
     if (!str)
+    {
         return NULL;
+    }
 
     pos = str;
-    for (const OCStringLL *it = ll; it ; it = it->next )
+    const OCStringLL *it = ll;
+    while (it)
     {
-        sublen = strlen(it->value) + 1;
-        count = snprintf(pos, len + 1, "%s%c", it->value, CSV_SEPARATOR);
-        if (count<sublen)
+        sublen = strlen(it->value);
+        count = snprintf(pos, len + 1, "%s", it->value);
+        if ((size_t)count < sublen)
         {
             free(str);
             return NULL;
         }
-        len-=sublen;
-        pos+=count;
+        len -= sublen;
+        pos += count;
+
+        it = it->next;
+        if (it)
+        {
+            *pos = CSV_SEPARATOR;
+            len--;
+            *(++pos) = '\0';
+       }
     }
 
     return str;
@@ -1574,7 +1592,11 @@ static OCResourcePayload* OCCopyResource(const OCResource* res, uint16_t secureP
         }
     }
 
-    pl->bitmap = res->resourceProperties & (OC_OBSERVABLE | OC_DISCOVERABLE);
+    pl->bitmap = res->resourceProperties & (OC_OBSERVABLE | OC_DISCOVERABLE
+#ifdef MQ_PUBLISHER
+                                            | OC_MQ_PUBLISHER
+#endif
+                                            );
     pl->secure = (res->resourceProperties & OC_SECURE) != 0;
     pl->port = securePort;
 #ifdef TCP_ADAPTER
@@ -1676,6 +1698,7 @@ void OCDiscoveryPayloadDestroy(OCDiscoveryPayload* payload)
     OICFree(payload->name);
     OCFreeOCStringLL(payload->iface);
     OCDiscoveryResourceDestroy(payload->resources);
+    OCDiscoveryPayloadDestroy(payload->next);
     OICFree(payload);
 }