[IOT-3284] IoTivity does not delete cloud account 21/29521/5
authorIurii Metelytsia <i.metelytsia@samsung.com>
Thu, 23 May 2019 14:40:09 +0000 (17:40 +0300)
committerNathan Heldt-Sheller <nathan.heldt-sheller@intel.com>
Wed, 24 Jul 2019 19:26:00 +0000 (19:26 +0000)
SignOut flow was modified.

Signed-off-by: Iurii Metelytsia <i.metelytsia@samsung.com>
Change-Id: Ica23a52b5f675971bfd11f73b47dddbd4d0a7442

resource/csdk/security/provisioning/include/cloud/auth.h
resource/csdk/security/provisioning/include/cloud/cloudresource.h
resource/csdk/security/provisioning/src/cloud/auth.c
resource/csdk/security/provisioning/src/cloud/cloudresource.c

index feca988..3d3ae0e 100644 (file)
@@ -85,6 +85,7 @@ struct OicCloud
     oc_thread   pid;
     session_t   *session;
     OicCloud_t  *next;
+    bool        delete_after_signout;
 };
 
 #define OIC_JSON_CLOUDS_NAME    "clouds"
index 1f7970f..5a44406 100644 (file)
@@ -56,17 +56,17 @@ OCStackResult CreateCloudResource();
 bool UpdateCloudPersistentStorage();
 
 /**
-* SignOut & release clouds
+* SignOut from cloud accounts.
 */
 void CloudsSignOut();
 
 /**
-* Release cloud entries
+* SignOut/Delete cloud accounts and release cloud entries
 */
 void ResetClouds();
 
 /**
-* Delete clouds acount
+* Delete cloud accounts and release cloud entries.
 */
 void DeleteCloudAccount();
 
