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;
693 EXPORT_API int notification_setting_db_update_system_setting(int do_not_disturb, int visibility_class)
695 int err = NOTIFICATION_ERROR_NONE;
700 sqlret = db_util_open(DBPATH, &db, 0);
701 if (sqlret != SQLITE_OK || db == NULL) {
702 NOTIFICATION_ERR("db_util_open failed [%s][%d]", DBPATH, sqlret);
703 return NOTIFICATION_ERROR_FROM_DB;
706 sqlbuf = sqlite3_mprintf("UPDATE %s SET do_not_disturb = %d, visibility_class = %d ",
707 NOTIFICATION_SYSTEM_SETTING_DB_TABLE, do_not_disturb, visibility_class);
710 NOTIFICATION_ERR("fail to alloc query");
711 err = NOTIFICATION_ERROR_OUT_OF_MEMORY;
712 goto return_close_db;
715 err = notification_db_exec(db, sqlbuf, NULL);
719 sqlite3_free(sqlbuf);
721 sqlret = db_util_close(db);
722 if (sqlret != SQLITE_OK) {
723 NOTIFICATION_WARN("fail to db_util_close - [%d]", sqlret);
729 /* OLD IMPLEMENTATION ----------------------------*/
730 #define NOTIFICATION_SETTING_DB "notification_setting"
731 #define NOTIFICATION_SETTING_DB_PATH "/opt/usr/dbspace/.notification_parser.db"
733 struct _notification_setting_h {
743 const char *property;
745 const char *default_value;
748 static struct prop_table g_prop_table[] = {
750 .property = "OPT_NOTIFICATION",
751 .column = "notification",
752 .default_value = "ON",
755 .property = "OPT_SOUNDS",
757 .default_value = "ON",
760 .property = "OPT_CONTENTS",
761 .column = "contents",
762 .default_value = "ON",
765 .property = "OPT_BADGE",
767 .default_value = "ON",
772 .default_value = NULL,
776 static const char *_get_prop_column(const char *property)
780 for (i = 0; g_prop_table[i].property; i++) {
781 if (strcmp(g_prop_table[i].property, property))
784 return g_prop_table[i].column;
791 static const char *_get_prop_default_value(const char *property)
795 for (i = 0; g_prop_table[i].property; i++) {
796 if (strcmp(g_prop_table[i].property, property))
799 return g_prop_table[i].default_value;
806 static int _is_record_exist(const char *pkgname, sqlite3 *db)
808 sqlite3_stmt *stmt = NULL;
810 int result = NOTIFICATION_ERROR_NONE;
815 return NOTIFICATION_ERROR_INVALID_PARAMETER;
818 return NOTIFICATION_ERROR_INVALID_PARAMETER;
820 sqlbuf = sqlite3_mprintf("SELECT count(*) FROM %s WHERE " \
822 NOTIFICATION_SETTING_DB, pkgname);
825 NOTIFICATION_ERR("fail to alloc sql query");
826 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
829 sqlret = sqlite3_prepare_v2(db, sqlbuf, -1, &stmt, NULL);
830 if (sqlret != SQLITE_OK) {
831 NOTIFICATION_ERR("DB err [%s]", sqlite3_errmsg(db));
832 NOTIFICATION_ERR("query[%s]", sqlbuf);
833 result = NOTIFICATION_ERROR_FROM_DB;
834 goto free_and_return;
837 sqlret = sqlite3_step(stmt);
838 if (sqlret == SQLITE_ROW)
839 count = sqlite3_column_int(stmt, 0);
844 result = NOTIFICATION_ERROR_ALREADY_EXIST_ID;
846 result = NOTIFICATION_ERROR_NOT_EXIST_ID;
850 sqlite3_free(sqlbuf);
853 sqlite3_finalize(stmt);
858 EXPORT_API int notification_setting_db_set(const char *pkgname, const char *property, const char *value)
860 int ret = NOTIFICATION_ERROR_NONE;
861 int result = NOTIFICATION_ERROR_NONE;
865 const char *column = NULL;
868 return NOTIFICATION_ERROR_INVALID_PARAMETER;
871 return NOTIFICATION_ERROR_INVALID_PARAMETER;
874 return NOTIFICATION_ERROR_INVALID_PARAMETER;
876 column = _get_prop_column(property);
878 return NOTIFICATION_ERROR_INVALID_PARAMETER;
880 sqlret = db_util_open(NOTIFICATION_SETTING_DB_PATH, &db, 0);
881 if (sqlret != SQLITE_OK || !db) {
882 NOTIFICATION_ERR("fail to db_util_open - [%d]", sqlret);
883 return NOTIFICATION_ERROR_FROM_DB;
886 ret = _is_record_exist(pkgname, db);
887 if (ret != NOTIFICATION_ERROR_ALREADY_EXIST_ID) {
889 goto return_close_db;
892 sqlbuf = sqlite3_mprintf("UPDATE %s SET %s = %Q " \
894 NOTIFICATION_SETTING_DB, column, value, pkgname);
896 NOTIFICATION_ERR("fail to alloc query");
897 result = NOTIFICATION_ERROR_OUT_OF_MEMORY;
898 goto return_close_db;
901 result = notification_db_exec(db, sqlbuf, NULL);
905 sqlite3_free(sqlbuf);
907 sqlret = db_util_close(db);
908 if (sqlret != SQLITE_OK) {
909 NOTIFICATION_WARN("fail to db_util_close - [%d]", sqlret);
915 EXPORT_API int notification_setting_db_get(const char *pkgname, const char *property, char **value)
917 int ret = NOTIFICATION_ERROR_NONE;
918 int result = NOTIFICATION_ERROR_NONE;
921 sqlite3_stmt *stmt = NULL;
923 const char *column = NULL;
926 return NOTIFICATION_ERROR_INVALID_PARAMETER;
929 return NOTIFICATION_ERROR_INVALID_PARAMETER;
932 return NOTIFICATION_ERROR_INVALID_PARAMETER;
934 column = _get_prop_column(property);
936 return NOTIFICATION_ERROR_INVALID_PARAMETER;
938 sqlret = db_util_open(NOTIFICATION_SETTING_DB_PATH, &db, 0);
939 if (sqlret != SQLITE_OK || !db) {
940 NOTIFICATION_ERR("fail to db_util_open - [%d]", sqlret);
941 return NOTIFICATION_ERROR_FROM_DB;
944 ret = _is_record_exist(pkgname, db);
945 if (ret != NOTIFICATION_ERROR_ALREADY_EXIST_ID) {
947 goto return_close_db;
950 sqlbuf = sqlite3_mprintf("SELECT %s FROM %s " \
952 column, NOTIFICATION_SETTING_DB, pkgname);
954 NOTIFICATION_ERR("fail to alloc query");
955 result = NOTIFICATION_ERROR_OUT_OF_MEMORY;
956 goto return_close_db;
959 sqlret = sqlite3_prepare_v2(db, sqlbuf, -1, &stmt, NULL);
960 if (sqlret != SQLITE_OK) {
961 NOTIFICATION_ERR("fail to prepare %s - [%s]",
962 sqlbuf, sqlite3_errmsg(db));
963 result = NOTIFICATION_ERROR_FROM_DB;
964 goto return_close_db;
967 sqlret = sqlite3_step(stmt);
968 if (sqlret == SQLITE_ROW) {
969 int get_bytes = sqlite3_column_bytes(stmt, 0);
970 char *get_data = (char *)calloc(get_bytes + 1, sizeof(char));
971 if (get_data != NULL) {
972 memcpy(get_data, sqlite3_column_text(stmt, 0),
973 get_bytes * sizeof(char));
974 get_data[get_bytes] = '\0';
977 NOTIFICATION_ERR("fail to alloc query");
978 result = NOTIFICATION_ERROR_OUT_OF_MEMORY;
979 goto return_close_db;
985 sqlite3_free(sqlbuf);
988 sqlite3_finalize(stmt);
990 sqlret = db_util_close(db);
991 if (sqlret != SQLITE_OK)
992 NOTIFICATION_WARN("fail to db_util_close - [%d]", sqlret);
997 EXPORT_API int notification_setting_property_set(const char *pkgname, const char *property, const char *value)
1002 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1005 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1008 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1010 ret = notification_ipc_noti_setting_property_set(pkgname, property, value);
1011 if (ret != NOTIFICATION_ERROR_NONE) {
1015 return NOTIFICATION_ERROR_NONE;
1018 EXPORT_API int notification_setting_property_get(const char *pkgname, const char *property, char **value)
1023 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1026 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1029 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1031 ret = notification_ipc_noti_setting_property_get(pkgname, property, value);
1032 if (ret != NOTIFICATION_ERROR_NONE) {
1036 return NOTIFICATION_ERROR_NONE;