Merge branch 'tizen_2.4' of ssh://spin:29418/apps/home/notification into tizen
[platform/core/api/notification.git] / src / notification_noti.c
1 /*
2  *  libnotification
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Seungtaek Chung <seungtaek.chung@samsung.com>, Mi-Ju Lee <miju52.lee@samsung.com>, Xi Zhichan <zhichan.xi@samsung.com>
7  *
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
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
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.
19  *
20  */
21
22 #include <stdio.h>
23 #include <string.h>
24 #include <stdlib.h>
25
26 #include <vconf.h>
27 #include <Ecore.h>
28 #include <Elementary.h>
29 #include <Eina.h>
30
31 #include <notification.h>
32 #include <notification_db.h>
33 #include <notification_noti.h>
34 #include <notification_debug.h>
35 #include <notification_private.h>
36
37 #define NOTI_BURST_DELETE_UNIT 10
38
39 static void __free_and_set(void **target_ptr, void *new_ptr) {
40         if (target_ptr != NULL) {
41                 if (*target_ptr != NULL) {
42                         free(*target_ptr);
43                 }
44                 *target_ptr = new_ptr;
45         }
46 }
47
48 static int _notification_noti_bind_query_text(sqlite3_stmt * stmt, const char *name,
49                                          const char *str)
50 {
51         int ret = 0;
52         int index = 0;
53
54         index = sqlite3_bind_parameter_index(stmt, name);
55         if (index == 0) {
56                 NOTIFICATION_ERR("Insert : invalid column name");
57                 return NOTIFICATION_ERROR_FROM_DB;
58         }
59
60         ret =
61             sqlite3_bind_text(stmt, index, NOTIFICATION_CHECK_STR(str), -1,
62                               SQLITE_STATIC);
63         if (ret != SQLITE_OK) {
64                 NOTIFICATION_ERR("Insert text : %s",
65                                  NOTIFICATION_CHECK_STR(str));
66                 return NOTIFICATION_ERROR_FROM_DB;
67         }
68
69         return NOTIFICATION_ERROR_NONE;
70 }
71
72 static int _notification_noti_bind_query_double(sqlite3_stmt * stmt, const char *name,
73                                          double val)
74 {
75         int ret = 0;
76         int index = 0;
77
78         index = sqlite3_bind_parameter_index(stmt, name);
79         if (index == 0) {
80                 NOTIFICATION_ERR("Insert : invalid column name");
81                 return NOTIFICATION_ERROR_FROM_DB;
82         }
83
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;
88         }
89
90         return NOTIFICATION_ERROR_NONE;
91 }
92
93 static int _notification_noti_check_priv_id(notification_h noti, sqlite3 * db)
94 {
95         int result = 0;
96         int ret = NOTIFICATION_ERROR_NONE;
97         char *query = NULL;
98         sqlite3_stmt *stmt = NULL;
99
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);
103         if (query == NULL) {
104                 ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
105                 goto err;
106         }
107
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,
111                                  sqlite3_errmsg(db));
112                 ret = NOTIFICATION_ERROR_FROM_DB;
113                 goto err;
114         }
115
116         ret = sqlite3_step(stmt);
117         if (ret == SQLITE_ROW) {
118                 result = sqlite3_column_int(stmt, 0);
119         } else {
120                 result = 0;
121         }
122
123         sqlite3_finalize(stmt);
124
125         /* If result > 0, there is priv_id in DB */
126         if (result > 0) {
127                 ret = NOTIFICATION_ERROR_ALREADY_EXIST_ID;
128         }
129
130 err:
131         if (query) {
132                 sqlite3_free(query);
133         }
134
135         return ret;
136 }
137
138 static int _notification_noti_get_internal_group_id_by_priv_id(const char *pkgname,
139                                                                int priv_id,
140                                                                sqlite3 * db)
141 {
142         char *query = NULL;
143         sqlite3_stmt *stmt = NULL;
144         int ret = NOTIFICATION_ERROR_NONE, result = 0;
145
146         query = sqlite3_mprintf("SELECT internal_group_id FROM noti_list WHERE caller_pkgname = '%s' AND priv_id = %d",
147                  pkgname, priv_id);
148         if (query == NULL) {
149                 ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
150                 goto err;
151         }
152
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,
156                                  sqlite3_errmsg(db));
157                 ret = NOTIFICATION_ERROR_FROM_DB;
158                 goto err;
159         }
160
161         ret = sqlite3_step(stmt);
162         if (ret == SQLITE_ROW) {
163                 result = sqlite3_column_int(stmt, 0);
164         } else {
165                 result = 0;
166         }
167
168 err:
169         if (stmt) {
170                 sqlite3_finalize(stmt);
171         }
172
173         if (query) {
174                 sqlite3_free(query);
175         }
176
177         if (ret != NOTIFICATION_ERROR_NONE) {
178                 NOTIFICATION_ERR("failed to internal group ID:%d", ret);
179         }
180
181         return result;
182 }
183
184 static int _insertion_query_create(notification_h noti, char **query)
185 {
186         int i = 0;
187         int b_encode_len = 0;
188         char *args = NULL;
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 , };
196         char *b_text = NULL;
197         char *b_key = NULL;
198         char *b_format_args = NULL;
199         int flag_simmode = 0;
200
201         if (query == NULL) {
202                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
203         }
204
205         /* Decode bundle to insert DB */
206         if (noti->args) {
207                 bundle_encode(noti->args, (bundle_raw **) & args, &b_encode_len);
208         }
209         if (noti->group_args) {
210                 bundle_encode(noti->group_args, (bundle_raw **) & group_args,
211                               &b_encode_len);
212         }
213
214         if (noti->b_execute_option) {
215                 bundle_encode(noti->b_execute_option,
216                               (bundle_raw **) & b_execute_option, &b_encode_len);
217         }
218         if (noti->b_service_responding) {
219                 bundle_encode(noti->b_service_responding,
220                               (bundle_raw **) & b_service_responding, &b_encode_len);
221         }
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);
225         }
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);
229         }
230
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);
235                 }
236         }
237
238         if (noti->b_text) {
239                 bundle_encode(noti->b_text, (bundle_raw **) & b_text, &b_encode_len);
240         }
241         if (noti->b_key) {
242                 bundle_encode(noti->b_key, (bundle_raw **) & b_key, &b_encode_len);
243         }
244         if (noti->b_format_args) {
245                 bundle_encode(noti->b_format_args,
246                               (bundle_raw **) & b_format_args, &b_encode_len);
247         }
248
249         if (noti->b_image_path) {
250                 bundle_encode(noti->b_image_path,
251                               (bundle_raw **) & b_image_path, &b_encode_len);
252         }
253
254         /* Check only simmode property is enable */
255         if (noti->flags_for_property & NOTIFICATION_PROP_DISPLAY_ONLY_SIMMODE) {
256                 flag_simmode = 1;
257         }
258
259         /* Make query */
260         *query = sqlite3_mprintf("INSERT INTO noti_list ("
261                  "type, "
262                  "layout, "
263                  "caller_pkgname, launch_pkgname, "
264                  "image_path, "
265                  "group_id, internal_group_id, priv_id, "
266                  "title_key, "
267                  "b_text, b_key, tag, b_format_args, num_format_args, "
268                  "text_domain, text_dir, "
269                  "time, insert_time, "
270                  "args, group_args, "
271                  "b_execute_option, "
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 ("
279                  "%d, "
280                  "%d, "
281                  "'%s', '%s', "
282                  "'%s', "
283                  "%d, %d, %d, "
284                  "$title_key, "
285                  "'%s', '%s', $tag, '%s', %d, "
286                  "'%s', '%s', "
287                  "%d, %d, "
288                  "'%s', '%s', "
289                  "'%s', "
290                  "'%s', '%s', '%s', "
291                  "'%s', '%s', '%s', "
292                  "'%s', '%s', '%s', "
293                  "'%s', '%s', "
294                  "%d, '%s', %d, '%s', %d, %d, %d, %d,"
295                  "%d, %d, %d, "
296                  "$progress_size, $progress_percentage)",
297                  noti->type,
298                  noti->layout,
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),
324                  noti->led_operation,
325                  noti->led_argb,
326                  noti->led_on_ms,
327                  noti->led_off_ms,
328                  noti->flags_for_property, flag_simmode, noti->display_applist);
329
330         /* Free decoded data */
331         if (args) {
332                 free(args);
333         }
334         if (group_args) {
335                 free(group_args);
336         }
337
338         if (b_execute_option) {
339                 free(b_execute_option);
340         }
341         if (b_service_responding) {
342                 free(b_service_responding);
343         }
344         if (b_service_single_launch) {
345                 free(b_service_single_launch);
346         }
347         if (b_service_multi_launch) {
348                 free(b_service_multi_launch);
349         }
350
351         if (b_text) {
352                 free(b_text);
353         }
354         if (b_key) {
355                 free(b_key);
356         }
357         if (b_format_args) {
358                 free(b_format_args);
359         }
360
361         if (b_image_path) {
362                 free(b_image_path);
363         }
364
365         if (*query == NULL) {
366                 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
367         }
368
369         return NOTIFICATION_ERROR_NONE;
370 }
371
372
373 static int _update_query_create(notification_h noti, char **query)
374 {
375         int i = 0;
376         int b_encode_len = 0;
377         char *args = NULL;
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 , };
385         char *b_text = NULL;
386         char *b_key = NULL;
387         char *b_format_args = NULL;
388         int flag_simmode = 0;
389
390         if (query == NULL) {
391                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
392         }
393
394         /* Decode bundle to update DB */
395         if (noti->args) {
396                 bundle_encode(noti->args, (bundle_raw **) & args, &b_encode_len);
397         }
398         if (noti->group_args) {
399                 bundle_encode(noti->group_args, (bundle_raw **) & group_args,
400                               &b_encode_len);
401         }
402
403         if (noti->b_execute_option) {
404                 bundle_encode(noti->b_execute_option,
405                               (bundle_raw **) & b_execute_option, &b_encode_len);
406         }
407         if (noti->b_service_responding) {
408                 bundle_encode(noti->b_service_responding,
409                               (bundle_raw **) & b_service_responding, &b_encode_len);
410         }
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);
414         }
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);
418         }
419
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);
424                 }
425         }
426
427         if (noti->b_text) {
428                 bundle_encode(noti->b_text, (bundle_raw **) & b_text, &b_encode_len);
429         }
430         if (noti->b_key) {
431                 bundle_encode(noti->b_key, (bundle_raw **) & b_key, &b_encode_len);
432         }
433         if (noti->b_format_args) {
434                 bundle_encode(noti->b_format_args,
435                               (bundle_raw **) & b_format_args, &b_encode_len);
436         }
437
438         if (noti->b_image_path) {
439                 bundle_encode(noti->b_image_path,
440                               (bundle_raw **) & b_image_path, &b_encode_len);
441         }
442
443         /* Check only simmode property is enable */
444         if (noti->flags_for_property & NOTIFICATION_PROP_DISPLAY_ONLY_SIMMODE) {
445                 flag_simmode = 1;
446         }
447
448         /* Make query */
449         *query = sqlite3_mprintf("UPDATE noti_list SET "
450                  "type = %d, "
451                  "layout = %d, "
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 ",
479                  noti->type,
480                  noti->layout,
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),
504                  noti->led_operation,
505                  noti->led_argb,
506                  noti->led_on_ms,
507                  noti->led_off_ms,
508                  noti->flags_for_property, flag_simmode, noti->display_applist,
509                  noti->priv_id);
510
511         /* Free decoded data */
512         if (args) {
513                 free(args);
514         }
515         if (group_args) {
516                 free(group_args);
517         }
518
519         if (b_execute_option) {
520                 free(b_execute_option);
521         }
522         if (b_service_responding) {
523                 free(b_service_responding);
524         }
525         if (b_service_single_launch) {
526                 free(b_service_single_launch);
527         }
528         if (b_service_multi_launch) {
529                 free(b_service_multi_launch);
530         }
531
532         if (b_text) {
533                 free(b_text);
534         }
535         if (b_key) {
536                 free(b_key);
537         }
538         if (b_format_args) {
539                 free(b_format_args);
540         }
541
542         if (b_image_path) {
543                 free(b_image_path);
544         }
545
546         if (*query == NULL) {
547                 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
548         }
549
550         return NOTIFICATION_ERROR_NONE;
551 }
552
553 static void _notification_noti_populate_from_stmt(sqlite3_stmt * stmt, notification_h noti) {
554         int col = 0;
555         int i = 0;
556
557         if (stmt == NULL || noti == NULL) {
558                 return ;
559         }
560
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++));
570
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++);
575
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++);
582
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++);
589
590         for (i = 0; i < NOTIFICATION_EVENT_TYPE_MAX; i++) {
591                 noti->b_event_handler[i] = notification_db_column_bundle(stmt, col++);
592         }
593
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++);
602
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++);
607
608         noti->app_icon_path = NULL;
609         noti->app_name = NULL;
610         noti->temp_title = NULL;
611         noti->temp_content = NULL;
612 }
613
614 static notification_h _notification_noti_get_item(sqlite3_stmt * stmt)
615 {
616         notification_h noti = NULL;
617
618         noti = (notification_h) calloc(1, sizeof(struct _notification));
619         if (noti == NULL) {
620                 return NULL;
621         }
622
623         _notification_noti_populate_from_stmt(stmt, noti);
624
625         return noti;
626 }
627
628 int notification_noti_set_tag(const char *tag, char *value, char *buf, int buf_len)
629 {
630         int len_total = 0;
631
632         len_total += (strlen(tag) * 2) + 5 + strlen(value) + 1;
633
634         if (buf_len <= len_total)
635                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
636
637         snprintf(buf, buf_len, "<%s>%s</%s>", tag, value, tag);
638
639         return NOTIFICATION_ERROR_NONE;
640 }
641
642 char *notification_noti_strip_tag(const char *tagged_str)
643 {
644         if (tagged_str == NULL)
645                 return NULL;
646
647         int len_total = strlen(tagged_str);
648
649         if (len_total == 0)
650                 return NULL;
651
652         char *b_f_e = strstr(tagged_str, ">");
653         char *b_e_s = strstr(tagged_str, "</");
654
655         if (b_f_e == NULL || b_e_s == NULL || (b_e_s - b_f_e - 1) <= 0)
656                 return NULL;
657
658         return strndup(b_f_e + 1, b_e_s - b_f_e - 1);
659 }
660
661 int notification_noti_get_tag_type(const char *tagged_str)
662 {
663         if (tagged_str == NULL)
664                 return TAG_TYPE_INVALID;
665
666         if (strlen(tagged_str)== 0)
667                 return TAG_TYPE_INVALID;
668
669         char *b_f_s = strstr(tagged_str, "<");
670         char *b_f_e = strstr(tagged_str, ">");
671
672         if (b_f_s == NULL || b_f_e == NULL || (b_f_e - b_f_s - 1) <= 0)
673                 return TAG_TYPE_INVALID;
674
675         char *start = b_f_s + 1;
676         int len_tag = b_f_e - b_f_s - 1;
677
678         if (strncmp(start,TAG_TIME,len_tag) == 0) {
679                 return TAG_TYPE_TIME;
680         }
681
682         return TAG_TYPE_INVALID;
683 }
684
685 static int _notification_noti_update_priv_id(sqlite3 * db, int rowid)
686 {
687         int ret = NOTIFICATION_ERROR_NONE;
688         char *query = NULL;
689
690         if (db == NULL) {
691                 ret = NOTIFICATION_ERROR_INVALID_PARAMETER;
692                 goto err;
693         }
694
695         query = sqlite3_mprintf("UPDATE noti_list SET "
696                         "priv_id = %d, internal_group_id = %d WHERE rowid = %d",
697                         rowid, rowid, rowid);
698         if (query == NULL) {
699                 ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
700                 goto err;
701         }
702
703         ret = notification_db_exec(db, query, NULL);
704
705 err:
706         if (query) {
707                 sqlite3_free(query);
708         }
709
710         return ret;
711 }
712
713 EXPORT_API int notification_noti_insert(notification_h noti)
714 {
715         int ret = 0;
716         sqlite3 *db = NULL;
717         sqlite3_stmt *stmt = NULL;
718         char *query = NULL;
719         char buf_key[32] = { 0, };
720         const char *title_key = NULL;
721
722         /* Open DB */
723         db = notification_db_open(DBPATH);
724         if (!db) {
725                 return get_last_result();
726         }
727
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;
732
733         /* make query */
734         ret = _insertion_query_create(noti, &query);
735         if (ret != NOTIFICATION_ERROR_NONE) {
736                 goto err;
737         }
738
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,
743                                  sqlite3_errmsg(db));
744                 ret = NOTIFICATION_ERROR_FROM_DB;
745                 goto err;
746         }
747
748         /* Get title key */
749         if (noti->b_key != NULL) {
750                 snprintf(buf_key, sizeof(buf_key), "%d",
751                          NOTIFICATION_TEXT_TYPE_TITLE);
752
753                 title_key = bundle_get_val(noti->b_key, buf_key);
754         }
755
756         if (title_key == NULL && noti->b_text != NULL) {
757                 snprintf(buf_key, sizeof(buf_key), "%d",
758                          NOTIFICATION_TEXT_TYPE_TITLE);
759
760                 title_key = bundle_get_val(noti->b_text, buf_key);
761         }
762
763         if (title_key == NULL) {
764                 title_key = noti->caller_pkgname;
765         }
766
767         /* Bind query */
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));
771                 goto err;
772         }
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));
776                 goto err;
777         }
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));
781                 if (stmt) {
782                         sqlite3_finalize(stmt);
783                 }
784                 return ret;
785         }
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));
789                 if (stmt) {
790                         sqlite3_finalize(stmt);
791                 }
792                 return ret;
793         }
794
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;
800                 } else {
801                         ret = NOTIFICATION_ERROR_FROM_DB;
802                 }
803         } else {
804                 ret = NOTIFICATION_ERROR_FROM_DB;
805         }
806 err:
807         if (stmt) {
808                 sqlite3_finalize(stmt);
809         }
810
811         /* Close DB */
812         if (db) {
813                 notification_db_close(&db);
814         }
815
816         if (query) {
817                 sqlite3_free(query);
818         }
819
820         return ret;
821 }
822
823 int notification_noti_get_by_priv_id(notification_h noti, char *pkgname, int priv_id)
824 {
825         int ret = 0;
826         char *query = NULL;
827         sqlite3 *db = NULL;
828         sqlite3_stmt *stmt = NULL;
829
830         if (priv_id < 0 || noti == NULL) {
831                 ret = NOTIFICATION_ERROR_INVALID_PARAMETER;
832                 goto err;
833         }
834
835         /* Open DB */
836         db = notification_db_open(DBPATH);
837         if (!db) {
838                 return get_last_result();
839         }
840
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 "
851                          "from noti_list ";
852
853         if (pkgname != NULL) {
854                 query = sqlite3_mprintf("%s where caller_pkgname = '%s' and priv_id = %d",
855                                 base_query ,pkgname, priv_id);
856         } else {
857                 query = sqlite3_mprintf("%s where priv_id = %d", base_query,  priv_id);
858         }
859         if (query == NULL) {
860                 ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
861                 goto err;
862         }
863
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,
868                                  sqlite3_errmsg(db));
869                 ret = NOTIFICATION_ERROR_FROM_DB;
870                 goto err;
871         }
872
873         ret = sqlite3_step(stmt);
874         if (ret == SQLITE_ROW) {
875                 _notification_noti_populate_from_stmt(stmt, noti);
876                 ret = NOTIFICATION_ERROR_NONE;
877         } else {
878                 ret = NOTIFICATION_ERROR_FROM_DB;
879         }
880 err:
881         if (query) {
882                 sqlite3_free(query);
883         }
884
885         if (stmt) {
886                 sqlite3_finalize(stmt);
887         }
888
889         /* Close DB */
890         if (db != NULL) {
891                 notification_db_close(&db);
892         }
893
894         return ret;
895 }
896
897 EXPORT_API int notification_noti_get_by_tag(notification_h noti, char *pkgname, char* tag)
898 {
899         int ret = 0;
900         sqlite3 *db = NULL;
901         sqlite3_stmt *stmt = NULL;
902
903         if (tag == NULL || noti == NULL) {
904                 ret = NOTIFICATION_ERROR_INVALID_PARAMETER;
905                 goto err;
906         }
907
908         /* Open DB */
909         db = notification_db_open(DBPATH);
910         if (!db) {
911                 return get_last_result();
912         }
913
914         if (pkgname != NULL) {
915                 ret = sqlite3_prepare_v2(db, "select "
916                          "type, layout, caller_pkgname, launch_pkgname, image_path, group_id, priv_id, "
917                          "tag, b_text, b_key, b_format_args, num_format_args, "
918                          "text_domain, text_dir, time, insert_time, args, group_args, "
919                          "b_execute_option, b_service_responding, b_service_single_launch, b_service_multi_launch, "
920                          "b_event_handler_click_on_button_1, b_event_handler_click_on_button_2, b_event_handler_click_on_button_3, "
921                          "b_event_handler_click_on_button_4, b_event_handler_click_on_button_5, b_event_handler_click_on_button_6, "
922                          "b_event_handler_click_on_icon, b_event_handler_click_on_thumbnail, "
923                          "sound_type, sound_path, vibration_type, vibration_path, led_operation, led_argb, led_on_ms, led_off_ms, "
924                          "flags_for_property, display_applist, progress_size, progress_percentage "
925                          "from noti_list where caller_pkgname = ? and tag = ?", -1, &stmt, NULL);
926                 if (ret != SQLITE_OK) {
927                         NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
928                         return NOTIFICATION_ERROR_OUT_OF_MEMORY;
929                 }
930
931                 ret = sqlite3_bind_text(stmt, 1, pkgname, -1, SQLITE_TRANSIENT);
932                 if (ret != SQLITE_OK) {
933                         NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
934                         goto err;
935                 }
936
937                 ret = sqlite3_bind_text(stmt, 2,  tag, -1, SQLITE_TRANSIENT);
938                 if (ret != SQLITE_OK) {
939                         NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
940                         goto err;
941                 } 
942         } else {
943                 ret = sqlite3_prepare_v2(db, "select "
944                          "type, layout, caller_pkgname, launch_pkgname, image_path, group_id, priv_id, "
945                          "tag, b_text, b_key, b_format_args, num_format_args, "
946                          "text_domain, text_dir, time, insert_time, args, group_args, "
947                          "b_execute_option, b_service_responding, b_service_single_launch, b_service_multi_launch, "
948                          "b_event_handler_click_on_button_1, b_event_handler_click_on_button_2, b_event_handler_click_on_button_3, "
949                          "b_event_handler_click_on_button_4, b_event_handler_click_on_button_5, b_event_handler_click_on_button_6, "
950                          "b_event_handler_click_on_icon, b_event_handler_click_on_thumbnail, "
951                          "sound_type, sound_path, vibration_type, vibration_path, led_operation, led_argb, led_on_ms, led_off_ms, "
952                          "flags_for_property, display_applist, progress_size, progress_percentage "
953                          "from noti_list where  tag = ?", -1, &stmt, NULL);
954                 if (ret != SQLITE_OK) {
955                         NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
956                         return NOTIFICATION_ERROR_OUT_OF_MEMORY;
957                 }
958
959                 ret = sqlite3_bind_text(stmt, 1, tag, -1, SQLITE_TRANSIENT);
960                 if (ret != SQLITE_OK) {
961                         NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
962                         goto err;
963                 }
964         }
965
966         ret = sqlite3_step(stmt);
967         if (ret == SQLITE_ROW) {
968                 _notification_noti_populate_from_stmt(stmt, noti);
969                 ret = NOTIFICATION_ERROR_NONE;
970         } else {
971                 ret = NOTIFICATION_ERROR_FROM_DB;
972         }
973 err:
974
975         if (stmt) {
976                 sqlite3_finalize(stmt);
977         }
978
979         /* Close DB */
980         if (db != NULL) {
981                 notification_db_close(&db);
982         }
983
984         return ret;
985 }
986
987 EXPORT_API int notification_noti_update(notification_h noti)
988 {
989         int ret = 0;
990         sqlite3 *db;
991         sqlite3_stmt *stmt = NULL;
992         char *query = NULL;
993
994         /* Open DB */
995         db = notification_db_open(DBPATH);
996         if (!db) {
997                 return get_last_result();
998         }
999
1000         /* Check private ID is exist */
1001         ret = _notification_noti_check_priv_id(noti, db);
1002         if (ret != NOTIFICATION_ERROR_ALREADY_EXIST_ID) {
1003                 ret = NOTIFICATION_ERROR_NOT_EXIST_ID;
1004                 goto err;
1005         }
1006
1007         /* make update query */
1008         ret = _update_query_create(noti, &query);
1009         if (ret != NOTIFICATION_ERROR_NONE) {
1010                 goto err;
1011         }
1012
1013         ret = sqlite3_prepare_v2(db, query, -1, &stmt, NULL);
1014         if (ret != SQLITE_OK) {
1015                 NOTIFICATION_ERR("Insert Query : %s", query);
1016                 NOTIFICATION_ERR("Insert DB error(%d) : %s", ret,
1017                                  sqlite3_errmsg(db));
1018                 ret = NOTIFICATION_ERROR_FROM_DB;
1019                 goto err;
1020         }
1021
1022         ret = _notification_noti_bind_query_text(stmt, "$tag", noti->tag);
1023         if (ret != NOTIFICATION_ERROR_NONE) {
1024                 NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db));
1025                 goto err;
1026         }
1027         ret = _notification_noti_bind_query_double(stmt, "$progress_size",noti->progress_size);
1028         if (ret != NOTIFICATION_ERROR_NONE) {
1029                 NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db));
1030                 goto err;
1031         }
1032         ret = _notification_noti_bind_query_double(stmt, "$progress_percentage",noti->progress_percentage);
1033         if (ret != NOTIFICATION_ERROR_NONE) {
1034                 NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db));
1035                 goto err;
1036         }
1037
1038         ret = sqlite3_step(stmt);
1039         if (ret == SQLITE_OK || ret == SQLITE_DONE) {
1040                 ret = NOTIFICATION_ERROR_NONE;
1041         } else {
1042                 ret = NOTIFICATION_ERROR_FROM_DB;
1043         }
1044 err:
1045         if (stmt) {
1046                 sqlite3_finalize(stmt);
1047         }
1048
1049         /* Close DB */
1050         if (db) {
1051                 notification_db_close(&db);
1052         }
1053
1054         if (query) {
1055                 sqlite3_free(query);
1056         }
1057
1058         return ret;
1059 }
1060
1061 EXPORT_API int notification_noti_delete_all(notification_type_e type, const char *pkgname, int *num_deleted, int **list_deleted_rowid)
1062 {
1063         int ret = NOTIFICATION_ERROR_NONE;
1064         int ret_tmp = NOTIFICATION_ERROR_NONE;
1065         int i = 0, data_cnt = 0;
1066         sqlite3 *db = NULL;
1067         sqlite3_stmt *stmt = NULL;
1068         char buf[128] = { 0, };
1069         char query[NOTIFICATION_QUERY_MAX] = { 0, };
1070         char query_base[NOTIFICATION_QUERY_MAX] = { 0, };
1071         char query_where[NOTIFICATION_QUERY_MAX] = { 0, };
1072
1073         /* Open DB */
1074         db = notification_db_open(DBPATH);
1075         if (!db) {
1076                 return get_last_result();
1077         }
1078
1079         if (pkgname == NULL) {
1080                 if (type != NOTIFICATION_TYPE_NONE) {
1081                         snprintf(query_where, sizeof(query_where),
1082                                  "where type = %d ", type);
1083                 }
1084         } else {
1085                 if (type == NOTIFICATION_TYPE_NONE) {
1086                         snprintf(query_where, sizeof(query_where),
1087                                  "where caller_pkgname = '%s' ", pkgname);
1088                 } else {
1089                         snprintf(query_where, sizeof(query_where),
1090                                  "where caller_pkgname = '%s' and type = %d ",
1091                                  pkgname, type);
1092                 }
1093         }
1094
1095         if (num_deleted != NULL) {
1096                 *num_deleted = 0;
1097         }
1098         if (list_deleted_rowid != NULL) {
1099                 *list_deleted_rowid = NULL;
1100                 snprintf(query, sizeof(query),
1101                                 "select priv_id from noti_list %s ", query_where);
1102
1103                 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
1104                 if (ret != SQLITE_OK) {
1105                         NOTIFICATION_ERR("Select Query : %s", query);
1106                         NOTIFICATION_ERR("Select DB error(%d) : %s", ret,
1107                                          sqlite3_errmsg(db));
1108
1109                         ret = NOTIFICATION_ERROR_FROM_DB;
1110                         goto err;
1111                 }
1112
1113                 while(sqlite3_step(stmt) == SQLITE_ROW) {
1114                         if (data_cnt % 8 == 0) {
1115                                 int *tmp;
1116
1117                                 tmp = (int *)realloc(*list_deleted_rowid, sizeof(int) * (data_cnt + 8 + 1));
1118                                 if (tmp) {
1119                                         *list_deleted_rowid = tmp;
1120                                 } else {
1121                                         NOTIFICATION_ERR("Heap: %d\n", errno);
1122                                         /*!
1123                                          * \TODO
1124                                          * How can I handle this?
1125                                          */
1126                                         free(*list_deleted_rowid);
1127                                         *list_deleted_rowid = NULL;
1128                                         ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
1129                                         goto err;
1130                                 }
1131                         }
1132                         *((*list_deleted_rowid) + data_cnt) = sqlite3_column_int(stmt, 0);
1133                         data_cnt++;
1134                 }
1135
1136                 if (stmt) {
1137                         sqlite3_finalize(stmt);
1138                         stmt = NULL;
1139                 }
1140
1141                 if (data_cnt > 0) {
1142                         query_where[0] = '\0';
1143                         snprintf(query_base, sizeof(query_base) - 1, "delete from noti_list");
1144                         for (i = 0; i < data_cnt ; i++) {
1145                                 if (i % NOTI_BURST_DELETE_UNIT == 0 && i != 0) {
1146                                         snprintf(query, sizeof(query) - 1, "%s where priv_id in (%s)", query_base, query_where);
1147                                         ret_tmp = notification_db_exec(db, query, NULL);
1148                                         query_where[0] = '\0';
1149                                         if (ret == NOTIFICATION_ERROR_NONE) {
1150                                                 ret = ret_tmp;
1151                                         }
1152                                 }
1153                                 snprintf(buf, sizeof(buf) - 1, "%s%d", (i % NOTI_BURST_DELETE_UNIT == 0) ? "" : ",", *((*list_deleted_rowid) + i));
1154                                 strncat(query_where, buf,sizeof(query_where) - strlen(query_where) - 1);
1155                         }
1156                         if ((i <= NOTI_BURST_DELETE_UNIT) || ((i % NOTI_BURST_DELETE_UNIT) > 0) ) {
1157                                 snprintf(query, sizeof(query) - 1, "%s where priv_id in (%s)", query_base, query_where);
1158                                 ret_tmp = notification_db_exec(db, query, NULL);
1159                                 if (ret == NOTIFICATION_ERROR_NONE) {
1160                                         ret = ret_tmp;
1161                                 }
1162                         }
1163                 } else {
1164                         free(*list_deleted_rowid);
1165                         *list_deleted_rowid = NULL;
1166                 }
1167
1168                 if (num_deleted != NULL) {
1169                         *num_deleted = data_cnt;
1170                 }
1171         } else {
1172                 /* Make main query */
1173                 snprintf(query_base, sizeof(query_base), "delete from noti_list ");
1174                 snprintf(query, sizeof(query), "%s %s", query_base, query_where);
1175
1176                 ret = notification_db_exec(db, query, NULL);
1177
1178                 if (num_deleted != NULL) {
1179                         *num_deleted = sqlite3_changes(db);
1180                 }
1181         }
1182
1183 err:
1184         if (stmt) {
1185                 sqlite3_finalize(stmt);
1186         }
1187         /* Close DB */
1188         if (db) {
1189                 notification_db_close(&db);
1190         }
1191
1192         return ret;
1193 }
1194
1195 int notification_noti_delete_group_by_group_id(const char *pkgname,
1196                                                int group_id, int *num_deleted, int **list_deleted_rowid)
1197 {
1198         int ret = NOTIFICATION_ERROR_NONE;
1199         int ret_tmp = NOTIFICATION_ERROR_NONE;
1200         sqlite3 *db = NULL;
1201         int i = 0, data_cnt = 0;
1202         sqlite3_stmt *stmt = NULL;
1203         char buf[128] = { 0, };
1204         char query[NOTIFICATION_QUERY_MAX] = { 0, };
1205         char query_base[NOTIFICATION_QUERY_MAX] = { 0, };
1206         char query_where[NOTIFICATION_QUERY_MAX] = { 0, };
1207
1208         /* Check pkgname is valid */
1209         if (pkgname == NULL) {
1210                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1211         }
1212
1213         snprintf(query_where, sizeof(query_where),
1214                         "where caller_pkgname = '%s' and group_id = %d", pkgname, group_id);
1215
1216         /* Open DB */
1217         db = notification_db_open(DBPATH);
1218         if (!db) {
1219                 return get_last_result();
1220         }
1221
1222         if (num_deleted != NULL) {
1223                 *num_deleted = 0;
1224         }
1225         if (list_deleted_rowid != NULL) {
1226                 *list_deleted_rowid = NULL;
1227                 snprintf(query, sizeof(query),
1228                                 "select priv_id from noti_list %s ", query_where);
1229
1230                 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
1231                 if (ret != SQLITE_OK) {
1232                         NOTIFICATION_ERR("Select Query : %s", query);
1233                         NOTIFICATION_ERR("Select DB error(%d) : %s", ret,
1234                                          sqlite3_errmsg(db));
1235
1236                         ret = NOTIFICATION_ERROR_FROM_DB;
1237                         goto err;
1238                 }
1239
1240                 while(sqlite3_step(stmt) == SQLITE_ROW) {
1241                         if (data_cnt % 8 == 0) {
1242                                 int *tmp;
1243                                 tmp = (int *)realloc(*list_deleted_rowid, sizeof(int) * (data_cnt + 8 + 1));
1244                                 if (tmp) {
1245                                         *list_deleted_rowid = tmp;
1246                                 } else {
1247                                         free(*list_deleted_rowid);
1248                                         *list_deleted_rowid = NULL;
1249                                         ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
1250                                         goto err;
1251                                 }
1252                         }
1253                         *((*list_deleted_rowid) + data_cnt) = sqlite3_column_int(stmt, 0);
1254                         data_cnt++;
1255                 }
1256
1257                 if (stmt) {
1258                         sqlite3_finalize(stmt);
1259                         stmt = NULL;
1260                 }
1261
1262                 if (data_cnt > 0) {
1263                         query_where[0] = '\0';
1264                         snprintf(query_base, sizeof(query_base) - 1, "delete from noti_list");
1265                         for (i = 0; i < data_cnt ; i++) {
1266                                 if (i % NOTI_BURST_DELETE_UNIT == 0 && i != 0) {
1267                                         snprintf(query, sizeof(query) - 1, "%s where priv_id in (%s)", query_base, query_where);
1268                                         ret_tmp = notification_db_exec(db, query, NULL);
1269                                         query_where[0] = '\0';
1270                                         if (ret == NOTIFICATION_ERROR_NONE) {
1271                                                 ret = ret_tmp;
1272                                         }
1273                                 }
1274                                 snprintf(buf, sizeof(buf) - 1, "%s%d", (i % NOTI_BURST_DELETE_UNIT == 0) ? "" : ",", *((*list_deleted_rowid) + i));
1275                                 strncat(query_where, buf,sizeof(query_where) - strlen(query_where) - 1);
1276                         }
1277                         if ((i <= NOTI_BURST_DELETE_UNIT) || ((i % NOTI_BURST_DELETE_UNIT) > 0) ) {
1278                                 snprintf(query, sizeof(query) - 1, "%s where priv_id in (%s)", query_base, query_where);
1279                                 ret_tmp = notification_db_exec(db, query, NULL);
1280                                 if (ret == NOTIFICATION_ERROR_NONE) {
1281                                         ret = ret_tmp;
1282                                 }
1283                         }
1284                 } else {
1285                         free(*list_deleted_rowid);
1286                         *list_deleted_rowid = NULL;
1287                 }
1288
1289                 if (num_deleted != NULL) {
1290                         *num_deleted = data_cnt;
1291                 }
1292         } else {
1293                 /* Make query */
1294                 snprintf(query, sizeof(query), "delete from noti_list %s", query_where);
1295
1296                 /* execute DB */
1297                 ret = notification_db_exec(db, query, NULL);
1298         }
1299
1300 err:
1301         if (stmt) {
1302                 sqlite3_finalize(stmt);
1303         }
1304         /* Close DB */
1305         if (db) {
1306                 notification_db_close(&db);
1307         }
1308
1309         return ret;
1310 }
1311
1312 int notification_noti_delete_group_by_priv_id(const char *pkgname, int priv_id)
1313 {
1314         sqlite3 *db = NULL;
1315         char query[NOTIFICATION_QUERY_MAX] = { 0, };
1316         int internal_group_id = 0;
1317         int ret;
1318
1319         /* Check pkgname is valid */
1320         if (pkgname == NULL) {
1321                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1322         }
1323
1324         /* Open DB */
1325         db = notification_db_open(DBPATH);
1326         if (!db) {
1327                 return get_last_result();
1328         }
1329
1330         /* Get internal group id using priv id */
1331         internal_group_id =
1332             _notification_noti_get_internal_group_id_by_priv_id(pkgname,
1333                                                                 priv_id, db);
1334
1335         /* Make query */
1336         snprintf(query, sizeof(query), "delete from noti_list "
1337                  "where caller_pkgname = '%s' and internal_group_id = %d",
1338                  pkgname, internal_group_id);
1339
1340         /* execute DB */
1341         ret = notification_db_exec(db, query, NULL);
1342
1343         /* Close DB */
1344         notification_db_close(&db);
1345
1346         return ret;
1347 }
1348
1349 EXPORT_API int notification_noti_delete_by_priv_id(const char *pkgname, int priv_id)
1350 {
1351         sqlite3 *db = NULL;
1352         char query[NOTIFICATION_QUERY_MAX] = { 0, };
1353         int ret;
1354
1355         /* Check pkgname is valid */
1356         if (pkgname == NULL) {
1357                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1358         }
1359
1360         /* Open DB */
1361         db = notification_db_open(DBPATH);
1362         if (!db) {
1363                 return get_last_result();
1364         }
1365
1366         /* Make query */
1367         snprintf(query, sizeof(query), "delete from noti_list "
1368                  "where caller_pkgname = '%s' and priv_id = %d", pkgname,
1369                  priv_id);
1370
1371         /* execute DB */
1372         ret = notification_db_exec(db, query, NULL);
1373
1374         /* Close DB */
1375         if (db) {
1376                 notification_db_close(&db);
1377         }
1378
1379         return ret;
1380 }
1381
1382 EXPORT_API int notification_noti_delete_by_priv_id_get_changes(const char *pkgname, int priv_id, int *num_changes)
1383 {
1384         sqlite3 *db = NULL;
1385         char query[NOTIFICATION_QUERY_MAX] = { 0, };
1386         int ret;
1387
1388         /* Check pkgname is valid */
1389         if (pkgname == NULL) {
1390                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1391         }
1392
1393         /* Open DB */
1394         db = notification_db_open(DBPATH);
1395         if (!db) {
1396                 return get_last_result();
1397         }
1398
1399         /* Make query */
1400         snprintf(query, sizeof(query), "delete from noti_list "
1401                  "where caller_pkgname = '%s' and priv_id = %d", pkgname,
1402                  priv_id);
1403
1404         /* execute DB */
1405         ret = notification_db_exec(db, query, num_changes);
1406
1407         if (num_changes != NULL) {
1408                 NOTIFICATION_DBG("deleted num:%d", *num_changes);
1409         }
1410
1411         /* Close DB */
1412         if (db) {
1413                 notification_db_close(&db);
1414         }
1415
1416         return ret;
1417 }
1418
1419 int notification_noti_get_count(notification_type_e type,
1420                                                  const char *pkgname,
1421                                                  int group_id, int priv_id,
1422                                                  int *count)
1423 {
1424         sqlite3 *db = NULL;
1425         sqlite3_stmt *stmt = NULL;
1426         char query[NOTIFICATION_QUERY_MAX] = { 0, };
1427         char query_base[NOTIFICATION_QUERY_MAX] = { 0, };
1428         char query_where[NOTIFICATION_QUERY_MAX] = { 0, };
1429         char query_where_more[NOTIFICATION_QUERY_MAX] = { 0, };
1430
1431         int ret = 0, get_count = 0, internal_group_id = 0;
1432         int status = VCONFKEY_TELEPHONY_SIM_UNKNOWN;
1433         int flag_where = 0;
1434         int flag_where_more = 0;
1435         int ret_vconf = 0;
1436
1437         /* Open DB */
1438         db = notification_db_open(DBPATH);
1439         if (!db) {
1440                 return get_last_result();
1441         }
1442
1443         /* Check current sim status */
1444         ret_vconf = vconf_get_int(VCONFKEY_TELEPHONY_SIM_SLOT, &status);
1445
1446         /* Make query */
1447         snprintf(query_base, sizeof(query_base),
1448                  "select count(*) from noti_list ");
1449
1450         if (pkgname != NULL) {
1451                 if (group_id == NOTIFICATION_GROUP_ID_NONE) {
1452                         if (priv_id == NOTIFICATION_PRIV_ID_NONE) {
1453                                 snprintf(query_where, sizeof(query_where),
1454                                          "where caller_pkgname = '%s' ",
1455                                          pkgname);
1456                                 flag_where = 1;
1457                         } else {
1458                                 internal_group_id =
1459                                     _notification_noti_get_internal_group_id_by_priv_id
1460                                     (pkgname, priv_id, db);
1461                                 snprintf(query_where, sizeof(query_where),
1462                                          "where caller_pkgname = '%s' and internal_group_id = %d ",
1463                                          pkgname, internal_group_id);
1464                                 flag_where = 1;
1465                         }
1466                 } else {
1467                         if (priv_id == NOTIFICATION_PRIV_ID_NONE) {
1468                                 snprintf(query_where, sizeof(query_where),
1469                                          "where caller_pkgname = '%s' and group_id = %d ",
1470                                          pkgname, group_id);
1471                                 flag_where = 1;
1472                         } else {
1473                                 internal_group_id =
1474                                     _notification_noti_get_internal_group_id_by_priv_id
1475                                     (pkgname, priv_id, db);
1476                                 snprintf(query_where, sizeof(query_where),
1477                                          "where caller_pkgname = '%s' and internal_group_id = %d ",
1478                                          pkgname, internal_group_id);
1479                                 flag_where = 1;
1480                         }
1481                 }
1482
1483         }
1484
1485         if (ret_vconf == 0 && status == VCONFKEY_TELEPHONY_SIM_INSERTED) {
1486                 if (type != NOTIFICATION_TYPE_NONE) {
1487                         snprintf(query_where_more, sizeof(query_where_more),
1488                                  "type = %d ", type);
1489                         flag_where_more = 1;
1490                 }
1491         } else {
1492                 if (type != NOTIFICATION_TYPE_NONE) {
1493                         snprintf(query_where_more, sizeof(query_where_more),
1494                                  "type = %d and flag_simmode = 0 ", type);
1495                         flag_where_more = 1;
1496                 } else {
1497                         snprintf(query_where_more, sizeof(query_where_more),
1498                                  "flag_simmode = 0 ");
1499                         flag_where_more = 1;
1500                 }
1501         }
1502
1503         if (flag_where == 1) {
1504                 if (flag_where_more == 1) {
1505                         snprintf(query, sizeof(query), "%s %s and %s",
1506                                  query_base, query_where, query_where_more);
1507                 } else {
1508                         snprintf(query, sizeof(query), "%s %s", query_base,
1509                                  query_where);
1510                 }
1511
1512         } else {
1513                 if (flag_where_more == 1) {
1514                         snprintf(query, sizeof(query), "%s where %s",
1515                                  query_base, query_where_more);
1516                 } else {
1517                         snprintf(query, sizeof(query), "%s", query_base);
1518                 }
1519         }
1520
1521         ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
1522         if (ret != SQLITE_OK) {
1523                 NOTIFICATION_ERR("Select Query : %s", query);
1524                 NOTIFICATION_ERR("Select DB error(%d) : %s", ret,
1525                                  sqlite3_errmsg(db));
1526
1527                 ret = NOTIFICATION_ERROR_FROM_DB;
1528                 goto err;
1529         }
1530
1531         ret = sqlite3_step(stmt);
1532         if (ret == SQLITE_ROW) {
1533                 get_count = sqlite3_column_int(stmt, 0);
1534         }
1535
1536         ret = NOTIFICATION_ERROR_NONE;
1537
1538 err:
1539         if (stmt) {
1540                 sqlite3_finalize(stmt);
1541         }
1542
1543         /* Close DB */
1544         if (db) {
1545                 notification_db_close(&db);
1546         }
1547
1548         *count = get_count;
1549
1550         return ret;
1551 }
1552
1553 int notification_noti_get_grouping_list(notification_type_e type,
1554                                                          int count,
1555                                                          notification_list_h *
1556                                                          list)
1557 {
1558         sqlite3 *db = NULL;
1559         sqlite3_stmt *stmt = NULL;
1560         char query[NOTIFICATION_QUERY_MAX] = { 0, };
1561         char query_base[NOTIFICATION_QUERY_MAX] = { 0, };
1562         char query_where[NOTIFICATION_QUERY_MAX] = { 0, };
1563
1564         int ret = 0;
1565         notification_list_h get_list = NULL;
1566         notification_h noti = NULL;
1567         int internal_count = 0;
1568         int status;
1569
1570         /* Open DB */
1571         db = notification_db_open(DBPATH);
1572         if (!db) {
1573                 return get_last_result();
1574         }
1575
1576         /* Check current sim status */
1577         ret = vconf_get_int(VCONFKEY_TELEPHONY_SIM_SLOT, &status);
1578
1579         /* Make query */
1580         snprintf(query_base, sizeof(query_base), "select "
1581                  "type, layout, caller_pkgname, launch_pkgname, image_path, group_id, priv_id, "
1582                  "tag, b_text, b_key, b_format_args, num_format_args, "
1583                  "text_domain, text_dir, time, insert_time, args, group_args, "
1584                  "b_execute_option, b_service_responding, b_service_single_launch, b_service_multi_launch, "
1585                  "b_event_handler_click_on_button_1, b_event_handler_click_on_button_2, b_event_handler_click_on_button_3, "
1586                  "b_event_handler_click_on_button_4, b_event_handler_click_on_button_5, b_event_handler_click_on_button_6, "
1587                  "b_event_handler_click_on_icon, b_event_handler_click_on_thumbnail, "
1588                  "sound_type, sound_path, vibration_type, vibration_path, led_operation, led_argb, led_on_ms, led_off_ms, "
1589                  "flags_for_property, display_applist, progress_size, progress_percentage "
1590                  "from noti_list ");
1591
1592         if (status == VCONFKEY_TELEPHONY_SIM_INSERTED) {
1593                 if (type != NOTIFICATION_TYPE_NONE) {
1594                         snprintf(query_where, sizeof(query_where),
1595                                  "where type = %d ", type);
1596                 }
1597         } else {
1598                 if (type != NOTIFICATION_TYPE_NONE) {
1599                         snprintf(query_where, sizeof(query_where),
1600                                  "where type = %d and flag_simmode = 0 ", type);
1601                 } else {
1602                         snprintf(query_where, sizeof(query_where),
1603                                  "where flag_simmode = 0 ");
1604                 }
1605         }
1606
1607         snprintf(query, sizeof(query),
1608                  "%s %s "
1609                  "group by internal_group_id "
1610                  "order by rowid desc, time desc", query_base, query_where);
1611
1612         ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
1613         if (ret != SQLITE_OK) {
1614                 NOTIFICATION_ERR("Select Query : %s", query);
1615                 NOTIFICATION_ERR("Select DB error(%d) : %s", ret,
1616                                  sqlite3_errmsg(db));
1617
1618                 ret = NOTIFICATION_ERROR_FROM_DB;
1619                 goto err;
1620         }
1621
1622         while (sqlite3_step(stmt) == SQLITE_ROW) {
1623                 /* Make notification list */
1624                 noti = _notification_noti_get_item(stmt);
1625                 if (noti != NULL) {
1626                         internal_count++;
1627
1628                         get_list = notification_list_append(get_list, noti);
1629
1630                         if (count != -1 && internal_count >= count) {
1631                                 NOTIFICATION_INFO
1632                                     ("internal count %d >= count %d",
1633                                      internal_count, count);
1634                                 break;
1635                         }
1636                 }
1637         }
1638
1639         ret = NOTIFICATION_ERROR_NONE;
1640
1641 err:
1642         if (stmt) {
1643                 sqlite3_finalize(stmt);
1644         }
1645
1646         /* Close DB */
1647         if (db) {
1648                 notification_db_close(&db);
1649         }
1650
1651         if (get_list != NULL) {
1652                 *list = notification_list_get_head(get_list);
1653         }
1654
1655         return ret;
1656 }
1657
1658 int notification_noti_get_detail_list(const char *pkgname,
1659                                                        int group_id,
1660                                                        int priv_id, int count,
1661                                                        notification_list_h *list)
1662 {
1663         sqlite3 *db = NULL;
1664         sqlite3_stmt *stmt = NULL;
1665         char query_base[NOTIFICATION_QUERY_MAX] = { 0, };
1666         char query_where[NOTIFICATION_QUERY_MAX] = { 0, };
1667
1668         char query[NOTIFICATION_QUERY_MAX] = { 0, };
1669         int ret = 0;
1670         notification_list_h get_list = NULL;
1671         notification_h noti = NULL;
1672         int internal_count = 0;
1673         int internal_group_id = 0;
1674         int status = 0; /* If the vconf_get_int failed, the status will be the garbage value */
1675
1676         /* Open DB */
1677         db = notification_db_open(DBPATH);
1678         if (!db) {
1679                 return get_last_result();
1680         }
1681
1682         /* Check current sim status */
1683         ret = vconf_get_int(VCONFKEY_TELEPHONY_SIM_SLOT, &status);
1684
1685         /* Make query */
1686         snprintf(query_base, sizeof(query_base), "select "
1687                  "type, layout, caller_pkgname, launch_pkgname, image_path, group_id, priv_id, "
1688                  "tag, b_text, b_key, b_format_args, num_format_args, "
1689                  "text_domain, text_dir, time, insert_time, args, group_args, "
1690                  "b_execute_option, b_service_responding, b_service_single_launch, b_service_multi_launch, "
1691                  "b_event_handler_click_on_button_1, b_event_handler_click_on_button_2, b_event_handler_click_on_button_3, "
1692                  "b_event_handler_click_on_button_4, b_event_handler_click_on_button_5, b_event_handler_click_on_button_6, "
1693                  "b_event_handler_click_on_icon, b_event_handler_click_on_thumbnail, "
1694                  "sound_type, sound_path, vibration_type, vibration_path, led_operation, led_argb, led_on_ms, led_off_ms, "
1695                  "flags_for_property, display_applist, progress_size, progress_percentage "
1696                  "from noti_list ");
1697
1698         if (priv_id == NOTIFICATION_PRIV_ID_NONE && group_id == NOTIFICATION_GROUP_ID_NONE) {
1699                 if (status == VCONFKEY_TELEPHONY_SIM_INSERTED) {
1700                         snprintf(query_where, sizeof(query_where),
1701                                  "where  caller_pkgname = '%s' ", pkgname);
1702                 } else {
1703                         snprintf(query_where, sizeof(query_where),
1704                                  "where  caller_pkgname = '%s' and flag_simmode = 0 ", pkgname);
1705                 }
1706         } else {
1707                 internal_group_id =
1708                     _notification_noti_get_internal_group_id_by_priv_id(pkgname,
1709                                                                         priv_id, db);
1710
1711                 if (status == VCONFKEY_TELEPHONY_SIM_INSERTED) {
1712                         snprintf(query_where, sizeof(query_where),
1713                                  "where  caller_pkgname = '%s' and internal_group_id = %d ",
1714                                  pkgname, internal_group_id);
1715                 } else {
1716                         snprintf(query_where, sizeof(query_where),
1717                                  "where  caller_pkgname = '%s' and internal_group_id = %d and flag_simmode = 0 ",
1718                                  pkgname, internal_group_id);
1719                 }
1720         }
1721
1722         snprintf(query, sizeof(query),
1723                  "%s %s "
1724                  "order by rowid desc, time desc", query_base, query_where);
1725
1726         ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
1727         if (ret != SQLITE_OK) {
1728                 NOTIFICATION_ERR("Select Query : %s", query);
1729                 NOTIFICATION_ERR("Select DB error(%d) : %s", ret,
1730                                  sqlite3_errmsg(db));
1731
1732                 ret = NOTIFICATION_ERROR_FROM_DB;
1733                 goto err;
1734         }
1735
1736         while (sqlite3_step(stmt) == SQLITE_ROW) {
1737                 /* Make notification list */
1738                 noti = _notification_noti_get_item(stmt);
1739                 if (noti != NULL) {
1740                         internal_count++;
1741
1742                         get_list = notification_list_append(get_list, noti);
1743
1744                         if (count != -1 && internal_count >= count) {
1745                                 NOTIFICATION_INFO
1746                                     ("internal count %d >= count %d",
1747                                      internal_count, count);
1748                                 break;
1749                         }
1750                 }
1751         }
1752
1753         ret = NOTIFICATION_ERROR_NONE;
1754
1755 err:
1756         if (stmt) {
1757                 sqlite3_finalize(stmt);
1758         }
1759
1760         /* Close DB */
1761         if (db) {
1762                 notification_db_close(&db);
1763         }
1764
1765         if (get_list != NULL) {
1766                 *list = notification_list_get_head(get_list);
1767         }
1768
1769         return ret;
1770 }
1771
1772 EXPORT_API int notification_noti_check_tag(notification_h noti)
1773 {
1774         int result = 0;
1775         int ret = NOTIFICATION_ERROR_NONE;
1776         sqlite3 *db;
1777         sqlite3_stmt *stmt = NULL;
1778
1779         if (noti->tag == NULL) {
1780                 return NOTIFICATION_ERROR_NOT_EXIST_ID;
1781         }
1782
1783         /* Open DB */
1784         db = notification_db_open(DBPATH);
1785         if (!db) {
1786                 return get_last_result();
1787         }
1788
1789         ret = sqlite3_prepare_v2(db, "SELECT priv_id FROM noti_list WHERE caller_pkgname = ? and tag = ?", -1, &stmt, NULL);
1790         if (ret != SQLITE_OK) {
1791                 NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
1792                 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
1793         }
1794
1795         ret = sqlite3_bind_text(stmt, 1, noti->caller_pkgname, -1, SQLITE_TRANSIENT);
1796         if (ret != SQLITE_OK) {
1797                 NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
1798                 goto err;
1799         }
1800
1801         ret = sqlite3_bind_text(stmt, 2, noti->tag, -1, SQLITE_TRANSIENT);
1802         if (ret != SQLITE_OK) {
1803                 NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
1804                 goto err;
1805         }
1806
1807 /*
1808         query = sqlite3_mprintf("select priv_id from noti_list where caller_pkgname = '%s' and tag = '%s'",
1809                  noti->caller_pkgname, noti->tag);
1810         if (query == NULL) {
1811                 ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
1812                 goto err;
1813         }
1814
1815         ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
1816         if (ret != SQLITE_OK) {
1817                 NOTIFICATION_ERR("Get priv id DB err(%d) : %s", ret,
1818                                  sqlite3_errmsg(db));
1819                 ret = NOTIFICATION_ERROR_FROM_DB;
1820                 goto err;
1821         }
1822 */
1823         ret = sqlite3_step(stmt);
1824         if (ret == SQLITE_ROW) {
1825                 result = sqlite3_column_int(stmt, 0);
1826         } else {
1827                 result = 0;
1828         }
1829
1830         sqlite3_finalize(stmt);
1831
1832         /* If result > 0, there is priv_id in DB */
1833         if (result > 0) {
1834                 noti->priv_id = result;
1835                 ret = NOTIFICATION_ERROR_ALREADY_EXIST_ID;
1836         } else {
1837                 ret = NOTIFICATION_ERROR_NOT_EXIST_ID;
1838         }
1839
1840 err:
1841
1842         return ret;
1843 }