Commit e64d33ff authored by Iurii Metelytsia's avatar Iurii Metelytsia Committed by Nathan Heldt-Sheller

[IOT-3284] IoTivity does not delete cloud account

SignOut flow was modified.
Signed-off-by: default avatarIurii Metelytsia <i.metelytsia@samsung.com>
Change-Id: Ica23a52b5f675971bfd11f73b47dddbd4d0a7442
parent ebbaa348
...@@ -85,6 +85,7 @@ struct OicCloud ...@@ -85,6 +85,7 @@ struct OicCloud
oc_thread pid; oc_thread pid;
session_t *session; session_t *session;
OicCloud_t *next; OicCloud_t *next;
bool delete_after_signout;
}; };
#define OIC_JSON_CLOUDS_NAME "clouds" #define OIC_JSON_CLOUDS_NAME "clouds"
......
...@@ -56,17 +56,17 @@ OCStackResult CreateCloudResource(); ...@@ -56,17 +56,17 @@ OCStackResult CreateCloudResource();
bool UpdateCloudPersistentStorage(); bool UpdateCloudPersistentStorage();
/** /**
* SignOut & release clouds * SignOut from cloud accounts.
*/ */
void CloudsSignOut(); void CloudsSignOut();
/** /**
* Release cloud entries * SignOut/Delete cloud accounts and release cloud entries
*/ */
void ResetClouds(); void ResetClouds();
/** /**
* Delete clouds acount * Delete cloud accounts and release cloud entries.
*/ */
void DeleteCloudAccount(); void DeleteCloudAccount();
......
...@@ -1005,6 +1005,18 @@ static OCStackApplicationResult handleCloudSignOutResponse(void *ctx, ...@@ -1005,6 +1005,18 @@ static OCStackApplicationResult handleCloudSignOutResponse(void *ctx,
cloud->session = NULL; cloud->session = NULL;
cloud->stat = OC_CLOUD_PROV; 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__); OIC_LOG_V(DEBUG, TAG, "%s: OUT", __func__);
return ret; return ret;
...@@ -1147,11 +1159,15 @@ static OCStackApplicationResult handleCloudDeleteResponse(void *ctx, ...@@ -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, response, ERROR, OC_STACK_DELETE_TRANSACTION);
VERIFY_NOT_NULL_RETURN(TAG, cloud, 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; cloud->stat = OC_CLOUD_EXIT;
FreeCloud(cloud);
OIC_LOG_V(DEBUG, TAG, "%s: OUT", __func__); OIC_LOG_V(DEBUG, TAG, "%s: OUT", __func__);
return ret; return ret;
......
...@@ -64,32 +64,24 @@ static OicCloud_t gDefaultCloud = ...@@ -64,32 +64,24 @@ static OicCloud_t gDefaultCloud =
NULL, NULL,
NULL, 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__); 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; OicCloud_t *p1 = NULL, *p2 = NULL;
oc_mutex_lock(gCloudMutex);
LL_FOREACH_SAFE(clouds, p1, p2) LL_FOREACH_SAFE(clouds, p1, p2)
{ {
if (signout) if (delete_after_signout)
{ {
OCCloudSignOut(p1); LL_DELETE(clouds, p1);
} }
LL_DELETE(clouds, p1); p1->delete_after_signout = delete_after_signout;
FreeCloud(p1); OCCloudSignOut(p1);
p1 = NULL;
} }
oc_mutex_unlock(gCloudMutex);
OIC_LOG_V(DEBUG, TAG, "%s: OUT", __func__); OIC_LOG_V(DEBUG, TAG, "%s: OUT", __func__);
} }
...@@ -98,20 +90,14 @@ void CloudsSignOut() ...@@ -98,20 +90,14 @@ void CloudsSignOut()
{ {
OIC_LOG_V(DEBUG, TAG, "%s: IN", __func__); OIC_LOG_V(DEBUG, TAG, "%s: IN", __func__);
oc_mutex_lock(gCloudMutex);
if (!gCloud) if (!gCloud)
{ {
OIC_LOG_V(WARNING, TAG, "%s: cloud is NULL", __func__); OIC_LOG_V(WARNING, TAG, "%s: cloud is NULL", __func__);
oc_mutex_unlock(gCloudMutex);
return; return;
} }
DeleteCloudList(gCloud, false);
OicCloud_t *p1 = NULL, *p2 = NULL;
oc_mutex_lock(gCloudMutex);
LL_FOREACH_SAFE(gCloud, p1, p2)
{
OCCloudSignOut(p1);
StopCloudRefresh(p1);
p1 = NULL;
}
oc_mutex_unlock(gCloudMutex); oc_mutex_unlock(gCloudMutex);
OIC_LOG_V(DEBUG, TAG, "%s: OUT", __func__); OIC_LOG_V(DEBUG, TAG, "%s: OUT", __func__);
...@@ -119,20 +105,43 @@ void CloudsSignOut() ...@@ -119,20 +105,43 @@ void CloudsSignOut()
void ResetClouds() 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; gCloud = NULL;
oc_mutex_unlock(gCloudMutex);
OIC_LOG_V(DEBUG, TAG, "%s: OUT", __func__);
} }
void DeleteCloudAccount() 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) static void *CloudWaitForRFNOP(void *data)
...@@ -537,6 +546,7 @@ static OCEntityHandlerResult HandleCloudDeleteRequest(OCEntityHandlerRequest *eh ...@@ -537,6 +546,7 @@ static OCEntityHandlerResult HandleCloudDeleteRequest(OCEntityHandlerRequest *eh
{ {
OIC_LOG_V(INFO, TAG, "%s: delete cloud: %s", __func__, p1->cis); OIC_LOG_V(INFO, TAG, "%s: delete cloud: %s", __func__, p1->cis);
p1->stat = OC_CLOUD_EXIT; p1->stat = OC_CLOUD_EXIT;
p1->delete_after_signout = true;
OCCloudSignOut(p1); OCCloudSignOut(p1);
LL_DELETE(gCloud, p1); LL_DELETE(gCloud, p1);
ehRet = OC_EH_OK; ehRet = OC_EH_OK;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment