{
case OCREP_PROP_INT:
dest->arr.iArray = (int64_t*)OICMalloc(dimTotal * sizeof(int64_t));
+ VERIFY_PARAM_NON_NULL(TAG, dest->arr.iArray, "Failed allocating memory");
memcpy(dest->arr.iArray, source->arr.iArray, dimTotal * sizeof(int64_t));
break;
case OCREP_PROP_DOUBLE:
dest->arr.dArray = (double*)OICMalloc(dimTotal * sizeof(double));
+ VERIFY_PARAM_NON_NULL(TAG, dest->arr.dArray, "Failed allocating memory");
memcpy(dest->arr.dArray, source->arr.dArray, dimTotal * sizeof(double));
break;
case OCREP_PROP_BOOL:
dest->arr.bArray = (bool*)OICMalloc(dimTotal * sizeof(bool));
+ VERIFY_PARAM_NON_NULL(TAG, dest->arr.bArray, "Failed allocating memory");
memcpy(dest->arr.bArray, source->arr.bArray, dimTotal * sizeof(bool));
break;
case OCREP_PROP_STRING:
dest->arr.strArray = (char**)OICMalloc(dimTotal * sizeof(char*));
+ VERIFY_PARAM_NON_NULL(TAG, dest->arr.strArray, "Failed allocating memory");
for(size_t i = 0; i < dimTotal; ++i)
{
dest->arr.strArray[i] = OICStrdup(source->arr.strArray[i]);
break;
case OCREP_PROP_OBJECT:
dest->arr.objArray = (OCRepPayload**)OICMalloc(dimTotal * sizeof(OCRepPayload*));
+ VERIFY_PARAM_NON_NULL(TAG, dest->arr.objArray, "Failed allocating memory");
for(size_t i = 0; i < dimTotal; ++i)
{
dest->arr.objArray[i] = OCRepPayloadClone(source->arr.objArray[i]);
break;
case OCREP_PROP_ARRAY:
dest->arr.objArray = (OCRepPayload**)OICMalloc(dimTotal * sizeof(OCRepPayload*));
+ VERIFY_PARAM_NON_NULL(TAG, dest->arr.objArray, "Failed allocating memory");
for(size_t i = 0; i < dimTotal; ++i)
{
dest->arr.objArray[i] = OCRepPayloadClone(source->arr.objArray[i]);
OIC_LOG(ERROR, TAG, "CopyPropertyValueArray invalid type");
break;
}
+exit:
+ return;
}
static void OCCopyPropertyValue (OCRepPayloadValue *dest, OCRepPayloadValue *source)
{
OCRepPayloadValue* val = OCRepPayloadFindValue(payload, name);
- if (!val || val->type != OCREP_PROP_DOUBLE)
+ if (val)
{
- return false;
+ if (val->type == OCREP_PROP_DOUBLE)
+ {
+ *value = val->d;
+ return true;
+ }
+ else if (val->type == OCREP_PROP_INT)
+ {
+ *value = val->i;
+ return true;
+ }
}
- *value = val->d;
- return true;
+ return false;
}
bool OCRepPayloadSetPropString(OCRepPayload* payload, const char* name, const char* value)
{
OCRepPayloadValue* val = OCRepPayloadFindValue(payload, name);
- if (!val || val->type != OCREP_PROP_ARRAY || val->arr.type != OCREP_PROP_DOUBLE
+ if (!val || val->type != OCREP_PROP_ARRAY ||
+ (val->arr.type != OCREP_PROP_DOUBLE && val->arr.type != OCREP_PROP_INT)
|| !val->arr.dArray)
{
return false;
return false;
}
- memcpy(*array, val->arr.dArray, dimTotal * sizeof(double));
+ if (val->arr.type != OCREP_PROP_DOUBLE)
+ {
+ memcpy(*array, val->arr.dArray, dimTotal * sizeof(double));
+ }
+ else
+ {
+ /* need to convert from integer */
+ size_t n = 0;
+ for ( ; n < dimTotal; ++n)
+ {
+ (*array)[n] = val->arr.iArray[n];
+ }
+ }
memcpy(dimensions, val->arr.dimensions, MAX_REP_ARRAY_DEPTH * sizeof(size_t));
return true;
}
return payload;
}
-OCSecurityPayload* OCSecurityPayloadCreate(const char* securityData)
+OCSecurityPayload* OCSecurityPayloadCreate(const uint8_t* securityData, size_t size)
{
OCSecurityPayload* payload = (OCSecurityPayload*)OICCalloc(1, sizeof(OCSecurityPayload));
}
payload->base.type = PAYLOAD_TYPE_SECURITY;
- payload->securityData = OICStrdup(securityData);
+ payload->securityData = (uint8_t *)OICCalloc(1, size);
+ if (!payload->securityData)
+ {
+ OICFree(payload);
+ return NULL;
+ }
+ memcpy(payload->securityData, (uint8_t *)securityData, size);
+ payload->payloadSize = size;
return payload;
}
return NULL;
}
-static OCResourcePayload* OCCopyResource(const OCResource* res, uint16_t port)
+static OCResourcePayload* OCCopyResource(const OCResource* res, uint16_t securePort,
+ uint16_t tcpPort)
{
OCResourcePayload* pl = (OCResourcePayload*)OICCalloc(1, sizeof(OCResourcePayload));
if (!pl)
pl->bitmap = res->resourceProperties & (OC_OBSERVABLE | OC_DISCOVERABLE);
pl->secure = (res->resourceProperties & OC_SECURE) != 0;
- pl->port = port;
-
+ pl->port = securePort;
+#ifdef TCP_ADAPTER
+ pl->tcpPort = tcpPort;
+#endif
return pl;
}
void OCDiscoveryPayloadAddResource(OCDiscoveryPayload* payload, const OCResource* res,
- uint16_t port)
+ uint16_t securePort, uint16_t tcpPort)
{
- OCDiscoveryPayloadAddNewResource(payload, OCCopyResource(res, port));
+ OCDiscoveryPayloadAddNewResource(payload, OCCopyResource(res, securePort, tcpPort));
}
bool OCResourcePayloadAddStringLL(OCStringLL **stringLL, const char *value)
if (!*stringLL)
{
*stringLL = (OCStringLL *)OICCalloc(1, sizeof(OCStringLL));
- VERIFY_PARAM_NON_NULL(TAG, dup, "Failed allocating memory");
+ VERIFY_PARAM_NON_NULL(TAG, *stringLL, "Failed allocating memory");
(*stringLL)->value = dup;
return true;
}
return;
}
OICFree(payload->sid);
+ OICFree(payload->baseURI);
+ OICFree(payload->uri);
+ OICFree(payload->type);
+ OICFree(payload->name);
+ OCFreeOCStringLL(payload->interface);
OCDiscoveryResourceDestroy(payload->resources);
OICFree(payload);
}
goto exit;
}
+ OCResourcePayloadAddStringLL(&payload->interfaces, OC_RSRVD_INTERFACE_DEFAULT);
+ OCResourcePayloadAddStringLL(&payload->interfaces, OC_RSRVD_INTERFACE_READ);
+
payload->types = CloneOCStringLL((OCStringLL *)types);
if (types && !payload->types)
{
OICFree(payload->specVersion);
OICFree(payload->dataModelVersion);
OCFreeOCStringLL(payload->types);
+ OCFreeOCStringLL(payload->interfaces);
OICFree(payload);
}
}
payload->base.type = PAYLOAD_TYPE_PLATFORM;
+
+ payload->interfaces = (OCStringLL*)OICCalloc(1, sizeof(OCStringLL));
+ if (!payload->interfaces)
+ {
+ return NULL;
+ }
+ payload->interfaces->value = OICStrdup(OC_RSRVD_INTERFACE_READ);
+ payload->rt = OICStrdup(OC_RSRVD_RESOURCE_TYPE_PLATFORM);
payload->info = *platformInfo;
return payload;
}
payload->base.type = PAYLOAD_TYPE_PLATFORM;
+ payload->rt = OICStrdup(OC_RSRVD_RESOURCE_TYPE_PLATFORM);
+
+ OCResourcePayloadAddStringLL(&payload->interfaces, OC_RSRVD_INTERFACE_DEFAULT);
+ OCResourcePayloadAddStringLL(&payload->interfaces, OC_RSRVD_INTERFACE_READ);
+
OCCopyPlatformInfo(platformInfo, payload);
return payload;
}
OICFree(payload->uri);
OCPlatformInfoDestroy(&payload->info);
+ OICFree(payload->rt);
+ OCFreeOCStringLL(payload->interfaces);
OICFree(payload);
}