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 static int _notification_noti_bind_query(sqlite3_stmt * stmt, const char *name,
40 index = sqlite3_bind_parameter_index(stmt, name);
42 NOTIFICATION_ERR("Insert : invalid column name");
43 return NOTIFICATION_ERROR_FROM_DB;
47 sqlite3_bind_text(stmt, index, NOTIFICATION_CHECK_STR(str), -1,
49 if (ret != SQLITE_OK) {
50 NOTIFICATION_ERR("Insert text : %s",
51 NOTIFICATION_CHECK_STR(str));
52 return NOTIFICATION_ERROR_FROM_DB;
55 return NOTIFICATION_ERROR_NONE;
58 static int _notification_noti_check_priv_id(notification_h noti, sqlite3 * db)
60 sqlite3_stmt *stmt = NULL;
61 char query[NOTIFICATION_QUERY_MAX] = { 0, };
62 int ret = NOTIFICATION_ERROR_NONE, result = 0;
64 /* Make query to check priv_id exist */
65 snprintf(query, sizeof(query),
66 "select count(*) from noti_list where caller_pkgname = '%s' and priv_id = %d",
67 noti->caller_pkgname, noti->priv_id);
69 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
70 if (ret != SQLITE_OK) {
71 NOTIFICATION_ERR("Get count DB err(%d) : %s", ret,
73 return NOTIFICATION_ERROR_FROM_DB;
76 ret = sqlite3_step(stmt);
77 if (ret == SQLITE_ROW) {
78 result = sqlite3_column_int(stmt, 0);
83 sqlite3_finalize(stmt);
85 /* If result > 0, there is priv_id in DB */
87 return NOTIFICATION_ERROR_ALREADY_EXIST_ID;
90 return NOTIFICATION_ERROR_NONE;
93 static int _notification_noti_get_priv_id(notification_h noti, sqlite3 * db)
95 sqlite3_stmt *stmt = NULL;
96 char query[NOTIFICATION_QUERY_MAX] = { 0, };
97 int ret = NOTIFICATION_ERROR_NONE, result = 0;
99 /* Make query to get max priv_id */
100 snprintf(query, sizeof(query),
101 "select max(priv_id) from noti_list where caller_pkgname = '%s'",
102 noti->caller_pkgname);
104 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
105 if (ret != SQLITE_OK) {
106 NOTIFICATION_ERR("Get count DB err(%d) : %s", ret,
108 return NOTIFICATION_ERROR_FROM_DB;
111 ret = sqlite3_step(stmt);
112 if (ret == SQLITE_ROW) {
113 result = sqlite3_column_int(stmt, 0);
118 sqlite3_finalize(stmt);
121 return NOTIFICATION_ERROR_FROM_DB;
124 /* Increase result(max priv_id value) for next priv_id */
125 noti->priv_id = result + 1;
127 return NOTIFICATION_ERROR_NONE;
130 static int _notification_noti_get_internal_group_id_by_priv_id(const char *pkgname,
134 sqlite3_stmt *stmt = NULL;
135 char query[NOTIFICATION_QUERY_MAX] = { 0, };
136 int ret = NOTIFICATION_ERROR_NONE, result = 0;
138 snprintf(query, sizeof(query),
139 "select internal_group_id from noti_list where caller_pkgname = '%s' and priv_id = %d",
142 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
143 if (ret != SQLITE_OK) {
144 NOTIFICATION_ERR("Get count DB err(%d) : %s", ret,
146 return NOTIFICATION_ERROR_FROM_DB;
149 ret = sqlite3_step(stmt);
150 if (ret == SQLITE_ROW) {
151 result = sqlite3_column_int(stmt, 0);
156 sqlite3_finalize(stmt);
161 static int _notification_noti_get_max_internal_group_id(notification_h noti,
164 sqlite3_stmt *stmt = NULL;
165 char query[NOTIFICATION_QUERY_MAX] = { 0, };
166 int ret = NOTIFICATION_ERROR_NONE, result = 0;
168 /* Get max internal group id */
169 snprintf(query, sizeof(query),
170 "select max(internal_group_id) from noti_list");
172 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
173 if (ret != SQLITE_OK) {
174 NOTIFICATION_ERR("Get count DB err(%d) : %s", ret,
176 return NOTIFICATION_ERROR_FROM_DB;
179 ret = sqlite3_step(stmt);
180 if (ret == SQLITE_ROW) {
181 result = sqlite3_column_int(stmt, 0);
186 sqlite3_finalize(stmt);
191 static int _notification_noti_get_internal_group_id(notification_h noti,
194 sqlite3_stmt *stmt = NULL;
195 char query[NOTIFICATION_QUERY_MAX] = { 0, };
196 int ret = NOTIFICATION_ERROR_NONE, result = 0;
197 const char *ret_title = NULL;
198 char buf_key[32] = { 0, };
200 if (noti->group_id == NOTIFICATION_GROUP_ID_NONE) {
201 /* If Group ID is NONE Get max internal group ID */
202 result = _notification_noti_get_max_internal_group_id(noti, db);
204 return NOTIFICATION_ERROR_FROM_DB;
207 /* Internal Group ID is max internal group ID + 1 */
208 noti->internal_group_id = result + 1;
210 return NOTIFICATION_ERROR_NONE;
211 } else if (noti->group_id == NOTIFICATION_GROUP_ID_DEFAULT) {
212 /* If Group ID is DEFAULT, Get internal group id if it exist */
213 if (noti->b_key != NULL) {
214 snprintf(buf_key, sizeof(buf_key), "%d",
215 NOTIFICATION_TEXT_TYPE_TITLE);
217 ret_title = bundle_get_val(noti->b_key, buf_key);
220 if (ret_title == NULL && noti->b_text != NULL) {
221 snprintf(buf_key, sizeof(buf_key), "%d",
222 NOTIFICATION_TEXT_TYPE_TITLE);
224 ret_title = bundle_get_val(noti->b_text, buf_key);
227 if (ret_title == NULL) {
228 ret_title = noti->caller_pkgname;
231 snprintf(query, sizeof(query),
232 "select internal_group_id from noti_list where title_key = $title_key and group_id = %d",
233 NOTIFICATION_GROUP_ID_DEFAULT);
235 /* If Group ID is > DEFAULT, Get internal group id if it exit */
236 snprintf(query, sizeof(query),
237 "select internal_group_id from noti_list where caller_pkgname = '%s' and group_id = %d",
238 NOTIFICATION_CHECK_STR(noti->caller_pkgname),
242 ret = sqlite3_prepare_v2(db, query, -1, &stmt, NULL);
243 if (ret != SQLITE_OK) {
244 NOTIFICATION_ERR("Select Query : %s", query);
245 NOTIFICATION_ERR("Select DB error(%d) : %s", ret,
248 sqlite3_finalize(stmt);
250 return NOTIFICATION_ERROR_FROM_DB;
254 if (ret_title != NULL) {
256 _notification_noti_bind_query(stmt, "$title_key",
257 NOTIFICATION_CHECK_STR
259 if (ret != NOTIFICATION_ERROR_NONE) {
260 NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db));
262 sqlite3_finalize(stmt);
268 ret = sqlite3_step(stmt);
269 if (ret == SQLITE_ROW) {
270 result = sqlite3_column_int(stmt, 0);
272 /* If there is not internal_group_id, create new one */
273 result = _notification_noti_get_max_internal_group_id(noti, db);
277 sqlite3_finalize(stmt);
279 noti->internal_group_id = result;
281 return NOTIFICATION_ERROR_NONE;
284 static int _notification_noti_make_query(notification_h noti, char *query,
288 char *group_args = NULL;
289 char *b_image_path = NULL;
290 char *b_execute_option = NULL;
291 char *b_service_responding = NULL;
292 char *b_service_single_launch = NULL;
293 char *b_service_multi_launch = NULL;
296 char *b_format_args = NULL;
297 int flag_simmode = 0;
299 /* Decode bundle to insert DB */
301 bundle_encode(noti->args, (bundle_raw **) & args, NULL);
303 if (noti->group_args) {
304 bundle_encode(noti->group_args, (bundle_raw **) & group_args,
308 if (noti->b_execute_option) {
309 bundle_encode(noti->b_execute_option,
310 (bundle_raw **) & b_execute_option, NULL);
312 if (noti->b_service_responding) {
313 bundle_encode(noti->b_service_responding,
314 (bundle_raw **) & b_service_responding, NULL);
316 if (noti->b_service_single_launch) {
317 bundle_encode(noti->b_service_single_launch,
318 (bundle_raw **) & b_service_single_launch, NULL);
320 if (noti->b_service_multi_launch) {
321 bundle_encode(noti->b_service_multi_launch,
322 (bundle_raw **) & b_service_multi_launch, NULL);
326 bundle_encode(noti->b_text, (bundle_raw **) & b_text, NULL);
329 bundle_encode(noti->b_key, (bundle_raw **) & b_key, NULL);
331 if (noti->b_format_args) {
332 bundle_encode(noti->b_format_args,
333 (bundle_raw **) & b_format_args, NULL);
336 if (noti->b_image_path) {
337 bundle_encode(noti->b_image_path,
338 (bundle_raw **) & b_image_path, NULL);
341 /* Check only simmode property is enable */
342 if (noti->flags_for_property & NOTIFICATION_PROP_DISPLAY_ONLY_SIMMODE) {
347 snprintf(query, query_size, "insert into noti_list ("
350 "caller_pkgname, launch_pkgname, "
352 "group_id, internal_group_id, priv_id, "
354 "b_text, b_key, b_format_args, num_format_args, "
355 "text_domain, text_dir, "
356 "time, insert_time, "
359 "b_service_responding, b_service_single_launch, b_service_multi_launch, "
360 "sound_type, sound_path, vibration_type, vibration_path, "
361 "flags_for_property, flag_simmode, display_applist, "
362 "progress_size, progress_percentage) values ("
369 "'%s', '%s', '%s', %d, "
375 "%d, '%s', %d, '%s', "
380 NOTIFICATION_CHECK_STR(noti->caller_pkgname),
381 NOTIFICATION_CHECK_STR(noti->launch_pkgname),
382 NOTIFICATION_CHECK_STR(b_image_path), noti->group_id,
383 noti->internal_group_id, noti->priv_id,
384 NOTIFICATION_CHECK_STR(b_text), NOTIFICATION_CHECK_STR(b_key),
385 NOTIFICATION_CHECK_STR(b_format_args), noti->num_format_args,
386 NOTIFICATION_CHECK_STR(noti->domain),
387 NOTIFICATION_CHECK_STR(noti->dir), (int)noti->time,
388 (int)noti->insert_time, NOTIFICATION_CHECK_STR(args),
389 NOTIFICATION_CHECK_STR(group_args),
390 NOTIFICATION_CHECK_STR(b_execute_option),
391 NOTIFICATION_CHECK_STR(b_service_responding),
392 NOTIFICATION_CHECK_STR(b_service_single_launch),
393 NOTIFICATION_CHECK_STR(b_service_multi_launch),
394 noti->sound_type, NOTIFICATION_CHECK_STR(noti->sound_path),
395 noti->vibration_type,
396 NOTIFICATION_CHECK_STR(noti->vibration_path),
397 noti->flags_for_property, flag_simmode, noti->display_applist,
398 noti->progress_size, noti->progress_percentage);
400 /* Free decoded data */
408 if (b_execute_option) {
409 free(b_execute_option);
411 if (b_service_responding) {
412 free(b_service_responding);
414 if (b_service_single_launch) {
415 free(b_service_single_launch);
417 if (b_service_multi_launch) {
418 free(b_service_multi_launch);
435 return NOTIFICATION_ERROR_NONE;
439 static int _notification_noti_make_update_query(notification_h noti, char *query,
443 char *group_args = NULL;
444 char *b_image_path = NULL;
445 char *b_execute_option = NULL;
446 char *b_service_responding = NULL;
447 char *b_service_single_launch = NULL;
448 char *b_service_multi_launch = NULL;
451 char *b_format_args = NULL;
452 int flag_simmode = 0;
454 /* Decode bundle to update DB */
456 bundle_encode(noti->args, (bundle_raw **) & args, NULL);
458 if (noti->group_args) {
459 bundle_encode(noti->group_args, (bundle_raw **) & group_args,
463 if (noti->b_execute_option) {
464 bundle_encode(noti->b_execute_option,
465 (bundle_raw **) & b_execute_option, NULL);
467 if (noti->b_service_responding) {
468 bundle_encode(noti->b_service_responding,
469 (bundle_raw **) & b_service_responding, NULL);
471 if (noti->b_service_single_launch) {
472 bundle_encode(noti->b_service_single_launch,
473 (bundle_raw **) & b_service_single_launch, NULL);
475 if (noti->b_service_multi_launch) {
476 bundle_encode(noti->b_service_multi_launch,
477 (bundle_raw **) & b_service_multi_launch, NULL);
481 bundle_encode(noti->b_text, (bundle_raw **) & b_text, NULL);
484 bundle_encode(noti->b_key, (bundle_raw **) & b_key, NULL);
486 if (noti->b_format_args) {
487 bundle_encode(noti->b_format_args,
488 (bundle_raw **) & b_format_args, NULL);
491 if (noti->b_image_path) {
492 bundle_encode(noti->b_image_path,
493 (bundle_raw **) & b_image_path, NULL);
496 /* Check only simmode property is enable */
497 if (noti->flags_for_property & NOTIFICATION_PROP_DISPLAY_ONLY_SIMMODE) {
502 snprintf(query, query_size, "update noti_list set "
505 "launch_pkgname = '%s', "
506 "image_path = '%s', "
507 "b_text = '%s', b_key = '%s', "
508 "b_format_args = '%s', num_format_args = %d, "
509 "text_domain = '%s', text_dir = '%s', "
510 "time = %d, insert_time = %d, "
511 "args = '%s', group_args = '%s', "
512 "b_execute_option = '%s', "
513 "b_service_responding = '%s', "
514 "b_service_single_launch = '%s', "
515 "b_service_multi_launch = '%s', "
516 "sound_type = %d, sound_path = '%s', "
517 "vibration_type = %d, vibration_path = '%s', "
518 "flags_for_property = %d, flag_simmode = %d, "
519 "display_applist = %d, "
520 "progress_size = %f, progress_percentage = %f "
521 "where priv_id = %d ",
524 NOTIFICATION_CHECK_STR(noti->launch_pkgname),
525 NOTIFICATION_CHECK_STR(b_image_path),
526 NOTIFICATION_CHECK_STR(b_text), NOTIFICATION_CHECK_STR(b_key),
527 NOTIFICATION_CHECK_STR(b_format_args), noti->num_format_args,
528 NOTIFICATION_CHECK_STR(noti->domain),
529 NOTIFICATION_CHECK_STR(noti->dir),
530 (int)noti->time, (int)noti->insert_time,
531 NOTIFICATION_CHECK_STR(args), NOTIFICATION_CHECK_STR(group_args),
532 NOTIFICATION_CHECK_STR(b_execute_option),
533 NOTIFICATION_CHECK_STR(b_service_responding),
534 NOTIFICATION_CHECK_STR(b_service_single_launch),
535 NOTIFICATION_CHECK_STR(b_service_multi_launch),
536 noti->sound_type, NOTIFICATION_CHECK_STR(noti->sound_path),
537 noti->vibration_type,
538 NOTIFICATION_CHECK_STR(noti->vibration_path),
539 noti->flags_for_property, flag_simmode, noti->display_applist,
540 noti->progress_size, noti->progress_percentage,
543 /* Free decoded data */
551 if (b_execute_option) {
552 free(b_execute_option);
554 if (b_service_responding) {
555 free(b_service_responding);
557 if (b_service_single_launch) {
558 free(b_service_single_launch);
560 if (b_service_multi_launch) {
561 free(b_service_multi_launch);
578 return NOTIFICATION_ERROR_NONE;
581 static void _notification_noti_populate_from_stmt(sqlite3_stmt * stmt, notification_h noti) {
584 if (stmt == NULL || noti == NULL) {
588 noti->type = sqlite3_column_int(stmt, col++);
589 noti->layout = sqlite3_column_int(stmt, col++);
590 noti->caller_pkgname = notification_db_column_text(stmt, col++);
591 noti->launch_pkgname = notification_db_column_text(stmt, col++);
592 noti->b_image_path = notification_db_column_bundle(stmt, col++);
593 noti->group_id = sqlite3_column_int(stmt, col++);
594 noti->internal_group_id = 0;
595 noti->priv_id = sqlite3_column_int(stmt, col++);
597 noti->b_text = notification_db_column_bundle(stmt, col++);
598 noti->b_key = notification_db_column_bundle(stmt, col++);
599 noti->b_format_args = notification_db_column_bundle(stmt, col++);
600 noti->num_format_args = sqlite3_column_int(stmt, col++);
602 noti->domain = notification_db_column_text(stmt, col++);
603 noti->dir = notification_db_column_text(stmt, col++);
604 noti->time = sqlite3_column_int(stmt, col++);
605 noti->insert_time = sqlite3_column_int(stmt, col++);
606 noti->args = notification_db_column_bundle(stmt, col++);
607 noti->group_args = notification_db_column_bundle(stmt, col++);
609 noti->b_execute_option = notification_db_column_bundle(stmt, col++);
610 noti->b_service_responding = notification_db_column_bundle(stmt, col++);
611 noti->b_service_single_launch =
612 notification_db_column_bundle(stmt, col++);
613 noti->b_service_multi_launch =
614 notification_db_column_bundle(stmt, col++);
616 noti->sound_type = sqlite3_column_int(stmt, col++);
617 noti->sound_path = notification_db_column_text(stmt, col++);
618 noti->vibration_type = sqlite3_column_int(stmt, col++);
619 noti->vibration_path = notification_db_column_text(stmt, col++);
621 noti->flags_for_property = sqlite3_column_int(stmt, col++);
622 noti->display_applist = sqlite3_column_int(stmt, col++);
623 noti->progress_size = sqlite3_column_double(stmt, col++);
624 noti->progress_percentage = sqlite3_column_double(stmt, col++);
626 noti->app_icon_path = NULL;
627 noti->app_name = NULL;
628 noti->temp_title = NULL;
629 noti->temp_content = NULL;
632 static notification_h _notification_noti_get_item(sqlite3_stmt * stmt)
634 notification_h noti = NULL;
636 noti = malloc(sizeof(struct _notification));
641 _notification_noti_populate_from_stmt(stmt, noti);
646 int notification_noti_set_tag(const char *tag, char *value, char *buf, int buf_len)
650 len_total += (strlen(tag) * 2) + 5 + strlen(value) + 1;
652 if (buf_len <= len_total)
653 return NOTIFICATION_ERROR_INVALID_DATA;
655 snprintf(buf, buf_len, "<%s>%s</%s>", tag, value, tag);
657 return NOTIFICATION_ERROR_NONE;
660 char *notification_noti_strip_tag(const char *tagged_str)
662 if (tagged_str == NULL)
665 int len_total = strlen(tagged_str);
670 char *b_f_e = strstr(tagged_str, ">");
671 char *b_e_s = strstr(tagged_str, "</");
673 if (b_f_e == NULL || b_e_s == NULL || (b_e_s - b_f_e - 1) <= 0)
676 return strndup(b_f_e + 1, b_e_s - b_f_e - 1);
679 int notification_noti_get_tag_type(const char *tagged_str)
681 if (tagged_str == NULL)
682 return TAG_TYPE_INVALID;
684 if (strlen(tagged_str)== 0)
685 return TAG_TYPE_INVALID;
687 char *b_f_s = strstr(tagged_str, "<");
688 char *b_f_e = strstr(tagged_str, ">");
690 if (b_f_s == NULL || b_f_e == NULL || (b_f_e - b_f_s - 1) <= 0)
691 return TAG_TYPE_INVALID;
693 char *start = b_f_s + 1;
694 int len_tag = b_f_e - b_f_s - 1;
696 if (strncmp(start,TAG_TIME,len_tag) == 0) {
697 return TAG_TYPE_TIME;
700 return TAG_TYPE_INVALID;
703 static int _notification_noti_update_priv_id(sqlite3 * db, int rowid)
705 char query[128] = { 0, };
708 return NOTIFICATION_ERROR_INVALID_DATA;
711 snprintf(query, sizeof(query), "update noti_list set "
712 "priv_id = %d, internal_group_id = %d where rowid = %d",
713 rowid, rowid, rowid);
715 return notification_db_exec(db, query);
718 int notification_noti_insert(notification_h noti)
721 sqlite3_stmt *stmt = NULL;
722 char query[NOTIFICATION_QUERY_MAX] = { 0, };
724 char buf_key[32] = { 0, };
725 const char *title_key = NULL;
728 db = notification_db_open(DBPATH);
730 /* Initialize private ID */
731 noti->priv_id = NOTIFICATION_PRIV_ID_NONE;
732 noti->group_id = NOTIFICATION_GROUP_ID_NONE;
733 noti->internal_group_id = NOTIFICATION_GROUP_ID_NONE;
736 ret = _notification_noti_make_query(noti, query, sizeof(query));
737 if (ret != NOTIFICATION_ERROR_NONE) {
741 ret = sqlite3_prepare_v2(db, query, -1, &stmt, NULL);
742 if (ret != SQLITE_OK) {
743 NOTIFICATION_ERR("Insert Query : %s", query);
744 NOTIFICATION_ERR("Insert DB error(%d) : %s", ret,
746 ret = NOTIFICATION_ERROR_FROM_DB;
751 if (noti->b_key != NULL) {
752 snprintf(buf_key, sizeof(buf_key), "%d",
753 NOTIFICATION_TEXT_TYPE_TITLE);
755 title_key = bundle_get_val(noti->b_key, buf_key);
758 if (title_key == NULL && noti->b_text != NULL) {
759 snprintf(buf_key, sizeof(buf_key), "%d",
760 NOTIFICATION_TEXT_TYPE_TITLE);
762 title_key = bundle_get_val(noti->b_text, buf_key);
765 if (title_key == NULL) {
766 title_key = noti->caller_pkgname;
770 ret = _notification_noti_bind_query(stmt, "$title_key", title_key);
771 if (ret != NOTIFICATION_ERROR_NONE) {
772 NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db));
776 ret = sqlite3_step(stmt);
777 if (ret == SQLITE_OK || ret == SQLITE_DONE) {
778 noti->priv_id = (int)sqlite3_last_insert_rowid(db);
779 if (_notification_noti_update_priv_id(db, noti->priv_id) == 0) {
780 ret = NOTIFICATION_ERROR_NONE;
782 ret = NOTIFICATION_ERROR_FROM_DB;
785 ret = NOTIFICATION_ERROR_FROM_DB;
789 sqlite3_finalize(stmt);
794 notification_db_close(&db);
800 int notification_noti_get_by_priv_id(notification_h noti, char *pkgname, int priv_id)
803 sqlite3_stmt *stmt = NULL;
804 char query[NOTIFICATION_QUERY_MAX] = { 0, };
807 if (priv_id < 0 || noti == NULL) {
808 ret = NOTIFICATION_ERROR_INVALID_DATA;
813 db = notification_db_open(DBPATH);
815 char *base_query = "select "
816 "type, layout, caller_pkgname, launch_pkgname, image_path, group_id, priv_id, "
817 "b_text, b_key, b_format_args, num_format_args, "
818 "text_domain, text_dir, time, insert_time, args, group_args, "
819 "b_execute_option, b_service_responding, b_service_single_launch, b_service_multi_launch, "
820 "sound_type, sound_path, vibration_type, vibration_path, "
821 "flags_for_property, display_applist, progress_size, progress_percentage "
824 if (pkgname != NULL) {
825 snprintf(query, sizeof(query), "%s where caller_pkgname = '%s' and priv_id = %d",
826 base_query ,pkgname, priv_id);
828 snprintf(query, sizeof(query), "%s where priv_id = %d", base_query, priv_id);
831 ret = sqlite3_prepare_v2(db, query, -1, &stmt, NULL);
832 if (ret != SQLITE_OK) {
833 NOTIFICATION_ERR("select Query : %s", query);
834 NOTIFICATION_ERR("select DB error(%d) : %s", ret,
836 ret = NOTIFICATION_ERROR_FROM_DB;
840 ret = sqlite3_step(stmt);
841 if (ret == SQLITE_ROW) {
842 _notification_noti_populate_from_stmt(stmt, noti);
843 ret = NOTIFICATION_ERROR_NONE;
845 ret = NOTIFICATION_ERROR_FROM_DB;
849 sqlite3_finalize(stmt);
854 notification_db_close(&db);
860 int notification_noti_update(notification_h noti)
863 sqlite3_stmt *stmt = NULL;
864 char query[NOTIFICATION_QUERY_MAX] = { 0, };
868 db = notification_db_open(DBPATH);
870 /* Check private ID is exist */
871 ret = _notification_noti_check_priv_id(noti, db);
872 if (ret != NOTIFICATION_ERROR_ALREADY_EXIST_ID) {
873 ret = NOTIFICATION_ERROR_NOT_EXIST_ID;
877 /* make update query */
878 ret = _notification_noti_make_update_query(noti, query, sizeof(query));
879 if (ret != NOTIFICATION_ERROR_NONE) {
883 ret = sqlite3_prepare_v2(db, query, -1, &stmt, NULL);
884 if (ret != SQLITE_OK) {
885 NOTIFICATION_ERR("Insert Query : %s", query);
886 NOTIFICATION_ERR("Insert DB error(%d) : %s", ret,
888 ret = NOTIFICATION_ERROR_FROM_DB;
892 ret = sqlite3_step(stmt);
893 if (ret == SQLITE_OK || ret == SQLITE_DONE) {
894 ret = NOTIFICATION_ERROR_NONE;
896 ret = NOTIFICATION_ERROR_FROM_DB;
900 sqlite3_finalize(stmt);
905 notification_db_close(&db);
911 int notification_noti_delete_all(notification_type_e type, const char *pkgname, int *num_deleted, int **list_deleted_rowid)
913 int ret = NOTIFICATION_ERROR_NONE;
914 int i = 0, data_cnt = 0;
916 sqlite3_stmt *stmt = NULL;
917 char buf[128] = { 0, };
918 char query[NOTIFICATION_QUERY_MAX] = { 0, };
919 char query_base[NOTIFICATION_QUERY_MAX] = { 0, };
920 char query_where[NOTIFICATION_QUERY_MAX] = { 0, };
923 db = notification_db_open(DBPATH);
925 if (pkgname == NULL) {
926 if (type != NOTIFICATION_TYPE_NONE) {
927 snprintf(query_where, sizeof(query_where),
928 "where type = %d ", type);
931 if (type == NOTIFICATION_TYPE_NONE) {
932 snprintf(query_where, sizeof(query_where),
933 "where caller_pkgname = '%s' ", pkgname);
935 snprintf(query_where, sizeof(query_where),
936 "where caller_pkgname = '%s' and type = %d ",
941 if (list_deleted_rowid != NULL) {
942 *list_deleted_rowid = NULL;
943 snprintf(query, sizeof(query),
944 "select priv_id from noti_list %s ", query_where);
946 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
947 if (ret != SQLITE_OK) {
948 NOTIFICATION_ERR("Select Query : %s", query);
949 NOTIFICATION_ERR("Select DB error(%d) : %s", ret,
952 ret = NOTIFICATION_ERROR_FROM_DB;
956 while(sqlite3_step(stmt) == SQLITE_ROW) {
957 if (data_cnt % 8 == 0) {
958 *list_deleted_rowid =
959 (int *)realloc(*list_deleted_rowid, sizeof(int) * (data_cnt + 8 + 1));
961 *((*list_deleted_rowid) + data_cnt) = sqlite3_column_int(stmt, 0);
966 sqlite3_finalize(stmt);
971 query_where[0] = '\0';
972 for (i = 0; i < data_cnt ; i++) {
973 snprintf(buf, sizeof(buf), "%s%d", (i == 0) ? "" : ",", *((*list_deleted_rowid) + i));
974 strncat(query_where, buf,sizeof(query_where) - strlen(query_where) - 1);
976 snprintf(query_base, sizeof(query_base), "delete from noti_list");
977 snprintf(query, sizeof(query), "%s where priv_id in (%s)", query_base, query_where);
979 NOTIFICATION_ERR("check : %s", query);
980 notification_db_exec(db, query);
982 free(*list_deleted_rowid);
983 *list_deleted_rowid = NULL;
986 if (num_deleted != NULL) {
987 *num_deleted = data_cnt;
990 /* Make main query */
991 snprintf(query_base, sizeof(query_base), "delete from noti_list ");
992 snprintf(query, sizeof(query), "%s %s", query_base, query_where);
994 notification_db_exec(db, query);
996 if (num_deleted != NULL) {
997 *num_deleted = sqlite3_changes(db);
1003 sqlite3_finalize(stmt);
1007 notification_db_close(&db);
1013 int notification_noti_delete_group_by_group_id(const char *pkgname,
1014 int group_id, int *num_deleted, int **list_deleted_rowid)
1016 int ret = NOTIFICATION_ERROR_NONE;
1018 int i = 0, data_cnt = 0;
1019 sqlite3_stmt *stmt = NULL;
1020 char buf[128] = { 0, };
1021 char query[NOTIFICATION_QUERY_MAX] = { 0, };
1022 char query_base[NOTIFICATION_QUERY_MAX] = { 0, };
1023 char query_where[NOTIFICATION_QUERY_MAX] = { 0, };
1025 /* Check pkgname is valid */
1026 if (pkgname == NULL) {
1027 return NOTIFICATION_ERROR_INVALID_DATA;
1030 snprintf(query_where, sizeof(query_where),
1031 "where caller_pkgname = '%s' and group_id = %d", pkgname, group_id);
1034 db = notification_db_open(DBPATH);
1036 if (list_deleted_rowid != NULL) {
1037 *list_deleted_rowid = NULL;
1038 snprintf(query, sizeof(query),
1039 "select priv_id from noti_list %s ", query_where);
1041 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
1042 if (ret != SQLITE_OK) {
1043 NOTIFICATION_ERR("Select Query : %s", query);
1044 NOTIFICATION_ERR("Select DB error(%d) : %s", ret,
1045 sqlite3_errmsg(db));
1047 ret = NOTIFICATION_ERROR_FROM_DB;
1051 while(sqlite3_step(stmt) == SQLITE_ROW) {
1052 if (data_cnt % 8 == 0) {
1053 *list_deleted_rowid =
1054 (int *)realloc(*list_deleted_rowid, sizeof(int) * (data_cnt + 8 + 1));
1056 *((*list_deleted_rowid) + data_cnt) = sqlite3_column_int(stmt, 0);
1061 sqlite3_finalize(stmt);
1066 query_where[0] = '\0';
1067 for (i = 0; i < data_cnt ; i++) {
1068 snprintf(buf, sizeof(buf), "%s%d", (i == 0) ? "" : ",", *((*list_deleted_rowid) + i));
1069 strncat(query_where, buf,sizeof(query_where) - strlen(query_where) - 1);
1071 snprintf(query_base, sizeof(query_base), "delete from noti_list");
1072 snprintf(query, sizeof(query), "%s where priv_id in (%s)", query_base, query_where);
1074 NOTIFICATION_ERR("check : %s", query);
1075 notification_db_exec(db, query);
1077 free(*list_deleted_rowid);
1078 *list_deleted_rowid = NULL;
1081 if (num_deleted != NULL) {
1082 *num_deleted = data_cnt;
1086 snprintf(query, sizeof(query), "delete from noti_list %s", query_where);
1089 notification_db_exec(db, query);
1091 return NOTIFICATION_ERROR_NONE;
1096 sqlite3_finalize(stmt);
1100 notification_db_close(&db);
1106 int notification_noti_delete_group_by_priv_id(const char *pkgname, int priv_id)
1109 char query[NOTIFICATION_QUERY_MAX] = { 0, };
1110 int internal_group_id = 0;
1112 /* Check pkgname is valid */
1113 if (pkgname == NULL) {
1114 return NOTIFICATION_ERROR_INVALID_DATA;
1118 db = notification_db_open(DBPATH);
1120 /* Get internal group id using priv id */
1122 _notification_noti_get_internal_group_id_by_priv_id(pkgname,
1126 snprintf(query, sizeof(query), "delete from noti_list "
1127 "where caller_pkgname = '%s' and internal_group_id = %d",
1128 pkgname, internal_group_id);
1131 notification_db_exec(db, query);
1135 notification_db_close(&db);
1138 return NOTIFICATION_ERROR_NONE;
1141 int notification_noti_delete_by_priv_id(const char *pkgname, int priv_id)
1144 char query[NOTIFICATION_QUERY_MAX] = { 0, };
1146 /* Check pkgname is valid */
1147 if (pkgname == NULL) {
1148 return NOTIFICATION_ERROR_INVALID_DATA;
1152 db = notification_db_open(DBPATH);
1155 snprintf(query, sizeof(query), "delete from noti_list "
1156 "where caller_pkgname = '%s' and priv_id = %d", pkgname,
1160 notification_db_exec(db, query);
1164 notification_db_close(&db);
1167 return NOTIFICATION_ERROR_NONE;
1170 notification_error_e notification_noti_get_count(notification_type_e type,
1171 const char *pkgname,
1172 int group_id, int priv_id,
1176 sqlite3_stmt *stmt = NULL;
1177 char query[NOTIFICATION_QUERY_MAX] = { 0, };
1178 char query_base[NOTIFICATION_QUERY_MAX] = { 0, };
1179 char query_where[NOTIFICATION_QUERY_MAX] = { 0, };
1180 char query_where_more[NOTIFICATION_QUERY_MAX] = { 0, };
1182 int ret = 0, get_count = 0, internal_group_id = 0;
1183 int status = VCONFKEY_TELEPHONY_SIM_UNKNOWN;
1185 int flag_where_more = 0;
1189 db = notification_db_open(DBPATH);
1191 /* Check current sim status */
1192 ret_vconf = vconf_get_int(VCONFKEY_TELEPHONY_SIM_SLOT, &status);
1195 snprintf(query_base, sizeof(query_base),
1196 "select count(*) from noti_list ");
1198 if (pkgname != NULL) {
1199 if (group_id == NOTIFICATION_GROUP_ID_NONE) {
1200 if (priv_id == NOTIFICATION_PRIV_ID_NONE) {
1201 snprintf(query_where, sizeof(query_where),
1202 "where caller_pkgname = '%s' ",
1207 _notification_noti_get_internal_group_id_by_priv_id
1208 (pkgname, priv_id, db);
1209 snprintf(query_where, sizeof(query_where),
1210 "where caller_pkgname = '%s' and internal_group_id = %d ",
1211 pkgname, internal_group_id);
1215 if (priv_id == NOTIFICATION_PRIV_ID_NONE) {
1216 snprintf(query_where, sizeof(query_where),
1217 "where caller_pkgname = '%s' and group_id = %d ",
1222 _notification_noti_get_internal_group_id_by_priv_id
1223 (pkgname, priv_id, db);
1224 snprintf(query_where, sizeof(query_where),
1225 "where caller_pkgname = '%s' and internal_group_id = %d ",
1226 pkgname, internal_group_id);
1233 if (ret_vconf == 0 && status == VCONFKEY_TELEPHONY_SIM_INSERTED) {
1234 if (type != NOTIFICATION_TYPE_NONE) {
1235 snprintf(query_where_more, sizeof(query_where_more),
1236 "type = %d ", type);
1237 flag_where_more = 1;
1240 if (type != NOTIFICATION_TYPE_NONE) {
1241 snprintf(query_where_more, sizeof(query_where_more),
1242 "type = %d and flag_simmode = 0 ", type);
1243 flag_where_more = 1;
1245 snprintf(query_where_more, sizeof(query_where_more),
1246 "flag_simmode = 0 ");
1247 flag_where_more = 1;
1251 if (flag_where == 1) {
1252 if (flag_where_more == 1) {
1253 snprintf(query, sizeof(query), "%s %s and %s",
1254 query_base, query_where, query_where_more);
1256 snprintf(query, sizeof(query), "%s %s", query_base,
1261 if (flag_where_more == 1) {
1262 snprintf(query, sizeof(query), "%s where %s",
1263 query_base, query_where_more);
1265 snprintf(query, sizeof(query), "%s", query_base);
1269 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
1270 if (ret != SQLITE_OK) {
1271 NOTIFICATION_ERR("Select Query : %s", query);
1272 NOTIFICATION_ERR("Select DB error(%d) : %s", ret,
1273 sqlite3_errmsg(db));
1275 ret = NOTIFICATION_ERROR_FROM_DB;
1279 ret = sqlite3_step(stmt);
1280 if (ret == SQLITE_ROW) {
1281 get_count = sqlite3_column_int(stmt, 0);
1284 ret = NOTIFICATION_ERROR_NONE;
1288 sqlite3_finalize(stmt);
1293 notification_db_close(&db);
1301 notification_error_e notification_noti_get_grouping_list(notification_type_e type,
1303 notification_list_h *
1307 sqlite3_stmt *stmt = NULL;
1308 char query[NOTIFICATION_QUERY_MAX] = { 0, };
1309 char query_base[NOTIFICATION_QUERY_MAX] = { 0, };
1310 char query_where[NOTIFICATION_QUERY_MAX] = { 0, };
1313 notification_list_h get_list = NULL;
1314 notification_h noti = NULL;
1315 int internal_count = 0;
1319 db = notification_db_open(DBPATH);
1321 /* Check current sim status */
1322 ret = vconf_get_int(VCONFKEY_TELEPHONY_SIM_SLOT, &status);
1325 snprintf(query_base, sizeof(query_base), "select "
1326 "type, layout, caller_pkgname, launch_pkgname, image_path, group_id, priv_id, "
1327 "b_text, b_key, b_format_args, num_format_args, "
1328 "text_domain, text_dir, time, insert_time, args, group_args, "
1329 "b_execute_option, b_service_responding, b_service_single_launch, b_service_multi_launch, "
1330 "sound_type, sound_path, vibration_type, vibration_path, "
1331 "flags_for_property, display_applist, progress_size, progress_percentage "
1334 if (status == VCONFKEY_TELEPHONY_SIM_INSERTED) {
1335 if (type != NOTIFICATION_TYPE_NONE) {
1336 snprintf(query_where, sizeof(query_where),
1337 "where type = %d ", type);
1340 if (type != NOTIFICATION_TYPE_NONE) {
1341 snprintf(query_where, sizeof(query_where),
1342 "where type = %d and flag_simmode = 0 ", type);
1344 snprintf(query_where, sizeof(query_where),
1345 "where flag_simmode = 0 ");
1349 snprintf(query, sizeof(query),
1351 "group by internal_group_id "
1352 "order by rowid desc, time desc", query_base, query_where);
1354 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
1355 if (ret != SQLITE_OK) {
1356 NOTIFICATION_ERR("Select Query : %s", query);
1357 NOTIFICATION_ERR("Select DB error(%d) : %s", ret,
1358 sqlite3_errmsg(db));
1360 ret = NOTIFICATION_ERROR_FROM_DB;
1364 ret = sqlite3_step(stmt);
1365 while (ret == SQLITE_ROW) {
1366 /* Make notification list */
1367 noti = _notification_noti_get_item(stmt);
1371 get_list = notification_list_append(get_list, noti);
1373 if (count != -1 && internal_count >= count) {
1375 ("internal count %d >= count %d",
1376 internal_count, count);
1381 ret = sqlite3_step(stmt);
1384 ret = NOTIFICATION_ERROR_NONE;
1388 sqlite3_finalize(stmt);
1393 notification_db_close(&db);
1396 if (get_list != NULL) {
1397 *list = notification_list_get_head(get_list);
1403 notification_error_e notification_noti_get_detail_list(const char *pkgname,
1405 int priv_id, int count,
1406 notification_list_h *list)
1409 sqlite3_stmt *stmt = NULL;
1410 char query_base[NOTIFICATION_QUERY_MAX] = { 0, };
1411 char query_where[NOTIFICATION_QUERY_MAX] = { 0, };
1413 char query[NOTIFICATION_QUERY_MAX] = { 0, };
1415 notification_list_h get_list = NULL;
1416 notification_h noti = NULL;
1417 int internal_count = 0;
1418 int internal_group_id = 0;
1422 db = notification_db_open(DBPATH);
1424 /* Check current sim status */
1425 ret = vconf_get_int(VCONFKEY_TELEPHONY_SIM_SLOT, &status);
1428 snprintf(query_base, sizeof(query_base), "select "
1429 "type, layout, caller_pkgname, launch_pkgname, image_path, group_id, priv_id, "
1430 "b_text, b_key, b_format_args, num_format_args, "
1431 "text_domain, text_dir, time, insert_time, args, group_args, "
1432 "b_execute_option, b_service_responding, b_service_single_launch, b_service_multi_launch, "
1433 "sound_type, sound_path, vibration_type, vibration_path, "
1434 "flags_for_property, display_applist, progress_size, progress_percentage "
1437 if (priv_id == NOTIFICATION_PRIV_ID_NONE && group_id == NOTIFICATION_GROUP_ID_NONE) {
1438 if (status == VCONFKEY_TELEPHONY_SIM_INSERTED) {
1439 snprintf(query_where, sizeof(query_where),
1440 "where caller_pkgname = '%s' ",
1441 pkgname, internal_group_id);
1443 snprintf(query_where, sizeof(query_where),
1444 "where caller_pkgname = '%s' and flag_simmode = 0 ",
1445 pkgname, internal_group_id);
1449 _notification_noti_get_internal_group_id_by_priv_id(pkgname,
1452 if (status == VCONFKEY_TELEPHONY_SIM_INSERTED) {
1453 snprintf(query_where, sizeof(query_where),
1454 "where caller_pkgname = '%s' and internal_group_id = %d ",
1455 pkgname, internal_group_id);
1457 snprintf(query_where, sizeof(query_where),
1458 "where caller_pkgname = '%s' and internal_group_id = %d and flag_simmode = 0 ",
1459 pkgname, internal_group_id);
1463 snprintf(query, sizeof(query),
1465 "order by rowid desc, time desc", query_base, query_where);
1467 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
1468 if (ret != SQLITE_OK) {
1469 NOTIFICATION_ERR("Select Query : %s", query);
1470 NOTIFICATION_ERR("Select DB error(%d) : %s", ret,
1471 sqlite3_errmsg(db));
1473 ret = NOTIFICATION_ERROR_FROM_DB;
1477 ret = sqlite3_step(stmt);
1478 while (ret == SQLITE_ROW) {
1479 /* Make notification list */
1480 noti = _notification_noti_get_item(stmt);
1484 get_list = notification_list_append(get_list, noti);
1486 if (count != -1 && internal_count >= count) {
1488 ("internal count %d >= count %d",
1489 internal_count, count);
1494 ret = sqlite3_step(stmt);
1497 ret = NOTIFICATION_ERROR_NONE;
1501 sqlite3_finalize(stmt);
1506 notification_db_close(&db);
1509 if (get_list != NULL) {
1510 *list = notification_list_get_head(get_list);