// Required for strok_r
#define _POSIX_C_SOURCE 200112L
+#include "iotivity_config.h"
#include <stdio.h>
#include "ocpayload.h"
#include "octypes.h"
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);
if (!val)
{
- return false;
+ return true;
}
return val->type == OCREP_PROP_NULL;
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;
}
}
- 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
OICFree(payload->name);
OCFreeOCStringLL(payload->iface);
OCDiscoveryResourceDestroy(payload->resources);
+ OCDiscoveryPayloadDestroy(payload->next);
OICFree(payload);
}