DI field was being sent as a byte string over ther wire.
This patch update it to be sent as a string.
ocpayloadparse.c can handle both byte string and text string.
But ocpayloadconvert.c will be sending in text string.
Jira Issue: IOT-914
Signed-off-by: Habib Virji <habib.virji@samsung.com>
Change-Id: I049bf4cff5f2b390e589eb5cf55966e8034838b1
Reviewed-on: https://gerrit.iotivity.org/gerrit/5691
Reviewed-by: Dwarkaprasad Dayama <dwarka.dayama@samsung.com>
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
OCStackResult CAResultToOCResult(CAResult_t caResult);
/**
- * Get a byte representation of the server instance ID.
- * The memory is managed internal to this function, so freeing it externally will
- * result in a runtime error.
- *
- * Note: This will NOT seed the RNG, so it must be called after the RNG is seeded.
- * This is done automatically during the OCInit process,
- * so ensure that this call is done after that.
- *
- * @return A uint8_t representation the server instance ID.
- */
-const OicUuid_t* OCGetServerInstanceID(void);
-
-/**
* Map OCQualityOfService to CAMessageType.
*
* @param qos Input qos.
void OCDiscoveryPayloadDestroy(OCDiscoveryPayload* payload);
// Device Payload
-OCDevicePayload* OCDevicePayloadCreate(const uint8_t* sid, const char* dname,
+OCDevicePayload* OCDevicePayloadCreate(const char* sid, const char* dname,
const char* specVer, const char* dmVer);
void OCDevicePayloadDestroy(OCDevicePayload* payload);
{
OCPayload base;
- uint8_t* sid;
+ char *sid;
/** A special case for handling RD address. */
char* baseURI;
typedef struct
{
OCPayload base;
- uint8_t* sid;
+ char* sid;
char* deviceName;
char* specVersion;
char* dataModelVersion;
OIC_LOG(level, PL_TAG, "\tNO Resources");
return;
}
- OIC_LOG(level, PL_TAG, "\tSID:");
- OIC_LOG_BUFFER(level, PL_TAG, payload->sid, UUID_SIZE);
+ OIC_LOG_V(level, PL_TAG, "\tSID: %s", payload->sid);
OCResourcePayload* res = payload->resources;
while(res)
static inline void OCPayloadLogDevice(LogLevel level, OCDevicePayload* payload)
{
OIC_LOG(level, PL_TAG, "Payload Type: Device");
- OIC_LOG(level, PL_TAG, "\tSID:");
- OIC_LOG_BUFFER(level, PL_TAG, payload->sid, UUID_SIZE);
+ OIC_LOG_V(level, PL_TAG, "\tSID:%s", payload->sid);
OIC_LOG_V(level, PL_TAG, "\tDevice Name:%s", payload->deviceName);
OIC_LOG_V(level, PL_TAG, "\tSpec Version%s", payload->specVersion);
OIC_LOG_V(level, PL_TAG, "\tData Model Version:%s", payload->dataModelVersion);
OICFree(payload);
}
-OCDevicePayload* OCDevicePayloadCreate(const uint8_t* sid, const char* dname,
+OCDevicePayload* OCDevicePayloadCreate(const char* sid, const char* dname,
const char* specVer, const char* dmVer)
{
}
payload->base.type = PAYLOAD_TYPE_DEVICE;
-
- if (sid)
+ payload->sid = OICStrdup(sid);
+ if (sid && !payload->sid)
{
- payload->sid = (uint8_t*)OICMalloc(UUID_SIZE);
- if (!payload->sid)
- {
- goto exit;
- }
- memcpy(payload->sid, sid, UUID_SIZE);
+ goto exit;
}
payload->deviceName = OICStrdup(dname);
VERIFY_CBOR_SUCCESS(TAG, err, "Failed creating discovery map");
// Insert Device ID into the root map
- err |= cbor_encode_text_string(&rootMap, OC_RSRVD_DEVICE_ID, sizeof(OC_RSRVD_DEVICE_ID) - 1);
- VERIFY_CBOR_SUCCESS(TAG, err, "Failed setting tag device id");
- err |= cbor_encode_byte_string(&rootMap, payload->sid, UUID_SIZE);
- VERIFY_CBOR_SUCCESS(TAG, err, "Failed setting value of device id");
+ err |= AddTextStringToMap(&rootMap, OC_RSRVD_DEVICE_ID, sizeof(OC_RSRVD_DEVICE_ID) - 1, payload->sid);
+ VERIFY_CBOR_SUCCESS(TAG, err, "Failed setting device id");
// Insert baseURI if present
err |= ConditionalAddTextStringToMap(&rootMap, OC_RSRVD_BASE_URI,
VERIFY_CBOR_SUCCESS(TAG, err, "Failed creating device map");
// Device ID
- err |= cbor_encode_text_string(&repMap, OC_RSRVD_DEVICE_ID, sizeof(OC_RSRVD_DEVICE_ID) - 1);
- VERIFY_CBOR_SUCCESS(TAG, err, "Failed adding device id tag");
- err |= cbor_encode_byte_string(&repMap, payload->sid, UUID_SIZE);
- VERIFY_CBOR_SUCCESS(TAG, err, "Failed adding data device id");
+ err |= AddTextStringToMap(&repMap, OC_RSRVD_DEVICE_ID, sizeof(OC_RSRVD_DEVICE_ID) - 1 , payload->sid);
+ VERIFY_CBOR_SUCCESS(TAG, err, "Failed adding device id");
// Device Name
err |= ConditionalAddTextStringToMap(&repMap, OC_RSRVD_DEVICE_NAME,
CborValue curVal;
err = cbor_value_map_find_value(&rootMap, OC_RSRVD_DEVICE_ID, &curVal);
VERIFY_CBOR_SUCCESS(TAG, err, "to find device id tag");
+ if (cbor_value_is_valid(&curVal))
{
- err = cbor_value_dup_byte_string(&curVal, &(out->sid), &len, NULL);
- VERIFY_CBOR_SUCCESS(TAG, err, "to copy device id value");
+ if (cbor_value_is_byte_string(&curVal))
+ {
+ err = cbor_value_dup_byte_string(&curVal, (uint8_t **)&(out->sid), &len, NULL);
+ VERIFY_CBOR_SUCCESS(TAG, err, "to copy device id value");
+ }
+ else if (cbor_value_is_text_string(&curVal))
+ {
+ err = cbor_value_dup_text_string(&curVal, &(out->sid), &len, NULL);
+ VERIFY_CBOR_SUCCESS(TAG, err, "to copy device id value");
+ }
}
// BaseURI - Not a mandatory field
err = cbor_value_map_find_value(rootValue, OC_RSRVD_DEVICE_ID, &curVal);
if (cbor_value_is_valid(&curVal))
{
- err = cbor_value_dup_byte_string(&curVal, &out->sid, &len, NULL);
- VERIFY_CBOR_SUCCESS(TAG, err, "to find device id in device payload");
+ if (cbor_value_is_byte_string(&curVal))
+ {
+ err = cbor_value_dup_byte_string(&curVal, (uint8_t **)&out->sid, &len, NULL);
+ VERIFY_CBOR_SUCCESS(TAG, err, "to find device id in device payload");
+ }
+ else if (cbor_value_is_text_string(&curVal))
+ {
+ err = cbor_value_dup_text_string(&curVal, &out->sid, &len, NULL);
+ VERIFY_CBOR_SUCCESS(TAG, err, "to find device id in device payload");
+ }
}
// Device Name
err = cbor_value_map_find_value(rootValue, OC_RSRVD_DEVICE_NAME, &curVal);
if (discoveryResult == OC_STACK_OK)
{
- payload = (OCPayload*)OCDiscoveryPayloadCreate();
+ payload = (OCPayload *)OCDiscoveryPayloadCreate();
if(payload)
{
- ((OCDiscoveryPayload*)payload)->sid = (uint8_t*)OICCalloc(1, UUID_SIZE);
- memcpy(((OCDiscoveryPayload*)payload)->sid, OCGetServerInstanceID(), UUID_SIZE);
+ ((OCDiscoveryPayload*)payload)->sid = (char *)OICCalloc(1, UUID_STRING_SIZE);
+ VERIFY_NON_NULL(((OCDiscoveryPayload*)payload)->sid, ERROR, OC_STACK_NO_MEMORY);
+ memcpy(((OCDiscoveryPayload*)payload)->sid, OCGetServerInstanceIDString(), UUID_STRING_SIZE);
bool foundResourceAtRD = false;
for(;resource && discoveryResult == OC_STACK_OK; resource = resource->next)
}
else if (virtualUriInRequest == OC_DEVICE_URI)
{
- const OicUuid_t* deviceId = OCGetServerInstanceID();
+ const char* deviceId = OCGetServerInstanceIDString();
if (!deviceId)
{
discoveryResult = OC_STACK_ERROR;
}
else
{
- payload = (OCPayload*) OCDevicePayloadCreate((const uint8_t*) &deviceId->id, savedDeviceInfo.deviceName,
+ payload = (OCPayload*) OCDevicePayloadCreate(deviceId, savedDeviceInfo.deviceName,
OC_SPEC_VERSION, OC_DATA_MODEL_VERSION);
if (!payload)
{
VERIFY_SUCCESS(res, OC_STACK_OK);
- if(OCGetServerInstanceID() == NULL)
+ if (OCGetServerInstanceIDString() == NULL)
{
OIC_LOG(INFO, TAG, "Device ID generation failed");
res = OC_STACK_ERROR;
return OC_STACK_NO_MEMORY;
}
-const OicUuid_t* OCGetServerInstanceID(void)
+static const OicUuid_t* OCGetServerInstanceID(void)
{
static bool generated = false;
static OicUuid_t sid;
return &sid;
}
- if (GetDoxmDeviceID(&sid) != OC_STACK_OK)
+ if (RAND_UUID_OK != OCGenerateUuid(sid.id))
{
OIC_LOG(FATAL, TAG, "Generate UUID for Server Instance failed!");
return NULL;
return sidStr;
}
- const OicUuid_t* sid = OCGetServerInstanceID();
-
+ const OicUuid_t *sid = OCGetServerInstanceID();
if(OCConvertUuidToString(sid->id, sidStr) != RAND_UUID_OK)
{
OIC_LOG(FATAL, TAG, "Generate UUID String for Server Instance failed!");
{
while(res)
{
- char uuidString[UUID_STRING_SIZE];
- if(OCConvertUuidToString(payload->sid, uuidString) != RAND_UUID_OK)
- {
- uuidString[0]= '\0';
- }
-
if (res->secure)
{
m_devAddr.flags =
m_resources.push_back(std::shared_ptr<OC::OCResource>(
new OC::OCResource(m_clientWrapper, rdPubAddr,
std::string(res->uri),
- std::string((char*)uuidString),
+ std::string(payload->sid),
(res->bitmap & OC_OBSERVABLE) == OC_OBSERVABLE,
StringLLToVector(res->types),
StringLLToVector(res->interfaces)
m_resources.push_back(std::shared_ptr<OC::OCResource>(
new OC::OCResource(m_clientWrapper, m_devAddr,
std::string(res->uri),
- std::string(uuidString),
+ std::string(payload->sid),
(res->bitmap & OC_OBSERVABLE) == OC_OBSERVABLE,
StringLLToVector(res->types),
StringLLToVector(res->interfaces)
}
OCRepresentation rep;
- char uuidString[UUID_STRING_SIZE];
- if (payload->sid && RAND_UUID_OK == OCConvertUuidToString(payload->sid, uuidString))
- {
- rep[OC_RSRVD_DEVICE_ID] = std::string(uuidString);
- }
- else
- {
- rep[OC_RSRVD_DEVICE_ID] = std::string();
- }
+ rep[OC_RSRVD_DEVICE_ID] = (payload->sid) ?
+ std::string(payload->sid) :
+ std::string();
rep[OC_RSRVD_DEVICE_NAME] = payload->deviceName ?
std::string(payload->deviceName) :
std::string();
#include <OCApi.h>
#include <OCRepresentation.h>
#include <octypes.h>
+#include <ocstack.h>
#include <ocpayload.h>
#include <ocpayloadcbor.h>
#include <oic_malloc.h>
// CBOR->OCPayload and OCPayload->OCRepresentation conversions
namespace OCRepresentationEncodingTest
{
- static const uint8_t sid1[] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16};
+ static const char *sid1 = OCGetServerInstanceIDString();
static const char devicename1[] = "device name";
static const char specver1[] = "spec version";
static const char dmver1[] = "data model version";
devicename1,
specver1,
dmver1);
-
+ EXPECT_STREQ(sid1, device->sid);
EXPECT_STREQ(devicename1, device->deviceName);
EXPECT_STREQ(specver1, device->specVersion);
EXPECT_STREQ(dmver1, device->dataModelVersion);
EXPECT_EQ(PAYLOAD_TYPE_DEVICE, ((OCPayload*)device)->type);
- for (uint8_t i = 1; i <= sizeof(sid1); ++i)
- {
- EXPECT_EQ(i, sid1[i - 1]);
- }
-
uint8_t* cborData;
size_t cborSize;
OCPayload* parsedDevice;
cborData, cborSize));
OICFree(cborData);
+ EXPECT_STREQ(device->sid, ((OCDevicePayload*)parsedDevice)->sid);
EXPECT_STREQ(device->deviceName, ((OCDevicePayload*)parsedDevice)->deviceName);
EXPECT_STREQ(device->specVersion, ((OCDevicePayload*)parsedDevice)->specVersion);
EXPECT_STREQ(device->dataModelVersion, ((OCDevicePayload*)parsedDevice)->dataModelVersion);
mc.setPayload(parsedDevice);
EXPECT_EQ(1u, mc.representations().size());
const OC::OCRepresentation& r = mc.representations()[0];
+ EXPECT_STREQ(sid1, r.getValue<std::string>(OC_RSRVD_DEVICE_ID).c_str());
EXPECT_STREQ(devicename1, r.getValue<std::string>(OC_RSRVD_DEVICE_NAME).c_str());
EXPECT_STREQ(specver1, r.getValue<std::string>(OC_RSRVD_SPEC_VERSION).c_str());
EXPECT_STREQ(dmver1, r.getValue<std::string>(OC_RSRVD_DATA_MODEL_VERSION).c_str());
{
OCDiscoveryPayload* payload = OCDiscoveryPayloadCreate();
OCResourcePayload* resource = (OCResourcePayload*)OICCalloc(1, sizeof(OCResourcePayload));
- payload->sid = (uint8_t*)OICMalloc(16);
+ payload->sid = OICStrdup(sid1);
payload->resources = resource;
EXPECT_TRUE(OCResourcePayloadAddStringLL(&resource->types, "rt.singleitem"));
EXPECT_EQ(1u, OCDiscoveryPayloadGetResourceCount((OCDiscoveryPayload*)cparsed));
OCResourcePayload* parsedResource = ((OCDiscoveryPayload*)cparsed)->resources;
+ EXPECT_STREQ(sid1, ((OCDiscoveryPayload*)cparsed)->sid);
EXPECT_EQ(NULL, parsedResource->next);
EXPECT_STREQ("rt.singleitem", parsedResource->types->value);
EXPECT_EQ(NULL, parsedResource->types->next);
TEST(DiscoveryRTandIF, SingleItemFrontTrim)
{
OCDiscoveryPayload* payload = OCDiscoveryPayloadCreate();
- payload->sid = (uint8_t*)OICMalloc(16);
+ payload->sid = OICStrdup(sid1);
OCResourcePayload* resource = (OCResourcePayload*)OICCalloc(1, sizeof(OCResourcePayload));
payload->resources = resource;
OCResourcePayload* parsedResource = ((OCDiscoveryPayload*)cparsed)->resources;
EXPECT_EQ(NULL, parsedResource->next);
-
+ EXPECT_STREQ(sid1, ((OCDiscoveryPayload*)cparsed)->sid);
EXPECT_EQ(NULL, parsedResource->types->next);
EXPECT_STREQ("rt.singleitem", parsedResource->types->value);
EXPECT_EQ(NULL, parsedResource->interfaces->next);
TEST(DiscoveryRTandIF, SingleItemBackTrim)
{
OCDiscoveryPayload* payload = OCDiscoveryPayloadCreate();
- payload->sid = (uint8_t*)OICMalloc(16);
+ payload->sid = OICStrdup(sid1);
OCResourcePayload* resource = (OCResourcePayload*)OICCalloc(1, sizeof(OCResourcePayload));
payload->resources = resource;
OCResourcePayload* parsedResource = ((OCDiscoveryPayload*)cparsed)->resources;
EXPECT_EQ(NULL, parsedResource->next);
-
+ EXPECT_STREQ(sid1, ((OCDiscoveryPayload*)cparsed)->sid);
EXPECT_EQ(NULL, parsedResource->types->next);
EXPECT_STREQ("rt.singleitem", parsedResource->types->value);
EXPECT_EQ(NULL, parsedResource->interfaces->next);
TEST(DiscoveryRTandIF, SingleItemBothTrim)
{
OCDiscoveryPayload* payload = OCDiscoveryPayloadCreate();
- payload->sid = (uint8_t*)OICMalloc(16);
+ payload->sid = OICStrdup(sid1);
OCResourcePayload* resource = (OCResourcePayload*)OICCalloc(1, sizeof(OCResourcePayload));
payload->resources = resource;
OCResourcePayload* parsedResource = ((OCDiscoveryPayload*)cparsed)->resources;
EXPECT_EQ(NULL, parsedResource->next);
-
+ EXPECT_STREQ(sid1, ((OCDiscoveryPayload*)cparsed)->sid);
EXPECT_EQ(NULL, parsedResource->types->next);
EXPECT_STREQ("rt.singleitem", parsedResource->types->value);
EXPECT_EQ(NULL, parsedResource->interfaces->next);
TEST(DiscoveryRTandIF, MultiItemsNormal)
{
OCDiscoveryPayload* payload = OCDiscoveryPayloadCreate();
- payload->sid = (uint8_t*)OICMalloc(16);
+ payload->sid = OICStrdup(sid1);
OCResourcePayload* resource = (OCResourcePayload*)OICCalloc(1, sizeof(OCResourcePayload));
payload->resources = resource;
OCResourcePayload* parsedResource = ((OCDiscoveryPayload*)cparsed)->resources;
EXPECT_EQ(NULL, parsedResource->next);
-
+ EXPECT_STREQ(sid1, ((OCDiscoveryPayload*)cparsed)->sid);
EXPECT_EQ(NULL, parsedResource->types->next->next);
EXPECT_STREQ("rt.firstitem", parsedResource->types->value);
EXPECT_STREQ("rt.seconditem", parsedResource->types->next->value);
TEST(DiscoveryRTandIF, MultiItemExtraLeadSpaces)
{
OCDiscoveryPayload* payload = OCDiscoveryPayloadCreate();
- payload->sid = (uint8_t*)OICMalloc(16);
+ payload->sid = OICStrdup(sid1);
OCResourcePayload* resource = (OCResourcePayload*)OICCalloc(1, sizeof(OCResourcePayload));
payload->resources = resource;
OCResourcePayload* parsedResource = ((OCDiscoveryPayload*)cparsed)->resources;
EXPECT_EQ(NULL, parsedResource->next);
-
+ EXPECT_STREQ(sid1, ((OCDiscoveryPayload*)cparsed)->sid);
EXPECT_EQ(NULL, parsedResource->types->next->next);
EXPECT_STREQ("rt.firstitem", parsedResource->types->value);
EXPECT_STREQ("rt.seconditem", parsedResource->types->next->value);
TEST(DiscoveryRTandIF, MultiItemExtraTrailSpaces)
{
OCDiscoveryPayload* payload = OCDiscoveryPayloadCreate();
- payload->sid = (uint8_t*)OICMalloc(16);
+ payload->sid = OICStrdup(sid1);
OCResourcePayload* resource = (OCResourcePayload*)OICCalloc(1, sizeof(OCResourcePayload));
payload->resources = resource;
OCResourcePayload* parsedResource = ((OCDiscoveryPayload*)cparsed)->resources;
EXPECT_EQ(NULL, parsedResource->next);
-
+ EXPECT_STREQ(sid1, ((OCDiscoveryPayload*)cparsed)->sid);
EXPECT_EQ(NULL, parsedResource->types->next->next);
EXPECT_STREQ("rt.firstitem", parsedResource->types->value);
EXPECT_STREQ("rt.seconditem", parsedResource->types->next->value);
TEST(DiscoveryRTandIF, MultiItemBothSpaces)
{
OCDiscoveryPayload* payload = OCDiscoveryPayloadCreate();
- payload->sid = (uint8_t*)OICMalloc(16);
+ payload->sid = OICStrdup(sid1);
OCResourcePayload* resource = (OCResourcePayload*)OICCalloc(1, sizeof(OCResourcePayload));
payload->resources = resource;
OCResourcePayload* parsedResource = ((OCDiscoveryPayload*)cparsed)->resources;
EXPECT_EQ(NULL, parsedResource->next);
-
+ EXPECT_STREQ(sid1, ((OCDiscoveryPayload*)cparsed)->sid);
EXPECT_EQ(NULL, parsedResource->types->next->next);
EXPECT_STREQ("rt.firstitem", parsedResource->types->value);
EXPECT_STREQ("rt.seconditem", parsedResource->types->next->value);