#include "logger.h"
#include "oic_malloc.h"
#include "base64.h"
+#include "ocrandom.h"
#define TAG "OIC_SRM_UTILITY"
OCStackResult ConvertStrToUuid(const char* strUuid, OicUuid_t* uuid)
{
- if(NULL == strUuid || NULL == uuid)
- {
- OIC_LOG(ERROR, TAG, "ConvertStrToUuid : Invalid param");
- return OC_STACK_INVALID_PARAM;
- }
-
- size_t urnIdx = 0;
- size_t uuidIdx = 0;
- size_t strUuidLen = 0;
- char convertedUuid[UUID_LENGTH * 2] = {0};
-
- strUuidLen = strlen(strUuid);
- if(0 == strUuidLen)
- {
- OIC_LOG(INFO, TAG, "The empty string detected, The UUID will be converted to "\
- "\"00000000-0000-0000-0000-000000000000\"");
- }
- else if(UUID_LENGTH * 2 + 4 == strUuidLen)
- {
- for(uuidIdx=0, urnIdx=0; uuidIdx < UUID_LENGTH ; uuidIdx++, urnIdx+=2)
- {
- if(*(strUuid + urnIdx) == '-')
- {
- urnIdx++;
- }
- sscanf(strUuid + urnIdx, "%2hhx", &convertedUuid[uuidIdx]);
- }
- }
- else
- {
- OIC_LOG(ERROR, TAG, "Invalid string uuid format, Please set the uuid as correct format");
- OIC_LOG(ERROR, TAG, "e.g) \"72616E64-5069-6E44-6576-557569643030\" (4-2-2-2-6)");
- OIC_LOG(ERROR, TAG, "e.g) \"\"");
-
- return OC_STACK_INVALID_PARAM;
- }
-
- memcpy(uuid->id, convertedUuid, UUID_LENGTH);
-
- return OC_STACK_OK;
+ OCRandomUuidResult result = OCConvertStringToUuid(strUuid, uuid->id);
+ return (result == RAND_UUID_OK) ? OC_STACK_OK : OC_STACK_INVALID_PARAM;
}
goto exit;
}
+ /*
+ * @todo (IOT-1541) There are several versions of a UUID structure and conversion
+ * methods scattered around the IoTivity code base. They need to be combined
+ * into one PAL API.
+ */
+ uint8_t uuid[UUID_SIZE];
+ if (OCConvertStringToUuid(info.platformID, uuid) != RAND_UUID_OK)
+ {
+ OIC_LOG(ERROR, TAG, "Platform ID is not a UUID.");
+ goto exit;
+ }
+
resource = FindResourceByUri(OC_RSRVD_PLATFORM_URI);
if (!resource)
{
//-----------------------------------------------------------------------------
static const char TAG[] = "TestHarness";
-char gDeviceUUID[] = "myDeviceUUID";
+char gDeviceUUID[] = "fe3f9a68-4931-4cb0-9ea4-81702b43116c";
char gManufacturerName[] = "myName";
static OCPrm_t pmSel;
static char pinNumber;
EXPECT_EQ(OC_STACK_OK, OCStop());
}
+TEST(StackStart, SetPlatformInfoWithBadPlatformID)
+{
+ itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
+ EXPECT_EQ(OC_STACK_OK, OCInit("127.0.0.1", 5683, OC_SERVER));
+
+ OCPlatformInfo info =
+ {
+ "myDeviceUUID",
+ gManufacturerName,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0
+ };
+
+ EXPECT_EQ(OC_STACK_INVALID_PARAM, OCSetPlatformInfo(info));
+ EXPECT_EQ(OC_STACK_OK, OCStop());
+}
+
TEST(StackStart, SetPlatformInfoWithNoManufacturerName)
{
itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);