From 76fc92a8b28d7e2c140fd091377e523b20ffd91e Mon Sep 17 00:00:00 2001 From: "seungha.son" Date: Thu, 29 Sep 2016 18:05:07 +0900 Subject: [PATCH] Fix 'allowed calls exception' do not work problem - Modify GList find method. - Modify DB query in dnd_allow_exception db table. Signed-off-by: seungha.son Change-Id: I2c042fa99b2443d23fc83187eaafe197a4a1cd0b --- src/notification_setting.c | 29 ++++++++++----------- src/notification_setting_service.c | 52 +++++++++++++++++++++++++------------- 2 files changed, 47 insertions(+), 34 deletions(-) diff --git a/src/notification_setting.c b/src/notification_setting.c index eb55c67..013efdd 100755 --- a/src/notification_setting.c +++ b/src/notification_setting.c @@ -765,7 +765,7 @@ EXPORT_API int notification_system_setting_get_dnd_allow_exceptions(notification return NOTIFICATION_ERROR_INVALID_PARAMETER; } - list = g_list_find_custom(system_setting->dnd_allow_exceptions, (gconstpointer)type, _dnd_allow_exception_compare); + list = g_list_find_custom(system_setting->dnd_allow_exceptions, (gconstpointer)type, (GCompareFunc)_dnd_allow_exception_compare); if (list) { dnd_allow_exception_data = (dnd_allow_exception_h)list->data; *value = dnd_allow_exception_data->value; @@ -780,7 +780,7 @@ EXPORT_API int notification_system_setting_get_dnd_allow_exceptions(notification EXPORT_API int notification_system_setting_set_dnd_allow_exceptions(notification_system_setting_h system_setting, dnd_allow_exception_type_e type, int value) { dnd_allow_exception_h dnd_allow_exception_data; - GList *list; + GList *list = NULL; if (system_setting == NULL) { NOTIFICATION_ERR("Invalid parameter"); @@ -788,23 +788,20 @@ EXPORT_API int notification_system_setting_set_dnd_allow_exceptions(notification } list = g_list_first(system_setting->dnd_allow_exceptions); + list = g_list_find_custom(list, (gconstpointer)type, (GCompareFunc)_dnd_allow_exception_compare); - for (; list != NULL; list = list->next) { + if (list) { dnd_allow_exception_data = (dnd_allow_exception_h)list->data; - if (dnd_allow_exception_data->type == type) { - dnd_allow_exception_data->value = value; - return NOTIFICATION_ERROR_NONE; - } - } - - dnd_allow_exception_data = (dnd_allow_exception_h)malloc(sizeof(struct notification_system_setting_dnd_allow_exception)); - if (dnd_allow_exception_data == NULL) - return NOTIFICATION_ERROR_OUT_OF_MEMORY; - - dnd_allow_exception_data->type = type; - dnd_allow_exception_data->value = value; + dnd_allow_exception_data->value = value; + } else { + dnd_allow_exception_data = (dnd_allow_exception_h)malloc(sizeof(struct notification_system_setting_dnd_allow_exception)); + if (dnd_allow_exception_data == NULL) + return NOTIFICATION_ERROR_OUT_OF_MEMORY; - system_setting->dnd_allow_exceptions = g_list_append(system_setting->dnd_allow_exceptions, dnd_allow_exception_data); + dnd_allow_exception_data->type = type; + dnd_allow_exception_data->value = value; + system_setting->dnd_allow_exceptions = g_list_append(list, dnd_allow_exception_data); + } return NOTIFICATION_ERROR_NONE; } diff --git a/src/notification_setting_service.c b/src/notification_setting_service.c index 03a7d51..f5d7382 100644 --- a/src/notification_setting_service.c +++ b/src/notification_setting_service.c @@ -740,31 +740,47 @@ EXPORT_API int notification_system_setting_update_dnd_allow_exception(int type, { int ret = NOTIFICATION_ERROR_NONE; int sqlret; + int field_index = 1; sqlite3 *db = NULL; - char *sqlbuf = NULL; + sqlite3_stmt *db_statement = NULL; - sqlret = db_util_open(DBPATH, &db, 0); - if (sqlret != SQLITE_OK || db == NULL) { - NOTIFICATION_ERR("db_util_open failed [%s][%d]", DBPATH, sqlret); - return NOTIFICATION_ERROR_FROM_DB; - } + db = notification_db_open(DBPATH); + if (db == NULL) + return get_last_result(); - sqlbuf = sqlite3_mprintf("UPDATE dnd_allow_exception SET value = %d WHERE type = %d AND uid = %d", value, type, uid); - if (!sqlbuf) { - NOTIFICATION_ERR("fail to alloc query"); - ret = NOTIFICATION_ERROR_OUT_OF_MEMORY; - goto return_close_db; + sqlite3_exec(db, "BEGIN immediate;", NULL, NULL, NULL); + + sqlret = sqlite3_prepare_v2(db, "INSERT OR REPLACE INTO dnd_allow_exception (uid, type, value) VALUES(?, ?, ?) ", -1, &db_statement, NULL); + + if (sqlret != SQLITE_OK) { + NOTIFICATION_ERR("sqlite3_prepare_v2 failed [%d][%s]", sqlret, sqlite3_errmsg(db)); + ret = NOTIFICATION_ERROR_FROM_DB; + goto out; } - ret = notification_db_exec(db, sqlbuf, NULL); + sqlite3_bind_int(db_statement, field_index++, uid); + sqlite3_bind_int(db_statement, field_index++, type); + sqlite3_bind_int(db_statement, field_index++, value); -return_close_db: - if (sqlbuf) - sqlite3_free(sqlbuf); + sqlret = sqlite3_step(db_statement); + if (sqlret != SQLITE_OK && sqlret != SQLITE_DONE) { + NOTIFICATION_ERR("sqlite3_step failed [%d][%s]", sqlret, sqlite3_errmsg(db)); + ret = NOTIFICATION_ERROR_FROM_DB; + goto out; + } - sqlret = db_util_close(db); - if (sqlret != SQLITE_OK) - NOTIFICATION_WARN("fail to db_util_close - [%d]", sqlret); + sqlret = sqlite3_changes(db); + + if (sqlret == 0) + NOTIFICATION_WARN("No changes on DB"); +out: + if (db_statement) + sqlite3_finalize(db_statement); + if (ret == NOTIFICATION_ERROR_NONE) + sqlite3_exec(db, "END;", NULL, NULL, NULL); + else + sqlite3_exec(db, "ROLLBACK;", NULL, NULL, NULL); + notification_db_close(&db); return ret; } -- 2.7.4