Fixed wrong return type in PDM
authorRandeep Singh <randeep.s@samsung.com>
Fri, 18 Sep 2015 10:36:25 +0000 (19:36 +0900)
committerSachin Agrawal <sachin.agrawal@intel.com>
Thu, 24 Sep 2015 16:01:50 +0000 (16:01 +0000)
PDMIsDuplicateDevice API declaration returns null but function defination
have conditions which returns other values.

Change-Id: I3bab66243fb03908072d16dbc64cc4e8823755ad
Signed-off-by: Randeep Singh <randeep.s@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/2895
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Woochul Shim <woochul.shim@samsung.com>
Reviewed-by: Sachin Agrawal <sachin.agrawal@intel.com>
resource/csdk/security/provisioning/include/internal/provisioningdatabasemanager.h
resource/csdk/security/provisioning/src/ownershiptransfermanager.c
resource/csdk/security/provisioning/src/provisioningdatabasemanager.c
resource/csdk/security/provisioning/unittest/provisioningdatabasemanager.cpp

index 3d3f2d4..6a31a91 100644 (file)
@@ -43,10 +43,11 @@ OCStackResult PDMInit(const char* dbPath);
  * provisioning database.
  *
  * @param[in] uuidOfDevice information about the target device's uuid.
+ * @param[out] result true in case device UUID already exist otherwise false.
  *
- * @return false when non-duplication and true when duplication or uuidOfDevicea is NULL .
+ * @return OC_STACK_OK in case of success and other value otherwise.
  */
-bool PDMIsDuplicateDevice(const OicUuid_t* uuidOfDevice);
+OCStackResult PDMIsDuplicateDevice(const OicUuid_t* uuidOfDevice, bool* result);
 
 /**
  * This method is used by provisioning manager to add owned device's Device ID.
index 764172c..a34894d 100644 (file)
@@ -920,9 +920,17 @@ OCStackResult OTMDoOwnershipTransfer(void* ctx,
     for(size_t devIdx = 0; devIdx < otmCtx->ctxResultArraySize; devIdx++)
     {
         //Checking duplication of Device ID.
-        if(true == PDMIsDuplicateDevice(&pCurDev->doxm->deviceID))
+        bool isDuplicate = true;
+        OCStackResult res = PDMIsDuplicateDevice(&pCurDev->doxm->deviceID, &isDuplicate);
+        if (OC_STACK_OK != res)
+        {
+            OICFree(otmCtx->ctxResultArray);
+            OICFree(otmCtx);
+            return res;
+        }
+        if (isDuplicate)
         {
-            OC_LOG(ERROR, TAG, "OTMDoOwnershipTransfer : Device ID is duplicate");
+            OC_LOG(ERROR, TAG, "OTMDoOwnershipTransfer : Device ID is duplicated");
             OICFree(otmCtx->ctxResultArray);
             OICFree(otmCtx);
             return OC_STACK_INVALID_PARAM;
index cec8a36..6e4035e 100644 (file)
@@ -243,37 +243,34 @@ static OCStackResult getIdForUUID(const OicUuid_t *UUID , int *id)
 /**
  * Function to check duplication of device's Device ID.
  */
