2 * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
26 #include <notification.h>
27 #include <notification_db.h>
28 #include <notification_error.h>
29 #include <notification_debug.h>
30 #include <notification_private.h>
31 #include <notification_setting.h>
32 #include <notification_setting_internal.h>
33 #include <notification_setting_service.h>
35 static int _get_table_field_data_int(char **table, int *buf, int index)
37 if ((table == NULL) || (buf == NULL) || (index < 0)) {
39 NOTIFICATION_ERR("table[%p], buf[%p], index[%d]", table, buf, index);
44 if (table[index] != NULL) {
45 *buf = atoi(table[index]);
55 static int _get_table_field_data_string(char **table, char **buf, int ucs2, int index)
59 if ((table == NULL) || (buf == NULL) || (index < 0)) {
61 NOTIFICATION_ERR("table[%p], buf[%p], index[%d]", table, buf, index);
66 char *pTemp = table[index];
69 *buf = NULL; /* LCOV_EXCL_LINE */
73 *buf = (char *) malloc(sLen + 1);
75 NOTIFICATION_ERR("malloc is failed"); /* LCOV_EXCL_LINE */
78 memset(*buf, 0, sLen + 1);
79 strncpy(*buf, pTemp, sLen);
81 *buf = NULL; /* LCOV_EXCL_LINE */
92 int noti_setting_service_get_setting_by_package_name(const char *package_name, notification_setting_h *setting, uid_t uid)
94 int err = NOTIFICATION_ERROR_NONE;
95 sqlite3 *local_db_handle = NULL;
96 char *sql_query = NULL;
97 char **query_result = NULL;
100 int column_count = 0;
103 notification_setting_h result_setting_array = NULL;
105 if (package_name == NULL || setting == NULL) {
106 NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER"); /* LCOV_EXCL_LINE */
107 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
111 sql_return = db_util_open(DBPATH, &local_db_handle, 0);
113 if (sql_return != SQLITE_OK || local_db_handle == NULL) {
114 NOTIFICATION_ERR("db_util_open failed [%d]", sql_return); /* LCOV_EXCL_LINE */
115 err = NOTIFICATION_ERROR_FROM_DB;
119 sql_query = sqlite3_mprintf("SELECT package_name, allow_to_notify, do_not_disturb_except, visibility_class, "
120 "pop_up_notification, lock_screen_content_level FROM %s "
121 "WHERE package_name = %Q AND uid = %d", NOTIFICATION_SETTING_DB_TABLE, package_name, uid);
124 NOTIFICATION_ERR("fail to alloc query"); /* LCOV_EXCL_LINE */
125 err = NOTIFICATION_ERROR_OUT_OF_MEMORY;
129 sql_return = sqlite3_get_table(local_db_handle, sql_query, &query_result, &row_count, &column_count, NULL);
131 if (sql_return != SQLITE_OK && sql_return != -1) {
132 NOTIFICATION_ERR("sqlite3_get_table failed [%d][%s]", sql_return, sql_query); /* LCOV_EXCL_LINE */
133 err = NOTIFICATION_ERROR_FROM_DB;
138 NOTIFICATION_DBG("No setting found for [%s]", package_name); /* LCOV_EXCL_LINE */
139 err = NOTIFICATION_ERROR_NOT_EXIST_ID;
143 NOTIFICATION_DBG("row_count [%d] column_count [%d]", row_count, column_count);
147 if (!(result_setting_array = (struct notification_setting *)malloc(sizeof(struct notification_setting) * row_count))) {
148 NOTIFICATION_ERR("malloc failed..."); /* LCOV_EXCL_LINE */
149 err = NOTIFICATION_ERROR_OUT_OF_MEMORY;
153 col_index = column_count;
155 _get_table_field_data_string(query_result, &(result_setting_array[i].package_name), 1, col_index++);
156 _get_table_field_data_int(query_result, (int *)&(result_setting_array[i].allow_to_notify), col_index++);
157 _get_table_field_data_int(query_result, (int *)&(result_setting_array[i].do_not_disturb_except), col_index++);
158 _get_table_field_data_int(query_result, &(result_setting_array[i].visibility_class), col_index++);
159 _get_table_field_data_int(query_result, (int *)&(result_setting_array[i].pop_up_notification), col_index++);
160 _get_table_field_data_int(query_result, (int *)&(result_setting_array[i].lock_screen_content_level), col_index++);
162 *setting = result_setting_array;
166 sqlite3_free_table(query_result);
169 sqlite3_free(sql_query);
171 if (local_db_handle) {
172 sql_return = db_util_close(local_db_handle);
173 if (sql_return != SQLITE_OK)
174 NOTIFICATION_WARN("fail to db_util_close - [%d]", sql_return); /* LCOV_EXCL_LINE */
181 int noti_setting_get_setting_array(notification_setting_h *setting_array, int *count, uid_t uid)
183 int err = NOTIFICATION_ERROR_NONE;
184 sqlite3 *local_db_handle = NULL;
185 char *sql_query = NULL;
186 char **query_result = NULL;
189 int column_count = 0;
192 notification_setting_h result_setting_array = NULL;
194 if (setting_array == NULL || count == NULL) {
195 NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER"); /* LCOV_EXCL_LINE */
196 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
200 sql_return = db_util_open(DBPATH, &local_db_handle, 0);
202 if (sql_return != SQLITE_OK || local_db_handle == NULL) {
203 NOTIFICATION_ERR("db_util_open failed [%d]", sql_return); /* LCOV_EXCL_LINE */
204 err = NOTIFICATION_ERROR_FROM_DB;
208 sql_query = sqlite3_mprintf("SELECT package_name, allow_to_notify, do_not_disturb_except, visibility_class, "
209 "pop_up_notification, lock_screen_content_level FROM %s WHERE uid = %d "
210 "ORDER BY package_name", NOTIFICATION_SETTING_DB_TABLE, uid);
213 NOTIFICATION_ERR("fail to alloc query"); /* LCOV_EXCL_LINE */
214 err = NOTIFICATION_ERROR_OUT_OF_MEMORY;
218 sql_return = sqlite3_get_table(local_db_handle, sql_query, &query_result, &row_count, &column_count, NULL);
220 if (sql_return != SQLITE_OK && sql_return != -1) {
221 NOTIFICATION_ERR("NOTIFICATION_ERROR_FROM_DB failed [%d][%s]", sql_return, sql_query); /* LCOV_EXCL_LINE */
222 err = NOTIFICATION_ERROR_FROM_DB;
227 NOTIFICATION_DBG("No setting found..."); /* LCOV_EXCL_LINE */
228 err = NOTIFICATION_ERROR_NOT_EXIST_ID;
232 NOTIFICATION_DBG("row_count [%d] column_count [%d]", row_count, column_count);
233 if (!(result_setting_array = (struct notification_setting *)malloc(sizeof(struct notification_setting) * row_count))) {
234 NOTIFICATION_ERR("malloc failed..."); /* LCOV_EXCL_LINE */
235 err = NOTIFICATION_ERROR_OUT_OF_MEMORY;
239 col_index = column_count;
241 for (i = 0; i < row_count; i++) {
242 _get_table_field_data_string(query_result, &(result_setting_array[i].package_name), 1, col_index++);
243 _get_table_field_data_int(query_result, (int *)&(result_setting_array[i].allow_to_notify), col_index++);
244 _get_table_field_data_int(query_result, (int *)&(result_setting_array[i].do_not_disturb_except), col_index++);
245 _get_table_field_data_int(query_result, &(result_setting_array[i].visibility_class), col_index++);
246 _get_table_field_data_int(query_result, (int *)&(result_setting_array[i].pop_up_notification), col_index++);
247 _get_table_field_data_int(query_result, (int *)&(result_setting_array[i].lock_screen_content_level), col_index++);
250 *setting_array = result_setting_array;
255 sqlite3_free_table(query_result);
258 sqlite3_free(sql_query);
260 if (local_db_handle) {
261 sql_return = db_util_close(local_db_handle);
262 if (sql_return != SQLITE_OK)
263 NOTIFICATION_WARN("fail to db_util_close - [%d]", sql_return); /* LCOV_EXCL_LINE */
271 int noti_system_setting_load_system_setting(notification_system_setting_h *system_setting, uid_t uid)
273 int err = NOTIFICATION_ERROR_NONE;
274 sqlite3 *local_db_handle = NULL;
275 char *sql_query = NULL;
276 char **query_result = NULL;
279 int column_count = 0;
281 notification_system_setting_h result_system_setting = NULL;
283 if (system_setting == NULL) {
284 NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER"); /* LCOV_EXCL_LINE */
285 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
289 sql_return = db_util_open(DBPATH, &local_db_handle, 0);
291 if (sql_return != SQLITE_OK || local_db_handle == NULL) {
292 NOTIFICATION_ERR("db_util_open failed [%d]", sql_return); /* LCOV_EXCL_LINE */
293 err = NOTIFICATION_ERROR_FROM_DB;
297 sql_query = sqlite3_mprintf("SELECT do_not_disturb, visibility_class, "
298 "dnd_schedule_enabled, dnd_schedule_day, "
299 "dnd_start_hour, dnd_start_min, dnd_end_hour, dnd_end_min, "
300 "lock_screen_content_level "
301 "FROM %s WHERE uid = %d", NOTIFICATION_SYSTEM_SETTING_DB_TABLE, uid);
304 NOTIFICATION_ERR("fail to alloc query"); /* LCOV_EXCL_LINE */
305 err = NOTIFICATION_ERROR_OUT_OF_MEMORY;
309 sql_return = sqlite3_get_table(local_db_handle, sql_query, &query_result, &row_count, &column_count, NULL);
311 if (sql_return != SQLITE_OK && sql_return != -1) {
312 NOTIFICATION_ERR("sqlite3_get_table failed [%d][%s]", sql_return, sql_query); /* LCOV_EXCL_LINE */
313 err = NOTIFICATION_ERROR_FROM_DB;
317 NOTIFICATION_DBG("row_count [%d] column_count [%d]", row_count, column_count);
318 if (!(result_system_setting = (struct notification_system_setting *)malloc(sizeof(struct notification_system_setting)))) {
319 NOTIFICATION_ERR("malloc failed..."); /* LCOV_EXCL_LINE */
320 err = NOTIFICATION_ERROR_OUT_OF_MEMORY;
324 /* no system setting record. allow everyting */
326 NOTIFICATION_DBG("No setting found..."); /* LCOV_EXCL_LINE */
327 result_system_setting->do_not_disturb = 0;
328 result_system_setting->visibility_class = 0;
329 result_system_setting->dnd_schedule_enabled = 0;
330 result_system_setting->dnd_schedule_day = 0;
331 result_system_setting->dnd_start_hour = 0;
332 result_system_setting->dnd_start_min = 0;
333 result_system_setting->dnd_end_hour = 0;
334 result_system_setting->dnd_end_min = 0;
335 result_system_setting->lock_screen_content_level = 0;
336 result_system_setting->dnd_allow_exceptions = NULL;
338 /* LCOV_EXCL_START */
339 col_index = column_count;
340 _get_table_field_data_int(query_result, (int *)&(result_system_setting->do_not_disturb), col_index++);
341 _get_table_field_data_int(query_result, &(result_system_setting->visibility_class), col_index++);
342 _get_table_field_data_int(query_result, (int *)&(result_system_setting->dnd_schedule_enabled), col_index++);
343 _get_table_field_data_int(query_result, &(result_system_setting->dnd_schedule_day), col_index++);
344 _get_table_field_data_int(query_result, &(result_system_setting->dnd_start_hour), col_index++);
345 _get_table_field_data_int(query_result, &(result_system_setting->dnd_start_min), col_index++);
346 _get_table_field_data_int(query_result, &(result_system_setting->dnd_end_hour), col_index++);
347 _get_table_field_data_int(query_result, &(result_system_setting->dnd_end_min), col_index++);
348 _get_table_field_data_int(query_result, (int *)&(result_system_setting->lock_screen_content_level), col_index++);
349 result_system_setting->dnd_allow_exceptions = NULL;
353 *system_setting = result_system_setting;
356 sqlite3_free_table(query_result);
359 sqlite3_free(sql_query);
361 if (local_db_handle) {
362 sql_return = db_util_close(local_db_handle);
363 if (sql_return != SQLITE_OK)
364 NOTIFICATION_WARN("fail to db_util_close - [%d]", sql_return); /* LCOV_EXCL_LINE */
371 int notification_setting_db_update(const char *package_name, int allow_to_notify,
372 int do_not_disturb_except, int visibility_class,
373 int pop_up_notification, int lock_screen_content_level,
376 int err = NOTIFICATION_ERROR_NONE;
381 if (package_name == NULL || strlen(package_name) == 0)
382 return NOTIFICATION_ERROR_INVALID_PARAMETER;
384 sqlret = db_util_open(DBPATH, &db, 0);
385 if (sqlret != SQLITE_OK || db == NULL) {
386 NOTIFICATION_ERR("db_util_open failed [%s][%d]", DBPATH, sqlret);
387 return NOTIFICATION_ERROR_FROM_DB;
390 sqlbuf = sqlite3_mprintf("UPDATE %s SET allow_to_notify = %d, do_not_disturb_except = %d, visibility_class = %d, " \
391 "pop_up_notification = %d, lock_screen_content_level = %d " \
392 "WHERE package_name = %Q AND uid = %d",
393 NOTIFICATION_SETTING_DB_TABLE, allow_to_notify, do_not_disturb_except, visibility_class,
394 pop_up_notification, lock_screen_content_level, package_name, uid);
396 NOTIFICATION_ERR("fail to alloc query");
397 err = NOTIFICATION_ERROR_OUT_OF_MEMORY;
398 goto return_close_db;
401 err = notification_db_exec(db, sqlbuf, NULL);
405 sqlite3_free(sqlbuf);
407 sqlret = db_util_close(db);
408 if (sqlret != SQLITE_OK)
409 NOTIFICATION_WARN("fail to db_util_close - [%d]", sqlret);
415 int notification_setting_db_update_system_setting(int do_not_disturb, int visibility_class,
416 int dnd_schedule_enabled, int dnd_schedule_day,
417 int dnd_start_hour, int dnd_start_min,
418 int dnd_end_hour, int dnd_end_min,
419 int lock_screen_content_level, uid_t uid)
421 int err = NOTIFICATION_ERROR_NONE;
425 sqlite3_stmt *db_statement = NULL;
427 sqlret = db_util_open(DBPATH, &db, 0);
429 if (sqlret != SQLITE_OK || db == NULL) {
430 NOTIFICATION_ERR("db_util_open failed [%s][%d][%s]", DBPATH, sqlret, sqlite3_errmsg(db));
431 err = NOTIFICATION_ERROR_FROM_DB;
432 goto return_close_db;
435 sqlite3_exec(db, "BEGIN immediate;", NULL, NULL, NULL);
437 sqlret = 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);
439 if (sqlret != SQLITE_OK) {
440 NOTIFICATION_ERR("sqlite3_prepare_v2 failed [%d][%s]", sqlret, sqlite3_errmsg(db));
441 err = NOTIFICATION_ERROR_FROM_DB;
442 goto return_close_db;
445 sqlite3_bind_int(db_statement, field_index++, uid);
446 sqlite3_bind_int(db_statement, field_index++, do_not_disturb);
447 sqlite3_bind_int(db_statement, field_index++, visibility_class);
448 sqlite3_bind_int(db_statement, field_index++, dnd_schedule_enabled);
449 sqlite3_bind_int(db_statement, field_index++, dnd_schedule_day);
450 sqlite3_bind_int(db_statement, field_index++, dnd_start_hour);
451 sqlite3_bind_int(db_statement, field_index++, dnd_start_min);
452 sqlite3_bind_int(db_statement, field_index++, dnd_end_hour);
453 sqlite3_bind_int(db_statement, field_index++, dnd_end_min);
454 sqlite3_bind_int(db_statement, field_index++, lock_screen_content_level);
456 sqlret = sqlite3_step(db_statement);
457 if (sqlret != SQLITE_OK && sqlret != SQLITE_DONE) {
458 NOTIFICATION_ERR("sqlite3_step failed [%d][%s]", sqlret, sqlite3_errmsg(db));
459 err = NOTIFICATION_ERROR_FROM_DB;
460 goto return_close_db;
463 sqlret = sqlite3_changes(db);
466 NOTIFICATION_WARN("No changes on DB");
470 sqlite3_finalize(db_statement);
474 if (err == NOTIFICATION_ERROR_NONE)
475 sqlite3_exec(db, "END;", NULL, NULL, NULL);
477 sqlite3_exec(db, "ROLLBACK;", NULL, NULL, NULL);
479 sqlret = db_util_close(db);
482 if (sqlret != SQLITE_OK)
483 NOTIFICATION_WARN("fail to db_util_close - [%d]", sqlret);
488 /* LCOV_EXCL_START */
490 int notification_setting_db_update_do_not_disturb(int do_not_disturb, uid_t uid)
492 int err = NOTIFICATION_ERROR_NONE;
497 sqlret = db_util_open(DBPATH, &db, 0);
498 if (sqlret != SQLITE_OK || db == NULL) {
499 NOTIFICATION_ERR("db_util_open failed [%s][%d]", DBPATH, sqlret);
500 return NOTIFICATION_ERROR_FROM_DB;
503 sqlbuf = sqlite3_mprintf("UPDATE notification_system_setting SET do_not_disturb = %d WHERE uid = %d", do_not_disturb, uid);
505 NOTIFICATION_ERR("fail to alloc query");
506 err = NOTIFICATION_ERROR_OUT_OF_MEMORY;
507 goto return_close_db;
510 err = notification_db_exec(db, sqlbuf, NULL);
514 sqlite3_free(sqlbuf);
516 sqlret = db_util_close(db);
517 if (sqlret != SQLITE_OK)
518 NOTIFICATION_WARN("fail to db_util_close - [%d]", sqlret);
524 EXPORT_API int notification_system_setting_get_dnd_schedule_enabled_uid(uid_t **uids, int *count)
528 int column_count = 0;
529 int column_index = 0;
531 char **query_result = NULL;
535 db = notification_db_open(DBPATH);
537 return get_last_result();
539 query = sqlite3_mprintf("SELECT uid FROM %s WHERE dnd_schedule_enabled = 1",
540 NOTIFICATION_SYSTEM_SETTING_DB_TABLE);
542 ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
546 ret = sqlite3_get_table(db, query, &query_result, &row_count, &column_count, NULL);
547 if (ret != SQLITE_OK && ret != -1) {
548 NOTIFICATION_ERR("NOTIFICATION_ERROR_FROM_DB failed [%d][%s]", ret, query); /* LCOV_EXCL_LINE */
549 ret = NOTIFICATION_ERROR_FROM_DB;
553 if (row_count == 0) {
554 NOTIFICATION_DBG("No enabled do_not_disturb user");
555 ret = NOTIFICATION_ERROR_NONE;
559 if (!(result_uids = (uid_t *)malloc(sizeof(int) * row_count))) {
560 NOTIFICATION_ERR("Memory allocation fail");
561 ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
565 column_index = column_count;
566 for (i = 0; i < row_count; i++)
567 _get_table_field_data_int(query_result, (int *)&(result_uids[i]), column_index++);
574 sqlite3_free_table(query_result);
578 notification_db_close(&db);
583 EXPORT_API int notification_get_dnd_and_allow_to_notify(const char *pkgname,
585 int *do_not_disturb_except,
586 int *allow_to_notify,
589 int ret = NOTIFICATION_ERROR_NONE;
595 char *query_setting = NULL;
596 char **query_setting_result = NULL;
597 char *query_system_setting = NULL;
598 char **query_system_setting_result = NULL;
601 return NOTIFICATION_ERROR_INVALID_PARAMETER;
603 db = notification_db_open(DBPATH);
605 return get_last_result();
607 query_setting = sqlite3_mprintf("SELECT allow_to_notify, do_not_disturb_except "
608 "FROM %s WHERE package_name = %Q AND uid = %d",
609 NOTIFICATION_SETTING_DB_TABLE, pkgname, uid);
610 if (query_setting == NULL) {
611 NOTIFICATION_ERR("fail to alloc query");
612 ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
616 query_system_setting = sqlite3_mprintf("SELECT do_not_disturb FROM %s WHERE uid = %d",
617 NOTIFICATION_SYSTEM_SETTING_DB_TABLE, uid);
619 if (query_system_setting == NULL) {
620 NOTIFICATION_ERR("fail to alloc query");
621 ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
625 sql_ret = sqlite3_get_table(db, query_setting, &query_setting_result, &row_count, &col_count, NULL);
626 if (sql_ret != SQLITE_OK && sql_ret != -1) {
627 NOTIFICATION_ERR("NOTIFICATION_ERROR_FROM_DB failed [%d][%s]", sql_ret, query_setting);
628 ret = NOTIFICATION_ERROR_FROM_DB;
632 col_index = col_count;
633 _get_table_field_data_int(query_setting_result, (int *)allow_to_notify, col_index++);
634 _get_table_field_data_int(query_setting_result, (int *)do_not_disturb_except, col_index++);
636 sql_ret = sqlite3_get_table(db, query_system_setting, &query_system_setting_result, &row_count, &col_count, NULL);
637 if (sql_ret != SQLITE_OK && sql_ret != -1) {
638 NOTIFICATION_ERR("NOTIFICATION_ERROR_FROM_DB failed [%d][%s]", sql_ret, query_setting);
639 ret = NOTIFICATION_ERROR_FROM_DB;
643 col_index = col_count;
644 _get_table_field_data_int(query_system_setting_result, (int *)do_not_disturb, col_index++);
647 if (query_setting_result)
648 sqlite3_free_table(query_setting_result);
649 if (query_system_setting_result)
650 sqlite3_free_table(query_system_setting_result);
652 sqlite3_free(query_setting);
653 if (query_system_setting)
654 sqlite3_free(query_system_setting);
656 notification_db_close(&db);
661 EXPORT_API int notification_system_setting_load_dnd_allow_exception(dnd_allow_exception_h *dnd_allow_exception, int *count, uid_t uid)
663 int err = NOTIFICATION_ERROR_NONE;
666 int column_count = 0;
669 char *sql_query = NULL;
670 char **query_result = NULL;
671 sqlite3 *local_db_handle = NULL;
672 dnd_allow_exception_h dnd_allow_exception_data = NULL;
674 if (dnd_allow_exception == NULL) {
675 NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER"); /* LCOV_EXCL_LINE */
676 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
680 sql_return = db_util_open(DBPATH, &local_db_handle, 0);
681 if (sql_return != SQLITE_OK || local_db_handle == NULL) {
682 NOTIFICATION_ERR("db_util_open failed [%d]", sql_return); /* LCOV_EXCL_LINE */
683 err = NOTIFICATION_ERROR_FROM_DB;
687 sql_query = sqlite3_mprintf("SELECT type, value FROM %s WHERE uid = %d",
688 NOTIFICATION_DND_ALLOW_EXCEPTION, uid);
690 NOTIFICATION_ERR("fail to alloc query"); /* LCOV_EXCL_LINE */
691 err = NOTIFICATION_ERROR_OUT_OF_MEMORY;
695 sql_return = sqlite3_get_table(local_db_handle, sql_query, &query_result, &row_count, &column_count, NULL);
696 if (sql_return != SQLITE_OK && sql_return != -1) {
697 NOTIFICATION_ERR("sqlite3_get_table failed [%d][%s]", sql_return, sql_query); /* LCOV_EXCL_LINE */
698 err = NOTIFICATION_ERROR_FROM_DB;
703 NOTIFICATION_DBG("No setting found..."); /* LCOV_EXCL_LINE */
706 dnd_allow_exception_data = (dnd_allow_exception_h)malloc(sizeof(struct notification_system_setting_dnd_allow_exception) * row_count);
707 if (dnd_allow_exception_data == NULL) {
708 NOTIFICATION_ERR("failed to malloc");
709 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
712 col_index = column_count;
714 for (i = 0; i < row_count; i++) {
715 _get_table_field_data_int(query_result, (int *)&(dnd_allow_exception_data[i].type), col_index++);
716 _get_table_field_data_int(query_result, (int *)&(dnd_allow_exception_data[i].value), col_index++);
720 *dnd_allow_exception = dnd_allow_exception_data;
725 sqlite3_free_table(query_result);
728 sqlite3_free(sql_query);
730 if (local_db_handle) {
731 sql_return = db_util_close(local_db_handle);
732 if (sql_return != SQLITE_OK)
733 NOTIFICATION_WARN("fail to db_util_close - [%d]", sql_return); /* LCOV_EXCL_LINE */
739 EXPORT_API int notification_system_setting_update_dnd_allow_exception(int type, int value, uid_t uid)
741 int ret = NOTIFICATION_ERROR_NONE;
746 sqlret = db_util_open(DBPATH, &db, 0);
747 if (sqlret != SQLITE_OK || db == NULL) {
748 NOTIFICATION_ERR("db_util_open failed [%s][%d]", DBPATH, sqlret);
749 return NOTIFICATION_ERROR_FROM_DB;
752 sqlbuf = sqlite3_mprintf("UPDATE dnd_allow_exception SET value = %d WHERE type = %d AND uid = %d", value, type, uid);
754 NOTIFICATION_ERR("fail to alloc query");
755 ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
756 goto return_close_db;
759 ret = notification_db_exec(db, sqlbuf, NULL);
763 sqlite3_free(sqlbuf);
765 sqlret = db_util_close(db);
766 if (sqlret != SQLITE_OK)
767 NOTIFICATION_WARN("fail to db_util_close - [%d]", sqlret);