diff options
Diffstat (limited to 'src')
-rwxr-xr-x | src/notification.c | 332 | ||||
-rwxr-xr-x | src/notification_db.c | 7 | ||||
-rwxr-xr-x | src/notification_ipc.c | 171 | ||||
-rwxr-xr-x | src/notification_noti.c | 286 | ||||
-rwxr-xr-x | src/notification_ongoing.c | 9 | ||||
-rwxr-xr-x | src/notification_setting.c | 351 | ||||
-rwxr-xr-x | src/notification_status.c | 14 |
7 files changed, 701 insertions, 469 deletions
diff --git a/src/notification.c b/src/notification.c index 8c85a90..27a440f 100755 --- a/src/notification.c +++ b/src/notification.c @@ -30,7 +30,6 @@ #include <aul.h> #include <ail.h> -#include <appsvc.h> #include <vconf-keys.h> #include <vconf.h> @@ -64,12 +63,6 @@ static notification_cb_list_s *g_notification_cb_list = NULL; #define NOTI_TEXT_RESULT_LEN 2048 #define NOTI_PKGNAME_LEN 512 -#define NOTI_CHANGED_NOTI "notification_noti_changed" -#define NOTI_CHANGED_ONGOING "notification_ontoing_changed" - -#define NOTI_DBUS_BUS_NAME "org.tizen.libnotification" -#define NOTI_DBUS_PATH "/org/tizen/libnotification" -#define NOTI_DBUS_INTERFACE "org.tizen.libnotification.signal" static char *_notification_get_pkgname_by_pid(void) { @@ -117,62 +110,6 @@ static char *_notification_get_pkgname_by_pid(void) return dup_pkgname; } -static char *_notification_get_icon(const char *package) -{ - ail_appinfo_h handle; - ail_error_e ret; - char *str = NULL; - char *icon = NULL; - - ret = ail_package_get_appinfo(package, &handle); - if (ret != AIL_ERROR_OK) { - return NULL; - } - - ret = ail_appinfo_get_str(handle, AIL_PROP_ICON_STR, &str); - if (ret != AIL_ERROR_OK) { - ail_package_destroy_appinfo(handle); - return NULL; - } - - icon = strdup(str); - - ret = ail_package_destroy_appinfo(handle); - if (ret != AIL_ERROR_OK) { - NOTIFICATION_ERR("Fail to ail_package_destroy_appinfo"); - } - - return icon; -} - -static char *_notification_get_name(const char *package) -{ - ail_appinfo_h handle; - ail_error_e ret; - char *str = NULL; - char *name = NULL; - - ret = ail_package_get_appinfo(package, &handle); - if (ret != AIL_ERROR_OK) { - return NULL; - } - - ret = ail_appinfo_get_str(handle, AIL_PROP_NAME_STR, &str); - if (ret != AIL_ERROR_OK) { - ail_package_destroy_appinfo(handle); - return NULL; - } - - name = strdup(str); - - ret = ail_package_destroy_appinfo(handle); - if (ret != AIL_ERROR_OK) { - NOTIFICATION_ERR("Fail to ail_package_destroy_appinfo"); - } - - return name; -} - static void _notification_get_text_domain(notification_h noti) { if (noti->domain != NULL) { @@ -277,7 +214,6 @@ EXPORT_API notification_error_e notification_get_image(notification_h noti, bundle *b = NULL; char buf_key[32] = { 0, }; const char *ret_val = NULL; - const char *pkgname = NULL; /* Check noti and image_path is valid data */ if (noti == NULL || image_path == NULL) { @@ -315,31 +251,7 @@ EXPORT_API notification_error_e notification_get_image(notification_h noti, /* image path will be app icon path */ *image_path = noti->app_icon_path; } else { - /* Get image path using launch_pkgname */ - if (noti->launch_pkgname != NULL) { - noti->app_icon_path = - _notification_get_icon(noti->launch_pkgname); - } - - /* If app icon path is NULL, get image path using caller_pkgname */ - if (noti->app_icon_path == NULL - && noti->caller_pkgname != NULL) { - noti->app_icon_path = - _notification_get_icon(noti->caller_pkgname); - } - - /* If app icon path is NULL, get image path using service data */ - if (noti->app_icon_path == NULL - && noti->b_service_single_launch != NULL) { - pkgname = - appsvc_get_pkgname(noti->b_service_single_launch); - if (pkgname != NULL) { - noti->app_icon_path = - _notification_get_icon(pkgname); - } - } - - *image_path = noti->app_icon_path; + *image_path = NULL; } } @@ -745,11 +657,8 @@ EXPORT_API notification_error_e notification_get_text(notification_h noti, bundle *b = NULL; char buf_key[32] = { 0, }; const char *ret_val = NULL; - const char *pkgname = NULL; const char *get_str = NULL; const char *get_check_type_str = NULL; - int ret = 0; - int boolval = 0; notification_text_type_e check_type = NOTIFICATION_TEXT_TYPE_NONE; int display_option_flag = 0; @@ -1095,46 +1004,7 @@ EXPORT_API notification_error_e notification_get_text(notification_h noti, } } else { - if (check_type == NOTIFICATION_TEXT_TYPE_TITLE - || check_type == NOTIFICATION_TEXT_TYPE_GROUP_TITLE) { - /* Remove app name if exist, because pkgname is changed according to language setting */ - if (noti->app_name != NULL) { - free(noti->app_name); - noti->app_name = NULL; - } - - /* First, get app name from launch_pkgname */ - if (noti->launch_pkgname != NULL) { - noti->app_name = - _notification_get_name(noti-> - launch_pkgname); - } - - /* Second, get app name from caller_pkgname */ - if (noti->app_name == NULL - && noti->caller_pkgname != NULL) { - noti->app_name = - _notification_get_name(noti-> - caller_pkgname); - } - - /* Third, get app name from service data */ - if (noti->app_name == NULL - && noti->b_service_single_launch != NULL) { - pkgname = - appsvc_get_pkgname(noti-> - b_service_single_launch); - - if (pkgname != NULL) { - noti->app_name = - _notification_get_name(pkgname); - } - } - - *text = noti->app_name; - } else { - *text = NULL; - } + *text = NULL; } return NOTIFICATION_ERROR_NONE; @@ -1218,8 +1088,6 @@ EXPORT_API notification_error_e notification_get_time_from_text(notification_h n time_t *time) { notification_error_e ret = NOTIFICATION_ERROR_NONE; - char buf[256] = { 0, }; - char buf_tag[512] = { 0, }; if (noti == NULL) { return NOTIFICATION_ERROR_INVALID_DATA; @@ -1580,44 +1448,48 @@ EXPORT_API notification_error_e notification_set_execute_option(notification_h n } switch (type) { - case NOTIFICATION_EXECUTE_TYPE_RESPONDING: - /* Remove previous data if exist */ - if (noti->b_service_responding != NULL) { - bundle_free(noti->b_service_responding); - noti->b_service_responding = NULL; - } + case NOTIFICATION_EXECUTE_TYPE_RESPONDING: + /* Remove previous data if exist */ + if (noti->b_service_responding != NULL) { + bundle_free(noti->b_service_responding); + noti->b_service_responding = NULL; + } - /* Save service handle */ - if (service_handle != NULL) { - noti->b_service_responding = bundle_dup(service_handle); - } - break; - case NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH: - /* Remove previous data if exist */ - if (noti->b_service_single_launch != NULL) { - bundle_free(noti->b_service_single_launch); - noti->b_service_single_launch = NULL; - } + /* Save service handle */ + if (service_handle != NULL) { + noti->b_service_responding = bundle_dup(service_handle); + } + break; + case NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH: + /* Remove previous data if exist */ + if (noti->b_service_single_launch != NULL) { + bundle_free(noti->b_service_single_launch); + noti->b_service_single_launch = NULL; + } - /* Save service handle */ - if (service_handle != NULL) { - noti->b_service_single_launch = - bundle_dup(service_handle); - } - break; - case NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH: - /* Remove previous data if exist */ - if (noti->b_service_multi_launch != NULL) { - bundle_free(noti->b_service_multi_launch); - noti->b_service_multi_launch = NULL; - } + /* Save service handle */ + if (service_handle != NULL) { + noti->b_service_single_launch = + bundle_dup(service_handle); + } + break; + case NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH: + /* Remove previous data if exist */ + if (noti->b_service_multi_launch != NULL) { + bundle_free(noti->b_service_multi_launch); + noti->b_service_multi_launch = NULL; + } - /* Save service handle */ - if (service_handle != NULL) { - noti->b_service_multi_launch = - bundle_dup(service_handle); - } - break; + /* Save service handle */ + if (service_handle != NULL) { + noti->b_service_multi_launch = + bundle_dup(service_handle); + } + break; + case NOTIFICATION_EXECUTE_TYPE_NONE: + case NOTIFICATION_EXECUTE_TYPE_MAX: + NOTIFICATION_ERR("invalid execution type"); + break; } return NOTIFICATION_ERROR_NONE; @@ -1892,75 +1764,6 @@ EXPORT_API notification_error_e notification_get_layout(notification_h noti, return NOTIFICATION_ERROR_NONE; } -EXPORT_API notification_error_e notification_set_badge(const char *pkgname, - int group_id, int count) -{ - char *caller_pkgname = NULL; - int ret = NOTIFICATION_ERROR_NONE; - - /* Check count is valid count */ - if (count < 0) { - return NOTIFICATION_ERROR_INVALID_DATA; - } - - /* Check pkgname */ - if (pkgname == NULL) { - caller_pkgname = _notification_get_pkgname_by_pid(); - - /* Set count into Group DB */ - ret = - notification_group_set_badge(caller_pkgname, group_id, - count); - - if (caller_pkgname != NULL) { - free(caller_pkgname); - } - } else { - /* Set count into Group DB */ - ret = notification_group_set_badge(pkgname, group_id, count); - } - - return ret; -} - -EXPORT_API notification_error_e notification_get_badge(const char *pkgname, - int group_id, int *count) -{ - char *caller_pkgname = NULL; - int ret = NOTIFICATION_ERROR_NONE; - int ret_unread_count = 0; - - /* Check pkgname */ - if (pkgname == NULL) { - caller_pkgname = _notification_get_pkgname_by_pid(); - - /* Get count from Group DB */ - ret = - notification_group_get_badge(caller_pkgname, group_id, - &ret_unread_count); - - if (caller_pkgname != NULL) { - free(caller_pkgname); - } - } else { - /* Get count from Group DB */ - ret = - notification_group_get_badge(pkgname, group_id, - &ret_unread_count); - } - - if (ret != NOTIFICATION_ERROR_NONE) { - return ret; - } - - /* Set count */ - if (count != NULL) { - *count = ret_unread_count; - } - - return NOTIFICATION_ERROR_NONE; -} - EXPORT_API notification_error_e notification_get_id(notification_h noti, int *group_id, int *priv_id) { @@ -2057,6 +1860,23 @@ EXPORT_API notification_error_e notification_update(notification_h noti) return NOTIFICATION_ERROR_NONE; } +EXPORT_API notification_error_e notification_update_async(notification_h noti, + void (*result_cb)(int priv_id, int result, void *data), void *user_data) +{ + int ret = 0; + + /* Check noti is valid data */ + if (noti != NULL) { + /* Update insert time ? */ + noti->insert_time = time(NULL); + ret = notification_ipc_request_update_async(noti, result_cb, user_data); + if (ret != NOTIFICATION_ERROR_NONE) { + return ret; + } + } + return NOTIFICATION_ERROR_NONE; +} + EXPORT_API notification_error_e notifiation_clear(notification_type_e type) { int ret = 0; @@ -2083,6 +1903,9 @@ EXPORT_API notification_error_e notification_delete_all_by_type(const char *pkgn ret = notification_ipc_request_delete_multiple(type, caller_pkgname); if (ret != NOTIFICATION_ERROR_NONE) { + if (caller_pkgname) { + free(caller_pkgname); + } return ret; } @@ -2107,6 +1930,9 @@ EXPORT_API notification_error_e notification_delete_group_by_group_id(const char ret = notification_ipc_request_delete_multiple(type, caller_pkgname); if (ret != NOTIFICATION_ERROR_NONE) { + if (caller_pkgname) { + free(caller_pkgname); + } return ret; } @@ -2131,6 +1957,9 @@ EXPORT_API notification_error_e notification_delete_group_by_priv_id(const char ret = notification_ipc_request_delete_single(type, caller_pkgname, priv_id); if (ret != NOTIFICATION_ERROR_NONE) { + if (caller_pkgname) { + free(caller_pkgname); + } return ret; } @@ -2159,6 +1988,9 @@ EXPORT_API notification_error_e notification_delete_by_priv_id(const char *pkgna ret = notification_ipc_request_delete_single(type, caller_pkgname, priv_id); if (ret != NOTIFICATION_ERROR_NONE) { + if (caller_pkgname) { + free(caller_pkgname); + } return ret; } @@ -2352,12 +2184,11 @@ EXPORT_API notification_h notification_load(char *pkgname, int ret = 0; notification_h noti = NULL; - noti = (notification_h) malloc(sizeof(struct _notification)); + noti = (notification_h) calloc(1, sizeof(struct _notification)); if (noti == NULL) { NOTIFICATION_ERR("NO MEMORY : noti == NULL"); return NULL; } - memset(noti, 0x00, sizeof(struct _notification)); ret = notification_noti_get_by_priv_id(noti, pkgname, priv_id); if (ret != NOTIFICATION_ERROR_NONE) { @@ -2377,12 +2208,11 @@ EXPORT_API notification_error_e notification_clone(notification_h noti, notifica return NOTIFICATION_ERROR_INVALID_DATA; } - new_noti = (notification_h) malloc(sizeof(struct _notification)); + new_noti = (notification_h) calloc(1, sizeof(struct _notification)); if (new_noti == NULL) { NOTIFICATION_ERR("NO MEMORY : noti == NULL"); return NOTIFICATION_ERROR_NO_MEMORY; } - memset(new_noti, 0x00, sizeof(struct _notification)); new_noti->type = noti->type; new_noti->layout = noti->layout; @@ -2760,24 +2590,6 @@ notification_unregister_detailed_changed_cb( return NOTIFICATION_ERROR_INVALID_DATA; } -EXPORT_API notification_error_e -notification_resister_badge_changed_cb(void (*changed_cb) - (void *data, const char *pkgname, - int group_id), void *user_data) -{ - // Add DBus signal handler - return NOTIFICATION_ERROR_NONE; -} - -EXPORT_API notification_error_e -notification_unresister_badge_changed_cb(void (*changed_cb) - (void *data, const char *pkgname, - int group_id)) -{ - // Del DBus signal handler - return NOTIFICATION_ERROR_NONE; -} - EXPORT_API notification_error_e notification_get_count(notification_type_e type, const char *pkgname, int group_id, diff --git a/src/notification_db.c b/src/notification_db.c index 6cfa2d6..0bc01e7 100755 --- a/src/notification_db.c +++ b/src/notification_db.c @@ -31,8 +31,6 @@ #include <notification_debug.h> #include <notification_db.h> -#define SDFTET "/opt/dbspace/.notification_noti.db" - sqlite3 *notification_db_open(const char *dbfile) { int ret = 0; @@ -66,7 +64,7 @@ int notification_db_close(sqlite3 ** db) return NOTIFICATION_ERROR_NONE; } -int notification_db_exec(sqlite3 * db, const char *query) +int notification_db_exec(sqlite3 * db, const char *query, int *num_changes) { int ret = 0; char *err_msg = NULL; @@ -81,6 +79,9 @@ int notification_db_exec(sqlite3 * db, const char *query) sqlite3_free(err_msg); return NOTIFICATION_ERROR_FROM_DB; } + if (num_changes != NULL) { + *num_changes = sqlite3_changes(db); + } return NOTIFICATION_ERROR_NONE; } diff --git a/src/notification_ipc.c b/src/notification_ipc.c index 9ac5e3f..1ea374a 100755 --- a/src/notification_ipc.c +++ b/src/notification_ipc.c @@ -36,10 +36,12 @@ #include <notification_internal.h> #include <notification_debug.h> -#define NOTIFICATION_IPC_TIMEOUT 1.0 +#define NOTIFICATION_IPC_TIMEOUT 0.0 static struct info { int server_fd; + int server_cl_fd; + int server_cl_fd_ref_cnt; int client_fd; const char *socket_file; struct { @@ -50,6 +52,8 @@ static struct info { int is_started_cb_set_svc; } s_info = { .server_fd = -1, + .server_cl_fd = -1, + .server_cl_fd_ref_cnt = 0, .client_fd = -1, .socket_file = NOTIFICATION_ADDR, .initialized = 0, @@ -65,6 +69,11 @@ struct _task_list { void *data; }; +typedef struct _result_cb_item { + void (*result_cb)(int priv_id, int result, void *data); + void *data; +} result_cb_item; + static task_list *g_task_list; static Eina_Bool _do_deffered_task(void *data); @@ -175,6 +184,7 @@ static Eina_Bool _do_deffered_task(void *data) { task_list *list_do = NULL; task_list *list_temp = NULL; + if (g_task_list) { list_do = g_task_list; g_task_list = NULL; @@ -776,6 +786,7 @@ notification_error_e notification_ipc_monitor_init(void) NOTIFICATION_ERR("register a service\n"); + com_core_packet_use_thread(1); s_info.server_fd = com_core_packet_client_init(s_info.socket_file, 0, service_table); if (s_info.server_fd < 0) { NOTIFICATION_ERR("Failed to make a connection to the master\n"); @@ -785,6 +796,7 @@ notification_error_e notification_ipc_monitor_init(void) packet = packet_create("service_register", ""); if (!packet) { NOTIFICATION_ERR("Failed to build a packet\n"); + com_core_packet_client_fini(s_info.server_fd); return NOTIFICATION_ERROR_IO; } @@ -943,6 +955,106 @@ notification_error_e notification_ipc_request_update(notification_h noti) return status; } +static int _notification_ipc_update_cb(pid_t pid, int handle, const struct packet *packet, void *data) +{ + int status = 0; + int id = NOTIFICATION_PRIV_ID_NONE; + result_cb_item *cb_item = (result_cb_item *)data; + + if (cb_item == NULL) { + NOTIFICATION_ERR("Failed to get a callback item"); + return NOTIFICATION_ERROR_INVALID_DATA; + } + s_info.server_cl_fd_ref_cnt = (s_info.server_cl_fd_ref_cnt <= 1) ? 0 : s_info.server_cl_fd_ref_cnt - 1; + if (s_info.server_cl_fd_ref_cnt <= 0) { + NOTIFICATION_DBG("REFCNT: %d (fd: %d)", s_info.server_cl_fd_ref_cnt, s_info.server_cl_fd); + int fd_temp = s_info.server_cl_fd; + s_info.server_cl_fd = -1; + com_core_packet_client_fini(fd_temp); + NOTIFICATION_DBG("FD(%d) finalized", fd_temp); + } + + if (packet != NULL) { + if (packet_get(packet, "ii", &status, &id) != 2) { + NOTIFICATION_ERR("Failed to get a result packet"); + status = NOTIFICATION_ERROR_IO; + } + } + + if (cb_item->result_cb != NULL) { + cb_item->result_cb(id, status, cb_item->data); + } + free(cb_item); + + return status; +} + +notification_error_e notification_ipc_request_update_async(notification_h noti, + void (*result_cb)(int priv_id, int result, void *data), void *user_data) +{ + int ret = NOTIFICATION_ERROR_NONE; + int ret_con = 0; + struct packet *packet = NULL; + result_cb_item *cb_item = NULL; + + packet = notification_ipc_make_packet_from_noti(noti, "update_noti", 1); + if (packet == NULL) { + ret = NOTIFICATION_ERROR_INVALID_DATA; + goto fail; + } + + cb_item = calloc(1, sizeof(result_cb_item)); + if (cb_item == NULL) { + ret = NOTIFICATION_ERROR_NO_MEMORY; + goto fail; + } + + if (s_info.server_cl_fd < 0) { + com_core_packet_use_thread(1); + s_info.server_cl_fd = com_core_packet_client_init(s_info.socket_file, 0, NULL); + if (s_info.server_cl_fd < 0) { + NOTIFICATION_DBG("Failed to init client: %d", s_info.server_cl_fd); + ret = NOTIFICATION_ERROR_SERVICE_NOT_READY; + goto fail; + } + s_info.server_cl_fd_ref_cnt = 1; + } else { + s_info.server_cl_fd_ref_cnt++; + } + + cb_item->result_cb = result_cb; + cb_item->data = user_data; + + NOTIFICATION_INFO("Connection count:%d, fd:%d", s_info.server_cl_fd_ref_cnt, s_info.server_cl_fd); + + ret_con = com_core_packet_async_send(s_info.server_cl_fd, packet, 0.0f, + _notification_ipc_update_cb, cb_item); + if (ret_con < 0) { + NOTIFICATION_ERR("Failed to request update, %d\n", ret_con); + s_info.server_cl_fd_ref_cnt = (s_info.server_cl_fd_ref_cnt <= 1) ? 0 : s_info.server_cl_fd_ref_cnt - 1; + if (s_info.server_cl_fd_ref_cnt <= 0) { + int fd_temp = s_info.server_cl_fd; + s_info.server_cl_fd = -1; + com_core_packet_client_fini(fd_temp); + NOTIFICATION_INFO("FD(%d) finalized", fd_temp); + } + ret = NOTIFICATION_ERROR_IO; + goto fail; + } else { + ret = NOTIFICATION_ERROR_NONE; + goto success; + } + +fail: + if (cb_item) free(cb_item); + NOTIFICATION_ERR("Err: %d\n", ret); + +success: + if (packet) packet_destroy(packet); + + return ret; +} + notification_error_e notification_ipc_request_refresh(void) { int status = 0; @@ -968,3 +1080,60 @@ notification_error_e notification_ipc_request_refresh(void) return status; } + +notification_error_e notification_ipc_noti_setting_property_set(const char *pkgname, const char *property, const char *value) +{ + int status = 0; + int ret = 0; + struct packet *packet; + struct packet *result; + + packet = packet_create("set_noti_property", "sss", pkgname, property, value); + result = com_core_packet_oneshot_send(NOTIFICATION_ADDR, + packet, + NOTIFICATION_IPC_TIMEOUT); + packet_destroy(packet); + + if (result != NULL) { + if (packet_get(result, "ii", &status, &ret) != 2) { + NOTIFICATION_ERR("Failed to get a result packet"); + packet_unref(result); + return NOTIFICATION_ERROR_IO; + } + packet_unref(result); + } else { + return NOTIFICATION_ERROR_SERVICE_NOT_READY; + } + + return status; +} + +notification_error_e notification_ipc_noti_setting_property_get(const char *pkgname, const char *property, char **value) +{ + int status = 0; + char *ret = NULL; + struct packet *packet; + struct packet *result; + + packet = packet_create("get_noti_property", "ss", pkgname, property); + result = com_core_packet_oneshot_send(NOTIFICATION_ADDR, + packet, + NOTIFICATION_IPC_TIMEOUT); + packet_destroy(packet); + + if (result != NULL) { + if (packet_get(result, "is", &status, &ret) != 2) { + NOTIFICATION_ERR("Failed to get a result packet"); + packet_unref(result); + return NOTIFICATION_ERROR_IO; + } + if (status == NOTIFICATION_ERROR_NONE && ret != NULL) { + *value = strdup(ret); + } + packet_unref(result); + } else { + return NOTIFICATION_ERROR_SERVICE_NOT_READY; + } + + return status; +} diff --git a/src/notification_noti.c b/src/notification_noti.c index 996465e..0c447fb 100755 --- a/src/notification_noti.c +++ b/src/notification_noti.c @@ -31,6 +31,17 @@ #include <notification_debug.h> #include <notification_internal.h> +#define NOTI_BURST_DELETE_UNIT 10 + +static void __free_and_set(void **target_ptr, void *new_ptr) { + if (target_ptr != NULL) { + if (*target_ptr != NULL) { + free(*target_ptr); + } + *target_ptr = new_ptr; + } +} + static int _notification_noti_bind_query_text(sqlite3_stmt * stmt, const char *name, const char *str) { @@ -111,43 +122,6 @@ static int _notification_noti_check_priv_id(notification_h noti, sqlite3 * db) return NOTIFICATION_ERROR_NONE; } -static int _notification_noti_get_priv_id(notification_h noti, sqlite3 * db) -{ - sqlite3_stmt *stmt = NULL; - char query[NOTIFICATION_QUERY_MAX] = { 0, }; - int ret = NOTIFICATION_ERROR_NONE, result = 0; - - /* Make query to get max priv_id */ - snprintf(query, sizeof(query), - "select max(priv_id) from noti_list where caller_pkgname = '%s'", - noti->caller_pkgname); - - ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL); - if (ret != SQLITE_OK) { - NOTIFICATION_ERR("Get count DB err(%d) : %s", ret, - sqlite3_errmsg(db)); - return NOTIFICATION_ERROR_FROM_DB; - } - - ret = sqlite3_step(stmt); - if (ret == SQLITE_ROW) { - result = sqlite3_column_int(stmt, 0); - } else { - result = 0; - } - - sqlite3_finalize(stmt); - - if (result < 0) { - return NOTIFICATION_ERROR_FROM_DB; - } - - /* Increase result(max priv_id value) for next priv_id */ - noti->priv_id = result + 1; - - return NOTIFICATION_ERROR_NONE; -} - static int _notification_noti_get_internal_group_id_by_priv_id(const char *pkgname, int priv_id, sqlite3 * db) @@ -179,129 +153,6 @@ static int _notification_noti_get_internal_group_id_by_priv_id(const char *pkgna return result; } -static int _notification_noti_get_max_internal_group_id(notification_h noti, - sqlite3 * db) -{ - sqlite3_stmt *stmt = NULL; - char query[NOTIFICATION_QUERY_MAX] = { 0, }; - int ret = NOTIFICATION_ERROR_NONE, result = 0; - - /* Get max internal group id */ - snprintf(query, sizeof(query), - "select max(internal_group_id) from noti_list"); - - ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL); - if (ret != SQLITE_OK) { - NOTIFICATION_ERR("Get count DB err(%d) : %s", ret, - sqlite3_errmsg(db)); - return NOTIFICATION_ERROR_FROM_DB; - } - - ret = sqlite3_step(stmt); - if (ret == SQLITE_ROW) { - result = sqlite3_column_int(stmt, 0); - } else { - result = 0; - } - - sqlite3_finalize(stmt); - - return result; -} - -static int _notification_noti_get_internal_group_id(notification_h noti, - sqlite3 * db) -{ - sqlite3_stmt *stmt = NULL; - char query[NOTIFICATION_QUERY_MAX] = { 0, }; - int ret = NOTIFICATION_ERROR_NONE, result = 0; - const char *ret_title = NULL; - char buf_key[32] = { 0, }; - - if (noti->group_id == NOTIFICATION_GROUP_ID_NONE) { - /* If Group ID is NONE Get max internal group ID */ - result = _notification_noti_get_max_internal_group_id(noti, db); - if (result < 0) { - return NOTIFICATION_ERROR_FROM_DB; - } - - /* Internal Group ID is max internal group ID + 1 */ - noti->internal_group_id = result + 1; - - return NOTIFICATION_ERROR_NONE; - } else if (noti->group_id == NOTIFICATION_GROUP_ID_DEFAULT) { - /* If Group ID is DEFAULT, Get internal group id if it exist */ - if (noti->b_key != NULL) { - snprintf(buf_key, sizeof(buf_key), "%d", - NOTIFICATION_TEXT_TYPE_TITLE); - - ret_title = bundle_get_val(noti->b_key, buf_key); - } - - if (ret_title == NULL && noti->b_text != NULL) { - snprintf(buf_key, sizeof(buf_key), "%d", - NOTIFICATION_TEXT_TYPE_TITLE); - - ret_title = bundle_get_val(noti->b_text, buf_key); - } - - if (ret_title == NULL) { - ret_title = noti->caller_pkgname; - } - - snprintf(query, sizeof(query), - "select internal_group_id from noti_list where title_key = $title_key and group_id = %d", - NOTIFICATION_GROUP_ID_DEFAULT); - } else { - /* If Group ID is > DEFAULT, Get internal group id if it exit */ - snprintf(query, sizeof(query), - "select internal_group_id from noti_list where caller_pkgname = '%s' and group_id = %d", - NOTIFICATION_CHECK_STR(noti->caller_pkgname), - noti->group_id); - } - - ret = sqlite3_prepare_v2(db, query, -1, &stmt, NULL); - if (ret != SQLITE_OK) { - NOTIFICATION_ERR("Select Query : %s", query); - NOTIFICATION_ERR("Select DB error(%d) : %s", ret, - sqlite3_errmsg(db)); - if (stmt) { - sqlite3_finalize(stmt); - } - return NOTIFICATION_ERROR_FROM_DB; - } - - /* Bind query */ - if (ret_title != NULL) { - ret = - _notification_noti_bind_query_text(stmt, "$title_key", - NOTIFICATION_CHECK_STR - (ret_title)); - if (ret != NOTIFICATION_ERROR_NONE) { - NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db)); - if (stmt) { - sqlite3_finalize(stmt); - } - return ret; - } - } - - ret = sqlite3_step(stmt); - if (ret == SQLITE_ROW) { - result = sqlite3_column_int(stmt, 0); - } else { - /* If there is not internal_group_id, create new one */ - result = _notification_noti_get_max_internal_group_id(noti, db); - result++; - } - - sqlite3_finalize(stmt); - - noti->internal_group_id = result; - - return NOTIFICATION_ERROR_NONE; -} - static int _notification_noti_make_query(notification_h noti, char *query, int query_size) { @@ -616,8 +467,8 @@ static void _notification_noti_populate_from_stmt(sqlite3_stmt * stmt, notificat noti->type = sqlite3_column_int(stmt, col++); noti->layout = sqlite3_column_int(stmt, col++); - noti->caller_pkgname = notification_db_column_text(stmt, col++); - noti->launch_pkgname = notification_db_column_text(stmt, col++); + __free_and_set((void **)&(noti->caller_pkgname), notification_db_column_text(stmt, col++)); + __free_and_set((void **)&(noti->launch_pkgname), notification_db_column_text(stmt, col++)); noti->b_image_path = notification_db_column_bundle(stmt, col++); noti->group_id = sqlite3_column_int(stmt, col++); noti->internal_group_id = 0; @@ -628,8 +479,8 @@ static void _notification_noti_populate_from_stmt(sqlite3_stmt * stmt, notificat noti->b_format_args = notification_db_column_bundle(stmt, col++); noti->num_format_args = sqlite3_column_int(stmt, col++); - noti->domain = notification_db_column_text(stmt, col++); - noti->dir = notification_db_column_text(stmt, col++); + __free_and_set((void **)&(noti->domain), notification_db_column_text(stmt, col++)); + __free_and_set((void **)&(noti->dir), notification_db_column_text(stmt, col++)); noti->time = sqlite3_column_int(stmt, col++); noti->insert_time = sqlite3_column_int(stmt, col++); noti->args = notification_db_column_bundle(stmt, col++); @@ -643,9 +494,9 @@ static void _notification_noti_populate_from_stmt(sqlite3_stmt * stmt, notificat notification_db_column_bundle(stmt, col++); noti->sound_type = sqlite3_column_int(stmt, col++); - noti->sound_path = notification_db_column_text(stmt, col++); + __free_and_set((void **)&(noti->sound_path), notification_db_column_text(stmt, col++)); noti->vibration_type = sqlite3_column_int(stmt, col++); - noti->vibration_path = notification_db_column_text(stmt, col++); + __free_and_set((void **)&(noti->vibration_path), notification_db_column_text(stmt, col++)); noti->led_operation = sqlite3_column_int(stmt, col++); noti->led_argb = sqlite3_column_int(stmt, col++); noti->led_on_ms = sqlite3_column_int(stmt, col++); @@ -666,7 +517,7 @@ static notification_h _notification_noti_get_item(sqlite3_stmt * stmt) { notification_h noti = NULL; - noti = malloc(sizeof(struct _notification)); + noti = (notification_h) calloc(1, sizeof(struct _notification)); if (noti == NULL) { return NULL; } @@ -745,7 +596,7 @@ static int _notification_noti_update_priv_id(sqlite3 * db, int rowid) "priv_id = %d, internal_group_id = %d where rowid = %d", rowid, rowid, rowid); - return notification_db_exec(db, query); + return notification_db_exec(db, query, NULL); } EXPORT_API int notification_noti_insert(notification_h noti) @@ -980,6 +831,7 @@ err: EXPORT_API int notification_noti_delete_all(notification_type_e type, const char *pkgname, int *num_deleted, int **list_deleted_rowid) { int ret = NOTIFICATION_ERROR_NONE; + int ret_tmp = NOTIFICATION_ERROR_NONE; int i = 0, data_cnt = 0; sqlite3 *db = NULL; sqlite3_stmt *stmt = NULL; @@ -1058,15 +910,26 @@ EXPORT_API int notification_noti_delete_all(notification_type_e type, const char if (data_cnt > 0) { query_where[0] = '\0'; + snprintf(query_base, sizeof(query_base) - 1, "delete from noti_list"); for (i = 0; i < data_cnt ; i++) { - snprintf(buf, sizeof(buf), "%s%d", (i == 0) ? "" : ",", *((*list_deleted_rowid) + i)); + if (i % NOTI_BURST_DELETE_UNIT == 0 && i != 0) { + snprintf(query, sizeof(query) - 1, "%s where priv_id in (%s)", query_base, query_where); + ret_tmp = notification_db_exec(db, query, NULL); + query_where[0] = '\0'; + if (ret == NOTIFICATION_ERROR_NONE) { + ret = ret_tmp; + } + } + snprintf(buf, sizeof(buf) - 1, "%s%d", (i % NOTI_BURST_DELETE_UNIT == 0) ? "" : ",", *((*list_deleted_rowid) + i)); strncat(query_where, buf,sizeof(query_where) - strlen(query_where) - 1); } - snprintf(query_base, sizeof(query_base), "delete from noti_list"); - snprintf(query, sizeof(query), "%s where priv_id in (%s)", query_base, query_where); - - NOTIFICATION_ERR("check : %s", query); - ret = notification_db_exec(db, query); + if ((i <= NOTI_BURST_DELETE_UNIT) || ((i % NOTI_BURST_DELETE_UNIT) > 0) ) { + snprintf(query, sizeof(query) - 1, "%s where priv_id in (%s)", query_base, query_where); + ret_tmp = notification_db_exec(db, query, NULL); + if (ret == NOTIFICATION_ERROR_NONE) { + ret = ret_tmp; + } + } } else { free(*list_deleted_rowid); *list_deleted_rowid = NULL; @@ -1080,7 +943,7 @@ EXPORT_API int notification_noti_delete_all(notification_type_e type, const char snprintf(query_base, sizeof(query_base), "delete from noti_list "); snprintf(query, sizeof(query), "%s %s", query_base, query_where); - ret = notification_db_exec(db, query); + ret = notification_db_exec(db, query, NULL); if (num_deleted != NULL) { *num_deleted = sqlite3_changes(db); @@ -1103,6 +966,7 @@ int notification_noti_delete_group_by_group_id(const char *pkgname, int group_id, int *num_deleted, int **list_deleted_rowid) { int ret = NOTIFICATION_ERROR_NONE; + int ret_tmp = NOTIFICATION_ERROR_NONE; sqlite3 *db = NULL; int i = 0, data_cnt = 0; sqlite3_stmt *stmt = NULL; @@ -1167,15 +1031,26 @@ int notification_noti_delete_group_by_group_id(const char *pkgname, if (data_cnt > 0) { query_where[0] = '\0'; + snprintf(query_base, sizeof(query_base) - 1, "delete from noti_list"); for (i = 0; i < data_cnt ; i++) { - snprintf(buf, sizeof(buf), "%s%d", (i == 0) ? "" : ",", *((*list_deleted_rowid) + i)); + if (i % NOTI_BURST_DELETE_UNIT == 0 && i != 0) { + snprintf(query, sizeof(query) - 1, "%s where priv_id in (%s)", query_base, query_where); + ret_tmp = notification_db_exec(db, query, NULL); + query_where[0] = '\0'; + if (ret == NOTIFICATION_ERROR_NONE) { + ret = ret_tmp; + } + } + snprintf(buf, sizeof(buf) - 1, "%s%d", (i % NOTI_BURST_DELETE_UNIT == 0) ? "" : ",", *((*list_deleted_rowid) + i)); strncat(query_where, buf,sizeof(query_where) - strlen(query_where) - 1); } - snprintf(query_base, sizeof(query_base), "delete from noti_list"); - snprintf(query, sizeof(query), "%s where priv_id in (%s)", query_base, query_where); - - NOTIFICATION_ERR("check : %s", query); - ret = notification_db_exec(db, query); + if ((i <= NOTI_BURST_DELETE_UNIT) || ((i % NOTI_BURST_DELETE_UNIT) > 0) ) { + snprintf(query, sizeof(query) - 1, "%s where priv_id in (%s)", query_base, query_where); + ret_tmp = notification_db_exec(db, query, NULL); + if (ret == NOTIFICATION_ERROR_NONE) { + ret = ret_tmp; + } + } } else { free(*list_deleted_rowid); *list_deleted_rowid = NULL; @@ -1189,7 +1064,7 @@ int notification_noti_delete_group_by_group_id(const char *pkgname, snprintf(query, sizeof(query), "delete from noti_list %s", query_where); /* execute DB */ - ret = notification_db_exec(db, query); + ret = notification_db_exec(db, query, NULL); } err: @@ -1233,7 +1108,7 @@ int notification_noti_delete_group_by_priv_id(const char *pkgname, int priv_id) pkgname, internal_group_id); /* execute DB */ - ret = notification_db_exec(db, query); + ret = notification_db_exec(db, query, NULL); /* Close DB */ notification_db_close(&db); @@ -1264,7 +1139,44 @@ EXPORT_API int notification_noti_delete_by_priv_id(const char *pkgname, int priv priv_id); /* execute DB */ - ret = notification_db_exec(db, query); + ret = notification_db_exec(db, query, NULL); + + /* Close DB */ + if (db) { + notification_db_close(&db); + } + + return ret; +} + +EXPORT_API int notification_noti_delete_by_priv_id_get_changes(const char *pkgname, int priv_id, int *num_changes) +{ + sqlite3 *db = NULL; + char query[NOTIFICATION_QUERY_MAX] = { 0, }; + int ret; + + /* Check pkgname is valid */ + if (pkgname == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + /* Open DB */ + db = notification_db_open(DBPATH); + if (!db) { + return NOTIFICATION_ERROR_FROM_DB; + } + + /* Make query */ + snprintf(query, sizeof(query), "delete from noti_list " + "where caller_pkgname = '%s' and priv_id = %d", pkgname, + priv_id); + + /* execute DB */ + ret = notification_db_exec(db, query, num_changes); + + if (num_changes != NULL) { + NOTIFICATION_DBG("deleted num:%d", *num_changes); + } /* Close DB */ if (db) { @@ -1550,12 +1462,10 @@ notification_error_e notification_noti_get_detail_list(const char *pkgname, if (priv_id == NOTIFICATION_PRIV_ID_NONE && group_id == NOTIFICATION_GROUP_ID_NONE) { if (status == VCONFKEY_TELEPHONY_SIM_INSERTED) { snprintf(query_where, sizeof(query_where), - "where caller_pkgname = '%s' ", - pkgname, internal_group_id); + "where caller_pkgname = '%s' ", pkgname); } else { snprintf(query_where, sizeof(query_where), - "where caller_pkgname = '%s' and flag_simmode = 0 ", - pkgname, internal_group_id); + "where caller_pkgname = '%s' and flag_simmode = 0 ", pkgname); } } else { internal_group_id = diff --git a/src/notification_ongoing.c b/src/notification_ongoing.c index f248bc1..eea1860 100755 --- a/src/notification_ongoing.c +++ b/src/notification_ongoing.c @@ -70,8 +70,6 @@ notification_error_e notification_ongoing_update_progress(const char *caller_pkg dbus_message_unref(signal); if (ret) { - NOTIFICATION_INFO("Send progress info : %s(%d) %.2f", - caller_pkgname, priv_id, progress); return NOTIFICATION_ERROR_NONE; } @@ -106,11 +104,8 @@ notification_error_e notification_ongoing_update_size(const char *caller_pkgname DBUS_TYPE_INT32, &priv_id, DBUS_TYPE_DOUBLE, &size, DBUS_TYPE_INVALID); - NOTIFICATION_INFO("arg..."); if (ret) { ret = dbus_connection_send(connection, signal, NULL); - NOTIFICATION_INFO("Send size info : %s(%d) %.2f", - caller_pkgname, priv_id, size); if (ret) { dbus_connection_flush(connection); @@ -120,8 +115,6 @@ notification_error_e notification_ongoing_update_size(const char *caller_pkgname dbus_message_unref(signal); if (ret) { - NOTIFICATION_INFO("Send size info : %s(%d) %.2f", - caller_pkgname, priv_id, size); return NOTIFICATION_ERROR_NONE; } @@ -165,8 +158,6 @@ notification_error_e notification_ongoing_update_content(const char *caller_pkgn } if (ret) { ret = dbus_connection_send(connection, signal, NULL); - NOTIFICATION_INFO("Send content : %s(%d) %s", - caller_pkgname, priv_id, content); if (ret) { dbus_connection_flush(connection); diff --git a/src/notification_setting.c b/src/notification_setting.c new file mode 100755 index 0000000..246f964 --- /dev/null +++ b/src/notification_setting.c @@ -0,0 +1,351 @@ +/* + * libnotification + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Seungtaek Chung <seungtaek.chung@samsung.com>, Mi-Ju Lee <miju52.lee@samsung.com>, Xi Zhichan <zhichan.xi@samsung.com> + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <db-util.h> + +#include <notification.h> +#include <notification_db.h> +#include <notification_noti.h> +#include <notification_debug.h> +#include <notification_ipc.h> +#include <notification_setting.h> +#include <notification_internal.h> + +#define NOTIFICATION_SETTING_DB "notification_setting" +#define NOTIFICATION_SETTING_DB_PATH "/opt/usr/dbspace/.notification_parser.db" + +struct _notification_setting_h { + char *appid; + char *notification; + char *sounds; + char *contents; + char *badge; + char *pkgid; +}; + +struct prop_table { + const char *property; + const char *column; + const char *default_value; +}; + +static struct prop_table g_prop_table[] = { + { + .property = "OPT_NOTIFICATION", + .column = "notification", + .default_value = "ON", + }, + { + .property = "OPT_SOUNDS", + .column = "sounds", + .default_value = "ON", + }, + { + .property = "OPT_CONTENTS", + .column = "contents", + .default_value = "ON", + }, + { + .property = "OPT_BADGE", + .column = "badge", + .default_value = "ON", + }, + { + .property = NULL, + .column = NULL, + .default_value = NULL, + } +}; + +static const char *_get_prop_column(const char *property) +{ + int i; + + for (i = 0; g_prop_table[i].property; i++) { + if (strcmp(g_prop_table[i].property, property)) + continue; + + return g_prop_table[i].column; + } + + return NULL; +} + +#ifdef TBD +static const char *_get_prop_default_value(const char *property) +{ + int i; + + for (i = 0; g_prop_table[i].property; i++) { + if (strcmp(g_prop_table[i].property, property)) + continue; + + return g_prop_table[i].default_value; + } + + return NULL; +} +#endif + +static notification_error_e _is_record_exist(const char *pkgname, sqlite3 *db) +{ + sqlite3_stmt *stmt = NULL; + int count = 0; + int result = NOTIFICATION_ERROR_NONE; + char *sqlbuf = NULL; + int sqlret; + + if (!pkgname) + return NOTIFICATION_ERROR_INVALID_DATA; + + if (!db) + return NOTIFICATION_ERROR_INVALID_DATA; + + sqlbuf = sqlite3_mprintf("SELECT count(*) FROM %s WHERE " \ + "appid = %Q", + NOTIFICATION_SETTING_DB, pkgname); + + if (!sqlbuf) { + NOTIFICATION_ERR("fail to alloc sql query"); + return NOTIFICATION_ERROR_NO_MEMORY; + } + + sqlret = sqlite3_prepare_v2(db, sqlbuf, -1, &stmt, NULL); + if (sqlret != SQLITE_OK) { + NOTIFICATION_ERR("DB err [%s]", sqlite3_errmsg(db)); + NOTIFICATION_ERR("query[%s]", sqlbuf); + result = NOTIFICATION_ERROR_FROM_DB; + goto free_and_return; + } + + sqlret = sqlite3_step(stmt); + if (sqlret == SQLITE_ROW) + count = sqlite3_column_int(stmt, 0); + else + count = 0; + + if (count > 0) + result = NOTIFICATION_ERROR_ALREADY_EXIST_ID; + else + result = NOTIFICATION_ERROR_NOT_EXIST_ID; + +free_and_return: + if (sqlbuf) + sqlite3_free(sqlbuf); + + if (stmt) + sqlite3_finalize(stmt); + + return result; +} + +EXPORT_API notification_error_e notification_setting_db_set(const char *pkgname, const char *property, const char *value) +{ + notification_error_e ret = NOTIFICATION_ERROR_NONE; + notification_error_e result = NOTIFICATION_ERROR_NONE; + sqlite3 *db = NULL; + char *sqlbuf = NULL; + int sqlret; + char *err_msg = NULL; + const char *column = NULL; + + if (!pkgname) + return NOTIFICATION_ERROR_INVALID_DATA; + + if (!property) + return NOTIFICATION_ERROR_INVALID_DATA; + + if (!value) + return NOTIFICATION_ERROR_INVALID_DATA; + + column = _get_prop_column(property); + if (!column) + return NOTIFICATION_ERROR_INVALID_DATA; + + sqlret = db_util_open(NOTIFICATION_SETTING_DB_PATH, &db, 0); + if (sqlret != SQLITE_OK || !db) { + NOTIFICATION_ERR("fail to db_util_open - [%d]", sqlret); + return NOTIFICATION_ERROR_FROM_DB; + } + + ret = _is_record_exist(pkgname, db); + if (ret != NOTIFICATION_ERROR_ALREADY_EXIST_ID) { + result = ret; + goto return_close_db; + } + + sqlbuf = sqlite3_mprintf("UPDATE %s SET %s = %Q " \ + "WHERE appid = %Q", + NOTIFICATION_SETTING_DB, column, value, pkgname); + if (!sqlbuf) { + NOTIFICATION_ERR("fail to alloc query"); + result = NOTIFICATION_ERROR_NO_MEMORY; + goto return_close_db; + } + + sqlret = sqlite3_exec(db, sqlbuf, NULL, NULL, &err_msg); + if (sqlret != SQLITE_OK) { + NOTIFICATION_ERR("fail to set pkgname[%s] option[%s], value[%s], err[%d - %s]", + pkgname, value, property, sqlret, err_msg); + result = NOTIFICATION_ERROR_FROM_DB; + goto return_close_db; + } + +return_close_db: + if (err_msg) + sqlite3_free(err_msg); + + if (sqlbuf) + sqlite3_free(sqlbuf); + + sqlret = db_util_close(db); + if (sqlret != SQLITE_OK) + NOTIFICATION_WARN("fail to db_util_close - [%d]", sqlret); + + return result; +} + +EXPORT_API notification_error_e notification_setting_db_get(const char *pkgname, const char *property, char **value) +{ + notification_error_e ret = NOTIFICATION_ERROR_NONE; + notification_error_e result = NOTIFICATION_ERROR_NONE; + sqlite3 *db = NULL; + char *sqlbuf = NULL; + sqlite3_stmt *stmt = NULL; + int sqlret; + const char *column = NULL; + + if (!pkgname) + return NOTIFICATION_ERROR_INVALID_DATA; + + if (!property) + return NOTIFICATION_ERROR_INVALID_DATA; + + if (!value) + return NOTIFICATION_ERROR_INVALID_DATA; + + column = _get_prop_column(property); + if (!column) + return NOTIFICATION_ERROR_INVALID_DATA; + + sqlret = db_util_open(NOTIFICATION_SETTING_DB_PATH, &db, 0); + if (sqlret != SQLITE_OK || !db) { + NOTIFICATION_ERR("fail to db_util_open - [%d]", sqlret); + return NOTIFICATION_ERROR_FROM_DB; + } + + ret = _is_record_exist(pkgname, db); + if (ret != NOTIFICATION_ERROR_ALREADY_EXIST_ID) { + result = ret; + goto return_close_db; + } + + sqlbuf = sqlite3_mprintf("SELECT %s FROM %s " \ + "WHERE appid = %Q", + column, NOTIFICATION_SETTING_DB, pkgname); + if (!sqlbuf) { + NOTIFICATION_ERR("fail to alloc query"); + result = NOTIFICATION_ERROR_NO_MEMORY; + goto return_close_db; + } + + sqlret = sqlite3_prepare_v2(db, sqlbuf, -1, &stmt, NULL); + if (sqlret != SQLITE_OK) { + NOTIFICATION_ERR("fail to prepare %s - [%s]", + sqlbuf, sqlite3_errmsg(db)); + result = NOTIFICATION_ERROR_FROM_DB; + goto return_close_db; + } + + sqlret = sqlite3_step(stmt); + if (sqlret == SQLITE_ROW) { + int get_bytes = sqlite3_column_bytes(stmt, 0); + char *get_data = (char *)calloc(get_bytes + 1, sizeof(char)); + if (get_data != NULL) { + memcpy(get_data, sqlite3_column_text(stmt, 0), + get_bytes * sizeof(char)); + get_data[get_bytes] = '\0'; + *value = get_data; + } else { + NOTIFICATION_ERR("fail to alloc query"); + result = NOTIFICATION_ERROR_NO_MEMORY; + goto return_close_db; + } + } + +return_close_db: + if (sqlbuf) + sqlite3_free(sqlbuf); + + if (stmt) + sqlite3_finalize(stmt); + + sqlret = db_util_close(db); + if (sqlret != SQLITE_OK) + NOTIFICATION_WARN("fail to db_util_close - [%d]", sqlret); + + return result; +} + +EXPORT_API notification_error_e notification_setting_property_set(const char *pkgname, const char *property, const char *value) +{ + int ret = 0; + + if (!pkgname) + return NOTIFICATION_ERROR_INVALID_DATA; + + if (!property) + return NOTIFICATION_ERROR_INVALID_DATA; + + if (!value) + return NOTIFICATION_ERROR_INVALID_DATA; + + ret = notification_ipc_noti_setting_property_set(pkgname, property, value); + if (ret != NOTIFICATION_ERROR_NONE) { + return ret; + } + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e notification_setting_property_get(const char *pkgname, const char *property, char **value) +{ + int ret = 0; + + if (!pkgname) + return NOTIFICATION_ERROR_INVALID_DATA; + + if (!property) + return NOTIFICATION_ERROR_INVALID_DATA; + + if (!value) + return NOTIFICATION_ERROR_INVALID_DATA; + + ret = notification_ipc_noti_setting_property_get(pkgname, property, value); + if (ret != NOTIFICATION_ERROR_NONE) { + return ret; + } + + return NOTIFICATION_ERROR_NONE; +} diff --git a/src/notification_status.c b/src/notification_status.c index 734d30d..97fbe41 100755 --- a/src/notification_status.c +++ b/src/notification_status.c @@ -26,14 +26,12 @@ #include <errno.h> #include <vconf.h> -#include "notification_error.h" -#include "notification_type.h" -#include "notification_debug.h" -#include "notification_status.h" - -#ifndef EXPORT_API -#define EXPORT_API __attribute__ ((visibility("default"))) -#endif +#include <notification.h> +#include <notification_db.h> +#include <notification_noti.h> +#include <notification_debug.h> +#include <notification_internal.h> +#include <notification_status.h> #define NOTIFICATION_STATUS_MESSAGE_KEY "memory/private/libstatus/message" |