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)
902 sqlite3_stmt *stmt = NULL;
904 if (tag == NULL || noti == NULL) {
905 ret = NOTIFICATION_ERROR_INVALID_PARAMETER;
910 db = notification_db_open(DBPATH);
912 return get_last_result();
915 if (pkgname != NULL) {
916 ret = sqlite3_prepare_v2(db, "select "
917 "type, layout, caller_pkgname, launch_pkgname, image_path, group_id, priv_id, "
918 "tag, b_text, b_key, b_format_args, num_format_args, "
919 "text_domain, text_dir, time, insert_time, args, group_args, "
920 "b_execute_option, b_service_responding, b_service_single_launch, b_service_multi_launch, "
921 "b_event_handler_click_on_button_1, b_event_handler_click_on_button_2, b_event_handler_click_on_button_3, "
922 "b_event_handler_click_on_button_4, b_event_handler_click_on_button_5, b_event_handler_click_on_button_6, "
923 "b_event_handler_click_on_icon, b_event_handler_click_on_thumbnail, "
924 "sound_type, sound_path, vibration_type, vibration_path, led_operation, led_argb, led_on_ms, led_off_ms, "
925 "flags_for_property, display_applist, progress_size, progress_percentage "
926 "from noti_list where caller_pkgname = ? and tag = ?", -1, &stmt, NULL);
927 if (ret != SQLITE_OK) {
928 NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
929 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
932 ret = sqlite3_bind_text(stmt, 1, pkgname, -1, SQLITE_TRANSIENT);
933 if (ret != SQLITE_OK) {
934 NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
938 ret = sqlite3_bind_text(stmt, 2, tag, -1, SQLITE_TRANSIENT);
939 if (ret != SQLITE_OK) {
940 NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
944 ret = sqlite3_prepare_v2(db, "select "
945 "type, layout, caller_pkgname, launch_pkgname, image_path, group_id, priv_id, "
946 "tag, b_text, b_key, b_format_args, num_format_args, "
947 "text_domain, text_dir, time, insert_time, args, group_args, "
948 "b_execute_option, b_service_responding, b_service_single_launch, b_service_multi_launch, "
949 "b_event_handler_click_on_button_1, b_event_handler_click_on_button_2, b_event_handler_click_on_button_3, "
950 "b_event_handler_click_on_button_4, b_event_handler_click_on_button_5, b_event_handler_click_on_button_6, "
951 "b_event_handler_click_on_icon, b_event_handler_click_on_thumbnail, "
952 "sound_type, sound_path, vibration_type, vibration_path, led_operation, led_argb, led_on_ms, led_off_ms, "
953 "flags_for_property, display_applist, progress_size, progress_percentage "
954 "from noti_list where tag = ?", -1, &stmt, NULL);
955 if (ret != SQLITE_OK) {
956 NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
957 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
960 ret = sqlite3_bind_text(stmt, 1, tag, -1, SQLITE_TRANSIENT);
961 if (ret != SQLITE_OK) {
962 NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
967 char *base_query = "select "
968 "type, layout, caller_pkgname, launch_pkgname, image_path, group_id, priv_id, "
969 "tag, b_text, b_key, b_format_args, num_format_args, "
970 "text_domain, text_dir, time, insert_time, args, group_args, "
971 "b_execute_option, b_service_responding, b_service_single_launch, b_service_multi_launch, "
972 "sound_type, sound_path, vibration_type, vibration_path, led_operation, led_argb, led_on_ms, led_off_ms, "
973 "flags_for_property, display_applist, progress_size, progress_percentage "
976 if (pkgname != NULL) {
977 query = sqlite3_mprintf("%s where caller_pkgname = '%s' and tag = '%s'",
978 base_query ,pkgname, tag);
980 query = sqlite3_mprintf("%s where tag = '%s'", base_query, tag);
983 ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
987 ret = sqlite3_prepare_v2(db, query, -1, &stmt, NULL);
988 if (ret != SQLITE_OK) {
989 NOTIFICATION_ERR("select Query : %s", query);
990 NOTIFICATION_ERR("select DB error(%d) : %s", ret,
992 ret = NOTIFICATION_ERROR_FROM_DB;
996 ret = sqlite3_step(stmt);
997 if (ret == SQLITE_ROW) {
998 _notification_noti_populate_from_stmt(stmt, noti);
999 ret = NOTIFICATION_ERROR_NONE;
1001 ret = NOTIFICATION_ERROR_FROM_DB;
1005 sqlite3_free(query);
1009 sqlite3_finalize(stmt);
1014 notification_db_close(&db);
1020 EXPORT_API int notification_noti_update(notification_h noti)
1024 sqlite3_stmt *stmt = NULL;
1028 db = notification_db_open(DBPATH);
1030 return get_last_result();
1033 /* Check private ID is exist */
1034 ret = _notification_noti_check_priv_id(noti, db);
1035 if (ret != NOTIFICATION_ERROR_ALREADY_EXIST_ID) {
1036 ret = NOTIFICATION_ERROR_NOT_EXIST_ID;
1040 /* make update query */
1041 ret = _update_query_create(noti, &query);
1042 if (ret != NOTIFICATION_ERROR_NONE) {
1046 ret = sqlite3_prepare_v2(db, query, -1, &stmt, NULL);
1047 if (ret != SQLITE_OK) {
1048 NOTIFICATION_ERR("Insert Query : %s", query);
1049 NOTIFICATION_ERR("Insert DB error(%d) : %s", ret,
1050 sqlite3_errmsg(db));
1051 ret = NOTIFICATION_ERROR_FROM_DB;
1055 ret = _notification_noti_bind_query_text(stmt, "$tag", noti->tag);
1056 if (ret != NOTIFICATION_ERROR_NONE) {
1057 NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db));
1060 ret = _notification_noti_bind_query_double(stmt, "$progress_size",noti->progress_size);
1061 if (ret != NOTIFICATION_ERROR_NONE) {
1062 NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db));
1065 ret = _notification_noti_bind_query_double(stmt, "$progress_percentage",noti->progress_percentage);
1066 if (ret != NOTIFICATION_ERROR_NONE) {
1067 NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db));
1071 ret = sqlite3_step(stmt);
1072 if (ret == SQLITE_OK || ret == SQLITE_DONE) {
1073 ret = NOTIFICATION_ERROR_NONE;
1075 ret = NOTIFICATION_ERROR_FROM_DB;
1079 sqlite3_finalize(stmt);
1084 notification_db_close(&db);
1088 sqlite3_free(query);
1094 EXPORT_API int notification_noti_delete_all(notification_type_e type, const char *pkgname, int *num_deleted, int **list_deleted_rowid)
1096 int ret = NOTIFICATION_ERROR_NONE;
1097 int ret_tmp = NOTIFICATION_ERROR_NONE;
1098 int i = 0, data_cnt = 0;
1100 sqlite3_stmt *stmt = NULL;
1101 char buf[128] = { 0, };
1102 char query[NOTIFICATION_QUERY_MAX] = { 0, };
1103 char query_base[NOTIFICATION_QUERY_MAX] = { 0, };
1104 char query_where[NOTIFICATION_QUERY_MAX] = { 0, };
1107 db = notification_db_open(DBPATH);
1109 return get_last_result();
1112 if (pkgname == NULL) {
1113 if (type != NOTIFICATION_TYPE_NONE) {
1114 snprintf(query_where, sizeof(query_where),
1115 "where type = %d ", type);
1118 if (type == NOTIFICATION_TYPE_NONE) {
1119 snprintf(query_where, sizeof(query_where),
1120 "where caller_pkgname = '%s' ", pkgname);
1122 snprintf(query_where, sizeof(query_where),
1123 "where caller_pkgname = '%s' and type = %d ",
1128 if (num_deleted != NULL) {
1131 if (list_deleted_rowid != NULL) {
1132 *list_deleted_rowid = NULL;
1133 snprintf(query, sizeof(query),
1134 "select priv_id from noti_list %s ", query_where);
1136 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
1137 if (ret != SQLITE_OK) {
1138 NOTIFICATION_ERR("Select Query : %s", query);
1139 NOTIFICATION_ERR("Select DB error(%d) : %s", ret,
1140 sqlite3_errmsg(db));
1142 ret = NOTIFICATION_ERROR_FROM_DB;
1146 while(sqlite3_step(stmt) == SQLITE_ROW) {
1147 if (data_cnt % 8 == 0) {
1150 tmp = (int *)realloc(*list_deleted_rowid, sizeof(int) * (data_cnt + 8 + 1));
1152 *list_deleted_rowid = tmp;
1154 NOTIFICATION_ERR("Heap: %s\n", strerror(errno));
1157 * How can I handle this?
1159 free(*list_deleted_rowid);
1160 *list_deleted_rowid = NULL;
1161 ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
1165 *((*list_deleted_rowid) + data_cnt) = sqlite3_column_int(stmt, 0);
1170 sqlite3_finalize(stmt);
1175 query_where[0] = '\0';
1176 snprintf(query_base, sizeof(query_base) - 1, "delete from noti_list");
1177 for (i = 0; i < data_cnt ; i++) {
1178 if (i % NOTI_BURST_DELETE_UNIT == 0 && i != 0) {
1179 snprintf(query, sizeof(query) - 1, "%s where priv_id in (%s)", query_base, query_where);
1180 ret_tmp = notification_db_exec(db, query, NULL);
1181 query_where[0] = '\0';
1182 if (ret == NOTIFICATION_ERROR_NONE) {
1186 snprintf(buf, sizeof(buf) - 1, "%s%d", (i % NOTI_BURST_DELETE_UNIT == 0) ? "" : ",", *((*list_deleted_rowid) + i));
1187 strncat(query_where, buf,sizeof(query_where) - strlen(query_where) - 1);
1189 if ((i <= NOTI_BURST_DELETE_UNIT) || ((i % NOTI_BURST_DELETE_UNIT) > 0) ) {
1190 snprintf(query, sizeof(query) - 1, "%s where priv_id in (%s)", query_base, query_where);
1191 ret_tmp = notification_db_exec(db, query, NULL);
1192 if (ret == NOTIFICATION_ERROR_NONE) {
1197 free(*list_deleted_rowid);
1198 *list_deleted_rowid = NULL;
1201 if (num_deleted != NULL) {
1202 *num_deleted = data_cnt;
1205 /* Make main query */
1206 snprintf(query_base, sizeof(query_base), "delete from noti_list ");
1207 snprintf(query, sizeof(query), "%s %s", query_base, query_where);
1209 ret = notification_db_exec(db, query, NULL);
1211 if (num_deleted != NULL) {
1212 *num_deleted = sqlite3_changes(db);
1218 sqlite3_finalize(stmt);
1222 notification_db_close(&db);
1228 int notification_noti_delete_group_by_group_id(const char *pkgname,
1229 int group_id, int *num_deleted, int **list_deleted_rowid)
1231 int ret = NOTIFICATION_ERROR_NONE;
1232 int ret_tmp = NOTIFICATION_ERROR_NONE;
1234 int i = 0, data_cnt = 0;
1235 sqlite3_stmt *stmt = NULL;
1236 char buf[128] = { 0, };
1237 char query[NOTIFICATION_QUERY_MAX] = { 0, };
1238 char query_base[NOTIFICATION_QUERY_MAX] = { 0, };
1239 char query_where[NOTIFICATION_QUERY_MAX] = { 0, };
1241 /* Check pkgname is valid */
1242 if (pkgname == NULL) {
1243 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1246 snprintf(query_where, sizeof(query_where),
1247 "where caller_pkgname = '%s' and group_id = %d", pkgname, group_id);
1250 db = notification_db_open(DBPATH);
1252 return get_last_result();
1255 if (num_deleted != NULL) {
1258 if (list_deleted_rowid != NULL) {
1259 *list_deleted_rowid = NULL;
1260 snprintf(query, sizeof(query),
1261 "select priv_id from noti_list %s ", query_where);
1263 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
1264 if (ret != SQLITE_OK) {
1265 NOTIFICATION_ERR("Select Query : %s", query);
1266 NOTIFICATION_ERR("Select DB error(%d) : %s", ret,
1267 sqlite3_errmsg(db));
1269 ret = NOTIFICATION_ERROR_FROM_DB;
1273 while(sqlite3_step(stmt) == SQLITE_ROW) {
1274 if (data_cnt % 8 == 0) {
1276 tmp = (int *)realloc(*list_deleted_rowid, sizeof(int) * (data_cnt + 8 + 1));
1278 *list_deleted_rowid = tmp;
1280 free(*list_deleted_rowid);
1281 *list_deleted_rowid = NULL;
1282 ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
1286 *((*list_deleted_rowid) + data_cnt) = sqlite3_column_int(stmt, 0);
1291 sqlite3_finalize(stmt);
1296 query_where[0] = '\0';
1297 snprintf(query_base, sizeof(query_base) - 1, "delete from noti_list");
1298 for (i = 0; i < data_cnt ; i++) {
1299 if (i % NOTI_BURST_DELETE_UNIT == 0 && i != 0) {
1300 snprintf(query, sizeof(query) - 1, "%s where priv_id in (%s)", query_base, query_where);
1301 ret_tmp = notification_db_exec(db, query, NULL);
1302 query_where[0] = '\0';
1303 if (ret == NOTIFICATION_ERROR_NONE) {
1307 snprintf(buf, sizeof(buf) - 1, "%s%d", (i % NOTI_BURST_DELETE_UNIT == 0) ? "" : ",", *((*list_deleted_rowid) + i));
1308 strncat(query_where, buf,sizeof(query_where) - strlen(query_where) - 1);
1310 if ((i <= NOTI_BURST_DELETE_UNIT) || ((i % NOTI_BURST_DELETE_UNIT) > 0) ) {
1311 snprintf(query, sizeof(query) - 1, "%s where priv_id in (%s)", query_base, query_where);
1312 ret_tmp = notification_db_exec(db, query, NULL);
1313 if (ret == NOTIFICATION_ERROR_NONE) {
1318 free(*list_deleted_rowid);
1319 *list_deleted_rowid = NULL;
1322 if (num_deleted != NULL) {
1323 *num_deleted = data_cnt;
1327 snprintf(query, sizeof(query), "delete from noti_list %s", query_where);
1330 ret = notification_db_exec(db, query, NULL);
1335 sqlite3_finalize(stmt);
1339 notification_db_close(&db);
1345 int notification_noti_delete_group_by_priv_id(const char *pkgname, int priv_id)
1348 char query[NOTIFICATION_QUERY_MAX] = { 0, };
1349 int internal_group_id = 0;
1352 /* Check pkgname is valid */
1353 if (pkgname == NULL) {
1354 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1358 db = notification_db_open(DBPATH);
1360 return get_last_result();
1363 /* Get internal group id using priv id */
1365 _notification_noti_get_internal_group_id_by_priv_id(pkgname,
1369 snprintf(query, sizeof(query), "delete from noti_list "
1370 "where caller_pkgname = '%s' and internal_group_id = %d",
1371 pkgname, internal_group_id);
1374 ret = notification_db_exec(db, query, NULL);
1377 notification_db_close(&db);
1382 EXPORT_API int notification_noti_delete_by_priv_id(const char *pkgname, int priv_id)
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, NULL);
1409 notification_db_close(&db);
1415 EXPORT_API int notification_noti_delete_by_priv_id_get_changes(const char *pkgname, int priv_id, int *num_changes)
1418 char query[NOTIFICATION_QUERY_MAX] = { 0, };
1421 /* Check pkgname is valid */
1422 if (pkgname == NULL) {
1423 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1427 db = notification_db_open(DBPATH);
1429 return get_last_result();
1433 snprintf(query, sizeof(query), "delete from noti_list "
1434 "where caller_pkgname = '%s' and priv_id = %d", pkgname,
1438 ret = notification_db_exec(db, query, num_changes);
1440 if (num_changes != NULL) {
1441 NOTIFICATION_DBG("deleted num:%d", *num_changes);
1446 notification_db_close(&db);
1452 int notification_noti_get_count(notification_type_e type,
1453 const char *pkgname,
1454 int group_id, int priv_id,
1458 sqlite3_stmt *stmt = NULL;
1459 char query[NOTIFICATION_QUERY_MAX] = { 0, };
1460 char query_base[NOTIFICATION_QUERY_MAX] = { 0, };
1461 char query_where[NOTIFICATION_QUERY_MAX] = { 0, };
1462 char query_where_more[NOTIFICATION_QUERY_MAX] = { 0, };
1464 int ret = 0, get_count = 0, internal_group_id = 0;
1465 int status = VCONFKEY_TELEPHONY_SIM_UNKNOWN;
1467 int flag_where_more = 0;
1471 db = notification_db_open(DBPATH);
1473 return get_last_result();
1476 /* Check current sim status */
1477 ret_vconf = vconf_get_int(VCONFKEY_TELEPHONY_SIM_SLOT, &status);
1480 snprintf(query_base, sizeof(query_base),
1481 "select count(*) from noti_list ");
1483 if (pkgname != NULL) {
1484 if (group_id == NOTIFICATION_GROUP_ID_NONE) {
1485 if (priv_id == NOTIFICATION_PRIV_ID_NONE) {
1486 snprintf(query_where, sizeof(query_where),
1487 "where caller_pkgname = '%s' ",
1492 _notification_noti_get_internal_group_id_by_priv_id
1493 (pkgname, priv_id, db);
1494 snprintf(query_where, sizeof(query_where),
1495 "where caller_pkgname = '%s' and internal_group_id = %d ",
1496 pkgname, internal_group_id);
1500 if (priv_id == NOTIFICATION_PRIV_ID_NONE) {
1501 snprintf(query_where, sizeof(query_where),
1502 "where caller_pkgname = '%s' and group_id = %d ",
1507 _notification_noti_get_internal_group_id_by_priv_id
1508 (pkgname, priv_id, db);
1509 snprintf(query_where, sizeof(query_where),
1510 "where caller_pkgname = '%s' and internal_group_id = %d ",
1511 pkgname, internal_group_id);
1518 if (ret_vconf == 0 && status == VCONFKEY_TELEPHONY_SIM_INSERTED) {
1519 if (type != NOTIFICATION_TYPE_NONE) {
1520 snprintf(query_where_more, sizeof(query_where_more),
1521 "type = %d ", type);
1522 flag_where_more = 1;
1525 if (type != NOTIFICATION_TYPE_NONE) {
1526 snprintf(query_where_more, sizeof(query_where_more),
1527 "type = %d and flag_simmode = 0 ", type);
1528 flag_where_more = 1;
1530 snprintf(query_where_more, sizeof(query_where_more),
1531 "flag_simmode = 0 ");
1532 flag_where_more = 1;
1536 if (flag_where == 1) {
1537 if (flag_where_more == 1) {
1538 snprintf(query, sizeof(query), "%s %s and %s",
1539 query_base, query_where, query_where_more);
1541 snprintf(query, sizeof(query), "%s %s", query_base,
1546 if (flag_where_more == 1) {
1547 snprintf(query, sizeof(query), "%s where %s",
1548 query_base, query_where_more);
1550 snprintf(query, sizeof(query), "%s", query_base);
1554 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
1555 if (ret != SQLITE_OK) {
1556 NOTIFICATION_ERR("Select Query : %s", query);
1557 NOTIFICATION_ERR("Select DB error(%d) : %s", ret,
1558 sqlite3_errmsg(db));
1560 ret = NOTIFICATION_ERROR_FROM_DB;
1564 ret = sqlite3_step(stmt);
1565 if (ret == SQLITE_ROW) {
1566 get_count = sqlite3_column_int(stmt, 0);
1569 ret = NOTIFICATION_ERROR_NONE;
1573 sqlite3_finalize(stmt);
1578 notification_db_close(&db);
1586 int notification_noti_get_grouping_list(notification_type_e type,
1588 notification_list_h *
1592 sqlite3_stmt *stmt = NULL;
1593 char query[NOTIFICATION_QUERY_MAX] = { 0, };
1594 char query_base[NOTIFICATION_QUERY_MAX] = { 0, };
1595 char query_where[NOTIFICATION_QUERY_MAX] = { 0, };
1598 notification_list_h get_list = NULL;
1599 notification_h noti = NULL;
1600 int internal_count = 0;
1604 db = notification_db_open(DBPATH);
1606 return get_last_result();
1609 /* Check current sim status */
1610 ret = vconf_get_int(VCONFKEY_TELEPHONY_SIM_SLOT, &status);
1613 snprintf(query_base, sizeof(query_base), "select "
1614 "type, layout, caller_pkgname, launch_pkgname, image_path, group_id, priv_id, "
1615 "tag, b_text, b_key, b_format_args, num_format_args, "
1616 "text_domain, text_dir, time, insert_time, args, group_args, "
1617 "b_execute_option, b_service_responding, b_service_single_launch, b_service_multi_launch, "
1618 "b_event_handler_click_on_button_1, b_event_handler_click_on_button_2, b_event_handler_click_on_button_3, "
1619 "b_event_handler_click_on_button_4, b_event_handler_click_on_button_5, b_event_handler_click_on_button_6, "
1620 "b_event_handler_click_on_icon, b_event_handler_click_on_thumbnail, "
1621 "sound_type, sound_path, vibration_type, vibration_path, led_operation, led_argb, led_on_ms, led_off_ms, "
1622 "flags_for_property, display_applist, progress_size, progress_percentage "
1625 if (status == VCONFKEY_TELEPHONY_SIM_INSERTED) {
1626 if (type != NOTIFICATION_TYPE_NONE) {
1627 snprintf(query_where, sizeof(query_where),
1628 "where type = %d ", type);
1631 if (type != NOTIFICATION_TYPE_NONE) {
1632 snprintf(query_where, sizeof(query_where),
1633 "where type = %d and flag_simmode = 0 ", type);
1635 snprintf(query_where, sizeof(query_where),
1636 "where flag_simmode = 0 ");
1640 snprintf(query, sizeof(query),
1642 "group by internal_group_id "
1643 "order by rowid desc, time desc", query_base, query_where);
1645 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
1646 if (ret != SQLITE_OK) {
1647 NOTIFICATION_ERR("Select Query : %s", query);
1648 NOTIFICATION_ERR("Select DB error(%d) : %s", ret,
1649 sqlite3_errmsg(db));
1651 ret = NOTIFICATION_ERROR_FROM_DB;
1655 while (sqlite3_step(stmt) == SQLITE_ROW) {
1656 /* Make notification list */
1657 noti = _notification_noti_get_item(stmt);
1661 get_list = notification_list_append(get_list, noti);
1663 if (count != -1 && internal_count >= count) {
1665 ("internal count %d >= count %d",
1666 internal_count, count);
1672 ret = NOTIFICATION_ERROR_NONE;
1676 sqlite3_finalize(stmt);
1681 notification_db_close(&db);
1684 if (get_list != NULL) {
1685 *list = notification_list_get_head(get_list);
1691 int notification_noti_get_detail_list(const char *pkgname,
1693 int priv_id, int count,
1694 notification_list_h *list)
1697 sqlite3_stmt *stmt = NULL;
1698 char query_base[NOTIFICATION_QUERY_MAX] = { 0, };
1699 char query_where[NOTIFICATION_QUERY_MAX] = { 0, };
1701 char query[NOTIFICATION_QUERY_MAX] = { 0, };
1703 notification_list_h get_list = NULL;
1704 notification_h noti = NULL;
1705 int internal_count = 0;
1706 int internal_group_id = 0;
1707 int status = 0; /* If the vconf_get_int failed, the status will be the garbage value */
1710 db = notification_db_open(DBPATH);
1712 return get_last_result();
1715 /* Check current sim status */
1716 ret = vconf_get_int(VCONFKEY_TELEPHONY_SIM_SLOT, &status);
1719 snprintf(query_base, sizeof(query_base), "select "
1720 "type, layout, caller_pkgname, launch_pkgname, image_path, group_id, priv_id, "
1721 "tag, b_text, b_key, b_format_args, num_format_args, "
1722 "text_domain, text_dir, time, insert_time, args, group_args, "
1723 "b_execute_option, b_service_responding, b_service_single_launch, b_service_multi_launch, "
1724 "b_event_handler_click_on_button_1, b_event_handler_click_on_button_2, b_event_handler_click_on_button_3, "
1725 "b_event_handler_click_on_button_4, b_event_handler_click_on_button_5, b_event_handler_click_on_button_6, "
1726 "b_event_handler_click_on_icon, b_event_handler_click_on_thumbnail, "
1727 "sound_type, sound_path, vibration_type, vibration_path, led_operation, led_argb, led_on_ms, led_off_ms, "
1728 "flags_for_property, display_applist, progress_size, progress_percentage "
1731 if (priv_id == NOTIFICATION_PRIV_ID_NONE && group_id == NOTIFICATION_GROUP_ID_NONE) {
1732 if (status == VCONFKEY_TELEPHONY_SIM_INSERTED) {
1733 snprintf(query_where, sizeof(query_where),
1734 "where caller_pkgname = '%s' ", pkgname);
1736 snprintf(query_where, sizeof(query_where),
1737 "where caller_pkgname = '%s' and flag_simmode = 0 ", pkgname);
1741 _notification_noti_get_internal_group_id_by_priv_id(pkgname,
1744 if (status == VCONFKEY_TELEPHONY_SIM_INSERTED) {
1745 snprintf(query_where, sizeof(query_where),
1746 "where caller_pkgname = '%s' and internal_group_id = %d ",
1747 pkgname, internal_group_id);
1749 snprintf(query_where, sizeof(query_where),
1750 "where caller_pkgname = '%s' and internal_group_id = %d and flag_simmode = 0 ",
1751 pkgname, internal_group_id);
1755 snprintf(query, sizeof(query),
1757 "order by rowid desc, time desc", query_base, query_where);
1759 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
1760 if (ret != SQLITE_OK) {
1761 NOTIFICATION_ERR("Select Query : %s", query);
1762 NOTIFICATION_ERR("Select DB error(%d) : %s", ret,
1763 sqlite3_errmsg(db));
1765 ret = NOTIFICATION_ERROR_FROM_DB;
1769 while (sqlite3_step(stmt) == SQLITE_ROW) {
1770 /* Make notification list */
1771 noti = _notification_noti_get_item(stmt);
1775 get_list = notification_list_append(get_list, noti);
1777 if (count != -1 && internal_count >= count) {
1779 ("internal count %d >= count %d",
1780 internal_count, count);
1786 ret = NOTIFICATION_ERROR_NONE;
1790 sqlite3_finalize(stmt);
1795 notification_db_close(&db);
1798 if (get_list != NULL) {
1799 *list = notification_list_get_head(get_list);
1805 EXPORT_API int notification_noti_check_tag(notification_h noti)
1808 int ret = NOTIFICATION_ERROR_NONE;
1811 sqlite3_stmt *stmt = NULL;
1813 if (noti->tag == NULL) {
1814 return NOTIFICATION_ERROR_NOT_EXIST_ID;
1818 db = notification_db_open(DBPATH);
1820 return get_last_result();
1823 ret = sqlite3_prepare_v2(db, "SELECT priv_id FROM noti_list WHERE caller_pkgname = ? and tag = ?", -1, &stmt, NULL);
1824 if (ret != SQLITE_OK) {
1825 NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
1826 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
1829 ret = sqlite3_bind_text(stmt, 1, noti->caller_pkgname, -1, SQLITE_TRANSIENT);
1830 if (ret != SQLITE_OK) {
1831 NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
1835 ret = sqlite3_bind_text(stmt, 2, noti->tag, -1, SQLITE_TRANSIENT);
1836 if (ret != SQLITE_OK) {
1837 NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
1842 query = sqlite3_mprintf("select priv_id from noti_list where caller_pkgname = '%s' and tag = '%s'",
1843 noti->caller_pkgname, noti->tag);
1844 if (query == NULL) {
1845 ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
1849 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
1850 if (ret != SQLITE_OK) {
1851 NOTIFICATION_ERR("Get priv id DB err(%d) : %s", ret,
1852 sqlite3_errmsg(db));
1853 ret = NOTIFICATION_ERROR_FROM_DB;
1857 ret = sqlite3_step(stmt);
1858 if (ret == SQLITE_ROW) {
1859 result = sqlite3_column_int(stmt, 0);
1864 sqlite3_finalize(stmt);
1866 /* If result > 0, there is priv_id in DB */
1868 noti->priv_id = result;
1869 ret = NOTIFICATION_ERROR_ALREADY_EXIST_ID;
1871 ret = NOTIFICATION_ERROR_NOT_EXIST_ID;
1876 sqlite3_free(query);