3525865104ada46a84cc2f435544c5d4be60c83e
[apps/home/notification.git] / src / notification.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 <stdlib.h>
24 #include <string.h>
25 #include <unistd.h>
26 #include <fcntl.h>
27 #include <libintl.h>
28
29 #include <aul.h>
30 #include <ail.h>
31 #include <appsvc.h>
32 #include <heynoti.h>
33 #include <vconf-keys.h>
34 #include <vconf.h>
35
36 #include <notification.h>
37 #include <notification_list.h>
38 #include <notification_debug.h>
39 #include <notification_internal.h>
40 #include <notification_noti.h>
41 #include <notification_ongoing.h>
42 #include <notification_group.h>
43
44 typedef struct _notification_cb_list notification_cb_list_s;
45
46 struct _notification_cb_list {
47         notification_cb_list_s *prev;
48         notification_cb_list_s *next;
49
50         void (*changed_cb) (void *data, notification_type_e type);
51         void *data;
52 };
53
54 static notification_cb_list_s *g_notification_cb_list = NULL;
55 static int g_notification_heynoti_fd = -1;
56
57 #define NOTI_PKGNAME_LEN        512
58 #define NOTI_CHANGED_NOTI       "notification_noti_changed"
59 #define NOTI_CHANGED_ONGOING    "notification_ontoing_changed"
60
61 static char *_notification_get_pkgname_by_pid(void)
62 {
63         char buf[NOTI_PKGNAME_LEN] = { 0, };
64         char pkgname[NOTI_PKGNAME_LEN] = { 0, };
65         int pid = 0, ret = AUL_R_OK;
66         int fd;
67
68         pid = getpid();
69
70         ret = aul_app_get_pkgname_bypid(pid, pkgname, sizeof(pkgname));
71         if (ret != AUL_R_OK) {
72                 snprintf(buf, sizeof(buf), "/proc/%d/cmdline", pid);
73
74                 fd = open(buf, O_RDONLY);
75                 if (fd < 0) {
76                         return NULL;
77                 }
78
79                 ret = read(fd, pkgname, sizeof(pkgname) - 1);
80                 if (ret <= 0) {
81                         close(fd);
82                         return NULL;
83                 }
84
85                 buf[ret] = 0;
86
87                 close(fd);
88         }
89
90         if (pkgname == NULL || pkgname[0] == '\0') {
91                 return NULL;
92         } else {
93                 return strdup(pkgname);
94         }
95 }
96
97 static char *_notification_get_icon(const char *package)
98 {
99         ail_appinfo_h handle;
100         ail_error_e ret;
101         char *str = NULL;
102         char *icon = NULL;
103
104         ret = ail_package_get_appinfo(package, &handle);
105         if (ret != AIL_ERROR_OK) {
106                 return NULL;
107         }
108
109         ret = ail_appinfo_get_str(handle, AIL_PROP_ICON_STR, &str);
110         if (ret != AIL_ERROR_OK) {
111                 ail_package_destroy_appinfo(handle);
112                 return NULL;
113         }
114
115         icon = strdup(str);
116
117         ret = ail_package_destroy_appinfo(handle);
118         if (ret != AIL_ERROR_OK) {
119                 NOTIFICATION_ERR("Fail to ail_package_destroy_appinfo");
120         }
121
122         return icon;
123 }
124
125 static char *_notification_get_name(const char *package)
126 {
127         ail_appinfo_h handle;
128         ail_error_e ret;
129         char *str = NULL;
130         char *name = NULL;
131
132         ret = ail_package_get_appinfo(package, &handle);
133         if (ret != AIL_ERROR_OK) {
134                 return NULL;
135         }
136
137         ret = ail_appinfo_get_str(handle, AIL_PROP_NAME_STR, &str);
138         if (ret != AIL_ERROR_OK) {
139                 ail_package_destroy_appinfo(handle);
140                 return NULL;
141         }
142
143         name = strdup(str);
144
145         ret = ail_package_destroy_appinfo(handle);
146         if (ret != AIL_ERROR_OK) {
147                 NOTIFICATION_ERR("Fail to ail_package_destroy_appinfo");
148         }
149
150         return name;
151 }
152
153 static void _notification_get_text_domain(notification_h noti)
154 {
155         if (noti->domain != NULL) {
156
157         }
158
159         if (noti->dir != NULL) {
160
161         }
162 }
163
164 static void _notification_chagned_noti_cb(void *data)
165 {
166         notification_cb_list_s *noti_cb_list = NULL;
167
168         if (g_notification_cb_list == NULL) {
169                 return;
170         }
171
172         noti_cb_list = g_notification_cb_list;
173
174         while (noti_cb_list->prev != NULL) {
175                 noti_cb_list = noti_cb_list->prev;
176         }
177
178         while (noti_cb_list != NULL) {
179                 if (noti_cb_list->changed_cb) {
180                         noti_cb_list->changed_cb(noti_cb_list->data,
181                                                  NOTIFICATION_TYPE_NOTI);
182                 }
183
184                 noti_cb_list = noti_cb_list->next;
185         }
186 }
187
188 #if 0
189 static void _notification_chagned_ongoing_cb(void *data)
190 {
191         notification_cb_list_s *noti_cb_list = NULL;
192
193         if (g_notification_cb_list == NULL) {
194                 return;
195         }
196
197         noti_cb_list = g_notification_cb_list;
198
199         while (noti_cb_list->prev != NULL) {
200                 noti_cb_list = noti_cb_list->prev;
201         }
202
203         while (noti_cb_list != NULL) {
204                 if (noti_cb_list->changed_cb) {
205                         noti_cb_list->changed_cb(noti_cb_list->data,
206                                                  NOTIFICATION_TYPE_ONGOING);
207                 }
208
209                 noti_cb_list = noti_cb_list->next;
210         }
211 }
212 #endif
213
214 static void _notification_changed(const char *type)
215 {
216         heynoti_publish(type);
217 }
218
219 /* notification_set_icon will be removed */
220 EXPORT_API notification_error_e notification_set_icon(notification_h noti,
221                                                       const char *icon_path)
222 {
223         int ret_err = NOTIFICATION_ERROR_NONE;
224
225         ret_err =
226             notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON,
227                                    icon_path);
228
229         return ret_err;
230 }
231
232 /* notification_get_icon will be removed */
233 EXPORT_API notification_error_e notification_get_icon(notification_h noti,
234                                                       char **icon_path)
235 {
236         int ret_err = NOTIFICATION_ERROR_NONE;
237         char *ret_image_path = NULL;
238
239         ret_err =
240             notification_get_image(noti, NOTIFICATION_IMAGE_TYPE_ICON,
241                                    &ret_image_path);
242
243         if (ret_err == NOTIFICATION_ERROR_NONE && icon_path != NULL) {
244                 *icon_path = ret_image_path;
245
246                 //NOTIFICATION_DBG("Get icon : %s", *icon_path);
247         }
248
249         return ret_err;
250 }
251
252 EXPORT_API notification_error_e notification_set_image(notification_h noti,
253                                                        notification_image_type_e type,
254                                                        const char *image_path)
255 {
256         bundle *b = NULL;
257         char buf_key[32] = { 0, };
258         const char *ret_val = NULL;
259
260         /* Check noti and image_path are valid data */
261         if (noti == NULL || image_path == NULL) {
262                 return NOTIFICATION_ERROR_INVALID_DATA;
263         }
264
265         /* Check image type is valid type */
266         if (type <= NOTIFICATION_IMAGE_TYPE_NONE
267             || type >= NOTIFICATION_IMAGE_TYPE_MAX) {
268                 return NOTIFICATION_ERROR_INVALID_DATA;
269         }
270
271         /* Check image path bundle is exist */
272         if (noti->b_image_path) {
273                 /* If image path bundle is exist, store local bundle value */
274                 b = noti->b_image_path;
275
276                 /* Set image type to key as char string type */
277                 snprintf(buf_key, sizeof(buf_key), "%d", type);
278
279                 /* Get value using key */
280                 ret_val = bundle_get_val(b, buf_key);
281                 if (ret_val != NULL) {
282                         /* If key is exist, remove this value to store new image path */
283                         bundle_del(b, buf_key);
284                 }
285
286                 /* Add new image path with type key */
287                 bundle_add(b, buf_key, image_path);
288         } else {
289                 /* If image path bundle is not exist, create new one */
290                 b = bundle_create();
291
292                 /* Set image type to key as char string type */
293                 snprintf(buf_key, sizeof(buf_key), "%d", type);
294
295                 /* Add new image path with type key */
296                 bundle_add(b, buf_key, image_path);
297
298                 /* Save to image path bundle */
299                 noti->b_image_path = b;
300         }
301
302         return NOTIFICATION_ERROR_NONE;
303 }
304
305 EXPORT_API notification_error_e notification_get_image(notification_h noti,
306                                                        notification_image_type_e type,
307                                                        char **image_path)
308 {
309         bundle *b = NULL;
310         char buf_key[32] = { 0, };
311         const char *ret_val = NULL;
312         const char *pkgname = NULL;
313
314         /* Check noti and image_path is valid data */
315         if (noti == NULL || image_path == NULL) {
316                 return NOTIFICATION_ERROR_INVALID_DATA;
317         }
318
319         /* Check image type is valid data */
320         if (type <= NOTIFICATION_IMAGE_TYPE_NONE
321             || type >= NOTIFICATION_IMAGE_TYPE_MAX) {
322                 return NOTIFICATION_ERROR_INVALID_DATA;
323         }
324
325         /* Check image path bundle exist */
326         if (noti->b_image_path) {
327                 /* If image path bundle exist, store local bundle data */
328                 b = noti->b_image_path;
329
330                 /* Set image type to key as char string type */
331                 snprintf(buf_key, sizeof(buf_key), "%d", type);
332
333                 /* Get value of key */
334                 ret_val = bundle_get_val(b, buf_key);
335
336                 *image_path = (char *)ret_val;
337         } else {
338                 /* If image path bundle does not exist, image path is NULL */
339                 *image_path = NULL;
340         }
341
342         /* If image path is NULL and type is ICON, icon path set from AIL */
343         /* order : user icon -> launch_pkgname icon -> caller_pkgname icon -> service app icon */
344         if (*image_path == NULL && type == NOTIFICATION_IMAGE_TYPE_ICON) {
345                 /* Check App icon path is already set */
346                 if (noti->app_icon_path != NULL) {
347                         /* image path will be app icon path */
348                         *image_path = noti->app_icon_path;
349                 } else {
350                         /* Get image path using launch_pkgname */
351                         if (noti->launch_pkgname != NULL) {
352                                 noti->app_icon_path =
353                                     _notification_get_icon(noti->launch_pkgname);
354                         }
355
356                         /* If app icon path is NULL, get image path using caller_pkgname */
357                         if (noti->app_icon_path == NULL
358                             && noti->caller_pkgname != NULL) {
359                                 noti->app_icon_path =
360                                     _notification_get_icon(noti->caller_pkgname);
361                         }
362
363                         /* If app icon path is NULL, get image path using service data */
364                         if (noti->app_icon_path == NULL
365                             && noti->b_service_single_launch != NULL) {
366                                 pkgname =
367                                     appsvc_get_pkgname(noti->b_service_single_launch);
368                                 if (pkgname != NULL) {
369                                         noti->app_icon_path =
370                                             _notification_get_icon(pkgname);
371                                 }
372                         }
373
374                         *image_path = noti->app_icon_path;
375                 }
376         }
377
378         return NOTIFICATION_ERROR_NONE;
379 }
380
381 EXPORT_API notification_error_e notification_set_time(notification_h noti,
382                                                       time_t input_time)
383 {
384         /* Check noti is valid data */
385         if (noti == NULL) {
386                 return NOTIFICATION_ERROR_INVALID_DATA;
387         }
388
389         if (input_time == 0) {
390                 /* If input time is 0, set current time */
391                 noti->time = time(NULL);
392         } else {
393                 /* save input time */
394                 noti->time = input_time;
395         }
396
397         return NOTIFICATION_ERROR_NONE;
398 }
399
400 EXPORT_API notification_error_e notification_get_time(notification_h noti,
401                                                       time_t * ret_time)
402 {
403         /* Check noti and time is valid data */
404         if (noti == NULL || ret_time == NULL) {
405                 return NOTIFICATION_ERROR_INVALID_DATA;
406         }
407
408         /* Set time infomation */
409         *ret_time = noti->time;
410
411         return NOTIFICATION_ERROR_NONE;
412 }
413
414 EXPORT_API notification_error_e notification_get_insert_time(notification_h noti,
415                                                              time_t * ret_time)
416 {
417         /* Check noti and ret_time is valid data */
418         if (noti == NULL || ret_time == NULL) {
419                 return NOTIFICATION_ERROR_INVALID_DATA;
420         }
421
422         /* Set insert time information */
423         *ret_time = noti->insert_time;
424
425         return NOTIFICATION_ERROR_NONE;
426 }
427
428 EXPORT_API notification_error_e notification_set_title(notification_h noti,
429                                                        const char *title,
430                                                        const char *loc_title)
431 {
432         int noti_err = NOTIFICATION_ERROR_NONE;
433
434         noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE,
435                                          title, loc_title,
436                                          NOTIFICATION_VARIABLE_TYPE_NONE);
437
438         return noti_err;
439 }
440
441 EXPORT_API notification_error_e notification_get_title(notification_h noti,
442                                                        char **title,
443                                                        char **loc_title)
444 {
445         int noti_err = NOTIFICATION_ERROR_NONE;
446         char *ret_text = NULL;
447
448         noti_err =
449             notification_get_text(noti, NOTIFICATION_TEXT_TYPE_TITLE,
450                                   &ret_text);
451
452         if (title != NULL) {
453                 *title = ret_text;
454         }
455
456         if (loc_title != NULL) {
457                 *loc_title = NULL;
458         }
459
460         return noti_err;
461 }
462
463 EXPORT_API notification_error_e notification_set_content(notification_h noti,
464                                                          const char *content,
465                                                          const char *loc_content)
466 {
467         int noti_err = NOTIFICATION_ERROR_NONE;
468
469         noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT,
470                                          content, loc_content,
471                                          NOTIFICATION_VARIABLE_TYPE_NONE);
472
473         return noti_err;
474 }
475
476 EXPORT_API notification_error_e notification_get_content(notification_h noti,
477                                                          char **content,
478                                                          char **loc_content)
479 {
480         int noti_err = NOTIFICATION_ERROR_NONE;
481         char *ret_text = NULL;
482
483         noti_err =
484             notification_get_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT,
485                                   &ret_text);
486
487         if (content != NULL) {
488                 *content = ret_text;
489         }
490
491         if (loc_content != NULL) {
492                 *loc_content = NULL;
493         }
494
495         return noti_err;
496
497 #if 0
498         ret =
499             vconf_get_bool
500             (VCONFKEY_SETAPPL_STATE_TICKER_NOTI_DISPLAY_CONTENT_BOOL, &boolval);
501
502         if (ret == -1 || boolval == 0) {
503                 if (content != NULL && noti->default_content != NULL) {
504                         *content = noti->default_content;
505                 }
506
507                 if (loc_content != NULL && noti->loc_default_content != NULL) {
508                         *loc_content = noti->loc_default_content;
509                 }
510         }
511 #endif
512 }
513
514 EXPORT_API notification_error_e notification_set_text(notification_h noti,
515                                                       notification_text_type_e type,
516                                                       const char *text,
517                                                       const char *key,
518                                                       int args_type, ...)
519 {
520         bundle *b = NULL;
521         char buf_key[32] = { 0, };
522         char buf_val[1024] = { 0, };
523         const char *ret_val = NULL;
524         va_list var_args;
525         notification_variable_type_e var_type;
526         int num_args = 0;
527         notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
528         int var_value_int = 0;
529         double var_value_double = 0.0;
530         char *var_value_string = NULL;
531         notification_count_pos_type_e var_value_count =
532             NOTIFICATION_COUNT_POS_NONE;
533
534         /* Check noti is valid data */
535         if (noti == NULL) {
536                 return NOTIFICATION_ERROR_INVALID_DATA;
537         }
538
539         /* Check text type is valid type */
540         if (type <= NOTIFICATION_TEXT_TYPE_NONE
541             || type >= NOTIFICATION_TEXT_TYPE_MAX) {
542                 return NOTIFICATION_ERROR_INVALID_DATA;
543         }
544
545         /* Check text bundle exist */
546         if (text != NULL) {
547                 if (noti->b_text != NULL) {
548                         /* If text bundle exist, store local bundle data */
549                         b = noti->b_text;
550
551                         /* Make type to key as char string */
552                         snprintf(buf_key, sizeof(buf_key), "%d", type);
553
554                         /* Get value using type key */
555                         ret_val = bundle_get_val(b, buf_key);
556                         if (ret_val != NULL) {
557                                 /* If value exist, remove this to add new value */
558                                 bundle_del(b, buf_key);
559                         }
560
561                         snprintf(buf_val, sizeof(buf_val), "%s", text);
562
563                         /* Add new text value */
564                         bundle_add(b, buf_key, buf_val);
565                 } else {
566                         /* If text bundle does not exist, create new one */
567                         b = bundle_create();
568
569                         /* Make type to key as char string */
570                         snprintf(buf_key, sizeof(buf_key), "%d", type);
571
572                         snprintf(buf_val, sizeof(buf_val), "%s", text);
573
574                         /* Add new text value */
575                         bundle_add(b, buf_key, buf_val);
576
577                         /* Save text bundle */
578                         noti->b_text = b;
579                 }
580         } else {
581                 /* Reset if text is NULL */
582                 if (noti->b_text != NULL) {
583                         /* If text bundle exist, store local bundle data */
584                         b = noti->b_text;
585
586                         /* Make type to key as char string */
587                         snprintf(buf_key, sizeof(buf_key), "%d", type);
588
589                         /* Get value using type key */
590                         ret_val = bundle_get_val(b, buf_key);
591                         if (ret_val != NULL) {
592                                 /* If value exist, remove this */
593                                 bundle_del(b, buf_key);
594                         }
595                 }
596         }
597
598         /* Save key if key is valid data */
599         if (key != NULL) {
600                 /* Check key bundle exist */
601                 if (noti->b_key != NULL) {
602                         /* If key bundle exist,  store local bundle data */
603                         b = noti->b_key;
604
605                         /* Make type to key as char string */
606                         snprintf(buf_key, sizeof(buf_key), "%d", type);
607
608                         /* Get value using type key */
609                         ret_val = bundle_get_val(b, buf_key);
610                         if (ret_val != NULL) {
611                                 /* If value exist, remove this to add new value */
612                                 bundle_del(b, buf_key);
613                         }
614
615                         snprintf(buf_val, sizeof(buf_val), "%s", key);
616
617                         /* Add new key value */
618                         bundle_add(b, buf_key, buf_val);
619                 } else {
620                         /* If key bundle does not exist, create new one */
621                         b = bundle_create();
622
623                         /* Make type to key as char string */
624                         snprintf(buf_key, sizeof(buf_key), "%d", type);
625
626                         snprintf(buf_val, sizeof(buf_val), "%s", key);
627
628                         /* Add new key value */
629                         bundle_add(b, buf_key, buf_val);
630
631                         /* Save key bundle */
632                         noti->b_key = b;
633                 }
634         } else {
635                 /* Reset if key is NULL */
636                 if (noti->b_key != NULL) {
637                         /* If key bundle exist,  store local bundle data */
638                         b = noti->b_key;
639
640                         /* Make type to key as char string */
641                         snprintf(buf_key, sizeof(buf_key), "%d", type);
642
643                         /* Get value using type key */
644                         ret_val = bundle_get_val(b, buf_key);
645                         if (ret_val != NULL) {
646                                 /* If value exist, remove this */
647                                 bundle_del(b, buf_key);
648                         }
649                 }
650         }
651
652         if (noti->b_format_args != NULL) {
653                 b = noti->b_format_args;
654         } else {
655                 b = bundle_create();
656         }
657
658         va_start(var_args, args_type);
659
660         var_type = args_type;
661         num_args = 0;
662
663         while (var_type != NOTIFICATION_VARIABLE_TYPE_NONE) {
664                 /* Type */
665                 snprintf(buf_key, sizeof(buf_key), "%dtype%d", type, num_args);
666                 snprintf(buf_val, sizeof(buf_val), "%d", var_type);
667
668                 ret_val = bundle_get_val(b, buf_key);
669                 if (ret_val != NULL) {
670                         bundle_del(b, buf_key);
671                 }
672
673                 bundle_add(b, buf_key, buf_val);
674
675                 switch (var_type) {
676                 case NOTIFICATION_VARIABLE_TYPE_INT:
677                         var_value_int = va_arg(var_args, int);
678
679                         /* Value */
680                         snprintf(buf_key, sizeof(buf_key), "%dvalue%d", type,
681                                  num_args);
682                         snprintf(buf_val, sizeof(buf_val), "%d", var_value_int);
683
684                         ret_val = bundle_get_val(b, buf_key);
685                         if (ret_val != NULL) {
686                                 bundle_del(b, buf_key);
687                         }
688
689                         bundle_add(b, buf_key, buf_val);
690                         break;
691                 case NOTIFICATION_VARIABLE_TYPE_DOUBLE:
692                         var_value_double = va_arg(var_args, double);
693
694                         /* Value */
695                         snprintf(buf_key, sizeof(buf_key), "%dvalue%d", type,
696                                  num_args);
697                         snprintf(buf_val, sizeof(buf_val), "%.2f",
698                                  var_value_double);
699
700                         ret_val = bundle_get_val(b, buf_key);
701                         if (ret_val != NULL) {
702                                 bundle_del(b, buf_key);
703                         }
704
705                         bundle_add(b, buf_key, buf_val);
706                         break;
707                 case NOTIFICATION_VARIABLE_TYPE_STRING:
708                         var_value_string = va_arg(var_args, char *);
709
710                         /* Value */
711                         snprintf(buf_key, sizeof(buf_key), "%dvalue%d", type,
712                                  num_args);
713                         snprintf(buf_val, sizeof(buf_val), "%s",
714                                  var_value_string);
715
716                         ret_val = bundle_get_val(b, buf_key);
717                         if (ret_val != NULL) {
718                                 bundle_del(b, buf_key);
719                         }
720
721                         bundle_add(b, buf_key, buf_val);
722                         break;
723                 case NOTIFICATION_VARIABLE_TYPE_COUNT:
724                         var_value_count =
725                             va_arg(var_args, notification_count_pos_type_e);
726
727                         /* Value */
728                         snprintf(buf_key, sizeof(buf_key), "%dvalue%d", type,
729                                  num_args);
730                         snprintf(buf_val, sizeof(buf_val), "%d",
731                                  var_value_count);
732
733                         ret_val = bundle_get_val(b, buf_key);
734                         if (ret_val != NULL) {
735                                 bundle_del(b, buf_key);
736                         }
737
738                         bundle_add(b, buf_key, buf_val);
739                         break;
740                 default:
741                         NOTIFICATION_ERR("Error. invalid variable type. : %d",
742                                          var_type);
743                         noti_err = NOTIFICATION_ERROR_INVALID_DATA;
744                         break;
745                 }
746
747                 num_args++;
748                 var_type = va_arg(var_args, notification_variable_type_e);
749         }
750         va_end(var_args);
751
752         if (noti_err == NOTIFICATION_ERROR_NONE) {
753                 noti->num_format_args = num_args;
754         } else {
755                 noti->num_format_args = 0;
756         }
757
758         snprintf(buf_key, sizeof(buf_key), "num%d", type);
759         snprintf(buf_val, sizeof(buf_val), "%d", noti->num_format_args);
760
761         ret_val = bundle_get_val(b, buf_key);
762         if (ret_val != NULL) {
763                 bundle_del(b, buf_key);
764         }
765
766         bundle_add(b, buf_key, buf_val);
767
768         noti->b_format_args = b;
769
770         return noti_err;
771 }
772
773 EXPORT_API notification_error_e notification_get_text(notification_h noti,
774                                                       notification_text_type_e type,
775                                                       char **text)
776 {
777         bundle *b = NULL;
778         char buf_key[32] = { 0, };
779         const char *ret_val = NULL;
780         const char *pkgname = NULL;
781         const char *get_str = NULL;
782         const char *get_check_type_str = NULL;
783         int ret = 0;
784         int boolval = 0;
785         notification_text_type_e check_type = NOTIFICATION_TEXT_TYPE_NONE;
786         int display_option_flag = 0;
787
788         char *temp_str = NULL;
789         char result_str[1024] = { 0, };
790         char buf_str[1024] = { 0, };
791         int num_args = 0;
792         notification_variable_type_e ret_var_type = 0;
793         int ret_variable_int = 0;
794         double ret_variable_double = 0.0;
795
796         /* Check noti is valid data */
797         if (noti == NULL || text == NULL) {
798                 return NOTIFICATION_ERROR_INVALID_DATA;
799         }
800
801         /* Check text type is valid type */
802         if (type <= NOTIFICATION_TEXT_TYPE_NONE
803             || type >= NOTIFICATION_TEXT_TYPE_MAX) {
804                 return NOTIFICATION_ERROR_INVALID_DATA;
805         }
806
807         /* Check content display option of setting */
808         if (type == NOTIFICATION_TEXT_TYPE_CONTENT
809             || type == NOTIFICATION_TEXT_TYPE_GROUP_CONTENT) {
810                 ret =
811                     vconf_get_bool
812                     (VCONFKEY_SETAPPL_STATE_TICKER_NOTI_DISPLAY_CONTENT_BOOL,
813                      &boolval);
814                 if (ret == -1 || boolval == 0) {
815                         /* Set flag as display option is OFF */
816                         //display_option_flag = 1;
817                 }
818         }
819
820         /* Check key */
821         if (noti->b_key != NULL) {
822                 b = noti->b_key;
823
824                 /* Get text domain and dir */
825                 _notification_get_text_domain(noti);
826
827                 snprintf(buf_key, sizeof(buf_key), "%d", type);
828
829                 ret_val = bundle_get_val(b, buf_key);
830                 if (ret_val != NULL && noti->domain != NULL
831                     && noti->dir != NULL) {
832                         /* Get application string */
833                         bindtextdomain(noti->domain, noti->dir);
834
835                         get_str = dgettext(noti->domain, ret_val);
836                 } else if (ret_val != NULL) {
837                         /* Get system string */
838                         get_str = dgettext("sys_string", ret_val);
839                 } else {
840                         get_str = NULL;
841                 }
842         }
843
844         if (get_str == NULL && noti->b_text != NULL) {
845                 b = noti->b_text;
846                 /* Get basic text */
847                 snprintf(buf_key, sizeof(buf_key), "%d", type);
848
849                 get_str = bundle_get_val(b, buf_key);
850         }
851
852         check_type = type;
853
854         /* Set display option is off type when option is off, type is noti */
855         if (get_str != NULL && display_option_flag == 1
856             && noti->type == NOTIFICATION_TYPE_NOTI) {
857                 if (type == NOTIFICATION_TEXT_TYPE_CONTENT
858                     || type == NOTIFICATION_TEXT_TYPE_GROUP_CONTENT) {
859                         /* Set check_type to option content string */
860                         if (type == NOTIFICATION_TEXT_TYPE_CONTENT) {
861                                 check_type =
862                                     NOTIFICATION_TEXT_TYPE_CONTENT_FOR_DISPLAY_OPTION_IS_OFF;
863                         } else if (type == NOTIFICATION_TEXT_TYPE_GROUP_CONTENT) {
864                                 check_type =
865                                     NOTIFICATION_TEXT_TYPE_GROUP_CONTENT_FOR_DISPLAY_OPTION_IS_OFF;
866                         }
867
868                         /* Check key */
869                         if (noti->b_key != NULL) {
870                                 b = noti->b_key;
871
872                                 /* Get text domain and dir */
873                                 _notification_get_text_domain(noti);
874
875                                 snprintf(buf_key, sizeof(buf_key), "%d",
876                                          check_type);
877
878                                 ret_val = bundle_get_val(b, buf_key);
879                                 if (ret_val != NULL && noti->domain != NULL
880                                     && noti->dir != NULL) {
881                                         /* Get application string */
882                                         bindtextdomain(noti->domain, noti->dir);
883
884                                         get_check_type_str =
885                                             dgettext(noti->domain, ret_val);
886                                 } else if (ret_val != NULL) {
887                                         /* Get system string */
888                                         get_check_type_str =
889                                             dgettext("sys_string", ret_val);
890                                 } else {
891                                         get_check_type_str = NULL;
892                                 }
893                         }
894
895                         if (get_check_type_str == NULL && noti->b_text != NULL) {
896                                 b = noti->b_text;
897                                 /* Get basic text */
898                                 snprintf(buf_key, sizeof(buf_key), "%d",
899                                          check_type);
900
901                                 get_check_type_str = bundle_get_val(b, buf_key);
902                         }
903                 }
904
905                 if (get_check_type_str != NULL) {
906                         /* Replace option off type string */
907                         get_str = get_check_type_str;
908                 } else {
909                         /* Set default string */
910                         get_str =
911                             dgettext("sys_string", "IDS_COM_POP_MISSED_EVENT");
912                 }
913         }
914
915         if (get_str != NULL) {
916                 /* Get number format args */
917                 b = noti->b_format_args;
918                 noti->num_format_args = 0;
919
920                 if (b != NULL) {
921                         snprintf(buf_key, sizeof(buf_key), "num%d", check_type);
922                         ret_val = bundle_get_val(b, buf_key);
923                         if (ret_val != NULL) {
924                                 noti->num_format_args = atoi(ret_val);
925                         }
926                 }
927
928                 if (noti->num_format_args == 0) {
929                         *text = (char *)get_str;
930                 } else {
931                         /* Check first variable is count, LEFT pos */
932                         snprintf(buf_key, sizeof(buf_key), "%dtype%d",
933                                  check_type, num_args);
934                         ret_val = bundle_get_val(b, buf_key);
935                         ret_var_type = atoi(ret_val);
936
937                         if (ret_var_type == NOTIFICATION_VARIABLE_TYPE_COUNT) {
938                                 /* Get var Value */
939                                 snprintf(buf_key, sizeof(buf_key), "%dvalue%d",
940                                          check_type, num_args);
941                                 ret_val = bundle_get_val(b, buf_key);
942                                 ret_variable_int = atoi(ret_val);
943
944                                 if (ret_variable_int ==
945                                     NOTIFICATION_COUNT_POS_LEFT) {
946                                         notification_noti_get_count(noti->type,
947                                                                     noti->caller_pkgname,
948                                                                     noti->group_id,
949                                                                     noti->priv_id,
950                                                                     &ret_variable_int);
951                                         snprintf(buf_str, sizeof(buf_str),
952                                                  "%d ", ret_variable_int);
953                                         strncat(result_str, buf_str,
954                                                 sizeof(result_str));
955
956                                         num_args++;
957                                 }
958
959                         }
960
961                         /* Check variable IN pos */
962                         for (temp_str = (char *)get_str; *temp_str != '\0';
963                              temp_str++) {
964                                 if (*temp_str != '%') {
965                                         strncat(result_str, temp_str, 1);
966                                 } else {
967                                         if (*(temp_str + 1) == '%') {
968                                                 strncat(result_str, temp_str,
969                                                         1);
970                                         } else if (*(temp_str + 1) == 'd') {
971                                                 /* Get var Type */
972                                                 ret_variable_int = 0;
973
974                                                 snprintf(buf_key,
975                                                          sizeof(buf_key),
976                                                          "%dtype%d", check_type,
977                                                          num_args);
978                                                 ret_val =
979                                                     bundle_get_val(b, buf_key);
980                                                 ret_var_type = atoi(ret_val);
981                                                 if (ret_var_type ==
982                                                     NOTIFICATION_VARIABLE_TYPE_COUNT)
983                                                 {
984                                                         /* Get notification count */
985                                                         notification_noti_get_count
986                                                             (noti->type,
987                                                              noti->caller_pkgname,
988                                                              noti->group_id,
989                                                              noti->priv_id,
990                                                              &ret_variable_int);
991                                                 } else {
992                                                         /* Get var Value */
993                                                         snprintf(buf_key,
994                                                                  sizeof
995                                                                  (buf_key),
996                                                                  "%dvalue%d",
997                                                                  check_type,
998                                                                  num_args);
999                                                         ret_val =
1000                                                             bundle_get_val(b,
1001                                                                            buf_key);
1002                                                         ret_variable_int =
1003                                                             atoi(ret_val);
1004                                                 }
1005
1006                                                 snprintf(buf_str,
1007                                                          sizeof(buf_str), "%d",
1008                                                          ret_variable_int);
1009                                                 strncat(result_str, buf_str,
1010                                                         sizeof(result_str));
1011
1012                                                 temp_str++;
1013
1014                                                 num_args++;
1015                                         } else if (*(temp_str + 1) == 's') {
1016                                                 /* Get var Value */
1017                                                 snprintf(buf_key,
1018                                                          sizeof(buf_key),
1019                                                          "%dvalue%d",
1020                                                          check_type, num_args);
1021                                                 ret_val =
1022                                                     bundle_get_val(b, buf_key);
1023
1024                                                 snprintf(buf_str,
1025                                                          sizeof(buf_str), "%s",
1026                                                          ret_val);
1027                                                 strncat(result_str, buf_str,
1028                                                         sizeof(result_str));
1029
1030                                                 temp_str++;
1031
1032                                                 num_args++;
1033                                         } else if (*(temp_str + 1) == 'f') {
1034                                                 /* Get var Value */
1035                                                 snprintf(buf_key,
1036                                                          sizeof(buf_key),
1037                                                          "%dvalue%d",
1038                                                          check_type, num_args);
1039                                                 ret_val =
1040                                                     bundle_get_val(b, buf_key);
1041                                                 ret_variable_double =
1042                                                     atof(ret_val);
1043
1044                                                 snprintf(buf_str,
1045                                                          sizeof(buf_str),
1046                                                          "%.2f",
1047                                                          ret_variable_double);
1048                                                 strncat(result_str, buf_str,
1049                                                         sizeof(result_str));
1050
1051                                                 temp_str++;
1052
1053                                                 num_args++;
1054                                         }
1055                                 }
1056
1057                         }
1058
1059                         /* Check last variable is count, LEFT pos */
1060                         if (num_args < noti->num_format_args) {
1061                                 snprintf(buf_key, sizeof(buf_key), "%dtype%d",
1062                                          check_type, num_args);
1063                                 ret_val = bundle_get_val(b, buf_key);
1064                                 ret_var_type = atoi(ret_val);
1065                                 if (ret_var_type ==
1066                                     NOTIFICATION_VARIABLE_TYPE_COUNT) {
1067                                         /* Get var Value */
1068                                         snprintf(buf_key, sizeof(buf_key),
1069                                                  "%dvalue%d", check_type,
1070                                                  num_args);
1071                                         ret_val = bundle_get_val(b, buf_key);
1072                                         ret_variable_int = atoi(ret_val);
1073
1074                                         if (ret_variable_int ==
1075                                             NOTIFICATION_COUNT_POS_RIGHT) {
1076                                                 notification_noti_get_count
1077                                                     (noti->type,
1078                                                      noti->caller_pkgname,
1079                                                      noti->group_id,
1080                                                      noti->priv_id,
1081                                                      &ret_variable_int);
1082                                                 snprintf(buf_str,
1083                                                          sizeof(buf_str), " %d",
1084                                                          ret_variable_int);
1085                                                 strncat(result_str, buf_str,
1086                                                         sizeof(result_str));
1087
1088                                                 num_args++;
1089                                         }
1090
1091                                 }
1092                         }
1093
1094                         switch (check_type) {
1095                         case NOTIFICATION_TEXT_TYPE_TITLE:
1096                         case NOTIFICATION_TEXT_TYPE_GROUP_TITLE:
1097                                 if (noti->temp_title != NULL)
1098                                         free(noti->temp_title);
1099
1100                                 noti->temp_title = strdup(result_str);
1101
1102                                 *text = noti->temp_title;
1103                                 break;
1104                         case NOTIFICATION_TEXT_TYPE_CONTENT:
1105                         case NOTIFICATION_TEXT_TYPE_CONTENT_FOR_DISPLAY_OPTION_IS_OFF:
1106                         case NOTIFICATION_TEXT_TYPE_GROUP_CONTENT:
1107                         case NOTIFICATION_TEXT_TYPE_GROUP_CONTENT_FOR_DISPLAY_OPTION_IS_OFF:
1108                                 if (noti->temp_content !=
1109                                     NULL)
1110                                         free(noti->temp_content);
1111
1112                                 noti->temp_content = strdup(result_str);
1113
1114                                 *text = noti->temp_content;
1115                                 break;
1116                         default:
1117                                 break;
1118                         }
1119
1120                 }
1121
1122         } else {
1123                 if (check_type == NOTIFICATION_TEXT_TYPE_TITLE
1124                     || check_type == NOTIFICATION_TEXT_TYPE_GROUP_TITLE) {
1125                         /* Remove app name if exist, because pkgname is changed according to language setting */
1126                         if (noti->app_name != NULL) {
1127                                 free(noti->app_name);
1128                                 noti->app_name = NULL;
1129                         }
1130
1131                         /* First, get app name from launch_pkgname */
1132                         if (noti->launch_pkgname != NULL) {
1133                                 noti->app_name =
1134                                     _notification_get_name(noti->
1135                                                            launch_pkgname);
1136                         }
1137
1138                         /* Second, get app name from caller_pkgname */
1139                         if (noti->app_name == NULL
1140                             && noti->caller_pkgname != NULL) {
1141                                 noti->app_name =
1142                                     _notification_get_name(noti->
1143                                                            caller_pkgname);
1144                         }
1145
1146                         /* Third, get app name from service data */
1147                         if (noti->app_name == NULL
1148                             && noti->b_service_single_launch != NULL) {
1149                                 pkgname =
1150                                     appsvc_get_pkgname(noti->
1151                                                        b_service_single_launch);
1152
1153                                 if (pkgname != NULL) {
1154                                         noti->app_name =
1155                                             _notification_get_name(pkgname);
1156                                 }
1157                         }
1158
1159                         *text = noti->app_name;
1160                 } else {
1161                         *text = NULL;
1162                 }
1163         }
1164
1165         NOTIFICATION_INFO("Get text : %s", *text);
1166
1167         return NOTIFICATION_ERROR_NONE;
1168 }
1169
1170 EXPORT_API notification_error_e notification_set_text_domain(notification_h noti,
1171                                                              const char *domain,
1172                                                              const char *dir)
1173 {
1174         /* check noti and domain is valid data */
1175         if (noti == NULL || domain == NULL) {
1176                 return NOTIFICATION_ERROR_INVALID_DATA;
1177         }
1178
1179         /* Check domain */
1180         if (noti->domain) {
1181                 /* Remove previous domain */
1182                 free(noti->domain);
1183         }
1184         /* Copy domain */
1185         noti->domain = strdup(domain);
1186
1187         /* Check locale dir */
1188         if (noti->dir) {
1189                 /* Remove previous locale dir */
1190                 free(noti->dir);
1191         }
1192         /* Copy locale dir */
1193         noti->dir = strdup(dir);
1194
1195         return NOTIFICATION_ERROR_NONE;
1196 }
1197
1198 EXPORT_API notification_error_e notification_get_text_domain(notification_h noti,
1199                                                              char **domain,
1200                                                              char **dir)
1201 {
1202         /* Check noti is valid data */
1203         if (noti == NULL) {
1204                 return NOTIFICATION_ERROR_INVALID_DATA;
1205         }
1206
1207         /* Get domain */
1208         if (domain != NULL && noti->domain != NULL) {
1209                 *domain = noti->domain;
1210         }
1211
1212         /* Get locale dir */
1213         if (dir != NULL && noti->dir != NULL) {
1214                 *dir = noti->dir;
1215         }
1216
1217         return NOTIFICATION_ERROR_NONE;
1218 }
1219
1220 EXPORT_API notification_error_e notification_set_sound(notification_h noti,
1221                                                        notification_sound_type_e type,
1222                                                        const char *path)
1223 {
1224         /* Check noti is valid data */
1225         if (noti == NULL) {
1226                 return NOTIFICATION_ERROR_INVALID_DATA;
1227         }
1228
1229         /* Check type is valid */
1230         if (type < NOTIFICATION_SOUND_TYPE_NONE
1231             || type >= NOTIFICATION_SOUND_TYPE_MAX) {
1232                 return NOTIFICATION_ERROR_INVALID_DATA;
1233         }
1234
1235         /* Save sound type */
1236         noti->sound_type = type;
1237
1238         /* Save sound path if user data type */
1239         if (type == NOTIFICATION_SOUND_TYPE_USER_DATA && path != NULL) {
1240                 if (noti->sound_path != NULL) {
1241                         free(noti->sound_path);
1242                 }
1243
1244                 noti->sound_path = strdup(path);
1245         } else {
1246                 if (noti->sound_path != NULL) {
1247                         free(noti->sound_path);
1248                         noti->sound_path = NULL;
1249                 }
1250         }
1251
1252         return NOTIFICATION_ERROR_NONE;
1253 }
1254
1255 EXPORT_API notification_error_e notification_get_sound(notification_h noti,
1256                                                        notification_sound_type_e *type,
1257                                                        const char **path)
1258 {
1259         /* check noti and type is valid data */
1260         if (noti == NULL || type == NULL) {
1261                 return NOTIFICATION_ERROR_INVALID_DATA;
1262         }
1263
1264         /* Set sound type */
1265         *type = noti->sound_type;
1266
1267         /* Set sound path if user data type */
1268         if (noti->sound_type == NOTIFICATION_SOUND_TYPE_USER_DATA
1269             && path != NULL) {
1270                 *path = noti->sound_path;
1271         }
1272
1273         return NOTIFICATION_ERROR_NONE;
1274 }
1275
1276 EXPORT_API notification_error_e notification_set_vibration(notification_h noti,
1277                                                            notification_vibration_type_e type,
1278                                                            const char *path)
1279 {
1280         /* Check noti is valid data */
1281         if (noti == NULL) {
1282                 return NOTIFICATION_ERROR_INVALID_DATA;
1283         }
1284
1285         /* Check type is valid */
1286         if (type < NOTIFICATION_VIBRATION_TYPE_NONE
1287             || type >= NOTIFICATION_VIBRATION_TYPE_MAX) {
1288                 return NOTIFICATION_ERROR_INVALID_DATA;
1289         }
1290
1291         /* Save vibration type */
1292         noti->vibration_type = type;
1293
1294         /* Save sound path if user data type */
1295         if (type == NOTIFICATION_VIBRATION_TYPE_USER_DATA && path != NULL) {
1296                 if (noti->vibration_path != NULL) {
1297                         free(noti->vibration_path);
1298                 }
1299
1300                 noti->vibration_path = strdup(path);
1301         } else {
1302                 if (noti->vibration_path != NULL) {
1303                         free(noti->vibration_path);
1304                         noti->vibration_path = NULL;
1305                 }
1306         }
1307
1308         return NOTIFICATION_ERROR_NONE;
1309
1310 }
1311
1312 EXPORT_API notification_error_e notification_get_vibration(notification_h noti,
1313                                                            notification_vibration_type_e *type,
1314                                                            const char **path)
1315 {
1316         /* check noti and type is valid data */
1317         if (noti == NULL || type == NULL) {
1318                 return NOTIFICATION_ERROR_INVALID_DATA;
1319         }
1320
1321         /* Set vibration type */
1322         *type = noti->vibration_type;
1323
1324         /* Set sound path if user data type */
1325         if (noti->vibration_type == NOTIFICATION_VIBRATION_TYPE_USER_DATA
1326             && path != NULL) {
1327                 *path = noti->vibration_path;
1328         }
1329
1330         return NOTIFICATION_ERROR_NONE;
1331 }
1332
1333 EXPORT_API notification_error_e notification_set_application(notification_h noti,
1334                                                              const char *pkgname)
1335 {
1336         if (noti == NULL || pkgname == NULL) {
1337                 return NOTIFICATION_ERROR_INVALID_DATA;
1338         }
1339
1340         if (noti->launch_pkgname) {
1341                 free(noti->launch_pkgname);
1342         }
1343
1344         noti->launch_pkgname = strdup(pkgname);
1345
1346         return NOTIFICATION_ERROR_NONE;
1347 }
1348
1349 EXPORT_API notification_error_e notification_get_application(notification_h noti,
1350                                                              char **pkgname)
1351 {
1352         if (noti == NULL || pkgname == NULL) {
1353                 return NOTIFICATION_ERROR_INVALID_DATA;
1354         }
1355
1356         if (noti->launch_pkgname) {
1357                 *pkgname = noti->launch_pkgname;
1358         } else {
1359                 *pkgname = noti->caller_pkgname;
1360         }
1361
1362         return NOTIFICATION_ERROR_NONE;
1363 }
1364
1365 EXPORT_API notification_error_e notification_set_args(notification_h noti,
1366                                                       bundle * args,
1367                                                       bundle * group_args)
1368 {
1369         if (noti == NULL || args == NULL) {
1370                 return NOTIFICATION_ERROR_INVALID_DATA;
1371         }
1372
1373         if (noti->args) {
1374                 bundle_free(noti->args);
1375         }
1376
1377         noti->args = bundle_dup(args);
1378
1379         if (noti->group_args) {
1380                 bundle_free(noti->group_args);
1381                 noti->group_args = NULL;
1382         }
1383
1384         if (group_args != NULL) {
1385                 noti->group_args = bundle_dup(group_args);
1386         }
1387
1388         return NOTIFICATION_ERROR_NONE;
1389 }
1390
1391 EXPORT_API notification_error_e notification_get_args(notification_h noti,
1392                                                       bundle ** args,
1393                                                       bundle ** group_args)
1394 {
1395         if (noti == NULL || args == NULL) {
1396                 return NOTIFICATION_ERROR_INVALID_DATA;
1397         }
1398
1399         if (noti->args) {
1400                 *args = noti->args;
1401         } else {
1402                 *args = NULL;
1403         }
1404
1405         if (group_args != NULL && noti->group_args) {
1406                 *group_args = noti->group_args;
1407         }
1408
1409         return NOTIFICATION_ERROR_NONE;
1410 }
1411
1412 EXPORT_API notification_error_e notification_set_execute_option(notification_h noti,
1413                                                                 notification_execute_type_e type,
1414                                                                 const char *text,
1415                                                                 const char *key,
1416                                                                 bundle *service_handle)
1417 {
1418         char buf_key[32] = { 0, };
1419         const char *ret_val = NULL;
1420         bundle *b = NULL;
1421
1422         if (noti == NULL) {
1423                 return NOTIFICATION_ERROR_INVALID_DATA;
1424         }
1425
1426         if (type <= NOTIFICATION_EXECUTE_TYPE_NONE
1427             || type >= NOTIFICATION_EXECUTE_TYPE_MAX) {
1428                 return NOTIFICATION_ERROR_INVALID_DATA;
1429         }
1430
1431         /* Create execute option bundle if does not exist */
1432         if (noti->b_execute_option != NULL) {
1433                 noti->b_execute_option = bundle_create();
1434         }
1435
1436         b = noti->b_execute_option;
1437
1438         /* Save text */
1439         if (text != NULL) {
1440                 /* Make text key */
1441                 snprintf(buf_key, sizeof(buf_key), "text%d", type);
1442
1443                 /* Check text key exist */
1444                 ret_val = bundle_get_val(b, buf_key);
1445                 if (ret_val != NULL) {
1446                         /* Remove previous data */
1447                         bundle_del(b, buf_key);
1448                 }
1449
1450                 /* Add text data */
1451                 bundle_add(b, buf_key, text);
1452         }
1453
1454         /* Save key */
1455         if (key != NULL) {
1456                 /* Make key key */
1457                 snprintf(buf_key, sizeof(buf_key), "key%d", type);
1458
1459                 /* Check key key exist */
1460                 ret_val = bundle_get_val(b, buf_key);
1461                 if (ret_val != NULL) {
1462                         /* Remove previous data */
1463                         bundle_del(b, buf_key);
1464                 }
1465
1466                 /* Add text data */
1467                 bundle_add(b, buf_key, key);
1468         }
1469
1470         switch (type) {
1471         case NOTIFICATION_EXECUTE_TYPE_RESPONDING:
1472                 /* Remove previous data if exist */
1473                 if (noti->b_service_responding != NULL) {
1474                         bundle_free(noti->b_service_responding);
1475                         noti->b_service_responding = NULL;
1476                 }
1477
1478                 /* Save service handle */
1479                 if (service_handle != NULL) {
1480                         noti->b_service_responding = bundle_dup(service_handle);
1481                 }
1482                 break;
1483         case NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH:
1484                 /* Remove previous data if exist */
1485                 if (noti->b_service_single_launch != NULL) {
1486                         bundle_free(noti->b_service_single_launch);
1487                         noti->b_service_single_launch = NULL;
1488                 }
1489
1490                 /* Save service handle */
1491                 if (service_handle != NULL) {
1492                         noti->b_service_single_launch =
1493                             bundle_dup(service_handle);
1494                 }
1495                 break;
1496         case NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH:
1497                 /* Remove previous data if exist */
1498                 if (noti->b_service_multi_launch != NULL) {
1499                         bundle_free(noti->b_service_multi_launch);
1500                         noti->b_service_multi_launch = NULL;
1501                 }
1502
1503                 /* Save service handle */
1504                 if (service_handle != NULL) {
1505                         noti->b_service_multi_launch =
1506                             bundle_dup(service_handle);
1507                 }
1508                 break;
1509         default:
1510                 break;
1511         }
1512
1513         return NOTIFICATION_ERROR_NONE;
1514 }
1515
1516 EXPORT_API notification_error_e notification_get_execute_option(notification_h noti,
1517                                                                 notification_execute_type_e type,
1518                                                                 const char **text,
1519                                                                 bundle **service_handle)
1520 {
1521         char buf_key[32] = { 0, };
1522         const char *ret_val = NULL;
1523         char *get_str = NULL;
1524         bundle *b = NULL;
1525
1526         if (noti == NULL) {
1527                 return NOTIFICATION_ERROR_INVALID_DATA;
1528         }
1529
1530         if (type <= NOTIFICATION_EXECUTE_TYPE_NONE
1531             || type >= NOTIFICATION_EXECUTE_TYPE_MAX) {
1532                 return NOTIFICATION_ERROR_INVALID_DATA;
1533         }
1534
1535         switch (type) {
1536         case NOTIFICATION_EXECUTE_TYPE_RESPONDING:
1537                 b = noti->b_service_responding;
1538                 break;
1539         case NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH:
1540                 b = noti->b_service_single_launch;
1541                 break;
1542         case NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH:
1543                 b = noti->b_service_multi_launch;
1544                 break;
1545         default:
1546                 b = NULL;
1547                 break;
1548         }
1549
1550         if (b != NULL) {
1551                 // Return text
1552                 if (text != NULL) {
1553                         // Get text domain and dir
1554                         if (noti->domain == NULL || noti->dir == NULL) {
1555                                 _notification_get_text_domain(noti);
1556                         }
1557
1558                         /* Make key */
1559                         snprintf(buf_key, sizeof(buf_key), "key%d", type);
1560
1561                         /* Check key key exist */
1562                         ret_val = bundle_get_val(b, buf_key);
1563                         if (ret_val != NULL && noti->domain != NULL
1564                             && noti->dir != NULL) {
1565                                 /* Get application string */
1566                                 bindtextdomain(noti->domain, noti->dir);
1567
1568                                 get_str = dgettext(noti->domain, ret_val);
1569
1570                                 *text = get_str;
1571                         } else if (ret_val != NULL) {
1572                                 /* Get system string */
1573                                 get_str = dgettext("sys_string", ret_val);
1574
1575                                 *text = get_str;
1576                         } else {
1577                                 /* Get basic text */
1578                                 snprintf(buf_key, sizeof(buf_key), "text%d",
1579                                          type);
1580
1581                                 ret_val = bundle_get_val(b, buf_key);
1582
1583                                 *text = ret_val;
1584                         }
1585                 }
1586         }
1587
1588         switch (type) {
1589         case NOTIFICATION_EXECUTE_TYPE_RESPONDING:
1590                 b = noti->b_service_responding;
1591                 break;
1592         case NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH:
1593                 b = noti->b_service_single_launch;
1594                 break;
1595         case NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH:
1596                 b = noti->b_service_multi_launch;
1597                 break;
1598         default:
1599                 b = NULL;
1600                 break;
1601         }
1602
1603         if (service_handle != NULL) {
1604                 *service_handle = b;
1605         }
1606
1607         return NOTIFICATION_ERROR_NONE;
1608 }
1609
1610 EXPORT_API notification_error_e notification_set_property(notification_h noti,
1611                                                           int flags)
1612 {
1613         /* Check noti is valid data */
1614         if (noti == NULL) {
1615                 return NOTIFICATION_ERROR_INVALID_DATA;
1616         }
1617
1618         /* Set flags */
1619         noti->flags_for_property = flags;
1620
1621         return NOTIFICATION_ERROR_NONE;
1622 }
1623
1624 EXPORT_API notification_error_e notification_get_property(notification_h noti,
1625                                                           int *flags)
1626 {
1627         /* Check noti and flags are valid data */
1628         if (noti == NULL || flags == NULL) {
1629                 return NOTIFICATION_ERROR_INVALID_DATA;
1630         }
1631
1632         /* Set flags */
1633         *flags = noti->flags_for_property;
1634
1635         return NOTIFICATION_ERROR_NONE;
1636 }
1637
1638 EXPORT_API notification_error_e notification_set_display_applist(notification_h noti,
1639                                                                  int applist)
1640 {
1641         /* Check noti is valid data */
1642         if (noti == NULL) {
1643                 return NOTIFICATION_ERROR_INVALID_DATA;
1644         }
1645
1646         /* Set app list */
1647         noti->display_applist = applist;
1648
1649         return NOTIFICATION_ERROR_NONE;
1650 }
1651
1652 EXPORT_API notification_error_e notification_get_display_applist(notification_h noti,
1653                                                                  int *applist)
1654 {
1655         /* Check noti and applist are valid data */
1656         if (noti == NULL || applist == NULL) {
1657                 return NOTIFICATION_ERROR_INVALID_DATA;
1658         }
1659
1660         /* Set app list */
1661         *applist = noti->display_applist;
1662
1663         return NOTIFICATION_ERROR_NONE;
1664 }
1665
1666 EXPORT_API notification_error_e notification_set_size(notification_h noti,
1667                                                       double size)
1668 {
1669         /* Check noti is valid data */
1670         if (noti == NULL) {
1671                 return NOTIFICATION_ERROR_INVALID_DATA;
1672         }
1673
1674         /* Save progress size */
1675         noti->progress_size = size;
1676
1677         return NOTIFICATION_ERROR_NONE;
1678 }
1679
1680 EXPORT_API notification_error_e notification_get_size(notification_h noti,
1681                                                       double *size)
1682 {
1683         /* Check noti and size is valid data */
1684         if (noti == NULL || size == NULL) {
1685                 return NOTIFICATION_ERROR_INVALID_DATA;
1686         }
1687
1688         /* Set progress size */
1689         *size = noti->progress_size;
1690
1691         return NOTIFICATION_ERROR_NONE;
1692 }
1693
1694 EXPORT_API notification_error_e notification_set_progress(notification_h noti,
1695                                                           double percentage)
1696 {
1697         /* Check noti is valid data */
1698         if (noti == NULL) {
1699                 return NOTIFICATION_ERROR_INVALID_DATA;
1700         }
1701
1702         /* Save progress percentage */
1703         noti->progress_percentage = percentage;
1704
1705         return NOTIFICATION_ERROR_NONE;
1706 }
1707
1708 EXPORT_API notification_error_e notification_get_progress(notification_h noti,
1709                                                           double *percentage)
1710 {
1711         /* Check noti and percentage are valid data */
1712         if (noti == NULL || percentage == NULL) {
1713                 return NOTIFICATION_ERROR_INVALID_DATA;
1714         }
1715
1716         /* Set progress percentage */
1717         *percentage = noti->progress_percentage;
1718
1719         return NOTIFICATION_ERROR_NONE;
1720 }
1721
1722 EXPORT_API notification_error_e notification_set_pkgname(notification_h noti,
1723                                                          const char *pkgname)
1724 {
1725         /* check noti and pkgname are valid data */
1726         if (noti == NULL || pkgname == NULL) {
1727                 return NOTIFICATION_ERROR_INVALID_DATA;
1728         }
1729
1730         /* Remove previous caller pkgname */
1731         if (noti->caller_pkgname) {
1732                 free(noti->caller_pkgname);
1733                 noti->caller_pkgname = NULL;
1734         }
1735
1736         noti->caller_pkgname = strdup(pkgname);
1737
1738         return NOTIFICATION_ERROR_NONE;
1739 }
1740
1741 EXPORT_API notification_error_e notification_get_pkgname(notification_h noti,
1742                                                          char **pkgname)
1743 {
1744         /* Check noti and pkgname are valid data */
1745         if (noti == NULL || pkgname == NULL) {
1746                 return NOTIFICATION_ERROR_INVALID_DATA;
1747         }
1748
1749         /* Get caller pkgname */
1750         if (noti->caller_pkgname) {
1751                 *pkgname = noti->caller_pkgname;
1752         } else {
1753                 *pkgname = NULL;
1754         }
1755
1756         return NOTIFICATION_ERROR_NONE;
1757 }
1758
1759 EXPORT_API notification_error_e notification_set_badge(const char *pkgname,
1760                                                        int group_id, int count)
1761 {
1762         char *caller_pkgname = NULL;
1763         int ret = NOTIFICATION_ERROR_NONE;
1764
1765         /* Check count is valid count */
1766         if (count < 0) {
1767                 return NOTIFICATION_ERROR_INVALID_DATA;
1768         }
1769
1770         /* Check pkgname */
1771         if (pkgname == NULL) {
1772                 caller_pkgname = _notification_get_pkgname_by_pid();
1773
1774                 /* Set count into Group DB */
1775                 ret =
1776                     notification_group_set_badge(caller_pkgname, group_id,
1777                                                  count);
1778
1779                 if (caller_pkgname != NULL) {
1780                         free(caller_pkgname);
1781                 }
1782         } else {
1783                 /* Set count into Group DB */
1784                 ret = notification_group_set_badge(pkgname, group_id, count);
1785         }
1786
1787         return ret;
1788 }
1789
1790 EXPORT_API notification_error_e notification_get_badge(const char *pkgname,
1791                                                        int group_id, int *count)
1792 {
1793         char *caller_pkgname = NULL;
1794         int ret = NOTIFICATION_ERROR_NONE;
1795         int ret_unread_count = 0;
1796
1797         /* Check pkgname */
1798         if (pkgname == NULL) {
1799                 caller_pkgname = _notification_get_pkgname_by_pid();
1800
1801                 /* Get count from Group DB */
1802                 ret =
1803                     notification_group_get_badge(caller_pkgname, group_id,
1804                                                  &ret_unread_count);
1805
1806                 if (caller_pkgname != NULL) {
1807                         free(caller_pkgname);
1808                 }
1809         } else {
1810                 /* Get count from Group DB */
1811                 ret =
1812                     notification_group_get_badge(pkgname, group_id,
1813                                                  &ret_unread_count);
1814         }
1815
1816         if (ret != NOTIFICATION_ERROR_NONE) {
1817                 return ret;
1818         }
1819
1820         /* Set count */
1821         if (count != NULL) {
1822                 *count = ret_unread_count;
1823         }
1824
1825         return NOTIFICATION_ERROR_NONE;
1826 }
1827
1828 EXPORT_API notification_error_e notification_get_id(notification_h noti,
1829                                                     int *group_id, int *priv_id)
1830 {
1831         /* check noti is valid data */
1832         if (noti == NULL) {
1833                 return NOTIFICATION_ERROR_INVALID_DATA;
1834         }
1835
1836         /* Check group_id is valid data */
1837         if (group_id) {
1838                 /* Set group id */
1839                 if (noti->group_id < NOTIFICATION_GROUP_ID_NONE) {
1840                         *group_id = NOTIFICATION_GROUP_ID_NONE;
1841                 } else {
1842                         *group_id = noti->group_id;
1843                 }
1844         }
1845
1846         /* Check priv_id is valid data */
1847         if (priv_id) {
1848                 /* Set priv_id */
1849                 *priv_id = noti->priv_id;
1850         }
1851
1852         return NOTIFICATION_ERROR_NONE;
1853 }
1854
1855 EXPORT_API notification_error_e notification_get_type(notification_h noti,
1856                                                       notification_type_e *type)
1857 {
1858         /* Check noti and type is valid data */
1859         if (noti == NULL || type == NULL) {
1860                 return NOTIFICATION_ERROR_INVALID_DATA;
1861         }
1862
1863         /* Set noti type */
1864         *type = noti->type;
1865
1866         return NOTIFICATION_ERROR_NONE;
1867 }
1868
1869 EXPORT_API notification_error_e notification_insert(notification_h noti,
1870                                                     int *priv_id)
1871 {
1872         int ret = 0;
1873
1874         /* Check noti is vaild data */
1875         if (noti == NULL) {
1876                 return NOTIFICATION_ERROR_INVALID_DATA;
1877         }
1878
1879         /* Check noti type is valid type */
1880         if (noti->type <= NOTIFICATION_TYPE_NONE
1881             || noti->type >= NOTIFICATION_TYPE_MAX) {
1882                 return NOTIFICATION_ERROR_INVALID_DATA;
1883         }
1884
1885         /* Save insert time */
1886         noti->insert_time = time(NULL);
1887
1888         /* Insert into DB */
1889         ret = notification_noti_insert(noti);
1890         if (ret != NOTIFICATION_ERROR_NONE) {
1891                 return ret;
1892         }
1893
1894         /* Check disable update on insert property */
1895         if (noti->flags_for_property
1896                 & NOTIFICATION_PROP_DISABLE_UPDATE_ON_INSERT) {
1897                 /* Disable changed cb */
1898         } else {
1899                 /* Enable changed cb */
1900                 _notification_changed(NOTI_CHANGED_NOTI);
1901         }
1902
1903         /* If priv_id is valid data, set priv_id */
1904         if (priv_id != NULL) {
1905                 *priv_id = noti->priv_id;
1906         }
1907
1908         return NOTIFICATION_ERROR_NONE;
1909 }
1910
1911 EXPORT_API notification_error_e notification_update(notification_h noti)
1912 {
1913         int ret = 0;
1914
1915         /* Check noti is valid data */
1916         if (noti != NULL) {
1917                 /* Update insert time ? */
1918                 noti->insert_time = time(NULL);
1919
1920                 ret = notification_noti_update(noti);
1921                 if (ret != NOTIFICATION_ERROR_NONE) {
1922                         return ret;
1923                 }
1924         }
1925
1926         /* Send changed notification */
1927         _notification_changed(NOTI_CHANGED_NOTI);
1928
1929         return NOTIFICATION_ERROR_NONE;
1930 }
1931
1932 EXPORT_API notification_error_e notifiation_clear(notification_type_e type)
1933 {
1934         int ret = 0;
1935
1936         /* Delete all notification of type */
1937         ret = notification_noti_delete_all(type, NULL);
1938         if (ret != NOTIFICATION_ERROR_NONE) {
1939                 return ret;
1940         }
1941
1942         /* Send chagned notification */
1943         _notification_changed(NOTI_CHANGED_NOTI);
1944
1945         return NOTIFICATION_ERROR_NONE;
1946 }
1947
1948 EXPORT_API notification_error_e notification_delete_all_by_type(const char *pkgname,
1949                                                                 notification_type_e type)
1950 {
1951         int ret = 0;
1952         char *caller_pkgname = NULL;
1953
1954         if (pkgname == NULL) {
1955                 caller_pkgname = _notification_get_pkgname_by_pid();
1956         } else {
1957                 caller_pkgname = strdup(pkgname);
1958         }
1959
1960         ret = notification_noti_delete_all(type, caller_pkgname);
1961         if (ret != NOTIFICATION_ERROR_NONE) {
1962                 free(caller_pkgname);
1963                 return ret;
1964         }
1965
1966         _notification_changed(NOTI_CHANGED_NOTI);
1967
1968         free(caller_pkgname);
1969
1970         return ret;
1971 }
1972
1973 EXPORT_API notification_error_e notification_delete_group_by_group_id(const char *pkgname,
1974                                                                       notification_type_e type,
1975                                                                       int group_id)
1976 {
1977         int ret = 0;
1978         char *caller_pkgname = NULL;
1979
1980         if (group_id < NOTIFICATION_GROUP_ID_NONE) {
1981                 return NOTIFICATION_ERROR_INVALID_DATA;
1982         }
1983
1984         if (pkgname == NULL) {
1985                 caller_pkgname = _notification_get_pkgname_by_pid();
1986         } else {
1987                 caller_pkgname = strdup(pkgname);
1988         }
1989
1990         ret =
1991             notification_noti_delete_group_by_group_id(caller_pkgname,
1992                                                        group_id);
1993         if (ret != NOTIFICATION_ERROR_NONE) {
1994                 free(caller_pkgname);
1995                 return ret;
1996         }
1997
1998         _notification_changed(NOTI_CHANGED_NOTI);
1999
2000         free(caller_pkgname);
2001
2002         return ret;
2003 }
2004
2005 EXPORT_API notification_error_e notification_delete_group_by_priv_id(const char *pkgname,
2006                                                                      notification_type_e type,
2007                                                                      int priv_id)
2008 {
2009         int ret = 0;
2010         char *caller_pkgname = NULL;
2011
2012         if (priv_id < NOTIFICATION_PRIV_ID_NONE) {
2013                 return NOTIFICATION_ERROR_INVALID_DATA;
2014         }
2015
2016         if (pkgname == NULL) {
2017                 caller_pkgname = _notification_get_pkgname_by_pid();
2018         } else {
2019                 caller_pkgname = strdup(pkgname);
2020         }
2021
2022         ret =
2023             notification_noti_delete_group_by_priv_id(caller_pkgname, priv_id);
2024         if (ret != NOTIFICATION_ERROR_NONE) {
2025                 free(caller_pkgname);
2026                 return ret;
2027         }
2028
2029         _notification_changed(NOTI_CHANGED_NOTI);
2030
2031         free(caller_pkgname);
2032
2033         return ret;
2034 }
2035
2036 EXPORT_API notification_error_e notification_delete_by_priv_id(const char *pkgname,
2037                                                                notification_type_e type,
2038                                                                int priv_id)
2039 {
2040         int ret = 0;
2041         char *caller_pkgname = NULL;
2042
2043         if (priv_id <= NOTIFICATION_PRIV_ID_NONE) {
2044                 return NOTIFICATION_ERROR_INVALID_DATA;
2045         }
2046
2047         if (pkgname == NULL) {
2048                 caller_pkgname = _notification_get_pkgname_by_pid();
2049         } else {
2050                 caller_pkgname = strdup(pkgname);
2051         }
2052
2053         ret = notification_noti_delete_by_priv_id(caller_pkgname, priv_id);
2054         if (ret != NOTIFICATION_ERROR_NONE) {
2055                 free(caller_pkgname);
2056                 return ret;
2057         }
2058
2059         _notification_changed(NOTI_CHANGED_NOTI);
2060
2061         free(caller_pkgname);
2062
2063         return ret;
2064 }
2065
2066 EXPORT_API notification_error_e notification_delete(notification_h noti)
2067 {
2068         int ret = 0;
2069
2070         if (noti == NULL) {
2071                 return NOTIFICATION_ERROR_INVALID_DATA;
2072         }
2073
2074         ret =
2075             notification_noti_delete_by_priv_id(noti->caller_pkgname,
2076                                                 noti->priv_id);
2077         if (ret != NOTIFICATION_ERROR_NONE) {
2078                 return ret;
2079         }
2080
2081         if (noti->flags_for_property
2082                 & NOTIFICATION_PROP_DISABLE_UPDATE_ON_DELETE) {
2083                 NOTIFICATION_INFO("Disabled update while delete.");
2084         } else {
2085                 _notification_changed(NOTI_CHANGED_NOTI);
2086         }
2087
2088         return NOTIFICATION_ERROR_NONE;
2089 }
2090
2091 EXPORT_API notification_error_e notification_update_progress(notification_h noti,
2092                                                              int priv_id,
2093                                                              double progress)
2094 {
2095         char *caller_pkgname = NULL;
2096         int input_priv_id = 0;
2097         double input_progress = 0.0;
2098
2099         if (priv_id <= NOTIFICATION_PRIV_ID_NONE) {
2100                 if (noti == NULL) {
2101                         return NOTIFICATION_ERROR_INVALID_DATA;
2102                 } else {
2103                         input_priv_id = noti->priv_id;
2104                 }
2105         } else {
2106                 input_priv_id = priv_id;
2107         }
2108
2109         if (noti == NULL) {
2110                 caller_pkgname = _notification_get_pkgname_by_pid();
2111         } else {
2112                 caller_pkgname = strdup(noti->caller_pkgname);
2113         }
2114
2115         if (progress < 0.0) {
2116                 input_progress = 0.0;
2117         } else if (progress > 1.0) {
2118                 input_progress = 1.0;
2119         } else {
2120                 input_progress = progress;
2121         }
2122
2123         notification_ongoing_update_progress(caller_pkgname, input_priv_id,
2124                                              input_progress);
2125
2126         if (caller_pkgname) {
2127                 free(caller_pkgname);
2128         }
2129
2130         return NOTIFICATION_ERROR_NONE;
2131 }
2132
2133 EXPORT_API notification_error_e notification_update_size(notification_h noti,
2134                                                          int priv_id,
2135                                                          double size)
2136 {
2137         char *caller_pkgname = NULL;
2138         int input_priv_id = 0;
2139         double input_size = 0.0;
2140
2141         if (priv_id <= NOTIFICATION_PRIV_ID_NONE) {
2142                 if (noti == NULL) {
2143                         return NOTIFICATION_ERROR_INVALID_DATA;
2144                 } else {
2145                         input_priv_id = noti->priv_id;
2146                 }
2147         } else {
2148                 input_priv_id = priv_id;
2149         }
2150
2151         if (noti == NULL) {
2152                 caller_pkgname = _notification_get_pkgname_by_pid();
2153         } else {
2154                 caller_pkgname = strdup(noti->caller_pkgname);
2155         }
2156
2157         if (size < 0.0) {
2158                 input_size = 0.0;
2159         } else {
2160                 input_size = size;
2161         }
2162
2163         notification_ongoing_update_size(caller_pkgname, input_priv_id,
2164                                          input_size);
2165
2166         if (caller_pkgname) {
2167                 free(caller_pkgname);
2168         }
2169
2170         return NOTIFICATION_ERROR_NONE;
2171 }
2172
2173 EXPORT_API notification_error_e notification_update_content(notification_h noti,
2174                                                          int priv_id,
2175                                                          const char *content)
2176 {
2177         char *caller_pkgname = NULL;
2178         int input_priv_id = 0;
2179
2180         if (priv_id <= NOTIFICATION_PRIV_ID_NONE) {
2181                 if (noti == NULL) {
2182                         return NOTIFICATION_ERROR_INVALID_DATA;
2183                 } else {
2184                         input_priv_id = noti->priv_id;
2185                 }
2186         } else {
2187                 input_priv_id = priv_id;
2188         }
2189
2190         if (noti == NULL) {
2191                 caller_pkgname = _notification_get_pkgname_by_pid();
2192         } else {
2193                 caller_pkgname = strdup(noti->caller_pkgname);
2194         }
2195
2196         notification_ongoing_update_content(caller_pkgname, input_priv_id,
2197                                          content);
2198
2199         if (caller_pkgname) {
2200                 free(caller_pkgname);
2201         }
2202
2203         return NOTIFICATION_ERROR_NONE;
2204 }
2205
2206 EXPORT_API notification_h notification_new(notification_type_e type,
2207                                            int group_id, int priv_id)
2208 {
2209         notification_h noti = NULL;
2210
2211         if (type <= NOTIFICATION_TYPE_NONE || type >= NOTIFICATION_TYPE_MAX) {
2212                 NOTIFICATION_ERR("INVALID TYPE : %d", type);
2213                 return NULL;
2214         }
2215
2216         if (group_id < NOTIFICATION_GROUP_ID_NONE) {
2217                 NOTIFICATION_ERR("INVALID GROUP ID : %d", group_id);
2218                 return NULL;
2219         }
2220
2221         if (priv_id < NOTIFICATION_PRIV_ID_NONE) {
2222                 NOTIFICATION_ERR("INVALID PRIV ID : %d", priv_id);
2223                 return NULL;
2224         }
2225
2226         noti = (notification_h) malloc(sizeof(struct _notification));
2227         if (noti == NULL) {
2228                 NOTIFICATION_ERR("NO MEMORY : noti == NULL");
2229                 return NULL;
2230         }
2231         memset(noti, 0x00, sizeof(struct _notification));
2232
2233         noti->type = type;
2234
2235         noti->group_id = group_id;
2236         noti->internal_group_id = 0;
2237         noti->priv_id = priv_id;
2238
2239         noti->caller_pkgname = _notification_get_pkgname_by_pid();
2240         noti->launch_pkgname = NULL;
2241         noti->args = NULL;
2242         noti->group_args = NULL;
2243
2244         noti->b_execute_option = NULL;
2245         noti->b_service_responding = NULL;
2246         noti->b_service_single_launch = NULL;
2247         noti->b_service_multi_launch = NULL;
2248
2249         noti->sound_type = NOTIFICATION_SOUND_TYPE_NONE;
2250         noti->sound_path = NULL;
2251
2252         noti->vibration_type = NOTIFICATION_VIBRATION_TYPE_NONE;
2253         noti->vibration_path = NULL;
2254
2255         noti->domain = NULL;
2256         noti->dir = NULL;
2257
2258         noti->b_text = NULL;
2259         noti->b_key = NULL;
2260         noti->b_format_args = NULL;
2261         noti->num_format_args = 0;
2262
2263         noti->b_image_path = NULL;
2264
2265         noti->time = 0;
2266         noti->insert_time = 0;
2267
2268         noti->flags_for_property = 0;
2269         noti->display_applist = NOTIFICATION_DISPLAY_APP_ALL;
2270
2271         noti->progress_size = 0.0;
2272         noti->progress_percentage = 0.0;
2273
2274         noti->app_icon_path = NULL;
2275         noti->app_name = NULL;
2276         noti->temp_title = NULL;
2277         noti->temp_content = NULL;
2278
2279         return noti;
2280 }
2281
2282 EXPORT_API notification_error_e notification_clone(notification_h noti, notification_h *clone)
2283 {
2284         notification_h new_noti = NULL;
2285
2286         if (noti == NULL || clone == NULL) {
2287                 NOTIFICATION_ERR("INVALID PARAMETER.");
2288                 return NOTIFICATION_ERROR_INVALID_DATA;
2289         }
2290
2291         new_noti = (notification_h) malloc(sizeof(struct _notification));
2292         if (new_noti == NULL) {
2293                 NOTIFICATION_ERR("NO MEMORY : noti == NULL");
2294                 return NOTIFICATION_ERROR_NO_MEMORY;
2295         }
2296         memset(new_noti, 0x00, sizeof(struct _notification));
2297
2298         new_noti->type = noti->type;
2299
2300         new_noti->group_id = noti->group_id;
2301         new_noti->internal_group_id = noti->internal_group_id;
2302         new_noti->priv_id = noti->priv_id;
2303
2304         if(noti->caller_pkgname != NULL) {
2305                 new_noti->caller_pkgname = strdup(noti->caller_pkgname);
2306         } else {
2307                 new_noti->caller_pkgname = _notification_get_pkgname_by_pid();
2308         }
2309         if(noti->launch_pkgname != NULL) {
2310                 new_noti->launch_pkgname = strdup(noti->launch_pkgname);
2311         } else {
2312                 new_noti->launch_pkgname = NULL;
2313         }
2314
2315         if(noti->args != NULL) {
2316                 new_noti->args = bundle_dup(noti->args);
2317         } else {
2318                 new_noti->args = NULL;
2319         }
2320         if(noti->group_args != NULL) {
2321                 new_noti->group_args = bundle_dup(noti->group_args);
2322         } else {
2323                 new_noti->group_args = NULL;
2324         }
2325
2326         if(noti->b_execute_option != NULL) {
2327                 new_noti->b_execute_option = bundle_dup(noti->b_execute_option);
2328         } else {
2329                 new_noti->b_execute_option = NULL;
2330         }
2331         if(noti->b_service_responding != NULL) {
2332                 new_noti->b_service_responding = bundle_dup(noti->b_service_responding);
2333         } else {
2334                 new_noti->b_service_responding = NULL;
2335         }
2336         if(noti->b_service_single_launch != NULL) {
2337                 new_noti->b_service_single_launch = bundle_dup(noti->b_service_single_launch);
2338         } else {
2339                 new_noti->b_service_single_launch = NULL;
2340         }
2341         if(noti->b_service_multi_launch != NULL) {
2342                 new_noti->b_service_multi_launch = bundle_dup(noti->b_service_multi_launch);
2343         } else {
2344                 new_noti->b_service_multi_launch = NULL;
2345         }
2346
2347         new_noti->sound_type = noti->sound_type;
2348         if(noti->sound_path != NULL) {
2349                 new_noti->sound_path = strdup(noti->sound_path);
2350         } else {
2351                 new_noti->sound_path = NULL;
2352         }
2353         new_noti->vibration_type = noti->vibration_type;
2354         if(noti->vibration_path != NULL) {
2355                 new_noti->vibration_path = strdup(noti->vibration_path);
2356         } else {
2357                 new_noti->vibration_path = NULL;
2358         }
2359
2360         if(noti->domain != NULL) {
2361                 new_noti->domain = strdup(noti->domain);
2362         } else {
2363                 new_noti->domain = NULL;
2364         }
2365         if(noti->dir != NULL) {
2366                 new_noti->dir = strdup(noti->dir);
2367         } else {
2368                 new_noti->dir = NULL;
2369         }
2370
2371         if(noti->b_text != NULL) {
2372                 new_noti->b_text = bundle_dup(noti->b_text);
2373         } else {
2374                 new_noti->b_text = NULL;
2375         }
2376         if(noti->b_key != NULL) {
2377                 new_noti->b_key = bundle_dup(noti->b_key);
2378         } else {
2379                 new_noti->b_key = NULL;
2380         }
2381         if(noti->b_format_args != NULL) {
2382                 new_noti->b_format_args = bundle_dup(noti->b_format_args);
2383         } else {
2384                 new_noti->b_format_args = NULL;
2385         }
2386         new_noti->num_format_args = noti->num_format_args;
2387
2388         if(noti->b_image_path != NULL) {
2389                 new_noti->b_image_path = bundle_dup(noti->b_image_path);
2390         } else {
2391                 new_noti->b_image_path = NULL;
2392         }
2393
2394         new_noti->time = noti->time;
2395         new_noti->insert_time = noti->insert_time;
2396
2397         new_noti->flags_for_property = noti->flags_for_property;
2398         new_noti->display_applist = noti->display_applist;
2399
2400         new_noti->progress_size = noti->progress_size;
2401         new_noti->progress_percentage = noti->progress_percentage;
2402
2403         new_noti->app_icon_path = NULL;
2404         new_noti->app_name = NULL;
2405         new_noti->temp_title = NULL;
2406         new_noti->temp_content = NULL;
2407
2408         *clone = new_noti;
2409
2410         return NOTIFICATION_ERROR_NONE;
2411 }
2412
2413
2414 EXPORT_API notification_error_e notification_free(notification_h noti)
2415 {
2416         if (noti == NULL) {
2417                 return NOTIFICATION_ERROR_INVALID_DATA;
2418         }
2419
2420         if (noti->caller_pkgname) {
2421                 free(noti->caller_pkgname);
2422         }
2423         if (noti->launch_pkgname) {
2424                 free(noti->launch_pkgname);
2425         }
2426         if (noti->args) {
2427                 bundle_free(noti->args);
2428         }
2429         if (noti->group_args) {
2430                 bundle_free(noti->group_args);
2431         }
2432
2433         if (noti->b_execute_option) {
2434                 bundle_free(noti->b_execute_option);
2435         }
2436         if (noti->b_service_responding) {
2437                 bundle_free(noti->b_service_responding);
2438         }
2439         if (noti->b_service_single_launch) {
2440                 bundle_free(noti->b_service_single_launch);
2441         }
2442         if (noti->b_service_multi_launch) {
2443                 bundle_free(noti->b_service_multi_launch);
2444         }
2445
2446         if (noti->sound_path) {
2447                 free(noti->sound_path);
2448         }
2449         if (noti->vibration_path) {
2450                 free(noti->vibration_path);
2451         }
2452
2453         if (noti->domain) {
2454                 free(noti->domain);
2455         }
2456         if (noti->dir) {
2457                 free(noti->dir);
2458         }
2459
2460         if (noti->b_text) {
2461                 bundle_free(noti->b_text);
2462         }
2463         if (noti->b_key) {
2464                 bundle_free(noti->b_key);
2465         }
2466         if (noti->b_format_args) {
2467                 bundle_free(noti->b_format_args);
2468         }
2469
2470         if (noti->b_image_path) {
2471                 bundle_free(noti->b_image_path);
2472         }
2473
2474         if (noti->app_icon_path) {
2475                 free(noti->app_icon_path);
2476         }
2477         if (noti->app_name) {
2478                 free(noti->app_name);
2479         }
2480         if (noti->temp_title) {
2481                 free(noti->temp_title);
2482         }
2483         if (noti->temp_content) {
2484                 free(noti->temp_content);
2485         }
2486
2487         free(noti);
2488
2489         return NOTIFICATION_ERROR_NONE;
2490 }
2491
2492 EXPORT_API notification_error_e
2493 notification_resister_changed_cb(void (*changed_cb)
2494                                  (void *data, notification_type_e type),
2495                                  void *user_data)
2496 {
2497         notification_cb_list_s *noti_cb_list_new = NULL;
2498         notification_cb_list_s *noti_cb_list = NULL;
2499
2500         noti_cb_list_new =
2501             (notification_cb_list_s *) malloc(sizeof(notification_cb_list_s));
2502
2503         noti_cb_list_new->next = NULL;
2504         noti_cb_list_new->prev = NULL;
2505
2506         noti_cb_list_new->changed_cb = changed_cb;
2507         noti_cb_list_new->data = user_data;
2508
2509         if (g_notification_cb_list == NULL) {
2510                 g_notification_cb_list = noti_cb_list_new;
2511         } else {
2512                 noti_cb_list = g_notification_cb_list;
2513
2514                 while (noti_cb_list->next != NULL) {
2515                         noti_cb_list = noti_cb_list->next;
2516                 }
2517
2518                 noti_cb_list->next = noti_cb_list_new;
2519                 noti_cb_list_new->prev = noti_cb_list;
2520         }
2521
2522         if (g_notification_heynoti_fd < 0) {
2523                 g_notification_heynoti_fd = heynoti_init();
2524
2525                 heynoti_subscribe(g_notification_heynoti_fd, NOTI_CHANGED_NOTI,
2526                                   _notification_chagned_noti_cb, NULL);
2527
2528                 heynoti_attach_handler(g_notification_heynoti_fd);
2529         }
2530
2531         return NOTIFICATION_ERROR_NONE;
2532 }
2533
2534 EXPORT_API notification_error_e
2535 notification_unresister_changed_cb(void (*changed_cb)
2536                                    (void *data, notification_type_e type))
2537 {
2538         notification_cb_list_s *noti_cb_list = NULL;
2539         notification_cb_list_s *noti_cb_list_prev = NULL;
2540         notification_cb_list_s *noti_cb_list_next = NULL;
2541
2542         noti_cb_list = g_notification_cb_list;
2543
2544         if (noti_cb_list == NULL) {
2545                 return NOTIFICATION_ERROR_INVALID_DATA;
2546         }
2547
2548         while (noti_cb_list->prev != NULL) {
2549                 noti_cb_list = noti_cb_list->prev;
2550         }
2551
2552         do {
2553                 if (noti_cb_list->changed_cb == changed_cb) {
2554                         noti_cb_list_prev = noti_cb_list->prev;
2555                         noti_cb_list_next = noti_cb_list->next;
2556
2557                         if (noti_cb_list_prev == NULL) {
2558                                 g_notification_cb_list = noti_cb_list_next;
2559                         } else {
2560                                 noti_cb_list_prev->next = noti_cb_list_next;
2561                         }
2562
2563                         if (noti_cb_list_next == NULL) {
2564                                 if (noti_cb_list_prev != NULL) {
2565                                         noti_cb_list_prev->next = NULL;
2566                                 }
2567                         } else {
2568                                 noti_cb_list_next->prev = noti_cb_list_prev;
2569                         }
2570
2571                         free(noti_cb_list);
2572
2573                         if (g_notification_cb_list == NULL) {
2574                                 heynoti_detach_handler
2575                                     (g_notification_heynoti_fd);
2576                                 heynoti_close(g_notification_heynoti_fd);
2577                                 g_notification_heynoti_fd = -1;
2578                         }
2579
2580                         return NOTIFICATION_ERROR_NONE;
2581                 }
2582                 noti_cb_list = noti_cb_list->next;
2583         } while (noti_cb_list != NULL);
2584
2585         return NOTIFICATION_ERROR_INVALID_DATA;
2586 }
2587
2588 EXPORT_API notification_error_e
2589 notification_resister_badge_changed_cb(void (*changed_cb)
2590                                        (void *data, const char *pkgname,
2591                                         int group_id), void *user_data)
2592 {
2593         // Add DBus signal handler
2594         return NOTIFICATION_ERROR_NONE;
2595 }
2596
2597 EXPORT_API notification_error_e
2598 notification_unresister_badge_changed_cb(void (*changed_cb)
2599                                          (void *data, const char *pkgname,
2600                                           int group_id))
2601 {
2602         // Del DBus signal handler
2603         return NOTIFICATION_ERROR_NONE;
2604 }
2605
2606 EXPORT_API notification_error_e notification_get_count(notification_type_e type,
2607                                                        const char *pkgname,
2608                                                        int group_id,
2609                                                        int priv_id, int *count)
2610 {
2611         int ret = 0;
2612         int noti_count = 0;
2613
2614         ret =
2615             notification_noti_get_count(type, pkgname, group_id, priv_id,
2616                                         &noti_count);
2617         if (ret != NOTIFICATION_ERROR_NONE) {
2618                 return ret;
2619         }
2620
2621         if (count != NULL) {
2622                 *count = noti_count;
2623         }
2624
2625         return NOTIFICATION_ERROR_NONE;
2626 }
2627
2628 EXPORT_API notification_error_e notification_get_list(notification_type_e type,
2629                                                       int count,
2630                                                       notification_list_h *list)
2631 {
2632         notification_list_h get_list = NULL;
2633         int ret = 0;
2634
2635         ret = notification_noti_get_grouping_list(type, count, &get_list);
2636         if (ret != NOTIFICATION_ERROR_NONE) {
2637                 return ret;
2638         }
2639
2640         *list = get_list;
2641
2642         return NOTIFICATION_ERROR_NONE;
2643 }
2644
2645 EXPORT_API notification_error_e
2646 notification_get_grouping_list(notification_type_e type, int count,
2647                                notification_list_h * list)
2648 {
2649         notification_list_h get_list = NULL;
2650         int ret = 0;
2651
2652         ret = notification_noti_get_grouping_list(type, count, &get_list);
2653         if (ret != NOTIFICATION_ERROR_NONE) {
2654                 return ret;
2655         }
2656
2657         *list = get_list;
2658
2659         return NOTIFICATION_ERROR_NONE;
2660 }
2661
2662 EXPORT_API notification_error_e notification_get_detail_list(const char *pkgname,
2663                                                              int group_id,
2664                                                              int priv_id,
2665                                                              int count,
2666                                                              notification_list_h *list)
2667 {
2668         notification_list_h get_list = NULL;
2669         int ret = 0;
2670
2671         ret =
2672             notification_noti_get_detail_list(pkgname, group_id, priv_id, count,
2673                                               &get_list);
2674         if (ret != NOTIFICATION_ERROR_NONE) {
2675                 return ret;
2676         }
2677
2678         *list = get_list;
2679
2680         return NOTIFICATION_ERROR_NONE;
2681 }
2682
2683 EXPORT_API notification_error_e notification_free_list(notification_list_h list)
2684 {
2685         notification_list_h cur_list = NULL;
2686         notification_h noti = NULL;
2687
2688         if (list == NULL) {
2689                 NOTIFICATION_ERR("INVALID DATA : list == NULL");
2690                 return NOTIFICATION_ERROR_INVALID_DATA;
2691         }
2692
2693         cur_list = notification_list_get_head(list);
2694
2695         while (cur_list != NULL) {
2696                 noti = notification_list_get_data(cur_list);
2697                 cur_list = notification_list_remove(cur_list, noti);
2698
2699                 notification_free(noti);
2700         }
2701
2702         return NOTIFICATION_ERROR_NONE;
2703 }