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