else // PUT/POST JSON will not have deviceID so set it to the gDoxm->deviceID.id
{
VERIFY_NON_NULL(TAG, gDoxm, ERROR);
- VERIFY_SUCCESS(TAG, strcmp((char *)gDoxm->deviceID.id, "") != 0, ERROR);
- strncpy((char *)doxm->deviceID.id, (char *)gDoxm->deviceID.id, sizeof(doxm->deviceID.id));
+ memcpy((char *)doxm->deviceID.id, (char *)gDoxm->deviceID.id, sizeof(doxm->deviceID.id));
}
//Owner -- will be empty when device status is unowned.
* Once DeviceID is assigned to the device it does not change for the lifetime of the device.
*
*/
-void CheckDeviceID()
+static OCStackResult CheckDeviceID()
{
- if(strcmp((char *)gDoxm->deviceID.id, "") == 0 )
+ OCStackResult ret = OC_STACK_ERROR;
+ bool validId = false;
+ for (uint8_t i = 0; i < UUID_LENGTH; i++)
+ {
+ if (gDoxm->deviceID.id[i] != 0)
+ {
+ validId = true;
+ break;
+ }
+ }
+
+ if (!validId)
+ {
+ if (OCGenerateUuid(gDoxm->deviceID.id) != RAND_UUID_OK)
+ {
+ OC_LOG(FATAL, TAG, PCF("Generate UUID for Server Instance failed!"));
+ return ret;
+ }
+ ret = OC_STACK_OK;
+
+ if (UpdatePersistentStorage(gDoxm))
+ {
+ //TODO: After registering PSI handler in all samples, do ret = OC_STACK_OK here.
+ OC_LOG(FATAL, TAG, PCF("UpdatePersistentStorage failed!"));
+ }
+ }
+ else
{
- OCFillRandomMem(gDoxm->deviceID.id, sizeof(gDoxm->deviceID.id));
- UpdatePersistentStorage(gDoxm);
+ ret = OC_STACK_OK;
}
+ return ret;
}
/**
{
gDoxm = GetDoxmDefault();
}
- CheckDeviceID();
- //Instantiate 'oic.sec.doxm'
- ret = CreateDoxmResource();
+ ret = CheckDeviceID();
+ if (ret == OC_STACK_OK)
+ {
+ //Instantiate 'oic.sec.doxm'
+ ret = CreateDoxmResource();
+ }
+ else
+ {
+ OC_LOG (ERROR, TAG, PCF("CheckDeviceID failed"));
+ }
OICFree(jsonSVRDatabase);
return ret;
}
#include "oic_string.h"
#include "ocserverrequest.h"
#include "secureresourcemanager.h"
+#include "doxmresource.h"
#include "cacommon.h"
#include "cainterface.h"
#include "ocpayload.h"
return OC_STACK_NO_MEMORY;
}
-const uint8_t* OCGetServerInstanceID(void)
+const OicUuid_t* OCGetServerInstanceID(void)
{
static bool generated = false;
- static ServerID sid;
- if(generated)
+ static OicUuid_t sid;
+ if (generated)
{
- return sid;
+ return &sid;
}
- if (OCGenerateUuid(sid) != RAND_UUID_OK)
+ if (GetDoxmDeviceID(&sid) != OC_STACK_OK)
{
OC_LOG(FATAL, TAG, PCF("Generate UUID for Server Instance failed!"));
return NULL;
}
generated = true;
- return sid;
+ return &sid;
}
const char* OCGetServerInstanceIDString(void)
return sidStr;
}
- const uint8_t* sid = OCGetServerInstanceID();
+ const OicUuid_t* sid = OCGetServerInstanceID();
- if(OCConvertUuidToString(sid, sidStr) != RAND_UUID_OK)
+ if(OCConvertUuidToString(sid->id, sidStr) != RAND_UUID_OK)
{
OC_LOG(FATAL, TAG, PCF("Generate UUID String for Server Instance failed!"));
return NULL;
const std::string gResourceInterface = DEFAULT_INTERFACE;
const uint8_t gResourceProperty = OC_DISCOVERABLE | OC_OBSERVABLE;
OCResourceHandle resourceHandle;
- //OCPersistent Storage Handlers
- static FILE* client_open(const char* /*path*/, const char *mode)
- {
- std::cout << "<===Opening SVR DB file = './oic_svr_db_client.json' with mode = '"<< mode<<"' "<<std::endl;
- return fopen("./oic_svr_db_client.json", mode);
- }
+ //OCPersistent Storage Handlers
+ static FILE* client_open(const char * /*path*/, const char *mode)
+ {
+ std::cout << "<===Opening SVR DB file = './oic_svr_db_client.json' with mode = '" << mode
+ << "' " << std::endl;
+ return fopen("./oic_svr_db_client.json", mode);
+ }
+ OCPersistentStorage gps {client_open, fread, fwrite, fclose, unlink };
+
// Callbacks
OCEntityHandlerResult entityHandler(std::shared_ptr<OCResourceRequest> /*request*/)
{
OCResourceHandle RegisterResource(std::string uri, std::string type, std::string iface)
{
- PlatformConfig cfg = {};
+ PlatformConfig cfg
+ { OC::ServiceType::OutOfProc, OC::ModeType::Server, "0.0.0.0", 0,
+ OC::QualityOfService::LowQos, &gps };
OCPlatform::Configure(cfg);
EXPECT_EQ(OC_STACK_OK,OCPlatform::registerResource(
resourceHandle, uri, type,
OCResourceHandle RegisterResource(std::string uri, std::string type)
{
- PlatformConfig cfg = {};
+ PlatformConfig cfg
+ { OC::ServiceType::OutOfProc, OC::ModeType::Server, "0.0.0.0", 0,
+ OC::QualityOfService::LowQos, &gps };
OCPlatform::Configure(cfg);
EXPECT_EQ(OC_STACK_OK, OCPlatform::registerResource(
resourceHandle, uri, type,
OCResourceHandle RegisterResource(std::string uri)
{
- PlatformConfig cfg = {};
+ PlatformConfig cfg
+ { OC::ServiceType::OutOfProc, OC::ModeType::Server, "0.0.0.0", 0,
+ OC::QualityOfService::LowQos, &gps };
OCPlatform::Configure(cfg);
EXPECT_EQ(OC_STACK_OK, OCPlatform::registerResource(
resourceHandle, uri, gResourceTypeName,
TEST(ConfigureTest, ConfigureServerOutProc)
{
- PlatformConfig cfg {
+ PlatformConfig cfg
+ {
OC::ServiceType::OutOfProc,
OC::ModeType::Server,
"0.0.0.0",
0,
- OC::QualityOfService::LowQos
+ OC::QualityOfService::LowQos, &gps
};
std::string uri = "/a/light67";
std::string type = "core.light";
OC::ModeType::Server,
"0.0.0.0",
0,
- OC::QualityOfService::LowQos
+ OC::QualityOfService::LowQos, &gps
};
OCPlatform::Configure(cfg);
std::string uri = "/a/light70";
std::string type = "core.light";
uint8_t gResourceProperty = 0;
- PlatformConfig cfg {
+ PlatformConfig cfg
+ {
OC::ServiceType::InProc,
OC::ModeType::Client,
"0.0.0.0",
0,
- OC::QualityOfService::LowQos
+ OC::QualityOfService::LowQos,
+ &gps
};
- OCPlatform::Configure(cfg);
EXPECT_NO_THROW(OCPlatform::registerResource(
resourceHandle, uri, type,
//PersistentStorageTest
TEST(ConfigureTest, ConfigurePersistentStorage)
{
- OCPersistentStorage ps {client_open, fread, fwrite, fclose, unlink };
- PlatformConfig cfg {
+ PlatformConfig cfg {
OC::ServiceType::InProc,
OC::ModeType::Both,
"0.0.0.0",
0,
OC::QualityOfService::LowQos,
- &ps
+ &gps
};
OCPlatform::Configure(cfg);
EXPECT_NO_THROW(OCPlatform::setDefaultDeviceEntityHandler(nullptr));
//PersistentStorageTest
TEST(ConfigureTest, ConfigureNULLHandlersPersistentStorage)
{
- OCPersistentStorage ps {client_open, nullptr, nullptr, nullptr, nullptr };
PlatformConfig cfg {
OC::ServiceType::InProc,
OC::ModeType::Both,
"0.0.0.0",
0,
OC::QualityOfService::LowQos,
- &ps
+ &gps
};
OCPlatform::Configure(cfg);
EXPECT_NO_THROW(OCPlatform::setDefaultDeviceEntityHandler(nullptr));
OCDeviceInfo deviceInfo;
DuplicateString(&deviceInfo.deviceName, "myDeviceName");
-
EXPECT_EQ(OC_STACK_OK, OCPlatform::registerDeviceInfo(deviceInfo));
EXPECT_NO_THROW(DeleteDeviceInfo(deviceInfo));
}