summaryrefslogtreecommitdiff
path: root/email-api/email-api-account.c
diff options
context:
space:
mode:
Diffstat (limited to 'email-api/email-api-account.c')
-rwxr-xr-xemail-api/email-api-account.c189
1 files changed, 151 insertions, 38 deletions
diff --git a/email-api/email-api-account.c b/email-api/email-api-account.c
index 08702c3..648e17f 100755
--- a/email-api/email-api-account.c
+++ b/email-api/email-api-account.c
@@ -29,7 +29,6 @@
* email-service .
*/
-#include "email-api.h"
#include "string.h"
#include "email-convert.h"
#include "email-api-account.h"
@@ -45,10 +44,11 @@
EXPORT_API int email_add_account(email_account_t* account)
{
EM_DEBUG_API_BEGIN ("account[%p]", account);
- char* local_account_stream = NULL;
int size = 0;
int err = EMAIL_ERROR_NONE;
int ret_from_ipc = EMAIL_ERROR_NONE;
+ char *multi_user_name = NULL;
+ char* local_account_stream = NULL;
HIPC_API hAPI = NULL;
if (account == NULL || account->user_email_address == NULL || account->incoming_server_user_name == NULL || account->incoming_server_address == NULL||
@@ -57,38 +57,53 @@ EXPORT_API int email_add_account(email_account_t* account)
return EMAIL_ERROR_INVALID_PARAM;
}
- if(emstorage_check_duplicated_account(account, true, &err) == false) {
+ if ((err = emipc_get_user_name(&multi_user_name)) != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("emipc_get_user_name failed : [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ if (!emstorage_check_duplicated_account(multi_user_name, account, true, &err)) {
EM_DEBUG_EXCEPTION("emstorage_check_duplicated_account failed (%d) ", err);
- return err;
+ goto FINISH_OFF;
}
/* composing account information to be added */
hAPI = emipc_create_email_api(_EMAIL_API_ADD_ACCOUNT);
- EM_IF_NULL_RETURN_VALUE(hAPI, EMAIL_ERROR_NULL_VALUE);
+ if (hAPI == NULL) {
+ EM_DEBUG_EXCEPTION("emipc_create_email_api failed");
+ err = EMAIL_ERROR_NULL_VALUE;
+ goto FINISH_OFF;
+ }
local_account_stream = em_convert_account_to_byte_stream(account, &size);
- EM_PROXY_IF_NULL_RETURN_VALUE(local_account_stream, hAPI, EMAIL_ERROR_NULL_VALUE);
+ if (local_account_stream == NULL) {
+ EM_DEBUG_EXCEPTION("em_convert_account_to_byte_stream failed");
+ err = EMAIL_ERROR_NULL_VALUE;
+ goto FINISH_OFF;
+ }
- if(!emipc_add_dynamic_parameter(hAPI, ePARAMETER_IN, local_account_stream, size)) {
+ if (!emipc_add_dynamic_parameter(hAPI, ePARAMETER_IN, local_account_stream, size)) {
EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
- EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
+ err = EMAIL_ERROR_NULL_VALUE;
+ goto FINISH_OFF;
}
EM_DEBUG_LOG("APPID[%d], APIID [%d]", emipc_get_app_id(hAPI), emipc_get_api_id(hAPI));
/* passing account information to service */
- if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
+ if (emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
- EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_IPC_SOCKET_FAILURE);
+ err = EMAIL_ERROR_IPC_SOCKET_FAILURE;
+ goto FINISH_OFF;
}
/* get result from service */
- if( (ret_from_ipc = emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err)) != EMAIL_ERROR_NONE) {
+ if ((ret_from_ipc = emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emipc_get_parameter failed [%d]", ret_from_ipc);
err = ret_from_ipc;
goto FINISH_OFF;
}
- if(err == EMAIL_ERROR_NONE) {
+ if (err == EMAIL_ERROR_NONE) {
emipc_get_parameter(hAPI, ePARAMETER_OUT, 1, sizeof(int), &account->account_id);
}
else { /* get error code */
@@ -97,9 +112,11 @@ EXPORT_API int email_add_account(email_account_t* account)
FINISH_OFF:
- if(hAPI)
+ if (hAPI)
emipc_destroy_email_api(hAPI);
+ EM_SAFE_FREE(multi_user_name);
+
EM_DEBUG_API_END ("err[%d]", err);
return err;
}
@@ -182,6 +199,7 @@ EXPORT_API int email_delete_account(int account_id)
if(ret != EMAIL_ERROR_NONE) { /* get error code */
emipc_get_parameter(hAPI, ePARAMETER_OUT, 1, sizeof(int), &err);
}
+
emipc_destroy_email_api(hAPI);
hAPI = NULL;
@@ -305,16 +323,21 @@ EXPORT_API int email_get_account(int account_id, int pulloption, email_account_t
{
EM_DEBUG_FUNC_BEGIN ("account_id[%d] pulloption[%d]", account_id, pulloption);
int err = EMAIL_ERROR_NONE;
+ char *multi_user_name = NULL;
emstorage_account_tbl_t *account_tbl = NULL;
EM_IF_NULL_RETURN_VALUE(account_id, EMAIL_ERROR_INVALID_PARAM);
EM_IF_NULL_RETURN_VALUE(account, EMAIL_ERROR_INVALID_PARAM);
+ if ((err = emipc_get_user_name(&multi_user_name)) != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("emipc_get_user_name failed : [%d]", err);
+ goto FINISH_OFF;
+ }
if (pulloption == GET_FULL_DATA)
pulloption = EMAIL_ACC_GET_OPT_FULL_DATA;
- if (!emstorage_get_account_by_id(account_id, pulloption, &account_tbl, true, &err)) {
+ if (!emstorage_get_account_by_id(multi_user_name, account_id, pulloption, &account_tbl, true, &err)) {
if (err != EMAIL_ERROR_SECURED_STORAGE_FAILURE) {
EM_DEBUG_EXCEPTION("emstorage_get_account_by_id failed - %d", err);
goto FINISH_OFF;
@@ -325,7 +348,7 @@ EXPORT_API int email_get_account(int account_id, int pulloption, email_account_t
EM_DEBUG_LOG("change pulloption : disable password");
}
- if (!emstorage_get_account_by_id(account_id, pulloption, &account_tbl, true, &err)) {
+ if (!emstorage_get_account_by_id(multi_user_name, account_id, pulloption, &account_tbl, true, &err)) {
EM_DEBUG_EXCEPTION("emstorage_get_account_by_id failed - %d", err);
goto FINISH_OFF;
}
@@ -340,9 +363,12 @@ EXPORT_API int email_get_account(int account_id, int pulloption, email_account_t
em_convert_account_tbl_to_account(account_tbl, *account);
FINISH_OFF:
+
if (account_tbl)
emstorage_free_account(&account_tbl, 1, NULL);
+ EM_SAFE_FREE(multi_user_name);
+
EM_DEBUG_FUNC_END ("err[%d]", err);
return err;
}
@@ -352,15 +378,20 @@ EXPORT_API int email_get_account_list(email_account_t** account_list, int* count
EM_DEBUG_FUNC_BEGIN ();
int err = EMAIL_ERROR_NONE, i = 0;
- emstorage_account_tbl_t *temp_account_tbl = NULL;
+ char *multi_user_name = NULL;
EM_IF_NULL_RETURN_VALUE(account_list, EMAIL_ERROR_INVALID_PARAM);
EM_IF_NULL_RETURN_VALUE(count, EMAIL_ERROR_INVALID_PARAM);
+ emstorage_account_tbl_t *temp_account_tbl = NULL;
+
+ if ((err = emipc_get_user_name(&multi_user_name)) != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("emipc_get_user_name failed : [%d]", err);
+ goto FINISH_OFF;
+ }
- if (!emstorage_get_account_list(count, &temp_account_tbl , true, false, &err)) {
+ if (!emstorage_get_account_list(multi_user_name, count, &temp_account_tbl , true, false, &err)) {
EM_DEBUG_EXCEPTION("emstorage_get_account_list failed [%d]", err);
-
goto FINISH_OFF;
}
@@ -371,6 +402,7 @@ EXPORT_API int email_get_account_list(email_account_t** account_list, int* count
err = EMAIL_ERROR_OUT_OF_MEMORY;
goto FINISH_OFF;
}
+
memset((void*)*account_list, 0, sizeof(email_account_t) * (*count));
for(i = 0; i < (*count); i++)
em_convert_account_tbl_to_account(temp_account_tbl + i, (*account_list) + i);
@@ -378,9 +410,11 @@ EXPORT_API int email_get_account_list(email_account_t** account_list, int* count
FINISH_OFF:
-
if(temp_account_tbl)
emstorage_free_account(&temp_account_tbl, (*count), NULL);
+
+ EM_SAFE_FREE(multi_user_name);
+
EM_DEBUG_FUNC_END ("err[%d]", err);
return err;
@@ -435,7 +469,8 @@ EXPORT_API int email_validate_account_ex(email_account_t* account, int *handle)
int size = 0;
int err = EMAIL_ERROR_NONE;
- if (account == NULL || account->user_email_address == NULL || account->incoming_server_user_name == NULL || account->incoming_server_address == NULL||
+ if (account == NULL || account->user_email_address == NULL ||
+ account->incoming_server_user_name == NULL || account->incoming_server_address == NULL||
account->outgoing_server_user_name == NULL || account->outgoing_server_address == NULL) {
EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
return EMAIL_ERROR_INVALID_PARAM;
@@ -480,6 +515,8 @@ EXPORT_API int email_add_account_with_validation(email_account_t* account, int *
int ret = -1;
int size = 0;
int err = EMAIL_ERROR_NONE;
+ char *multi_user_name = NULL;
+ HIPC_API hAPI = NULL;
if (account == NULL || account->user_email_address == NULL || account->incoming_server_user_name == NULL || account->incoming_server_address == NULL||
account->outgoing_server_user_name == NULL || account->outgoing_server_address == NULL) {
@@ -487,25 +524,41 @@ EXPORT_API int email_add_account_with_validation(email_account_t* account, int *
return EMAIL_ERROR_INVALID_PARAM;
}
- if(emstorage_check_duplicated_account(account, true, &err) == false) {
+ if ((err = emipc_get_user_name(&multi_user_name)) != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("emipc_get_user_name failed : [%d]", err);
+ return err;
+ }
+
+ if(emstorage_check_duplicated_account(multi_user_name, account, true, &err) == false) {
EM_DEBUG_EXCEPTION("emstorage_check_duplicated_account failed (%d) ", err);
- return err;
+ goto FINISH_OFF;
}
/* create account information */
- HIPC_API hAPI = emipc_create_email_api(_EMAIL_API_ADD_ACCOUNT_WITH_VALIDATION);
- EM_IF_NULL_RETURN_VALUE(hAPI, EMAIL_ERROR_NULL_VALUE);
+ hAPI = emipc_create_email_api(_EMAIL_API_ADD_ACCOUNT_WITH_VALIDATION);
+ if (hAPI == NULL) {
+ EM_DEBUG_EXCEPTION("emipc_create_email_api failed");
+ err = EMAIL_ERROR_NULL_VALUE;
+ goto FINISH_OFF;
+ }
local_account_stream = em_convert_account_to_byte_stream(account, &size);
- EM_PROXY_IF_NULL_RETURN_VALUE(local_account_stream, hAPI, EMAIL_ERROR_NULL_VALUE);
+ if (local_account_stream == NULL) {
+ EM_DEBUG_EXCEPTION("em_convert_account_to_byte_stream failed");
+ err = EMAIL_ERROR_NULL_VALUE;
+ goto FINISH_OFF;
+ }
+
if(!emipc_add_dynamic_parameter(hAPI, ePARAMETER_IN, local_account_stream, size)) {
EM_DEBUG_EXCEPTION(" emipc_add_parameter failed ");
- EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
+ err = EMAIL_ERROR_NULL_VALUE;
+ goto FINISH_OFF;
}
if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION(" emipc_execute_proxy_api failed ");
- EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_IPC_SOCKET_FAILURE);
+ err = EMAIL_ERROR_IPC_SOCKET_FAILURE;
+ goto FINISH_OFF;
}
emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &ret);
@@ -517,8 +570,14 @@ EXPORT_API int email_add_account_with_validation(email_account_t* account, int *
emipc_get_parameter(hAPI, ePARAMETER_OUT, 1, sizeof(int), &err);
}
- emipc_destroy_email_api(hAPI);
- hAPI = NULL;
+FINISH_OFF:
+
+ if (hAPI) {
+ emipc_destroy_email_api(hAPI);
+ hAPI = NULL;
+ }
+
+ EM_SAFE_FREE(multi_user_name);
EM_DEBUG_API_END ("err[%d]", err);
return err;
@@ -539,29 +598,46 @@ EXPORT_API int email_backup_accounts_into_secure_storage(const char *file_name)
}
HIPC_API hAPI = emipc_create_email_api(_EMAIL_API_BACKUP_ACCOUNTS);
-
EM_IF_NULL_RETURN_VALUE(hAPI, EMAIL_ERROR_NULL_VALUE);
+ /* Checked the existed account */
+ int account_count = 0;
+
+ if (!emstorage_get_account_count(NULL, &account_count, false, &err)) {
+ EM_DEBUG_EXCEPTION("emstorage_get_account_count failed - %d", err);
+ goto FINISH_OFF;
+ }
+
+ if (account_count == 0) {
+ EM_DEBUG_LOG("Account is empty");
+ err = EMAIL_ERROR_ACCOUNT_NOT_FOUND;
+ goto FINISH_OFF;
+ }
+
/* file_name */
- if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)file_name, EM_SAFE_STRLEN(file_name)+1)) {
+ if (!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)file_name, EM_SAFE_STRLEN(file_name)+1)) {
EM_DEBUG_EXCEPTION(" emipc_add_parameter account_id failed ");
- EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
+ err = EMAIL_ERROR_NULL_VALUE;
+ goto FINISH_OFF;
}
- if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
+ if (emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION(" emipc_execute_proxy_api failed ");
- EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_IPC_SOCKET_FAILURE);
+ err = EMAIL_ERROR_IPC_SOCKET_FAILURE;
+ goto FINISH_OFF;
}
emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &ret);
- if(0 == ret) { /* get error code */
+ if (ret == false) { /* get error code */
emipc_get_parameter(hAPI, ePARAMETER_OUT, 1, sizeof(int), &err);
}
- emipc_destroy_email_api(hAPI);
+FINISH_OFF:
+ emipc_destroy_email_api(hAPI);
hAPI = NULL;
+
EM_DEBUG_API_END ("err[%d]", err);
return err;
}
@@ -770,9 +846,25 @@ EXPORT_API int email_save_default_account_id(int input_account_id)
EM_DEBUG_EXCEPTION ("EMAIL_ERROR_INVALID_PARAM");
return EMAIL_ERROR_INVALID_PARAM;
}
+
+ HIPC_API hAPI = emipc_create_email_api(_EMAIL_API_SAVE_DEFAULT_ACCOUNT_ID);
+ EM_IF_NULL_RETURN_VALUE(hAPI, EMAIL_ERROR_NULL_VALUE);
+
+ /* Input account ID */
+ if (!emipc_add_parameter(hAPI, ePARAMETER_IN, (char *)&input_account_id, sizeof(int))) {
+ EM_DEBUG_EXCEPTION("emipc_add_parameter input_account_id failed");
+ EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
+ }
+
+ if (emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
+ EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_IPC_SOCKET_FAILURE);
+ }
- err = emcore_save_default_account_id(input_account_id);
+ emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
+ emipc_destroy_email_api(hAPI);
+ hAPI = NULL;
EM_DEBUG_API_END ("ret[%d]", err);
return err;
}
@@ -780,9 +872,30 @@ EXPORT_API int email_save_default_account_id(int input_account_id)
EXPORT_API int email_load_default_account_id(int *output_account_id)
{
EM_DEBUG_FUNC_BEGIN ("output_account_id[%p]", output_account_id);
+
int err = EMAIL_ERROR_NONE;
+ int account_id = 0;
+
+ EM_IF_NULL_RETURN_VALUE(output_account_id, EMAIL_ERROR_INVALID_PARAM);
+
+ HIPC_API hAPI = emipc_create_email_api(_EMAIL_API_LOAD_DEFAULT_ACCOUNT_ID);
+ EM_IF_NULL_RETURN_VALUE(hAPI, EMAIL_ERROR_NULL_VALUE);
+
+ if (emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
+ EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_IPC_SOCKET_FAILURE);
+ }
+
+ emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
+
+ if (err == EMAIL_ERROR_NONE) {
+ emipc_get_parameter(hAPI, ePARAMETER_OUT, 1, sizeof(int), &account_id);
+ }
+
+ emipc_destroy_email_api(hAPI);
+ hAPI = NULL;
- err = emcore_load_default_account_id(output_account_id);
+ *output_account_id = account_id;
EM_DEBUG_FUNC_END ("ret[%d]", err);
return err;