#include <dbg.h>
#include <account-private.h>
+#include <account_free.h>
#include <account_ipc_marshal.h>
#include <account-mgr-stub.h>
static AccountManager *_acc_mgr = NULL;
-static char *_account_get_text(const char *text_data);
-static int _account_gslist_free(GSList* list);
-static int _account_glist_free(GList* list);
-
-static int _account_free_capability_items(account_capability_s *data)
-{
- if(!data) {
- return ACCOUNT_ERROR_INVALID_PARAMETER;
- }
-
- _ACCOUNT_FREE(data->type);
- _ACCOUNT_FREE(data->package_name);
- _ACCOUNT_FREE(data->user_name);
-
- return ACCOUNT_ERROR_NONE;
-}
-
-static int _account_free_custom_items(account_custom_s *data)
-{
- if(!data) {
- return ACCOUNT_ERROR_INVALID_PARAMETER;
- }
-
- _ACCOUNT_FREE(data->app_id);
- _ACCOUNT_FREE(data->key);
- _ACCOUNT_FREE(data->value);
-
- return ACCOUNT_ERROR_NONE;
-}
-
-static int _account_capability_gslist_free(GSList* list)
-{
- if(!list){
- return ACCOUNT_ERROR_INVALID_PARAMETER;
- }
-
- GSList* iter;
-
- for (iter = list; iter != NULL; iter = g_slist_next(iter)) {
- account_capability_s *capability_data = (account_capability_s*)iter->data;
- _account_free_capability_items(capability_data);
- _ACCOUNT_FREE(capability_data);
- }
-
- g_slist_free(list);
- list = NULL;
-
- return ACCOUNT_ERROR_NONE;
-}
-
-static int _account_custom_gslist_free(GSList* list)
-{
- if(!list){
- return ACCOUNT_ERROR_INVALID_PARAMETER;
- }
-
- GSList* iter;
-
- for (iter = list; iter != NULL; iter = g_slist_next(iter)) {
- account_custom_s *custom_data = (account_custom_s*)iter->data;
- _account_free_custom_items(custom_data);
- _ACCOUNT_FREE(custom_data);
- }
-
- g_slist_free(list);
- list = NULL;
-
- return ACCOUNT_ERROR_NONE;
-}
-/*
-static int _account_list_free(GList* list)
-{
- if(!list){
- return ACCOUNT_ERROR_INVALID_PARAMETER;
- }
-
- g_list_free_full(list, g_free);
- list = NULL;
-
- return ACCOUNT_ERROR_NONE;
-}
-*/
-
-static int _account_free_account_items(account_s *data)
-{
- if(!data) {
- return ACCOUNT_ERROR_INVALID_PARAMETER;
- }
-
- _ACCOUNT_FREE(data->user_name);
- _ACCOUNT_FREE(data->email_address);
- _ACCOUNT_FREE(data->display_name);
- _ACCOUNT_FREE(data->icon_path);
- _ACCOUNT_FREE(data->source);
- _ACCOUNT_FREE(data->package_name);
- _ACCOUNT_FREE(data->domain_name);
- _ACCOUNT_FREE(data->access_token);
-
- int i;
- for(i=0;i<USER_TXT_CNT;i++)
- _ACCOUNT_FREE(data->user_data_txt[i]);
-
- _account_capability_gslist_free(data->capablity_list);
- _account_glist_free(data->account_list);
- _account_custom_gslist_free(data->custom_list);
-
- return ACCOUNT_ERROR_NONE;
-}
-
-static int _account_gslist_free(GSList* list)
-{
- if(!list){
- return ACCOUNT_ERROR_INVALID_PARAMETER;
- }
-
- GSList* iter;
-
- for (iter = list; iter != NULL; iter = g_slist_next(iter)) {
- account_s *account_record = (account_s*)iter->data;
- _account_free_account_items(account_record);
- _ACCOUNT_FREE(account_record);
- }
-
- g_slist_free(list);
- list = NULL;
-
- return ACCOUNT_ERROR_NONE;
-}
-
-static int _account_glist_free(GList* list)
-{
- if(!list){
- return ACCOUNT_ERROR_INVALID_PARAMETER;
- }
-
- GList* iter;
-
- for (iter = list; iter != NULL; iter = g_list_next(iter)) {
- account_s *account_record = (account_s*)iter->data;
- _account_free_account_items(account_record);
- _ACCOUNT_FREE(account_record);
- }
-
- g_list_free(list);
- list = NULL;
-
- return ACCOUNT_ERROR_NONE;
-}
-
static char *_account_get_text(const char *text_data)
{
char *text_value = NULL;
if (g_strcmp0(_account_svc_errors[i].dbus_error_name, remote_error) == 0)
{
_INFO("Remote error code matched[%d]", _account_svc_errors[i].error_code);
+ g_free(remote_error);
return _account_svc_errors[i].error_code;
}
}
+ g_free(remote_error);
}
}
//All undocumented errors mapped to ACCOUNT_ERROR_PERMISSION_DENIED
error_code = _account_get_error_code(is_success, error);
g_clear_error(&error);
_ERR("account_manager_call_account_delete_from_db_by_user_name_sync failed [%d]", error_code);
- _account_gslist_free(account_list);
+ _account_gslist_account_free(account_list);
return error_code;
}
g_clear_error(&error);
- _account_gslist_free(account_list);
+ _account_gslist_account_free(account_list);
return ACCOUNT_ERROR_NONE;
}
ACCOUNT_RETURN_VAL((data != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("Account handle is null!"));
- _account_free_account_items(data);
- _ACCOUNT_FREE(data);
+ _account_free_account_with_items(data);
_INFO("account_destroy end");
return ACCOUNT_ERROR_NONE;
}
_INFO("After one iteration callback");
}
- _account_gslist_free(account_list);
+ _account_gslist_account_free(account_list);
_INFO("account_foreach_account_from_db end");
return ACCOUNT_ERROR_NONE;
account_s **input = (account_s **)account;
- _account_free_account_items(*input);
- _ACCOUNT_FREE(*input);
+ _account_free_account_with_items(*input);
*input = account_data;
}
_INFO("account_query_account_by_user_name end");
- _account_gslist_free(account_list);
+ _account_gslist_account_free(account_list);
return ACCOUNT_ERROR_NONE;
}
break;
}
}
- _account_gslist_free(account_list);
+ _account_gslist_account_free(account_list);
_INFO("account_query_account_by_package_name end");
return ACCOUNT_ERROR_NONE;
}
break;
}
}
- _account_gslist_free(account_list);
+ _account_gslist_account_free(account_list);
_INFO("account_query_account_by_capability end");
return ACCOUNT_ERROR_NONE;
}
break;
}
}
- _account_gslist_free(account_list);
+ _account_gslist_account_free(account_list);
_INFO("account_query_account_by_capability end");
return ACCOUNT_ERROR_NONE;
}
_INFO("");
}
- _account_capability_gslist_free(capability_list);
+ _account_gslist_capability_free(capability_list);
_INFO("account_query_capability_by_account_id end");
return ACCOUNT_ERROR_NONE;
}
return error_code;
}
+/*
static int _account_type_free_label_items(label_s *data)
{
if(!data) {
return ACCOUNT_ERROR_NONE;
}
+*/
/*
static int _account_type_glist_free(GList* list)
return ACCOUNT_ERROR_INVALID_PARAMETER;
}
- _account_type_free_account_type_items(data);
- _ACCOUNT_FREE(data);
+ _account_type_free_account_type_with_items(data);
return ACCOUNT_ERROR_NONE;
}
}
}
- _account_type_provider_feature_gslist_free(provider_feature_list);
+ _account_type_gslist_feature_free(provider_feature_list);
_INFO("account_type_query_provider_feature_by_app_id end");
return error_code;
}
_INFO("");
}
- _account_type_label_gslist_free(label_list);
+ _account_type_gslist_label_free(label_list);
_INFO("account_type_query_label_by_app_id end");
return ACCOUNT_ERROR_NONE;
}
}
}
- _account_type_gslist_free(account_type_list);
+ _account_type_gslist_account_type_free(account_type_list);
_INFO("account_type_foreach_account_type_from_db end");
return ACCOUNT_ERROR_NONE;
}
_INFO("");
}
- _account_type_gslist_free(account_type_list);
+ _account_type_gslist_account_type_free(account_type_list);
_INFO("account_type_query_by_provider_feature end");
return ACCOUNT_ERROR_NONE;
}
#include <db-util.h>
#include <pthread.h>
#include <vconf.h>
+#include <account_free.h>
#include <unistd.h>
#include "account-private.h"
return return_code;
}
+static void _account_db_data_to_text(const char *textbuf, char **output)
+{
+ if (textbuf && strlen(textbuf)>0) {
+ if (*output) {
+ free(*output);
+ *output = NULL;
+ }
+ *output = strdup(textbuf);
+ }
+}
+static int _account_query_table_column_int(account_stmt pStmt, int pos)
+{
+ if(!pStmt){
+ ACCOUNT_ERROR("statement is null");
+ return -1;
+ }
+
+ if(pos < 0){
+ ACCOUNT_ERROR("invalid pos");
+ return -1;
+ }
+
+ return sqlite3_column_int(pStmt, pos);
+}
+
+static const char *_account_query_table_column_text(account_stmt pStmt, int pos)
+{
+ if(!pStmt){
+ ACCOUNT_ERROR("statement is null");
+ return NULL;
+ }
+
+ if(pos < 0){
+ ACCOUNT_ERROR("invalid pos");
+ return NULL;
+ }
+
+ return (const char*)sqlite3_column_text(pStmt, pos);
+}
+
+static void _account_convert_column_to_account(account_stmt hstmt, account_s *account_record)
+{
+ const char *textbuf = NULL;
+
+ account_record->id = _account_query_table_column_int(hstmt, ACCOUNT_FIELD_ID);
+ ACCOUNT_DEBUG("account_record->id =[%d]", account_record->id);
+
+ textbuf = _account_query_table_column_text(hstmt, ACCOUNT_FIELD_USER_NAME);
+ _account_db_data_to_text(textbuf, &(account_record->user_name));
+
+ textbuf = _account_query_table_column_text(hstmt, ACCOUNT_FIELD_EMAIL_ADDRESS);
+ _account_db_data_to_text(textbuf, &(account_record->email_address));
+
+ textbuf = _account_query_table_column_text(hstmt, ACCOUNT_FIELD_DISPLAY_NAME);
+ _account_db_data_to_text(textbuf, &(account_record->display_name));
+
+ textbuf = _account_query_table_column_text(hstmt, ACCOUNT_FIELD_ICON_PATH);
+ _account_db_data_to_text(textbuf, &(account_record->icon_path));
+
+ textbuf = _account_query_table_column_text(hstmt, ACCOUNT_FIELD_SOURCE);
+ _account_db_data_to_text(textbuf, &(account_record->source));
+
+ textbuf = _account_query_table_column_text(hstmt, ACCOUNT_FIELD_PACKAGE_NAME);
+ _account_db_data_to_text(textbuf, &(account_record->package_name));
+
+ textbuf = _account_query_table_column_text(hstmt, ACCOUNT_FIELD_ACCESS_TOKEN);
+ _account_db_data_to_text(textbuf, &(account_record->access_token));
+
+ textbuf = _account_query_table_column_text(hstmt, ACCOUNT_FIELD_DOMAIN_NAME);
+ _account_db_data_to_text(textbuf, &(account_record->domain_name));
+
+ account_record->auth_type = _account_query_table_column_int(hstmt, ACCOUNT_FIELD_AUTH_TYPE);
+
+ account_record->secret = _account_query_table_column_int(hstmt, ACCOUNT_FIELD_SECRET);
+
+ account_record->sync_support = _account_query_table_column_int(hstmt, ACCOUNT_FIELD_SYNC_SUPPORT);
+
+ textbuf = _account_query_table_column_text(hstmt, ACCOUNT_FIELD_USER_TEXT_0);
+ _account_db_data_to_text(textbuf, &(account_record->user_data_txt[0]));
+
+ textbuf = _account_query_table_column_text(hstmt, ACCOUNT_FIELD_USER_TEXT_1);
+ _account_db_data_to_text(textbuf, &(account_record->user_data_txt[1]));
+
+ textbuf = _account_query_table_column_text(hstmt, ACCOUNT_FIELD_USER_TEXT_2);
+ _account_db_data_to_text(textbuf, &(account_record->user_data_txt[2]));
+
+ textbuf = _account_query_table_column_text(hstmt, ACCOUNT_FIELD_USER_TEXT_3);
+ _account_db_data_to_text(textbuf, &(account_record->user_data_txt[3]));
+
+ textbuf = _account_query_table_column_text(hstmt, ACCOUNT_FIELD_USER_TEXT_4);
+ _account_db_data_to_text(textbuf, &(account_record->user_data_txt[4]));
+
+ account_record->user_data_int[0] = _account_query_table_column_int(hstmt, ACCOUNT_FIELD_USER_INT_0);
+ account_record->user_data_int[1] = _account_query_table_column_int(hstmt, ACCOUNT_FIELD_USER_INT_1);
+ account_record->user_data_int[2] = _account_query_table_column_int(hstmt, ACCOUNT_FIELD_USER_INT_2);
+ account_record->user_data_int[3] = _account_query_table_column_int(hstmt, ACCOUNT_FIELD_USER_INT_3);
+ account_record->user_data_int[4] = _account_query_table_column_int(hstmt, ACCOUNT_FIELD_USER_INT_4);
+}
+
+GList* _account_query_account_by_package_name(const char* package_name, int *error_code)
+{
+ _INFO("_account_query_account_by_package_name");
+
+ *error_code = ACCOUNT_ERROR_NONE;
+ account_stmt hstmt = NULL;
+ char query[ACCOUNT_SQL_LEN_MAX] = {0, };
+ int rc = 0;
+
+ ACCOUNT_RETURN_VAL((package_name != NULL), {*error_code = ACCOUNT_ERROR_INVALID_PARAMETER;}, NULL, ("PACKAGE NAME IS NULL"));
+ ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {*error_code = ACCOUNT_ERROR_DB_NOT_OPENED;}, NULL, ("The database isn't connected."));
+
+ ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
+
+ ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s WHERE package_name=?", ACCOUNT_TABLE);
+
+ hstmt = _account_prepare_query(query);
+
+ if( _account_db_err_code() == SQLITE_PERM ){
+ ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg());
+ *error_code = ACCOUNT_ERROR_PERMISSION_DENIED;
+ return NULL;
+ }
+
+ int binding_count = 1;
+ _account_query_bind_text(hstmt, binding_count++, package_name);
+
+ rc = _account_query_step(hstmt);
+
+ account_s* account_head = NULL;
+
+ ACCOUNT_CATCH_ERROR_P(rc == SQLITE_ROW, {}, ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.(%s)\n", package_name));
+
+ int tmp = 0;
+
+ account_head = (account_s*) malloc(sizeof(account_s));
+ if (account_head == NULL) {
+ ACCOUNT_FATAL("malloc Failed");
+ if (hstmt != NULL) {
+ rc = _account_query_finalize(hstmt);
+ ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {*error_code = rc;}, NULL, ("finalize error"));
+ hstmt = NULL;
+ }
+ *error_code = ACCOUNT_ERROR_OUT_OF_MEMORY;
+ return NULL;
+ }
+ ACCOUNT_MEMSET(account_head, 0x00, sizeof(account_s));
+
+ while (rc == SQLITE_ROW) {
+ account_s* account_record = NULL;
+
+ account_record = (account_s*) malloc(sizeof(account_s));
+
+ if (account_record == NULL) {
+ ACCOUNT_FATAL("malloc Failed");
+ break;
+ }
+ ACCOUNT_MEMSET(account_record, 0x00, sizeof(account_s));
+
+ _account_convert_column_to_account(hstmt, account_record);
+
+ _INFO("Adding account_list");
+ account_head->account_list = g_list_append(account_head->account_list, account_record);
+
+ rc = _account_query_step(hstmt);
+ tmp++;
+ }
+
+ rc = _account_query_finalize(hstmt);
+ ACCOUNT_CATCH_ERROR_P((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
+ hstmt = NULL;
+/*
+ GList *iter;
+
+ tmp = g_list_length(account_head->account_list);
+
+ for (iter = account_head->account_list; iter != NULL; iter = g_list_next(iter)) {
+ account_s* testaccount = (account_s*)iter->data;
+
+ _account_query_capability_by_account_id(_account_get_capability_text_cb, testaccount->id, (void*)testaccount);
+ _account_query_custom_by_account_id(_account_get_custom_text_cb, testaccount->id, (void*)testaccount);
+ }
+*/
+ *error_code = ACCOUNT_ERROR_NONE;
+
+CATCH:
+ if (hstmt != NULL)
+ {
+ rc = _account_query_finalize(hstmt);
+ if (rc != ACCOUNT_ERROR_NONE) {
+ *error_code = rc;
+ _ERR("finalize error");
+ }
+ hstmt = NULL;
+ }
+
+ pthread_mutex_unlock(&account_mutex);
+
+ if( (*error_code != ACCOUNT_ERROR_NONE) && account_head ) {
+ _account_glist_account_free(account_head->account_list);
+ _ACCOUNT_FREE(account_head);
+ account_head = NULL;
+ }
+
+ if ((*error_code == ACCOUNT_ERROR_NONE) && account_head != NULL)
+ {
+ _INFO("Returning account_list");
+// _remove_sensitive_info_from_non_owning_account_list(getpid(), account_head->account_list);
+ GList* result = account_head->account_list;
+ _ACCOUNT_FREE(account_head);
+ return result;
+ }
+ return NULL;
+}
+
+static void _account_insert_delete_update_notification_send(char *noti_name, int pid)
+{
+ if (!noti_name) {
+ _ERR("Noti Name is NULL!!!!!!\n");
+ return;
+ }
+
+ if (vconf_set_str(VCONFKEY_ACCOUNT_MSG_STR, noti_name) != 0) {
+ _ERR("Vconf MSG Str set FAILED !!!!!!\n");;
+ }
+}
+
+int _account_delete_from_db_by_package_name_offline(const char *package_name)
+{
+ int error_code = ACCOUNT_ERROR_NONE;
+ account_stmt hstmt = NULL;
+ char query[ACCOUNT_SQL_LEN_MAX] = {0, };
+ int rc = 0;
+ int ret_transaction = 0;
+ bool is_success = FALSE;
+ int binding_count = 1;
+ GSList *account_id_list = NULL;
+ int ret = -1;
+
+ // It only needs list of ids, does not need to query sensitive info. So sending 0
+ GList* account_list_temp = _account_query_account_by_package_name(package_name, &ret);
+ if (account_list_temp == NULL)
+ {
+ _ERR("_account_query_account_by_package_name returned NULL");
+ return ACCOUNT_ERROR_DB_FAILED;
+ }
+
+ if( _account_db_err_code() == SQLITE_PERM ){
+ ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg());
+ _account_glist_account_free(account_list_temp);
+ return ACCOUNT_ERROR_PERMISSION_DENIED;
+ }
+
+ if(ret != ACCOUNT_ERROR_NONE){
+ _account_glist_account_free(account_list_temp);
+ return ret;
+ }
+
+ account_list_temp = g_list_first(account_list_temp);
+ _INFO("account_list_temp length=[%d]",g_list_length(account_list_temp));
+
+ GList* iter = NULL;
+ for (iter = account_list_temp; iter != NULL; iter = g_list_next(iter))
+ {
+ _INFO("iterating account_list_temp");
+ account_s *account = NULL;
+ _INFO("Before iter->data");
+ account = (account_s*)iter->data;
+ _INFO("After iter->data");
+ if (account != NULL)
+ {
+ char id[256] = {0, };
+
+ ACCOUNT_MEMSET(id, 0, 256);
+
+ ACCOUNT_SNPRINTF(id, 256, "%d", account->id);
+
+ _INFO("Adding account id [%s]", id);
+ account_id_list = g_slist_append(account_id_list, g_strdup(id));
+ }
+ }
+
+ _account_glist_account_free(account_list_temp);
+ /* transaction control required*/
+ ret_transaction = _account_begin_transaction();
+
+ if( _account_db_err_code() == SQLITE_PERM ){
+ pthread_mutex_unlock(&account_mutex);
+ ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg());
+ return ACCOUNT_ERROR_PERMISSION_DENIED;
+ }
+
+ if( ret_transaction == ACCOUNT_ERROR_DATABASE_BUSY ){
+ ACCOUNT_ERROR( "database busy(%s)", _account_db_err_msg());
+ pthread_mutex_unlock(&account_mutex);
+ return ACCOUNT_ERROR_DATABASE_BUSY;
+ }else if (ret_transaction != ACCOUNT_ERROR_NONE) {
+ ACCOUNT_ERROR("account_delete:_account_begin_transaction fail %d\n", ret_transaction);
+ pthread_mutex_unlock(&account_mutex);
+ return ret_transaction;
+ }
+
+ /* delete custom table */
+ ACCOUNT_MEMSET(query, 0, sizeof(query));
+ ACCOUNT_SNPRINTF(query, sizeof(query), "DELETE FROM %s WHERE AppId = ?", ACCOUNT_CUSTOM_TABLE);
+
+ hstmt = _account_prepare_query(query);
+
+ if( _account_db_err_code() == SQLITE_PERM ){
+ _account_end_transaction(FALSE);
+ pthread_mutex_unlock(&account_mutex);
+ ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg());
+ return ACCOUNT_ERROR_PERMISSION_DENIED;
+ }
+
+ ACCOUNT_CATCH_ERROR(hstmt != NULL, {}, ACCOUNT_ERROR_DB_FAILED,
+ ("_account_svc_query_prepare(%s) failed(%s).\n", query, _account_db_err_msg()));
+
+ binding_count = 1;
+ _account_query_bind_text(hstmt, binding_count++, package_name);
+
+ rc = _account_query_step(hstmt);
+ ACCOUNT_CATCH_ERROR(rc == SQLITE_DONE, {}, ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
+
+ rc = _account_query_finalize(hstmt);
+ ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
+ hstmt = NULL;
+
+ /* delete capability table */
+ ACCOUNT_MEMSET(query, 0, sizeof(query));
+ ACCOUNT_SNPRINTF(query, sizeof(query), "DELETE FROM %s WHERE package_name = ?", CAPABILITY_TABLE);
+
+ hstmt = _account_prepare_query(query);
+
+ ACCOUNT_CATCH_ERROR(hstmt != NULL, {}, ACCOUNT_ERROR_DB_FAILED,
+ ("_account_svc_query_prepare(%s) failed(%s).\n", query, _account_db_err_msg()));
+
+ binding_count = 1;
+ _account_query_bind_text(hstmt, binding_count++, package_name);
+
+ rc = _account_query_step(hstmt);
+ ACCOUNT_CATCH_ERROR(rc == SQLITE_DONE, {}, ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
+
+ rc = _account_query_finalize(hstmt);
+ ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
+ hstmt = NULL;
+
+ /* delete account table */
+ ACCOUNT_MEMSET(query, 0, sizeof(query));
+
+ ACCOUNT_SNPRINTF(query, sizeof(query), "DELETE FROM %s WHERE package_name = ?", ACCOUNT_TABLE);
+
+ hstmt = _account_prepare_query(query);
+ ACCOUNT_CATCH_ERROR(hstmt != NULL, {}, ACCOUNT_ERROR_DB_FAILED,
+ ("_account_svc_query_prepare(%s) failed(%s).\n", query, _account_db_err_msg()));
+
+ binding_count = 1;
+ _account_query_bind_text(hstmt, binding_count++, package_name);
+
+ rc = _account_query_step(hstmt);
+ ACCOUNT_CATCH_ERROR(rc == SQLITE_DONE, {}, ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found. package_name=%s, rc=%d\n", package_name, rc));
+
+ rc = _account_query_finalize(hstmt);
+ ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
+ is_success = TRUE;
+
+ hstmt = NULL;
+
+CATCH:
+ if (hstmt != NULL) {
+ rc = _account_query_finalize(hstmt);
+ ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
+ hstmt = NULL;
+ }
+
+ ret_transaction = _account_end_transaction(is_success);
+
+ if (ret_transaction != ACCOUNT_ERROR_NONE) {
+ ACCOUNT_ERROR("account_delete:_account_end_transaction fail %d, is_success=%d\n", ret_transaction, is_success);
+ } else {
+ if (is_success == true) {
+ GSList* gs_iter = NULL;
+ for (gs_iter = account_id_list; gs_iter != NULL; gs_iter = g_slist_next(gs_iter)) {
+ char* p_tmpid = NULL;
+ p_tmpid = (char*)gs_iter->data;
+ char buf[64]={0,};
+ ACCOUNT_SNPRINTF(buf, sizeof(buf), "%s:%s", ACCOUNT_NOTI_NAME_DELETE, p_tmpid);
+ ACCOUNT_SLOGD("%s", buf);
+ _account_insert_delete_update_notification_send(buf, getpid());
+ _ACCOUNT_FREE(p_tmpid);
+ }
+ g_slist_free(account_id_list);
+ }
+ }
+
+ pthread_mutex_unlock(&account_mutex);
+
+ _INFO("_account_delete_from_db_by_package_name_offline end");
+ return error_code;
+}
+
+ACCOUNT_INTERNAL_API int account_delete_from_db_by_package_name_offline(const char *package_name)
+{
+ _INFO("_account_delete_from_db_by_package_name_offline");
+
+ ACCOUNT_RETURN_VAL((package_name != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("package_name is null!"));
+
+ int return_code = _account_db_open(1);
+ if (return_code != ACCOUNT_ERROR_NONE)
+ {
+ _ERR("_account_db_open() error, ret = %d", return_code);
+
+ goto RETURN;
+ }
+
+ int uid = getuid();
+ if (uid != 0)
+ {
+ _ERR("current process user is not root, uid=%d", uid);
+ return_code = ACCOUNT_ERROR_PERMISSION_DENIED;
+ goto RETURN;
+ }
+
+ _INFO("before _account_delete_from_db_by_package_name_offline");
+ return_code = _account_delete_from_db_by_package_name_offline(package_name);
+ _INFO("after _account_delete_from_db_by_package_name_offline=[%d]", return_code);
+
+ if (return_code != ACCOUNT_ERROR_NONE)
+ {
+ _ERR("_account_delete_from_db_by_package_name_offline error");
+ goto RETURN;
+ }
+
+RETURN:
+ _INFO("account_delete_from_db_by_package_name_offline end");
+
+ if( g_hAccountDB == NULL )
+ return return_code;
+
+ return_code = _account_db_close();
+ if (return_code != ACCOUNT_ERROR_NONE)
+ {
+ ACCOUNT_DEBUG("_account_db_close() fail[%d]", return_code);
+ return_code = ACCOUNT_ERROR_DB_FAILED;
+ }
+
+ return return_code;
+}