index 243b0b4..c0880de 100644 (file)
@@ -1005,6 +1005,18 @@ static OCStackApplicationResult handleCloudSignOutResponse(void *ctx,
     cloud->session = NULL;
     cloud->stat = OC_CLOUD_PROV;
 
+    if (cloud->delete_after_signout)
+    {
+        if (OC_STACK_OK != OCCloudDelete(cloud))
+        {
+            OIC_LOG(ERROR, TAG, "cannot delete cloud");
+        }
+        else
+        {
+            OIC_LOG(DEBUG, TAG, "cloud deleted successfully");
+        }
+    }
+
     OIC_LOG_V(DEBUG, TAG, "%s: OUT", __func__);
 
     return ret;
@@ -1147,11 +1159,15 @@ static OCStackApplicationResult handleCloudDeleteResponse(void *ctx,
 
     VERIFY_NOT_NULL_RETURN(TAG, response, ERROR, OC_STACK_DELETE_TRANSACTION);
     VERIFY_NOT_NULL_RETURN(TAG, cloud, ERROR, OC_STACK_DELETE_TRANSACTION);
-    VERIFY_NOT_NULL_RETURN(TAG, cloud->session, ERROR, OC_STACK_DELETE_TRANSACTION);
+    if (!cloud->session)
+    {
+        OIC_LOG_V(DEBUG, TAG, "%s: session already deleted", __func__);
+    }
 
-    OIC_LOG_V(ERROR, TAG, "%s: response result: %d", __func__, response->result);
+    OIC_LOG_V(DEBUG, TAG, "%s: response result: %d", __func__, response->result);
 
     cloud->stat = OC_CLOUD_EXIT;
+    FreeCloud(cloud);
 
     OIC_LOG_V(DEBUG, TAG, "%s: OUT", __func__);
     return ret;
index 121e0de..e4bca1a 100644 (file)
@@ -64,32 +64,24 @@ static OicCloud_t gDefaultCloud =
     NULL,
     NULL,
     NULL,
-    NULL
+    NULL,
+    false
 };
 
-static void DeleteCloudList(OicCloud_t *clouds, bool signout)
+static void DeleteCloudList(OicCloud_t *clouds, bool delete_after_signout)
 {
     OIC_LOG_V(DEBUG, TAG, "%s: IN", __func__);
 
-    if (!clouds)
-    {
-        OIC_LOG_V(WARNING, TAG, "%s: cloud is NULL", __func__);
-        return;
-    }
-
     OicCloud_t *p1 = NULL, *p2 = NULL;
-    oc_mutex_lock(gCloudMutex);
     LL_FOREACH_SAFE(clouds, p1, p2)
     {
-        if (signout)
+        if (delete_after_signout)
         {
-            OCCloudSignOut(p1);
+            LL_DELETE(clouds, p1);
         }
-        LL_DELETE(clouds, p1);
-        FreeCloud(p1);
-        p1 = NULL;
+        p1->delete_after_signout = delete_after_signout;
+        OCCloudSignOut(p1);
     }
-    oc_mutex_unlock(gCloudMutex);
 
     OIC_LOG_V(DEBUG, TAG, "%s: OUT", __func__);
 }
@@ -98,20 +90,14 @@ void CloudsSignOut()
 {
     OIC_LOG_V(DEBUG, TAG, "%s: IN", __func__);
 
+    oc_mutex_lock(gCloudMutex);
     if (!gCloud)
     {
         OIC_LOG_V(WARNING, TAG, "%s: cloud is NULL", __func__);
+        oc_mutex_unlock(gCloudMutex);
         return;
     }
-
-    OicCloud_t *p1 = NULL, *p2 = NULL;
-    oc_mutex_lock(gCloudMutex);
-    LL_FOREACH_SAFE(gCloud, p1, p2)
-    {
-        OCCloudSignOut(p1);
-        StopCloudRefresh(p1);
-        p1 = NULL;
-    }
+    DeleteCloudList(gCloud, false);
     oc_mutex_unlock(gCloudMutex);
 
     OIC_LOG_V(DEBUG, TAG, "%s: OUT", __func__);
@@ -119,20 +105,43 @@ void CloudsSignOut()
 
 void ResetClouds()
 {
-    DeleteCloudList(gCloud, false);
+    OIC_LOG_V(DEBUG, TAG, "%s: IN", __func__);
+
+    oc_mutex_lock(gCloudMutex);
+    if (!gCloud)
+    {
+        OIC_LOG_V(WARNING, TAG, "%s: cloud is NULL", __func__);
+        oc_mutex_unlock(gCloudMutex);
+        return;
+    }
+    DeleteCloudList(gCloud, true);
     gCloud = NULL;
+    oc_mutex_unlock(gCloudMutex);
+
+    OIC_LOG_V(DEBUG, TAG, "%s: OUT", __func__);
 }
 
 void DeleteCloudAccount()
 {
-    if ( OC_STACK_OK != OCCloudDelete(gCloud))
+    OIC_LOG_V(DEBUG, TAG, "%s: IN", __func__);
+
+    oc_mutex_lock(gCloudMutex);
+    if (!gCloud)
     {
-        OIC_LOG_V(ERROR, TAG, "%s: cannot delete cloud", __func__);
+        OIC_LOG_V(WARNING, TAG, "%s: cloud is NULL", __func__);
+        oc_mutex_unlock(gCloudMutex);
+        return;
     }
-    else
+    OicCloud_t *p1 = NULL, *p2 = NULL;
+    LL_FOREACH_SAFE(gCloud, p1, p2)
     {
-        OIC_LOG_V(ERROR, TAG, "%s: cloud is deleted", __func__);
+        LL_DELETE(gCloud, p1);
+        OCCloudDelete(p1);
     }
+    gCloud = NULL;
+    oc_mutex_unlock(gCloudMutex);
+
+    OIC_LOG_V(DEBUG, TAG, "%s: OUT", __func__);
 }
 
 static void *CloudWaitForRFNOP(void *data)
@@ -537,6 +546,7 @@ static OCEntityHandlerResult HandleCloudDeleteRequest(OCEntityHandlerRequest *eh
         {
             OIC_LOG_V(INFO, TAG, "%s: delete cloud: %s", __func__, p1->cis);
             p1->stat = OC_CLOUD_EXIT;
+            p1->delete_after_signout = true;
             OCCloudSignOut(p1);
             LL_DELETE(gCloud, p1);
             ehRet = OC_EH_OK;