pid = fork();
switch (pid) {
- case -1 :
+ case -1 :
perror("fork failed");
return -1;
case 0 :
- execvp(argv[0], (char *const *)argv);
- _exit(-1);
+ if (execvp(argv[0], (char *const *)argv) == -1) {
+ perror("execute init db script");
+ _exit(-1);
+ }
+
+ _exit(2);
default:
/* parent */
break;
#define SCRIPT_INIT_DB "/usr/bin/email-service_init_db.sh"
+INTERNAL_FUNC int emstorage_init_db(char *multi_user_name)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int err = EMAIL_ERROR_NONE;
+ char *prefix_path = NULL;
+ char *output_file_path = NULL;
+ char temp_file_path[MAX_PATH] = {0};
+
+ if (EM_SAFE_STRLEN(multi_user_name) > 0) {
+ err = emcore_get_container_path(multi_user_name, &prefix_path);
+ if (err != EMAIL_ERROR_NONE) {
+ if (err != EMAIL_ERROR_CONTAINER_NOT_INITIALIZATION) {
+ EM_DEBUG_EXCEPTION("emcore_get_container_path failed :[%d]", err);
+ goto FINISH_OFF;
+ }
+ }
+ } else {
+ prefix_path = strdup("");
+ }
+
+ if (err == EMAIL_ERROR_CONTAINER_NOT_INITIALIZATION) {
+ err = emcore_get_canonicalize_path(EMAIL_SERVICE_DB_FILE_PATH, &output_file_path);
+ if (err != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("emcore_get_canonicalize_path failed : [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ SNPRINTF(temp_file_path, sizeof(temp_file_path), "%s", output_file_path);
+ } else {
+ SNPRINTF(temp_file_path, sizeof(temp_file_path), "%s%s", prefix_path, EMAIL_SERVICE_DB_FILE_PATH);
+ }
+
+ EM_DEBUG_LOG("db file path : [%s]", temp_file_path);
+
+ if (!g_file_test(temp_file_path, G_FILE_TEST_EXISTS)) {
+ int ret = true;
+ const char *argv_script[] = {"/bin/sh", SCRIPT_INIT_DB, NULL};
+ ret = _xsystem(argv_script);
+
+ if (ret == -1) {
+ EM_DEBUG_EXCEPTION("_xsystem failed");
+ err = EMAIL_ERROR_SYSTEM_FAILURE;
+ }
+ }
+
+FINISH_OFF:
+
+ EM_SAFE_FREE(prefix_path);
+ EM_SAFE_FREE(output_file_path);
+
+ EM_DEBUG_FUNC_END();
+ return err;
+}
+
INTERNAL_FUNC int em_db_open(char *db_file_path, sqlite3 **sqlite_handle, int *err_code)
{
EM_DEBUG_FUNC_BEGIN();
return true;
}
- /* Generate db file */
- struct stat sts;
- ret = stat(db_file_path, &sts);
- if (ret == -1 && errno == ENOENT) {
- const char *argv_script[] = {"/bin/sh", SCRIPT_INIT_DB, NULL};
- ret = _xsystem(argv_script);
- }
-
EM_DEBUG_LOG("DB file path : [%s]", db_file_path);
/* db open */
ret = emcore_get_password_in_key_manager(file_name, password);
if (ret != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emcore_get_password_in_key_manager failed : [%d]", ret);
- goto FINISH_OFF;
+ goto FINISH_OFF;
}
FINISH_OFF:
}
/* get password file name */
- if ((err = _get_password_file_name(multi_user_name,
- input_account_id,
- recv_password_file_name,
+ if ((err = _get_password_file_name(multi_user_name,
+ input_account_id,
+ recv_password_file_name,
send_password_file_name)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("_get_password_file_name failed.");
goto FINISH_OFF;
}
- EM_DEBUG_LOG_SEC("recv_password_file_name [%s] input_incoming_server_password [%s]",
+ EM_DEBUG_LOG_SEC("recv_password_file_name [%s] input_incoming_server_password [%s]",
recv_password_file_name, input_incoming_server_password);
- EM_DEBUG_LOG_SEC("send_password_file_name [%s] input_outgoing_server_password [%s]",
+ EM_DEBUG_LOG_SEC("send_password_file_name [%s] input_outgoing_server_password [%s]",
send_password_file_name, input_outgoing_server_password);
err = emcore_remove_password_in_key_manager(recv_password_file_name);
email_digest_type digest_type; /* Sepeifies the digest algorithm*/
/* Multi user and KNOX options */
- char *user_name; /* Specifies the container name */
+ char *user_name; /* Specifies the container name */
} emstorage_account_tbl_t;
typedef struct
INTERNAL_FUNC int emstorage_shm_file_init(const char *shm_file_name);
-
+INTERNAL_FUNC int emstorage_init_db(char *multi_user_name);
/************** Database Management ***************/
/*
* em_db_open
* arguments :
* return :
*/
-INTERNAL_FUNC int emstorage_remove_downloaded_mail(char *multi_user_name,
- int account_id,
+INTERNAL_FUNC int emstorage_remove_downloaded_mail(char *multi_user_name,
+ int account_id,
int mailbox_id,
- char *mailbox_name,
- char *uid,
- int transaction,
+ char *mailbox_name,
+ char *uid,
+ int transaction,
int *err_code);
INTERNAL_FUNC int emstorage_update_read_mail_uid(char *multi_user_name, int mail_id, char *new_server_uid, char *mbox_name, int *err_code);
INTERNAL_FUNC int emstorage_get_searched_mail_list(char *multi_user_name, int account_id, int mailbox_id, int thread_id, int search_type, const char *search_value, int start_index, int limit_count, email_sort_type_t sorting, int transaction, email_mail_list_item_t **mail_list, int *result_count, int *err_code);
-INTERNAL_FUNC int emstorage_get_maildata_by_servermailid(char *multi_user_name,
- char *server_mail_id,
- int mailbox_id,
- emstorage_mail_tbl_t **mail,
- int transaction,
+INTERNAL_FUNC int emstorage_get_maildata_by_servermailid(char *multi_user_name,
+ char *server_mail_id,
+ int mailbox_id,
+ emstorage_mail_tbl_t **mail,
+ int transaction,
int *err_code);
INTERNAL_FUNC int emstorage_get_unread_mailid(char *multi_user_name, int account_id, int vip_mode, int **mail_ids, int *mail_number, int *err_code);
* @remarks N/A
* @return This function returns 0 on success or error code on failure.
*/
-INTERNAL_FUNC int emstorage_mail_search_start(char *multi_user_name,
- emstorage_search_filter_t *search,
- int account_id,
- int mailbox_id,
- int sorting,
- DB_STMT *search_handle,
- int *searched,
- int transaction,
+INTERNAL_FUNC int emstorage_mail_search_start(char *multi_user_name,
+ emstorage_search_filter_t *search,
+ int account_id,
+ int mailbox_id,
+ int sorting,
+ DB_STMT *search_handle,
+ int *searched,
+ int transaction,
int *err_code);
/*
* mail : double pointer to hold mail
* return :
*/
-INTERNAL_FUNC int emstorage_mail_search_result(DB_STMT search_handle,
- emstorage_mail_field_type_t type,
- void **data,
- int transaction,
+INTERNAL_FUNC int emstorage_mail_search_result(DB_STMT search_handle,
+ emstorage_mail_field_type_t type,
+ void **data,
+ int transaction,
int *err_code);
/*
INTERNAL_FUNC int emstorage_clean_save_status(char *multi_user_name, int save_status, int *err_code);
-INTERNAL_FUNC int emstorage_update_server_uid(char *multi_user_name,
+INTERNAL_FUNC int emstorage_update_server_uid(char *multi_user_name,
int mail_id,
- char *old_server_uid,
- char *new_server_uid,
+ char *old_server_uid,
+ char *new_server_uid,
int *err_code);
INTERNAL_FUNC int emstorage_increase_mail_id(char *multi_user_name, int *mail_id, int transaction, int *err_code);
* emstorage_get_attachment_list
*
* description : get attachment list from attachment table
- * arguments :
+ * arguments :
* input_mail_id : mail id
* input_transaction : transaction option
* attachment_list : result attachment list
INTERNAL_FUNC int emstorage_get_thread_id_by_mail_id(char *multi_user_name, int mail_id, int *thread_id, int *err_code);
-INTERNAL_FUNC int emstorage_update_latest_thread_mail(char *multi_user_name,
- int account_id,
- int mailbox_id,
+INTERNAL_FUNC int emstorage_update_latest_thread_mail(char *multi_user_name,
+ int account_id,
+ int mailbox_id,
int mailbox_type,
- int thread_id,
- int *updated_thread_id,
- int latest_mail_id,
- int thread_item_count,
- int noti_type,
- int transaction,
+ int thread_id,
+ int *updated_thread_id,
+ int latest_mail_id,
+ int thread_item_count,
+ int noti_type,
+ int transaction,
int *err_code);
INTERNAL_FUNC int emstorage_get_thread_id_from_mailbox(char *multi_user_name, int account_id, int mailbox_id, char *mail_subject, int *thread_id, int *thread_item_count);
/* check if inbox folder sync is finished */
if (!emstorage_get_mailbox_by_mailbox_type (multi_user_name, account_info->account_id, EMAIL_MAILBOX_TYPE_INBOX, &local_mailbox, false, &err)) {
if (err == EMAIL_ERROR_MAILBOX_NOT_FOUND) {
- int handle = 0;
+ int handle = 0;
emdaemon_get_imap_mailbox_list(multi_user_name, account_info->account_id, "", &handle, &err);
if (err != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emdaemon_get_imap_mailbox_list error [%d]", err);
EM_DEBUG_LOG("Initialization was already done. increased counter=[%d]", g_client_count);
EM_DEBUG_LOG("************* start email service build time [%s %s] ************* ", __DATE__, __TIME__);
+ err = emstorage_init_db(multi_user_name);
+ if (err != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("DB create failed");
+ goto FINISH_OFF;
+ }
dbus_threads_init_default();
-#if !GLIB_CHECK_VERSION(2, 36, 0)
- g_type_init();
+#if !GLIB_CHECK_VERSION(2, 36, 0)
+ g_type_init();
#endif
if ((err = _emdaemon_load_email_core()) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("_emdaemon_load_email_core failed [%d]", err);
vconf_notify_key_changed(VCONFKEY_MSG_SERVER_READY, callback_for_VCONFKEY_MSG_SERVER_READY, NULL);
}
#endif
+
}
/* open database */
goto FINISH_OFF;
}
- if ((err = emstorage_update_db_table_schema(multi_user_name)) != EMAIL_ERROR_NONE)
+ if ((err = emstorage_update_db_table_schema(multi_user_name)) != EMAIL_ERROR_NONE)
EM_DEBUG_EXCEPTION("emstorage_update_db_table_schema failed [%d]", err);
if (!emstorage_clean_save_status(multi_user_name, EMAIL_MAIL_STATUS_SAVED, &err))
/* get account list */
if (!emstorage_get_account_list(multi_user_name, &count, &account_list, false, false, &err)) {
- EM_DEBUG_EXCEPTION("emstorage_get_account_list failed [%d]", err);
+ EM_DEBUG_EXCEPTION("emstorage_get_account_list failed [%d]", err);
goto FINISH_OFF;
}