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>
31 #include <notification.h>
32 #include <notification_db.h>
33 #include <notification_noti.h>
34 #include <notification_debug.h>
35 #include <notification_private.h>
37 #define NOTI_BURST_DELETE_UNIT 10
39 static void __free_and_set(void **target_ptr, void *new_ptr) {
40 if (target_ptr != NULL) {
41 if (*target_ptr != NULL) {
44 *target_ptr = new_ptr;
48 static int _notification_noti_bind_query_text(sqlite3_stmt * stmt, const char *name,
54 index = sqlite3_bind_parameter_index(stmt, name);
56 NOTIFICATION_ERR("Insert : invalid column name");
57 return NOTIFICATION_ERROR_FROM_DB;
61 sqlite3_bind_text(stmt, index, NOTIFICATION_CHECK_STR(str), -1,
63 if (ret != SQLITE_OK) {
64 NOTIFICATION_ERR("Insert text : %s",
65 NOTIFICATION_CHECK_STR(str));
66 return NOTIFICATION_ERROR_FROM_DB;
69 return NOTIFICATION_ERROR_NONE;
72 static int _notification_noti_bind_query_double(sqlite3_stmt * stmt, const char *name,
78 index = sqlite3_bind_parameter_index(stmt, name);
80 NOTIFICATION_ERR("Insert : invalid column name");
81 return NOTIFICATION_ERROR_FROM_DB;
84 ret = sqlite3_bind_double(stmt, index, val);
85 if (ret != SQLITE_OK) {
86 NOTIFICATION_ERR("Insert double : %f", val);
87 return NOTIFICATION_ERROR_FROM_DB;
90 return NOTIFICATION_ERROR_NONE;
93 static int _notification_noti_check_priv_id(notification_h noti, sqlite3 * db)
96 int ret = NOTIFICATION_ERROR_NONE;
98 sqlite3_stmt *stmt = NULL;
100 /* Make query to check priv_id exist */
101 query = sqlite3_mprintf("SELECT count(*) FROM noti_list WHERE caller_pkgname = '%s' AND priv_id = %d",
102 noti->caller_pkgname, noti->priv_id);
104 ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
108 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
109 if (ret != SQLITE_OK) {
110 NOTIFICATION_ERR("Get count DB err(%d) : %s", ret,
112 ret = NOTIFICATION_ERROR_FROM_DB;
116 ret = sqlite3_step(stmt);
117 if (ret == SQLITE_ROW) {
118 result = sqlite3_column_int(stmt, 0);
123 sqlite3_finalize(stmt);
125 /* If result > 0, there is priv_id in DB */
127 ret = NOTIFICATION_ERROR_ALREADY_EXIST_ID;
138 static int _notification_noti_get_internal_group_id_by_priv_id(const char *pkgname,
143 sqlite3_stmt *stmt = NULL;
144 int ret = NOTIFICATION_ERROR_NONE, result = 0;
146 query = sqlite3_mprintf("SELECT internal_group_id FROM noti_list WHERE caller_pkgname = '%s' AND priv_id = %d",
149 ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
153 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
154 if (ret != SQLITE_OK) {
155 NOTIFICATION_ERR("Get count DB err(%d) : %s", ret,
157 ret = NOTIFICATION_ERROR_FROM_DB;
161 ret = sqlite3_step(stmt);
162 if (ret == SQLITE_ROW) {
163 result = sqlite3_column_int(stmt, 0);
170 sqlite3_finalize(stmt);
177 if (ret != NOTIFICATION_ERROR_NONE) {
178 NOTIFICATION_ERR("failed to internal group ID:%d", ret);
184 static int _insertion_query_create(notification_h noti, char **query)
187 int b_encode_len = 0;
189 char *group_args = NULL;
190 char *b_image_path = NULL;
191 char *b_execute_option = NULL;
192 char *b_service_responding = NULL;
193 char *b_service_single_launch = NULL;
194 char *b_service_multi_launch = NULL;
195 char *b_event_handler[NOTIFICATION_EVENT_TYPE_MAX] = { NULL , };
198 char *b_format_args = NULL;
199 int flag_simmode = 0;
202 return NOTIFICATION_ERROR_INVALID_PARAMETER;
205 /* Decode bundle to insert DB */
207 bundle_encode(noti->args, (bundle_raw **) & args, &b_encode_len);
209 if (noti->group_args) {
210 bundle_encode(noti->group_args, (bundle_raw **) & group_args,
214 if (noti->b_execute_option) {
215 bundle_encode(noti->b_execute_option,
216 (bundle_raw **) & b_execute_option, &b_encode_len);
218 if (noti->b_service_responding) {
219 bundle_encode(noti->b_service_responding,
220 (bundle_raw **) & b_service_responding, &b_encode_len);
222 if (noti->b_service_single_launch) {
223 bundle_encode(noti->b_service_single_launch,
224 (bundle_raw **) & b_service_single_launch, &b_encode_len);
226 if (noti->b_service_multi_launch) {
227 bundle_encode(noti->b_service_multi_launch,
228 (bundle_raw **) & b_service_multi_launch, &b_encode_len);
231 for (i = 0; i < NOTIFICATION_EVENT_TYPE_MAX; i++) {
232 if (noti->b_event_handler[i]) {
233 bundle_encode(noti->b_event_handler[i],
234 (bundle_raw **) & b_event_handler[i], &b_encode_len);
239 bundle_encode(noti->b_text, (bundle_raw **) & b_text, &b_encode_len);
242 bundle_encode(noti->b_key, (bundle_raw **) & b_key, &b_encode_len);
244 if (noti->b_format_args) {
245 bundle_encode(noti->b_format_args,
246 (bundle_raw **) & b_format_args, &b_encode_len);
249 if (noti->b_image_path) {
250 bundle_encode(noti->b_image_path,
251 (bundle_raw **) & b_image_path, &b_encode_len);
254 /* Check only simmode property is enable */
255 if (noti->flags_for_property & NOTIFICATION_PROP_DISPLAY_ONLY_SIMMODE) {
260 *query = sqlite3_mprintf("INSERT INTO noti_list ("
263 "caller_pkgname, launch_pkgname, "
265 "group_id, internal_group_id, priv_id, "
267 "b_text, b_key, tag, b_format_args, num_format_args, "
268 "text_domain, text_dir, "
269 "time, insert_time, "
272 "b_service_responding, b_service_single_launch, b_service_multi_launch, "
273 "b_event_handler_click_on_button_1, b_event_handler_click_on_button_2, b_event_handler_click_on_button_3, "
274 "b_event_handler_click_on_button_4, b_event_handler_click_on_button_5, b_event_handler_click_on_button_6, "
275 "b_event_handler_click_on_icon, b_event_handler_click_on_thumbnail, "
276 "sound_type, sound_path, vibration_type, vibration_path, led_operation, led_argb, led_on_ms, led_off_ms, "
277 "flags_for_property, flag_simmode, display_applist, "
278 "progress_size, progress_percentage) values ("
285 "'%s', '%s', $tag, '%s', %d, "
294 "%d, '%s', %d, '%s', %d, %d, %d, %d,"
296 "$progress_size, $progress_percentage)",
299 NOTIFICATION_CHECK_STR(noti->caller_pkgname),
300 NOTIFICATION_CHECK_STR(noti->launch_pkgname),
301 NOTIFICATION_CHECK_STR(b_image_path), noti->group_id,
302 noti->internal_group_id, noti->priv_id,
303 NOTIFICATION_CHECK_STR(b_text), NOTIFICATION_CHECK_STR(b_key),
304 NOTIFICATION_CHECK_STR(b_format_args), noti->num_format_args,
305 NOTIFICATION_CHECK_STR(noti->domain),
306 NOTIFICATION_CHECK_STR(noti->dir), (int)noti->time,
307 (int)noti->insert_time, NOTIFICATION_CHECK_STR(args),
308 NOTIFICATION_CHECK_STR(group_args),
309 NOTIFICATION_CHECK_STR(b_execute_option),
310 NOTIFICATION_CHECK_STR(b_service_responding),
311 NOTIFICATION_CHECK_STR(b_service_single_launch),
312 NOTIFICATION_CHECK_STR(b_service_multi_launch),
313 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1]),
314 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_2]),
315 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_3]),
316 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_4]),
317 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_5]),
318 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_6]),
319 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_ICON]),
320 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_THUMBNAIL]),
321 noti->sound_type, NOTIFICATION_CHECK_STR(noti->sound_path),
322 noti->vibration_type,
323 NOTIFICATION_CHECK_STR(noti->vibration_path),
328 noti->flags_for_property, flag_simmode, noti->display_applist);
330 /* Free decoded data */
338 if (b_execute_option) {
339 free(b_execute_option);
341 if (b_service_responding) {
342 free(b_service_responding);
344 if (b_service_single_launch) {
345 free(b_service_single_launch);
347 if (b_service_multi_launch) {
348 free(b_service_multi_launch);
365 if (*query == NULL) {
366 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
369 return NOTIFICATION_ERROR_NONE;
373 static int _update_query_create(notification_h noti, char **query)
376 int b_encode_len = 0;
378 char *group_args = NULL;
379 char *b_image_path = NULL;
380 char *b_execute_option = NULL;
381 char *b_service_responding = NULL;
382 char *b_service_single_launch = NULL;
383 char *b_service_multi_launch = NULL;
384 char *b_event_handler[NOTIFICATION_EVENT_TYPE_MAX] = { NULL , };
387 char *b_format_args = NULL;
388 int flag_simmode = 0;
391 return NOTIFICATION_ERROR_INVALID_PARAMETER;
394 /* Decode bundle to update DB */
396 bundle_encode(noti->args, (bundle_raw **) & args, &b_encode_len);
398 if (noti->group_args) {
399 bundle_encode(noti->group_args, (bundle_raw **) & group_args,
403 if (noti->b_execute_option) {
404 bundle_encode(noti->b_execute_option,
405 (bundle_raw **) & b_execute_option, &b_encode_len);
407 if (noti->b_service_responding) {
408 bundle_encode(noti->b_service_responding,
409 (bundle_raw **) & b_service_responding, &b_encode_len);
411 if (noti->b_service_single_launch) {
412 bundle_encode(noti->b_service_single_launch,
413 (bundle_raw **) & b_service_single_launch, &b_encode_len);
415 if (noti->b_service_multi_launch) {
416 bundle_encode(noti->b_service_multi_launch,
417 (bundle_raw **) & b_service_multi_launch, &b_encode_len);
420 for (i = 0; i < NOTIFICATION_EVENT_TYPE_MAX; i++) {
421 if (noti->b_event_handler[i]) {
422 bundle_encode(noti->b_event_handler[i],
423 (bundle_raw **) & b_event_handler[i], &b_encode_len);
428 bundle_encode(noti->b_text, (bundle_raw **) & b_text, &b_encode_len);
431 bundle_encode(noti->b_key, (bundle_raw **) & b_key, &b_encode_len);
433 if (noti->b_format_args) {
434 bundle_encode(noti->b_format_args,
435 (bundle_raw **) & b_format_args, &b_encode_len);
438 if (noti->b_image_path) {
439 bundle_encode(noti->b_image_path,
440 (bundle_raw **) & b_image_path, &b_encode_len);
443 /* Check only simmode property is enable */
444 if (noti->flags_for_property & NOTIFICATION_PROP_DISPLAY_ONLY_SIMMODE) {
449 *query = sqlite3_mprintf("UPDATE noti_list SET "
452 "launch_pkgname = '%s', "
453 "image_path = '%s', "
454 "b_text = '%s', b_key = '%s', tag = $tag, "
455 "b_format_args = '%s', num_format_args = %d, "
456 "text_domain = '%s', text_dir = '%s', "
457 "time = %d, insert_time = %d, "
458 "args = '%s', group_args = '%s', "
459 "b_execute_option = '%s', "
460 "b_service_responding = '%s', "
461 "b_service_single_launch = '%s', "
462 "b_service_multi_launch = '%s', "
463 "b_event_handler_click_on_button_1 = '%s', "
464 "b_event_handler_click_on_button_2= '%s', "
465 "b_event_handler_click_on_button_3= '%s', "
466 "b_event_handler_click_on_button_4= '%s', "
467 "b_event_handler_click_on_button_5= '%s', "
468 "b_event_handler_click_on_button_6= '%s', "
469 "b_event_handler_click_on_icon= '%s', "
470 "b_event_handler_click_on_thumbnail= '%s', "
471 "sound_type = %d, sound_path = '%s', "
472 "vibration_type = %d, vibration_path = '%s', "
473 "led_operation = %d, led_argb = %d, "
474 "led_on_ms = %d, led_off_ms = %d, "
475 "flags_for_property = %d, flag_simmode = %d, "
476 "display_applist = %d, "
477 "progress_size = $progress_size, progress_percentage = $progress_percentage "
478 "where priv_id = %d ",
481 NOTIFICATION_CHECK_STR(noti->launch_pkgname),
482 NOTIFICATION_CHECK_STR(b_image_path),
483 NOTIFICATION_CHECK_STR(b_text), NOTIFICATION_CHECK_STR(b_key),
484 NOTIFICATION_CHECK_STR(b_format_args), noti->num_format_args,
485 NOTIFICATION_CHECK_STR(noti->domain),
486 NOTIFICATION_CHECK_STR(noti->dir),
487 (int)noti->time, (int)noti->insert_time,
488 NOTIFICATION_CHECK_STR(args), NOTIFICATION_CHECK_STR(group_args),
489 NOTIFICATION_CHECK_STR(b_execute_option),
490 NOTIFICATION_CHECK_STR(b_service_responding),
491 NOTIFICATION_CHECK_STR(b_service_single_launch),
492 NOTIFICATION_CHECK_STR(b_service_multi_launch),
493 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1]),
494 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_2]),
495 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_3]),
496 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_4]),
497 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_5]),
498 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_6]),
499 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_ICON]),
500 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_THUMBNAIL]),
501 noti->sound_type, NOTIFICATION_CHECK_STR(noti->sound_path),
502 noti->vibration_type,
503 NOTIFICATION_CHECK_STR(noti->vibration_path),
508 noti->flags_for_property, flag_simmode, noti->display_applist,
511 /* Free decoded data */
519 if (b_execute_option) {
520 free(b_execute_option);
522 if (b_service_responding) {
523 free(b_service_responding);
525 if (b_service_single_launch) {
526 free(b_service_single_launch);
528 if (b_service_multi_launch) {
529 free(b_service_multi_launch);
546 if (*query == NULL) {
547 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
550 return NOTIFICATION_ERROR_NONE;
553 static void _notification_noti_populate_from_stmt(sqlite3_stmt * stmt, notification_h noti) {
557 if (stmt == NULL || noti == NULL) {
561 noti->type = sqlite3_column_int(stmt, col++);
562 noti->layout = sqlite3_column_int(stmt, col++);
563 __free_and_set((void **)&(noti->caller_pkgname), notification_db_column_text(stmt, col++));
564 __free_and_set((void **)&(noti->launch_pkgname), notification_db_column_text(stmt, col++));
565 noti->b_image_path = notification_db_column_bundle(stmt, col++);
566 noti->group_id = sqlite3_column_int(stmt, col++);
567 noti->internal_group_id = 0;
568 noti->priv_id = sqlite3_column_int(stmt, col++);
569 __free_and_set((void **)&(noti->tag), notification_db_column_text(stmt, col++));
571 noti->b_text = notification_db_column_bundle(stmt, col++);
572 noti->b_key = notification_db_column_bundle(stmt, col++);
573 noti->b_format_args = notification_db_column_bundle(stmt, col++);
574 noti->num_format_args = sqlite3_column_int(stmt, col++);
576 __free_and_set((void **)&(noti->domain), notification_db_column_text(stmt, col++));
577 __free_and_set((void **)&(noti->dir), notification_db_column_text(stmt, col++));
578 noti->time = sqlite3_column_int(stmt, col++);
579 noti->insert_time = sqlite3_column_int(stmt, col++);
580 noti->args = notification_db_column_bundle(stmt, col++);
581 noti->group_args = notification_db_column_bundle(stmt, col++);
583 noti->b_execute_option = notification_db_column_bundle(stmt, col++);
584 noti->b_service_responding = notification_db_column_bundle(stmt, col++);
585 noti->b_service_single_launch =
586 notification_db_column_bundle(stmt, col++);
587 noti->b_service_multi_launch =
588 notification_db_column_bundle(stmt, col++);
590 for (i = 0; i < NOTIFICATION_EVENT_TYPE_MAX; i++) {
591 noti->b_event_handler[i] = notification_db_column_bundle(stmt, col++);
594 noti->sound_type = sqlite3_column_int(stmt, col++);
595 __free_and_set((void **)&(noti->sound_path), notification_db_column_text(stmt, col++));
596 noti->vibration_type = sqlite3_column_int(stmt, col++);
597 __free_and_set((void **)&(noti->vibration_path), notification_db_column_text(stmt, col++));
598 noti->led_operation = sqlite3_column_int(stmt, col++);
599 noti->led_argb = sqlite3_column_int(stmt, col++);
600 noti->led_on_ms = sqlite3_column_int(stmt, col++);
601 noti->led_off_ms = sqlite3_column_int(stmt, col++);
603 noti->flags_for_property = sqlite3_column_int(stmt, col++);
604 noti->display_applist = sqlite3_column_int(stmt, col++);
605 noti->progress_size = sqlite3_column_double(stmt, col++);
606 noti->progress_percentage = sqlite3_column_double(stmt, col++);
608 noti->app_icon_path = NULL;
609 noti->app_name = NULL;
610 noti->temp_title = NULL;
611 noti->temp_content = NULL;
614 static notification_h _notification_noti_get_item(sqlite3_stmt * stmt)
616 notification_h noti = NULL;
618 noti = (notification_h) calloc(1, sizeof(struct _notification));
623 _notification_noti_populate_from_stmt(stmt, noti);
628 int notification_noti_set_tag(const char *tag, char *value, char *buf, int buf_len)
632 len_total += (strlen(tag) * 2) + 5 + strlen(value) + 1;
634 if (buf_len <= len_total)
635 return NOTIFICATION_ERROR_INVALID_PARAMETER;
637 snprintf(buf, buf_len, "<%s>%s</%s>", tag, value, tag);
639 return NOTIFICATION_ERROR_NONE;
642 char *notification_noti_strip_tag(const char *tagged_str)
644 if (tagged_str == NULL)
647 int len_total = strlen(tagged_str);
652 char *b_f_e = strstr(tagged_str, ">");
653 char *b_e_s = strstr(tagged_str, "</");
655 if (b_f_e == NULL || b_e_s == NULL || (b_e_s - b_f_e - 1) <= 0)
658 return strndup(b_f_e + 1, b_e_s - b_f_e - 1);
661 int notification_noti_get_tag_type(const char *tagged_str)
663 if (tagged_str == NULL)
664 return TAG_TYPE_INVALID;
666 if (strlen(tagged_str)== 0)
667 return TAG_TYPE_INVALID;
669 char *b_f_s = strstr(tagged_str, "<");
670 char *b_f_e = strstr(tagged_str, ">");
672 if (b_f_s == NULL || b_f_e == NULL || (b_f_e - b_f_s - 1) <= 0)
673 return TAG_TYPE_INVALID;
675 char *start = b_f_s + 1;
676 int len_tag = b_f_e - b_f_s - 1;
678 if (strncmp(start,TAG_TIME,len_tag) == 0) {
679 return TAG_TYPE_TIME;
682 return TAG_TYPE_INVALID;
685 static int _notification_noti_update_priv_id(sqlite3 * db, int rowid)
687 int ret = NOTIFICATION_ERROR_NONE;
691 ret = NOTIFICATION_ERROR_INVALID_PARAMETER;
695 query = sqlite3_mprintf("UPDATE noti_list SET "
696 "priv_id = %d, internal_group_id = %d WHERE rowid = %d",
697 rowid, rowid, rowid);
699 ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
703 ret = notification_db_exec(db, query, NULL);
713 EXPORT_API int notification_noti_insert(notification_h noti)
717 sqlite3_stmt *stmt = NULL;
719 char buf_key[32] = { 0, };
720 const char *title_key = NULL;
723 db = notification_db_open(DBPATH);
725 return get_last_result();
728 /* Initialize private ID */
729 noti->priv_id = NOTIFICATION_PRIV_ID_NONE;
730 noti->group_id = NOTIFICATION_GROUP_ID_NONE;
731 noti->internal_group_id = NOTIFICATION_GROUP_ID_NONE;
734 ret = _insertion_query_create(noti, &query);
735 if (ret != NOTIFICATION_ERROR_NONE) {
739 ret = sqlite3_prepare_v2(db, query, -1, &stmt, NULL);
740 if (ret != SQLITE_OK) {
741 NOTIFICATION_ERR("Insert Query : %s", query);
742 NOTIFICATION_ERR("Insert DB error(%d) : %s", ret,
744 ret = NOTIFICATION_ERROR_FROM_DB;
749 if (noti->b_key != NULL) {
750 snprintf(buf_key, sizeof(buf_key), "%d",
751 NOTIFICATION_TEXT_TYPE_TITLE);
753 title_key = bundle_get_val(noti->b_key, buf_key);
756 if (title_key == NULL && noti->b_text != NULL) {
757 snprintf(buf_key, sizeof(buf_key), "%d",
758 NOTIFICATION_TEXT_TYPE_TITLE);
760 title_key = bundle_get_val(noti->b_text, buf_key);
763 if (title_key == NULL) {
764 title_key = noti->caller_pkgname;
768 ret = _notification_noti_bind_query_text(stmt, "$tag", noti->tag);
769 if (ret != NOTIFICATION_ERROR_NONE) {
770 NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db));
773 ret = _notification_noti_bind_query_text(stmt, "$title_key", title_key);
774 if (ret != NOTIFICATION_ERROR_NONE) {
775 NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db));
778 ret = _notification_noti_bind_query_double(stmt, "$progress_size",noti->progress_size);
779 if (ret != NOTIFICATION_ERROR_NONE) {
780 NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db));
782 sqlite3_finalize(stmt);
786 ret = _notification_noti_bind_query_double(stmt, "$progress_percentage",noti->progress_percentage);
787 if (ret != NOTIFICATION_ERROR_NONE) {
788 NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db));
790 sqlite3_finalize(stmt);
795 ret = sqlite3_step(stmt);
796 if (ret == SQLITE_OK || ret == SQLITE_DONE) {
797 noti->priv_id = (int)sqlite3_last_insert_rowid(db);
798 if (_notification_noti_update_priv_id(db, noti->priv_id) == 0) {
799 ret = NOTIFICATION_ERROR_NONE;
801 ret = NOTIFICATION_ERROR_FROM_DB;
804 ret = NOTIFICATION_ERROR_FROM_DB;
808 sqlite3_finalize(stmt);
813 notification_db_close(&db);
823 int notification_noti_get_by_priv_id(notification_h noti, char *pkgname, int priv_id)
828 sqlite3_stmt *stmt = NULL;
830 if (priv_id < 0 || noti == NULL) {
831 ret = NOTIFICATION_ERROR_INVALID_PARAMETER;
836 db = notification_db_open(DBPATH);
838 return get_last_result();
841 char *base_query = "select "
842 "type, layout, caller_pkgname, launch_pkgname, image_path, group_id, priv_id, "
843 "tag, b_text, b_key, b_format_args, num_format_args, "
844 "text_domain, text_dir, time, insert_time, args, group_args, "
845 "b_execute_option, b_service_responding, b_service_single_launch, b_service_multi_launch, "
846 "b_event_handler_click_on_button_1, b_event_handler_click_on_button_2, b_event_handler_click_on_button_3, "
847 "b_event_handler_click_on_button_4, b_event_handler_click_on_button_5, b_event_handler_click_on_button_6, "
848 "b_event_handler_click_on_icon, b_event_handler_click_on_thumbnail, "
849 "sound_type, sound_path, vibration_type, vibration_path, led_operation, led_argb, led_on_ms, led_off_ms, "
850 "flags_for_property, display_applist, progress_size, progress_percentage "
853 if (pkgname != NULL) {
854 query = sqlite3_mprintf("%s where caller_pkgname = '%s' and priv_id = %d",
855 base_query ,pkgname, priv_id);
857 query = sqlite3_mprintf("%s where priv_id = %d", base_query, priv_id);
860 ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
864 ret = sqlite3_prepare_v2(db, query, -1, &stmt, NULL);
865 if (ret != SQLITE_OK) {
866 NOTIFICATION_ERR("select Query : %s", query);
867 NOTIFICATION_ERR("select DB error(%d) : %s", ret,
869 ret = NOTIFICATION_ERROR_FROM_DB;
873 ret = sqlite3_step(stmt);
874 if (ret == SQLITE_ROW) {
875 _notification_noti_populate_from_stmt(stmt, noti);
876 ret = NOTIFICATION_ERROR_NONE;
878 ret = NOTIFICATION_ERROR_FROM_DB;
886 sqlite3_finalize(stmt);
891 notification_db_close(&db);
897 EXPORT_API int notification_noti_get_by_tag(notification_h noti, char *pkgname, char* tag)
901 sqlite3_stmt *stmt = NULL;
903 if (tag == NULL || noti == NULL) {
904 ret = NOTIFICATION_ERROR_INVALID_PARAMETER;
909 db = notification_db_open(DBPATH);
911 return get_last_result();
914 if (pkgname != NULL) {
915 ret = sqlite3_prepare_v2(db, "select "
916 "type, layout, caller_pkgname, launch_pkgname, image_path, group_id, priv_id, "
917 "tag, b_text, b_key, b_format_args, num_format_args, "
918 "text_domain, text_dir, time, insert_time, args, group_args, "
919 "b_execute_option, b_service_responding, b_service_single_launch, b_service_multi_launch, "
920 "b_event_handler_click_on_button_1, b_event_handler_click_on_button_2, b_event_handler_click_on_button_3, "
921 "b_event_handler_click_on_button_4, b_event_handler_click_on_button_5, b_event_handler_click_on_button_6, "
922 "b_event_handler_click_on_icon, b_event_handler_click_on_thumbnail, "
923 "sound_type, sound_path, vibration_type, vibration_path, led_operation, led_argb, led_on_ms, led_off_ms, "
924 "flags_for_property, display_applist, progress_size, progress_percentage "
925 "from noti_list where caller_pkgname = ? and tag = ?", -1, &stmt, NULL);
926 if (ret != SQLITE_OK) {
927 NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
928 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
931 ret = sqlite3_bind_text(stmt, 1, pkgname, -1, SQLITE_TRANSIENT);
932 if (ret != SQLITE_OK) {
933 NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
937 ret = sqlite3_bind_text(stmt, 2, tag, -1, SQLITE_TRANSIENT);
938 if (ret != SQLITE_OK) {
939 NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
943 ret = sqlite3_prepare_v2(db, "select "
944 "type, layout, caller_pkgname, launch_pkgname, image_path, group_id, priv_id, "
945 "tag, b_text, b_key, b_format_args, num_format_args, "
946 "text_domain, text_dir, time, insert_time, args, group_args, "
947 "b_execute_option, b_service_responding, b_service_single_launch, b_service_multi_launch, "
948 "b_event_handler_click_on_button_1, b_event_handler_click_on_button_2, b_event_handler_click_on_button_3, "
949 "b_event_handler_click_on_button_4, b_event_handler_click_on_button_5, b_event_handler_click_on_button_6, "
950 "b_event_handler_click_on_icon, b_event_handler_click_on_thumbnail, "
951 "sound_type, sound_path, vibration_type, vibration_path, led_operation, led_argb, led_on_ms, led_off_ms, "
952 "flags_for_property, display_applist, progress_size, progress_percentage "
953 "from noti_list where tag = ?", -1, &stmt, NULL);
954 if (ret != SQLITE_OK) {
955 NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
956 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
959 ret = sqlite3_bind_text(stmt, 1, tag, -1, SQLITE_TRANSIENT);
960 if (ret != SQLITE_OK) {
961 NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
966 ret = sqlite3_step(stmt);
967 if (ret == SQLITE_ROW) {
968 _notification_noti_populate_from_stmt(stmt, noti);
969 ret = NOTIFICATION_ERROR_NONE;
971 ret = NOTIFICATION_ERROR_FROM_DB;
976 sqlite3_finalize(stmt);
981 notification_db_close(&db);
987 EXPORT_API int notification_noti_update(notification_h noti)
991 sqlite3_stmt *stmt = NULL;
995 db = notification_db_open(DBPATH);
997 return get_last_result();
1000 /* Check private ID is exist */
1001 ret = _notification_noti_check_priv_id(noti, db);
1002 if (ret != NOTIFICATION_ERROR_ALREADY_EXIST_ID) {
1003 ret = NOTIFICATION_ERROR_NOT_EXIST_ID;
1007 /* make update query */
1008 ret = _update_query_create(noti, &query);
1009 if (ret != NOTIFICATION_ERROR_NONE) {
1013 ret = sqlite3_prepare_v2(db, query, -1, &stmt, NULL);
1014 if (ret != SQLITE_OK) {
1015 NOTIFICATION_ERR("Insert Query : %s", query);
1016 NOTIFICATION_ERR("Insert DB error(%d) : %s", ret,
1017 sqlite3_errmsg(db));
1018 ret = NOTIFICATION_ERROR_FROM_DB;
1022 ret = _notification_noti_bind_query_text(stmt, "$tag", noti->tag);
1023 if (ret != NOTIFICATION_ERROR_NONE) {
1024 NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db));
1027 ret = _notification_noti_bind_query_double(stmt, "$progress_size",noti->progress_size);
1028 if (ret != NOTIFICATION_ERROR_NONE) {
1029 NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db));
1032 ret = _notification_noti_bind_query_double(stmt, "$progress_percentage",noti->progress_percentage);
1033 if (ret != NOTIFICATION_ERROR_NONE) {
1034 NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db));
1038 ret = sqlite3_step(stmt);
1039 if (ret == SQLITE_OK || ret == SQLITE_DONE) {
1040 ret = NOTIFICATION_ERROR_NONE;
1042 ret = NOTIFICATION_ERROR_FROM_DB;
1046 sqlite3_finalize(stmt);
1051 notification_db_close(&db);
1055 sqlite3_free(query);
1061 EXPORT_API int notification_noti_delete_all(notification_type_e type, const char *pkgname, int *num_deleted, int **list_deleted_rowid)
1063 int ret = NOTIFICATION_ERROR_NONE;
1064 int ret_tmp = NOTIFICATION_ERROR_NONE;
1065 int i = 0, data_cnt = 0;
1067 sqlite3_stmt *stmt = NULL;
1068 char buf[128] = { 0, };
1069 char query[NOTIFICATION_QUERY_MAX] = { 0, };
1070 char query_base[NOTIFICATION_QUERY_MAX] = { 0, };
1071 char query_where[NOTIFICATION_QUERY_MAX] = { 0, };
1074 db = notification_db_open(DBPATH);
1076 return get_last_result();
1079 if (pkgname == NULL) {
1080 if (type != NOTIFICATION_TYPE_NONE) {
1081 snprintf(query_where, sizeof(query_where),
1082 "where type = %d ", type);
1085 if (type == NOTIFICATION_TYPE_NONE) {
1086 snprintf(query_where, sizeof(query_where),
1087 "where caller_pkgname = '%s' ", pkgname);
1089 snprintf(query_where, sizeof(query_where),
1090 "where caller_pkgname = '%s' and type = %d ",
1095 if (num_deleted != NULL) {
1098 if (list_deleted_rowid != NULL) {
1099 *list_deleted_rowid = NULL;
1100 snprintf(query, sizeof(query),
1101 "select priv_id from noti_list %s ", query_where);
1103 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
1104 if (ret != SQLITE_OK) {
1105 NOTIFICATION_ERR("Select Query : %s", query);
1106 NOTIFICATION_ERR("Select DB error(%d) : %s", ret,
1107 sqlite3_errmsg(db));
1109 ret = NOTIFICATION_ERROR_FROM_DB;
1113 while(sqlite3_step(stmt) == SQLITE_ROW) {
1114 if (data_cnt % 8 == 0) {
1117 tmp = (int *)realloc(*list_deleted_rowid, sizeof(int) * (data_cnt + 8 + 1));
1119 *list_deleted_rowid = tmp;
1121 NOTIFICATION_ERR("Heap: %d\n", errno);
1124 * How can I handle this?
1126 free(*list_deleted_rowid);
1127 *list_deleted_rowid = NULL;
1128 ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
1132 *((*list_deleted_rowid) + data_cnt) = sqlite3_column_int(stmt, 0);
1137 sqlite3_finalize(stmt);
1142 query_where[0] = '\0';
1143 snprintf(query_base, sizeof(query_base) - 1, "delete from noti_list");
1144 for (i = 0; i < data_cnt ; i++) {
1145 if (i % NOTI_BURST_DELETE_UNIT == 0 && i != 0) {
1146 snprintf(query, sizeof(query) - 1, "%s where priv_id in (%s)", query_base, query_where);
1147 ret_tmp = notification_db_exec(db, query, NULL);
1148 query_where[0] = '\0';
1149 if (ret == NOTIFICATION_ERROR_NONE) {
1153 snprintf(buf, sizeof(buf) - 1, "%s%d", (i % NOTI_BURST_DELETE_UNIT == 0) ? "" : ",", *((*list_deleted_rowid) + i));
1154 strncat(query_where, buf,sizeof(query_where) - strlen(query_where) - 1);
1156 if ((i <= NOTI_BURST_DELETE_UNIT) || ((i % NOTI_BURST_DELETE_UNIT) > 0) ) {
1157 snprintf(query, sizeof(query) - 1, "%s where priv_id in (%s)", query_base, query_where);
1158 ret_tmp = notification_db_exec(db, query, NULL);
1159 if (ret == NOTIFICATION_ERROR_NONE) {
1164 free(*list_deleted_rowid);
1165 *list_deleted_rowid = NULL;
1168 if (num_deleted != NULL) {
1169 *num_deleted = data_cnt;
1172 /* Make main query */
1173 snprintf(query_base, sizeof(query_base), "delete from noti_list ");
1174 snprintf(query, sizeof(query), "%s %s", query_base, query_where);
1176 ret = notification_db_exec(db, query, NULL);
1178 if (num_deleted != NULL) {
1179 *num_deleted = sqlite3_changes(db);
1185 sqlite3_finalize(stmt);
1189 notification_db_close(&db);
1195 int notification_noti_delete_group_by_group_id(const char *pkgname,
1196 int group_id, int *num_deleted, int **list_deleted_rowid)
1198 int ret = NOTIFICATION_ERROR_NONE;
1199 int ret_tmp = NOTIFICATION_ERROR_NONE;
1201 int i = 0, data_cnt = 0;
1202 sqlite3_stmt *stmt = NULL;
1203 char buf[128] = { 0, };
1204 char query[NOTIFICATION_QUERY_MAX] = { 0, };
1205 char query_base[NOTIFICATION_QUERY_MAX] = { 0, };
1206 char query_where[NOTIFICATION_QUERY_MAX] = { 0, };
1208 /* Check pkgname is valid */
1209 if (pkgname == NULL) {
1210 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1213 snprintf(query_where, sizeof(query_where),
1214 "where caller_pkgname = '%s' and group_id = %d", pkgname, group_id);
1217 db = notification_db_open(DBPATH);
1219 return get_last_result();
1222 if (num_deleted != NULL) {
1225 if (list_deleted_rowid != NULL) {
1226 *list_deleted_rowid = NULL;
1227 snprintf(query, sizeof(query),
1228 "select priv_id from noti_list %s ", query_where);
1230 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
1231 if (ret != SQLITE_OK) {
1232 NOTIFICATION_ERR("Select Query : %s", query);
1233 NOTIFICATION_ERR("Select DB error(%d) : %s", ret,
1234 sqlite3_errmsg(db));
1236 ret = NOTIFICATION_ERROR_FROM_DB;
1240 while(sqlite3_step(stmt) == SQLITE_ROW) {
1241 if (data_cnt % 8 == 0) {
1243 tmp = (int *)realloc(*list_deleted_rowid, sizeof(int) * (data_cnt + 8 + 1));
1245 *list_deleted_rowid = tmp;
1247 free(*list_deleted_rowid);
1248 *list_deleted_rowid = NULL;
1249 ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
1253 *((*list_deleted_rowid) + data_cnt) = sqlite3_column_int(stmt, 0);
1258 sqlite3_finalize(stmt);
1263 query_where[0] = '\0';
1264 snprintf(query_base, sizeof(query_base) - 1, "delete from noti_list");
1265 for (i = 0; i < data_cnt ; i++) {
1266 if (i % NOTI_BURST_DELETE_UNIT == 0 && i != 0) {
1267 snprintf(query, sizeof(query) - 1, "%s where priv_id in (%s)", query_base, query_where);
1268 ret_tmp = notification_db_exec(db, query, NULL);
1269 query_where[0] = '\0';
1270 if (ret == NOTIFICATION_ERROR_NONE) {
1274 snprintf(buf, sizeof(buf) - 1, "%s%d", (i % NOTI_BURST_DELETE_UNIT == 0) ? "" : ",", *((*list_deleted_rowid) + i));
1275 strncat(query_where, buf,sizeof(query_where) - strlen(query_where) - 1);
1277 if ((i <= NOTI_BURST_DELETE_UNIT) || ((i % NOTI_BURST_DELETE_UNIT) > 0) ) {
1278 snprintf(query, sizeof(query) - 1, "%s where priv_id in (%s)", query_base, query_where);
1279 ret_tmp = notification_db_exec(db, query, NULL);
1280 if (ret == NOTIFICATION_ERROR_NONE) {
1285 free(*list_deleted_rowid);
1286 *list_deleted_rowid = NULL;
1289 if (num_deleted != NULL) {
1290 *num_deleted = data_cnt;
1294 snprintf(query, sizeof(query), "delete from noti_list %s", query_where);
1297 ret = notification_db_exec(db, query, NULL);
1302 sqlite3_finalize(stmt);
1306 notification_db_close(&db);
1312 int notification_noti_delete_group_by_priv_id(const char *pkgname, int priv_id)
1315 char query[NOTIFICATION_QUERY_MAX] = { 0, };
1316 int internal_group_id = 0;
1319 /* Check pkgname is valid */
1320 if (pkgname == NULL) {
1321 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1325 db = notification_db_open(DBPATH);
1327 return get_last_result();
1330 /* Get internal group id using priv id */
1332 _notification_noti_get_internal_group_id_by_priv_id(pkgname,
1336 snprintf(query, sizeof(query), "delete from noti_list "
1337 "where caller_pkgname = '%s' and internal_group_id = %d",
1338 pkgname, internal_group_id);
1341 ret = notification_db_exec(db, query, NULL);
1344 notification_db_close(&db);
1349 EXPORT_API int notification_noti_delete_by_priv_id(const char *pkgname, int priv_id)
1352 char query[NOTIFICATION_QUERY_MAX] = { 0, };
1355 /* Check pkgname is valid */
1356 if (pkgname == NULL) {
1357 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1361 db = notification_db_open(DBPATH);
1363 return get_last_result();
1367 snprintf(query, sizeof(query), "delete from noti_list "
1368 "where caller_pkgname = '%s' and priv_id = %d", pkgname,
1372 ret = notification_db_exec(db, query, NULL);
1376 notification_db_close(&db);
1382 EXPORT_API int notification_noti_delete_by_priv_id_get_changes(const char *pkgname, int priv_id, int *num_changes)
1385 char query[NOTIFICATION_QUERY_MAX] = { 0, };
1388 /* Check pkgname is valid */
1389 if (pkgname == NULL) {
1390 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1394 db = notification_db_open(DBPATH);
1396 return get_last_result();
1400 snprintf(query, sizeof(query), "delete from noti_list "
1401 "where caller_pkgname = '%s' and priv_id = %d", pkgname,
1405 ret = notification_db_exec(db, query, num_changes);
1407 if (num_changes != NULL) {
1408 NOTIFICATION_DBG("deleted num:%d", *num_changes);
1413 notification_db_close(&db);
1419 int notification_noti_get_count(notification_type_e type,
1420 const char *pkgname,
1421 int group_id, int priv_id,
1425 sqlite3_stmt *stmt = NULL;
1426 char query[NOTIFICATION_QUERY_MAX] = { 0, };
1427 char query_base[NOTIFICATION_QUERY_MAX] = { 0, };
1428 char query_where[NOTIFICATION_QUERY_MAX] = { 0, };
1429 char query_where_more[NOTIFICATION_QUERY_MAX] = { 0, };
1431 int ret = 0, get_count = 0, internal_group_id = 0;
1432 int status = VCONFKEY_TELEPHONY_SIM_UNKNOWN;
1434 int flag_where_more = 0;
1438 db = notification_db_open(DBPATH);
1440 return get_last_result();
1443 /* Check current sim status */
1444 ret_vconf = vconf_get_int(VCONFKEY_TELEPHONY_SIM_SLOT, &status);
1447 snprintf(query_base, sizeof(query_base),
1448 "select count(*) from noti_list ");
1450 if (pkgname != NULL) {
1451 if (group_id == NOTIFICATION_GROUP_ID_NONE) {
1452 if (priv_id == NOTIFICATION_PRIV_ID_NONE) {
1453 snprintf(query_where, sizeof(query_where),
1454 "where caller_pkgname = '%s' ",
1459 _notification_noti_get_internal_group_id_by_priv_id
1460 (pkgname, priv_id, db);
1461 snprintf(query_where, sizeof(query_where),
1462 "where caller_pkgname = '%s' and internal_group_id = %d ",
1463 pkgname, internal_group_id);
1467 if (priv_id == NOTIFICATION_PRIV_ID_NONE) {
1468 snprintf(query_where, sizeof(query_where),
1469 "where caller_pkgname = '%s' and group_id = %d ",
1474 _notification_noti_get_internal_group_id_by_priv_id
1475 (pkgname, priv_id, db);
1476 snprintf(query_where, sizeof(query_where),
1477 "where caller_pkgname = '%s' and internal_group_id = %d ",
1478 pkgname, internal_group_id);
1485 if (ret_vconf == 0 && status == VCONFKEY_TELEPHONY_SIM_INSERTED) {
1486 if (type != NOTIFICATION_TYPE_NONE) {
1487 snprintf(query_where_more, sizeof(query_where_more),
1488 "type = %d ", type);
1489 flag_where_more = 1;
1492 if (type != NOTIFICATION_TYPE_NONE) {
1493 snprintf(query_where_more, sizeof(query_where_more),
1494 "type = %d and flag_simmode = 0 ", type);
1495 flag_where_more = 1;
1497 snprintf(query_where_more, sizeof(query_where_more),
1498 "flag_simmode = 0 ");
1499 flag_where_more = 1;
1503 if (flag_where == 1) {
1504 if (flag_where_more == 1) {
1505 snprintf(query, sizeof(query), "%s %s and %s",
1506 query_base, query_where, query_where_more);
1508 snprintf(query, sizeof(query), "%s %s", query_base,
1513 if (flag_where_more == 1) {
1514 snprintf(query, sizeof(query), "%s where %s",
1515 query_base, query_where_more);
1517 snprintf(query, sizeof(query), "%s", query_base);
1521 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
1522 if (ret != SQLITE_OK) {
1523 NOTIFICATION_ERR("Select Query : %s", query);
1524 NOTIFICATION_ERR("Select DB error(%d) : %s", ret,
1525 sqlite3_errmsg(db));
1527 ret = NOTIFICATION_ERROR_FROM_DB;
1531 ret = sqlite3_step(stmt);
1532 if (ret == SQLITE_ROW) {
1533 get_count = sqlite3_column_int(stmt, 0);
1536 ret = NOTIFICATION_ERROR_NONE;
1540 sqlite3_finalize(stmt);
1545 notification_db_close(&db);
1553 int notification_noti_get_grouping_list(notification_type_e type,
1555 notification_list_h *
1559 sqlite3_stmt *stmt = NULL;
1560 char query[NOTIFICATION_QUERY_MAX] = { 0, };
1561 char query_base[NOTIFICATION_QUERY_MAX] = { 0, };
1562 char query_where[NOTIFICATION_QUERY_MAX] = { 0, };
1565 notification_list_h get_list = NULL;
1566 notification_h noti = NULL;
1567 int internal_count = 0;
1571 db = notification_db_open(DBPATH);
1573 return get_last_result();
1576 /* Check current sim status */
1577 ret = vconf_get_int(VCONFKEY_TELEPHONY_SIM_SLOT, &status);
1580 snprintf(query_base, sizeof(query_base), "select "
1581 "type, layout, caller_pkgname, launch_pkgname, image_path, group_id, priv_id, "
1582 "tag, b_text, b_key, b_format_args, num_format_args, "
1583 "text_domain, text_dir, time, insert_time, args, group_args, "
1584 "b_execute_option, b_service_responding, b_service_single_launch, b_service_multi_launch, "
1585 "b_event_handler_click_on_button_1, b_event_handler_click_on_button_2, b_event_handler_click_on_button_3, "
1586 "b_event_handler_click_on_button_4, b_event_handler_click_on_button_5, b_event_handler_click_on_button_6, "
1587 "b_event_handler_click_on_icon, b_event_handler_click_on_thumbnail, "
1588 "sound_type, sound_path, vibration_type, vibration_path, led_operation, led_argb, led_on_ms, led_off_ms, "
1589 "flags_for_property, display_applist, progress_size, progress_percentage "
1592 if (status == VCONFKEY_TELEPHONY_SIM_INSERTED) {
1593 if (type != NOTIFICATION_TYPE_NONE) {
1594 snprintf(query_where, sizeof(query_where),
1595 "where type = %d ", type);
1598 if (type != NOTIFICATION_TYPE_NONE) {
1599 snprintf(query_where, sizeof(query_where),
1600 "where type = %d and flag_simmode = 0 ", type);
1602 snprintf(query_where, sizeof(query_where),
1603 "where flag_simmode = 0 ");
1607 snprintf(query, sizeof(query),
1609 "group by internal_group_id "
1610 "order by rowid desc, time desc", query_base, query_where);
1612 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
1613 if (ret != SQLITE_OK) {
1614 NOTIFICATION_ERR("Select Query : %s", query);
1615 NOTIFICATION_ERR("Select DB error(%d) : %s", ret,
1616 sqlite3_errmsg(db));
1618 ret = NOTIFICATION_ERROR_FROM_DB;
1622 while (sqlite3_step(stmt) == SQLITE_ROW) {
1623 /* Make notification list */
1624 noti = _notification_noti_get_item(stmt);
1628 get_list = notification_list_append(get_list, noti);
1630 if (count != -1 && internal_count >= count) {
1632 ("internal count %d >= count %d",
1633 internal_count, count);
1639 ret = NOTIFICATION_ERROR_NONE;
1643 sqlite3_finalize(stmt);
1648 notification_db_close(&db);
1651 if (get_list != NULL) {
1652 *list = notification_list_get_head(get_list);
1658 int notification_noti_get_detail_list(const char *pkgname,
1660 int priv_id, int count,
1661 notification_list_h *list)
1664 sqlite3_stmt *stmt = NULL;
1665 char query_base[NOTIFICATION_QUERY_MAX] = { 0, };
1666 char query_where[NOTIFICATION_QUERY_MAX] = { 0, };
1668 char query[NOTIFICATION_QUERY_MAX] = { 0, };
1670 notification_list_h get_list = NULL;
1671 notification_h noti = NULL;
1672 int internal_count = 0;
1673 int internal_group_id = 0;
1674 int status = 0; /* If the vconf_get_int failed, the status will be the garbage value */
1677 db = notification_db_open(DBPATH);
1679 return get_last_result();
1682 /* Check current sim status */
1683 ret = vconf_get_int(VCONFKEY_TELEPHONY_SIM_SLOT, &status);
1686 snprintf(query_base, sizeof(query_base), "select "
1687 "type, layout, caller_pkgname, launch_pkgname, image_path, group_id, priv_id, "
1688 "tag, b_text, b_key, b_format_args, num_format_args, "
1689 "text_domain, text_dir, time, insert_time, args, group_args, "
1690 "b_execute_option, b_service_responding, b_service_single_launch, b_service_multi_launch, "
1691 "b_event_handler_click_on_button_1, b_event_handler_click_on_button_2, b_event_handler_click_on_button_3, "
1692 "b_event_handler_click_on_button_4, b_event_handler_click_on_button_5, b_event_handler_click_on_button_6, "
1693 "b_event_handler_click_on_icon, b_event_handler_click_on_thumbnail, "
1694 "sound_type, sound_path, vibration_type, vibration_path, led_operation, led_argb, led_on_ms, led_off_ms, "
1695 "flags_for_property, display_applist, progress_size, progress_percentage "
1698 if (priv_id == NOTIFICATION_PRIV_ID_NONE && group_id == NOTIFICATION_GROUP_ID_NONE) {
1699 if (status == VCONFKEY_TELEPHONY_SIM_INSERTED) {
1700 snprintf(query_where, sizeof(query_where),
1701 "where caller_pkgname = '%s' ", pkgname);
1703 snprintf(query_where, sizeof(query_where),
1704 "where caller_pkgname = '%s' and flag_simmode = 0 ", pkgname);
1708 _notification_noti_get_internal_group_id_by_priv_id(pkgname,
1711 if (status == VCONFKEY_TELEPHONY_SIM_INSERTED) {
1712 snprintf(query_where, sizeof(query_where),
1713 "where caller_pkgname = '%s' and internal_group_id = %d ",
1714 pkgname, internal_group_id);
1716 snprintf(query_where, sizeof(query_where),
1717 "where caller_pkgname = '%s' and internal_group_id = %d and flag_simmode = 0 ",
1718 pkgname, internal_group_id);
1722 snprintf(query, sizeof(query),
1724 "order by rowid desc, time desc", query_base, query_where);
1726 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
1727 if (ret != SQLITE_OK) {
1728 NOTIFICATION_ERR("Select Query : %s", query);
1729 NOTIFICATION_ERR("Select DB error(%d) : %s", ret,
1730 sqlite3_errmsg(db));
1732 ret = NOTIFICATION_ERROR_FROM_DB;
1736 while (sqlite3_step(stmt) == SQLITE_ROW) {
1737 /* Make notification list */
1738 noti = _notification_noti_get_item(stmt);
1742 get_list = notification_list_append(get_list, noti);
1744 if (count != -1 && internal_count >= count) {
1746 ("internal count %d >= count %d",
1747 internal_count, count);
1753 ret = NOTIFICATION_ERROR_NONE;
1757 sqlite3_finalize(stmt);
1762 notification_db_close(&db);
1765 if (get_list != NULL) {
1766 *list = notification_list_get_head(get_list);
1772 EXPORT_API int notification_noti_check_tag(notification_h noti)
1775 int ret = NOTIFICATION_ERROR_NONE;
1777 sqlite3_stmt *stmt = NULL;
1779 if (noti->tag == NULL) {
1780 return NOTIFICATION_ERROR_NOT_EXIST_ID;
1784 db = notification_db_open(DBPATH);
1786 return get_last_result();
1789 ret = sqlite3_prepare_v2(db, "SELECT priv_id FROM noti_list WHERE caller_pkgname = ? and tag = ?", -1, &stmt, NULL);
1790 if (ret != SQLITE_OK) {
1791 NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
1792 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
1795 ret = sqlite3_bind_text(stmt, 1, noti->caller_pkgname, -1, SQLITE_TRANSIENT);
1796 if (ret != SQLITE_OK) {
1797 NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
1801 ret = sqlite3_bind_text(stmt, 2, noti->tag, -1, SQLITE_TRANSIENT);
1802 if (ret != SQLITE_OK) {
1803 NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
1808 query = sqlite3_mprintf("select priv_id from noti_list where caller_pkgname = '%s' and tag = '%s'",
1809 noti->caller_pkgname, noti->tag);
1810 if (query == NULL) {
1811 ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
1815 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
1816 if (ret != SQLITE_OK) {
1817 NOTIFICATION_ERR("Get priv id DB err(%d) : %s", ret,
1818 sqlite3_errmsg(db));
1819 ret = NOTIFICATION_ERROR_FROM_DB;
1823 ret = sqlite3_step(stmt);
1824 if (ret == SQLITE_ROW) {
1825 result = sqlite3_column_int(stmt, 0);
1830 sqlite3_finalize(stmt);
1832 /* If result > 0, there is priv_id in DB */
1834 noti->priv_id = result;
1835 ret = NOTIFICATION_ERROR_ALREADY_EXIST_ID;
1837 ret = NOTIFICATION_ERROR_NOT_EXIST_ID;