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>, Youngsub Ko <ys4610.ko@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 <notification.h>
29 #include <notification_db.h>
30 #include <notification_noti.h>
31 #include <notification_debug.h>
32 #include <notification_internal.h>
34 #define NOTI_BURST_DELETE_UNIT 10
36 static void __free_and_set(void **target_ptr, void *new_ptr) {
37 if (target_ptr != NULL) {
38 if (*target_ptr != NULL) {
41 *target_ptr = new_ptr;
45 static int _notification_noti_bind_query_text(sqlite3_stmt * stmt, const char *name,
51 index = sqlite3_bind_parameter_index(stmt, name);
53 NOTIFICATION_ERR("Insert : invalid column name");
54 return NOTIFICATION_ERROR_FROM_DB;
58 sqlite3_bind_text(stmt, index, NOTIFICATION_CHECK_STR(str), -1,
60 if (ret != SQLITE_OK) {
61 NOTIFICATION_ERR("Insert text : %s",
62 NOTIFICATION_CHECK_STR(str));
63 return NOTIFICATION_ERROR_FROM_DB;
66 return NOTIFICATION_ERROR_NONE;
69 static int _notification_noti_bind_query_double(sqlite3_stmt * stmt, const char *name,
75 index = sqlite3_bind_parameter_index(stmt, name);
77 NOTIFICATION_ERR("Insert : invalid column name");
78 return NOTIFICATION_ERROR_FROM_DB;
81 ret = sqlite3_bind_double(stmt, index, val);
82 if (ret != SQLITE_OK) {
83 NOTIFICATION_ERR("Insert double : %f", val);
84 return NOTIFICATION_ERROR_FROM_DB;
87 return NOTIFICATION_ERROR_NONE;
90 static int _notification_noti_check_priv_id(notification_h noti, sqlite3 * db)
92 sqlite3_stmt *stmt = NULL;
93 char query[NOTIFICATION_QUERY_MAX] = { 0, };
94 int ret = NOTIFICATION_ERROR_NONE, result = 0;
96 /* Make query to check priv_id exist */
97 snprintf(query, sizeof(query),
98 "select count(*) from noti_list where caller_pkgname = '%s' and priv_id = %d",
99 noti->caller_pkgname, noti->priv_id);
101 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
102 if (ret != SQLITE_OK) {
103 NOTIFICATION_ERR("Get count DB err(%d) : %s", ret,
105 return NOTIFICATION_ERROR_FROM_DB;
108 ret = sqlite3_step(stmt);
109 if (ret == SQLITE_ROW) {
110 result = sqlite3_column_int(stmt, 0);
115 sqlite3_finalize(stmt);
117 /* If result > 0, there is priv_id in DB */
119 return NOTIFICATION_ERROR_ALREADY_EXIST_ID;
122 return NOTIFICATION_ERROR_NONE;
125 static int _notification_noti_get_internal_group_id_by_priv_id(const char *pkgname,
129 sqlite3_stmt *stmt = NULL;
130 char query[NOTIFICATION_QUERY_MAX] = { 0, };
131 int ret = NOTIFICATION_ERROR_NONE, result = 0;
133 snprintf(query, sizeof(query),
134 "select internal_group_id from noti_list where caller_pkgname = '%s' and priv_id = %d",
137 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
138 if (ret != SQLITE_OK) {
139 NOTIFICATION_ERR("Get count DB err(%d) : %s", ret,
141 return NOTIFICATION_ERROR_FROM_DB;
144 ret = sqlite3_step(stmt);
145 if (ret == SQLITE_ROW) {
146 result = sqlite3_column_int(stmt, 0);
151 sqlite3_finalize(stmt);
156 static int _notification_noti_make_query(notification_h noti, char *query,
160 char *group_args = NULL;
161 char *b_image_path = NULL;
162 char *b_execute_option = NULL;
163 char *b_service_responding = NULL;
164 char *b_service_single_launch = NULL;
165 char *b_service_multi_launch = NULL;
168 char *b_format_args = NULL;
169 int flag_simmode = 0;
171 /* Decode bundle to insert DB */
173 bundle_encode(noti->args, (bundle_raw **) & args, NULL);
175 if (noti->group_args) {
176 bundle_encode(noti->group_args, (bundle_raw **) & group_args,
180 if (noti->b_execute_option) {
181 bundle_encode(noti->b_execute_option,
182 (bundle_raw **) & b_execute_option, NULL);
184 if (noti->b_service_responding) {
185 bundle_encode(noti->b_service_responding,
186 (bundle_raw **) & b_service_responding, NULL);
188 if (noti->b_service_single_launch) {
189 bundle_encode(noti->b_service_single_launch,
190 (bundle_raw **) & b_service_single_launch, NULL);
192 if (noti->b_service_multi_launch) {
193 bundle_encode(noti->b_service_multi_launch,
194 (bundle_raw **) & b_service_multi_launch, NULL);
198 bundle_encode(noti->b_text, (bundle_raw **) & b_text, NULL);
201 bundle_encode(noti->b_key, (bundle_raw **) & b_key, NULL);
203 if (noti->b_format_args) {
204 bundle_encode(noti->b_format_args,
205 (bundle_raw **) & b_format_args, NULL);
208 if (noti->b_image_path) {
209 bundle_encode(noti->b_image_path,
210 (bundle_raw **) & b_image_path, NULL);
213 /* Check only simmode property is enable */
214 if (noti->flags_for_property & NOTIFICATION_PROP_DISPLAY_ONLY_SIMMODE) {
219 snprintf(query, query_size, "insert into noti_list ("
222 "caller_pkgname, launch_pkgname, "
224 "group_id, internal_group_id, priv_id, "
226 "b_text, b_key, b_format_args, num_format_args, "
227 "text_domain, text_dir, "
228 "time, insert_time, "
231 "b_service_responding, b_service_single_launch, b_service_multi_launch, "
232 "sound_type, sound_path, vibration_type, vibration_path, led_operation, led_argb, led_on_ms, led_off_ms, "
233 "flags_for_property, flag_simmode, display_applist, "
234 "progress_size, progress_percentage) values ("
241 "'%s', '%s', '%s', %d, "
247 "%d, '%s', %d, '%s', %d, %d, %d, %d,"
249 "$progress_size, $progress_percentage)",
252 NOTIFICATION_CHECK_STR(noti->caller_pkgname),
253 NOTIFICATION_CHECK_STR(noti->launch_pkgname),
254 NOTIFICATION_CHECK_STR(b_image_path), noti->group_id,
255 noti->internal_group_id, noti->priv_id,
256 NOTIFICATION_CHECK_STR(b_text), NOTIFICATION_CHECK_STR(b_key),
257 NOTIFICATION_CHECK_STR(b_format_args), noti->num_format_args,
258 NOTIFICATION_CHECK_STR(noti->domain),
259 NOTIFICATION_CHECK_STR(noti->dir), (int)noti->time,
260 (int)noti->insert_time, NOTIFICATION_CHECK_STR(args),
261 NOTIFICATION_CHECK_STR(group_args),
262 NOTIFICATION_CHECK_STR(b_execute_option),
263 NOTIFICATION_CHECK_STR(b_service_responding),
264 NOTIFICATION_CHECK_STR(b_service_single_launch),
265 NOTIFICATION_CHECK_STR(b_service_multi_launch),
266 noti->sound_type, NOTIFICATION_CHECK_STR(noti->sound_path),
267 noti->vibration_type,
268 NOTIFICATION_CHECK_STR(noti->vibration_path),
273 noti->flags_for_property, flag_simmode, noti->display_applist);
275 /* Free decoded data */
283 if (b_execute_option) {
284 free(b_execute_option);
286 if (b_service_responding) {
287 free(b_service_responding);
289 if (b_service_single_launch) {
290 free(b_service_single_launch);
292 if (b_service_multi_launch) {
293 free(b_service_multi_launch);
310 return NOTIFICATION_ERROR_NONE;
314 static int _notification_noti_make_update_query(notification_h noti, char *query,
318 char *group_args = NULL;
319 char *b_image_path = NULL;
320 char *b_execute_option = NULL;
321 char *b_service_responding = NULL;
322 char *b_service_single_launch = NULL;
323 char *b_service_multi_launch = NULL;
326 char *b_format_args = NULL;
327 int flag_simmode = 0;
329 /* Decode bundle to update DB */
331 bundle_encode(noti->args, (bundle_raw **) & args, NULL);
333 if (noti->group_args) {
334 bundle_encode(noti->group_args, (bundle_raw **) & group_args,
338 if (noti->b_execute_option) {
339 bundle_encode(noti->b_execute_option,
340 (bundle_raw **) & b_execute_option, NULL);
342 if (noti->b_service_responding) {
343 bundle_encode(noti->b_service_responding,
344 (bundle_raw **) & b_service_responding, NULL);
346 if (noti->b_service_single_launch) {
347 bundle_encode(noti->b_service_single_launch,
348 (bundle_raw **) & b_service_single_launch, NULL);
350 if (noti->b_service_multi_launch) {
351 bundle_encode(noti->b_service_multi_launch,
352 (bundle_raw **) & b_service_multi_launch, NULL);
356 bundle_encode(noti->b_text, (bundle_raw **) & b_text, NULL);
359 bundle_encode(noti->b_key, (bundle_raw **) & b_key, NULL);
361 if (noti->b_format_args) {
362 bundle_encode(noti->b_format_args,
363 (bundle_raw **) & b_format_args, NULL);
366 if (noti->b_image_path) {
367 bundle_encode(noti->b_image_path,
368 (bundle_raw **) & b_image_path, NULL);
371 /* Check only simmode property is enable */
372 if (noti->flags_for_property & NOTIFICATION_PROP_DISPLAY_ONLY_SIMMODE) {
377 snprintf(query, query_size, "update noti_list set "
380 "launch_pkgname = '%s', "
381 "image_path = '%s', "
382 "b_text = '%s', b_key = '%s', "
383 "b_format_args = '%s', num_format_args = %d, "
384 "text_domain = '%s', text_dir = '%s', "
385 "time = %d, insert_time = %d, "
386 "args = '%s', group_args = '%s', "
387 "b_execute_option = '%s', "
388 "b_service_responding = '%s', "
389 "b_service_single_launch = '%s', "
390 "b_service_multi_launch = '%s', "
391 "sound_type = %d, sound_path = '%s', "
392 "vibration_type = %d, vibration_path = '%s', "
393 "led_operation = %d, led_argb = %d, "
394 "led_on_ms = %d, led_off_ms = %d, "
395 "flags_for_property = %d, flag_simmode = %d, "
396 "display_applist = %d, "
397 "progress_size = $progress_size, progress_percentage = $progress_percentage "
398 "where priv_id = %d ",
401 NOTIFICATION_CHECK_STR(noti->launch_pkgname),
402 NOTIFICATION_CHECK_STR(b_image_path),
403 NOTIFICATION_CHECK_STR(b_text), NOTIFICATION_CHECK_STR(b_key),
404 NOTIFICATION_CHECK_STR(b_format_args), noti->num_format_args,
405 NOTIFICATION_CHECK_STR(noti->domain),
406 NOTIFICATION_CHECK_STR(noti->dir),
407 (int)noti->time, (int)noti->insert_time,
408 NOTIFICATION_CHECK_STR(args), NOTIFICATION_CHECK_STR(group_args),
409 NOTIFICATION_CHECK_STR(b_execute_option),
410 NOTIFICATION_CHECK_STR(b_service_responding),
411 NOTIFICATION_CHECK_STR(b_service_single_launch),
412 NOTIFICATION_CHECK_STR(b_service_multi_launch),
413 noti->sound_type, NOTIFICATION_CHECK_STR(noti->sound_path),
414 noti->vibration_type,
415 NOTIFICATION_CHECK_STR(noti->vibration_path),
420 noti->flags_for_property, flag_simmode, noti->display_applist,
423 /* Free decoded data */
431 if (b_execute_option) {
432 free(b_execute_option);
434 if (b_service_responding) {
435 free(b_service_responding);
437 if (b_service_single_launch) {
438 free(b_service_single_launch);
440 if (b_service_multi_launch) {
441 free(b_service_multi_launch);
458 return NOTIFICATION_ERROR_NONE;
461 static void _notification_noti_populate_from_stmt(sqlite3_stmt * stmt, notification_h noti) {
464 if (stmt == NULL || noti == NULL) {
468 noti->type = sqlite3_column_int(stmt, col++);
469 noti->layout = sqlite3_column_int(stmt, col++);
470 __free_and_set((void **)&(noti->caller_pkgname), notification_db_column_text(stmt, col++));
471 __free_and_set((void **)&(noti->launch_pkgname), notification_db_column_text(stmt, col++));
472 noti->b_image_path = notification_db_column_bundle(stmt, col++);
473 noti->group_id = sqlite3_column_int(stmt, col++);
474 noti->internal_group_id = 0;
475 noti->priv_id = sqlite3_column_int(stmt, col++);
477 noti->b_text = notification_db_column_bundle(stmt, col++);
478 noti->b_key = notification_db_column_bundle(stmt, col++);
479 noti->b_format_args = notification_db_column_bundle(stmt, col++);
480 noti->num_format_args = sqlite3_column_int(stmt, col++);
482 __free_and_set((void **)&(noti->domain), notification_db_column_text(stmt, col++));
483 __free_and_set((void **)&(noti->dir), notification_db_column_text(stmt, col++));
484 noti->time = sqlite3_column_int(stmt, col++);
485 noti->insert_time = sqlite3_column_int(stmt, col++);
486 noti->args = notification_db_column_bundle(stmt, col++);
487 noti->group_args = notification_db_column_bundle(stmt, col++);
489 noti->b_execute_option = notification_db_column_bundle(stmt, col++);
490 noti->b_service_responding = notification_db_column_bundle(stmt, col++);
491 noti->b_service_single_launch =
492 notification_db_column_bundle(stmt, col++);
493 noti->b_service_multi_launch =
494 notification_db_column_bundle(stmt, col++);
496 noti->sound_type = sqlite3_column_int(stmt, col++);
497 __free_and_set((void **)&(noti->sound_path), notification_db_column_text(stmt, col++));
498 noti->vibration_type = sqlite3_column_int(stmt, col++);
499 __free_and_set((void **)&(noti->vibration_path), notification_db_column_text(stmt, col++));
500 noti->led_operation = sqlite3_column_int(stmt, col++);
501 noti->led_argb = sqlite3_column_int(stmt, col++);
502 noti->led_on_ms = sqlite3_column_int(stmt, col++);
503 noti->led_off_ms = sqlite3_column_int(stmt, col++);
505 noti->flags_for_property = sqlite3_column_int(stmt, col++);
506 noti->display_applist = sqlite3_column_int(stmt, col++);
507 noti->progress_size = sqlite3_column_double(stmt, col++);
508 noti->progress_percentage = sqlite3_column_double(stmt, col++);
510 noti->app_icon_path = NULL;
511 noti->app_name = NULL;
512 noti->temp_title = NULL;
513 noti->temp_content = NULL;
516 static notification_h _notification_noti_get_item(sqlite3_stmt * stmt)
518 notification_h noti = NULL;
520 noti = (notification_h) calloc(1, sizeof(struct _notification));
525 _notification_noti_populate_from_stmt(stmt, noti);
530 int notification_noti_set_tag(const char *tag, char *value, char *buf, int buf_len)
534 len_total += (strlen(tag) * 2) + 5 + strlen(value) + 1;
536 if (buf_len <= len_total)
537 return NOTIFICATION_ERROR_INVALID_PARAMETER;
539 snprintf(buf, buf_len, "<%s>%s</%s>", tag, value, tag);
541 return NOTIFICATION_ERROR_NONE;
544 char *notification_noti_strip_tag(const char *tagged_str)
546 if (tagged_str == NULL)
549 int len_total = strlen(tagged_str);
554 char *b_f_e = strstr(tagged_str, ">");
555 char *b_e_s = strstr(tagged_str, "</");
557 if (b_f_e == NULL || b_e_s == NULL || (b_e_s - b_f_e - 1) <= 0)
560 return strndup(b_f_e + 1, b_e_s - b_f_e - 1);
563 int notification_noti_get_tag_type(const char *tagged_str)
565 if (tagged_str == NULL)
566 return TAG_TYPE_INVALID;
568 if (strlen(tagged_str)== 0)
569 return TAG_TYPE_INVALID;
571 char *b_f_s = strstr(tagged_str, "<");
572 char *b_f_e = strstr(tagged_str, ">");
574 if (b_f_s == NULL || b_f_e == NULL || (b_f_e - b_f_s - 1) <= 0)
575 return TAG_TYPE_INVALID;
577 char *start = b_f_s + 1;
578 int len_tag = b_f_e - b_f_s - 1;
580 if (strncmp(start,TAG_TIME,len_tag) == 0) {
581 return TAG_TYPE_TIME;
584 return TAG_TYPE_INVALID;
587 static int _notification_noti_update_priv_id(sqlite3 * db, int rowid)
589 char query[128] = { 0, };
592 return NOTIFICATION_ERROR_INVALID_PARAMETER;
595 snprintf(query, sizeof(query), "update noti_list set "
596 "priv_id = %d, internal_group_id = %d where rowid = %d",
597 rowid, rowid, rowid);
599 return notification_db_exec(db, query, NULL);
602 EXPORT_API int notification_noti_insert(notification_h noti)
605 sqlite3_stmt *stmt = NULL;
606 char query[NOTIFICATION_QUERY_MAX] = { 0, };
608 char buf_key[32] = { 0, };
609 const char *title_key = NULL;
612 db = notification_db_open(DBPATH);
614 return NOTIFICATION_ERROR_FROM_DB;
617 /* Initialize private ID */
618 noti->priv_id = NOTIFICATION_PRIV_ID_NONE;
619 noti->group_id = NOTIFICATION_GROUP_ID_NONE;
620 noti->internal_group_id = NOTIFICATION_GROUP_ID_NONE;
623 ret = _notification_noti_make_query(noti, query, sizeof(query));
624 if (ret != NOTIFICATION_ERROR_NONE) {
628 ret = sqlite3_prepare_v2(db, query, -1, &stmt, NULL);
629 if (ret != SQLITE_OK) {
630 NOTIFICATION_ERR("Insert Query : %s", query);
631 NOTIFICATION_ERR("Insert DB error(%d) : %s", ret,
633 ret = NOTIFICATION_ERROR_FROM_DB;
638 if (noti->b_key != NULL) {
639 snprintf(buf_key, sizeof(buf_key), "%d",
640 NOTIFICATION_TEXT_TYPE_TITLE);
642 title_key = bundle_get_val(noti->b_key, buf_key);
645 if (title_key == NULL && noti->b_text != NULL) {
646 snprintf(buf_key, sizeof(buf_key), "%d",
647 NOTIFICATION_TEXT_TYPE_TITLE);
649 title_key = bundle_get_val(noti->b_text, buf_key);
652 if (title_key == NULL) {
653 title_key = noti->caller_pkgname;
657 ret = _notification_noti_bind_query_text(stmt, "$title_key", title_key);
658 if (ret != NOTIFICATION_ERROR_NONE) {
659 NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db));
662 ret = _notification_noti_bind_query_double(stmt, "$progress_size",noti->progress_size);
663 if (ret != NOTIFICATION_ERROR_NONE) {
664 NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db));
666 sqlite3_finalize(stmt);
670 ret = _notification_noti_bind_query_double(stmt, "$progress_percentage",noti->progress_percentage);
671 if (ret != NOTIFICATION_ERROR_NONE) {
672 NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db));
674 sqlite3_finalize(stmt);
679 ret = sqlite3_step(stmt);
680 if (ret == SQLITE_OK || ret == SQLITE_DONE) {
681 noti->priv_id = (int)sqlite3_last_insert_rowid(db);
682 if (_notification_noti_update_priv_id(db, noti->priv_id) == 0) {
683 ret = NOTIFICATION_ERROR_NONE;
685 ret = NOTIFICATION_ERROR_FROM_DB;
688 ret = NOTIFICATION_ERROR_FROM_DB;
692 sqlite3_finalize(stmt);
697 notification_db_close(&db);
703 int notification_noti_get_by_priv_id(notification_h noti, char *pkgname, int priv_id)
706 sqlite3_stmt *stmt = NULL;
707 char query[NOTIFICATION_QUERY_MAX] = { 0, };
710 if (priv_id < 0 || noti == NULL) {
711 ret = NOTIFICATION_ERROR_INVALID_PARAMETER;
716 db = notification_db_open(DBPATH);
718 return NOTIFICATION_ERROR_FROM_DB;
721 char *base_query = "select "
722 "type, layout, caller_pkgname, launch_pkgname, image_path, group_id, priv_id, "
723 "b_text, b_key, b_format_args, num_format_args, "
724 "text_domain, text_dir, time, insert_time, args, group_args, "
725 "b_execute_option, b_service_responding, b_service_single_launch, b_service_multi_launch, "
726 "sound_type, sound_path, vibration_type, vibration_path, led_operation, led_argb, led_on_ms, led_off_ms, "
727 "flags_for_property, display_applist, progress_size, progress_percentage "
730 if (pkgname != NULL) {
731 snprintf(query, sizeof(query), "%s where caller_pkgname = '%s' and priv_id = %d",
732 base_query ,pkgname, priv_id);
734 snprintf(query, sizeof(query), "%s where priv_id = %d", base_query, priv_id);
737 ret = sqlite3_prepare_v2(db, query, -1, &stmt, NULL);
738 if (ret != SQLITE_OK) {
739 NOTIFICATION_ERR("select Query : %s", query);
740 NOTIFICATION_ERR("select DB error(%d) : %s", ret,
742 ret = NOTIFICATION_ERROR_FROM_DB;
746 ret = sqlite3_step(stmt);
747 if (ret == SQLITE_ROW) {
748 _notification_noti_populate_from_stmt(stmt, noti);
749 ret = NOTIFICATION_ERROR_NONE;
751 ret = NOTIFICATION_ERROR_FROM_DB;
755 sqlite3_finalize(stmt);
760 notification_db_close(&db);
766 EXPORT_API int notification_noti_update(notification_h noti)
769 sqlite3_stmt *stmt = NULL;
770 char query[NOTIFICATION_QUERY_MAX] = { 0, };
774 db = notification_db_open(DBPATH);
776 return NOTIFICATION_ERROR_FROM_DB;
779 /* Check private ID is exist */
780 ret = _notification_noti_check_priv_id(noti, db);
781 if (ret != NOTIFICATION_ERROR_ALREADY_EXIST_ID) {
782 ret = NOTIFICATION_ERROR_NOT_EXIST_ID;
786 /* make update query */
787 ret = _notification_noti_make_update_query(noti, query, sizeof(query));
788 if (ret != NOTIFICATION_ERROR_NONE) {
792 ret = sqlite3_prepare_v2(db, query, -1, &stmt, NULL);
793 if (ret != SQLITE_OK) {
794 NOTIFICATION_ERR("Insert Query : %s", query);
795 NOTIFICATION_ERR("Insert DB error(%d) : %s", ret,
797 ret = NOTIFICATION_ERROR_FROM_DB;
801 ret = _notification_noti_bind_query_double(stmt, "$progress_size",noti->progress_size);
802 if (ret != NOTIFICATION_ERROR_NONE) {
803 NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db));
806 ret = _notification_noti_bind_query_double(stmt, "$progress_percentage",noti->progress_percentage);
807 if (ret != NOTIFICATION_ERROR_NONE) {
808 NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db));
812 ret = sqlite3_step(stmt);
813 if (ret == SQLITE_OK || ret == SQLITE_DONE) {
814 ret = NOTIFICATION_ERROR_NONE;
816 ret = NOTIFICATION_ERROR_FROM_DB;
820 sqlite3_finalize(stmt);
825 notification_db_close(&db);
831 EXPORT_API int notification_noti_delete_all(notification_type_e type, const char *pkgname, int *num_deleted, int **list_deleted_rowid)
833 int ret = NOTIFICATION_ERROR_NONE;
834 int ret_tmp = NOTIFICATION_ERROR_NONE;
835 int i = 0, data_cnt = 0;
837 sqlite3_stmt *stmt = NULL;
838 char buf[128] = { 0, };
839 char query[NOTIFICATION_QUERY_MAX] = { 0, };
840 char query_base[NOTIFICATION_QUERY_MAX] = { 0, };
841 char query_where[NOTIFICATION_QUERY_MAX] = { 0, };
844 db = notification_db_open(DBPATH);
846 return NOTIFICATION_ERROR_FROM_DB;
849 if (pkgname == NULL) {
850 if (type != NOTIFICATION_TYPE_NONE) {
851 snprintf(query_where, sizeof(query_where),
852 "where type = %d ", type);
855 if (type == NOTIFICATION_TYPE_NONE) {
856 snprintf(query_where, sizeof(query_where),
857 "where caller_pkgname = '%s' ", pkgname);
859 snprintf(query_where, sizeof(query_where),
860 "where caller_pkgname = '%s' and type = %d ",
865 if (num_deleted != NULL) {
868 if (list_deleted_rowid != NULL) {
869 *list_deleted_rowid = NULL;
870 snprintf(query, sizeof(query),
871 "select priv_id from noti_list %s ", query_where);
873 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
874 if (ret != SQLITE_OK) {
875 NOTIFICATION_ERR("Select Query : %s", query);
876 NOTIFICATION_ERR("Select DB error(%d) : %s", ret,
879 ret = NOTIFICATION_ERROR_FROM_DB;
883 while(sqlite3_step(stmt) == SQLITE_ROW) {
884 if (data_cnt % 8 == 0) {
887 tmp = (int *)realloc(*list_deleted_rowid, sizeof(int) * (data_cnt + 8 + 1));
889 *list_deleted_rowid = tmp;
891 NOTIFICATION_ERR("Heap: %s\n", strerror(errno));
894 * How can I handle this?
896 free(*list_deleted_rowid);
897 *list_deleted_rowid = NULL;
898 ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
902 *((*list_deleted_rowid) + data_cnt) = sqlite3_column_int(stmt, 0);
907 sqlite3_finalize(stmt);
912 query_where[0] = '\0';
913 snprintf(query_base, sizeof(query_base) - 1, "delete from noti_list");
914 for (i = 0; i < data_cnt ; i++) {
915 if (i % NOTI_BURST_DELETE_UNIT == 0 && i != 0) {
916 snprintf(query, sizeof(query) - 1, "%s where priv_id in (%s)", query_base, query_where);
917 ret_tmp = notification_db_exec(db, query, NULL);
918 query_where[0] = '\0';
919 if (ret == NOTIFICATION_ERROR_NONE) {
923 snprintf(buf, sizeof(buf) - 1, "%s%d", (i % NOTI_BURST_DELETE_UNIT == 0) ? "" : ",", *((*list_deleted_rowid) + i));
924 strncat(query_where, buf,sizeof(query_where) - strlen(query_where) - 1);
926 if ((i <= NOTI_BURST_DELETE_UNIT) || ((i % NOTI_BURST_DELETE_UNIT) > 0) ) {
927 snprintf(query, sizeof(query) - 1, "%s where priv_id in (%s)", query_base, query_where);
928 ret_tmp = notification_db_exec(db, query, NULL);
929 if (ret == NOTIFICATION_ERROR_NONE) {
934 free(*list_deleted_rowid);
935 *list_deleted_rowid = NULL;
938 if (num_deleted != NULL) {
939 *num_deleted = data_cnt;
942 /* Make main query */
943 snprintf(query_base, sizeof(query_base), "delete from noti_list ");
944 snprintf(query, sizeof(query), "%s %s", query_base, query_where);
946 ret = notification_db_exec(db, query, NULL);
948 if (num_deleted != NULL) {
949 *num_deleted = sqlite3_changes(db);
955 sqlite3_finalize(stmt);
959 notification_db_close(&db);
965 int notification_noti_delete_group_by_group_id(const char *pkgname,
966 int group_id, int *num_deleted, int **list_deleted_rowid)
968 int ret = NOTIFICATION_ERROR_NONE;
969 int ret_tmp = NOTIFICATION_ERROR_NONE;
971 int i = 0, data_cnt = 0;
972 sqlite3_stmt *stmt = NULL;
973 char buf[128] = { 0, };
974 char query[NOTIFICATION_QUERY_MAX] = { 0, };
975 char query_base[NOTIFICATION_QUERY_MAX] = { 0, };
976 char query_where[NOTIFICATION_QUERY_MAX] = { 0, };
978 /* Check pkgname is valid */
979 if (pkgname == NULL) {
980 return NOTIFICATION_ERROR_INVALID_PARAMETER;
983 snprintf(query_where, sizeof(query_where),
984 "where caller_pkgname = '%s' and group_id = %d", pkgname, group_id);
987 db = notification_db_open(DBPATH);
989 return NOTIFICATION_ERROR_FROM_DB;
992 if (num_deleted != NULL) {
995 if (list_deleted_rowid != NULL) {
996 *list_deleted_rowid = NULL;
997 snprintf(query, sizeof(query),
998 "select priv_id from noti_list %s ", query_where);
1000 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
1001 if (ret != SQLITE_OK) {
1002 NOTIFICATION_ERR("Select Query : %s", query);
1003 NOTIFICATION_ERR("Select DB error(%d) : %s", ret,
1004 sqlite3_errmsg(db));
1006 ret = NOTIFICATION_ERROR_FROM_DB;
1010 while(sqlite3_step(stmt) == SQLITE_ROW) {
1011 if (data_cnt % 8 == 0) {
1013 tmp = (int *)realloc(*list_deleted_rowid, sizeof(int) * (data_cnt + 8 + 1));
1015 *list_deleted_rowid = tmp;
1017 free(*list_deleted_rowid);
1018 *list_deleted_rowid = NULL;
1019 ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
1023 *((*list_deleted_rowid) + data_cnt) = sqlite3_column_int(stmt, 0);
1028 sqlite3_finalize(stmt);
1033 query_where[0] = '\0';
1034 snprintf(query_base, sizeof(query_base) - 1, "delete from noti_list");
1035 for (i = 0; i < data_cnt ; i++) {
1036 if (i % NOTI_BURST_DELETE_UNIT == 0 && i != 0) {
1037 snprintf(query, sizeof(query) - 1, "%s where priv_id in (%s)", query_base, query_where);
1038 ret_tmp = notification_db_exec(db, query, NULL);
1039 query_where[0] = '\0';
1040 if (ret == NOTIFICATION_ERROR_NONE) {
1044 snprintf(buf, sizeof(buf) - 1, "%s%d", (i % NOTI_BURST_DELETE_UNIT == 0) ? "" : ",", *((*list_deleted_rowid) + i));
1045 strncat(query_where, buf,sizeof(query_where) - strlen(query_where) - 1);
1047 if ((i <= NOTI_BURST_DELETE_UNIT) || ((i % NOTI_BURST_DELETE_UNIT) > 0) ) {
1048 snprintf(query, sizeof(query) - 1, "%s where priv_id in (%s)", query_base, query_where);
1049 ret_tmp = notification_db_exec(db, query, NULL);
1050 if (ret == NOTIFICATION_ERROR_NONE) {
1055 free(*list_deleted_rowid);
1056 *list_deleted_rowid = NULL;
1059 if (num_deleted != NULL) {
1060 *num_deleted = data_cnt;
1064 snprintf(query, sizeof(query), "delete from noti_list %s", query_where);
1067 ret = notification_db_exec(db, query, NULL);
1072 sqlite3_finalize(stmt);
1076 notification_db_close(&db);
1082 int notification_noti_delete_group_by_priv_id(const char *pkgname, int priv_id)
1085 char query[NOTIFICATION_QUERY_MAX] = { 0, };
1086 int internal_group_id = 0;
1089 /* Check pkgname is valid */
1090 if (pkgname == NULL) {
1091 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1095 db = notification_db_open(DBPATH);
1097 return NOTIFICATION_ERROR_FROM_DB;
1100 /* Get internal group id using priv id */
1102 _notification_noti_get_internal_group_id_by_priv_id(pkgname,
1106 snprintf(query, sizeof(query), "delete from noti_list "
1107 "where caller_pkgname = '%s' and internal_group_id = %d",
1108 pkgname, internal_group_id);
1111 ret = notification_db_exec(db, query, NULL);
1114 notification_db_close(&db);
1119 EXPORT_API int notification_noti_delete_by_priv_id(const char *pkgname, int priv_id)
1122 char query[NOTIFICATION_QUERY_MAX] = { 0, };
1125 /* Check pkgname is valid */
1126 if (pkgname == NULL) {
1127 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1131 db = notification_db_open(DBPATH);
1133 return NOTIFICATION_ERROR_FROM_DB;
1137 snprintf(query, sizeof(query), "delete from noti_list "
1138 "where caller_pkgname = '%s' and priv_id = %d", pkgname,
1142 ret = notification_db_exec(db, query, NULL);
1146 notification_db_close(&db);
1152 EXPORT_API int notification_noti_delete_by_priv_id_get_changes(const char *pkgname, int priv_id, int *num_changes)
1155 char query[NOTIFICATION_QUERY_MAX] = { 0, };
1158 /* Check pkgname is valid */
1159 if (pkgname == NULL) {
1160 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1164 db = notification_db_open(DBPATH);
1166 return NOTIFICATION_ERROR_FROM_DB;
1170 snprintf(query, sizeof(query), "delete from noti_list "
1171 "where caller_pkgname = '%s' and priv_id = %d", pkgname,
1175 ret = notification_db_exec(db, query, num_changes);
1177 if (num_changes != NULL) {
1178 NOTIFICATION_DBG("deleted num:%d", *num_changes);
1183 notification_db_close(&db);
1189 notification_error_e notification_noti_get_count(notification_type_e type,
1190 const char *pkgname,
1191 int group_id, int priv_id,
1195 sqlite3_stmt *stmt = NULL;
1196 char query[NOTIFICATION_QUERY_MAX] = { 0, };
1197 char query_base[NOTIFICATION_QUERY_MAX] = { 0, };
1198 char query_where[NOTIFICATION_QUERY_MAX] = { 0, };
1199 char query_where_more[NOTIFICATION_QUERY_MAX] = { 0, };
1201 int ret = 0, get_count = 0, internal_group_id = 0;
1202 int status = VCONFKEY_TELEPHONY_SIM_UNKNOWN;
1204 int flag_where_more = 0;
1208 db = notification_db_open(DBPATH);
1210 return NOTIFICATION_ERROR_FROM_DB;
1213 /* Check current sim status */
1214 ret_vconf = vconf_get_int(VCONFKEY_TELEPHONY_SIM_SLOT, &status);
1217 snprintf(query_base, sizeof(query_base),
1218 "select count(*) from noti_list ");
1220 if (pkgname != NULL) {
1221 if (group_id == NOTIFICATION_GROUP_ID_NONE) {
1222 if (priv_id == NOTIFICATION_PRIV_ID_NONE) {
1223 snprintf(query_where, sizeof(query_where),
1224 "where caller_pkgname = '%s' ",
1229 _notification_noti_get_internal_group_id_by_priv_id
1230 (pkgname, priv_id, db);
1231 snprintf(query_where, sizeof(query_where),
1232 "where caller_pkgname = '%s' and internal_group_id = %d ",
1233 pkgname, internal_group_id);
1237 if (priv_id == NOTIFICATION_PRIV_ID_NONE) {
1238 snprintf(query_where, sizeof(query_where),
1239 "where caller_pkgname = '%s' and group_id = %d ",
1244 _notification_noti_get_internal_group_id_by_priv_id
1245 (pkgname, priv_id, db);
1246 snprintf(query_where, sizeof(query_where),
1247 "where caller_pkgname = '%s' and internal_group_id = %d ",
1248 pkgname, internal_group_id);
1255 if (ret_vconf == 0 && status == VCONFKEY_TELEPHONY_SIM_INSERTED) {
1256 if (type != NOTIFICATION_TYPE_NONE) {
1257 snprintf(query_where_more, sizeof(query_where_more),
1258 "type = %d ", type);
1259 flag_where_more = 1;
1262 if (type != NOTIFICATION_TYPE_NONE) {
1263 snprintf(query_where_more, sizeof(query_where_more),
1264 "type = %d and flag_simmode = 0 ", type);
1265 flag_where_more = 1;
1267 snprintf(query_where_more, sizeof(query_where_more),
1268 "flag_simmode = 0 ");
1269 flag_where_more = 1;
1273 if (flag_where == 1) {
1274 if (flag_where_more == 1) {
1275 snprintf(query, sizeof(query), "%s %s and %s",
1276 query_base, query_where, query_where_more);
1278 snprintf(query, sizeof(query), "%s %s", query_base,
1283 if (flag_where_more == 1) {
1284 snprintf(query, sizeof(query), "%s where %s",
1285 query_base, query_where_more);
1287 snprintf(query, sizeof(query), "%s", query_base);
1291 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
1292 if (ret != SQLITE_OK) {
1293 NOTIFICATION_ERR("Select Query : %s", query);
1294 NOTIFICATION_ERR("Select DB error(%d) : %s", ret,
1295 sqlite3_errmsg(db));
1297 ret = NOTIFICATION_ERROR_FROM_DB;
1301 ret = sqlite3_step(stmt);
1302 if (ret == SQLITE_ROW) {
1303 get_count = sqlite3_column_int(stmt, 0);
1306 ret = NOTIFICATION_ERROR_NONE;
1310 sqlite3_finalize(stmt);
1315 notification_db_close(&db);
1323 notification_error_e notification_noti_get_grouping_list(notification_type_e type,
1325 notification_list_h *
1329 sqlite3_stmt *stmt = NULL;
1330 char query[NOTIFICATION_QUERY_MAX] = { 0, };
1331 char query_base[NOTIFICATION_QUERY_MAX] = { 0, };
1332 char query_where[NOTIFICATION_QUERY_MAX] = { 0, };
1335 notification_list_h get_list = NULL;
1336 notification_h noti = NULL;
1337 int internal_count = 0;
1341 db = notification_db_open(DBPATH);
1343 return NOTIFICATION_ERROR_FROM_DB;
1346 /* Check current sim status */
1347 ret = vconf_get_int(VCONFKEY_TELEPHONY_SIM_SLOT, &status);
1350 snprintf(query_base, sizeof(query_base), "select "
1351 "type, layout, caller_pkgname, launch_pkgname, image_path, group_id, priv_id, "
1352 "b_text, b_key, b_format_args, num_format_args, "
1353 "text_domain, text_dir, time, insert_time, args, group_args, "
1354 "b_execute_option, b_service_responding, b_service_single_launch, b_service_multi_launch, "
1355 "sound_type, sound_path, vibration_type, vibration_path, led_operation, led_argb, led_on_ms, led_off_ms, "
1356 "flags_for_property, display_applist, progress_size, progress_percentage "
1359 if (status == VCONFKEY_TELEPHONY_SIM_INSERTED) {
1360 if (type != NOTIFICATION_TYPE_NONE) {
1361 snprintf(query_where, sizeof(query_where),
1362 "where type = %d ", type);
1365 if (type != NOTIFICATION_TYPE_NONE) {
1366 snprintf(query_where, sizeof(query_where),
1367 "where type = %d and flag_simmode = 0 ", type);
1369 snprintf(query_where, sizeof(query_where),
1370 "where flag_simmode = 0 ");
1374 snprintf(query, sizeof(query),
1376 "group by internal_group_id "
1377 "order by rowid desc, time desc", query_base, query_where);
1379 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
1380 if (ret != SQLITE_OK) {
1381 NOTIFICATION_ERR("Select Query : %s", query);
1382 NOTIFICATION_ERR("Select DB error(%d) : %s", ret,
1383 sqlite3_errmsg(db));
1385 ret = NOTIFICATION_ERROR_FROM_DB;
1389 while (sqlite3_step(stmt) == SQLITE_ROW) {
1390 /* Make notification list */
1391 noti = _notification_noti_get_item(stmt);
1395 get_list = notification_list_append(get_list, noti);
1397 if (count != -1 && internal_count >= count) {
1399 ("internal count %d >= count %d",
1400 internal_count, count);
1406 ret = NOTIFICATION_ERROR_NONE;
1410 sqlite3_finalize(stmt);
1415 notification_db_close(&db);
1418 if (get_list != NULL) {
1419 *list = notification_list_get_head(get_list);
1425 notification_error_e notification_noti_get_detail_list(const char *pkgname,
1427 int priv_id, int count,
1428 notification_list_h *list)
1431 sqlite3_stmt *stmt = NULL;
1432 char query_base[NOTIFICATION_QUERY_MAX] = { 0, };
1433 char query_where[NOTIFICATION_QUERY_MAX] = { 0, };
1435 char query[NOTIFICATION_QUERY_MAX] = { 0, };
1437 notification_list_h get_list = NULL;
1438 notification_h noti = NULL;
1439 int internal_count = 0;
1440 int internal_group_id = 0;
1441 int status = 0; /* If the vconf_get_int failed, the status will be the garbage value */
1444 db = notification_db_open(DBPATH);
1446 return NOTIFICATION_ERROR_FROM_DB;
1449 /* Check current sim status */
1450 ret = vconf_get_int(VCONFKEY_TELEPHONY_SIM_SLOT, &status);
1453 snprintf(query_base, sizeof(query_base), "select "
1454 "type, layout, caller_pkgname, launch_pkgname, image_path, group_id, priv_id, "
1455 "b_text, b_key, b_format_args, num_format_args, "
1456 "text_domain, text_dir, time, insert_time, args, group_args, "
1457 "b_execute_option, b_service_responding, b_service_single_launch, b_service_multi_launch, "
1458 "sound_type, sound_path, vibration_type, vibration_path, led_operation, led_argb, led_on_ms, led_off_ms, "
1459 "flags_for_property, display_applist, progress_size, progress_percentage "
1462 if (priv_id == NOTIFICATION_PRIV_ID_NONE && group_id == NOTIFICATION_GROUP_ID_NONE) {
1463 if (status == VCONFKEY_TELEPHONY_SIM_INSERTED) {
1464 snprintf(query_where, sizeof(query_where),
1465 "where caller_pkgname = '%s' ", pkgname);
1467 snprintf(query_where, sizeof(query_where),
1468 "where caller_pkgname = '%s' and flag_simmode = 0 ", pkgname);
1472 _notification_noti_get_internal_group_id_by_priv_id(pkgname,
1475 if (status == VCONFKEY_TELEPHONY_SIM_INSERTED) {
1476 snprintf(query_where, sizeof(query_where),
1477 "where caller_pkgname = '%s' and internal_group_id = %d ",
1478 pkgname, internal_group_id);
1480 snprintf(query_where, sizeof(query_where),
1481 "where caller_pkgname = '%s' and internal_group_id = %d and flag_simmode = 0 ",
1482 pkgname, internal_group_id);
1486 snprintf(query, sizeof(query),
1488 "order by rowid desc, time desc", query_base, query_where);
1490 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
1491 if (ret != SQLITE_OK) {
1492 NOTIFICATION_ERR("Select Query : %s", query);
1493 NOTIFICATION_ERR("Select DB error(%d) : %s", ret,
1494 sqlite3_errmsg(db));
1496 ret = NOTIFICATION_ERROR_FROM_DB;
1500 while (sqlite3_step(stmt) == SQLITE_ROW) {
1501 /* Make notification list */
1502 noti = _notification_noti_get_item(stmt);
1506 get_list = notification_list_append(get_list, noti);
1508 if (count != -1 && internal_count >= count) {
1510 ("internal count %d >= count %d",
1511 internal_count, count);
1517 ret = NOTIFICATION_ERROR_NONE;
1521 sqlite3_finalize(stmt);
1526 notification_db_close(&db);
1529 if (get_list != NULL) {
1530 *list = notification_list_get_head(get_list);