4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Seungtaek Chung <seungtaek.chung@samsung.com>, Mi-Ju Lee <miju52.lee@samsung.com>, Xi Zhichan <zhichan.xi@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
27 #include <notification.h>
28 #include <notification_db.h>
29 #include <notification_noti.h>
30 #include <notification_debug.h>
31 #include <notification_ipc.h>
32 #include <notification_private.h>
33 #include <notification_setting.h>
34 #include <notification_setting_internal.h>
37 static int _get_table_field_data_int(char **table, int *buf, int index)
39 if ((table == NULL) || (buf == NULL) || (index < 0)) {
40 NOTIFICATION_ERR("table[%p], buf[%p], index[%d]", table, buf, index);
44 if (table[index] != NULL) {
45 *buf = atoi(table[index]);
53 static int _get_table_field_data_string(char **table, char **buf, int ucs2, int index)
57 if ((table == NULL) || (buf == NULL) || (index < 0)) {
58 NOTIFICATION_ERR("table[%p], buf[%p], index[%d]", table, buf, index);
62 char *pTemp = table[index];
69 *buf = (char *) malloc(sLen + 1);
71 NOTIFICATION_ERR("malloc is failed");
74 memset(*buf, 0, sLen + 1);
75 strncpy(*buf, pTemp, sLen);
89 EXPORT_API int notification_setting_get_setting_array(notification_setting_h *setting_array, int *count)
91 int err = NOTIFICATION_ERROR_NONE;
92 sqlite3 *local_db_handle = NULL;
93 char *sql_query = NULL;
94 char **query_result = NULL;
100 notification_setting_h result_setting_array= NULL;
102 if (setting_array == NULL || count == NULL) {
103 NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
104 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
108 sql_return = db_util_open(DBPATH, &local_db_handle, 0);
110 if (sql_return != SQLITE_OK || local_db_handle == NULL) {
111 NOTIFICATION_ERR("db_util_open failed [%d]", sql_return);
112 err = NOTIFICATION_ERROR_FROM_DB;
116 sql_query = sqlite3_mprintf("SELECT package_name, allow_to_notify, do_not_disturb_except, visibility_class "
118 "ORDER BY package_name", NOTIFICATION_SETTING_DB_TABLE);
121 NOTIFICATION_ERR("fail to alloc query");
122 err = NOTIFICATION_ERROR_OUT_OF_MEMORY;
126 sql_return = sqlite3_get_table(local_db_handle, sql_query, &query_result, &row_count, &column_count, NULL);
128 if (sql_return != SQLITE_OK && sql_return != -1) {
129 NOTIFICATION_ERR("NOTIFICATION_ERROR_FROM_DB failed [%d][%s]", sql_return, sql_query);
130 err = NOTIFICATION_ERROR_FROM_DB;
135 NOTIFICATION_DBG ("No setting found...");
136 err= NOTIFICATION_ERROR_NOT_EXIST_ID;
140 NOTIFICATION_DBG ("row_count [%d] column_count [%d]", row_count, column_count);
141 if (!(result_setting_array = (struct notification_setting*)malloc(sizeof(struct notification_setting) * row_count))) {
142 NOTIFICATION_ERR("malloc failed...");
143 err = NOTIFICATION_ERROR_OUT_OF_MEMORY;
147 col_index = column_count;
149 for (i = 0; i < row_count; i++) {
150 _get_table_field_data_string(query_result, &(result_setting_array[i].package_name), 1, col_index++);
151 _get_table_field_data_int(query_result, (int*)&(result_setting_array[i].allow_to_notify), col_index++);
152 _get_table_field_data_int(query_result, (int*)&(result_setting_array[i].do_not_disturb_except), col_index++);
153 _get_table_field_data_int(query_result, &(result_setting_array[i].visibility_class), col_index++);
156 *setting_array = result_setting_array;
161 sqlite3_free_table(query_result);
164 sqlite3_free(sql_query);
166 if (local_db_handle) {
167 sql_return = db_util_close(local_db_handle);
168 if (sql_return != SQLITE_OK) {
169 NOTIFICATION_WARN("fail to db_util_close - [%d]", sql_return);
176 EXPORT_API int notification_setting_get_setting_by_package_name(const char *package_name, notification_setting_h *setting)
178 int err = NOTIFICATION_ERROR_NONE;
179 sqlite3 *local_db_handle = NULL;
180 char *sql_query = NULL;
181 char **query_result = NULL;
184 int column_count = 0;
187 notification_setting_h result_setting_array= NULL;
189 if (package_name == NULL || setting == NULL) {
190 NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
191 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
195 sql_return = db_util_open(DBPATH, &local_db_handle, 0);
197 if (sql_return != SQLITE_OK || local_db_handle == NULL) {
198 NOTIFICATION_ERR("db_util_open failed [%d]", sql_return);
199 err = NOTIFICATION_ERROR_FROM_DB;
203 sql_query = sqlite3_mprintf("SELECT package_name, allow_to_notify, do_not_disturb_except, visibility_class "
205 "WHERE package_name = %Q ", NOTIFICATION_SETTING_DB_TABLE, package_name);
208 NOTIFICATION_ERR("fail to alloc query");
209 err = NOTIFICATION_ERROR_OUT_OF_MEMORY;
213 sql_return = sqlite3_get_table(local_db_handle, sql_query, &query_result, &row_count, &column_count, NULL);
215 if (sql_return != SQLITE_OK && sql_return != -1) {
216 NOTIFICATION_ERR("sqlite3_get_table failed [%d][%s]", sql_return, sql_query);
217 err = NOTIFICATION_ERROR_FROM_DB;
222 NOTIFICATION_DBG ("No setting found...");
223 err= NOTIFICATION_ERROR_NOT_EXIST_ID;
227 NOTIFICATION_DBG ("row_count [%d] column_count [%d]", row_count, column_count);
231 if (!(result_setting_array = (struct notification_setting*)malloc(sizeof(struct notification_setting) * row_count))) {
232 NOTIFICATION_ERR("malloc failed...");
233 err = NOTIFICATION_ERROR_OUT_OF_MEMORY;
237 col_index = column_count;
239 _get_table_field_data_string(query_result, &(result_setting_array[i].package_name), 1, col_index++);
240 _get_table_field_data_int(query_result, (int*)&(result_setting_array[i].allow_to_notify), col_index++);
241 _get_table_field_data_int(query_result, (int*)&(result_setting_array[i].do_not_disturb_except), col_index++);
242 _get_table_field_data_int(query_result, &(result_setting_array[i].visibility_class), col_index++);
244 *setting = result_setting_array;
248 sqlite3_free_table(query_result);
251 sqlite3_free(sql_query);
253 if (local_db_handle) {
254 sql_return = db_util_close(local_db_handle);
255 if (sql_return != SQLITE_OK) {
256 NOTIFICATION_WARN("fail to db_util_close - [%d]", sql_return);
263 EXPORT_API int notification_setting_get_setting(notification_setting_h *setting)
265 char *package_name = NULL;
267 package_name = notification_get_pkgname_by_pid();
269 if (package_name == NULL)
270 return NOTIFICATION_ERROR_NOT_EXIST_ID;
272 return notification_setting_get_setting_by_package_name(package_name, setting);
275 EXPORT_API int notification_setting_get_package_name(notification_setting_h setting, char **value)
277 int err = NOTIFICATION_ERROR_NONE;
279 if (setting == NULL || value == NULL) {
280 NOTIFICATION_ERR("Invalid parameter\n");
281 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
285 if (setting->package_name == NULL) {
286 NOTIFICATION_ERR("setting->package_name is null\n");
287 err = NOTIFICATION_ERROR_NOT_EXIST_ID;
291 *value = SAFE_STRDUP(setting->package_name);
298 EXPORT_API int notification_setting_set_package_name(notification_setting_h setting, char *value)
300 int err = NOTIFICATION_ERROR_NONE;
302 if (setting == NULL || value == NULL) {
303 NOTIFICATION_ERR("Invalid parameter\n");
304 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
308 if (setting->package_name != NULL) {
309 free(setting->package_name);
312 setting->package_name = SAFE_STRDUP(value);
319 EXPORT_API int notification_setting_get_allow_to_notify(notification_setting_h setting, bool *value)
321 int err = NOTIFICATION_ERROR_NONE;
323 if (setting == NULL || value == NULL) {
324 NOTIFICATION_ERR("Invalid parameter\n");
325 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
329 *value = setting->allow_to_notify;
336 EXPORT_API int notification_setting_set_allow_to_notify(notification_setting_h setting, bool value)
338 int err = NOTIFICATION_ERROR_NONE;
340 if (setting == NULL) {
341 NOTIFICATION_ERR("Invalid parameter\n");
342 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
346 setting->allow_to_notify = value;
353 EXPORT_API int notification_setting_get_do_not_disturb_except(notification_setting_h setting, bool *value)
355 int err = NOTIFICATION_ERROR_NONE;
357 if (setting == NULL || value == NULL) {
358 NOTIFICATION_ERR("Invalid parameter\n");
359 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
363 *value = setting->do_not_disturb_except;
370 EXPORT_API int notification_setting_set_do_not_disturb_except(notification_setting_h setting, bool value)
372 int err = NOTIFICATION_ERROR_NONE;
374 if (setting == NULL) {
375 NOTIFICATION_ERR("Invalid parameter\n");
376 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
380 setting->do_not_disturb_except = value;
387 EXPORT_API int notification_setting_get_visibility_class(notification_setting_h setting, int *value)
389 int err = NOTIFICATION_ERROR_NONE;
391 if (setting == NULL || value == NULL) {
392 NOTIFICATION_ERR("Invalid parameter\n");
393 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
397 *value = setting->visibility_class;
404 EXPORT_API int notification_setting_set_visibility_class(notification_setting_h setting, int value)
406 int err = NOTIFICATION_ERROR_NONE;
408 if (setting == NULL) {
409 NOTIFICATION_ERR("Invalid parameter\n");
410 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
414 setting->visibility_class = value;
421 EXPORT_API int notification_setting_update_setting(notification_setting_h setting)
423 int err = NOTIFICATION_ERROR_NONE;
425 if (setting == NULL) {
426 NOTIFICATION_ERR("Invalid parameter\n");
427 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
431 err = notification_ipc_update_setting(setting);
432 if (err != NOTIFICATION_ERROR_NONE) {
433 NOTIFICATION_ERR("notification_setting_update_setting returns[%d]\n", err);
441 EXPORT_API int notification_setting_free_notification(notification_setting_h setting)
443 int err = NOTIFICATION_ERROR_NONE;
445 if (setting == NULL) {
446 NOTIFICATION_ERR("Invalid parameter\n");
447 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
451 SAFE_FREE(setting->package_name);
454 /* add codes to free all properties */
462 EXPORT_API int notification_setting_db_update(const char *package_name, int allow_to_notify, int do_not_disturb_except, int visibility_class)
464 int err = NOTIFICATION_ERROR_NONE;
469 if (package_name == NULL)
470 return NOTIFICATION_ERROR_INVALID_PARAMETER;
472 sqlret = db_util_open(DBPATH, &db, 0);
473 if (sqlret != SQLITE_OK || db == NULL) {
474 NOTIFICATION_ERR("db_util_open failed [%s][%d]", DBPATH, sqlret);
475 return NOTIFICATION_ERROR_FROM_DB;
478 sqlbuf = sqlite3_mprintf("UPDATE %s SET allow_to_notify = %d, do_not_disturb_except = %d, visibility_class = %d " \
479 "WHERE package_name = %Q",
480 NOTIFICATION_SETTING_DB_TABLE, allow_to_notify, do_not_disturb_except, visibility_class, package_name);
482 NOTIFICATION_ERR("fail to alloc query");
483 err = NOTIFICATION_ERROR_OUT_OF_MEMORY;
484 goto return_close_db;
487 err = notification_db_exec(db, sqlbuf, NULL);
491 sqlite3_free(sqlbuf);
493 sqlret = db_util_close(db);
494 if (sqlret != SQLITE_OK) {
495 NOTIFICATION_WARN("fail to db_util_close - [%d]", sqlret);
501 /* system setting --------------------------------*/
503 EXPORT_API int notification_system_setting_load_system_setting(notification_system_setting_h *system_setting)
505 int err = NOTIFICATION_ERROR_NONE;
506 sqlite3 *local_db_handle = NULL;
507 char *sql_query = NULL;
508 char **query_result = NULL;
511 int column_count = 0;
513 notification_system_setting_h result_system_setting= NULL;
515 if (system_setting == NULL) {
516 NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
517 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
521 sql_return = db_util_open(DBPATH, &local_db_handle, 0);
523 if (sql_return != SQLITE_OK || local_db_handle == NULL) {
524 NOTIFICATION_ERR("db_util_open failed [%d]", sql_return);
525 err = NOTIFICATION_ERROR_FROM_DB;
529 sql_query = sqlite3_mprintf("SELECT do_not_disturb, visibility_class "
530 "FROM %s ", NOTIFICATION_SYSTEM_SETTING_DB_TABLE);
533 NOTIFICATION_ERR("fail to alloc query");
534 err = NOTIFICATION_ERROR_OUT_OF_MEMORY;
538 sql_return = sqlite3_get_table(local_db_handle, sql_query, &query_result, &row_count, &column_count, NULL);
540 if (sql_return != SQLITE_OK && sql_return != -1) {
541 NOTIFICATION_ERR("sqlite3_get_table failed [%d][%s]", sql_return, sql_query);
542 err = NOTIFICATION_ERROR_FROM_DB;
547 NOTIFICATION_DBG ("No setting found...");
548 err= NOTIFICATION_ERROR_NOT_EXIST_ID;
552 NOTIFICATION_DBG ("row_count [%d] column_count [%d]", row_count, column_count);
556 if (!(result_system_setting = (struct notification_system_setting*)malloc(sizeof(struct notification_system_setting)))) {
557 NOTIFICATION_ERR("malloc failed...");
558 err = NOTIFICATION_ERROR_OUT_OF_MEMORY;
562 col_index = column_count;
564 _get_table_field_data_int(query_result, (int*)&(result_system_setting->do_not_disturb), col_index++);
565 _get_table_field_data_int(query_result, &(result_system_setting->visibility_class), col_index++);
567 *system_setting = result_system_setting;
571 sqlite3_free_table(query_result);
574 sqlite3_free(sql_query);
576 if (local_db_handle) {
577 sql_return = db_util_close(local_db_handle);
578 if (sql_return != SQLITE_OK) {
579 NOTIFICATION_WARN("fail to db_util_close - [%d]", sql_return);
586 EXPORT_API int notification_system_setting_update_system_setting(notification_system_setting_h system_setting)
588 int err = NOTIFICATION_ERROR_NONE;
590 if (system_setting == NULL) {
591 NOTIFICATION_ERR("Invalid parameter\n");
592 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
596 err = notification_ipc_update_system_setting(system_setting);
597 if (err != NOTIFICATION_ERROR_NONE) {
598 NOTIFICATION_ERR("notification_ipc_update_system_setting returns[%d]\n", err);
606 EXPORT_API int notification_system_setting_free_system_setting(notification_system_setting_h system_setting)
608 int err = NOTIFICATION_ERROR_NONE;
610 if (system_setting == NULL) {
611 NOTIFICATION_ERR("Invalid parameter\n");
612 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
616 /* add codes to free all properties */
618 SAFE_FREE(system_setting);
625 EXPORT_API int notification_system_setting_get_do_not_disturb(notification_system_setting_h system_setting, bool *value)
627 int err = NOTIFICATION_ERROR_NONE;
629 if (system_setting == NULL || value == NULL) {
630 NOTIFICATION_ERR("Invalid parameter\n");
631 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
635 *value = system_setting->do_not_disturb;
642 EXPORT_API int notification_system_setting_set_do_not_disturb(notification_system_setting_h system_setting, bool value)
644 int err = NOTIFICATION_ERROR_NONE;
646 if (system_setting == NULL) {
647 NOTIFICATION_ERR("Invalid parameter\n");
648 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
652 system_setting->do_not_disturb = value;
659 EXPORT_API int notification_system_setting_get_visibility_class(notification_system_setting_h system_setting, int *value)
661 int err = NOTIFICATION_ERROR_NONE;
663 if (system_setting == NULL || value == NULL) {
664 NOTIFICATION_ERR("Invalid parameter\n");
665 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
669 *value = system_setting->visibility_class;
676 EXPORT_API int notification_system_setting_set_visibility_class(notification_system_setting_h system_setting, int value)
678 int err = NOTIFICATION_ERROR_NONE;
680 if (system_setting == NULL) {
681 NOTIFICATION_ERR("Invalid parameter\n");
682 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
686 system_setting->visibility_class = value;
694 EXPORT_API int notification_setting_db_update_system_setting(int do_not_disturb, int visibility_class)
696 int err = NOTIFICATION_ERROR_NONE;
697 char *query_buffer = NULL;
701 sqlite3_stmt *db_statement = NULL;
703 sqlret = db_util_open(DBPATH, &db, 0);
705 if (sqlret != SQLITE_OK || db == NULL) {
706 NOTIFICATION_ERR("db_util_open failed [%s][%d][%s]", DBPATH, sqlret, sqlite3_errmsg(db));
707 err = NOTIFICATION_ERROR_FROM_DB;
708 goto return_close_db;
711 query_buffer = strdup("UPDATE ? SET do_not_disturb = ?, visibility_class = ? ");
713 if (query_buffer == NULL) {
714 NOTIFICATION_ERR("fail to alloc query");
715 err = NOTIFICATION_ERROR_OUT_OF_MEMORY;
716 goto return_close_db;
719 sqlret = sqlite3_prepare_v2(db, query_buffer, strlen(query_buffer), &db_statement, NULL);
721 if (sqlret != SQLITE_OK) {
722 NOTIFICATION_ERR("sqlite3_prepare_v2 failed [%d][%s]", sqlret, sqlite3_errmsg(db));
723 err = NOTIFICATION_ERROR_FROM_DB;
724 goto return_close_db;
727 sqlite3_bind_text(db_statement, field_index++, NOTIFICATION_SYSTEM_SETTING_DB_TABLE, -1, SQLITE_STATIC);
728 sqlite3_bind_int(db_statement, field_index++, do_not_disturb);
729 sqlite3_bind_int(db_statement, field_index++, visibility_class);
731 sqlret = sqlite3_step(db_statement);
733 if (sqlret != SQLITE_OK && sqlret != SQLITE_DONE) {
734 NOTIFICATION_ERR("sqlite3_step failed [%d][%s]", sqlret, sqlite3_errmsg(db));
735 err = NOTIFICATION_ERROR_FROM_DB;
736 goto return_close_db;
739 sqlret = sqlite3_changes(db);
741 if (sqlret != SQLITE_OK && sqlret != SQLITE_DONE) {
742 NOTIFICATION_ERR("sqlite3_changes failed [%d][%s]", sqlret, sqlite3_errmsg(db));
743 err = NOTIFICATION_ERROR_FROM_DB;
744 goto return_close_db;
753 sqlite3_finalize(db_statement);
756 sqlret = db_util_close(db);
758 if (sqlret != SQLITE_OK) {
759 NOTIFICATION_WARN("fail to db_util_close - [%d]", sqlret);
765 /* OLD IMPLEMENTATION ----------------------------*/
766 #define NOTIFICATION_SETTING_DB "notification_setting"
767 #define NOTIFICATION_SETTING_DB_PATH "/opt/usr/dbspace/.notification_parser.db"
769 struct _notification_setting_h {
779 const char *property;
781 const char *default_value;
784 static struct prop_table g_prop_table[] = {
786 .property = "OPT_NOTIFICATION",
787 .column = "notification",
788 .default_value = "ON",
791 .property = "OPT_SOUNDS",
793 .default_value = "ON",
796 .property = "OPT_CONTENTS",
797 .column = "contents",
798 .default_value = "ON",
801 .property = "OPT_BADGE",
803 .default_value = "ON",
808 .default_value = NULL,
812 static const char *_get_prop_column(const char *property)
816 for (i = 0; g_prop_table[i].property; i++) {
817 if (strcmp(g_prop_table[i].property, property))
820 return g_prop_table[i].column;
827 static const char *_get_prop_default_value(const char *property)
831 for (i = 0; g_prop_table[i].property; i++) {
832 if (strcmp(g_prop_table[i].property, property))
835 return g_prop_table[i].default_value;
842 static int _is_record_exist(const char *pkgname, sqlite3 *db)
844 sqlite3_stmt *stmt = NULL;
846 int result = NOTIFICATION_ERROR_NONE;
851 return NOTIFICATION_ERROR_INVALID_PARAMETER;
854 return NOTIFICATION_ERROR_INVALID_PARAMETER;
856 sqlbuf = sqlite3_mprintf("SELECT count(*) FROM %s WHERE " \
858 NOTIFICATION_SETTING_DB, pkgname);
861 NOTIFICATION_ERR("fail to alloc sql query");
862 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
865 sqlret = sqlite3_prepare_v2(db, sqlbuf, -1, &stmt, NULL);
866 if (sqlret != SQLITE_OK) {
867 NOTIFICATION_ERR("DB err [%s]", sqlite3_errmsg(db));
868 NOTIFICATION_ERR("query[%s]", sqlbuf);
869 result = NOTIFICATION_ERROR_FROM_DB;
870 goto free_and_return;
873 sqlret = sqlite3_step(stmt);
874 if (sqlret == SQLITE_ROW)
875 count = sqlite3_column_int(stmt, 0);
880 result = NOTIFICATION_ERROR_ALREADY_EXIST_ID;
882 result = NOTIFICATION_ERROR_NOT_EXIST_ID;
886 sqlite3_free(sqlbuf);
889 sqlite3_finalize(stmt);
894 EXPORT_API int notification_setting_db_set(const char *pkgname, const char *property, const char *value)
896 int ret = NOTIFICATION_ERROR_NONE;
897 int result = NOTIFICATION_ERROR_NONE;
901 const char *column = NULL;
904 return NOTIFICATION_ERROR_INVALID_PARAMETER;
907 return NOTIFICATION_ERROR_INVALID_PARAMETER;
910 return NOTIFICATION_ERROR_INVALID_PARAMETER;
912 column = _get_prop_column(property);
914 return NOTIFICATION_ERROR_INVALID_PARAMETER;
916 sqlret = db_util_open(NOTIFICATION_SETTING_DB_PATH, &db, 0);
917 if (sqlret != SQLITE_OK || !db) {
918 NOTIFICATION_ERR("fail to db_util_open - [%d]", sqlret);
919 return NOTIFICATION_ERROR_FROM_DB;
922 ret = _is_record_exist(pkgname, db);
923 if (ret != NOTIFICATION_ERROR_ALREADY_EXIST_ID) {
925 goto return_close_db;
928 sqlbuf = sqlite3_mprintf("UPDATE %s SET %s = %Q " \
930 NOTIFICATION_SETTING_DB, column, value, pkgname);
932 NOTIFICATION_ERR("fail to alloc query");
933 result = NOTIFICATION_ERROR_OUT_OF_MEMORY;
934 goto return_close_db;
937 result = notification_db_exec(db, sqlbuf, NULL);
941 sqlite3_free(sqlbuf);
943 sqlret = db_util_close(db);
944 if (sqlret != SQLITE_OK) {
945 NOTIFICATION_WARN("fail to db_util_close - [%d]", sqlret);
951 EXPORT_API int notification_setting_db_get(const char *pkgname, const char *property, char **value)
953 int ret = NOTIFICATION_ERROR_NONE;
954 int result = NOTIFICATION_ERROR_NONE;
957 sqlite3_stmt *stmt = NULL;
959 const char *column = NULL;
962 return NOTIFICATION_ERROR_INVALID_PARAMETER;
965 return NOTIFICATION_ERROR_INVALID_PARAMETER;
968 return NOTIFICATION_ERROR_INVALID_PARAMETER;
970 column = _get_prop_column(property);
972 return NOTIFICATION_ERROR_INVALID_PARAMETER;
974 sqlret = db_util_open(NOTIFICATION_SETTING_DB_PATH, &db, 0);
975 if (sqlret != SQLITE_OK || !db) {
976 NOTIFICATION_ERR("fail to db_util_open - [%d]", sqlret);
977 return NOTIFICATION_ERROR_FROM_DB;
980 ret = _is_record_exist(pkgname, db);
981 if (ret != NOTIFICATION_ERROR_ALREADY_EXIST_ID) {
983 goto return_close_db;
986 sqlbuf = sqlite3_mprintf("SELECT %s FROM %s " \
988 column, NOTIFICATION_SETTING_DB, pkgname);
990 NOTIFICATION_ERR("fail to alloc query");
991 result = NOTIFICATION_ERROR_OUT_OF_MEMORY;
992 goto return_close_db;
995 sqlret = sqlite3_prepare_v2(db, sqlbuf, -1, &stmt, NULL);
996 if (sqlret != SQLITE_OK) {
997 NOTIFICATION_ERR("fail to prepare %s - [%s]",
998 sqlbuf, sqlite3_errmsg(db));
999 result = NOTIFICATION_ERROR_FROM_DB;
1000 goto return_close_db;
1003 sqlret = sqlite3_step(stmt);
1004 if (sqlret == SQLITE_ROW) {
1005 int get_bytes = sqlite3_column_bytes(stmt, 0);
1006 char *get_data = (char *)calloc(get_bytes + 1, sizeof(char));
1007 if (get_data != NULL) {
1008 memcpy(get_data, sqlite3_column_text(stmt, 0),
1009 get_bytes * sizeof(char));
1010 get_data[get_bytes] = '\0';
1013 NOTIFICATION_ERR("fail to alloc query");
1014 result = NOTIFICATION_ERROR_OUT_OF_MEMORY;
1015 goto return_close_db;
1021 sqlite3_free(sqlbuf);
1024 sqlite3_finalize(stmt);
1026 sqlret = db_util_close(db);
1027 if (sqlret != SQLITE_OK)
1028 NOTIFICATION_WARN("fail to db_util_close - [%d]", sqlret);
1033 EXPORT_API int notification_setting_property_set(const char *pkgname, const char *property, const char *value)
1038 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1041 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1044 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1046 ret = notification_ipc_noti_setting_property_set(pkgname, property, value);
1047 if (ret != NOTIFICATION_ERROR_NONE) {
1051 return NOTIFICATION_ERROR_NONE;
1054 EXPORT_API int notification_setting_property_get(const char *pkgname, const char *property, char **value)
1059 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1062 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1065 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1067 ret = notification_ipc_noti_setting_property_get(pkgname, property, value);
1068 if (ret != NOTIFICATION_ERROR_NONE) {
1072 return NOTIFICATION_ERROR_NONE;