*/
void PDMDestoryStaleLinkList(OCPairList_t* ptr);
+/**
+ * This method is used by provisioning manager to check does the link exists between
+ * two devices or not.
+ *
+ * @param[in] uuidOfDevice1 UUID of device1.
+ * @param[in] uuidOfDevice2 UUID of device2.
+ * @param[out] result true when link exists otherwise false.
+ *
+ * @return OC_STACK_OK in case of success and other value otherwise.
+ */
+OCStackResult PDMIsLinkExists(const OicUuid_t* uuidOfDevice1, const OicUuid_t* uuidOfDevice2,
+ bool *result );
+
#ifdef __cplusplus
}
#endif
OC_LOG(INFO, TAG, "OCProvisionPairwiseDevices : Invalid key size");
return OC_STACK_INVALID_PARAM;
}
+
+ OC_LOG(DEBUG, TAG, "Checking link in DB");
+ bool linkExists = true;
+ OCStackResult res = PDMIsLinkExists(&pDev1->doxm->deviceID, &pDev2->doxm->deviceID, &linkExists);
+ if(res != OC_STACK_OK)
+ {
+ OC_LOG(ERROR, TAG, "Internal Error Occured");
+ return res;
+ }
+ if (linkExists)
+ {
+ OC_LOG(ERROR, TAG, "Link already exists");
+ return OC_STACK_INVALID_PARAM;
+ }
+
int noOfResults = 2; // Initial Value
- if (NULL!=pDev1Acl)
+ if (NULL != pDev1Acl)
{
++noOfResults;
}
- if (NULL!=pDev2Acl)
+ if (NULL != pDev2Acl)
{
++noOfResults;
}
link->resultCallback = resultCallback;
link->currentCountResults = 0;
link->resArr = (OCProvisionResult_t*) OICMalloc(sizeof(OCProvisionResult_t)*noOfResults);
- OCStackResult res = SRPProvisionCredentials(link, type, keySize,
+ res = SRPProvisionCredentials(link, type, keySize,
pDev1, pDev2, &ProvisionCredsCB);
if (res != OC_STACK_OK)
{
{
return SRPProvisionCRL(ctx, selectedDeviceInfo, crl, resultCallback);
}
-#endif // __WITH_X509__
\ No newline at end of file
+#endif // __WITH_X509__
+
}
}
}
+
+OCStackResult PDMIsLinkExists(const OicUuid_t* uuidOfDevice1, const OicUuid_t* uuidOfDevice2,
+ bool* result)
+{
+ CHECK_PDM_INIT(TAG);
+ if (NULL == uuidOfDevice1 || NULL == uuidOfDevice2 || NULL == result)
+ {
+ return OC_STACK_INVALID_PARAM;
+ }
+ int id1 = 0;
+ int id2 = 0;
+ if (OC_STACK_OK != getIdForUUID(uuidOfDevice1, &id1))
+ {
+ OC_LOG(ERROR, TAG, "Requested value not found");
+ return OC_STACK_INVALID_PARAM;
+ }
+
+ if (OC_STACK_OK != getIdForUUID(uuidOfDevice2, &id2))
+ {
+ OC_LOG(ERROR, TAG, "Requested value not found");
+ return OC_STACK_INVALID_PARAM;
+ }
+
+ ASCENDING_ORDER(id1, id2);
+
+ sqlite3_stmt *stmt = 0;
+ int res = 0;
+ res = sqlite3_prepare_v2(g_db, PDM_SQLITE_GET_LINKED_DEVICES,
+ strlen(PDM_SQLITE_GET_LINKED_DEVICES) + 1, &stmt, NULL);
+ PDM_VERIFY_SQLITE_OK(TAG, res, ERROR, OC_STACK_ERROR);
+
+ res = sqlite3_bind_int(stmt, PDM_BIND_INDEX_FIRST, id1);
+ PDM_VERIFY_SQLITE_OK(TAG, res, ERROR, OC_STACK_ERROR);
+
+ res = sqlite3_bind_int(stmt, PDM_BIND_INDEX_SECOND, id2);
+ PDM_VERIFY_SQLITE_OK(TAG, res, ERROR, OC_STACK_ERROR);
+
+ bool ret = false;
+ while(SQLITE_ROW == sqlite3_step(stmt))
+ {
+ OC_LOG(INFO, TAG, "Link already exists between devices");
+ ret = true;
+ }
+ sqlite3_finalize(stmt);
+ *result = ret;
+ return OC_STACK_OK;
+}
OC_LOG(INFO, TAG, "In SRPProvisionCredentials");
+ bool linkExisits = true;
+ OCStackResult res = PDMIsLinkExists(&pDev1->doxm->deviceID, &pDev2->doxm->deviceID, &linkExisits);
+ if (res != OC_STACK_OK)
+ {
+ OC_LOG(ERROR, TAG, "Internal error occured");
+ return res;
+ }
+ if (linkExisits)
+ {
+ OC_LOG(ERROR, TAG, "Link already exists");
+ return OC_STACK_INVALID_PARAM;
+ }
+
OicUuid_t provTooldeviceID = {{0,}};
if (OC_STACK_OK != GetDoxmDeviceID(&provTooldeviceID))
{
const char ID_4[] = "4111111111111111";
const char ID_5[] = "5111111111111111";
const char ID_6[] = "6111111111111111";
+const char ID_7[] = "7777777777777777";
+const char ID_8[] = "8777777777777777";
TEST(CallPDMAPIbeforeInit, BeforeInit)
{
EXPECT_EQ(OC_STACK_PDM_IS_NOT_INITIALIZED, PDMGetLinkedDevices(NULL, NULL, NULL));
EXPECT_EQ(OC_STACK_PDM_IS_NOT_INITIALIZED, PDMSetLinkStale(NULL, NULL));
EXPECT_EQ(OC_STACK_PDM_IS_NOT_INITIALIZED, PDMGetToBeUnlinkedDevices(NULL, NULL));
+ EXPECT_EQ(OC_STACK_PDM_IS_NOT_INITIALIZED, PDMIsLinkExists(NULL, NULL, NULL));
}
TEST(PDMInitTest, PDMInitWithNULL)
{
PDMDestoryStaleLinkList(NULL);
}
+
+TEST(PDMIsLinkExistsTest, DuplicateID)
+{
+ EXPECT_EQ(OC_STACK_OK, PDMInit(NULL));
+ OicUuid_t uid1 = {{0,}};
+ memcpy(&uid1.id, ID_7, sizeof(uid1.id));
+ EXPECT_EQ(OC_STACK_OK, PDMAddDevice(&uid1));
+ OicUuid_t uid2 = {{0,}};
+ memcpy(&uid2.id, ID_8, sizeof(uid2.id));
+ EXPECT_EQ(OC_STACK_OK, PDMAddDevice(&uid2));
+
+ bool linkExisits = true;
+ OCStackResult res = PDMIsLinkExists(&uid1, &uid2, &linkExisits);
+ EXPECT_EQ(OC_STACK_OK, res);
+ EXPECT_FALSE(linkExisits);
+}
\ No newline at end of file