diff options
Diffstat (limited to 'src')
-rwxr-xr-x | src/notification.c | 3267 | ||||
-rwxr-xr-x | src/notification_db.c | 110 | ||||
-rwxr-xr-x | src/notification_group.c | 196 | ||||
-rwxr-xr-x | src/notification_list.c | 211 | ||||
-rwxr-xr-x | src/notification_noti.c | 1502 | ||||
-rwxr-xr-x | src/notification_ongoing.c | 184 | ||||
-rwxr-xr-x | src/notification_status.c | 135 |
7 files changed, 5605 insertions, 0 deletions
diff --git a/src/notification.c b/src/notification.c new file mode 100755 index 0000000..d435218 --- /dev/null +++ b/src/notification.c @@ -0,0 +1,3267 @@ +/* + * 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>, Youngsub Ko <ys4610.ko@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 <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <fcntl.h> +#include <libintl.h> +#include <dbus/dbus.h> +#include <dbus/dbus-glib-lowlevel.h> + +#include <aul.h> +#include <ail.h> +#include <appsvc.h> +#include <vconf-keys.h> +#include <vconf.h> + +#include <notification.h> +#include <notification_list.h> +#include <notification_debug.h> +#include <notification_internal.h> +#include <notification_noti.h> +#include <notification_ongoing.h> +#include <notification_group.h> + +typedef struct _notification_cb_list notification_cb_list_s; + +typedef enum __notification_cb_type { + NOTIFICATION_CB_NORMAL = 1, + NOTIFICATION_CB_DETAILED, +} _notification_cb_type_e; + +struct _notification_cb_list { + notification_cb_list_s *prev; + notification_cb_list_s *next; + + _notification_cb_type_e cb_type; + void (*changed_cb) (void *data, notification_type_e type); + void (*detailed_changed_cb) (void *data, notification_type_e type, notification_op *op_list, int num_op); + void *data; +}; + +static notification_cb_list_s *g_notification_cb_list = NULL; +static DBusConnection *g_dbus_handle; + +#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) +{ + char buf[NOTI_PKGNAME_LEN + 1] = { 0, }; + char pkgname[NOTI_PKGNAME_LEN + 1] = { 0, }; + int pid = 0, ret = AUL_R_OK; + int fd; + + pid = getpid(); + + ret = aul_app_get_pkgname_bypid(pid, pkgname, sizeof(pkgname)); + if (ret != AUL_R_OK) { + snprintf(buf, sizeof(buf), "/proc/%d/cmdline", pid); + + fd = open(buf, O_RDONLY); + if (fd < 0) { + return NULL; + } + + ret = read(fd, pkgname, sizeof(pkgname) - 1); + if (ret <= 0) { + close(fd); + return NULL; + } + + if (ret > NOTI_PKGNAME_LEN) + pkgname[NOTI_PKGNAME_LEN] = '\0'; + else + pkgname[ret] = '\0'; + + close(fd); + } + + if (strlen(pkgname) <= 0) { + return NULL; + } else { + return strdup(pkgname); + } +} + +static void _notification_pack_operation_msg(DBusMessageIter *iter, notification_op *op_list, int op_num) +{ + int i = 0; + + if (op_list == NULL) { + int tmp_op_num = 0; + + dbus_message_iter_append_basic(iter, DBUS_TYPE_INT32, &tmp_op_num); + return ; + } + + dbus_message_iter_append_basic(iter, DBUS_TYPE_INT32, &op_num); + for (i = 0; i < op_num; i++) { + NOTIFICATION_ERR("pack:%d/%d", i, op_num); + notification_op *op = op_list + i; + dbus_message_iter_append_basic(iter, DBUS_TYPE_INT32, &(op->type)); + dbus_message_iter_append_basic(iter, DBUS_TYPE_INT32, &(op->priv_id)); + dbus_message_iter_append_basic(iter, DBUS_TYPE_INT32, &(op->extra_info_1)); + dbus_message_iter_append_basic(iter, DBUS_TYPE_INT32, &(op->extra_info_2)); + } +} + +static void _notification_unpack_operation_msg(DBusMessageIter *iter, notification_op **op_list, int *op_num) +{ + int i = 0; + + if (iter == NULL || op_list == NULL || op_num == NULL) { + return; + } + + dbus_message_iter_get_basic(iter, op_num); + + int tmp_op_num = *op_num; + + if (tmp_op_num <= 0) { + *op_list = NULL; + *op_num = 0; + return; + } + + *op_list = (notification_op*)malloc(sizeof(notification_op) * (tmp_op_num)); + + dbus_message_iter_next(iter); + + if (*op_list != NULL) { + for (i = 0; i < tmp_op_num; i++) { + notification_op *op = (*op_list) + i; + dbus_message_iter_get_basic(iter, &(op->type)); + dbus_message_iter_next(iter); + dbus_message_iter_get_basic(iter, &(op->priv_id)); + dbus_message_iter_next(iter); + dbus_message_iter_get_basic(iter, &(op->extra_info_1)); + dbus_message_iter_next(iter); + dbus_message_iter_get_basic(iter, &(op->extra_info_2)); + dbus_message_iter_next(iter); + } + } +} + +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) { + + } + + if (noti->dir != NULL) { + + } +} + +static void _notification_chagned_noti_cb(DBusMessage *message, void *data) +{ + notification_cb_list_s *noti_cb_list = NULL; + DBusMessageIter iter; + + int op_num = 0; + notification_op *op_list = NULL; + + if (g_notification_cb_list == NULL) { + return; + } + + noti_cb_list = g_notification_cb_list; + + while (noti_cb_list->prev != NULL) { + noti_cb_list = noti_cb_list->prev; + } + + if (message != NULL) { + if (dbus_message_iter_init(message, &iter)) { + _notification_unpack_operation_msg(&iter, &op_list, &op_num); + NOTIFICATION_ERR("operation num:%d", op_num); + } + } + + while (noti_cb_list != NULL) { + if (noti_cb_list->cb_type == NOTIFICATION_CB_NORMAL && noti_cb_list->changed_cb) { + noti_cb_list->changed_cb(noti_cb_list->data, + NOTIFICATION_TYPE_NOTI); + } + if (noti_cb_list->cb_type == NOTIFICATION_CB_DETAILED && noti_cb_list->detailed_changed_cb) { + noti_cb_list->detailed_changed_cb(noti_cb_list->data, + NOTIFICATION_TYPE_NOTI, op_list, op_num); + } + + noti_cb_list = noti_cb_list->next; + } + + if (op_list != NULL) { + free(op_list); + } +} + +#if 0 +static void _notification_chagned_ongoing_cb(void *data) +{ + notification_cb_list_s *noti_cb_list = NULL; + + if (g_notification_cb_list == NULL) { + return; + } + + noti_cb_list = g_notification_cb_list; + + while (noti_cb_list->prev != NULL) { + noti_cb_list = noti_cb_list->prev; + } + + while (noti_cb_list != NULL) { + if (noti_cb_list->changed_cb) { + noti_cb_list->changed_cb(noti_cb_list->data, + NOTIFICATION_TYPE_ONGOING); + } + + noti_cb_list = noti_cb_list->next; + } +} +#endif + +static void _notification_pack_and_send_dbus_message(const char *type, notification_op *op_list , int op_num) +{ + DBusConnection *connection = NULL; + DBusMessage *message = NULL; + DBusMessageIter iter; + DBusError err; + dbus_bool_t ret; + int i = 0; + + if (!type) { + NOTIFICATION_ERR("type is NULL"); + return; + } + + dbus_error_init(&err); + connection = dbus_bus_get(DBUS_BUS_SYSTEM, &err); + if (!connection) { + NOTIFICATION_ERR("Fail to dbus_bus_get : %s", err.message); + return; + } + + message = dbus_message_new_signal(NOTI_DBUS_PATH, + NOTI_DBUS_INTERFACE, + type); + + if (!message) { + NOTIFICATION_ERR("fail to create dbus message"); + goto release_n_return; + } + + if (op_num > 0 && op_list != NULL) { + dbus_message_iter_init_append(message, &iter); + _notification_pack_operation_msg(&iter, op_list, op_num); + } + + ret = dbus_connection_send(connection, message, NULL); + if (!ret) { + NOTIFICATION_ERR("fail to send dbus message : %s", type); + goto release_n_return; + } + + dbus_connection_flush(connection); + + NOTIFICATION_DBG("success to emit signal [%s]", type); + +release_n_return: + dbus_error_free(&err); + + if (message) + dbus_message_unref(message); + + if (connection) + dbus_connection_unref(connection); +} + +#define SET_DBUS_MESSAGE 30 + +static void _notification_changed(const char *type, notification_op *op_list , int op_num) +{ + int set = 0; + int set_total = 0; + int set_modular = 0; + + if (op_num <= SET_DBUS_MESSAGE) { + _notification_pack_and_send_dbus_message(type, op_list, op_num); + } else { + set_total = op_num / SET_DBUS_MESSAGE; + set_modular = op_num - (set_total * SET_DBUS_MESSAGE); + + for (set = 0; set < set_total; set++) { + _notification_pack_and_send_dbus_message(type, op_list + (set * SET_DBUS_MESSAGE), SET_DBUS_MESSAGE); + } + + if (set_modular > 0) { + _notification_pack_and_send_dbus_message(type, + op_list + (set_total * SET_DBUS_MESSAGE), set_modular); + } + } +} + +static DBusHandlerResult _dbus_signal_filter(DBusConnection *conn, + DBusMessage *msg, void *user_data) +{ + const char *interface = NULL; + + interface = dbus_message_get_interface(msg); + NOTIFICATION_DBG("path : %s", dbus_message_get_path(msg)); + NOTIFICATION_DBG("interface : %s", interface); + + if (strcmp(NOTI_DBUS_INTERFACE, interface)) + return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + + + switch (dbus_message_get_type(msg)) { + case DBUS_MESSAGE_TYPE_SIGNAL: + _notification_chagned_noti_cb(msg, NULL); + return DBUS_HANDLER_RESULT_HANDLED; + default: + break; + } + return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; +} + +static DBusConnection *_noti_changed_monitor_init() +{ + DBusError err; + DBusConnection *conn = NULL; + char rule[1024]; + + dbus_error_init(&err); + conn = dbus_bus_get_private(DBUS_BUS_SYSTEM, &err); + if (!conn) { + printf("fail to get bus\n"); + return NULL; + } + dbus_connection_setup_with_g_main(conn, NULL); + snprintf(rule, 1024, + "path='%s',type='signal',interface='%s',member='%s'", + NOTI_DBUS_PATH, + NOTI_DBUS_INTERFACE, + NOTI_CHANGED_NOTI); + + dbus_bus_add_match(conn, rule, &err); + if (dbus_connection_add_filter(conn,_dbus_signal_filter, + NULL, NULL) == FALSE) { + NOTIFICATION_ERR("fail to dbus_connection_add_filter"); + dbus_connection_close(conn); + return NULL; + } + + dbus_connection_set_exit_on_disconnect(conn, FALSE); + return conn; +} + +static void _noti_chanaged_monitor_fini() +{ + DBusConnection *conn = g_dbus_handle; + char rule[1024]; + + if (!conn) + return; + dbus_connection_remove_filter(conn, _dbus_signal_filter, NULL); + + snprintf(rule, 1024, + "path='%s',type='signal',interface='%s',member='%s'", + NOTI_DBUS_PATH, + NOTI_DBUS_INTERFACE, + NOTI_CHANGED_NOTI); + dbus_bus_remove_match(conn, rule, NULL); + + dbus_connection_close(conn); + g_dbus_handle = NULL; +} + +notification_op *_notification_make_basic_op(notification_op_type_e type, int num_op, int *list_priv_id, int num_priv_id) +{ + int i = 0; + notification_op *op_list = NULL; + + if (num_op <= 0) { + return NULL; + } + + op_list = (notification_op *)malloc(sizeof(notification_op) * num_op); + memset(op_list, 0x0, sizeof(notification_op) * num_op); + + for (i = 0; i < num_priv_id; i++) { + (op_list + i)->type = type; + if (list_priv_id != NULL) { + (op_list + i)->priv_id = *(list_priv_id + i); + } + } + + return op_list; +} + +/* notification_set_icon will be removed */ +EXPORT_API notification_error_e notification_set_icon(notification_h noti, + const char *icon_path) +{ + int ret_err = NOTIFICATION_ERROR_NONE; + + ret_err = + notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, + icon_path); + + return ret_err; +} + +/* notification_get_icon will be removed */ +EXPORT_API notification_error_e notification_get_icon(notification_h noti, + char **icon_path) +{ + int ret_err = NOTIFICATION_ERROR_NONE; + char *ret_image_path = NULL; + + ret_err = + notification_get_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, + &ret_image_path); + + if (ret_err == NOTIFICATION_ERROR_NONE && icon_path != NULL) { + *icon_path = ret_image_path; + + //NOTIFICATION_DBG("Get icon : %s", *icon_path); + } + + return ret_err; +} + +EXPORT_API notification_error_e notification_set_image(notification_h noti, + notification_image_type_e type, + const char *image_path) +{ + bundle *b = NULL; + char buf_key[32] = { 0, }; + const char *ret_val = NULL; + + /* Check noti and image_path are valid data */ + if (noti == NULL || image_path == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + /* Check image type is valid type */ + if (type <= NOTIFICATION_IMAGE_TYPE_NONE + || type >= NOTIFICATION_IMAGE_TYPE_MAX) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + /* Check image path bundle is exist */ + if (noti->b_image_path) { + /* If image path bundle is exist, store local bundle value */ + b = noti->b_image_path; + + /* Set image type to key as char string type */ + snprintf(buf_key, sizeof(buf_key), "%d", type); + + /* Get value using key */ + ret_val = bundle_get_val(b, buf_key); + if (ret_val != NULL) { + /* If key is exist, remove this value to store new image path */ + bundle_del(b, buf_key); + } + + /* Add new image path with type key */ + bundle_add(b, buf_key, image_path); + } else { + /* If image path bundle is not exist, create new one */ + b = bundle_create(); + + /* Set image type to key as char string type */ + snprintf(buf_key, sizeof(buf_key), "%d", type); + + /* Add new image path with type key */ + bundle_add(b, buf_key, image_path); + + /* Save to image path bundle */ + noti->b_image_path = b; + } + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e notification_get_image(notification_h noti, + notification_image_type_e type, + char **image_path) +{ + 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) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + /* Check image type is valid data */ + if (type <= NOTIFICATION_IMAGE_TYPE_NONE + || type >= NOTIFICATION_IMAGE_TYPE_MAX) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + /* Check image path bundle exist */ + if (noti->b_image_path) { + /* If image path bundle exist, store local bundle data */ + b = noti->b_image_path; + + /* Set image type to key as char string type */ + snprintf(buf_key, sizeof(buf_key), "%d", type); + + /* Get value of key */ + ret_val = bundle_get_val(b, buf_key); + + *image_path = (char *)ret_val; + } else { + /* If image path bundle does not exist, image path is NULL */ + *image_path = NULL; + } + + /* If image path is NULL and type is ICON, icon path set from AIL */ + /* order : user icon -> launch_pkgname icon -> caller_pkgname icon -> service app icon */ + if (*image_path == NULL && type == NOTIFICATION_IMAGE_TYPE_ICON) { + /* Check App icon path is already set */ + if (noti->app_icon_path != NULL) { + /* 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; + } + } + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e notification_set_time(notification_h noti, + time_t input_time) +{ + /* Check noti is valid data */ + if (noti == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + if (input_time == 0) { + /* If input time is 0, set current time */ + noti->time = time(NULL); + } else { + /* save input time */ + noti->time = input_time; + } + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e notification_get_time(notification_h noti, + time_t * ret_time) +{ + /* Check noti and time is valid data */ + if (noti == NULL || ret_time == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + /* Set time infomation */ + *ret_time = noti->time; + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e notification_get_insert_time(notification_h noti, + time_t * ret_time) +{ + /* Check noti and ret_time is valid data */ + if (noti == NULL || ret_time == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + /* Set insert time information */ + *ret_time = noti->insert_time; + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e notification_set_title(notification_h noti, + const char *title, + const char *loc_title) +{ + int noti_err = NOTIFICATION_ERROR_NONE; + + noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, + title, loc_title, + NOTIFICATION_VARIABLE_TYPE_NONE); + + return noti_err; +} + +EXPORT_API notification_error_e notification_get_title(notification_h noti, + char **title, + char **loc_title) +{ + int noti_err = NOTIFICATION_ERROR_NONE; + char *ret_text = NULL; + + noti_err = + notification_get_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, + &ret_text); + + if (title != NULL) { + *title = ret_text; + } + + if (loc_title != NULL) { + *loc_title = NULL; + } + + return noti_err; +} + +EXPORT_API notification_error_e notification_set_content(notification_h noti, + const char *content, + const char *loc_content) +{ + int noti_err = NOTIFICATION_ERROR_NONE; + + noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, + content, loc_content, + NOTIFICATION_VARIABLE_TYPE_NONE); + + return noti_err; +} + +EXPORT_API notification_error_e notification_get_content(notification_h noti, + char **content, + char **loc_content) +{ + int noti_err = NOTIFICATION_ERROR_NONE; + char *ret_text = NULL; + + noti_err = + notification_get_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, + &ret_text); + + if (content != NULL) { + *content = ret_text; + } + + if (loc_content != NULL) { + *loc_content = NULL; + } + + return noti_err; + +#if 0 + ret = + vconf_get_bool + (VCONFKEY_SETAPPL_STATE_TICKER_NOTI_DISPLAY_CONTENT_BOOL, &boolval); + + if (ret == -1 || boolval == 0) { + if (content != NULL && noti->default_content != NULL) { + *content = noti->default_content; + } + + if (loc_content != NULL && noti->loc_default_content != NULL) { + *loc_content = noti->loc_default_content; + } + } +#endif +} + +EXPORT_API notification_error_e notification_set_text(notification_h noti, + notification_text_type_e type, + const char *text, + const char *key, + int args_type, ...) +{ + bundle *b = NULL; + char buf_key[32] = { 0, }; + char buf_val[1024] = { 0, }; + const char *ret_val = NULL; + va_list var_args; + notification_variable_type_e var_type; + int num_args = 0; + notification_error_e noti_err = NOTIFICATION_ERROR_NONE; + int var_value_int = 0; + double var_value_double = 0.0; + char *var_value_string = NULL; + notification_count_pos_type_e var_value_count = + NOTIFICATION_COUNT_POS_NONE; + + /* Check noti is valid data */ + if (noti == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + /* Check text type is valid type */ + if (type <= NOTIFICATION_TEXT_TYPE_NONE + || type >= NOTIFICATION_TEXT_TYPE_MAX) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + /* Check text bundle exist */ + if (text != NULL) { + if (noti->b_text != NULL) { + /* If text bundle exist, store local bundle data */ + b = noti->b_text; + + /* Make type to key as char string */ + snprintf(buf_key, sizeof(buf_key), "%d", type); + + /* Get value using type key */ + ret_val = bundle_get_val(b, buf_key); + if (ret_val != NULL) { + /* If value exist, remove this to add new value */ + bundle_del(b, buf_key); + } + + snprintf(buf_val, sizeof(buf_val), "%s", text); + + /* Add new text value */ + bundle_add(b, buf_key, buf_val); + } else { + /* If text bundle does not exist, create new one */ + b = bundle_create(); + + /* Make type to key as char string */ + snprintf(buf_key, sizeof(buf_key), "%d", type); + + snprintf(buf_val, sizeof(buf_val), "%s", text); + + /* Add new text value */ + bundle_add(b, buf_key, buf_val); + + /* Save text bundle */ + noti->b_text = b; + } + } else { + /* Reset if text is NULL */ + if (noti->b_text != NULL) { + /* If text bundle exist, store local bundle data */ + b = noti->b_text; + + /* Make type to key as char string */ + snprintf(buf_key, sizeof(buf_key), "%d", type); + + /* Get value using type key */ + ret_val = bundle_get_val(b, buf_key); + if (ret_val != NULL) { + /* If value exist, remove this */ + bundle_del(b, buf_key); + } + } + } + + /* Save key if key is valid data */ + if (key != NULL) { + /* Check key bundle exist */ + if (noti->b_key != NULL) { + /* If key bundle exist, store local bundle data */ + b = noti->b_key; + + /* Make type to key as char string */ + snprintf(buf_key, sizeof(buf_key), "%d", type); + + /* Get value using type key */ + ret_val = bundle_get_val(b, buf_key); + if (ret_val != NULL) { + /* If value exist, remove this to add new value */ + bundle_del(b, buf_key); + } + + snprintf(buf_val, sizeof(buf_val), "%s", key); + + /* Add new key value */ + bundle_add(b, buf_key, buf_val); + } else { + /* If key bundle does not exist, create new one */ + b = bundle_create(); + + /* Make type to key as char string */ + snprintf(buf_key, sizeof(buf_key), "%d", type); + + snprintf(buf_val, sizeof(buf_val), "%s", key); + + /* Add new key value */ + bundle_add(b, buf_key, buf_val); + + /* Save key bundle */ + noti->b_key = b; + } + } else { + /* Reset if key is NULL */ + if (noti->b_key != NULL) { + /* If key bundle exist, store local bundle data */ + b = noti->b_key; + + /* Make type to key as char string */ + snprintf(buf_key, sizeof(buf_key), "%d", type); + + /* Get value using type key */ + ret_val = bundle_get_val(b, buf_key); + if (ret_val != NULL) { + /* If value exist, remove this */ + bundle_del(b, buf_key); + } + } + } + + if (noti->b_format_args != NULL) { + b = noti->b_format_args; + } else { + b = bundle_create(); + } + + va_start(var_args, args_type); + + var_type = args_type; + num_args = 0; + + while (var_type != NOTIFICATION_VARIABLE_TYPE_NONE) { + /* Type */ + snprintf(buf_key, sizeof(buf_key), "%dtype%d", type, num_args); + snprintf(buf_val, sizeof(buf_val), "%d", var_type); + + ret_val = bundle_get_val(b, buf_key); + if (ret_val != NULL) { + bundle_del(b, buf_key); + } + + bundle_add(b, buf_key, buf_val); + + switch (var_type) { + case NOTIFICATION_VARIABLE_TYPE_INT: + var_value_int = va_arg(var_args, int); + + /* Value */ + snprintf(buf_key, sizeof(buf_key), "%dvalue%d", type, + num_args); + snprintf(buf_val, sizeof(buf_val), "%d", var_value_int); + + ret_val = bundle_get_val(b, buf_key); + if (ret_val != NULL) { + bundle_del(b, buf_key); + } + + bundle_add(b, buf_key, buf_val); + break; + case NOTIFICATION_VARIABLE_TYPE_DOUBLE: + var_value_double = va_arg(var_args, double); + + /* Value */ + snprintf(buf_key, sizeof(buf_key), "%dvalue%d", type, + num_args); + snprintf(buf_val, sizeof(buf_val), "%.2f", + var_value_double); + + ret_val = bundle_get_val(b, buf_key); + if (ret_val != NULL) { + bundle_del(b, buf_key); + } + + bundle_add(b, buf_key, buf_val); + break; + case NOTIFICATION_VARIABLE_TYPE_STRING: + var_value_string = va_arg(var_args, char *); + + /* Value */ + snprintf(buf_key, sizeof(buf_key), "%dvalue%d", type, + num_args); + snprintf(buf_val, sizeof(buf_val), "%s", + var_value_string); + + ret_val = bundle_get_val(b, buf_key); + if (ret_val != NULL) { + bundle_del(b, buf_key); + } + + bundle_add(b, buf_key, buf_val); + break; + case NOTIFICATION_VARIABLE_TYPE_COUNT: + var_value_count = + va_arg(var_args, notification_count_pos_type_e); + + /* Value */ + snprintf(buf_key, sizeof(buf_key), "%dvalue%d", type, + num_args); + snprintf(buf_val, sizeof(buf_val), "%d", + var_value_count); + + ret_val = bundle_get_val(b, buf_key); + if (ret_val != NULL) { + bundle_del(b, buf_key); + } + + bundle_add(b, buf_key, buf_val); + break; + default: + NOTIFICATION_ERR("Error. invalid variable type. : %d", + var_type); + noti_err = NOTIFICATION_ERROR_INVALID_DATA; + break; + } + + num_args++; + var_type = va_arg(var_args, notification_variable_type_e); + } + va_end(var_args); + + if (noti_err == NOTIFICATION_ERROR_NONE) { + noti->num_format_args = num_args; + } else { + noti->num_format_args = 0; + } + + snprintf(buf_key, sizeof(buf_key), "num%d", type); + snprintf(buf_val, sizeof(buf_val), "%d", noti->num_format_args); + + ret_val = bundle_get_val(b, buf_key); + if (ret_val != NULL) { + bundle_del(b, buf_key); + } + + bundle_add(b, buf_key, buf_val); + + noti->b_format_args = b; + + return noti_err; +} + +EXPORT_API notification_error_e notification_get_text(notification_h noti, + notification_text_type_e type, + char **text) +{ + 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; + + char *temp_str = NULL; + char result_str[NOTI_TEXT_RESULT_LEN] = { 0, }; + char buf_str[1024] = { 0, }; + int num_args = 0; + notification_variable_type_e ret_var_type = 0; + int ret_variable_int = 0; + double ret_variable_double = 0.0; + + /* Check noti is valid data */ + if (noti == NULL || text == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + /* Check text type is valid type */ + if (type <= NOTIFICATION_TEXT_TYPE_NONE + || type >= NOTIFICATION_TEXT_TYPE_MAX) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + /* Check key */ + if (noti->b_key != NULL) { + b = noti->b_key; + + /* Get text domain and dir */ + _notification_get_text_domain(noti); + + snprintf(buf_key, sizeof(buf_key), "%d", type); + + ret_val = bundle_get_val(b, buf_key); + if (ret_val != NULL && noti->domain != NULL + && noti->dir != NULL) { + /* Get application string */ + bindtextdomain(noti->domain, noti->dir); + + get_str = dgettext(noti->domain, ret_val); + } else if (ret_val != NULL) { + /* Get system string */ + get_str = dgettext("sys_string", ret_val); + } else { + get_str = NULL; + } + } + + if (get_str == NULL && noti->b_text != NULL) { + b = noti->b_text; + /* Get basic text */ + snprintf(buf_key, sizeof(buf_key), "%d", type); + + get_str = bundle_get_val(b, buf_key); + } + + check_type = type; + + /* Set display option is off type when option is off, type is noti */ + if (get_str != NULL && display_option_flag == 1 + && noti->type == NOTIFICATION_TYPE_NOTI) { + if (type == NOTIFICATION_TEXT_TYPE_CONTENT + || type == NOTIFICATION_TEXT_TYPE_GROUP_CONTENT) { + /* Set check_type to option content string */ + if (type == NOTIFICATION_TEXT_TYPE_CONTENT) { + check_type = + NOTIFICATION_TEXT_TYPE_CONTENT_FOR_DISPLAY_OPTION_IS_OFF; + } else if (type == NOTIFICATION_TEXT_TYPE_GROUP_CONTENT) { + check_type = + NOTIFICATION_TEXT_TYPE_GROUP_CONTENT_FOR_DISPLAY_OPTION_IS_OFF; + } + + /* Check key */ + if (noti->b_key != NULL) { + b = noti->b_key; + + /* Get text domain and dir */ + _notification_get_text_domain(noti); + + snprintf(buf_key, sizeof(buf_key), "%d", + check_type); + + ret_val = bundle_get_val(b, buf_key); + if (ret_val != NULL && noti->domain != NULL + && noti->dir != NULL) { + /* Get application string */ + bindtextdomain(noti->domain, noti->dir); + + get_check_type_str = + dgettext(noti->domain, ret_val); + } else if (ret_val != NULL) { + /* Get system string */ + get_check_type_str = + dgettext("sys_string", ret_val); + } else { + get_check_type_str = NULL; + } + } + + if (get_check_type_str == NULL && noti->b_text != NULL) { + b = noti->b_text; + /* Get basic text */ + snprintf(buf_key, sizeof(buf_key), "%d", + check_type); + + get_check_type_str = bundle_get_val(b, buf_key); + } + } + + if (get_check_type_str != NULL) { + /* Replace option off type string */ + get_str = get_check_type_str; + } else { + /* Set default string */ + get_str = + dgettext("sys_string", "IDS_COM_POP_MISSED_EVENT"); + } + } + + if (get_str != NULL) { + /* Get number format args */ + b = noti->b_format_args; + noti->num_format_args = 0; + + if (b != NULL) { + snprintf(buf_key, sizeof(buf_key), "num%d", check_type); + ret_val = bundle_get_val(b, buf_key); + if (ret_val != NULL) { + noti->num_format_args = atoi(ret_val); + } + } + + if (noti->num_format_args == 0) { + *text = (char *)get_str; + } else { + /* Check first variable is count, LEFT pos */ + snprintf(buf_key, sizeof(buf_key), "%dtype%d", + check_type, num_args); + ret_val = bundle_get_val(b, buf_key); + ret_var_type = atoi(ret_val); + + if (ret_var_type == NOTIFICATION_VARIABLE_TYPE_COUNT) { + /* Get var Value */ + snprintf(buf_key, sizeof(buf_key), "%dvalue%d", + check_type, num_args); + ret_val = bundle_get_val(b, buf_key); + ret_variable_int = atoi(ret_val); + + if (ret_variable_int == + NOTIFICATION_COUNT_POS_LEFT) { + notification_noti_get_count(noti->type, + noti->caller_pkgname, + noti->group_id, + noti->priv_id, + &ret_variable_int); + snprintf(buf_str, sizeof(buf_str), + "%d ", ret_variable_int); + + int src_len = strlen(result_str); + int max_len = NOTI_TEXT_RESULT_LEN - src_len - 1; + + strncat(result_str, buf_str, + max_len); + + num_args++; + } + + } + + /* Check variable IN pos */ + for (temp_str = (char *)get_str; *temp_str != '\0'; + temp_str++) { + if (*temp_str != '%') { + strncat(result_str, temp_str, 1); + } else { + if (*(temp_str + 1) == '%') { + strncat(result_str, temp_str, + 1); + } else if (*(temp_str + 1) == 'd') { + /* Get var Type */ + ret_variable_int = 0; + + snprintf(buf_key, + sizeof(buf_key), + "%dtype%d", check_type, + num_args); + ret_val = + bundle_get_val(b, buf_key); + ret_var_type = atoi(ret_val); + if (ret_var_type == + NOTIFICATION_VARIABLE_TYPE_COUNT) + { + /* Get notification count */ + notification_noti_get_count + (noti->type, + noti->caller_pkgname, + noti->group_id, + noti->priv_id, + &ret_variable_int); + } else { + /* Get var Value */ + snprintf(buf_key, + sizeof + (buf_key), + "%dvalue%d", + check_type, + num_args); + ret_val = + bundle_get_val(b, + buf_key); + ret_variable_int = + atoi(ret_val); + } + + snprintf(buf_str, + sizeof(buf_str), "%d", + ret_variable_int); + + int src_len = strlen(result_str); + int max_len = NOTI_TEXT_RESULT_LEN - src_len - 1; + + strncat(result_str, buf_str, + max_len); + + temp_str++; + + num_args++; + } else if (*(temp_str + 1) == 's') { + /* Get var Value */ + snprintf(buf_key, + sizeof(buf_key), + "%dvalue%d", + check_type, num_args); + ret_val = + bundle_get_val(b, buf_key); + + snprintf(buf_str, + sizeof(buf_str), "%s", + ret_val); + + int src_len = strlen(result_str); + int max_len = NOTI_TEXT_RESULT_LEN - src_len - 1; + + strncat(result_str, buf_str, + max_len); + + temp_str++; + + num_args++; + } else if (*(temp_str + 1) == 'f') { + /* Get var Value */ + snprintf(buf_key, + sizeof(buf_key), + "%dvalue%d", + check_type, num_args); + ret_val = + bundle_get_val(b, buf_key); + ret_variable_double = + atof(ret_val); + + snprintf(buf_str, + sizeof(buf_str), + "%.2f", + ret_variable_double); + + int src_len = strlen(result_str); + int max_len = NOTI_TEXT_RESULT_LEN - src_len - 1; + + strncat(result_str, buf_str, + max_len); + + temp_str++; + + num_args++; + } + } + + } + + /* Check last variable is count, LEFT pos */ + if (num_args < noti->num_format_args) { + snprintf(buf_key, sizeof(buf_key), "%dtype%d", + check_type, num_args); + ret_val = bundle_get_val(b, buf_key); + ret_var_type = atoi(ret_val); + if (ret_var_type == + NOTIFICATION_VARIABLE_TYPE_COUNT) { + /* Get var Value */ + snprintf(buf_key, sizeof(buf_key), + "%dvalue%d", check_type, + num_args); + ret_val = bundle_get_val(b, buf_key); + ret_variable_int = atoi(ret_val); + + if (ret_variable_int == + NOTIFICATION_COUNT_POS_RIGHT) { + notification_noti_get_count + (noti->type, + noti->caller_pkgname, + noti->group_id, + noti->priv_id, + &ret_variable_int); + snprintf(buf_str, + sizeof(buf_str), " %d", + ret_variable_int); + + int src_len = strlen(result_str); + int max_len = NOTI_TEXT_RESULT_LEN - src_len - 1; + + strncat(result_str, buf_str, + max_len); + + num_args++; + } + + } + } + + switch (check_type) { + case NOTIFICATION_TEXT_TYPE_TITLE: + case NOTIFICATION_TEXT_TYPE_GROUP_TITLE: + if (noti->temp_title != NULL) + free(noti->temp_title); + + noti->temp_title = strdup(result_str); + + *text = noti->temp_title; + break; + case NOTIFICATION_TEXT_TYPE_CONTENT: + case NOTIFICATION_TEXT_TYPE_CONTENT_FOR_DISPLAY_OPTION_IS_OFF: + case NOTIFICATION_TEXT_TYPE_GROUP_CONTENT: + case NOTIFICATION_TEXT_TYPE_GROUP_CONTENT_FOR_DISPLAY_OPTION_IS_OFF: + if (noti->temp_content != + NULL) + free(noti->temp_content); + + noti->temp_content = strdup(result_str); + + *text = noti->temp_content; + break; + default: + break; + } + + } + + } 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; + } + } + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e notification_set_text_domain(notification_h noti, + const char *domain, + const char *dir) +{ + /* check noti and domain is valid data */ + if (noti == NULL || domain == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + /* Check domain */ + if (noti->domain) { + /* Remove previous domain */ + free(noti->domain); + } + /* Copy domain */ + noti->domain = strdup(domain); + + /* Check locale dir */ + if (noti->dir) { + /* Remove previous locale dir */ + free(noti->dir); + } + /* Copy locale dir */ + noti->dir = strdup(dir); + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e notification_get_text_domain(notification_h noti, + char **domain, + char **dir) +{ + /* Check noti is valid data */ + if (noti == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + /* Get domain */ + if (domain != NULL && noti->domain != NULL) { + *domain = noti->domain; + } + + /* Get locale dir */ + if (dir != NULL && noti->dir != NULL) { + *dir = noti->dir; + } + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e notification_set_time_to_text(notification_h noti, notification_text_type_e type, + 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; + } + if (time <= 0) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + snprintf(buf, sizeof(buf), "%lu", time); + ret = notification_noti_set_tag(TAG_TIME, buf, buf_tag, sizeof(buf_tag)); + + if (ret != NOTIFICATION_ERROR_NONE) { + return ret; + } + + return notification_set_text(noti, type, buf_tag, NULL, NOTIFICATION_VARIABLE_TYPE_NONE); +} + +EXPORT_API notification_error_e notification_get_time_from_text(notification_h noti, notification_text_type_e type, + 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; + } + if (time == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + char *ret_text = NULL; + ret = notification_get_text(noti, type, &ret_text); + + if (ret != NOTIFICATION_ERROR_NONE || ret_text == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + if (notification_noti_get_tag_type(ret_text) == TAG_TYPE_INVALID) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + char *tag_value = NULL; + tag_value = notification_noti_strip_tag(ret_text); + if (tag_value == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + *time = atol(tag_value); + free(tag_value); + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e notification_set_sound(notification_h noti, + notification_sound_type_e type, + const char *path) +{ + /* Check noti is valid data */ + if (noti == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + /* Check type is valid */ + if (type < NOTIFICATION_SOUND_TYPE_NONE + || type >= NOTIFICATION_SOUND_TYPE_MAX) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + /* Save sound type */ + noti->sound_type = type; + + /* Save sound path if user data type */ + if (type == NOTIFICATION_SOUND_TYPE_USER_DATA && path != NULL) { + if (noti->sound_path != NULL) { + free(noti->sound_path); + } + + noti->sound_path = strdup(path); + } else { + if (noti->sound_path != NULL) { + free(noti->sound_path); + noti->sound_path = NULL; + } + } + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e notification_get_sound(notification_h noti, + notification_sound_type_e *type, + const char **path) +{ + /* check noti and type is valid data */ + if (noti == NULL || type == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + /* Set sound type */ + *type = noti->sound_type; + + /* Set sound path if user data type */ + if (noti->sound_type == NOTIFICATION_SOUND_TYPE_USER_DATA + && path != NULL) { + *path = noti->sound_path; + } + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e notification_set_vibration(notification_h noti, + notification_vibration_type_e type, + const char *path) +{ + /* Check noti is valid data */ + if (noti == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + /* Check type is valid */ + if (type < NOTIFICATION_VIBRATION_TYPE_NONE + || type >= NOTIFICATION_VIBRATION_TYPE_MAX) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + /* Save vibration type */ + noti->vibration_type = type; + + /* Save sound path if user data type */ + if (type == NOTIFICATION_VIBRATION_TYPE_USER_DATA && path != NULL) { + if (noti->vibration_path != NULL) { + free(noti->vibration_path); + } + + noti->vibration_path = strdup(path); + } else { + if (noti->vibration_path != NULL) { + free(noti->vibration_path); + noti->vibration_path = NULL; + } + } + + return NOTIFICATION_ERROR_NONE; + +} + +EXPORT_API notification_error_e notification_get_vibration(notification_h noti, + notification_vibration_type_e *type, + const char **path) +{ + /* check noti and type is valid data */ + if (noti == NULL || type == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + /* Set vibration type */ + *type = noti->vibration_type; + + /* Set sound path if user data type */ + if (noti->vibration_type == NOTIFICATION_VIBRATION_TYPE_USER_DATA + && path != NULL) { + *path = noti->vibration_path; + } + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e notification_set_application(notification_h noti, + const char *pkgname) +{ + if (noti == NULL || pkgname == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + if (noti->launch_pkgname) { + free(noti->launch_pkgname); + } + + noti->launch_pkgname = strdup(pkgname); + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e notification_get_application(notification_h noti, + char **pkgname) +{ + if (noti == NULL || pkgname == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + if (noti->launch_pkgname) { + *pkgname = noti->launch_pkgname; + } else { + *pkgname = noti->caller_pkgname; + } + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e notification_set_args(notification_h noti, + bundle * args, + bundle * group_args) +{ + if (noti == NULL || args == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + if (noti->args) { + bundle_free(noti->args); + } + + noti->args = bundle_dup(args); + + if (noti->group_args) { + bundle_free(noti->group_args); + noti->group_args = NULL; + } + + if (group_args != NULL) { + noti->group_args = bundle_dup(group_args); + } + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e notification_get_args(notification_h noti, + bundle ** args, + bundle ** group_args) +{ + if (noti == NULL || args == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + if (noti->args) { + *args = noti->args; + } else { + *args = NULL; + } + + if (group_args != NULL && noti->group_args) { + *group_args = noti->group_args; + } + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e notification_set_execute_option(notification_h noti, + notification_execute_type_e type, + const char *text, + const char *key, + bundle *service_handle) +{ + char buf_key[32] = { 0, }; + const char *ret_val = NULL; + bundle *b = NULL; + + if (noti == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + if (type <= NOTIFICATION_EXECUTE_TYPE_NONE + || type >= NOTIFICATION_EXECUTE_TYPE_MAX) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + /* Create execute option bundle if does not exist */ + if (noti->b_execute_option != NULL) { + noti->b_execute_option = bundle_create(); + } + + b = noti->b_execute_option; + + /* Save text */ + if (text != NULL) { + /* Make text key */ + snprintf(buf_key, sizeof(buf_key), "text%d", type); + + /* Check text key exist */ + ret_val = bundle_get_val(b, buf_key); + if (ret_val != NULL) { + /* Remove previous data */ + bundle_del(b, buf_key); + } + + /* Add text data */ + bundle_add(b, buf_key, text); + } + + /* Save key */ + if (key != NULL) { + /* Make key key */ + snprintf(buf_key, sizeof(buf_key), "key%d", type); + + /* Check key key exist */ + ret_val = bundle_get_val(b, buf_key); + if (ret_val != NULL) { + /* Remove previous data */ + bundle_del(b, buf_key); + } + + /* Add text data */ + bundle_add(b, buf_key, key); + } + + 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; + } + + /* 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_multi_launch = + bundle_dup(service_handle); + } + break; + } + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e notification_get_execute_option(notification_h noti, + notification_execute_type_e type, + const char **text, + bundle **service_handle) +{ + char buf_key[32] = { 0, }; + const char *ret_val = NULL; + char *get_str = NULL; + bundle *b = NULL; + + if (noti == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + if (type <= NOTIFICATION_EXECUTE_TYPE_NONE + || type >= NOTIFICATION_EXECUTE_TYPE_MAX) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + switch (type) { + case NOTIFICATION_EXECUTE_TYPE_RESPONDING: + b = noti->b_service_responding; + break; + case NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH: + b = noti->b_service_single_launch; + break; + case NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH: + b = noti->b_service_multi_launch; + break; + default: + b = NULL; + break; + } + + if (b != NULL) { + // Return text + if (text != NULL) { + // Get text domain and dir + if (noti->domain == NULL || noti->dir == NULL) { + _notification_get_text_domain(noti); + } + + /* Make key */ + snprintf(buf_key, sizeof(buf_key), "key%d", type); + + /* Check key key exist */ + ret_val = bundle_get_val(b, buf_key); + if (ret_val != NULL && noti->domain != NULL + && noti->dir != NULL) { + /* Get application string */ + bindtextdomain(noti->domain, noti->dir); + + get_str = dgettext(noti->domain, ret_val); + + *text = get_str; + } else if (ret_val != NULL) { + /* Get system string */ + get_str = dgettext("sys_string", ret_val); + + *text = get_str; + } else { + /* Get basic text */ + snprintf(buf_key, sizeof(buf_key), "text%d", + type); + + ret_val = bundle_get_val(b, buf_key); + + *text = ret_val; + } + } + } + + switch (type) { + case NOTIFICATION_EXECUTE_TYPE_RESPONDING: + b = noti->b_service_responding; + break; + case NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH: + b = noti->b_service_single_launch; + break; + case NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH: + b = noti->b_service_multi_launch; + break; + default: + b = NULL; + break; + } + + if (service_handle != NULL) { + *service_handle = b; + } + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e notification_set_property(notification_h noti, + int flags) +{ + /* Check noti is valid data */ + if (noti == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + /* Set flags */ + noti->flags_for_property = flags; + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e notification_get_property(notification_h noti, + int *flags) +{ + /* Check noti and flags are valid data */ + if (noti == NULL || flags == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + /* Set flags */ + *flags = noti->flags_for_property; + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e notification_set_display_applist(notification_h noti, + int applist) +{ + /* Check noti is valid data */ + if (noti == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + /* Set app list */ + noti->display_applist = applist; + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e notification_get_display_applist(notification_h noti, + int *applist) +{ + /* Check noti and applist are valid data */ + if (noti == NULL || applist == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + /* Set app list */ + *applist = noti->display_applist; + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e notification_set_size(notification_h noti, + double size) +{ + /* Check noti is valid data */ + if (noti == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + /* Save progress size */ + noti->progress_size = size; + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e notification_get_size(notification_h noti, + double *size) +{ + /* Check noti and size is valid data */ + if (noti == NULL || size == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + /* Set progress size */ + *size = noti->progress_size; + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e notification_set_progress(notification_h noti, + double percentage) +{ + /* Check noti is valid data */ + if (noti == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + /* Save progress percentage */ + noti->progress_percentage = percentage; + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e notification_get_progress(notification_h noti, + double *percentage) +{ + /* Check noti and percentage are valid data */ + if (noti == NULL || percentage == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + /* Set progress percentage */ + *percentage = noti->progress_percentage; + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e notification_set_pkgname(notification_h noti, + const char *pkgname) +{ + /* check noti and pkgname are valid data */ + if (noti == NULL || pkgname == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + /* Remove previous caller pkgname */ + if (noti->caller_pkgname) { + free(noti->caller_pkgname); + noti->caller_pkgname = NULL; + } + + noti->caller_pkgname = strdup(pkgname); + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e notification_get_pkgname(notification_h noti, + char **pkgname) +{ + /* Check noti and pkgname are valid data */ + if (noti == NULL || pkgname == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + /* Get caller pkgname */ + if (noti->caller_pkgname) { + *pkgname = noti->caller_pkgname; + } else { + *pkgname = NULL; + } + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e notification_set_layout(notification_h noti, + notification_ly_type_e layout) +{ + /* check noti and pkgname are valid data */ + if (noti == NULL || (layout < NOTIFICATION_LY_NONE || layout >= NOTIFICATION_LY_MAX)) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + noti->layout = layout; + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e notification_get_layout(notification_h noti, + notification_ly_type_e *layout) +{ + /* Check noti and pkgname are valid data */ + if (noti == NULL || layout == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + *layout = noti->layout; + + 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) +{ + /* check noti is valid data */ + if (noti == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + /* Check group_id is valid data */ + if (group_id) { + /* Set group id */ + if (noti->group_id < NOTIFICATION_GROUP_ID_NONE) { + *group_id = NOTIFICATION_GROUP_ID_NONE; + } else { + *group_id = noti->group_id; + } + } + + /* Check priv_id is valid data */ + if (priv_id) { + /* Set priv_id */ + *priv_id = noti->priv_id; + } + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e notification_get_type(notification_h noti, + notification_type_e *type) +{ + /* Check noti and type is valid data */ + if (noti == NULL || type == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + /* Set noti type */ + *type = noti->type; + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e notification_insert(notification_h noti, + int *priv_id) +{ + int ret = 0; + + /* Check noti is vaild data */ + if (noti == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + /* Check noti type is valid type */ + if (noti->type <= NOTIFICATION_TYPE_NONE + || noti->type >= NOTIFICATION_TYPE_MAX) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + /* Save insert time */ + noti->insert_time = time(NULL); + + /* Insert into DB */ + ret = notification_noti_insert(noti); + if (ret != NOTIFICATION_ERROR_NONE) { + return ret; + } + + /* Check disable update on insert property */ + if (noti->flags_for_property + & NOTIFICATION_PROP_DISABLE_UPDATE_ON_INSERT) { + /* Disable changed cb */ + } else { + /* Enable changed cb */ + notification_op *noti_op = _notification_make_basic_op(NOTIFICATION_OP_INSERT, 1, &(noti->priv_id), 1); + if (noti_op != NULL) { + _notification_changed(NOTI_CHANGED_NOTI, noti_op, 1); + free(noti_op); + } + } + + /* If priv_id is valid data, set priv_id */ + if (priv_id != NULL) { + *priv_id = noti->priv_id; + } + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e notification_update(notification_h noti) +{ + int ret = 0; + + /* Check noti is valid data */ + if (noti != NULL) { + /* Update insert time ? */ + noti->insert_time = time(NULL); + + ret = notification_noti_update(noti); + if (ret != NOTIFICATION_ERROR_NONE) { + return ret; + } + + notification_op *noti_op = _notification_make_basic_op(NOTIFICATION_OP_UPDATE, 1, &(noti->priv_id), 1); + if (noti_op != NULL) { + _notification_changed(NOTI_CHANGED_NOTI, noti_op, 1); + free(noti_op); + } + } else { + /* Send changed notification */ + notification_op *noti_op = _notification_make_basic_op(NOTIFICATION_OP_REFRESH, 1, NULL, 0); + if (noti_op != NULL) { + _notification_changed(NOTI_CHANGED_NOTI, noti_op, 1); + free(noti_op); + } + } + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e notifiation_clear(notification_type_e type) +{ + int ret = 0; + int num_deleted = 0; + int *list_deleted = NULL; + + /* Delete all notification of type */ + ret = notification_noti_delete_all(type, NULL, &num_deleted, &list_deleted); + if (ret != NOTIFICATION_ERROR_NONE) { + return ret; + } + + /* Send chagned notification */ + + if (num_deleted > 0 && list_deleted != NULL) { + notification_op *noti_op = _notification_make_basic_op(NOTIFICATION_OP_DELETE, num_deleted, list_deleted, num_deleted); + if (noti_op != NULL) { + NOTIFICATION_ERR("noti_op %x", noti_op); + _notification_changed(NOTI_CHANGED_NOTI, noti_op, num_deleted); + free(noti_op); + } + } + + if (list_deleted != NULL) { + free(list_deleted); + } + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e notification_delete_all_by_type(const char *pkgname, + notification_type_e type) +{ + int ret = 0; + int num_deleted = 0; + int *list_deleted = NULL; + char *caller_pkgname = NULL; + + if (pkgname == NULL) { + caller_pkgname = _notification_get_pkgname_by_pid(); + } else { + caller_pkgname = strdup(pkgname); + } + + ret = notification_noti_delete_all(type, caller_pkgname, &num_deleted, &list_deleted); + if (ret != NOTIFICATION_ERROR_NONE) { + free(caller_pkgname); + return ret; + } + + /* Send chagned notification */ + if (num_deleted > 0 && list_deleted != NULL) { + notification_op *noti_op = _notification_make_basic_op(NOTIFICATION_OP_DELETE, num_deleted, list_deleted, num_deleted); + if (noti_op != NULL) { + _notification_changed(NOTI_CHANGED_NOTI, noti_op, num_deleted); + free(noti_op); + } + } + if (caller_pkgname != NULL) { + free(caller_pkgname); + caller_pkgname = NULL; + } + if (list_deleted != NULL) { + free(list_deleted); + list_deleted = NULL; + } + + return ret; +} + +EXPORT_API notification_error_e notification_delete_group_by_group_id(const char *pkgname, + notification_type_e type, + int group_id) +{ + int ret = 0; + int num_deleted = 0; + int *list_deleted = NULL; + char *caller_pkgname = NULL; + + if (group_id < NOTIFICATION_GROUP_ID_NONE) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + if (pkgname == NULL) { + caller_pkgname = _notification_get_pkgname_by_pid(); + } else { + caller_pkgname = strdup(pkgname); + } + + ret = + notification_noti_delete_group_by_group_id(caller_pkgname, + group_id, &num_deleted, &list_deleted); + if (ret != NOTIFICATION_ERROR_NONE) { + free(caller_pkgname); + return ret; + } + + if (num_deleted > 0 && list_deleted != NULL) { + notification_op *noti_op = _notification_make_basic_op(NOTIFICATION_OP_DELETE, num_deleted, list_deleted, num_deleted); + if (noti_op != NULL) { + _notification_changed(NOTI_CHANGED_NOTI, noti_op, num_deleted); + free(noti_op); + } + } + + if (caller_pkgname != NULL) { + free(caller_pkgname); + caller_pkgname = NULL; + } + if (list_deleted != NULL) { + free(list_deleted); + list_deleted = NULL; + } + + return ret; +} + +EXPORT_API notification_error_e notification_delete_group_by_priv_id(const char *pkgname, + notification_type_e type, + int priv_id) +{ + int ret = 0; + char *caller_pkgname = NULL; + + if (priv_id < NOTIFICATION_PRIV_ID_NONE) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + if (pkgname == NULL) { + caller_pkgname = _notification_get_pkgname_by_pid(); + } else { + caller_pkgname = strdup(pkgname); + } + + ret = + notification_noti_delete_group_by_priv_id(caller_pkgname, priv_id); + if (ret != NOTIFICATION_ERROR_NONE) { + free(caller_pkgname); + return ret; + } + + notification_op *noti_op = _notification_make_basic_op(NOTIFICATION_OP_DELETE, 1, NULL, 0); + if (noti_op != NULL) { + _notification_changed(NOTI_CHANGED_NOTI, noti_op, 1); + free(noti_op); + } + + free(caller_pkgname); + + return ret; +} + +EXPORT_API notification_error_e notification_delete_by_priv_id(const char *pkgname, + notification_type_e type, + int priv_id) +{ + int ret = 0; + char *caller_pkgname = NULL; + + if (priv_id <= NOTIFICATION_PRIV_ID_NONE) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + if (pkgname == NULL) { + caller_pkgname = _notification_get_pkgname_by_pid(); + } else { + caller_pkgname = strdup(pkgname); + } + + ret = notification_noti_delete_by_priv_id(caller_pkgname, priv_id); + if (ret != NOTIFICATION_ERROR_NONE) { + free(caller_pkgname); + return ret; + } + + notification_op *noti_op = _notification_make_basic_op(NOTIFICATION_OP_DELETE, 1, &priv_id, 1); + if (noti_op != NULL) { + _notification_changed(NOTI_CHANGED_NOTI, noti_op, 1); + free(noti_op); + } + + free(caller_pkgname); + + return ret; +} + +EXPORT_API notification_error_e notification_delete(notification_h noti) +{ + int ret = 0; + + if (noti == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + ret = + notification_noti_delete_by_priv_id(noti->caller_pkgname, + noti->priv_id); + if (ret != NOTIFICATION_ERROR_NONE) { + return ret; + } + + if (noti->flags_for_property + & NOTIFICATION_PROP_DISABLE_UPDATE_ON_DELETE) { + NOTIFICATION_INFO("Disabled update while delete."); + } else { + notification_op *noti_op = _notification_make_basic_op(NOTIFICATION_OP_DELETE, 1, &(noti->priv_id), 1); + if (noti_op != NULL) { + _notification_changed(NOTI_CHANGED_NOTI, noti_op, 1); + free(noti_op); + } + } + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e notification_update_progress(notification_h noti, + int priv_id, + double progress) +{ + char *caller_pkgname = NULL; + int input_priv_id = 0; + double input_progress = 0.0; + + if (priv_id <= NOTIFICATION_PRIV_ID_NONE) { + if (noti == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } else { + input_priv_id = noti->priv_id; + } + } else { + input_priv_id = priv_id; + } + + if (noti == NULL) { + caller_pkgname = _notification_get_pkgname_by_pid(); + } else { + caller_pkgname = strdup(noti->caller_pkgname); + } + + if (progress < 0.0) { + input_progress = 0.0; + } else if (progress > 1.0) { + input_progress = 1.0; + } else { + input_progress = progress; + } + + notification_ongoing_update_progress(caller_pkgname, input_priv_id, + input_progress); + + if (caller_pkgname) { + free(caller_pkgname); + } + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e notification_update_size(notification_h noti, + int priv_id, + double size) +{ + char *caller_pkgname = NULL; + int input_priv_id = 0; + double input_size = 0.0; + + if (priv_id <= NOTIFICATION_PRIV_ID_NONE) { + if (noti == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } else { + input_priv_id = noti->priv_id; + } + } else { + input_priv_id = priv_id; + } + + if (noti == NULL) { + caller_pkgname = _notification_get_pkgname_by_pid(); + } else { + caller_pkgname = strdup(noti->caller_pkgname); + } + + if (size < 0.0) { + input_size = 0.0; + } else { + input_size = size; + } + + notification_ongoing_update_size(caller_pkgname, input_priv_id, + input_size); + + if (caller_pkgname) { + free(caller_pkgname); + } + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e notification_update_content(notification_h noti, + int priv_id, + const char *content) +{ + char *caller_pkgname = NULL; + int input_priv_id = 0; + + if (priv_id <= NOTIFICATION_PRIV_ID_NONE) { + if (noti == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } else { + input_priv_id = noti->priv_id; + } + } else { + input_priv_id = priv_id; + } + + if (noti == NULL) { + caller_pkgname = _notification_get_pkgname_by_pid(); + } else { + caller_pkgname = strdup(noti->caller_pkgname); + } + + notification_ongoing_update_content(caller_pkgname, input_priv_id, + content); + + if (caller_pkgname) { + free(caller_pkgname); + } + + return NOTIFICATION_ERROR_NONE; +} + +static notification_h _notification_create(notification_type_e type) { + notification_h noti = NULL; + + if (type <= NOTIFICATION_TYPE_NONE || type >= NOTIFICATION_TYPE_MAX) { + NOTIFICATION_ERR("INVALID TYPE : %d", type); + return NULL; + } + + noti = (notification_h) malloc(sizeof(struct _notification)); + if (noti == NULL) { + NOTIFICATION_ERR("NO MEMORY : noti == NULL"); + return NULL; + } + memset(noti, 0x00, sizeof(struct _notification)); + + noti->type = type; + + if (type == NOTIFICATION_TYPE_NOTI) + noti->layout = NOTIFICATION_LY_NOTI_EVENT_SINGLE; + else if (type == NOTIFICATION_TYPE_ONGOING) + noti->layout = NOTIFICATION_LY_ONGOING_PROGRESS; + + noti->group_id = NOTIFICATION_GROUP_ID_NONE; + noti->internal_group_id = 0; + noti->priv_id = NOTIFICATION_PRIV_ID_NONE; + + noti->caller_pkgname = _notification_get_pkgname_by_pid(); + noti->launch_pkgname = NULL; + noti->args = NULL; + noti->group_args = NULL; + + noti->b_execute_option = NULL; + noti->b_service_responding = NULL; + noti->b_service_single_launch = NULL; + noti->b_service_multi_launch = NULL; + + noti->sound_type = NOTIFICATION_SOUND_TYPE_NONE; + noti->sound_path = NULL; + + noti->vibration_type = NOTIFICATION_VIBRATION_TYPE_NONE; + noti->vibration_path = NULL; + + noti->domain = NULL; + noti->dir = NULL; + + noti->b_text = NULL; + noti->b_key = NULL; + noti->b_format_args = NULL; + noti->num_format_args = 0; + + noti->b_image_path = NULL; + + noti->time = 0; + noti->insert_time = 0; + + noti->flags_for_property = 0; + noti->display_applist = NOTIFICATION_DISPLAY_APP_ALL; + + noti->progress_size = 0.0; + noti->progress_percentage = 0.0; + + noti->app_icon_path = NULL; + noti->app_name = NULL; + noti->temp_title = NULL; + noti->temp_content = NULL; + + return noti; +} + +EXPORT_API notification_h notification_new(notification_type_e type, + int group_id, int priv_id) +{ + return _notification_create(type); +} + +EXPORT_API notification_h notification_create(notification_type_e type) +{ + return _notification_create(type); +} + +EXPORT_API notification_h notification_load(char *pkgname, + int priv_id) +{ + int ret = 0; + notification_h noti = NULL; + + noti = (notification_h) malloc(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) { + notification_free(noti); + return NULL; + } + + return noti; +} + +EXPORT_API notification_error_e notification_clone(notification_h noti, notification_h *clone) +{ + notification_h new_noti = NULL; + + if (noti == NULL || clone == NULL) { + NOTIFICATION_ERR("INVALID PARAMETER."); + return NOTIFICATION_ERROR_INVALID_DATA; + } + + new_noti = (notification_h) malloc(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; + + new_noti->group_id = noti->group_id; + new_noti->internal_group_id = noti->internal_group_id; + new_noti->priv_id = noti->priv_id; + + if(noti->caller_pkgname != NULL) { + new_noti->caller_pkgname = strdup(noti->caller_pkgname); + } else { + new_noti->caller_pkgname = _notification_get_pkgname_by_pid(); + } + if(noti->launch_pkgname != NULL) { + new_noti->launch_pkgname = strdup(noti->launch_pkgname); + } else { + new_noti->launch_pkgname = NULL; + } + + if(noti->args != NULL) { + new_noti->args = bundle_dup(noti->args); + } else { + new_noti->args = NULL; + } + if(noti->group_args != NULL) { + new_noti->group_args = bundle_dup(noti->group_args); + } else { + new_noti->group_args = NULL; + } + + if(noti->b_execute_option != NULL) { + new_noti->b_execute_option = bundle_dup(noti->b_execute_option); + } else { + new_noti->b_execute_option = NULL; + } + if(noti->b_service_responding != NULL) { + new_noti->b_service_responding = bundle_dup(noti->b_service_responding); + } else { + new_noti->b_service_responding = NULL; + } + if(noti->b_service_single_launch != NULL) { + new_noti->b_service_single_launch = bundle_dup(noti->b_service_single_launch); + } else { + new_noti->b_service_single_launch = NULL; + } + if(noti->b_service_multi_launch != NULL) { + new_noti->b_service_multi_launch = bundle_dup(noti->b_service_multi_launch); + } else { + new_noti->b_service_multi_launch = NULL; + } + + new_noti->sound_type = noti->sound_type; + if(noti->sound_path != NULL) { + new_noti->sound_path = strdup(noti->sound_path); + } else { + new_noti->sound_path = NULL; + } + new_noti->vibration_type = noti->vibration_type; + if(noti->vibration_path != NULL) { + new_noti->vibration_path = strdup(noti->vibration_path); + } else { + new_noti->vibration_path = NULL; + } + + if(noti->domain != NULL) { + new_noti->domain = strdup(noti->domain); + } else { + new_noti->domain = NULL; + } + if(noti->dir != NULL) { + new_noti->dir = strdup(noti->dir); + } else { + new_noti->dir = NULL; + } + + if(noti->b_text != NULL) { + new_noti->b_text = bundle_dup(noti->b_text); + } else { + new_noti->b_text = NULL; + } + if(noti->b_key != NULL) { + new_noti->b_key = bundle_dup(noti->b_key); + } else { + new_noti->b_key = NULL; + } + if(noti->b_format_args != NULL) { + new_noti->b_format_args = bundle_dup(noti->b_format_args); + } else { + new_noti->b_format_args = NULL; + } + new_noti->num_format_args = noti->num_format_args; + + if(noti->b_image_path != NULL) { + new_noti->b_image_path = bundle_dup(noti->b_image_path); + } else { + new_noti->b_image_path = NULL; + } + + new_noti->time = noti->time; + new_noti->insert_time = noti->insert_time; + + new_noti->flags_for_property = noti->flags_for_property; + new_noti->display_applist = noti->display_applist; + + new_noti->progress_size = noti->progress_size; + new_noti->progress_percentage = noti->progress_percentage; + + new_noti->app_icon_path = NULL; + new_noti->app_name = NULL; + new_noti->temp_title = NULL; + new_noti->temp_content = NULL; + + *clone = new_noti; + + return NOTIFICATION_ERROR_NONE; +} + + +EXPORT_API notification_error_e notification_free(notification_h noti) +{ + if (noti == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + if (noti->caller_pkgname) { + free(noti->caller_pkgname); + } + if (noti->launch_pkgname) { + free(noti->launch_pkgname); + } + if (noti->args) { + bundle_free(noti->args); + } + if (noti->group_args) { + bundle_free(noti->group_args); + } + + if (noti->b_execute_option) { + bundle_free(noti->b_execute_option); + } + if (noti->b_service_responding) { + bundle_free(noti->b_service_responding); + } + if (noti->b_service_single_launch) { + bundle_free(noti->b_service_single_launch); + } + if (noti->b_service_multi_launch) { + bundle_free(noti->b_service_multi_launch); + } + + if (noti->sound_path) { + free(noti->sound_path); + } + if (noti->vibration_path) { + free(noti->vibration_path); + } + + if (noti->domain) { + free(noti->domain); + } + if (noti->dir) { + free(noti->dir); + } + + if (noti->b_text) { + bundle_free(noti->b_text); + } + if (noti->b_key) { + bundle_free(noti->b_key); + } + if (noti->b_format_args) { + bundle_free(noti->b_format_args); + } + + if (noti->b_image_path) { + bundle_free(noti->b_image_path); + } + + if (noti->app_icon_path) { + free(noti->app_icon_path); + } + if (noti->app_name) { + free(noti->app_name); + } + if (noti->temp_title) { + free(noti->temp_title); + } + if (noti->temp_content) { + free(noti->temp_content); + } + + free(noti); + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e +notification_resister_changed_cb(void (*changed_cb) + (void *data, notification_type_e type), + void *user_data) +{ + notification_cb_list_s *noti_cb_list_new = NULL; + notification_cb_list_s *noti_cb_list = NULL; + + if (!g_dbus_handle) { + g_dbus_handle = _noti_changed_monitor_init(); + if (!g_dbus_handle) + return NOTIFICATION_ERROR_FROM_DBUS; + } + + noti_cb_list_new = + (notification_cb_list_s *) malloc(sizeof(notification_cb_list_s)); + + noti_cb_list_new->next = NULL; + noti_cb_list_new->prev = NULL; + + noti_cb_list_new->cb_type = NOTIFICATION_CB_NORMAL; + noti_cb_list_new->changed_cb = changed_cb; + noti_cb_list_new->detailed_changed_cb = NULL; + noti_cb_list_new->data = user_data; + + if (g_notification_cb_list == NULL) { + g_notification_cb_list = noti_cb_list_new; + } else { + noti_cb_list = g_notification_cb_list; + + while (noti_cb_list->next != NULL) { + noti_cb_list = noti_cb_list->next; + } + + noti_cb_list->next = noti_cb_list_new; + noti_cb_list_new->prev = noti_cb_list; + } + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e +notification_unresister_changed_cb(void (*changed_cb) + (void *data, notification_type_e type)) +{ + notification_cb_list_s *noti_cb_list = NULL; + notification_cb_list_s *noti_cb_list_prev = NULL; + notification_cb_list_s *noti_cb_list_next = NULL; + + noti_cb_list = g_notification_cb_list; + + if (noti_cb_list == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + while (noti_cb_list->prev != NULL) { + noti_cb_list = noti_cb_list->prev; + } + + do { + if (noti_cb_list->changed_cb == changed_cb) { + noti_cb_list_prev = noti_cb_list->prev; + noti_cb_list_next = noti_cb_list->next; + + if (noti_cb_list_prev == NULL) { + g_notification_cb_list = noti_cb_list_next; + } else { + noti_cb_list_prev->next = noti_cb_list_next; + } + + if (noti_cb_list_next == NULL) { + if (noti_cb_list_prev != NULL) { + noti_cb_list_prev->next = NULL; + } + } else { + noti_cb_list_next->prev = noti_cb_list_prev; + } + + free(noti_cb_list); + + if (g_notification_cb_list == NULL) + _noti_chanaged_monitor_fini(); + + return NOTIFICATION_ERROR_NONE; + } + noti_cb_list = noti_cb_list->next; + } while (noti_cb_list != NULL); + + return NOTIFICATION_ERROR_INVALID_DATA; +} + +EXPORT_API notification_error_e +notification_register_detailed_changed_cb( + void (*detailed_changed_cb)(void *data, notification_type_e type, notification_op *op_list, int num_op), + void *user_data) +{ + notification_cb_list_s *noti_cb_list_new = NULL; + notification_cb_list_s *noti_cb_list = NULL; + + if (!g_dbus_handle) { + g_dbus_handle = _noti_changed_monitor_init(); + if (!g_dbus_handle) + return NOTIFICATION_ERROR_FROM_DBUS; + } + + noti_cb_list_new = + (notification_cb_list_s *) malloc(sizeof(notification_cb_list_s)); + + noti_cb_list_new->next = NULL; + noti_cb_list_new->prev = NULL; + + noti_cb_list_new->cb_type = NOTIFICATION_CB_DETAILED; + noti_cb_list_new->changed_cb = NULL; + noti_cb_list_new->detailed_changed_cb = detailed_changed_cb; + noti_cb_list_new->data = user_data; + + if (g_notification_cb_list == NULL) { + g_notification_cb_list = noti_cb_list_new; + } else { + noti_cb_list = g_notification_cb_list; + + while (noti_cb_list->next != NULL) { + noti_cb_list = noti_cb_list->next; + } + + noti_cb_list->next = noti_cb_list_new; + noti_cb_list_new->prev = noti_cb_list; + } + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e +notification_unregister_detailed_changed_cb( + void (*detailed_changed_cb)(void *data, notification_type_e type, notification_op_type_e op_type, int *list_priv_id, int num_priv_id), + void *user_data) +{ + notification_cb_list_s *noti_cb_list = NULL; + notification_cb_list_s *noti_cb_list_prev = NULL; + notification_cb_list_s *noti_cb_list_next = NULL; + + noti_cb_list = g_notification_cb_list; + + if (noti_cb_list == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + while (noti_cb_list->prev != NULL) { + noti_cb_list = noti_cb_list->prev; + } + + do { + if (noti_cb_list->detailed_changed_cb == detailed_changed_cb) { + noti_cb_list_prev = noti_cb_list->prev; + noti_cb_list_next = noti_cb_list->next; + + if (noti_cb_list_prev == NULL) { + g_notification_cb_list = noti_cb_list_next; + } else { + noti_cb_list_prev->next = noti_cb_list_next; + } + + if (noti_cb_list_next == NULL) { + if (noti_cb_list_prev != NULL) { + noti_cb_list_prev->next = NULL; + } + } else { + noti_cb_list_next->prev = noti_cb_list_prev; + } + + free(noti_cb_list); + + if (g_notification_cb_list == NULL) + _noti_chanaged_monitor_fini(); + + return NOTIFICATION_ERROR_NONE; + } + noti_cb_list = noti_cb_list->next; + } while (noti_cb_list != NULL); + + 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, + int priv_id, int *count) +{ + int ret = 0; + int noti_count = 0; + + ret = + notification_noti_get_count(type, pkgname, group_id, priv_id, + ¬i_count); + if (ret != NOTIFICATION_ERROR_NONE) { + return ret; + } + + if (count != NULL) { + *count = noti_count; + } + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e notification_get_list(notification_type_e type, + int count, + notification_list_h *list) +{ + notification_list_h get_list = NULL; + int ret = 0; + + ret = notification_noti_get_grouping_list(type, count, &get_list); + if (ret != NOTIFICATION_ERROR_NONE) { + return ret; + } + + *list = get_list; + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e +notification_get_grouping_list(notification_type_e type, int count, + notification_list_h * list) +{ + notification_list_h get_list = NULL; + int ret = 0; + + ret = notification_noti_get_grouping_list(type, count, &get_list); + if (ret != NOTIFICATION_ERROR_NONE) { + return ret; + } + + *list = get_list; + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e notification_get_detail_list(const char *pkgname, + int group_id, + int priv_id, + int count, + notification_list_h *list) +{ + notification_list_h get_list = NULL; + int ret = 0; + + ret = + notification_noti_get_detail_list(pkgname, group_id, priv_id, count, + &get_list); + if (ret != NOTIFICATION_ERROR_NONE) { + return ret; + } + + *list = get_list; + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e notification_free_list(notification_list_h list) +{ + notification_list_h cur_list = NULL; + notification_h noti = NULL; + + if (list == NULL) { + NOTIFICATION_ERR("INVALID DATA : list == NULL"); + return NOTIFICATION_ERROR_INVALID_DATA; + } + + cur_list = notification_list_get_head(list); + + while (cur_list != NULL) { + noti = notification_list_get_data(cur_list); + cur_list = notification_list_remove(cur_list, noti); + + notification_free(noti); + } + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e notification_op_get_data(notification_op *noti_op, notification_op_data_type_e type, + void *data) +{ + if (noti_op == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + switch (type) { + case NOTIFICATION_OP_DATA_TYPE: + *((int*)data) = noti_op->type; + break; + case NOTIFICATION_OP_DATA_PRIV_ID: + *((int*)data) = noti_op->priv_id; + break; + case NOTIFICATION_OP_DATA_EXTRA_INFO_1: + *((int*)data) = noti_op->extra_info_1; + break; + case NOTIFICATION_OP_DATA_EXTRA_INFO_2: + *((int*)data) = noti_op->extra_info_2; + break; + default: + return NOTIFICATION_ERROR_INVALID_DATA; + break; + } + + return NOTIFICATION_ERROR_NONE; +} diff --git a/src/notification_db.c b/src/notification_db.c new file mode 100755 index 0000000..6cfa2d6 --- /dev/null +++ b/src/notification_db.c @@ -0,0 +1,110 @@ +/* + * 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>, Youngsub Ko <ys4610.ko@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 <errno.h> +#include <unistd.h> +#include <stdio.h> +#include <string.h> + +#include <sqlite3.h> +#include <db-util.h> + +#include <notification_error.h> +#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; + sqlite3 *db; + + ret = db_util_open(dbfile, &db, 0); + if (ret != SQLITE_OK) { + NOTIFICATION_ERR("DB open error(%d), %s", ret, dbfile); + return NULL; + } + + return db; +} + +int notification_db_close(sqlite3 ** db) +{ + int ret = 0; + + if (db == NULL || *db == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + ret = db_util_close(*db); + if (ret != SQLITE_OK) { + NOTIFICATION_ERR("DB close error(%d)", ret); + return NOTIFICATION_ERROR_FROM_DB; + } + + *db = NULL; + + return NOTIFICATION_ERROR_NONE; +} + +int notification_db_exec(sqlite3 * db, const char *query) +{ + int ret = 0; + char *err_msg = NULL; + + if (db == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + ret = sqlite3_exec(db, query, NULL, NULL, &err_msg); + if (ret != SQLITE_OK) { + NOTIFICATION_ERR("SQL error(%d) : %s", ret, err_msg); + sqlite3_free(err_msg); + return NOTIFICATION_ERROR_FROM_DB; + } + + return NOTIFICATION_ERROR_NONE; +} + +char *notification_db_column_text(sqlite3_stmt * stmt, int col) +{ + const unsigned char *col_text = NULL; + + col_text = sqlite3_column_text(stmt, col); + if (col_text == NULL || col_text[0] == '\0') { + return NULL; + } + + return strdup((char *)col_text); +} + +bundle *notification_db_column_bundle(sqlite3_stmt * stmt, int col) +{ + const unsigned char *col_bundle = NULL; + + col_bundle = sqlite3_column_text(stmt, col); + if (col_bundle == NULL || col_bundle[0] == '\0') { + return NULL; + } + + return bundle_decode(col_bundle, strlen((char *)col_bundle)); +} diff --git a/src/notification_group.c b/src/notification_group.c new file mode 100755 index 0000000..507e6bc --- /dev/null +++ b/src/notification_group.c @@ -0,0 +1,196 @@ +/* + * 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>, Youngsub Ko <ys4610.ko@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 <stdlib.h> +#include <string.h> + +#include <notification_debug.h> +#include <notification_group.h> +#include <notification_db.h> + +static int _notification_group_check_data_inserted(const char *pkgname, + int group_id, sqlite3 * db) +{ + sqlite3_stmt *stmt = NULL; + char query[NOTIFICATION_QUERY_MAX] = { 0, }; + int ret = NOTIFICATION_ERROR_NONE, result = 0; + + snprintf(query, sizeof(query), + "select count(*) from noti_group_data where caller_pkgname = '%s' and group_id = %d", + pkgname, group_id); + + 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; + } + + NOTIFICATION_INFO("Check Data Inserted : query[%s], result : [%d]", + query, result); + + sqlite3_finalize(stmt); + + if (result > 0) { + return NOTIFICATION_ERROR_ALREADY_EXIST_ID; + } + + return NOTIFICATION_ERROR_NONE; +} + +notification_error_e notification_group_set_badge(const char *pkgname, + int group_id, int count) +{ + sqlite3 *db; + sqlite3_stmt *stmt = NULL; + char query[NOTIFICATION_QUERY_MAX] = { 0, }; + int ret = 0; + int result = NOTIFICATION_ERROR_NONE; + + /* Open DB */ + db = notification_db_open(DBPATH); + + /* Check pkgname & group_id */ + ret = _notification_group_check_data_inserted(pkgname, group_id, db); + + /* Make query */ + if (ret == NOTIFICATION_ERROR_NONE) { + /* Insert if does not exist */ + snprintf(query, sizeof(query), "insert into noti_group_data (" + "caller_pkgname, group_id, badge, content, loc_content) values (" + "'%s', %d, %d, '', '')", pkgname, group_id, count); + + } else { + /* Update if exist */ + snprintf(query, sizeof(query), "update noti_group_data " + "set badge = %d " + "where caller_pkgname = '%s' and group_id = %d", + count, pkgname, group_id); + } + + ret = sqlite3_prepare_v2(db, query, -1, &stmt, NULL); + if (ret != SQLITE_OK) { + NOTIFICATION_ERR("Insert Query : %s", query); + NOTIFICATION_ERR("Insert DB error(%d) : %s", ret, + sqlite3_errmsg(db)); + if (stmt) { + sqlite3_finalize(stmt); + } + + if (db) { + notification_db_close(&db); + } + return NOTIFICATION_ERROR_FROM_DB; + } + + ret = sqlite3_step(stmt); + if (ret == SQLITE_OK || ret == SQLITE_DONE) { + result = NOTIFICATION_ERROR_NONE; + } else { + result = NOTIFICATION_ERROR_FROM_DB; + } + + if (stmt) { + sqlite3_finalize(stmt); + } + + /* Close DB */ + if (db) { + notification_db_close(&db); + } + + return result; +} + +notification_error_e notification_group_get_badge(const char *pkgname, + int group_id, int *count) +{ + sqlite3 *db; + sqlite3_stmt *stmt = NULL; + char query[NOTIFICATION_QUERY_MAX] = { 0, }; + int ret = 0; + int col = 0; + + /* Open DB */ + db = notification_db_open(DBPATH); + + /* Make query */ + if (group_id == NOTIFICATION_GROUP_ID_NONE) { + /* Check Group id None is exist */ + ret = + _notification_group_check_data_inserted(pkgname, group_id, + db); + + if (ret == NOTIFICATION_ERROR_NONE) { + /* Get all of pkgname count if none group id is not exist */ + snprintf(query, sizeof(query), + "select sum(badge) " + "from noti_group_data " + "where caller_pkgname = '%s'", pkgname); + } else { + /* Get none group id count */ + snprintf(query, sizeof(query), + "select badge " + "from noti_group_data " + "where caller_pkgname = '%s' and group_id = %d", + pkgname, group_id); + } + } else { + snprintf(query, sizeof(query), + "select badge " + "from noti_group_data " + "where caller_pkgname = '%s' and group_id = %d", + pkgname, group_id); + } + + NOTIFICATION_INFO("Get badge : query[%s]", query); + + ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL); + if (ret != SQLITE_OK) { + NOTIFICATION_ERR("Select Query : %s", query); + NOTIFICATION_ERR("Select DB error(%d) : %s", ret, + sqlite3_errmsg(db)); + + return NOTIFICATION_ERROR_FROM_DB; + } + + ret = sqlite3_step(stmt); + if (ret == SQLITE_ROW) { + *count = sqlite3_column_int(stmt, col++); + } + + sqlite3_finalize(stmt); + + // db close + if (db) { + notification_db_close(&db); + } + + return NOTIFICATION_ERROR_NONE; +} diff --git a/src/notification_list.c b/src/notification_list.c new file mode 100755 index 0000000..e516029 --- /dev/null +++ b/src/notification_list.c @@ -0,0 +1,211 @@ +/* + * 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>, Youngsub Ko <ys4610.ko@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 <stdlib.h> + +#include <notification.h> +#include <notification_list.h> +#include <notification_debug.h> +#include <notification_internal.h> + +struct _notification_list { + notification_list_h prev; + notification_list_h next; + + notification_h noti; +}; + +notification_list_h _notification_list_create(void) +{ + notification_list_h list = NULL; + + list = (notification_list_h) malloc(sizeof(struct _notification_list)); + if (list == NULL) { + NOTIFICATION_ERR("NO MEMORY"); + return NULL; + } + + list->prev = NULL; + list->next = NULL; + + list->noti = NULL; + + return list; +} + +EXPORT_API notification_list_h notification_list_get_head(notification_list_h list) +{ + notification_list_h cur_list = NULL; + + if (list == NULL) { + NOTIFICATION_ERR("INVALID DATA : list == NULL"); + return NULL; + } + + cur_list = list; + + while (cur_list->prev != NULL) { + cur_list = cur_list->prev; + } + + return cur_list; +} + +EXPORT_API notification_list_h notification_list_get_tail(notification_list_h list) +{ + notification_list_h cur_list = NULL; + + if (list == NULL) { + NOTIFICATION_ERR("INVALID DATA : list == NULL"); + return NULL; + } + + cur_list = list; + + while (cur_list->next != NULL) { + cur_list = cur_list->next; + } + + return cur_list; +} + +EXPORT_API notification_list_h notification_list_get_prev(notification_list_h list) +{ + notification_list_h cur_list = NULL; + + if (list == NULL) { + NOTIFICATION_ERR("INVALID DATA : list == NULL"); + return NULL; + } + + cur_list = list; + + return cur_list->prev; +} + +EXPORT_API notification_list_h notification_list_get_next(notification_list_h list) +{ + notification_list_h cur_list = NULL; + + if (list == NULL) { + NOTIFICATION_ERR("INVALID DATA : list == NULL"); + return NULL; + } + + cur_list = list; + + return cur_list->next; +} + +EXPORT_API notification_h notification_list_get_data(notification_list_h list) +{ + notification_list_h cur_list = NULL; + + if (list == NULL) { + NOTIFICATION_ERR("INVALID DATA : list == NULL"); + return NULL; + } + + cur_list = list; + + return cur_list->noti; +} + +EXPORT_API notification_list_h notification_list_append(notification_list_h list, + notification_h noti) +{ + notification_list_h new_list = NULL; + notification_list_h cur_list = NULL; + + if (noti == NULL) { + NOTIFICATION_ERR("INVALID DATA : data == NULL"); + return NULL; + } + + if (list != NULL) { + cur_list = notification_list_get_tail(list); + + new_list = _notification_list_create(); + if (new_list == NULL) { + NOTIFICATION_ERR("NO MEMORY"); + return NULL; + } + + cur_list->next = new_list; + new_list->prev = cur_list; + + new_list->noti = noti; + } else { + cur_list = _notification_list_create(); + if (cur_list == NULL) { + NOTIFICATION_ERR("NO MEMORY"); + return NULL; + } + + new_list = cur_list; + new_list->noti = noti; + } + + return new_list; +} + +EXPORT_API notification_list_h notification_list_remove(notification_list_h list, + notification_h noti) +{ + notification_list_h cur_list = NULL; + notification_list_h prev_list = NULL; + notification_list_h next_list = NULL; + + cur_list = notification_list_get_head(list); + while (cur_list != NULL) { + if (cur_list->noti == noti) { + //remove + prev_list = cur_list->prev; + next_list = cur_list->next; + + if (next_list != NULL) { + if (prev_list != NULL) { + prev_list->next = next_list; + next_list->prev = prev_list; + } else { + next_list->prev = NULL; + } + } else { + if (prev_list != NULL) { + prev_list->next = NULL; + } + } + + free(cur_list); + break; + } + + cur_list = cur_list->next; + } + + if (prev_list != NULL) { + return notification_list_get_head(prev_list); + } else if (next_list != NULL) { + return next_list; + } + + return NULL; +} diff --git a/src/notification_noti.c b/src/notification_noti.c new file mode 100755 index 0000000..5d2c218 --- /dev/null +++ b/src/notification_noti.c @@ -0,0 +1,1502 @@ +/* + * 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>, Youngsub Ko <ys4610.ko@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 <vconf.h> + +#include <notification.h> +#include <notification_db.h> +#include <notification_noti.h> +#include <notification_debug.h> +#include <notification_internal.h> + +static int _notification_noti_bind_query(sqlite3_stmt * stmt, const char *name, + const char *str) +{ + int ret = 0; + int index = 0; + + index = sqlite3_bind_parameter_index(stmt, name); + if (index == 0) { + NOTIFICATION_ERR("Insert : invalid column name"); + return NOTIFICATION_ERROR_FROM_DB; + } + + ret = + sqlite3_bind_text(stmt, index, NOTIFICATION_CHECK_STR(str), -1, + SQLITE_STATIC); + if (ret != SQLITE_OK) { + NOTIFICATION_ERR("Insert text : %s", + NOTIFICATION_CHECK_STR(str)); + return NOTIFICATION_ERROR_FROM_DB; + } + + return NOTIFICATION_ERROR_NONE; +} + +static int _notification_noti_check_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 check priv_id exist */ + snprintf(query, sizeof(query), + "select count(*) from noti_list where caller_pkgname = '%s' and priv_id = %d", + noti->caller_pkgname, noti->priv_id); + + 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, there is priv_id in DB */ + if (result > 0) { + return NOTIFICATION_ERROR_ALREADY_EXIST_ID; + } + + 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) +{ + sqlite3_stmt *stmt = NULL; + char query[NOTIFICATION_QUERY_MAX] = { 0, }; + int ret = NOTIFICATION_ERROR_NONE, result = 0; + + snprintf(query, sizeof(query), + "select internal_group_id from noti_list where caller_pkgname = '%s' and priv_id = %d", + pkgname, priv_id); + + 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_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(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) +{ + char *args = NULL; + char *group_args = NULL; + char *b_image_path = NULL; + char *b_execute_option = NULL; + char *b_service_responding = NULL; + char *b_service_single_launch = NULL; + char *b_service_multi_launch = NULL; + char *b_text = NULL; + char *b_key = NULL; + char *b_format_args = NULL; + int flag_simmode = 0; + + /* Decode bundle to insert DB */ + if (noti->args) { + bundle_encode(noti->args, (bundle_raw **) & args, NULL); + } + if (noti->group_args) { + bundle_encode(noti->group_args, (bundle_raw **) & group_args, + NULL); + } + + if (noti->b_execute_option) { + bundle_encode(noti->b_execute_option, + (bundle_raw **) & b_execute_option, NULL); + } + if (noti->b_service_responding) { + bundle_encode(noti->b_service_responding, + (bundle_raw **) & b_service_responding, NULL); + } + if (noti->b_service_single_launch) { + bundle_encode(noti->b_service_single_launch, + (bundle_raw **) & b_service_single_launch, NULL); + } + if (noti->b_service_multi_launch) { + bundle_encode(noti->b_service_multi_launch, + (bundle_raw **) & b_service_multi_launch, NULL); + } + + if (noti->b_text) { + bundle_encode(noti->b_text, (bundle_raw **) & b_text, NULL); + } + if (noti->b_key) { + bundle_encode(noti->b_key, (bundle_raw **) & b_key, NULL); + } + if (noti->b_format_args) { + bundle_encode(noti->b_format_args, + (bundle_raw **) & b_format_args, NULL); + } + + if (noti->b_image_path) { + bundle_encode(noti->b_image_path, + (bundle_raw **) & b_image_path, NULL); + } + + /* Check only simmode property is enable */ + if (noti->flags_for_property & NOTIFICATION_PROP_DISPLAY_ONLY_SIMMODE) { + flag_simmode = 1; + } + + /* Make query */ + snprintf(query, query_size, "insert into noti_list (" + "type, " + "layout, " + "caller_pkgname, launch_pkgname, " + "image_path, " + "group_id, internal_group_id, priv_id, " + "title_key, " + "b_text, b_key, b_format_args, num_format_args, " + "text_domain, text_dir, " + "time, insert_time, " + "args, group_args, " + "b_execute_option, " + "b_service_responding, b_service_single_launch, b_service_multi_launch, " + "sound_type, sound_path, vibration_type, vibration_path, " + "flags_for_property, flag_simmode, display_applist, " + "progress_size, progress_percentage) values (" + "%d, " + "%d, " + "'%s', '%s', " + "'%s', " + "%d, %d, %d, " + "$title_key, " + "'%s', '%s', '%s', %d, " + "'%s', '%s', " + "%d, %d, " + "'%s', '%s', " + "'%s', " + "'%s', '%s', '%s', " + "%d, '%s', %d, '%s', " + "%d, %d, %d, " + "%f, %f)", + noti->type, + noti->layout, + NOTIFICATION_CHECK_STR(noti->caller_pkgname), + NOTIFICATION_CHECK_STR(noti->launch_pkgname), + NOTIFICATION_CHECK_STR(b_image_path), noti->group_id, + noti->internal_group_id, noti->priv_id, + NOTIFICATION_CHECK_STR(b_text), NOTIFICATION_CHECK_STR(b_key), + NOTIFICATION_CHECK_STR(b_format_args), noti->num_format_args, + NOTIFICATION_CHECK_STR(noti->domain), + NOTIFICATION_CHECK_STR(noti->dir), (int)noti->time, + (int)noti->insert_time, NOTIFICATION_CHECK_STR(args), + NOTIFICATION_CHECK_STR(group_args), + NOTIFICATION_CHECK_STR(b_execute_option), + NOTIFICATION_CHECK_STR(b_service_responding), + NOTIFICATION_CHECK_STR(b_service_single_launch), + NOTIFICATION_CHECK_STR(b_service_multi_launch), + noti->sound_type, NOTIFICATION_CHECK_STR(noti->sound_path), + noti->vibration_type, + NOTIFICATION_CHECK_STR(noti->vibration_path), + noti->flags_for_property, flag_simmode, noti->display_applist, + noti->progress_size, noti->progress_percentage); + + /* Free decoded data */ + if (args) { + free(args); + } + if (group_args) { + free(group_args); + } + + if (b_execute_option) { + free(b_execute_option); + } + if (b_service_responding) { + free(b_service_responding); + } + if (b_service_single_launch) { + free(b_service_single_launch); + } + if (b_service_multi_launch) { + free(b_service_multi_launch); + } + + if (b_text) { + free(b_text); + } + if (b_key) { + free(b_key); + } + if (b_format_args) { + free(b_format_args); + } + + if (b_image_path) { + free(b_image_path); + } + + return NOTIFICATION_ERROR_NONE; +} + + +static int _notification_noti_make_update_query(notification_h noti, char *query, + int query_size) +{ + char *args = NULL; + char *group_args = NULL; + char *b_image_path = NULL; + char *b_execute_option = NULL; + char *b_service_responding = NULL; + char *b_service_single_launch = NULL; + char *b_service_multi_launch = NULL; + char *b_text = NULL; + char *b_key = NULL; + char *b_format_args = NULL; + int flag_simmode = 0; + + /* Decode bundle to update DB */ + if (noti->args) { + bundle_encode(noti->args, (bundle_raw **) & args, NULL); + } + if (noti->group_args) { + bundle_encode(noti->group_args, (bundle_raw **) & group_args, + NULL); + } + + if (noti->b_execute_option) { + bundle_encode(noti->b_execute_option, + (bundle_raw **) & b_execute_option, NULL); + } + if (noti->b_service_responding) { + bundle_encode(noti->b_service_responding, + (bundle_raw **) & b_service_responding, NULL); + } + if (noti->b_service_single_launch) { + bundle_encode(noti->b_service_single_launch, + (bundle_raw **) & b_service_single_launch, NULL); + } + if (noti->b_service_multi_launch) { + bundle_encode(noti->b_service_multi_launch, + (bundle_raw **) & b_service_multi_launch, NULL); + } + + if (noti->b_text) { + bundle_encode(noti->b_text, (bundle_raw **) & b_text, NULL); + } + if (noti->b_key) { + bundle_encode(noti->b_key, (bundle_raw **) & b_key, NULL); + } + if (noti->b_format_args) { + bundle_encode(noti->b_format_args, + (bundle_raw **) & b_format_args, NULL); + } + + if (noti->b_image_path) { + bundle_encode(noti->b_image_path, + (bundle_raw **) & b_image_path, NULL); + } + + /* Check only simmode property is enable */ + if (noti->flags_for_property & NOTIFICATION_PROP_DISPLAY_ONLY_SIMMODE) { + flag_simmode = 1; + } + + /* Make query */ + snprintf(query, query_size, "update noti_list set " + "type = %d, " + "layout = %d, " + "launch_pkgname = '%s', " + "image_path = '%s', " + "b_text = '%s', b_key = '%s', " + "b_format_args = '%s', num_format_args = %d, " + "text_domain = '%s', text_dir = '%s', " + "time = %d, insert_time = %d, " + "args = '%s', group_args = '%s', " + "b_execute_option = '%s', " + "b_service_responding = '%s', " + "b_service_single_launch = '%s', " + "b_service_multi_launch = '%s', " + "sound_type = %d, sound_path = '%s', " + "vibration_type = %d, vibration_path = '%s', " + "flags_for_property = %d, flag_simmode = %d, " + "display_applist = %d, " + "progress_size = %f, progress_percentage = %f " + "where priv_id = %d ", + noti->type, + noti->layout, + NOTIFICATION_CHECK_STR(noti->launch_pkgname), + NOTIFICATION_CHECK_STR(b_image_path), + NOTIFICATION_CHECK_STR(b_text), NOTIFICATION_CHECK_STR(b_key), + NOTIFICATION_CHECK_STR(b_format_args), noti->num_format_args, + NOTIFICATION_CHECK_STR(noti->domain), + NOTIFICATION_CHECK_STR(noti->dir), + (int)noti->time, (int)noti->insert_time, + NOTIFICATION_CHECK_STR(args), NOTIFICATION_CHECK_STR(group_args), + NOTIFICATION_CHECK_STR(b_execute_option), + NOTIFICATION_CHECK_STR(b_service_responding), + NOTIFICATION_CHECK_STR(b_service_single_launch), + NOTIFICATION_CHECK_STR(b_service_multi_launch), + noti->sound_type, NOTIFICATION_CHECK_STR(noti->sound_path), + noti->vibration_type, + NOTIFICATION_CHECK_STR(noti->vibration_path), + noti->flags_for_property, flag_simmode, noti->display_applist, + noti->progress_size, noti->progress_percentage, + noti->priv_id); + + /* Free decoded data */ + if (args) { + free(args); + } + if (group_args) { + free(group_args); + } + + if (b_execute_option) { + free(b_execute_option); + } + if (b_service_responding) { + free(b_service_responding); + } + if (b_service_single_launch) { + free(b_service_single_launch); + } + if (b_service_multi_launch) { + free(b_service_multi_launch); + } + + if (b_text) { + free(b_text); + } + if (b_key) { + free(b_key); + } + if (b_format_args) { + free(b_format_args); + } + + if (b_image_path) { + free(b_image_path); + } + + return NOTIFICATION_ERROR_NONE; +} + +static void _notification_noti_populate_from_stmt(sqlite3_stmt * stmt, notification_h noti) { + int col = 0; + + if (stmt == NULL || noti == NULL) { + return ; + } + + 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++); + noti->b_image_path = notification_db_column_bundle(stmt, col++); + noti->group_id = sqlite3_column_int(stmt, col++); + noti->internal_group_id = 0; + noti->priv_id = sqlite3_column_int(stmt, col++); + + noti->b_text = notification_db_column_bundle(stmt, col++); + noti->b_key = notification_db_column_bundle(stmt, col++); + 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++); + noti->time = sqlite3_column_int(stmt, col++); + noti->insert_time = sqlite3_column_int(stmt, col++); + noti->args = notification_db_column_bundle(stmt, col++); + noti->group_args = notification_db_column_bundle(stmt, col++); + + noti->b_execute_option = notification_db_column_bundle(stmt, col++); + noti->b_service_responding = notification_db_column_bundle(stmt, col++); + noti->b_service_single_launch = + notification_db_column_bundle(stmt, col++); + noti->b_service_multi_launch = + notification_db_column_bundle(stmt, col++); + + noti->sound_type = sqlite3_column_int(stmt, col++); + 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++); + + noti->flags_for_property = sqlite3_column_int(stmt, col++); + noti->display_applist = sqlite3_column_int(stmt, col++); + noti->progress_size = sqlite3_column_double(stmt, col++); + noti->progress_percentage = sqlite3_column_double(stmt, col++); + + noti->app_icon_path = NULL; + noti->app_name = NULL; + noti->temp_title = NULL; + noti->temp_content = NULL; +} + +static notification_h _notification_noti_get_item(sqlite3_stmt * stmt) +{ + notification_h noti = NULL; + + noti = malloc(sizeof(struct _notification)); + if (noti == NULL) { + return NULL; + } + + _notification_noti_populate_from_stmt(stmt, noti); + + return noti; +} + +int notification_noti_set_tag(const char *tag, char *value, char *buf, int buf_len) +{ + int len_total = 0; + + len_total += (strlen(tag) * 2) + 5 + strlen(value) + 1; + + if (buf_len <= len_total) + return NOTIFICATION_ERROR_INVALID_DATA; + + snprintf(buf, buf_len, "<%s>%s</%s>", tag, value, tag); + + return NOTIFICATION_ERROR_NONE; +} + +char *notification_noti_strip_tag(const char *tagged_str) +{ + if (tagged_str == NULL) + return NULL; + + int len_total = strlen(tagged_str); + + if (len_total == 0) + return NULL; + + char *b_f_e = strstr(tagged_str, ">"); + char *b_e_s = strstr(tagged_str, "</"); + + if (b_f_e == NULL || b_e_s == NULL || (b_e_s - b_f_e - 1) <= 0) + return NULL; + + return strndup(b_f_e + 1, b_e_s - b_f_e - 1); +} + +int notification_noti_get_tag_type(const char *tagged_str) +{ + if (tagged_str == NULL) + return TAG_TYPE_INVALID; + + if (strlen(tagged_str)== 0) + return TAG_TYPE_INVALID; + + char *b_f_s = strstr(tagged_str, "<"); + char *b_f_e = strstr(tagged_str, ">"); + + if (b_f_s == NULL || b_f_e == NULL || (b_f_e - b_f_s - 1) <= 0) + return TAG_TYPE_INVALID; + + char *start = b_f_s + 1; + int len_tag = b_f_e - b_f_s - 1; + + if (strncmp(start,TAG_TIME,len_tag) == 0) { + return TAG_TYPE_TIME; + } + + return TAG_TYPE_INVALID; +} + +static int _notification_noti_update_priv_id(sqlite3 * db, int rowid) +{ + char query[128] = { 0, }; + + if (db == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + snprintf(query, sizeof(query), "update noti_list set " + "priv_id = %d, internal_group_id = %d where rowid = %d", + rowid, rowid, rowid); + + return notification_db_exec(db, query); +} + +int notification_noti_insert(notification_h noti) +{ + sqlite3 *db = NULL; + sqlite3_stmt *stmt = NULL; + char query[NOTIFICATION_QUERY_MAX] = { 0, }; + int ret = 0; + char buf_key[32] = { 0, }; + const char *title_key = NULL; + + /* Open DB */ + db = notification_db_open(DBPATH); + + /* Initialize private ID */ + noti->priv_id = NOTIFICATION_PRIV_ID_NONE; + noti->group_id = NOTIFICATION_GROUP_ID_NONE; + noti->internal_group_id = NOTIFICATION_GROUP_ID_NONE; + + /* make query */ + ret = _notification_noti_make_query(noti, query, sizeof(query)); + if (ret != NOTIFICATION_ERROR_NONE) { + goto err; + } + + ret = sqlite3_prepare_v2(db, query, -1, &stmt, NULL); + if (ret != SQLITE_OK) { + NOTIFICATION_ERR("Insert Query : %s", query); + NOTIFICATION_ERR("Insert DB error(%d) : %s", ret, + sqlite3_errmsg(db)); + ret = NOTIFICATION_ERROR_FROM_DB; + goto err; + } + + /* Get title key */ + if (noti->b_key != NULL) { + snprintf(buf_key, sizeof(buf_key), "%d", + NOTIFICATION_TEXT_TYPE_TITLE); + + title_key = bundle_get_val(noti->b_key, buf_key); + } + + if (title_key == NULL && noti->b_text != NULL) { + snprintf(buf_key, sizeof(buf_key), "%d", + NOTIFICATION_TEXT_TYPE_TITLE); + + title_key = bundle_get_val(noti->b_text, buf_key); + } + + if (title_key == NULL) { + title_key = noti->caller_pkgname; + } + + /* Bind query */ + ret = _notification_noti_bind_query(stmt, "$title_key", title_key); + if (ret != NOTIFICATION_ERROR_NONE) { + NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db)); + goto err; + } + + ret = sqlite3_step(stmt); + if (ret == SQLITE_OK || ret == SQLITE_DONE) { + noti->priv_id = (int)sqlite3_last_insert_rowid(db); + if (_notification_noti_update_priv_id(db, noti->priv_id) == 0) { + ret = NOTIFICATION_ERROR_NONE; + } else { + ret = NOTIFICATION_ERROR_FROM_DB; + } + } else { + ret = NOTIFICATION_ERROR_FROM_DB; + } +err: + if (stmt) { + sqlite3_finalize(stmt); + } + + /* Close DB */ + if (db) { + notification_db_close(&db); + } + + return ret; +} + +int notification_noti_get_by_priv_id(notification_h noti, char *pkgname, int priv_id) +{ + sqlite3 *db = NULL; + sqlite3_stmt *stmt = NULL; + char query[NOTIFICATION_QUERY_MAX] = { 0, }; + int ret = 0; + + if (priv_id < 0 || noti == NULL) { + ret = NOTIFICATION_ERROR_INVALID_DATA; + goto err; + } + + /* Open DB */ + db = notification_db_open(DBPATH); + + char *base_query = "select " + "type, layout, caller_pkgname, launch_pkgname, image_path, group_id, priv_id, " + "b_text, b_key, b_format_args, num_format_args, " + "text_domain, text_dir, time, insert_time, args, group_args, " + "b_execute_option, b_service_responding, b_service_single_launch, b_service_multi_launch, " + "sound_type, sound_path, vibration_type, vibration_path, " + "flags_for_property, display_applist, progress_size, progress_percentage " + "from noti_list "; + + if (pkgname != NULL) { + snprintf(query, sizeof(query), "%s where caller_pkgname = '%s' and priv_id = %d", + base_query ,pkgname, priv_id); + } else { + snprintf(query, sizeof(query), "%s where priv_id = %d", base_query, priv_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)); + ret = NOTIFICATION_ERROR_FROM_DB; + goto err; + } + + ret = sqlite3_step(stmt); + if (ret == SQLITE_ROW) { + _notification_noti_populate_from_stmt(stmt, noti); + ret = NOTIFICATION_ERROR_NONE; + } else { + ret = NOTIFICATION_ERROR_FROM_DB; + } +err: + if (stmt) { + sqlite3_finalize(stmt); + } + + /* Close DB */ + if (db != NULL) { + notification_db_close(&db); + } + + return ret; +} + +int notification_noti_update(notification_h noti) +{ + sqlite3 *db; + sqlite3_stmt *stmt = NULL; + char query[NOTIFICATION_QUERY_MAX] = { 0, }; + int ret = 0; + + /* Open DB */ + db = notification_db_open(DBPATH); + + /* Check private ID is exist */ + ret = _notification_noti_check_priv_id(noti, db); + if (ret != NOTIFICATION_ERROR_ALREADY_EXIST_ID) { + ret = NOTIFICATION_ERROR_NOT_EXIST_ID; + goto err; + } + + /* make update query */ + ret = _notification_noti_make_update_query(noti, query, sizeof(query)); + if (ret != NOTIFICATION_ERROR_NONE) { + goto err; + } + + ret = sqlite3_prepare_v2(db, query, -1, &stmt, NULL); + if (ret != SQLITE_OK) { + NOTIFICATION_ERR("Insert Query : %s", query); + NOTIFICATION_ERR("Insert DB error(%d) : %s", ret, + sqlite3_errmsg(db)); + ret = NOTIFICATION_ERROR_FROM_DB; + goto err; + } + + ret = sqlite3_step(stmt); + if (ret == SQLITE_OK || ret == SQLITE_DONE) { + ret = NOTIFICATION_ERROR_NONE; + } else { + ret = NOTIFICATION_ERROR_FROM_DB; + } +err: + if (stmt) { + sqlite3_finalize(stmt); + } + + /* Close DB */ + if (db) { + notification_db_close(&db); + } + + return ret; +} + +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 i = 0, data_cnt = 0; + sqlite3 *db = NULL; + sqlite3_stmt *stmt = NULL; + char buf[128] = { 0, }; + char query[NOTIFICATION_QUERY_MAX] = { 0, }; + char query_base[NOTIFICATION_QUERY_MAX] = { 0, }; + char query_where[NOTIFICATION_QUERY_MAX] = { 0, }; + + /* Open DB */ + db = notification_db_open(DBPATH); + + if (pkgname == NULL) { + if (type != NOTIFICATION_TYPE_NONE) { + snprintf(query_where, sizeof(query_where), + "where type = %d ", type); + } + } else { + if (type == NOTIFICATION_TYPE_NONE) { + snprintf(query_where, sizeof(query_where), + "where caller_pkgname = '%s' ", pkgname); + } else { + snprintf(query_where, sizeof(query_where), + "where caller_pkgname = '%s' and type = %d ", + pkgname, type); + } + } + + if (list_deleted_rowid != NULL) { + *list_deleted_rowid = NULL; + snprintf(query, sizeof(query), + "select priv_id from noti_list %s ", query_where); + + ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL); + if (ret != SQLITE_OK) { + NOTIFICATION_ERR("Select Query : %s", query); + NOTIFICATION_ERR("Select DB error(%d) : %s", ret, + sqlite3_errmsg(db)); + + ret = NOTIFICATION_ERROR_FROM_DB; + goto err; + } + + while(sqlite3_step(stmt) == SQLITE_ROW) { + if (data_cnt % 8 == 0) { + *list_deleted_rowid = + (int *)realloc(*list_deleted_rowid, sizeof(int) * (data_cnt + 8 + 1)); + } + *((*list_deleted_rowid) + data_cnt) = sqlite3_column_int(stmt, 0); + data_cnt++; + } + + if (stmt) { + sqlite3_finalize(stmt); + stmt = NULL; + } + + if (data_cnt > 0) { + query_where[0] = '\0'; + for (i = 0; i < data_cnt ; i++) { + snprintf(buf, sizeof(buf), "%s%d", (i == 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); + notification_db_exec(db, query); + } else { + free(*list_deleted_rowid); + *list_deleted_rowid = NULL; + } + + if (num_deleted != NULL) { + *num_deleted = data_cnt; + } + } else { + /* Make main query */ + snprintf(query_base, sizeof(query_base), "delete from noti_list "); + snprintf(query, sizeof(query), "%s %s", query_base, query_where); + + notification_db_exec(db, query); + + if (num_deleted != NULL) { + *num_deleted = sqlite3_changes(db); + } + } + +err: + if (stmt) { + sqlite3_finalize(stmt); + } + /* Close DB */ + if (db) { + notification_db_close(&db); + } + + return ret; +} + +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; + sqlite3 *db = NULL; + int i = 0, data_cnt = 0; + sqlite3_stmt *stmt = NULL; + char buf[128] = { 0, }; + char query[NOTIFICATION_QUERY_MAX] = { 0, }; + char query_base[NOTIFICATION_QUERY_MAX] = { 0, }; + char query_where[NOTIFICATION_QUERY_MAX] = { 0, }; + + /* Check pkgname is valid */ + if (pkgname == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + snprintf(query_where, sizeof(query_where), + "where caller_pkgname = '%s' and group_id = %d", pkgname, group_id); + + /* Open DB */ + db = notification_db_open(DBPATH); + + if (list_deleted_rowid != NULL) { + *list_deleted_rowid = NULL; + snprintf(query, sizeof(query), + "select priv_id from noti_list %s ", query_where); + + ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL); + if (ret != SQLITE_OK) { + NOTIFICATION_ERR("Select Query : %s", query); + NOTIFICATION_ERR("Select DB error(%d) : %s", ret, + sqlite3_errmsg(db)); + + ret = NOTIFICATION_ERROR_FROM_DB; + goto err; + } + + while(sqlite3_step(stmt) == SQLITE_ROW) { + if (data_cnt % 8 == 0) { + *list_deleted_rowid = + (int *)realloc(*list_deleted_rowid, sizeof(int) * (data_cnt + 8 + 1)); + } + *((*list_deleted_rowid) + data_cnt) = sqlite3_column_int(stmt, 0); + data_cnt++; + } + + if (stmt) { + sqlite3_finalize(stmt); + stmt = NULL; + } + + if (data_cnt > 0) { + query_where[0] = '\0'; + for (i = 0; i < data_cnt ; i++) { + snprintf(buf, sizeof(buf), "%s%d", (i == 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); + notification_db_exec(db, query); + } else { + free(*list_deleted_rowid); + *list_deleted_rowid = NULL; + } + + if (num_deleted != NULL) { + *num_deleted = data_cnt; + } + } else { + /* Make query */ + snprintf(query, sizeof(query), "delete from noti_list %s", query_where); + + /* execute DB */ + notification_db_exec(db, query); + + return NOTIFICATION_ERROR_NONE; + } + +err: + if (stmt) { + sqlite3_finalize(stmt); + } + /* Close DB */ + if (db) { + notification_db_close(&db); + } + + return ret; +} + +int notification_noti_delete_group_by_priv_id(const char *pkgname, int priv_id) +{ + sqlite3 *db = NULL; + char query[NOTIFICATION_QUERY_MAX] = { 0, }; + int internal_group_id = 0; + + /* Check pkgname is valid */ + if (pkgname == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + /* Open DB */ + db = notification_db_open(DBPATH); + + /* Get internal group id using priv id */ + internal_group_id = + _notification_noti_get_internal_group_id_by_priv_id(pkgname, + priv_id, db); + + /* Make query */ + snprintf(query, sizeof(query), "delete from noti_list " + "where caller_pkgname = '%s' and internal_group_id = %d", + pkgname, internal_group_id); + + /* execute DB */ + notification_db_exec(db, query); + + /* Close DB */ + if (db) { + notification_db_close(&db); + } + + return NOTIFICATION_ERROR_NONE; +} + +int notification_noti_delete_by_priv_id(const char *pkgname, int priv_id) +{ + sqlite3 *db = NULL; + char query[NOTIFICATION_QUERY_MAX] = { 0, }; + + /* Check pkgname is valid */ + if (pkgname == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + /* Open DB */ + db = notification_db_open(DBPATH); + + /* Make query */ + snprintf(query, sizeof(query), "delete from noti_list " + "where caller_pkgname = '%s' and priv_id = %d", pkgname, + priv_id); + + /* execute DB */ + notification_db_exec(db, query); + + /* Close DB */ + if (db) { + notification_db_close(&db); + } + + return NOTIFICATION_ERROR_NONE; +} + +notification_error_e notification_noti_get_count(notification_type_e type, + const char *pkgname, + int group_id, int priv_id, + int *count) +{ + sqlite3 *db = NULL; + sqlite3_stmt *stmt = NULL; + char query[NOTIFICATION_QUERY_MAX] = { 0, }; + char query_base[NOTIFICATION_QUERY_MAX] = { 0, }; + char query_where[NOTIFICATION_QUERY_MAX] = { 0, }; + char query_where_more[NOTIFICATION_QUERY_MAX] = { 0, }; + + int ret = 0, get_count = 0, internal_group_id = 0; + int status = VCONFKEY_TELEPHONY_SIM_UNKNOWN; + int flag_where = 0; + int flag_where_more = 0; + int ret_vconf = 0; + + /* Open DB */ + db = notification_db_open(DBPATH); + + /* Check current sim status */ + ret_vconf = vconf_get_int(VCONFKEY_TELEPHONY_SIM_SLOT, &status); + + /* Make query */ + snprintf(query_base, sizeof(query_base), + "select count(*) from noti_list "); + + if (pkgname != NULL) { + if (group_id == NOTIFICATION_GROUP_ID_NONE) { + if (priv_id == NOTIFICATION_PRIV_ID_NONE) { + snprintf(query_where, sizeof(query_where), + "where caller_pkgname = '%s' ", + pkgname); + flag_where = 1; + } else { + internal_group_id = + _notification_noti_get_internal_group_id_by_priv_id + (pkgname, priv_id, db); + snprintf(query_where, sizeof(query_where), + "where caller_pkgname = '%s' and internal_group_id = %d ", + pkgname, internal_group_id); + flag_where = 1; + } + } else { + if (priv_id == NOTIFICATION_PRIV_ID_NONE) { + snprintf(query_where, sizeof(query_where), + "where caller_pkgname = '%s' and group_id = %d ", + pkgname, group_id); + flag_where = 1; + } else { + internal_group_id = + _notification_noti_get_internal_group_id_by_priv_id + (pkgname, priv_id, db); + snprintf(query_where, sizeof(query_where), + "where caller_pkgname = '%s' and internal_group_id = %d ", + pkgname, internal_group_id); + flag_where = 1; + } + } + + } + + if (ret_vconf == 0 && status == VCONFKEY_TELEPHONY_SIM_INSERTED) { + if (type != NOTIFICATION_TYPE_NONE) { + snprintf(query_where_more, sizeof(query_where_more), + "type = %d ", type); + flag_where_more = 1; + } + } else { + if (type != NOTIFICATION_TYPE_NONE) { + snprintf(query_where_more, sizeof(query_where_more), + "type = %d and flag_simmode = 0 ", type); + flag_where_more = 1; + } else { + snprintf(query_where_more, sizeof(query_where_more), + "flag_simmode = 0 "); + flag_where_more = 1; + } + } + + if (flag_where == 1) { + if (flag_where_more == 1) { + snprintf(query, sizeof(query), "%s %s and %s", + query_base, query_where, query_where_more); + } else { + snprintf(query, sizeof(query), "%s %s", query_base, + query_where); + } + + } else { + if (flag_where_more == 1) { + snprintf(query, sizeof(query), "%s where %s", + query_base, query_where_more); + } else { + snprintf(query, sizeof(query), "%s", query_base); + } + } + + ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL); + if (ret != SQLITE_OK) { + NOTIFICATION_ERR("Select Query : %s", query); + NOTIFICATION_ERR("Select DB error(%d) : %s", ret, + sqlite3_errmsg(db)); + + ret = NOTIFICATION_ERROR_FROM_DB; + goto err; + } + + ret = sqlite3_step(stmt); + if (ret == SQLITE_ROW) { + get_count = sqlite3_column_int(stmt, 0); + } + + ret = NOTIFICATION_ERROR_NONE; + +err: + if (stmt) { + sqlite3_finalize(stmt); + } + + /* Close DB */ + if (db) { + notification_db_close(&db); + } + + *count = get_count; + + return ret; +} + +notification_error_e notification_noti_get_grouping_list(notification_type_e type, + int count, + notification_list_h * + list) +{ + sqlite3 *db = NULL; + sqlite3_stmt *stmt = NULL; + char query[NOTIFICATION_QUERY_MAX] = { 0, }; + char query_base[NOTIFICATION_QUERY_MAX] = { 0, }; + char query_where[NOTIFICATION_QUERY_MAX] = { 0, }; + + int ret = 0; + notification_list_h get_list = NULL; + notification_h noti = NULL; + int internal_count = 0; + int status; + + /* Open DB */ + db = notification_db_open(DBPATH); + + /* Check current sim status */ + ret = vconf_get_int(VCONFKEY_TELEPHONY_SIM_SLOT, &status); + + /* Make query */ + snprintf(query_base, sizeof(query_base), "select " + "type, layout, caller_pkgname, launch_pkgname, image_path, group_id, priv_id, " + "b_text, b_key, b_format_args, num_format_args, " + "text_domain, text_dir, time, insert_time, args, group_args, " + "b_execute_option, b_service_responding, b_service_single_launch, b_service_multi_launch, " + "sound_type, sound_path, vibration_type, vibration_path, " + "flags_for_property, display_applist, progress_size, progress_percentage " + "from noti_list "); + + if (status == VCONFKEY_TELEPHONY_SIM_INSERTED) { + if (type != NOTIFICATION_TYPE_NONE) { + snprintf(query_where, sizeof(query_where), + "where type = %d ", type); + } + } else { + if (type != NOTIFICATION_TYPE_NONE) { + snprintf(query_where, sizeof(query_where), + "where type = %d and flag_simmode = 0 ", type); + } else { + snprintf(query_where, sizeof(query_where), + "where flag_simmode = 0 "); + } + } + + snprintf(query, sizeof(query), + "%s %s " + "group by internal_group_id " + "order by rowid desc, time desc", query_base, query_where); + + ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL); + if (ret != SQLITE_OK) { + NOTIFICATION_ERR("Select Query : %s", query); + NOTIFICATION_ERR("Select DB error(%d) : %s", ret, + sqlite3_errmsg(db)); + + ret = NOTIFICATION_ERROR_FROM_DB; + goto err; + } + + ret = sqlite3_step(stmt); + while (ret == SQLITE_ROW) { + /* Make notification list */ + noti = _notification_noti_get_item(stmt); + if (noti != NULL) { + internal_count++; + + get_list = notification_list_append(get_list, noti); + + if (count != -1 && internal_count >= count) { + NOTIFICATION_INFO + ("internal count %d >= count %d", + internal_count, count); + break; + } + } + + ret = sqlite3_step(stmt); + } + + ret = NOTIFICATION_ERROR_NONE; + +err: + if (stmt) { + sqlite3_finalize(stmt); + } + + /* Close DB */ + if (db) { + notification_db_close(&db); + } + + if (get_list != NULL) { + *list = notification_list_get_head(get_list); + } + + return ret; +} + +notification_error_e notification_noti_get_detail_list(const char *pkgname, + int group_id, + int priv_id, int count, + notification_list_h *list) +{ + sqlite3 *db = NULL; + sqlite3_stmt *stmt = NULL; + char query_base[NOTIFICATION_QUERY_MAX] = { 0, }; + char query_where[NOTIFICATION_QUERY_MAX] = { 0, }; + + char query[NOTIFICATION_QUERY_MAX] = { 0, }; + int ret = 0; + notification_list_h get_list = NULL; + notification_h noti = NULL; + int internal_count = 0; + int internal_group_id = 0; + int status; + + /* Open DB */ + db = notification_db_open(DBPATH); + + /* Check current sim status */ + ret = vconf_get_int(VCONFKEY_TELEPHONY_SIM_SLOT, &status); + + /* Make query */ + snprintf(query_base, sizeof(query_base), "select " + "type, layout, caller_pkgname, launch_pkgname, image_path, group_id, priv_id, " + "b_text, b_key, b_format_args, num_format_args, " + "text_domain, text_dir, time, insert_time, args, group_args, " + "b_execute_option, b_service_responding, b_service_single_launch, b_service_multi_launch, " + "sound_type, sound_path, vibration_type, vibration_path, " + "flags_for_property, display_applist, progress_size, progress_percentage " + "from noti_list "); + + internal_group_id = + _notification_noti_get_internal_group_id_by_priv_id(pkgname, + priv_id, db); + + if (status == VCONFKEY_TELEPHONY_SIM_INSERTED) { + snprintf(query_where, sizeof(query_where), + "where caller_pkgname = '%s' and internal_group_id = %d ", + pkgname, internal_group_id); + } else { + snprintf(query_where, sizeof(query_where), + "where caller_pkgname = '%s' and internal_group_id = %d and flag_simmode = 0 ", + pkgname, internal_group_id); + } + + snprintf(query, sizeof(query), + "%s %s " + "order by rowid desc, time desc", query_base, query_where); + + ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL); + if (ret != SQLITE_OK) { + NOTIFICATION_ERR("Select Query : %s", query); + NOTIFICATION_ERR("Select DB error(%d) : %s", ret, + sqlite3_errmsg(db)); + + ret = NOTIFICATION_ERROR_FROM_DB; + goto err; + } + + ret = sqlite3_step(stmt); + while (ret == SQLITE_ROW) { + /* Make notification list */ + noti = _notification_noti_get_item(stmt); + if (noti != NULL) { + internal_count++; + + get_list = notification_list_append(get_list, noti); + + if (count != -1 && internal_count >= count) { + NOTIFICATION_INFO + ("internal count %d >= count %d", + internal_count, count); + break; + } + } + + ret = sqlite3_step(stmt); + } + + ret = NOTIFICATION_ERROR_NONE; + +err: + if (stmt) { + sqlite3_finalize(stmt); + } + + /* Close DB */ + if (db) { + notification_db_close(&db); + } + + if (get_list != NULL) { + *list = notification_list_get_head(get_list); + } + + return ret; +} diff --git a/src/notification_ongoing.c b/src/notification_ongoing.c new file mode 100755 index 0000000..f248bc1 --- /dev/null +++ b/src/notification_ongoing.c @@ -0,0 +1,184 @@ +/* + * 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>, Youngsub Ko <ys4610.ko@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 <dbus/dbus.h> + +#include <notification_db.h> +#include <notification_debug.h> +#include <notification_ongoing.h> +#include <notification_internal.h> + +notification_error_e notification_ongoing_update_progress(const char *caller_pkgname, + int priv_id, + double progress) +{ + DBusConnection *connection = NULL; + DBusMessage *signal = NULL; + DBusError err; + dbus_bool_t ret; + + dbus_error_init(&err); + connection = dbus_bus_get(DBUS_BUS_SYSTEM, &err); + if (!connection) { + NOTIFICATION_ERR("Fail to dbus_bus_get"); + return NOTIFICATION_ERROR_FROM_DBUS; + } + + signal = + dbus_message_new_signal("/dbus/signal", "notification.ongoing", + "update_progress"); + if (!signal) { + NOTIFICATION_ERR("Fail to dbus_message_new_signal"); + return NOTIFICATION_ERROR_FROM_DBUS; + } + + ret = dbus_message_append_args(signal, + DBUS_TYPE_STRING, &caller_pkgname, + DBUS_TYPE_INT32, &priv_id, + DBUS_TYPE_DOUBLE, &progress, + DBUS_TYPE_INVALID); + + if (ret) { + ret = dbus_connection_send(connection, signal, NULL); + if (ret) { + dbus_connection_flush(connection); + } + } + + dbus_message_unref(signal); + + if (ret) { + NOTIFICATION_INFO("Send progress info : %s(%d) %.2f", + caller_pkgname, priv_id, progress); + return NOTIFICATION_ERROR_NONE; + } + + return NOTIFICATION_ERROR_FROM_DBUS; +} + +notification_error_e notification_ongoing_update_size(const char *caller_pkgname, + int priv_id, double size) +{ + DBusConnection *connection = NULL; + DBusMessage *signal = NULL; + DBusError err; + dbus_bool_t ret; + + dbus_error_init(&err); + connection = dbus_bus_get(DBUS_BUS_SYSTEM, &err); + if (!connection) { + NOTIFICATION_ERR("Fail to dbus_bus_get"); + return NOTIFICATION_ERROR_FROM_DBUS; + } + + signal = + dbus_message_new_signal("/dbus/signal", "notification.ongoing", + "update_size"); + if (!signal) { + NOTIFICATION_ERR("Fail to dbus_message_new_signal"); + return NOTIFICATION_ERROR_FROM_DBUS; + } + + ret = dbus_message_append_args(signal, + DBUS_TYPE_STRING, &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); + } + } + + dbus_message_unref(signal); + + if (ret) { + NOTIFICATION_INFO("Send size info : %s(%d) %.2f", + caller_pkgname, priv_id, size); + return NOTIFICATION_ERROR_NONE; + } + + return NOTIFICATION_ERROR_FROM_DBUS; +} + +notification_error_e notification_ongoing_update_content(const char *caller_pkgname, + int priv_id, const char *content) +{ + DBusConnection *connection = NULL; + DBusMessage *signal = NULL; + DBusError err; + dbus_bool_t ret; + + dbus_error_init(&err); + connection = dbus_bus_get(DBUS_BUS_SYSTEM, &err); + if (!connection) { + NOTIFICATION_ERR("Fail to dbus_bus_get"); + return NOTIFICATION_ERROR_FROM_DBUS; + } + + signal = + dbus_message_new_signal("/dbus/signal", "notification.ongoing", + "update_content"); + if (!signal) { + NOTIFICATION_ERR("Fail to dbus_message_new_signal"); + return NOTIFICATION_ERROR_FROM_DBUS; + } + + if(content == NULL) { + ret = dbus_message_append_args(signal, + DBUS_TYPE_STRING, &caller_pkgname, + DBUS_TYPE_INT32, &priv_id, + DBUS_TYPE_INVALID); + } else { + ret = dbus_message_append_args(signal, + DBUS_TYPE_STRING, &caller_pkgname, + DBUS_TYPE_INT32, &priv_id, + DBUS_TYPE_STRING, &content, + DBUS_TYPE_INVALID); + } + 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); + } + } + + dbus_message_unref(signal); + + if (ret) { + return NOTIFICATION_ERROR_NONE; + } + + return NOTIFICATION_ERROR_FROM_DBUS; +} + diff --git a/src/notification_status.c b/src/notification_status.c new file mode 100755 index 0000000..734d30d --- /dev/null +++ b/src/notification_status.c @@ -0,0 +1,135 @@ +/* + * 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 <sys/types.h> +#include <unistd.h> +#include <stdio.h> +#include <string.h> +#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 + +#define NOTIFICATION_STATUS_MESSAGE_KEY "memory/private/libstatus/message" + +struct _message_cb_data { + notification_status_message_cb callback; + void *data; +}; + +static struct _message_cb_data md; + +static void __notification_status_message_change_cb(keynode_t *node, void *user_data) +{ + int type; + char *message = NULL; + + if (!node) { + NOTIFICATION_ERR("key node is NULL"); + return; + } + + if (!md.callback) + return; + + type = vconf_keynode_get_type(node); + if (type != VCONF_TYPE_STRING) { + NOTIFICATION_ERR("invail node type : %d", type); + return; + } + + message = vconf_keynode_get_str(node); + if (!message) { + NOTIFICATION_ERR("fail to get message"); + return; + } + + if (strlen(message) <= 0){ + NOTIFICATION_DBG("message has only NULL"); + return; + } + + NOTIFICATION_DBG("message : %s", message); + md.callback(message, md.data); +} + +EXPORT_API +int notification_status_message_post(const char *message) +{ + int ret = 0; + + if (!message) { + NOTIFICATION_ERR("message is NULL"); + return NOTIFICATION_ERROR_INVALID_DATA; + } + + if (strlen(message) <= 0) { + NOTIFICATION_ERR("message has only NULL"); + return NOTIFICATION_ERROR_INVALID_DATA; + } + + + ret = vconf_set_str(NOTIFICATION_STATUS_MESSAGE_KEY, message); + if (ret) { + NOTIFICATION_ERR("fail to set message [%s]", message); + return NOTIFICATION_ERROR_IO; + } + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API +int notification_status_monitor_message_cb_set(notification_status_message_cb callback, void *user_data) +{ + int ret = 0; + if (!callback) + return NOTIFICATION_ERROR_INVALID_DATA; + + ret = vconf_notify_key_changed(NOTIFICATION_STATUS_MESSAGE_KEY, + __notification_status_message_change_cb, NULL); + if (ret && errno != EALREADY) { + NOTIFICATION_ERR("fail to set message cb"); + return NOTIFICATION_ERROR_IO; + } + + md.callback = callback; + md.data = user_data; + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API +int notification_status_monitor_message_cb_unset(void) +{ + vconf_ignore_key_changed(NOTIFICATION_STATUS_MESSAGE_KEY, + __notification_status_message_change_cb); + md.callback = NULL; + md.data = NULL; + + return NOTIFICATION_ERROR_NONE; +} |