-bool PDMIsDuplicateDevice(const OicUuid_t* UUID)
+OCStackResult PDMIsDuplicateDevice(const OicUuid_t* UUID, bool *result)
 {
-    if(gInit)
-    {
-        if (NULL == UUID)
-        {
-            OC_LOG(ERROR, TAG, "UUID is NULL");
-            return true;
-        }
 
-        sqlite3_stmt *stmt = 0;
-        int res = 0;
-        res = sqlite3_prepare_v2(g_db, PDM_SQLITE_GET_ID, strlen(PDM_SQLITE_GET_ID) + 1, &stmt, NULL);
-        PDM_VERIFY_SQLITE_OK(TAG, res, ERROR, OC_STACK_ERROR);
-
-        res = sqlite3_bind_blob(stmt, PDM_BIND_INDEX_FIRST, UUID, UUID_LENGTH, SQLITE_STATIC);
-        PDM_VERIFY_SQLITE_OK(TAG, res, ERROR, OC_STACK_ERROR);
+    CHECK_PDM_INIT(TAG);
+    if (NULL == UUID || NULL == result)
+    {
+        OC_LOG(ERROR, TAG, "UUID or result is NULL");
+        return OC_STACK_INVALID_PARAM;
+    }
+    sqlite3_stmt *stmt = 0;
+    int res = 0;
+    res = sqlite3_prepare_v2(g_db, PDM_SQLITE_GET_ID, strlen(PDM_SQLITE_GET_ID) + 1, &stmt, NULL);
+    PDM_VERIFY_SQLITE_OK(TAG, res, ERROR, OC_STACK_ERROR);
 
-        OC_LOG(DEBUG, TAG, "Binding Done");
+    res = sqlite3_bind_blob(stmt, PDM_BIND_INDEX_FIRST, UUID, UUID_LENGTH, SQLITE_STATIC);
+    PDM_VERIFY_SQLITE_OK(TAG, res, ERROR, OC_STACK_ERROR);
 
-        while (SQLITE_ROW == sqlite3_step(stmt))
-        {
-            OC_LOG(ERROR, TAG, "UUID is duplicated");
-            sqlite3_finalize(stmt);
-            return true;
-        }
-        sqlite3_finalize(stmt);
-        return false;
+    OC_LOG(DEBUG, TAG, "Binding Done");
+    bool retValue = false;
+    while(SQLITE_ROW == sqlite3_step(stmt))
+    {
+        OC_LOG(INFO, TAG, "Duplicated UUID");
+        retValue = true;
     }
-    OC_LOG(ERROR, TAG, "PDB is not initialized");
-    return true; // return true will stop futher process.
+
+    sqlite3_finalize(stmt);
+    *result = retValue;
+    return OC_STACK_OK;
 }
 
 /**
index 63a4dd8..0a53e1f 100644 (file)
@@ -32,7 +32,7 @@ const char ID_8[] = "8777777777777777";
 TEST(CallPDMAPIbeforeInit, BeforeInit)
 {
     EXPECT_EQ(OC_STACK_PDM_IS_NOT_INITIALIZED, PDMAddDevice(NULL));
-    EXPECT_EQ(true, PDMIsDuplicateDevice(NULL)); // return type is not OCStackResult
+    EXPECT_EQ(OC_STACK_PDM_IS_NOT_INITIALIZED, PDMIsDuplicateDevice(NULL,NULL));
     EXPECT_EQ(OC_STACK_PDM_IS_NOT_INITIALIZED, PDMLinkDevices(NULL, NULL));
     EXPECT_EQ(OC_STACK_PDM_IS_NOT_INITIALIZED, PDMUnlinkDevices(NULL, NULL));
     EXPECT_EQ(OC_STACK_PDM_IS_NOT_INITIALIZED, PDMDeleteDevice(NULL));
@@ -55,7 +55,7 @@ TEST(PDMAddDeviceTest, NullUUID)
 
 TEST(PDMIsDuplicateDeviceTest, NullUUID)
 {
-    EXPECT_TRUE(PDMIsDuplicateDevice(NULL));
+    EXPECT_EQ(OC_STACK_INVALID_PARAM, PDMIsDuplicateDevice(NULL,NULL));
 }
 
 
@@ -69,9 +69,12 @@ TEST(PDMIsDuplicateDeviceTest, ValidUUID)
     PDMAddDevice(&uid2);
     OicUuid_t uid3 = {{0,}};
     memcpy(&uid3.id, ID_3, sizeof(uid3.id));
+    bool isDuplicate = true;
+    EXPECT_EQ(OC_STACK_OK, PDMIsDuplicateDevice(&uid1,&isDuplicate));
+    EXPECT_TRUE(isDuplicate);
 
-    EXPECT_TRUE(PDMIsDuplicateDevice(&uid1));
-    EXPECT_FALSE(PDMIsDuplicateDevice(&uid3));
+    EXPECT_EQ(OC_STACK_OK, PDMIsDuplicateDevice(&uid3, &isDuplicate));
+    EXPECT_FALSE(isDuplicate);
 }
 
 TEST(PDMAddDeviceTest, ValidUUID)
@@ -260,4 +263,4 @@ TEST(PDMIsLinkExistsTest, DuplicateID)
     OCStackResult res = PDMIsLinkExists(&uid1, &uid2, &linkExisits);
     EXPECT_EQ(OC_STACK_OK, res);
     EXPECT_FALSE(linkExisits);
-}
\ No newline at end of file
+}