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