From 3ca0e24437c72ca1d7248ea6f20edce0c967ee83 Mon Sep 17 00:00:00 2001 From: "jiseob.jang" Date: Tue, 15 Sep 2015 18:59:42 +0900 Subject: [PATCH] merge from 2.4 Change-Id: I46c6f555a3fecea88b664c459daab5535a8d1e42 Signed-off-by: jiseob.jang --- CMakeLists.txt | 2 +- LICENSE => LICENSE.APLv2 | 1 - NOTICE | 3 + include/account_internal.h | 6 +- packaging/libaccount-service.spec | 2 +- src/CMakeLists.txt | 2 +- src/account.c | 187 ++-------------- src/account_offline.c | 448 ++++++++++++++++++++++++++++++++++++++ 8 files changed, 476 insertions(+), 175 deletions(-) rename LICENSE => LICENSE.APLv2 (99%) create mode 100644 NOTICE diff --git a/CMakeLists.txt b/CMakeLists.txt index d98ec53..e214093 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,6 +6,6 @@ SET(EXEC_PREFIX ${_prefix}) #SET(LIBDIR "\${prefix}/lib") #SET(INCLUDEDIR "\${prefix}/include ") SET(VERSION_MAJOR 0) -SET(VERSION "${VERSION_MAJOR}.3.3") +SET(VERSION "${VERSION_MAJOR}.3.5") ADD_SUBDIRECTORY(src) diff --git a/LICENSE b/LICENSE.APLv2 similarity index 99% rename from LICENSE rename to LICENSE.APLv2 index f94008a..8aa906c 100644 --- a/LICENSE +++ b/LICENSE.APLv2 @@ -1,4 +1,3 @@ -Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. Apache License Version 2.0, January 2004 diff --git a/NOTICE b/NOTICE new file mode 100644 index 0000000..0e0f016 --- /dev/null +++ b/NOTICE @@ -0,0 +1,3 @@ +Copyright (c) Samsung Electronics Co., Ltd. All rights reserved. +Except as noted, this software is licensed under Apache License, Version 2. +Please, see the LICENSE.APLv2 file for Apache License terms and conditions. diff --git a/include/account_internal.h b/include/account_internal.h index 8b4cb51..1fc0524 100644 --- a/include/account_internal.h +++ b/include/account_internal.h @@ -41,7 +41,7 @@ extern "C" /** * @internal - * @brief Deletes an account from the account database by package name without permission check. + * @brief Deletes an account from the account database by package name. * * @since_tizen 2.4 * @privlevel public @@ -59,8 +59,6 @@ extern "C" * @retval #ACCOUNT_ERROR_DATABASE_BUSY SQLite handler is busy * @retval #ACCOUNT_ERROR_DB_NOT_OPENED Account database did not opened * - * @pre This function requires an open connection to an account service by account_connect(). - * * @see account_connect() * @see account_insert_to_db() * @see account_delete_from_db_by_id() @@ -68,7 +66,7 @@ extern "C" * @see account_update_to_db_by_id() * @see account_update_to_db_by_user_name() */ -int account_delete_from_db_by_package_name_without_permission(const char *package_name); +int account_delete_from_db_by_package_name_offline(const char *package_name); /** * @internal diff --git a/packaging/libaccount-service.spec b/packaging/libaccount-service.spec index 2fcc9db..dbff1ad 100644 --- a/packaging/libaccount-service.spec +++ b/packaging/libaccount-service.spec @@ -1,7 +1,7 @@ Name: libaccount-service Summary: Account DB library -Version: 0.3.3 +Version: 0.3.5 Release: 1 Group: Social & Content/API License: Apache-2.0 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a8d218a..d879ed8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -64,7 +64,7 @@ ELSE(FEATURE_PROFILE_MOBILE) INSTALL(FILES ${CMAKE_SOURCE_DIR}/include/wearable/account.h DESTINATION include) ENDIF(FEATURE_PROFILE_MOBILE) -INSTALL(FILES ${CMAKE_SOURCE_DIR}/include/account.h DESTINATION include) +#INSTALL(FILES ${CMAKE_SOURCE_DIR}/include/account.h DESTINATION include) INSTALL(FILES ${CMAKE_SOURCE_DIR}/include/account-error.h DESTINATION include) INSTALL(FILES ${CMAKE_SOURCE_DIR}/include/account-types.h DESTINATION include) INSTALL(FILES ${CMAKE_SOURCE_DIR}/include/account_internal.h DESTINATION include) diff --git a/src/account.c b/src/account.c index b22d3c2..d0dde3b 100644 --- a/src/account.c +++ b/src/account.c @@ -28,6 +28,7 @@ #include #include +#include #include #include @@ -49,155 +50,6 @@ 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;iuser_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; @@ -308,9 +160,11 @@ static int _account_get_error_code(bool is_success, GError *error) 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 @@ -466,12 +320,12 @@ ACCOUNT_API int account_delete_from_db_by_user_name(char *user_name, char *packa 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; } @@ -739,8 +593,7 @@ ACCOUNT_API int account_destroy(account_h account) 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; @@ -1473,7 +1326,7 @@ ACCOUNT_API int account_foreach_account_from_db(account_cb callback, void *user_ } _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; @@ -1518,8 +1371,7 @@ ACCOUNT_API int account_query_account_by_account_id(int account_db_id, account_h account_s **input = (account_s **)account; - _account_free_account_items(*input); - _ACCOUNT_FREE(*input); + _account_free_account_with_items(*input); *input = account_data; @@ -1577,7 +1429,7 @@ ACCOUNT_API int account_query_account_by_user_name(account_cb callback, const ch } _INFO("account_query_account_by_user_name end"); - _account_gslist_free(account_list); + _account_gslist_account_free(account_list); return ACCOUNT_ERROR_NONE; } @@ -1629,7 +1481,7 @@ ACCOUNT_API int account_query_account_by_package_name(account_cb callback, const break; } } - _account_gslist_free(account_list); + _account_gslist_account_free(account_list); _INFO("account_query_account_by_package_name end"); return ACCOUNT_ERROR_NONE; } @@ -1687,7 +1539,7 @@ ACCOUNT_API int account_query_account_by_capability(account_cb callback, const c break; } } - _account_gslist_free(account_list); + _account_gslist_account_free(account_list); _INFO("account_query_account_by_capability end"); return ACCOUNT_ERROR_NONE; } @@ -1740,7 +1592,7 @@ ACCOUNT_API int account_query_account_by_capability_type(account_cb callback, co break; } } - _account_gslist_free(account_list); + _account_gslist_account_free(account_list); _INFO("account_query_account_by_capability end"); return ACCOUNT_ERROR_NONE; } @@ -1794,7 +1646,7 @@ ACCOUNT_API int account_query_capability_by_account_id(capability_cb callback, i _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; } @@ -1880,6 +1732,7 @@ ACCOUNT_API int account_update_sync_status_by_id(int account_db_id, const accoun return error_code; } +/* static int _account_type_free_label_items(label_s *data) { if(!data) { @@ -1976,6 +1829,7 @@ static int _account_type_gslist_free(GSList* list) return ACCOUNT_ERROR_NONE; } +*/ /* static int _account_type_glist_free(GList* list) @@ -2041,8 +1895,7 @@ ACCOUNT_API int account_type_destroy(account_type_h account_type) 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; } @@ -2244,7 +2097,7 @@ ACCOUNT_API int account_type_query_provider_feature_by_app_id(provider_feature_c } } - _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; } @@ -2610,7 +2463,7 @@ ACCOUNT_API int account_type_query_label_by_app_id(account_label_cb callback, co _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; } @@ -2713,7 +2566,7 @@ ACCOUNT_API int account_type_foreach_account_type_from_db(account_type_cb callba } } - _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; } @@ -2811,7 +2664,7 @@ ACCOUNT_API int account_type_query_by_provider_feature(account_type_cb callback, _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; } diff --git a/src/account_offline.c b/src/account_offline.c index f0b9a17..a4b642d 100644 --- a/src/account_offline.c +++ b/src/account_offline.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include "account-private.h" @@ -908,3 +909,450 @@ RETURN: 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; +} -- 2.7.4