summaryrefslogtreecommitdiff
path: root/src/notification_setting_service.c
diff options
context:
space:
mode:
authorMyungki Lee <mk5004.lee@samsung.com>2017-06-20 09:52:54 +0900
committerMyungki Lee <mk5004.lee@samsung.com>2017-06-20 09:52:54 +0900
commit62e877ee33772ee6abb2f1a214439951aecf0d55 (patch)
treee9a42be8082c6b860cdac02bd60ada38dac2d1d1 /src/notification_setting_service.c
parent8e489b0ef9756afe004363e2df751872e0926e97 (diff)
downloadnotification-62e877ee33772ee6abb2f1a214439951aecf0d55.tar.gz
notification-62e877ee33772ee6abb2f1a214439951aecf0d55.tar.bz2
notification-62e877ee33772ee6abb2f1a214439951aecf0d55.zip
Check coding style about sqlite
- notification_setting, notificaiton_setting_service Change-Id: I27d713d17bebf455feb82198d6fceedaf8b1b8bf Signed-off-by: Myungki Lee <mk5004.lee@samsung.com>
Diffstat (limited to 'src/notification_setting_service.c')
-rw-r--r--src/notification_setting_service.c504
1 files changed, 261 insertions, 243 deletions
diff --git a/src/notification_setting_service.c b/src/notification_setting_service.c
index 835b72c..a79c04e 100644
--- a/src/notification_setting_service.c
+++ b/src/notification_setting_service.c
@@ -93,11 +93,11 @@ out:
EXPORT_API
int noti_setting_service_get_setting_by_app_id(const char *app_id, notification_setting_h *setting, uid_t uid)
{
- int err = NOTIFICATION_ERROR_NONE;
- sqlite3 *local_db_handle = NULL;
- char *sql_query = NULL;
+ int ret = NOTIFICATION_ERROR_NONE;
+ sqlite3 *db = NULL;
+ char *query = NULL;
char **query_result = NULL;
- int sql_return;
+ int sql_ret;
int row_count = 0;
int column_count = 0;
int i = 0;
@@ -106,38 +106,34 @@ int noti_setting_service_get_setting_by_app_id(const char *app_id, notification_
if (app_id == NULL || setting == NULL) {
NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER"); /* LCOV_EXCL_LINE */
- err = NOTIFICATION_ERROR_INVALID_PARAMETER;
- goto out;
+ return NOTIFICATION_ERROR_INVALID_PARAMETER;
}
- sql_return = db_util_open(DBPATH, &local_db_handle, 0);
-
- if (sql_return != SQLITE_OK || local_db_handle == NULL) {
- NOTIFICATION_ERR("db_util_open failed [%d]", sql_return); /* LCOV_EXCL_LINE */
- err = NOTIFICATION_ERROR_FROM_DB;
- goto out;
+ sql_ret = db_util_open(DBPATH, &db, 0);
+ if (sql_ret != SQLITE_OK || db == NULL) {
+ NOTIFICATION_ERR("db_util_open failed [%d]", sql_ret); /* LCOV_EXCL_LINE */
+ return NOTIFICATION_ERROR_FROM_DB;
}
- sql_query = sqlite3_mprintf("SELECT package_name, app_id, allow_to_notify, do_not_disturb_except, visibility_class, "
+ query = sqlite3_mprintf("SELECT package_name, app_id, allow_to_notify, do_not_disturb_except, visibility_class, "
"pop_up_notification, lock_screen_content_level, app_disabled FROM %s "
"WHERE app_id = %Q AND uid = %d", NOTIFICATION_SETTING_DB_TABLE, app_id, uid);
-
- if (!sql_query) {
+ if (!query) {
NOTIFICATION_ERR("fail to alloc query"); /* LCOV_EXCL_LINE */
- err = NOTIFICATION_ERROR_OUT_OF_MEMORY;
+ ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
goto out;
}
- sql_return = sqlite3_get_table(local_db_handle, sql_query, &query_result, &row_count, &column_count, NULL);
- if (sql_return != SQLITE_OK && sql_return != -1) {
- NOTIFICATION_ERR("sqlite3_get_table failed [%d][%s]", sql_return, sql_query); /* LCOV_EXCL_LINE */
- err = NOTIFICATION_ERROR_FROM_DB;
+ sql_ret = sqlite3_get_table(db, query, &query_result, &row_count, &column_count, NULL);
+ if (sql_ret != SQLITE_OK && sql_ret != -1) {
+ NOTIFICATION_ERR("sqlite3_get_table failed [%d][%s]", sql_ret, query); /* LCOV_EXCL_LINE */
+ ret = NOTIFICATION_ERROR_FROM_DB;
goto out;
}
if (!row_count) {
NOTIFICATION_DBG("No setting found for [%s]", app_id); /* LCOV_EXCL_LINE */
- err = NOTIFICATION_ERROR_NOT_EXIST_ID;
+ ret = NOTIFICATION_ERROR_NOT_EXIST_ID;
goto out;
}
@@ -147,7 +143,7 @@ int noti_setting_service_get_setting_by_app_id(const char *app_id, notification_
if (!(result_setting_array = (struct notification_setting *)malloc(sizeof(struct notification_setting) * row_count))) {
NOTIFICATION_ERR("malloc failed..."); /* LCOV_EXCL_LINE */
- err = NOTIFICATION_ERROR_OUT_OF_MEMORY;
+ ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
goto out;
}
@@ -168,26 +164,26 @@ out:
if (query_result)
sqlite3_free_table(query_result);
- if (sql_query)
- sqlite3_free(sql_query);
+ if (query)
+ sqlite3_free(query);
- if (local_db_handle) {
- sql_return = db_util_close(local_db_handle);
- if (sql_return != SQLITE_OK)
- NOTIFICATION_WARN("fail to db_util_close - [%d]", sql_return); /* LCOV_EXCL_LINE */
+ if (db) {
+ sql_ret = db_util_close(db);
+ if (sql_ret != SQLITE_OK)
+ NOTIFICATION_WARN("fail to db_util_close - [%d]", sql_ret); /* LCOV_EXCL_LINE */
}
- return err;
+ return ret;
}
EXPORT_API
int noti_setting_get_setting_array(notification_setting_h *setting_array, int *count, uid_t uid)
{
- int err = NOTIFICATION_ERROR_NONE;
- sqlite3 *local_db_handle = NULL;
- char *sql_query = NULL;
+ int ret = NOTIFICATION_ERROR_NONE;
+ sqlite3 *db = NULL;
+ char *query = NULL;
char **query_result = NULL;
- int sql_return;
+ int sql_ret;
int row_count = 0;
int column_count = 0;
int i = 0;
@@ -196,46 +192,42 @@ int noti_setting_get_setting_array(notification_setting_h *setting_array, int *c
if (setting_array == NULL || count == NULL) {
NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER"); /* LCOV_EXCL_LINE */
- err = NOTIFICATION_ERROR_INVALID_PARAMETER;
- goto out;
+ return NOTIFICATION_ERROR_INVALID_PARAMETER;
}
- sql_return = db_util_open(DBPATH, &local_db_handle, 0);
-
- if (sql_return != SQLITE_OK || local_db_handle == NULL) {
- NOTIFICATION_ERR("db_util_open failed [%d]", sql_return); /* LCOV_EXCL_LINE */
- err = NOTIFICATION_ERROR_FROM_DB;
- goto out;
+ sql_ret = db_util_open(DBPATH, &db, 0);
+ if (sql_ret != SQLITE_OK || db == NULL) {
+ NOTIFICATION_ERR("db_util_open failed [%d]", sql_ret); /* LCOV_EXCL_LINE */
+ return NOTIFICATION_ERROR_FROM_DB;
}
- sql_query = sqlite3_mprintf("SELECT package_name, app_id, allow_to_notify, do_not_disturb_except, visibility_class, "
+ query = sqlite3_mprintf("SELECT package_name, app_id, allow_to_notify, do_not_disturb_except, visibility_class, "
"pop_up_notification, lock_screen_content_level, app_disabled FROM %s WHERE uid = %d AND app_disabled = %d "
"ORDER BY package_name, app_id ", NOTIFICATION_SETTING_DB_TABLE, uid, 0);
-
- if (!sql_query) {
+ if (!query) {
NOTIFICATION_ERR("fail to alloc query"); /* LCOV_EXCL_LINE */
- err = NOTIFICATION_ERROR_OUT_OF_MEMORY;
+ ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
goto out;
}
- sql_return = sqlite3_get_table(local_db_handle, sql_query, &query_result, &row_count, &column_count, NULL);
-
- if (sql_return != SQLITE_OK && sql_return != -1) {
- NOTIFICATION_ERR("NOTIFICATION_ERROR_FROM_DB failed [%d][%s]", sql_return, sql_query); /* LCOV_EXCL_LINE */
- err = NOTIFICATION_ERROR_FROM_DB;
+ sql_ret = sqlite3_get_table(db, query, &query_result, &row_count, &column_count, NULL);
+ if (sql_ret != SQLITE_OK && sql_ret != -1) {
+ NOTIFICATION_ERR("NOTIFICATION_ERROR_FROM_DB failed [%d][%s]", sql_ret, query); /* LCOV_EXCL_LINE */
+ ret = NOTIFICATION_ERROR_FROM_DB;
goto out;
}
if (!row_count) {
NOTIFICATION_DBG("No setting found..."); /* LCOV_EXCL_LINE */
- err = NOTIFICATION_ERROR_NOT_EXIST_ID;
+ ret = NOTIFICATION_ERROR_NOT_EXIST_ID;
goto out;
}
NOTIFICATION_DBG("row_count [%d] column_count [%d]", row_count, column_count);
+
if (!(result_setting_array = (struct notification_setting *)malloc(sizeof(struct notification_setting) * row_count))) {
NOTIFICATION_ERR("malloc failed..."); /* LCOV_EXCL_LINE */
- err = NOTIFICATION_ERROR_OUT_OF_MEMORY;
+ ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
goto out;
}
@@ -259,27 +251,27 @@ out:
if (query_result)
sqlite3_free_table(query_result);
- if (sql_query)
- sqlite3_free(sql_query);
+ if (query)
+ sqlite3_free(query);
- if (local_db_handle) {
- sql_return = db_util_close(local_db_handle);
- if (sql_return != SQLITE_OK)
- NOTIFICATION_WARN("fail to db_util_close - [%d]", sql_return); /* LCOV_EXCL_LINE */
+ if (db) {
+ sql_ret = db_util_close(db);
+ if (sql_ret != SQLITE_OK)
+ NOTIFICATION_WARN("fail to db_util_close - [%d]", sql_ret); /* LCOV_EXCL_LINE */
}
- return err;
+ return ret;
}
EXPORT_API
int noti_system_setting_load_system_setting(notification_system_setting_h *system_setting, uid_t uid)
{
- int err = NOTIFICATION_ERROR_NONE;
- sqlite3 *local_db_handle = NULL;
- char *sql_query = NULL;
+ int ret = NOTIFICATION_ERROR_NONE;
+ sqlite3 *db = NULL;
+ char *query = NULL;
char **query_result = NULL;
- int sql_return;
+ int sql_ret;
int row_count = 0;
int column_count = 0;
int col_index = 0;
@@ -287,42 +279,38 @@ int noti_system_setting_load_system_setting(notification_system_setting_h *syste
if (system_setting == NULL) {
NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER"); /* LCOV_EXCL_LINE */
- err = NOTIFICATION_ERROR_INVALID_PARAMETER;
- goto out;
+ return NOTIFICATION_ERROR_INVALID_PARAMETER;
}
- sql_return = db_util_open(DBPATH, &local_db_handle, 0);
-
- if (sql_return != SQLITE_OK || local_db_handle == NULL) {
- NOTIFICATION_ERR("db_util_open failed [%d]", sql_return); /* LCOV_EXCL_LINE */
- err = NOTIFICATION_ERROR_FROM_DB;
- goto out;
+ sql_ret = db_util_open(DBPATH, &db, 0);
+ if (sql_ret != SQLITE_OK || db == NULL) {
+ NOTIFICATION_ERR("db_util_open failed [%d]", sql_ret); /* LCOV_EXCL_LINE */
+ return NOTIFICATION_ERROR_FROM_DB;
}
- sql_query = sqlite3_mprintf("SELECT do_not_disturb, visibility_class, "
+ query = sqlite3_mprintf("SELECT do_not_disturb, visibility_class, "
"dnd_schedule_enabled, dnd_schedule_day, "
"dnd_start_hour, dnd_start_min, dnd_end_hour, dnd_end_min, "
"lock_screen_content_level "
"FROM %s WHERE uid = %d", NOTIFICATION_SYSTEM_SETTING_DB_TABLE, uid);
-
- if (!sql_query) {
+ if (!query) {
NOTIFICATION_ERR("fail to alloc query"); /* LCOV_EXCL_LINE */
- err = NOTIFICATION_ERROR_OUT_OF_MEMORY;
+ ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
goto out;
}
- sql_return = sqlite3_get_table(local_db_handle, sql_query, &query_result, &row_count, &column_count, NULL);
-
- if (sql_return != SQLITE_OK && sql_return != -1) {
- NOTIFICATION_ERR("sqlite3_get_table failed [%d][%s]", sql_return, sql_query); /* LCOV_EXCL_LINE */
- err = NOTIFICATION_ERROR_FROM_DB;
+ sql_ret = sqlite3_get_table(db, query, &query_result, &row_count, &column_count, NULL);
+ if (sql_ret != SQLITE_OK && sql_ret != -1) {
+ NOTIFICATION_ERR("sqlite3_get_table failed [%d][%s]", sql_ret, query); /* LCOV_EXCL_LINE */
+ ret = NOTIFICATION_ERROR_FROM_DB;
goto out;
}
NOTIFICATION_DBG("row_count [%d] column_count [%d]", row_count, column_count);
+
if (!(result_system_setting = (struct notification_system_setting *)malloc(sizeof(struct notification_system_setting)))) {
NOTIFICATION_ERR("malloc failed..."); /* LCOV_EXCL_LINE */
- err = NOTIFICATION_ERROR_OUT_OF_MEMORY;
+ ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
goto out;
}
@@ -360,16 +348,16 @@ out:
if (query_result)
sqlite3_free_table(query_result);
- if (sql_query)
- sqlite3_free(sql_query);
+ if (query)
+ sqlite3_free(query);
- if (local_db_handle) {
- sql_return = db_util_close(local_db_handle);
- if (sql_return != SQLITE_OK)
- NOTIFICATION_WARN("fail to db_util_close - [%d]", sql_return); /* LCOV_EXCL_LINE */
+ if (db) {
+ sql_ret = db_util_close(db);
+ if (sql_ret != SQLITE_OK)
+ NOTIFICATION_WARN("fail to db_util_close - [%d]", sql_ret); /* LCOV_EXCL_LINE */
}
- return err;
+ return ret;
}
EXPORT_API
@@ -378,18 +366,18 @@ int notification_setting_db_update(const char *package_name, const char *app_id,
int visibility_class, int pop_up_notification,
int lock_screen_content_level, uid_t uid)
{
- int err = NOTIFICATION_ERROR_NONE;
+ int ret = NOTIFICATION_ERROR_NONE;
sqlite3 *db = NULL;
char *sqlbuf = NULL;
- int sqlret;
+ int sql_ret;
if (package_name == NULL || strlen(package_name) == 0
|| app_id == NULL || strlen(app_id) == 0)
return NOTIFICATION_ERROR_INVALID_PARAMETER;
- sqlret = db_util_open(DBPATH, &db, 0);
- if (sqlret != SQLITE_OK || db == NULL) {
- NOTIFICATION_ERR("db_util_open failed [%s][%d]", DBPATH, sqlret);
+ sql_ret = db_util_open(DBPATH, &db, 0);
+ if (sql_ret != SQLITE_OK || db == NULL) {
+ NOTIFICATION_ERR("db_util_open failed [%s][%d]", DBPATH, sql_ret);
return NOTIFICATION_ERROR_FROM_DB;
}
@@ -400,21 +388,23 @@ int notification_setting_db_update(const char *package_name, const char *app_id,
pop_up_notification, lock_screen_content_level, app_id, package_name, uid);
if (!sqlbuf) {
NOTIFICATION_ERR("fail to alloc query");
- err = NOTIFICATION_ERROR_OUT_OF_MEMORY;
- goto return_close_db;
+ ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
+ goto out;
}
- err = notification_db_exec(db, sqlbuf, NULL);
+ ret = notification_db_exec(db, sqlbuf, NULL);
-return_close_db:
+out:
if (sqlbuf)
sqlite3_free(sqlbuf);
- sqlret = db_util_close(db);
- if (sqlret != SQLITE_OK)
- NOTIFICATION_WARN("fail to db_util_close - [%d]", sqlret);
+ if (db) {
+ sql_ret = db_util_close(db);
+ if (sql_ret != SQLITE_OK)
+ NOTIFICATION_WARN("fail to db_util_close - [%d]", sql_ret); /* LCOV_EXCL_LINE */
+ }
- return err;
+ return ret;
}
EXPORT_API
@@ -424,115 +414,116 @@ int notification_setting_db_update_system_setting(int do_not_disturb, int visibi
int dnd_end_hour, int dnd_end_min,
int lock_screen_content_level, uid_t uid)
{
- int err = NOTIFICATION_ERROR_NONE;
- int sqlret;
+ int ret = NOTIFICATION_ERROR_NONE;
+ int sql_ret;
int field_index = 1;
sqlite3 *db = NULL;
- sqlite3_stmt *db_statement = NULL;
-
- sqlret = db_util_open(DBPATH, &db, 0);
+ sqlite3_stmt *stmt = NULL;
- if (sqlret != SQLITE_OK || db == NULL) {
- NOTIFICATION_ERR("db_util_open failed [%s][%d][%s]", DBPATH, sqlret, sqlite3_errmsg(db));
- err = NOTIFICATION_ERROR_FROM_DB;
- goto return_close_db;
+ sql_ret = db_util_open(DBPATH, &db, 0);
+ if (sql_ret != SQLITE_OK || db == NULL) {
+ NOTIFICATION_ERR("db_util_open failed [%s][%d][%s]", DBPATH, sql_ret, sqlite3_errmsg(db));
+ return NOTIFICATION_ERROR_FROM_DB;
}
sqlite3_exec(db, "BEGIN immediate;", NULL, NULL, NULL);
- sqlret = sqlite3_prepare_v2(db, "INSERT OR REPLACE INTO notification_system_setting "
+ sql_ret = sqlite3_prepare_v2(db, "INSERT OR REPLACE INTO notification_system_setting "
"(uid, do_not_disturb, visibility_class, dnd_schedule_enabled, "
"dnd_schedule_day, dnd_start_hour, dnd_start_min, "
"dnd_end_hour, dnd_end_min, lock_screen_content_level) "
- "VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ", -1, &db_statement, NULL);
-
- if (sqlret != SQLITE_OK) {
- NOTIFICATION_ERR("sqlite3_prepare_v2 failed [%d][%s]", sqlret, sqlite3_errmsg(db));
- err = NOTIFICATION_ERROR_FROM_DB;
- goto return_close_db;
+ "VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ", -1, &stmt, NULL);
+ if (sql_ret != SQLITE_OK) {
+ NOTIFICATION_ERR("sqlite3_prepare_v2 failed [%d][%s]", sql_ret, sqlite3_errmsg(db));
+ ret = NOTIFICATION_ERROR_FROM_DB;
+ goto out;
}
- sqlite3_bind_int(db_statement, field_index++, uid);
- sqlite3_bind_int(db_statement, field_index++, do_not_disturb);
- sqlite3_bind_int(db_statement, field_index++, visibility_class);
- sqlite3_bind_int(db_statement, field_index++, dnd_schedule_enabled);
- sqlite3_bind_int(db_statement, field_index++, dnd_schedule_day);
- sqlite3_bind_int(db_statement, field_index++, dnd_start_hour);
- sqlite3_bind_int(db_statement, field_index++, dnd_start_min);
- sqlite3_bind_int(db_statement, field_index++, dnd_end_hour);
- sqlite3_bind_int(db_statement, field_index++, dnd_end_min);
- sqlite3_bind_int(db_statement, field_index++, lock_screen_content_level);
+ sqlite3_bind_int(stmt, field_index++, uid);
+ sqlite3_bind_int(stmt, field_index++, do_not_disturb);
+ sqlite3_bind_int(stmt, field_index++, visibility_class);
+ sqlite3_bind_int(stmt, field_index++, dnd_schedule_enabled);
+ sqlite3_bind_int(stmt, field_index++, dnd_schedule_day);
+ sqlite3_bind_int(stmt, field_index++, dnd_start_hour);
+ sqlite3_bind_int(stmt, field_index++, dnd_start_min);
+ sqlite3_bind_int(stmt, field_index++, dnd_end_hour);
+ sqlite3_bind_int(stmt, field_index++, dnd_end_min);
+ sqlite3_bind_int(stmt, field_index++, lock_screen_content_level);
- sqlret = sqlite3_step(db_statement);
- if (sqlret != SQLITE_OK && sqlret != SQLITE_DONE) {
- NOTIFICATION_ERR("sqlite3_step failed [%d][%s]", sqlret, sqlite3_errmsg(db));
- err = NOTIFICATION_ERROR_FROM_DB;
- goto return_close_db;
+ sql_ret = sqlite3_step(stmt);
+ if (sql_ret != SQLITE_OK && sql_ret != SQLITE_DONE) {
+ NOTIFICATION_ERR("sqlite3_step failed [%d][%s]", sql_ret, sqlite3_errmsg(db));
+ ret = NOTIFICATION_ERROR_FROM_DB;
+ goto out;
}
- sqlret = sqlite3_changes(db);
-
- if (sqlret == 0)
+ sql_ret = sqlite3_changes(db);
+ if (sql_ret == 0)
NOTIFICATION_WARN("No changes on DB");
-return_close_db:
- if (db_statement)
- sqlite3_finalize(db_statement);
+out:
+ if (stmt)
+ sqlite3_finalize(stmt);
if (db) {
- if (err == NOTIFICATION_ERROR_NONE)
+ if (ret == NOTIFICATION_ERROR_NONE)
sqlite3_exec(db, "END;", NULL, NULL, NULL);
else
sqlite3_exec(db, "ROLLBACK;", NULL, NULL, NULL);
- sqlret = db_util_close(db);
+ sql_ret = db_util_close(db);
}
- if (sqlret != SQLITE_OK)
- NOTIFICATION_WARN("fail to db_util_close - [%d]", sqlret);
+ if (sql_ret != SQLITE_OK)
+ NOTIFICATION_WARN("fail to db_util_close - [%d]", sql_ret);
- return err;
+ return ret;
}
/* LCOV_EXCL_START */
EXPORT_API
int notification_setting_db_update_do_not_disturb(int do_not_disturb, uid_t uid)
{
- int err = NOTIFICATION_ERROR_NONE;
- int sqlret;
+ int ret = NOTIFICATION_ERROR_NONE;
+ int sql_ret;
sqlite3 *db = NULL;
char *sqlbuf = NULL;
- sqlret = db_util_open(DBPATH, &db, 0);
- if (sqlret != SQLITE_OK || db == NULL) {
- NOTIFICATION_ERR("db_util_open failed [%s][%d]", DBPATH, sqlret);
+ sql_ret = db_util_open(DBPATH, &db, 0);
+ if (sql_ret != SQLITE_OK || db == NULL) {
+ NOTIFICATION_ERR("db_util_open failed [%s][%d]", DBPATH, sql_ret);
return NOTIFICATION_ERROR_FROM_DB;
}
sqlbuf = sqlite3_mprintf("UPDATE notification_system_setting SET do_not_disturb = %d WHERE uid = %d", do_not_disturb, uid);
if (!sqlbuf) {
NOTIFICATION_ERR("fail to alloc query");
- err = NOTIFICATION_ERROR_OUT_OF_MEMORY;
- goto return_close_db;
+ ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
+ goto out;
}
- err = notification_db_exec(db, sqlbuf, NULL);
+ ret = notification_db_exec(db, sqlbuf, NULL);
-return_close_db:
+out:
if (sqlbuf)
sqlite3_free(sqlbuf);
- sqlret = db_util_close(db);
- if (sqlret != SQLITE_OK)
- NOTIFICATION_WARN("fail to db_util_close - [%d]", sqlret);
+ if (db) {
+ sql_ret = db_util_close(db);
+ if (sql_ret != SQLITE_OK)
+ NOTIFICATION_WARN("fail to db_util_close - [%d]", sql_ret); /* LCOV_EXCL_LINE */
+ }
- return err;
+ return ret;
}
/* LCOV_EXCL_STOP */
-EXPORT_API int notification_system_setting_get_dnd_schedule_enabled_uid(uid_t **uids, int *count)
+EXPORT_API
+int notification_system_setting_get_dnd_schedule_enabled_uid(uid_t **uids, int *count)
{
- int ret, i;
+ int ret = NOTIFICATION_ERROR_NONE;
+ int i;
+ int sql_ret;
int row_count = 0;
int column_count = 0;
int column_index = 0;
@@ -541,34 +532,36 @@ EXPORT_API int notification_system_setting_get_dnd_schedule_enabled_uid(uid_t **
sqlite3 *db = NULL;
uid_t *result_uids;
- db = notification_db_open(DBPATH);
- if (db == NULL)
- return get_last_result();
+ sql_ret = db_util_open(DBPATH, &db, 0);
+ if (sql_ret != SQLITE_OK || db == NULL) {
+ NOTIFICATION_ERR("db_util_open failed [%s][%d]", DBPATH, sql_ret);
+ return NOTIFICATION_ERROR_FROM_DB;
+ }
query = sqlite3_mprintf("SELECT uid FROM %s WHERE dnd_schedule_enabled = 1",
NOTIFICATION_SYSTEM_SETTING_DB_TABLE);
if (query == NULL) {
ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
- goto err;
+ goto out;
}
ret = sqlite3_get_table(db, query, &query_result, &row_count, &column_count, NULL);
if (ret != SQLITE_OK && ret != -1) {
NOTIFICATION_ERR("NOTIFICATION_ERROR_FROM_DB failed [%d][%s]", ret, query); /* LCOV_EXCL_LINE */
ret = NOTIFICATION_ERROR_FROM_DB;
- goto err;
+ goto out;
}
if (row_count == 0) {
NOTIFICATION_DBG("No enabled do_not_disturb user");
ret = NOTIFICATION_ERROR_NONE;
- goto err;
+ goto out;
}
if (!(result_uids = (uid_t *)malloc(sizeof(int) * row_count))) {
NOTIFICATION_ERR("Memory allocation fail");
ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
- goto err;
+ goto out;
}
column_index = column_count;
@@ -578,22 +571,28 @@ EXPORT_API int notification_system_setting_get_dnd_schedule_enabled_uid(uid_t **
*uids = result_uids;
*count = row_count;
-err:
+out:
if (query_result)
sqlite3_free_table(query_result);
+
if (query)
sqlite3_free(query);
- if (db)
- notification_db_close(&db);
+
+ if (db) {
+ sql_ret = db_util_close(db);
+ if (sql_ret != SQLITE_OK)
+ NOTIFICATION_WARN("fail to db_util_close - [%d]", sql_ret); /* LCOV_EXCL_LINE */
+ }
return ret;
}
-EXPORT_API int notification_get_dnd_and_allow_to_notify(const char *app_id,
- int *do_not_disturb,
- int *do_not_disturb_except,
- int *allow_to_notify,
- uid_t uid)
+EXPORT_API
+int notification_get_dnd_and_allow_to_notify(const char *app_id,
+ int *do_not_disturb,
+ int *do_not_disturb_except,
+ int *allow_to_notify,
+ uid_t uid)
{
int ret = NOTIFICATION_ERROR_NONE;
int sql_ret;
@@ -609,9 +608,11 @@ EXPORT_API int notification_get_dnd_and_allow_to_notify(const char *app_id,
if (app_id == NULL)
return NOTIFICATION_ERROR_INVALID_PARAMETER;
- db = notification_db_open(DBPATH);
- if (db == NULL)
- return get_last_result();
+ sql_ret = db_util_open(DBPATH, &db, 0);
+ if (sql_ret != SQLITE_OK || db == NULL) {
+ NOTIFICATION_ERR("db_util_open failed [%s][%d]", DBPATH, sql_ret);
+ return NOTIFICATION_ERROR_FROM_DB;
+ }
query_setting = sqlite3_mprintf("SELECT allow_to_notify, do_not_disturb_except " \
"FROM %s WHERE app_id = %Q AND (uid = %d OR uid = %d) " \
@@ -667,56 +668,61 @@ EXPORT_API int notification_get_dnd_and_allow_to_notify(const char *app_id,
out:
if (query_setting_result)
sqlite3_free_table(query_setting_result);
+
if (query_system_setting_result)
sqlite3_free_table(query_system_setting_result);
+
if (query_setting)
sqlite3_free(query_setting);
+
if (query_system_setting)
sqlite3_free(query_system_setting);
- if (db)
- notification_db_close(&db);
+
+ if (db) {
+ sql_ret = db_util_close(db);
+ if (sql_ret != SQLITE_OK)
+ NOTIFICATION_WARN("fail to db_util_close - [%d]", sql_ret); /* LCOV_EXCL_LINE */
+ }
return ret;
}
EXPORT_API int notification_system_setting_load_dnd_allow_exception(dnd_allow_exception_h *dnd_allow_exception, int *count, uid_t uid)
{
- int err = NOTIFICATION_ERROR_NONE;
- int sql_return;
+ int ret = NOTIFICATION_ERROR_NONE;
+ int sql_ret;
int row_count = 0;
int column_count = 0;
int col_index = 0;
int i;
- char *sql_query = NULL;
+ char *query = NULL;
char **query_result = NULL;
- sqlite3 *local_db_handle = NULL;
+ sqlite3 *db = NULL;
dnd_allow_exception_h dnd_allow_exception_data = NULL;
if (dnd_allow_exception == NULL) {
NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER"); /* LCOV_EXCL_LINE */
- err = NOTIFICATION_ERROR_INVALID_PARAMETER;
- goto out;
+ return NOTIFICATION_ERROR_INVALID_PARAMETER;
}
- sql_return = db_util_open(DBPATH, &local_db_handle, 0);
- if (sql_return != SQLITE_OK || local_db_handle == NULL) {
- NOTIFICATION_ERR("db_util_open failed [%d]", sql_return); /* LCOV_EXCL_LINE */
- err = NOTIFICATION_ERROR_FROM_DB;
- goto out;
+ sql_ret = db_util_open(DBPATH, &db, 0);
+ if (sql_ret != SQLITE_OK || db == NULL) {
+ NOTIFICATION_ERR("db_util_open failed [%d]", sql_ret); /* LCOV_EXCL_LINE */
+ return NOTIFICATION_ERROR_FROM_DB;
}
- sql_query = sqlite3_mprintf("SELECT type, value FROM %s WHERE uid = %d",
+ query = sqlite3_mprintf("SELECT type, value FROM %s WHERE uid = %d",
NOTIFICATION_DND_ALLOW_EXCEPTION, uid);
- if (!sql_query) {
+ if (!query) {
NOTIFICATION_ERR("fail to alloc query"); /* LCOV_EXCL_LINE */
- err = NOTIFICATION_ERROR_OUT_OF_MEMORY;
+ ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
goto out;
}
- sql_return = sqlite3_get_table(local_db_handle, sql_query, &query_result, &row_count, &column_count, NULL);
- if (sql_return != SQLITE_OK && sql_return != -1) {
- NOTIFICATION_ERR("sqlite3_get_table failed [%d][%s]", sql_return, sql_query); /* LCOV_EXCL_LINE */
- err = NOTIFICATION_ERROR_FROM_DB;
+ sql_ret = sqlite3_get_table(db, query, &query_result, &row_count, &column_count, NULL);
+ if (sql_ret != SQLITE_OK && sql_ret != -1) {
+ NOTIFICATION_ERR("sqlite3_get_table failed [%d][%s]", sql_ret, query); /* LCOV_EXCL_LINE */
+ ret = NOTIFICATION_ERROR_FROM_DB;
goto out;
}
@@ -745,65 +751,70 @@ out:
if (query_result)
sqlite3_free_table(query_result);
- if (sql_query)
- sqlite3_free(sql_query);
+ if (query)
+ sqlite3_free(query);
- if (local_db_handle) {
- sql_return = db_util_close(local_db_handle);
- if (sql_return != SQLITE_OK)
- NOTIFICATION_WARN("fail to db_util_close - [%d]", sql_return); /* LCOV_EXCL_LINE */
+ if (db) {
+ sql_ret = db_util_close(db);
+ if (sql_ret != SQLITE_OK)
+ NOTIFICATION_WARN("fail to db_util_close - [%d]", sql_ret); /* LCOV_EXCL_LINE */
}
- return err;
+ return ret;
}
EXPORT_API int notification_system_setting_update_dnd_allow_exception(int type, int value, uid_t uid)
{
int ret = NOTIFICATION_ERROR_NONE;
- int sqlret;
+ int sql_ret;
int field_index = 1;
sqlite3 *db = NULL;
- sqlite3_stmt *db_statement = NULL;
+ sqlite3_stmt *stmt = NULL;
- db = notification_db_open(DBPATH);
- if (db == NULL)
- return get_last_result();
+ sql_ret = db_util_open(DBPATH, &db, 0);
+ if (sql_ret != SQLITE_OK || db == NULL) {
+ NOTIFICATION_ERR("db_util_open failed [%d]", sql_ret); /* LCOV_EXCL_LINE */
+ return NOTIFICATION_ERROR_FROM_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));
+ sql_ret = sqlite3_prepare_v2(db, "INSERT OR REPLACE INTO dnd_allow_exception (uid, type, value) VALUES(?, ?, ?) ", -1, &stmt, NULL);
+ if (sql_ret != SQLITE_OK) {
+ NOTIFICATION_ERR("sqlite3_prepare_v2 failed [%d][%s]", sql_ret, sqlite3_errmsg(db));
ret = NOTIFICATION_ERROR_FROM_DB;
goto out;
}
- sqlite3_bind_int(db_statement, field_index++, uid);
- sqlite3_bind_int(db_statement, field_index++, type);
- sqlite3_bind_int(db_statement, field_index++, value);
+ sqlite3_bind_int(stmt, field_index++, uid);
+ sqlite3_bind_int(stmt, field_index++, type);
+ sqlite3_bind_int(stmt, field_index++, value);
- sqlret = sqlite3_step(db_statement);
- if (sqlret != SQLITE_OK && sqlret != SQLITE_DONE) {
- NOTIFICATION_ERR("sqlite3_step failed [%d][%s]", sqlret, sqlite3_errmsg(db));
+ sql_ret = sqlite3_step(stmt);
+ if (sql_ret != SQLITE_OK && sql_ret != SQLITE_DONE) {
+ NOTIFICATION_ERR("sqlite3_step failed [%d][%s]", sql_ret, sqlite3_errmsg(db));
ret = NOTIFICATION_ERROR_FROM_DB;
goto out;
}
- sqlret = sqlite3_changes(db);
-
- if (sqlret == 0)
+ sql_ret = sqlite3_changes(db);
+ if (sql_ret == 0)
NOTIFICATION_WARN("No changes on DB");
+
out:
- if (db_statement)
- sqlite3_finalize(db_statement);
+ if (stmt)
+ sqlite3_finalize(stmt);
if (ret == NOTIFICATION_ERROR_NONE)
sqlite3_exec(db, "END;", NULL, NULL, NULL);
else
sqlite3_exec(db, "ROLLBACK;", NULL, NULL, NULL);
- notification_db_close(&db);
+ if (db) {
+ sql_ret = db_util_close(db);
+ if (sql_ret != SQLITE_OK)
+ NOTIFICATION_WARN("fail to db_util_close - [%d]", sql_ret); /* LCOV_EXCL_LINE */
+ }
return ret;
}
@@ -811,6 +822,7 @@ out:
EXPORT_API int noti_system_setting_get_do_not_disturb(int *do_not_disturb, uid_t uid)
{
int ret = NOTIFICATION_ERROR_NONE;
+ int sql_ret;
int row_count = 0;
int col_count = 0;
int col_index = 0;
@@ -818,13 +830,14 @@ EXPORT_API int noti_system_setting_get_do_not_disturb(int *do_not_disturb, uid_t
char **query_result = NULL;
sqlite3 *db = NULL;
- db = notification_db_open(DBPATH);
- if (db == NULL)
- return get_last_result();
+ sql_ret = db_util_open(DBPATH, &db, 0);
+ if (sql_ret != SQLITE_OK || db == NULL) {
+ NOTIFICATION_ERR("db_util_open failed [%d]", sql_ret); /* LCOV_EXCL_LINE */
+ return NOTIFICATION_ERROR_FROM_DB;
+ }
query = sqlite3_mprintf("SELECT do_not_disturb FROM %s WHERE uid = %d",
NOTIFICATION_SYSTEM_SETTING_DB_TABLE, uid);
-
if (query == NULL) {
NOTIFICATION_ERR("fail to alloc query");
ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
@@ -854,8 +867,11 @@ out:
if (query)
sqlite3_free(query);
- if (db)
- notification_db_close(&db);
+ if (db) {
+ sql_ret = db_util_close(db);
+ if (sql_ret != SQLITE_OK)
+ NOTIFICATION_WARN("fail to db_util_close - [%d]", sql_ret); /* LCOV_EXCL_LINE */
+ }
return ret;
}
@@ -863,17 +879,17 @@ out:
/* LCOV_EXCL_START */
EXPORT_API int notification_setting_db_update_app_disabled(const char *app_id, bool value, uid_t uid)
{
- int err = NOTIFICATION_ERROR_NONE;
- int sqlret;
+ int ret = NOTIFICATION_ERROR_NONE;
+ int sql_ret;
sqlite3 *db = NULL;
char *sqlbuf = NULL;
if (app_id == NULL)
return NOTIFICATION_ERROR_INVALID_PARAMETER;
- sqlret = db_util_open(DBPATH, &db, 0);
- if (sqlret != SQLITE_OK || db == NULL) {
- NOTIFICATION_ERR("db_util_open failed [%s][%d]", DBPATH, sqlret);
+ sql_ret = db_util_open(DBPATH, &db, 0);
+ if (sql_ret != SQLITE_OK || db == NULL) {
+ NOTIFICATION_ERR("db_util_open failed [%s][%d]", DBPATH, sql_ret);
return NOTIFICATION_ERROR_FROM_DB;
}
@@ -882,20 +898,22 @@ EXPORT_API int notification_setting_db_update_app_disabled(const char *app_id, b
value, app_id, uid);
if (!sqlbuf) {
NOTIFICATION_ERR("fail to alloc query");
- err = NOTIFICATION_ERROR_OUT_OF_MEMORY;
- goto return_close_db;
+ ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
+ goto out;
}
- err = notification_db_exec(db, sqlbuf, NULL);
+ ret = notification_db_exec(db, sqlbuf, NULL);
-return_close_db:
+out:
if (sqlbuf)
sqlite3_free(sqlbuf);
- sqlret = db_util_close(db);
- if (sqlret != SQLITE_OK)
- NOTIFICATION_WARN("fail to db_util_close - [%d]", sqlret);
+ if (db) {
+ sql_ret = db_util_close(db);
+ if (sql_ret != SQLITE_OK)
+ NOTIFICATION_WARN("fail to db_util_close - [%d]", sql_ret);
+ }
- return err;
+ return ret;
}
/* LCOV_EXCL_STOP */