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