4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Seungtaek Chung <seungtaek.chung@samsung.com>, Mi-Ju Lee <miju52.lee@samsung.com>, Xi Zhichan <zhichan.xi@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
28 #include <Elementary.h>
30 #include <package_manager.h>
32 #include <notification.h>
33 #include <notification_db.h>
34 #include <notification_list.h>
35 #include <notification_noti.h>
36 #include <notification_debug.h>
37 #include <notification_private.h>
38 #include <notification_setting.h>
39 #include <notification_setting_internal.h>
41 #define NOTI_BURST_DELETE_UNIT 10
43 static void __free_and_set(void **target_ptr, void *new_ptr) {
44 if (target_ptr != NULL) {
45 if (*target_ptr != NULL) {
48 *target_ptr = new_ptr;
52 static int _notification_noti_bind_query_text(sqlite3_stmt * stmt, const char *name,
58 index = sqlite3_bind_parameter_index(stmt, name);
60 NOTIFICATION_ERR("Insert : invalid column name");
61 return NOTIFICATION_ERROR_FROM_DB;
65 sqlite3_bind_text(stmt, index, NOTIFICATION_CHECK_STR(str), -1,
67 if (ret != SQLITE_OK) {
68 NOTIFICATION_ERR("Insert text : %s",
69 NOTIFICATION_CHECK_STR(str));
70 return NOTIFICATION_ERROR_FROM_DB;
73 return NOTIFICATION_ERROR_NONE;
76 static int _notification_noti_bind_query_double(sqlite3_stmt * stmt, const char *name,
82 index = sqlite3_bind_parameter_index(stmt, name);
84 NOTIFICATION_ERR("Insert : invalid column name");
85 return NOTIFICATION_ERROR_FROM_DB;
88 ret = sqlite3_bind_double(stmt, index, val);
89 if (ret != SQLITE_OK) {
90 NOTIFICATION_ERR("Insert double : %f", val);
91 return NOTIFICATION_ERROR_FROM_DB;
94 return NOTIFICATION_ERROR_NONE;
97 static int _notification_noti_check_priv_id(notification_h noti, sqlite3 * db)
100 int ret = NOTIFICATION_ERROR_NONE;
102 sqlite3_stmt *stmt = NULL;
104 /* Make query to check priv_id exist */
105 query = sqlite3_mprintf("SELECT count(*) FROM noti_list WHERE caller_pkgname = '%s' AND priv_id = %d",
106 noti->caller_pkgname, noti->priv_id);
108 ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
112 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
113 if (ret != SQLITE_OK) {
114 NOTIFICATION_ERR("Get count DB err(%d) : %s", ret,
116 ret = NOTIFICATION_ERROR_FROM_DB;
120 ret = sqlite3_step(stmt);
121 if (ret == SQLITE_ROW) {
122 result = sqlite3_column_int(stmt, 0);
127 sqlite3_finalize(stmt);
129 /* If result > 0, there is priv_id in DB */
131 ret = NOTIFICATION_ERROR_ALREADY_EXIST_ID;
142 static int _notification_noti_get_internal_group_id_by_priv_id(const char *pkgname,
147 sqlite3_stmt *stmt = NULL;
148 int ret = NOTIFICATION_ERROR_NONE, result = 0;
150 query = sqlite3_mprintf("SELECT internal_group_id FROM noti_list WHERE caller_pkgname = '%s' AND priv_id = %d",
153 ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
157 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
158 if (ret != SQLITE_OK) {
159 NOTIFICATION_ERR("Get count DB err(%d) : %s", ret,
161 ret = NOTIFICATION_ERROR_FROM_DB;
165 ret = sqlite3_step(stmt);
166 if (ret == SQLITE_ROW) {
167 result = sqlite3_column_int(stmt, 0);
174 sqlite3_finalize(stmt);
181 if (ret != NOTIFICATION_ERROR_NONE) {
182 NOTIFICATION_ERR("failed to internal group ID:%d", ret);
188 static int _insertion_query_create(notification_h noti, char **query)
191 int b_encode_len = 0;
193 char *group_args = NULL;
194 char *b_image_path = NULL;
195 char *b_execute_option = NULL;
196 char *b_service_responding = NULL;
197 char *b_service_single_launch = NULL;
198 char *b_service_multi_launch = NULL;
199 char *b_event_handler[NOTIFICATION_EVENT_TYPE_MAX] = { NULL , };
202 char *b_format_args = NULL;
203 int flag_simmode = 0;
206 return NOTIFICATION_ERROR_INVALID_PARAMETER;
209 /* Decode bundle to insert DB */
211 bundle_encode(noti->args, (bundle_raw **) & args, &b_encode_len);
213 if (noti->group_args) {
214 bundle_encode(noti->group_args, (bundle_raw **) & group_args,
218 if (noti->b_execute_option) {
219 bundle_encode(noti->b_execute_option,
220 (bundle_raw **) & b_execute_option, &b_encode_len);
222 if (noti->b_service_responding) {
223 bundle_encode(noti->b_service_responding,
224 (bundle_raw **) & b_service_responding, &b_encode_len);
226 if (noti->b_service_single_launch) {
227 bundle_encode(noti->b_service_single_launch,
228 (bundle_raw **) & b_service_single_launch, &b_encode_len);
230 if (noti->b_service_multi_launch) {
231 bundle_encode(noti->b_service_multi_launch,
232 (bundle_raw **) & b_service_multi_launch, &b_encode_len);
235 for (i = 0; i < NOTIFICATION_EVENT_TYPE_MAX; i++) {
236 if (noti->b_event_handler[i]) {
237 bundle_encode(noti->b_event_handler[i],
238 (bundle_raw **) & b_event_handler[i], &b_encode_len);
243 bundle_encode(noti->b_text, (bundle_raw **) & b_text, &b_encode_len);
246 bundle_encode(noti->b_key, (bundle_raw **) & b_key, &b_encode_len);
248 if (noti->b_format_args) {
249 bundle_encode(noti->b_format_args,
250 (bundle_raw **) & b_format_args, &b_encode_len);
253 if (noti->b_image_path) {
254 bundle_encode(noti->b_image_path,
255 (bundle_raw **) & b_image_path, &b_encode_len);
258 /* Check only simmode property is enable */
259 if (noti->flags_for_property & NOTIFICATION_PROP_DISPLAY_ONLY_SIMMODE) {
264 *query = sqlite3_mprintf("INSERT INTO noti_list ("
267 "caller_pkgname, launch_pkgname, "
269 "group_id, internal_group_id, priv_id, "
271 "b_text, b_key, tag, b_format_args, num_format_args, "
272 "text_domain, text_dir, "
273 "time, insert_time, "
276 "b_service_responding, b_service_single_launch, b_service_multi_launch, "
277 "b_event_handler_click_on_button_1, b_event_handler_click_on_button_2, b_event_handler_click_on_button_3, "
278 "b_event_handler_click_on_button_4, b_event_handler_click_on_button_5, b_event_handler_click_on_button_6, "
279 "b_event_handler_click_on_icon, b_event_handler_click_on_thumbnail, "
280 "sound_type, sound_path, vibration_type, vibration_path, led_operation, led_argb, led_on_ms, led_off_ms, "
281 "flags_for_property, flag_simmode, display_applist, "
282 "progress_size, progress_percentage) values ("
289 "'%s', '%s', $tag, '%s', %d, "
298 "%d, '%s', %d, '%s', %d, %d, %d, %d,"
300 "$progress_size, $progress_percentage)",
303 NOTIFICATION_CHECK_STR(noti->caller_pkgname),
304 NOTIFICATION_CHECK_STR(noti->launch_pkgname),
305 NOTIFICATION_CHECK_STR(b_image_path), noti->group_id,
306 noti->internal_group_id, noti->priv_id,
307 NOTIFICATION_CHECK_STR(b_text), NOTIFICATION_CHECK_STR(b_key),
308 NOTIFICATION_CHECK_STR(b_format_args), noti->num_format_args,
309 NOTIFICATION_CHECK_STR(noti->domain),
310 NOTIFICATION_CHECK_STR(noti->dir), (int)noti->time,
311 (int)noti->insert_time, NOTIFICATION_CHECK_STR(args),
312 NOTIFICATION_CHECK_STR(group_args),
313 NOTIFICATION_CHECK_STR(b_execute_option),
314 NOTIFICATION_CHECK_STR(b_service_responding),
315 NOTIFICATION_CHECK_STR(b_service_single_launch),
316 NOTIFICATION_CHECK_STR(b_service_multi_launch),
317 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1]),
318 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_2]),
319 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_3]),
320 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_4]),
321 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_5]),
322 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_6]),
323 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_ICON]),
324 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_THUMBNAIL]),
325 noti->sound_type, NOTIFICATION_CHECK_STR(noti->sound_path),
326 noti->vibration_type,
327 NOTIFICATION_CHECK_STR(noti->vibration_path),
332 noti->flags_for_property, flag_simmode, noti->display_applist);
334 /* Free decoded data */
342 if (b_execute_option) {
343 free(b_execute_option);
345 if (b_service_responding) {
346 free(b_service_responding);
348 if (b_service_single_launch) {
349 free(b_service_single_launch);
351 if (b_service_multi_launch) {
352 free(b_service_multi_launch);
369 if (*query == NULL) {
370 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
373 return NOTIFICATION_ERROR_NONE;
377 static int _update_query_create(notification_h noti, char **query)
380 int b_encode_len = 0;
382 char *group_args = NULL;
383 char *b_image_path = NULL;
384 char *b_execute_option = NULL;
385 char *b_service_responding = NULL;
386 char *b_service_single_launch = NULL;
387 char *b_service_multi_launch = NULL;
388 char *b_event_handler[NOTIFICATION_EVENT_TYPE_MAX] = { NULL , };
391 char *b_format_args = NULL;
392 int flag_simmode = 0;
395 return NOTIFICATION_ERROR_INVALID_PARAMETER;
398 /* Decode bundle to update DB */
400 bundle_encode(noti->args, (bundle_raw **) & args, &b_encode_len);
402 if (noti->group_args) {
403 bundle_encode(noti->group_args, (bundle_raw **) & group_args,
407 if (noti->b_execute_option) {
408 bundle_encode(noti->b_execute_option,
409 (bundle_raw **) & b_execute_option, &b_encode_len);
411 if (noti->b_service_responding) {
412 bundle_encode(noti->b_service_responding,
413 (bundle_raw **) & b_service_responding, &b_encode_len);
415 if (noti->b_service_single_launch) {
416 bundle_encode(noti->b_service_single_launch,
417 (bundle_raw **) & b_service_single_launch, &b_encode_len);
419 if (noti->b_service_multi_launch) {
420 bundle_encode(noti->b_service_multi_launch,
421 (bundle_raw **) & b_service_multi_launch, &b_encode_len);
424 for (i = 0; i < NOTIFICATION_EVENT_TYPE_MAX; i++) {
425 if (noti->b_event_handler[i]) {
426 bundle_encode(noti->b_event_handler[i],
427 (bundle_raw **) & b_event_handler[i], &b_encode_len);
432 bundle_encode(noti->b_text, (bundle_raw **) & b_text, &b_encode_len);
435 bundle_encode(noti->b_key, (bundle_raw **) & b_key, &b_encode_len);
437 if (noti->b_format_args) {
438 bundle_encode(noti->b_format_args,
439 (bundle_raw **) & b_format_args, &b_encode_len);
442 if (noti->b_image_path) {
443 bundle_encode(noti->b_image_path,
444 (bundle_raw **) & b_image_path, &b_encode_len);
447 /* Check only simmode property is enable */
448 if (noti->flags_for_property & NOTIFICATION_PROP_DISPLAY_ONLY_SIMMODE) {
453 *query = sqlite3_mprintf("UPDATE noti_list SET "
456 "launch_pkgname = '%s', "
457 "image_path = '%s', "
458 "b_text = '%s', b_key = '%s', tag = $tag, "
459 "b_format_args = '%s', num_format_args = %d, "
460 "text_domain = '%s', text_dir = '%s', "
461 "time = %d, insert_time = %d, "
462 "args = '%s', group_args = '%s', "
463 "b_execute_option = '%s', "
464 "b_service_responding = '%s', "
465 "b_service_single_launch = '%s', "
466 "b_service_multi_launch = '%s', "
467 "b_event_handler_click_on_button_1 = '%s', "
468 "b_event_handler_click_on_button_2= '%s', "
469 "b_event_handler_click_on_button_3= '%s', "
470 "b_event_handler_click_on_button_4= '%s', "
471 "b_event_handler_click_on_button_5= '%s', "
472 "b_event_handler_click_on_button_6= '%s', "
473 "b_event_handler_click_on_icon= '%s', "
474 "b_event_handler_click_on_thumbnail= '%s', "
475 "sound_type = %d, sound_path = '%s', "
476 "vibration_type = %d, vibration_path = '%s', "
477 "led_operation = %d, led_argb = %d, "
478 "led_on_ms = %d, led_off_ms = %d, "
479 "flags_for_property = %d, flag_simmode = %d, "
480 "display_applist = %d, "
481 "progress_size = $progress_size, progress_percentage = $progress_percentage "
482 "where priv_id = %d ",
485 NOTIFICATION_CHECK_STR(noti->launch_pkgname),
486 NOTIFICATION_CHECK_STR(b_image_path),
487 NOTIFICATION_CHECK_STR(b_text), NOTIFICATION_CHECK_STR(b_key),
488 NOTIFICATION_CHECK_STR(b_format_args), noti->num_format_args,
489 NOTIFICATION_CHECK_STR(noti->domain),
490 NOTIFICATION_CHECK_STR(noti->dir),
491 (int)noti->time, (int)noti->insert_time,
492 NOTIFICATION_CHECK_STR(args), NOTIFICATION_CHECK_STR(group_args),
493 NOTIFICATION_CHECK_STR(b_execute_option),
494 NOTIFICATION_CHECK_STR(b_service_responding),
495 NOTIFICATION_CHECK_STR(b_service_single_launch),
496 NOTIFICATION_CHECK_STR(b_service_multi_launch),
497 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1]),
498 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_2]),
499 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_3]),
500 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_4]),
501 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_5]),
502 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_6]),
503 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_ICON]),
504 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_THUMBNAIL]),
505 noti->sound_type, NOTIFICATION_CHECK_STR(noti->sound_path),
506 noti->vibration_type,
507 NOTIFICATION_CHECK_STR(noti->vibration_path),
512 noti->flags_for_property, flag_simmode, noti->display_applist,
515 /* Free decoded data */
523 if (b_execute_option) {
524 free(b_execute_option);
526 if (b_service_responding) {
527 free(b_service_responding);
529 if (b_service_single_launch) {
530 free(b_service_single_launch);
532 if (b_service_multi_launch) {
533 free(b_service_multi_launch);
550 if (*query == NULL) {
551 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
554 return NOTIFICATION_ERROR_NONE;
557 static void _notification_noti_populate_from_stmt(sqlite3_stmt * stmt, notification_h noti) {
561 if (stmt == NULL || noti == NULL) {
565 noti->type = sqlite3_column_int(stmt, col++);
566 noti->layout = sqlite3_column_int(stmt, col++);
567 __free_and_set((void **)&(noti->caller_pkgname), notification_db_column_text(stmt, col++));
568 __free_and_set((void **)&(noti->launch_pkgname), notification_db_column_text(stmt, col++));
569 noti->b_image_path = notification_db_column_bundle(stmt, col++);
570 noti->group_id = sqlite3_column_int(stmt, col++);
571 noti->internal_group_id = 0;
572 noti->priv_id = sqlite3_column_int(stmt, col++);
573 __free_and_set((void **)&(noti->tag), notification_db_column_text(stmt, col++));
575 noti->b_text = notification_db_column_bundle(stmt, col++);
576 noti->b_key = notification_db_column_bundle(stmt, col++);
577 noti->b_format_args = notification_db_column_bundle(stmt, col++);
578 noti->num_format_args = sqlite3_column_int(stmt, col++);
580 __free_and_set((void **)&(noti->domain), notification_db_column_text(stmt, col++));
581 __free_and_set((void **)&(noti->dir), notification_db_column_text(stmt, col++));
582 noti->time = sqlite3_column_int(stmt, col++);
583 noti->insert_time = sqlite3_column_int(stmt, col++);
584 noti->args = notification_db_column_bundle(stmt, col++);
585 noti->group_args = notification_db_column_bundle(stmt, col++);
587 noti->b_execute_option = notification_db_column_bundle(stmt, col++);
588 noti->b_service_responding = notification_db_column_bundle(stmt, col++);
589 noti->b_service_single_launch =
590 notification_db_column_bundle(stmt, col++);
591 noti->b_service_multi_launch =
592 notification_db_column_bundle(stmt, col++);
594 for (i = 0; i < NOTIFICATION_EVENT_TYPE_MAX; i++) {
595 noti->b_event_handler[i] = notification_db_column_bundle(stmt, col++);
598 noti->sound_type = sqlite3_column_int(stmt, col++);
599 __free_and_set((void **)&(noti->sound_path), notification_db_column_text(stmt, col++));
600 noti->vibration_type = sqlite3_column_int(stmt, col++);
601 __free_and_set((void **)&(noti->vibration_path), notification_db_column_text(stmt, col++));
602 noti->led_operation = sqlite3_column_int(stmt, col++);
603 noti->led_argb = sqlite3_column_int(stmt, col++);
604 noti->led_on_ms = sqlite3_column_int(stmt, col++);
605 noti->led_off_ms = sqlite3_column_int(stmt, col++);
607 noti->flags_for_property = sqlite3_column_int(stmt, col++);
608 noti->display_applist = sqlite3_column_int(stmt, col++);
609 noti->progress_size = sqlite3_column_double(stmt, col++);
610 noti->progress_percentage = sqlite3_column_double(stmt, col++);
612 noti->app_icon_path = NULL;
613 noti->app_name = NULL;
614 noti->temp_title = NULL;
615 noti->temp_content = NULL;
618 static notification_h _notification_noti_get_item(sqlite3_stmt * stmt)
620 notification_h noti = NULL;
622 noti = (notification_h) calloc(1, sizeof(struct _notification));
627 _notification_noti_populate_from_stmt(stmt, noti);
632 int notification_noti_set_tag(const char *tag, char *value, char *buf, int buf_len)
636 len_total += (strlen(tag) * 2) + 5 + strlen(value) + 1;
638 if (buf_len <= len_total)
639 return NOTIFICATION_ERROR_INVALID_PARAMETER;
641 snprintf(buf, buf_len, "<%s>%s</%s>", tag, value, tag);
643 return NOTIFICATION_ERROR_NONE;
646 char *notification_noti_strip_tag(const char *tagged_str)
648 if (tagged_str == NULL)
651 int len_total = strlen(tagged_str);
656 char *b_f_e = strstr(tagged_str, ">");
657 char *b_e_s = strstr(tagged_str, "</");
659 if (b_f_e == NULL || b_e_s == NULL || (b_e_s - b_f_e - 1) <= 0)
662 return strndup(b_f_e + 1, b_e_s - b_f_e - 1);
665 int notification_noti_get_tag_type(const char *tagged_str)
667 if (tagged_str == NULL)
668 return TAG_TYPE_INVALID;
670 if (strlen(tagged_str)== 0)
671 return TAG_TYPE_INVALID;
673 char *b_f_s = strstr(tagged_str, "<");
674 char *b_f_e = strstr(tagged_str, ">");
676 if (b_f_s == NULL || b_f_e == NULL || (b_f_e - b_f_s - 1) <= 0)
677 return TAG_TYPE_INVALID;
679 char *start = b_f_s + 1;
680 int len_tag = b_f_e - b_f_s - 1;
682 if (strncmp(start,TAG_TIME,len_tag) == 0) {
683 return TAG_TYPE_TIME;
686 return TAG_TYPE_INVALID;
689 static int _notification_noti_update_priv_id(sqlite3 * db, int rowid)
691 int ret = NOTIFICATION_ERROR_NONE;
695 ret = NOTIFICATION_ERROR_INVALID_PARAMETER;
699 query = sqlite3_mprintf("UPDATE noti_list SET "
700 "priv_id = %d, internal_group_id = %d WHERE rowid = %d",
701 rowid, rowid, rowid);
703 ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
707 ret = notification_db_exec(db, query, NULL);
717 static bool _is_allowed_to_notify(const char *caller_package_name)
719 notification_setting_h setting = NULL;
721 char *package_id = NULL;
724 err = notification_setting_get_setting_by_package_name(caller_package_name, &setting);
725 if (err != NOTIFICATION_ERROR_NONE) {
726 /* Retry with package id */
727 err = package_manager_get_package_id_by_app_id (caller_package_name, &package_id);
729 if (err != PACKAGE_MANAGER_ERROR_NONE || package_id == NULL) {
730 NOTIFICATION_ERR("package_manager_get_package_id_by_app_id failed [%d]", err);
734 err = notification_setting_get_setting_by_package_name(package_id, &setting);
735 if (err != NOTIFICATION_ERROR_NONE) {
736 NOTIFICATION_ERR("notification_setting_get_setting_by_package_name failed [%d]", err);
742 err = notification_setting_get_allow_to_notify(setting, &ret);
743 if (err != NOTIFICATION_ERROR_NONE) {
744 NOTIFICATION_ERR("notification_setting_get_allow_to_notify failed [%d]", err);
749 NOTIFICATION_DBG("[%s] is not allowed to notify", caller_package_name);
758 notification_setting_free_notification(setting);
764 EXPORT_API int notification_noti_insert(notification_h noti)
768 sqlite3_stmt *stmt = NULL;
770 char buf_key[32] = { 0, };
771 char *title_key = NULL;
774 NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
775 return NOTIFICATION_ERROR_INVALID_PARAMETER;
778 if (_is_allowed_to_notify((const char*)noti->caller_pkgname) == false) {
779 NOTIFICATION_DBG("Not allowed to notify");
780 return NOTIFICATION_ERROR_PERMISSION_DENIED;
784 db = notification_db_open(DBPATH);
786 return get_last_result();
789 /* Initialize private ID */
790 noti->priv_id = NOTIFICATION_PRIV_ID_NONE;
791 noti->group_id = NOTIFICATION_GROUP_ID_NONE;
792 noti->internal_group_id = NOTIFICATION_GROUP_ID_NONE;
795 ret = _insertion_query_create(noti, &query);
796 if (ret != NOTIFICATION_ERROR_NONE) {
800 ret = sqlite3_prepare_v2(db, query, -1, &stmt, NULL);
801 if (ret != SQLITE_OK) {
802 NOTIFICATION_ERR("Insert Query : %s", query);
803 NOTIFICATION_ERR("Insert DB error(%d) : %s", ret,
805 ret = NOTIFICATION_ERROR_FROM_DB;
810 if (noti->b_key != NULL) {
811 snprintf(buf_key, sizeof(buf_key), "%d",
812 NOTIFICATION_TEXT_TYPE_TITLE);
814 bundle_get_str(noti->b_key, buf_key, &title_key);
817 if (title_key == NULL && noti->b_text != NULL) {
818 snprintf(buf_key, sizeof(buf_key), "%d",
819 NOTIFICATION_TEXT_TYPE_TITLE);
821 bundle_get_str(noti->b_text, buf_key, &title_key);
824 if (title_key == NULL) {
825 title_key = noti->caller_pkgname;
829 ret = _notification_noti_bind_query_text(stmt, "$tag", noti->tag);
830 if (ret != NOTIFICATION_ERROR_NONE) {
831 NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db));
834 ret = _notification_noti_bind_query_text(stmt, "$title_key", title_key);
835 if (ret != NOTIFICATION_ERROR_NONE) {
836 NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db));
839 ret = _notification_noti_bind_query_double(stmt, "$progress_size",noti->progress_size);
840 if (ret != NOTIFICATION_ERROR_NONE) {
841 NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db));
843 sqlite3_finalize(stmt);
847 ret = _notification_noti_bind_query_double(stmt, "$progress_percentage",noti->progress_percentage);
848 if (ret != NOTIFICATION_ERROR_NONE) {
849 NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db));
851 sqlite3_finalize(stmt);
856 ret = sqlite3_step(stmt);
857 if (ret == SQLITE_OK || ret == SQLITE_DONE) {
858 noti->priv_id = (int)sqlite3_last_insert_rowid(db);
859 if (_notification_noti_update_priv_id(db, noti->priv_id) == 0) {
860 ret = NOTIFICATION_ERROR_NONE;
862 ret = NOTIFICATION_ERROR_FROM_DB;
865 ret = NOTIFICATION_ERROR_FROM_DB;
869 sqlite3_finalize(stmt);
874 notification_db_close(&db);
884 int notification_noti_get_by_priv_id(notification_h noti, char *pkgname, int priv_id)
889 sqlite3_stmt *stmt = NULL;
891 if (priv_id < 0 || noti == NULL) {
892 ret = NOTIFICATION_ERROR_INVALID_PARAMETER;
897 db = notification_db_open(DBPATH);
899 return get_last_result();
902 char *base_query = "select "
903 "type, layout, caller_pkgname, launch_pkgname, image_path, group_id, priv_id, "
904 "tag, b_text, b_key, b_format_args, num_format_args, "
905 "text_domain, text_dir, time, insert_time, args, group_args, "
906 "b_execute_option, b_service_responding, b_service_single_launch, b_service_multi_launch, "
907 "b_event_handler_click_on_button_1, b_event_handler_click_on_button_2, b_event_handler_click_on_button_3, "
908 "b_event_handler_click_on_button_4, b_event_handler_click_on_button_5, b_event_handler_click_on_button_6, "
909 "b_event_handler_click_on_icon, b_event_handler_click_on_thumbnail, "
910 "sound_type, sound_path, vibration_type, vibration_path, led_operation, led_argb, led_on_ms, led_off_ms, "
911 "flags_for_property, display_applist, progress_size, progress_percentage "
914 if (pkgname != NULL) {
915 query = sqlite3_mprintf("%s where caller_pkgname = '%s' and priv_id = %d",
916 base_query ,pkgname, priv_id);
918 query = sqlite3_mprintf("%s where priv_id = %d", base_query, priv_id);
921 ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
925 ret = sqlite3_prepare_v2(db, query, -1, &stmt, NULL);
926 if (ret != SQLITE_OK) {
927 NOTIFICATION_ERR("select Query : %s", query);
928 NOTIFICATION_ERR("select DB error(%d) : %s", ret,
930 ret = NOTIFICATION_ERROR_FROM_DB;
934 ret = sqlite3_step(stmt);
935 if (ret == SQLITE_ROW) {
936 _notification_noti_populate_from_stmt(stmt, noti);
937 ret = NOTIFICATION_ERROR_NONE;
939 ret = NOTIFICATION_ERROR_FROM_DB;
947 sqlite3_finalize(stmt);
952 notification_db_close(&db);
958 EXPORT_API int notification_noti_get_by_tag(notification_h noti, char *pkgname, char* tag)
962 sqlite3_stmt *stmt = NULL;
964 if (tag == NULL || noti == NULL) {
965 ret = NOTIFICATION_ERROR_INVALID_PARAMETER;
970 db = notification_db_open(DBPATH);
972 return get_last_result();
975 if (pkgname != NULL) {
976 ret = sqlite3_prepare_v2(db, "select "
977 "type, layout, caller_pkgname, launch_pkgname, image_path, group_id, priv_id, "
978 "tag, b_text, b_key, b_format_args, num_format_args, "
979 "text_domain, text_dir, time, insert_time, args, group_args, "
980 "b_execute_option, b_service_responding, b_service_single_launch, b_service_multi_launch, "
981 "b_event_handler_click_on_button_1, b_event_handler_click_on_button_2, b_event_handler_click_on_button_3, "
982 "b_event_handler_click_on_button_4, b_event_handler_click_on_button_5, b_event_handler_click_on_button_6, "
983 "b_event_handler_click_on_icon, b_event_handler_click_on_thumbnail, "
984 "sound_type, sound_path, vibration_type, vibration_path, led_operation, led_argb, led_on_ms, led_off_ms, "
985 "flags_for_property, display_applist, progress_size, progress_percentage "
986 "from noti_list where caller_pkgname = ? and tag = ?", -1, &stmt, NULL);
987 if (ret != SQLITE_OK) {
988 NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
989 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
992 ret = sqlite3_bind_text(stmt, 1, pkgname, -1, SQLITE_TRANSIENT);
993 if (ret != SQLITE_OK) {
994 NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
998 ret = sqlite3_bind_text(stmt, 2, tag, -1, SQLITE_TRANSIENT);
999 if (ret != SQLITE_OK) {
1000 NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
1004 ret = sqlite3_prepare_v2(db, "select "
1005 "type, layout, caller_pkgname, launch_pkgname, image_path, group_id, priv_id, "
1006 "tag, b_text, b_key, b_format_args, num_format_args, "
1007 "text_domain, text_dir, time, insert_time, args, group_args, "
1008 "b_execute_option, b_service_responding, b_service_single_launch, b_service_multi_launch, "
1009 "b_event_handler_click_on_button_1, b_event_handler_click_on_button_2, b_event_handler_click_on_button_3, "
1010 "b_event_handler_click_on_button_4, b_event_handler_click_on_button_5, b_event_handler_click_on_button_6, "
1011 "b_event_handler_click_on_icon, b_event_handler_click_on_thumbnail, "
1012 "sound_type, sound_path, vibration_type, vibration_path, led_operation, led_argb, led_on_ms, led_off_ms, "
1013 "flags_for_property, display_applist, progress_size, progress_percentage "
1014 "from noti_list where tag = ?", -1, &stmt, NULL);
1015 if (ret != SQLITE_OK) {
1016 NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
1017 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
1020 ret = sqlite3_bind_text(stmt, 1, tag, -1, SQLITE_TRANSIENT);
1021 if (ret != SQLITE_OK) {
1022 NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
1027 ret = sqlite3_step(stmt);
1028 if (ret == SQLITE_ROW) {
1029 _notification_noti_populate_from_stmt(stmt, noti);
1030 ret = NOTIFICATION_ERROR_NONE;
1032 ret = NOTIFICATION_ERROR_FROM_DB;
1038 sqlite3_finalize(stmt);
1043 notification_db_close(&db);
1049 EXPORT_API int notification_noti_update(notification_h noti)
1053 sqlite3_stmt *stmt = NULL;
1057 db = notification_db_open(DBPATH);
1059 return get_last_result();
1062 /* Check private ID is exist */
1063 ret = _notification_noti_check_priv_id(noti, db);
1064 if (ret != NOTIFICATION_ERROR_ALREADY_EXIST_ID) {
1065 ret = NOTIFICATION_ERROR_NOT_EXIST_ID;
1069 /* make update query */
1070 ret = _update_query_create(noti, &query);
1071 if (ret != NOTIFICATION_ERROR_NONE) {
1075 ret = sqlite3_prepare_v2(db, query, -1, &stmt, NULL);
1076 if (ret != SQLITE_OK) {
1077 NOTIFICATION_ERR("Insert Query : %s", query);
1078 NOTIFICATION_ERR("Insert DB error(%d) : %s", ret,
1079 sqlite3_errmsg(db));
1080 ret = NOTIFICATION_ERROR_FROM_DB;
1084 ret = _notification_noti_bind_query_text(stmt, "$tag", noti->tag);
1085 if (ret != NOTIFICATION_ERROR_NONE) {
1086 NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db));
1089 ret = _notification_noti_bind_query_double(stmt, "$progress_size",noti->progress_size);
1090 if (ret != NOTIFICATION_ERROR_NONE) {
1091 NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db));
1094 ret = _notification_noti_bind_query_double(stmt, "$progress_percentage",noti->progress_percentage);
1095 if (ret != NOTIFICATION_ERROR_NONE) {
1096 NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db));
1100 ret = sqlite3_step(stmt);
1101 if (ret == SQLITE_OK || ret == SQLITE_DONE) {
1102 ret = NOTIFICATION_ERROR_NONE;
1104 ret = NOTIFICATION_ERROR_FROM_DB;
1108 sqlite3_finalize(stmt);
1113 notification_db_close(&db);
1117 sqlite3_free(query);
1123 EXPORT_API int notification_noti_delete_all(notification_type_e type, const char *pkgname, int *num_deleted, int **list_deleted_rowid)
1125 int ret = NOTIFICATION_ERROR_NONE;
1126 int ret_tmp = NOTIFICATION_ERROR_NONE;
1127 int i = 0, data_cnt = 0;
1129 sqlite3_stmt *stmt = NULL;
1130 char buf[128] = { 0, };
1131 char query[NOTIFICATION_QUERY_MAX] = { 0, };
1132 char query_base[NOTIFICATION_QUERY_MAX] = { 0, };
1133 char query_where[NOTIFICATION_QUERY_MAX] = { 0, };
1136 db = notification_db_open(DBPATH);
1138 return get_last_result();
1141 if (pkgname == NULL) {
1142 if (type != NOTIFICATION_TYPE_NONE) {
1143 snprintf(query_where, sizeof(query_where),
1144 "where type = %d ", type);
1147 if (type == NOTIFICATION_TYPE_NONE) {
1148 snprintf(query_where, sizeof(query_where),
1149 "where caller_pkgname = '%s' ", pkgname);
1151 snprintf(query_where, sizeof(query_where),
1152 "where caller_pkgname = '%s' and type = %d ",
1157 if (num_deleted != NULL) {
1160 if (list_deleted_rowid != NULL) {
1161 *list_deleted_rowid = NULL;
1162 snprintf(query, sizeof(query),
1163 "select priv_id from noti_list %s ", query_where);
1165 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
1166 if (ret != SQLITE_OK) {
1167 NOTIFICATION_ERR("Select Query : %s", query);
1168 NOTIFICATION_ERR("Select DB error(%d) : %s", ret,
1169 sqlite3_errmsg(db));
1171 ret = NOTIFICATION_ERROR_FROM_DB;
1175 while(sqlite3_step(stmt) == SQLITE_ROW) {
1176 if (data_cnt % 8 == 0) {
1179 tmp = (int *)realloc(*list_deleted_rowid, sizeof(int) * (data_cnt + 8 + 1));
1181 *list_deleted_rowid = tmp;
1183 NOTIFICATION_ERR("Heap: %s\n", strerror(errno));
1186 * How can I handle this?
1188 free(*list_deleted_rowid);
1189 *list_deleted_rowid = NULL;
1190 ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
1194 *((*list_deleted_rowid) + data_cnt) = sqlite3_column_int(stmt, 0);
1199 sqlite3_finalize(stmt);
1204 query_where[0] = '\0';
1205 snprintf(query_base, sizeof(query_base) - 1, "delete from noti_list");
1206 for (i = 0; i < data_cnt ; i++) {
1207 if (i % NOTI_BURST_DELETE_UNIT == 0 && i != 0) {
1208 snprintf(query, sizeof(query) - 1, "%s where priv_id in (%s)", query_base, query_where);
1209 ret_tmp = notification_db_exec(db, query, NULL);
1210 query_where[0] = '\0';
1211 if (ret == NOTIFICATION_ERROR_NONE) {
1215 snprintf(buf, sizeof(buf) - 1, "%s%d", (i % NOTI_BURST_DELETE_UNIT == 0) ? "" : ",", *((*list_deleted_rowid) + i));
1216 strncat(query_where, buf,sizeof(query_where) - strlen(query_where) - 1);
1218 if ((i <= NOTI_BURST_DELETE_UNIT) || ((i % NOTI_BURST_DELETE_UNIT) > 0) ) {
1219 snprintf(query, sizeof(query) - 1, "%s where priv_id in (%s)", query_base, query_where);
1220 ret_tmp = notification_db_exec(db, query, NULL);
1221 if (ret == NOTIFICATION_ERROR_NONE) {
1226 free(*list_deleted_rowid);
1227 *list_deleted_rowid = NULL;
1230 if (num_deleted != NULL) {
1231 *num_deleted = data_cnt;
1234 /* Make main query */
1235 snprintf(query_base, sizeof(query_base), "delete from noti_list ");
1236 snprintf(query, sizeof(query), "%s %s", query_base, query_where);
1238 ret = notification_db_exec(db, query, NULL);
1240 if (num_deleted != NULL) {
1241 *num_deleted = sqlite3_changes(db);
1247 sqlite3_finalize(stmt);
1251 notification_db_close(&db);
1257 int notification_noti_delete_group_by_group_id(const char *pkgname,
1258 int group_id, int *num_deleted, int **list_deleted_rowid)
1260 int ret = NOTIFICATION_ERROR_NONE;
1261 int ret_tmp = NOTIFICATION_ERROR_NONE;
1263 int i = 0, data_cnt = 0;
1264 sqlite3_stmt *stmt = NULL;
1265 char buf[128] = { 0, };
1266 char query[NOTIFICATION_QUERY_MAX] = { 0, };
1267 char query_base[NOTIFICATION_QUERY_MAX] = { 0, };
1268 char query_where[NOTIFICATION_QUERY_MAX] = { 0, };
1270 /* Check pkgname is valid */
1271 if (pkgname == NULL) {
1272 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1275 snprintf(query_where, sizeof(query_where),
1276 "where caller_pkgname = '%s' and group_id = %d", pkgname, group_id);
1279 db = notification_db_open(DBPATH);
1281 return get_last_result();
1284 if (num_deleted != NULL) {
1287 if (list_deleted_rowid != NULL) {
1288 *list_deleted_rowid = NULL;
1289 snprintf(query, sizeof(query),
1290 "select priv_id from noti_list %s ", query_where);
1292 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
1293 if (ret != SQLITE_OK) {
1294 NOTIFICATION_ERR("Select Query : %s", query);
1295 NOTIFICATION_ERR("Select DB error(%d) : %s", ret,
1296 sqlite3_errmsg(db));
1298 ret = NOTIFICATION_ERROR_FROM_DB;
1302 while(sqlite3_step(stmt) == SQLITE_ROW) {
1303 if (data_cnt % 8 == 0) {
1305 tmp = (int *)realloc(*list_deleted_rowid, sizeof(int) * (data_cnt + 8 + 1));
1307 *list_deleted_rowid = tmp;
1309 free(*list_deleted_rowid);
1310 *list_deleted_rowid = NULL;
1311 ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
1315 *((*list_deleted_rowid) + data_cnt) = sqlite3_column_int(stmt, 0);
1320 sqlite3_finalize(stmt);
1325 query_where[0] = '\0';
1326 snprintf(query_base, sizeof(query_base) - 1, "delete from noti_list");
1327 for (i = 0; i < data_cnt ; i++) {
1328 if (i % NOTI_BURST_DELETE_UNIT == 0 && i != 0) {
1329 snprintf(query, sizeof(query) - 1, "%s where priv_id in (%s)", query_base, query_where);
1330 ret_tmp = notification_db_exec(db, query, NULL);
1331 query_where[0] = '\0';
1332 if (ret == NOTIFICATION_ERROR_NONE) {
1336 snprintf(buf, sizeof(buf) - 1, "%s%d", (i % NOTI_BURST_DELETE_UNIT == 0) ? "" : ",", *((*list_deleted_rowid) + i));
1337 strncat(query_where, buf,sizeof(query_where) - strlen(query_where) - 1);
1339 if ((i <= NOTI_BURST_DELETE_UNIT) || ((i % NOTI_BURST_DELETE_UNIT) > 0) ) {
1340 snprintf(query, sizeof(query) - 1, "%s where priv_id in (%s)", query_base, query_where);
1341 ret_tmp = notification_db_exec(db, query, NULL);
1342 if (ret == NOTIFICATION_ERROR_NONE) {
1347 free(*list_deleted_rowid);
1348 *list_deleted_rowid = NULL;
1351 if (num_deleted != NULL) {
1352 *num_deleted = data_cnt;
1356 snprintf(query, sizeof(query), "delete from noti_list %s", query_where);
1359 ret = notification_db_exec(db, query, NULL);
1364 sqlite3_finalize(stmt);
1368 notification_db_close(&db);
1374 int notification_noti_delete_group_by_priv_id(const char *pkgname, int priv_id)
1377 char query[NOTIFICATION_QUERY_MAX] = { 0, };
1378 int internal_group_id = 0;
1381 /* Check pkgname is valid */
1382 if (pkgname == NULL) {
1383 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1387 db = notification_db_open(DBPATH);
1389 return get_last_result();
1392 /* Get internal group id using priv id */
1394 _notification_noti_get_internal_group_id_by_priv_id(pkgname,
1398 snprintf(query, sizeof(query), "delete from noti_list "
1399 "where caller_pkgname = '%s' and internal_group_id = %d",
1400 pkgname, internal_group_id);
1403 ret = notification_db_exec(db, query, NULL);
1406 notification_db_close(&db);
1411 EXPORT_API int notification_noti_delete_by_priv_id(const char *pkgname, int priv_id)
1414 char query[NOTIFICATION_QUERY_MAX] = { 0, };
1417 /* Check pkgname is valid */
1418 if (pkgname == NULL) {
1419 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1423 db = notification_db_open(DBPATH);
1425 return get_last_result();
1429 snprintf(query, sizeof(query), "delete from noti_list "
1430 "where caller_pkgname = '%s' and priv_id = %d", pkgname,
1434 ret = notification_db_exec(db, query, NULL);
1438 notification_db_close(&db);
1444 EXPORT_API int notification_noti_delete_by_priv_id_get_changes(const char *pkgname, int priv_id, int *num_changes)
1447 char query[NOTIFICATION_QUERY_MAX] = { 0, };
1450 /* Check pkgname is valid */
1451 if (pkgname == NULL) {
1452 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1456 db = notification_db_open(DBPATH);
1458 return get_last_result();
1462 snprintf(query, sizeof(query), "delete from noti_list "
1463 "where caller_pkgname = '%s' and priv_id = %d", pkgname,
1467 ret = notification_db_exec(db, query, num_changes);
1469 if (num_changes != NULL) {
1470 NOTIFICATION_DBG("deleted num:%d", *num_changes);
1475 notification_db_close(&db);
1481 int notification_noti_get_count(notification_type_e type,
1482 const char *pkgname,
1483 int group_id, int priv_id,
1487 sqlite3_stmt *stmt = NULL;
1488 char query[NOTIFICATION_QUERY_MAX] = { 0, };
1489 char query_base[NOTIFICATION_QUERY_MAX] = { 0, };
1490 char query_where[NOTIFICATION_QUERY_MAX] = { 0, };
1491 char query_where_more[NOTIFICATION_QUERY_MAX] = { 0, };
1493 int ret = 0, get_count = 0, internal_group_id = 0;
1494 int status = VCONFKEY_TELEPHONY_SIM_UNKNOWN;
1496 int flag_where_more = 0;
1500 db = notification_db_open(DBPATH);
1502 return get_last_result();
1505 /* Check current sim status */
1506 ret_vconf = vconf_get_int(VCONFKEY_TELEPHONY_SIM_SLOT, &status);
1509 snprintf(query_base, sizeof(query_base),
1510 "select count(*) from noti_list ");
1512 if (pkgname != NULL) {
1513 if (group_id == NOTIFICATION_GROUP_ID_NONE) {
1514 if (priv_id == NOTIFICATION_PRIV_ID_NONE) {
1515 snprintf(query_where, sizeof(query_where),
1516 "where caller_pkgname = '%s' ",
1521 _notification_noti_get_internal_group_id_by_priv_id
1522 (pkgname, priv_id, db);
1523 snprintf(query_where, sizeof(query_where),
1524 "where caller_pkgname = '%s' and internal_group_id = %d ",
1525 pkgname, internal_group_id);
1529 if (priv_id == NOTIFICATION_PRIV_ID_NONE) {
1530 snprintf(query_where, sizeof(query_where),
1531 "where caller_pkgname = '%s' and group_id = %d ",
1536 _notification_noti_get_internal_group_id_by_priv_id
1537 (pkgname, priv_id, db);
1538 snprintf(query_where, sizeof(query_where),
1539 "where caller_pkgname = '%s' and internal_group_id = %d ",
1540 pkgname, internal_group_id);
1547 if (ret_vconf == 0 && status == VCONFKEY_TELEPHONY_SIM_INSERTED) {
1548 if (type != NOTIFICATION_TYPE_NONE) {
1549 snprintf(query_where_more, sizeof(query_where_more),
1550 "type = %d ", type);
1551 flag_where_more = 1;
1554 if (type != NOTIFICATION_TYPE_NONE) {
1555 snprintf(query_where_more, sizeof(query_where_more),
1556 "type = %d and flag_simmode = 0 ", type);
1557 flag_where_more = 1;
1559 snprintf(query_where_more, sizeof(query_where_more),
1560 "flag_simmode = 0 ");
1561 flag_where_more = 1;
1565 if (flag_where == 1) {
1566 if (flag_where_more == 1) {
1567 snprintf(query, sizeof(query), "%s %s and %s",
1568 query_base, query_where, query_where_more);
1570 snprintf(query, sizeof(query), "%s %s", query_base,
1575 if (flag_where_more == 1) {
1576 snprintf(query, sizeof(query), "%s where %s",
1577 query_base, query_where_more);
1579 snprintf(query, sizeof(query), "%s", query_base);
1583 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
1584 if (ret != SQLITE_OK) {
1585 NOTIFICATION_ERR("Select Query : %s", query);
1586 NOTIFICATION_ERR("Select DB error(%d) : %s", ret,
1587 sqlite3_errmsg(db));
1589 ret = NOTIFICATION_ERROR_FROM_DB;
1593 ret = sqlite3_step(stmt);
1594 if (ret == SQLITE_ROW) {
1595 get_count = sqlite3_column_int(stmt, 0);
1598 ret = NOTIFICATION_ERROR_NONE;
1602 sqlite3_finalize(stmt);
1607 notification_db_close(&db);
1615 int notification_noti_get_grouping_list(notification_type_e type,
1617 notification_list_h *
1621 sqlite3_stmt *stmt = NULL;
1622 char query[NOTIFICATION_QUERY_MAX] = { 0, };
1623 char query_base[NOTIFICATION_QUERY_MAX] = { 0, };
1624 char query_where[NOTIFICATION_QUERY_MAX] = { 0, };
1627 notification_list_h get_list = NULL;
1628 notification_h noti = NULL;
1629 int internal_count = 0;
1633 db = notification_db_open(DBPATH);
1635 return get_last_result();
1638 /* Check current sim status */
1639 ret = vconf_get_int(VCONFKEY_TELEPHONY_SIM_SLOT, &status);
1642 snprintf(query_base, sizeof(query_base), "select "
1643 "type, layout, caller_pkgname, launch_pkgname, image_path, group_id, priv_id, "
1644 "tag, b_text, b_key, b_format_args, num_format_args, "
1645 "text_domain, text_dir, time, insert_time, args, group_args, "
1646 "b_execute_option, b_service_responding, b_service_single_launch, b_service_multi_launch, "
1647 "b_event_handler_click_on_button_1, b_event_handler_click_on_button_2, b_event_handler_click_on_button_3, "
1648 "b_event_handler_click_on_button_4, b_event_handler_click_on_button_5, b_event_handler_click_on_button_6, "
1649 "b_event_handler_click_on_icon, b_event_handler_click_on_thumbnail, "
1650 "sound_type, sound_path, vibration_type, vibration_path, led_operation, led_argb, led_on_ms, led_off_ms, "
1651 "flags_for_property, display_applist, progress_size, progress_percentage "
1654 if (status == VCONFKEY_TELEPHONY_SIM_INSERTED) {
1655 if (type != NOTIFICATION_TYPE_NONE) {
1656 snprintf(query_where, sizeof(query_where),
1657 "where type = %d ", type);
1660 if (type != NOTIFICATION_TYPE_NONE) {
1661 snprintf(query_where, sizeof(query_where),
1662 "where type = %d and flag_simmode = 0 ", type);
1664 snprintf(query_where, sizeof(query_where),
1665 "where flag_simmode = 0 ");
1669 snprintf(query, sizeof(query),
1671 "group by internal_group_id "
1672 "order by rowid desc, time desc", query_base, query_where);
1674 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
1675 if (ret != SQLITE_OK) {
1676 NOTIFICATION_ERR("Select Query : %s", query);
1677 NOTIFICATION_ERR("Select DB error(%d) : %s", ret,
1678 sqlite3_errmsg(db));
1680 ret = NOTIFICATION_ERROR_FROM_DB;
1684 while (sqlite3_step(stmt) == SQLITE_ROW) {
1685 /* Make notification list */
1686 noti = _notification_noti_get_item(stmt);
1690 get_list = notification_list_append(get_list, noti);
1692 if (count != -1 && internal_count >= count) {
1694 ("internal count %d >= count %d",
1695 internal_count, count);
1701 ret = NOTIFICATION_ERROR_NONE;
1705 sqlite3_finalize(stmt);
1710 notification_db_close(&db);
1713 if (get_list != NULL) {
1714 *list = notification_list_get_head(get_list);
1720 int notification_noti_get_detail_list(const char *pkgname,
1722 int priv_id, int count,
1723 notification_list_h *list)
1726 sqlite3_stmt *stmt = NULL;
1727 char query_base[NOTIFICATION_QUERY_MAX] = { 0, };
1728 char query_where[NOTIFICATION_QUERY_MAX] = { 0, };
1730 char query[NOTIFICATION_QUERY_MAX] = { 0, };
1732 notification_list_h get_list = NULL;
1733 notification_h noti = NULL;
1734 int internal_count = 0;
1735 int internal_group_id = 0;
1736 int status = 0; /* If the vconf_get_int failed, the status will be the garbage value */
1739 db = notification_db_open(DBPATH);
1741 return get_last_result();
1744 /* Check current sim status */
1745 ret = vconf_get_int(VCONFKEY_TELEPHONY_SIM_SLOT, &status);
1748 snprintf(query_base, sizeof(query_base), "select "
1749 "type, layout, caller_pkgname, launch_pkgname, image_path, group_id, priv_id, "
1750 "tag, b_text, b_key, b_format_args, num_format_args, "
1751 "text_domain, text_dir, time, insert_time, args, group_args, "
1752 "b_execute_option, b_service_responding, b_service_single_launch, b_service_multi_launch, "
1753 "b_event_handler_click_on_button_1, b_event_handler_click_on_button_2, b_event_handler_click_on_button_3, "
1754 "b_event_handler_click_on_button_4, b_event_handler_click_on_button_5, b_event_handler_click_on_button_6, "
1755 "b_event_handler_click_on_icon, b_event_handler_click_on_thumbnail, "
1756 "sound_type, sound_path, vibration_type, vibration_path, led_operation, led_argb, led_on_ms, led_off_ms, "
1757 "flags_for_property, display_applist, progress_size, progress_percentage "
1760 if (priv_id == NOTIFICATION_PRIV_ID_NONE && group_id == NOTIFICATION_GROUP_ID_NONE) {
1761 if (status == VCONFKEY_TELEPHONY_SIM_INSERTED) {
1762 snprintf(query_where, sizeof(query_where),
1763 "where caller_pkgname = '%s' ", pkgname);
1765 snprintf(query_where, sizeof(query_where),
1766 "where caller_pkgname = '%s' and flag_simmode = 0 ", pkgname);
1770 _notification_noti_get_internal_group_id_by_priv_id(pkgname,
1773 if (status == VCONFKEY_TELEPHONY_SIM_INSERTED) {
1774 snprintf(query_where, sizeof(query_where),
1775 "where caller_pkgname = '%s' and internal_group_id = %d ",
1776 pkgname, internal_group_id);
1778 snprintf(query_where, sizeof(query_where),
1779 "where caller_pkgname = '%s' and internal_group_id = %d and flag_simmode = 0 ",
1780 pkgname, internal_group_id);
1784 snprintf(query, sizeof(query),
1786 "order by rowid desc, time desc", query_base, query_where);
1788 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
1789 if (ret != SQLITE_OK) {
1790 NOTIFICATION_ERR("Select Query : %s", query);
1791 NOTIFICATION_ERR("Select DB error(%d) : %s", ret,
1792 sqlite3_errmsg(db));
1794 ret = NOTIFICATION_ERROR_FROM_DB;
1798 while (sqlite3_step(stmt) == SQLITE_ROW) {
1799 /* Make notification list */
1800 noti = _notification_noti_get_item(stmt);
1804 get_list = notification_list_append(get_list, noti);
1806 if (count != -1 && internal_count >= count) {
1808 ("internal count %d >= count %d",
1809 internal_count, count);
1815 ret = NOTIFICATION_ERROR_NONE;
1819 sqlite3_finalize(stmt);
1824 notification_db_close(&db);
1827 if (get_list != NULL) {
1828 *list = notification_list_get_head(get_list);
1834 EXPORT_API int notification_noti_check_tag(notification_h noti)
1837 int ret = NOTIFICATION_ERROR_NONE;
1839 sqlite3_stmt *stmt = NULL;
1841 if (noti->tag == NULL) {
1842 return NOTIFICATION_ERROR_NOT_EXIST_ID;
1846 db = notification_db_open(DBPATH);
1848 return get_last_result();
1851 ret = sqlite3_prepare_v2(db, "SELECT priv_id FROM noti_list WHERE caller_pkgname = ? and tag = ?", -1, &stmt, NULL);
1852 if (ret != SQLITE_OK) {
1853 NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
1854 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
1857 ret = sqlite3_bind_text(stmt, 1, noti->caller_pkgname, -1, SQLITE_TRANSIENT);
1858 if (ret != SQLITE_OK) {
1859 NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
1863 ret = sqlite3_bind_text(stmt, 2, noti->tag, -1, SQLITE_TRANSIENT);
1864 if (ret != SQLITE_OK) {
1865 NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
1869 ret = sqlite3_step(stmt);
1870 if (ret == SQLITE_ROW) {
1871 result = sqlite3_column_int(stmt, 0);
1876 sqlite3_finalize(stmt);
1878 /* If result > 0, there is priv_id in DB */
1880 noti->priv_id = result;
1881 ret = NOTIFICATION_ERROR_ALREADY_EXIST_ID;
1883 ret = NOTIFICATION_ERROR_NOT_EXIST_ID;