18b19f0beaad4fa64324d3add1995093e45a09ee
[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_internal.h>
33 #include <app_manager.h>
34 #include <app_control_internal.h>
35 #include <package_manager.h>
36 #include <aul.h>
37 #include <ail.h>
38 #include <appsvc.h>
39 #include <tizen.h>
40 #include <vconf-keys.h>
41 #include <vconf.h>
42
43 #include <notification.h>
44 #include <notification_list.h>
45 #include <notification_debug.h>
46 #include <notification_private.h>
47 #include <notification_noti.h>
48 #include <notification_ongoing.h>
49 #include <notification_group.h>
50 #include <notification_ipc.h>
51 #include <notification_internal.h>
52
53 static void (*posted_toast_message_cb) (void *data);
54
55 #define NOTI_TEXT_RESULT_LEN 2048
56 #define NOTI_PKGNAME_LEN        512
57
58 char *notification_get_pkgname_by_pid(void)
59 {
60         char pkgname[NOTI_PKGNAME_LEN + 1] = { 0, };
61         int pid = 0, ret = AUL_R_OK;
62         int fd;
63         char  *dup_pkgname;
64
65         pid = getpid();
66
67         ret = aul_app_get_pkgname_bypid(pid, pkgname, sizeof(pkgname));
68         if (ret != AUL_R_OK) {
69                 char buf[NOTI_PKGNAME_LEN + 1] = { 0, };
70
71                 snprintf(buf, sizeof(buf), "/proc/%d/cmdline", pid);
72
73                 fd = open(buf, O_RDONLY);
74                 if (fd < 0) {
75                         return NULL;
76                 }
77
78                 ret = read(fd, pkgname, sizeof(pkgname) - 1);
79                 close(fd);
80
81                 if (ret <= 0) {
82                         return NULL;
83                 }
84
85                 pkgname[ret] = '\0';
86                 /*!
87                  * \NOTE
88                  * "ret" is not able to be larger than "sizeof(pkgname) - 1",
89                  * if the system is not going wrong.
90                  */
91         } else {
92                 if (strlen(pkgname) <= 0) {
93                         return NULL;
94                 }
95         }
96
97         dup_pkgname = strdup(pkgname);
98         if (!dup_pkgname)
99                 NOTIFICATION_ERR("Heap: %d\n", errno);
100
101         return dup_pkgname;
102 }
103
104 EXPORT_API int notification_set_image(notification_h noti,
105                                                        notification_image_type_e type,
106                                                        const char *image_path)
107 {
108         bundle *b = NULL;
109         char buf_key[32] = { 0, };
110         char *ret_val = NULL;
111
112         /* Check noti and image_path are valid data */
113         if (noti == NULL || image_path == NULL) {
114                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
115         }
116
117         /* Check image type is valid type */
118         if (type <= NOTIFICATION_IMAGE_TYPE_NONE
119             || type >= NOTIFICATION_IMAGE_TYPE_MAX) {
120                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
121         }
122
123         /* Check image path bundle is exist */
124         if (noti->b_image_path) {
125                 /* If image path bundle is exist, store local bundle value */
126                 b = noti->b_image_path;
127
128                 /* Set image type to key as char string type */
129                 snprintf(buf_key, sizeof(buf_key), "%d", type);
130
131                 /* Get value using key */
132                 bundle_get_str(b, buf_key, &ret_val);
133                 if (ret_val != NULL) {
134                         /* If key is exist, remove this value to store new image path */
135                         bundle_del(b, buf_key);
136                 }
137
138                 /* Add new image path with type key */
139                 bundle_add_str(b, buf_key, image_path);
140         } else {
141                 /* If image path bundle is not exist, create new one */
142                 b = bundle_create();
143
144                 /* Set image type to key as char string type */
145                 snprintf(buf_key, sizeof(buf_key), "%d", type);
146
147                 /* Add new image path with type key */
148                 bundle_add_str(b, buf_key, image_path);
149
150                 /* Save to image path bundle */
151                 noti->b_image_path = b;
152         }
153
154         return NOTIFICATION_ERROR_NONE;
155 }
156
157 EXPORT_API int notification_get_image(notification_h noti,
158                                                        notification_image_type_e type,
159                                                        char **image_path)
160 {
161         bundle *b = NULL;
162         char buf_key[32] = { 0, };
163         char *ret_val = NULL;
164
165         /* Check noti and image_path is valid data */
166         if (noti == NULL || image_path == NULL) {
167                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
168         }
169
170         /* Check image type is valid data */
171         if (type <= NOTIFICATION_IMAGE_TYPE_NONE
172             || type >= NOTIFICATION_IMAGE_TYPE_MAX) {
173                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
174         }
175
176         /* Check image path bundle exist */
177         if (noti->b_image_path) {
178                 /* If image path bundle exist, store local bundle data */
179                 b = noti->b_image_path;
180
181                 /* Set image type to key as char string type */
182                 snprintf(buf_key, sizeof(buf_key), "%d", type);
183
184                 /* Get value of key */
185                 bundle_get_str(b, buf_key, &ret_val);
186
187                 *image_path = ret_val;
188         } else {
189                 /* If image path bundle does not exist, image path is NULL */
190                 *image_path = NULL;
191         }
192
193         /* If image path is NULL and type is ICON, icon path set from AIL */
194         /* order : user icon -> launch_pkgname icon -> caller_pkgname icon -> service app icon */
195         if (*image_path == NULL && type == NOTIFICATION_IMAGE_TYPE_ICON) {
196                 /* Check App icon path is already set */
197                 if (noti->app_icon_path != NULL) {
198                         /* image path will be app icon path */
199                         *image_path = noti->app_icon_path;
200                 } else {
201                         *image_path = NULL;
202                 }
203         }
204
205         return NOTIFICATION_ERROR_NONE;
206 }
207
208 EXPORT_API int notification_set_time(notification_h noti,
209                                                       time_t input_time)
210 {
211         /* Check noti is valid data */
212         if (noti == NULL) {
213                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
214         }
215
216         if (input_time == 0) {
217                 /* If input time is 0, set current time */
218                 noti->time = time(NULL);
219         } else {
220                 /* save input time */
221                 noti->time = input_time;
222         }
223
224         return NOTIFICATION_ERROR_NONE;
225 }
226
227 EXPORT_API int notification_get_time(notification_h noti,
228                                                       time_t * ret_time)
229 {
230         /* Check noti and time is valid data */
231         if (noti == NULL || ret_time == NULL) {
232                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
233         }
234
235         /* Set time infomation */
236         *ret_time = noti->time;
237
238         return NOTIFICATION_ERROR_NONE;
239 }
240
241 EXPORT_API int notification_get_insert_time(notification_h noti,
242                                                              time_t * ret_time)
243 {
244         /* Check noti and ret_time is valid data */
245         if (noti == NULL || ret_time == NULL) {
246                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
247         }
248
249         /* Set insert time information */
250         *ret_time = noti->insert_time;
251
252         return NOTIFICATION_ERROR_NONE;
253 }
254
255 EXPORT_API int notification_set_text(notification_h noti,
256                                                       notification_text_type_e type,
257                                                       const char *text,
258                                                       const char *key,
259                                                       int args_type, ...)
260 {
261         bundle *b = NULL;
262         char buf_key[32] = { 0, };
263         char buf_val[1024] = { 0, };
264         char *ret_val = NULL;
265         va_list var_args;
266         notification_variable_type_e var_type;
267         int num_args = 0;
268         int noti_err = NOTIFICATION_ERROR_NONE;
269         int var_value_int = 0;
270         double var_value_double = 0.0;
271         char *var_value_string = NULL;
272         notification_count_pos_type_e var_value_count =
273             NOTIFICATION_COUNT_POS_NONE;
274
275         /* Check noti is valid data */
276         if (noti == NULL) {
277                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
278         }
279
280         /* Check text type is valid type */
281         if (type <= NOTIFICATION_TEXT_TYPE_NONE
282             || type >= NOTIFICATION_TEXT_TYPE_MAX) {
283                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
284         }
285
286         /* Check text bundle exist */
287         if (text != NULL) {
288                 if (noti->b_text != NULL) {
289                         /* If text bundle exist, store local bundle data */
290                         b = noti->b_text;
291
292                         /* Make type to key as char string */
293                         snprintf(buf_key, sizeof(buf_key), "%d", type);
294
295                         /* Get value using type key */
296                         bundle_get_str(b, buf_key, &ret_val);
297                         if (ret_val != NULL) {
298                                 /* If value exist, remove this to add new value */
299                                 bundle_del(b, buf_key);
300                         }
301
302                         snprintf(buf_val, sizeof(buf_val), "%s", text);
303
304                         /* Add new text value */
305                         bundle_add_str(b, buf_key, buf_val);
306                 } else {
307                         /* If text bundle does not exist, create new one */
308                         b = bundle_create();
309
310                         /* Make type to key as char string */
311                         snprintf(buf_key, sizeof(buf_key), "%d", type);
312
313                         snprintf(buf_val, sizeof(buf_val), "%s", text);
314
315                         /* Add new text value */
316                         bundle_add_str(b, buf_key, buf_val);
317
318                         /* Save text bundle */
319                         noti->b_text = b;
320                 }
321         } else {
322                 /* Reset if text is NULL */
323                 if (noti->b_text != NULL) {
324                         /* If text bundle exist, store local bundle data */
325                         b = noti->b_text;
326
327                         /* Make type to key as char string */
328                         snprintf(buf_key, sizeof(buf_key), "%d", type);
329
330                         /* Get value using type key */
331                         bundle_get_str(b, buf_key, &ret_val);
332                         if (ret_val != NULL) {
333                                 /* If value exist, remove this */
334                                 bundle_del(b, buf_key);
335                         }
336                 }
337         }
338
339         /* Save key if key is valid data */
340         if (key != NULL) {
341                 /* Check key bundle exist */
342                 if (noti->b_key != NULL) {
343                         /* If key bundle exist,  store local bundle data */
344                         b = noti->b_key;
345
346                         /* Make type to key as char string */
347                         snprintf(buf_key, sizeof(buf_key), "%d", type);
348
349                         /* Get value using type key */
350                         bundle_get_str(b, buf_key, &ret_val);
351                         if (ret_val != NULL) {
352                                 /* If value exist, remove this to add new value */
353                                 bundle_del(b, buf_key);
354                         }
355
356                         snprintf(buf_val, sizeof(buf_val), "%s", key);
357
358                         /* Add new key value */
359                         bundle_add_str(b, buf_key, buf_val);
360                 } else {
361                         /* If key bundle does not exist, create new one */
362                         b = bundle_create();
363
364                         /* Make type to key as char string */
365                         snprintf(buf_key, sizeof(buf_key), "%d", type);
366
367                         snprintf(buf_val, sizeof(buf_val), "%s", key);
368
369                         /* Add new key value */
370                         bundle_add_str(b, buf_key, buf_val);
371
372                         /* Save key bundle */
373                         noti->b_key = b;
374                 }
375         } else {
376                 /* Reset if key is NULL */
377                 if (noti->b_key != NULL) {
378                         /* If key bundle exist,  store local bundle data */
379                         b = noti->b_key;
380
381                         /* Make type to key as char string */
382                         snprintf(buf_key, sizeof(buf_key), "%d", type);
383
384                         /* Get value using type key */
385                         bundle_get_str(b, buf_key, &ret_val);
386                         if (ret_val != NULL) {
387                                 /* If value exist, remove this */
388                                 bundle_del(b, buf_key);
389                         }
390                 }
391         }
392
393         if (noti->b_format_args != NULL) {
394                 b = noti->b_format_args;
395         } else {
396                 b = bundle_create();
397         }
398
399         va_start(var_args, args_type);
400
401         var_type = args_type;
402         num_args = 0;
403
404         while (var_type != NOTIFICATION_VARIABLE_TYPE_NONE) {
405                 /* Type */
406                 snprintf(buf_key, sizeof(buf_key), "%dtype%d", type, num_args);
407                 snprintf(buf_val, sizeof(buf_val), "%d", var_type);
408
409                 bundle_get_str(b, buf_key, &ret_val);
410                 if (ret_val != NULL) {
411                         bundle_del(b, buf_key);
412                 }
413
414                 bundle_add_str(b, buf_key, buf_val);
415
416                 switch (var_type) {
417                 case NOTIFICATION_VARIABLE_TYPE_INT:
418                         var_value_int = va_arg(var_args, int);
419
420                         /* Value */
421                         snprintf(buf_key, sizeof(buf_key), "%dvalue%d", type,
422                                  num_args);
423                         snprintf(buf_val, sizeof(buf_val), "%d", var_value_int);
424
425                         bundle_get_str(b, buf_key, &ret_val);
426                         if (ret_val != NULL) {
427                                 bundle_del(b, buf_key);
428                         }
429
430                         bundle_add_str(b, buf_key, buf_val);
431                         break;
432                 case NOTIFICATION_VARIABLE_TYPE_DOUBLE:
433                         var_value_double = va_arg(var_args, double);
434
435                         /* Value */
436                         snprintf(buf_key, sizeof(buf_key), "%dvalue%d", type,
437                                  num_args);
438                         snprintf(buf_val, sizeof(buf_val), "%.2f",
439                                  var_value_double);
440
441                         bundle_get_str(b, buf_key, &ret_val);
442                         if (ret_val != NULL) {
443                                 bundle_del(b, buf_key);
444                         }
445
446                         bundle_add_str(b, buf_key, buf_val);
447                         break;
448                 case NOTIFICATION_VARIABLE_TYPE_STRING:
449                         var_value_string = va_arg(var_args, char *);
450
451                         /* Value */
452                         snprintf(buf_key, sizeof(buf_key), "%dvalue%d", type,
453                                  num_args);
454                         snprintf(buf_val, sizeof(buf_val), "%s",
455                                  var_value_string);
456
457                         bundle_get_str(b, buf_key, &ret_val);
458                         if (ret_val != NULL) {
459                                 bundle_del(b, buf_key);
460                         }
461
462                         bundle_add_str(b, buf_key, buf_val);
463                         break;
464                 case NOTIFICATION_VARIABLE_TYPE_COUNT:
465                         var_value_count =
466                             va_arg(var_args, notification_count_pos_type_e);
467
468                         /* Value */
469                         snprintf(buf_key, sizeof(buf_key), "%dvalue%d", type,
470                                  num_args);
471                         snprintf(buf_val, sizeof(buf_val), "%d",
472                                  var_value_count);
473
474                         bundle_get_str(b, buf_key, &ret_val);
475                         if (ret_val != NULL) {
476                                 bundle_del(b, buf_key);
477                         }
478
479                         bundle_add_str(b, buf_key, buf_val);
480                         break;
481                 default:
482                         NOTIFICATION_ERR("Error. invalid variable type. : %d",
483                                          var_type);
484                         noti_err = NOTIFICATION_ERROR_INVALID_PARAMETER;
485                         break;
486                 }
487
488                 num_args++;
489                 var_type = va_arg(var_args, notification_variable_type_e);
490         }
491         va_end(var_args);
492
493         if (noti_err == NOTIFICATION_ERROR_NONE) {
494                 noti->num_format_args = num_args;
495         } else {
496                 noti->num_format_args = 0;
497         }
498
499         snprintf(buf_key, sizeof(buf_key), "num%d", type);
500         snprintf(buf_val, sizeof(buf_val), "%d", noti->num_format_args);
501
502         bundle_get_str(b, buf_key, &ret_val);
503         if (ret_val != NULL) {
504                 bundle_del(b, buf_key);
505         }
506
507         bundle_add_str(b, buf_key, buf_val);
508
509         noti->b_format_args = b;
510
511         return noti_err;
512 }
513
514 EXPORT_API int notification_get_text(notification_h noti,
515                                                       notification_text_type_e type,
516                                                       char **text)
517 {
518         bundle *b = NULL;
519         char buf_key[32] = { 0, };
520         char *ret_val = NULL;
521         char *get_str = NULL;
522         notification_text_type_e check_type = NOTIFICATION_TEXT_TYPE_NONE;
523         //int display_option_flag = 0;
524
525         char *temp_str = NULL;
526         char *translated_str = NULL;
527         char result_str[NOTI_TEXT_RESULT_LEN] = { 0, };
528         char buf_str[1024] = { 0, };
529         int num_args = 0;
530         notification_variable_type_e ret_var_type = 0;
531         int ret_variable_int = 0;
532         double ret_variable_double = 0.0;
533
534         /* Check noti is valid data */
535         if (noti == NULL || text == NULL) {
536                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
537         }
538
539         /* Check text type is valid type */
540         if (type <= NOTIFICATION_TEXT_TYPE_NONE
541             || type >= NOTIFICATION_TEXT_TYPE_MAX) {
542                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
543         }
544
545         /* Check key */
546         if (noti->b_key != NULL) {
547                 b = noti->b_key;
548
549                 /* Get text domain and dir */
550                 //_notification_get_text_domain(noti);
551
552                 snprintf(buf_key, sizeof(buf_key), "%d", type);
553
554                 bundle_get_str(b, buf_key, &ret_val);
555                 if (ret_val != NULL && noti->domain != NULL
556                     && noti->dir != NULL) {
557                         /* Get application string */
558                         bindtextdomain(noti->domain, noti->dir);
559
560                         get_str = dgettext(noti->domain, ret_val);
561                 } else if (ret_val != NULL) {
562                         /* Get system string */
563                         get_str = dgettext("sys_string", ret_val);
564                 } else {
565                         get_str = NULL;
566                 }
567         }
568
569         if (get_str == NULL && noti->b_text != NULL) {
570                 b = noti->b_text;
571                 /* Get basic text */
572                 snprintf(buf_key, sizeof(buf_key), "%d", type);
573
574                 bundle_get_str(b, buf_key, &get_str);
575         }
576
577         check_type = type;
578
579         if (get_str != NULL) {
580                 /* Get number format args */
581                 b = noti->b_format_args;
582                 noti->num_format_args = 0;
583
584                 if (b != NULL) {
585                         snprintf(buf_key, sizeof(buf_key), "num%d", check_type);
586                         bundle_get_str(b, buf_key, &ret_val);
587                         if (ret_val != NULL) {
588                                 noti->num_format_args = atoi(ret_val);
589                         }
590                 }
591
592                 if (noti->num_format_args == 0) {
593                         *text = (char *)get_str;
594                 } else {
595                         /* Check first variable is count, LEFT pos */
596                         snprintf(buf_key, sizeof(buf_key), "%dtype%d",
597                                  check_type, num_args);
598                         bundle_get_str(b, buf_key, &ret_val);
599                         if (ret_val != NULL) {
600                                 ret_var_type = atoi(ret_val);
601                         }
602
603                         if (ret_var_type == NOTIFICATION_VARIABLE_TYPE_COUNT) {
604                                 /* Get var Value */
605                                 snprintf(buf_key, sizeof(buf_key), "%dvalue%d",
606                                          check_type, num_args);
607                                 bundle_get_str(b, buf_key, &ret_val);
608                                 if (ret_val != NULL) {
609                                         ret_variable_int = atoi(ret_val);
610                                 }
611
612                                 if (ret_variable_int ==
613                                     NOTIFICATION_COUNT_POS_LEFT) {
614                                         notification_noti_get_count(noti->type,
615                                                                     noti->caller_pkgname,
616                                                                     noti->group_id,
617                                                                     noti->priv_id,
618                                                                     &ret_variable_int);
619                                         snprintf(buf_str, sizeof(buf_str),
620                                                  "%d ", ret_variable_int);
621
622                                         int src_len = strlen(result_str);
623                                         int max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
624
625                                         strncat(result_str, buf_str,
626                                                         max_len);
627                                         num_args++;
628                                 }
629                         }
630
631                         /* Check variable IN pos */
632                         for (temp_str = (char *)get_str; *temp_str != '\0';
633                              temp_str++) {
634                                 if (*temp_str != '%') {
635                                         strncat(result_str, temp_str, 1);
636                                 } else {
637                                         if (*(temp_str + 1) == '%') {
638                                                 strncat(result_str, temp_str,
639                                                         1);
640                                         } else if (*(temp_str + 1) == 'd') {
641                                                 /* Get var Type */
642                                                 ret_variable_int = 0;
643
644                                                 snprintf(buf_key,
645                                                          sizeof(buf_key),
646                                                          "%dtype%d", check_type,
647                                                          num_args);
648                                                 bundle_get_str(b, buf_key, &ret_val);
649                                                 if (ret_val != NULL) {
650                                                         ret_var_type = atoi(ret_val);
651                                                 }
652                                                 if (ret_var_type ==
653                                                     NOTIFICATION_VARIABLE_TYPE_COUNT)
654                                                 {
655                                                         /* Get notification count */
656                                                         notification_noti_get_count
657                                                             (noti->type,
658                                                              noti->caller_pkgname,
659                                                              noti->group_id,
660                                                              noti->priv_id,
661                                                              &ret_variable_int);
662                                                 } else {
663                                                         /* Get var Value */
664                                                         snprintf(buf_key,
665                                                                  sizeof(buf_key),
666                                                                  "%dvalue%d",
667                                                                  check_type,
668                                                                  num_args);
669                                                         bundle_get_str(b, buf_key, &ret_val);
670                                                         if (ret_val != NULL) {
671                                                                 ret_variable_int = atoi(ret_val);
672                                                         }
673                                                 }
674
675                                                 snprintf(buf_str,
676                                                          sizeof(buf_str), "%d",
677                                                          ret_variable_int);
678
679                                                 int src_len = strlen(result_str);
680                                                 int max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
681
682                                                 strncat(result_str, buf_str,
683                                                                 max_len);
684
685                                                 temp_str++;
686
687                                                 num_args++;
688                                         } else if (*(temp_str + 1) == 's') {
689                                                 /* Get var Value */
690                                                 snprintf(buf_key,
691                                                          sizeof(buf_key),
692                                                          "%dvalue%d",
693                                                          check_type, num_args);
694                                                 bundle_get_str(b, buf_key, &ret_val);
695
696                                                 if (ret_val != NULL && noti->domain != NULL     && noti->dir != NULL) {
697                                                         /* Get application string */
698                                                         bindtextdomain(noti->domain, noti->dir);
699                                                         translated_str = dgettext(noti->domain, ret_val);
700                                                         NOTIFICATION_INFO("translated_str[%s]", translated_str);
701                                                 } else if (ret_val != NULL) {
702                                                         /* Get system string */
703                                                         translated_str = dgettext("sys_string", ret_val);
704                                                         NOTIFICATION_INFO("translated_str[%s]", translated_str);
705                                                 } else {
706                                                         translated_str = NULL;
707                                                 }
708
709                                                 strncpy(buf_str, translated_str, sizeof(buf_str) - 1);
710
711                                                 int src_len = strlen(result_str);
712                                                 int max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
713
714                                                 strncat(result_str, buf_str,
715                                                                 max_len);
716
717                                                 temp_str++;
718
719                                                 num_args++;
720                                         } else if (*(temp_str + 1) == 'f') {
721                                                 /* Get var Value */
722                                                 snprintf(buf_key,
723                                                          sizeof(buf_key),
724                                                          "%dvalue%d",
725                                                          check_type, num_args);
726                                                 bundle_get_str(b, buf_key, &ret_val);
727                                                 if (ret_val != NULL) {
728                                                         ret_variable_double = atof(ret_val);
729                                                 }
730
731                                                 snprintf(buf_str,
732                                                          sizeof(buf_str),
733                                                          "%.2f",
734                                                          ret_variable_double);
735
736                                                 int src_len = strlen(result_str);
737                                                 int max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
738
739                                                 strncat(result_str, buf_str,
740                                                                 max_len);
741
742                                                 temp_str++;
743
744                                                 num_args++;
745                                         } else if (*(temp_str + 1) >= '1' && *(temp_str + 1) <= '9') {
746                                                 if (*(temp_str + 3) == 'd') {
747                                                         /* Get var Type */
748                                                         ret_variable_int = 0;
749
750                                                         snprintf(buf_key,
751                                                                  sizeof(buf_key),
752                                                                  "%dtype%d", check_type,
753                                                                  num_args + *(temp_str + 1) - 49);
754                                                         bundle_get_str(b, buf_key, &ret_val);
755                                                         if (ret_val != NULL) {
756                                                                 ret_var_type = atoi(ret_val);
757                                                         }
758                                                         if (ret_var_type ==
759                                                             NOTIFICATION_VARIABLE_TYPE_COUNT)
760                                                         {
761                                                                 /* Get notification count */
762                                                                 notification_noti_get_count
763                                                                     (noti->type,
764                                                                      noti->caller_pkgname,
765                                                                      noti->group_id,
766                                                                      noti->priv_id,
767                                                                      &ret_variable_int);
768                                                         } else {
769                                                                 /* Get var Value */
770                                                                 snprintf(buf_key,
771                                                                          sizeof
772                                                                          (buf_key),
773                                                                          "%dvalue%d",
774                                                                          check_type,
775                                                                          num_args + *(temp_str + 1) - 49);
776                                                                 bundle_get_str(b, buf_key, &ret_val);
777                                                                 if (ret_val != NULL) {
778                                                                         ret_variable_int = atoi(ret_val);
779                                                                 }
780                                                         }
781
782                                                         snprintf(buf_str,
783                                                                  sizeof(buf_str), "%d",
784                                                                  ret_variable_int);
785
786                                                         int src_len = strlen(result_str);
787                                                         int max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
788
789                                                         strncat(result_str, buf_str,
790                                                                         max_len);
791
792                                                         temp_str += 3;
793                                                 } else if (*(temp_str + 3) == 's') {
794                                                         /* Get var Value */
795                                                         snprintf(buf_key,
796                                                                  sizeof(buf_key),
797                                                                  "%dvalue%d",
798                                                                  check_type, num_args + *(temp_str + 1) - 49);
799                                                         bundle_get_str(b, buf_key, &ret_val);
800
801                                                         snprintf(buf_str,
802                                                                  sizeof(buf_str), "%s",
803                                                                  ret_val);
804
805                                                         int src_len = strlen(result_str);
806                                                         int max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
807
808                                                         strncat(result_str, buf_str,
809                                                                         max_len);
810
811                                                         temp_str += 3;
812                                                 } else if (*(temp_str + 3) == 'f') {
813                                                         /* Get var Value */
814                                                         snprintf(buf_key,
815                                                                  sizeof(buf_key),
816                                                                  "%dvalue%d",
817                                                                  check_type, num_args + *(temp_str + 1) - 49);
818                                                         bundle_get_str(b, buf_key, &ret_val);
819                                                         if (ret_val != NULL) {
820                                                                 ret_variable_double = atof(ret_val);
821                                                         }
822
823                                                         snprintf(buf_str,
824                                                                  sizeof(buf_str),
825                                                                  "%.2f",
826                                                                  ret_variable_double);
827
828                                                         int src_len = strlen(result_str);
829                                                         int max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
830
831                                                         strncat(result_str, buf_str,
832                                                                         max_len);
833
834                                                         temp_str += 3;
835                                                 }
836                                         }
837                                 }
838
839                         }
840
841                         /* Check last variable is count, LEFT pos */
842                         if (num_args < noti->num_format_args) {
843                                 snprintf(buf_key, sizeof(buf_key), "%dtype%d",
844                                          check_type, num_args);
845                                 bundle_get_str(b, buf_key, &ret_val);
846                                 if (ret_val != NULL) {
847                                         ret_var_type = atoi(ret_val);
848                                 }
849
850                                 if (ret_var_type ==
851                                     NOTIFICATION_VARIABLE_TYPE_COUNT) {
852                                         /* Get var Value */
853                                         snprintf(buf_key, sizeof(buf_key),
854                                                  "%dvalue%d", check_type,
855                                                  num_args);
856                                         bundle_get_str(b, buf_key, &ret_val);
857                                         if (ret_val != NULL) {
858                                                 ret_variable_int = atoi(ret_val);
859                                         }
860
861                                         if (ret_variable_int ==
862                                             NOTIFICATION_COUNT_POS_RIGHT) {
863                                                 notification_noti_get_count
864                                                     (noti->type,
865                                                      noti->caller_pkgname,
866                                                      noti->group_id,
867                                                      noti->priv_id,
868                                                      &ret_variable_int);
869                                                 snprintf(buf_str,
870                                                          sizeof(buf_str), " %d",
871                                                          ret_variable_int);
872
873                                                 int src_len = strlen(result_str);
874                                                 int max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
875
876                                                 strncat(result_str, buf_str,
877                                                                 max_len);
878
879                                                 num_args++;
880                                         }
881
882                                 }
883                         }
884
885                         switch (check_type) {
886                         case NOTIFICATION_TEXT_TYPE_TITLE:
887                         case NOTIFICATION_TEXT_TYPE_GROUP_TITLE:
888                                 if (noti->temp_title != NULL)
889                                         free(noti->temp_title);
890
891                                 noti->temp_title = strdup(result_str);
892
893                                 *text = noti->temp_title;
894                                 break;
895                         case NOTIFICATION_TEXT_TYPE_CONTENT:
896                         case NOTIFICATION_TEXT_TYPE_CONTENT_FOR_DISPLAY_OPTION_IS_OFF:
897                         case NOTIFICATION_TEXT_TYPE_GROUP_CONTENT:
898                         case NOTIFICATION_TEXT_TYPE_GROUP_CONTENT_FOR_DISPLAY_OPTION_IS_OFF:
899                                 if (noti->temp_content !=
900                                     NULL)
901                                         free(noti->temp_content);
902
903                                 noti->temp_content = strdup(result_str);
904
905                                 *text = noti->temp_content;
906                                 break;
907                         default:
908                                 break;
909                         }
910
911                 }
912
913         } else {
914                 *text = NULL;
915         }
916
917         return NOTIFICATION_ERROR_NONE;
918 }
919
920 EXPORT_API int notification_set_text_domain(notification_h noti,
921                                                              const char *domain,
922                                                              const char *dir)
923 {
924         /* check noti and domain is valid data */
925         if (noti == NULL || domain == NULL || dir == NULL) {
926                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
927         }
928
929         /* Check domain */
930         if (noti->domain) {
931                 /* Remove previous domain */
932                 free(noti->domain);
933         }
934         /* Copy domain */
935         noti->domain = strdup(domain);
936
937         /* Check locale dir */
938         if (noti->dir) {
939                 /* Remove previous locale dir */
940                 free(noti->dir);
941         }
942         /* Copy locale dir */
943         noti->dir = strdup(dir);
944
945         return NOTIFICATION_ERROR_NONE;
946 }
947
948 EXPORT_API int notification_get_text_domain(notification_h noti,
949                                                              char **domain,
950                                                              char **dir)
951 {
952         /* Check noti is valid data */
953         if (noti == NULL) {
954                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
955         }
956
957         /* Get domain */
958         if (domain != NULL && noti->domain != NULL) {
959                 *domain = noti->domain;
960         }
961
962         /* Get locale dir */
963         if (dir != NULL && noti->dir != NULL) {
964                 *dir = noti->dir;
965         }
966
967         return NOTIFICATION_ERROR_NONE;
968 }
969
970 EXPORT_API int notification_set_time_to_text(notification_h noti, notification_text_type_e type,
971                                                                 time_t time)
972 {
973         int ret = NOTIFICATION_ERROR_NONE;
974         char buf[256] = { 0, };
975         char buf_tag[512] = { 0, };
976
977         if (noti == NULL) {
978                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
979         }
980         if (time <= 0) {
981                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
982         }
983         if (type <= NOTIFICATION_TEXT_TYPE_NONE
984             || type >= NOTIFICATION_TEXT_TYPE_MAX) {
985                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
986         }
987
988
989         snprintf(buf, sizeof(buf), "%lu", time);
990         ret = notification_noti_set_tag(TAG_TIME, buf, buf_tag, sizeof(buf_tag));
991
992         if (ret != NOTIFICATION_ERROR_NONE) {
993                 return ret;
994         }
995
996         return notification_set_text(noti, type, buf_tag, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
997 }
998
999 EXPORT_API int notification_get_time_from_text(notification_h noti, notification_text_type_e type,
1000                                                                 time_t *time)
1001 {
1002         int ret = NOTIFICATION_ERROR_NONE;
1003
1004         if (noti == NULL) {
1005                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1006         }
1007         if (time == NULL) {
1008                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1009         }
1010         if (type <= NOTIFICATION_TEXT_TYPE_NONE
1011             || type >= NOTIFICATION_TEXT_TYPE_MAX) {
1012                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1013         }
1014
1015         char *ret_text = NULL;
1016         ret = notification_get_text(noti, type, &ret_text);
1017
1018         if (ret != NOTIFICATION_ERROR_NONE || ret_text == NULL) {
1019                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1020         }
1021
1022         if (notification_noti_get_tag_type(ret_text) == TAG_TYPE_INVALID) {
1023                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1024         }
1025
1026         char *tag_value = NULL;
1027         tag_value = notification_noti_strip_tag(ret_text);
1028         if (tag_value == NULL) {
1029                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1030         }
1031
1032         *time = atol(tag_value);
1033         free(tag_value);
1034
1035         return NOTIFICATION_ERROR_NONE;
1036 }
1037
1038 EXPORT_API int notification_set_sound(notification_h noti,
1039                                                        notification_sound_type_e type,
1040                                                        const char *path)
1041 {
1042         /* Check noti is valid data */
1043         if (noti == NULL) {
1044                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1045         }
1046
1047         /* Check type is valid */
1048         if (type < NOTIFICATION_SOUND_TYPE_NONE
1049             || type >= NOTIFICATION_SOUND_TYPE_MAX) {
1050                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1051         }
1052
1053         /* Save sound type */
1054         noti->sound_type = type;
1055
1056         /* Save sound path if user data type */
1057         if (type == NOTIFICATION_SOUND_TYPE_USER_DATA && path != NULL) {
1058                 if (noti->sound_path != NULL) {
1059                         free(noti->sound_path);
1060                 }
1061
1062                 noti->sound_path = strdup(path);
1063         } else {
1064                 if (noti->sound_path != NULL) {
1065                         free(noti->sound_path);
1066                         noti->sound_path = NULL;
1067                 }
1068                 if (type == NOTIFICATION_SOUND_TYPE_USER_DATA) {
1069                         noti->sound_type = NOTIFICATION_SOUND_TYPE_DEFAULT;
1070                         return NOTIFICATION_ERROR_INVALID_PARAMETER;
1071                 }
1072         }
1073
1074         return NOTIFICATION_ERROR_NONE;
1075 }
1076
1077 EXPORT_API int notification_get_sound(notification_h noti,
1078                                                        notification_sound_type_e *type,
1079                                                        const char **path)
1080 {
1081         /* check noti and type is valid data */
1082         if (noti == NULL || type == NULL) {
1083                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1084         }
1085
1086         /* Set sound type */
1087         *type = noti->sound_type;
1088
1089         /* Set sound path if user data type */
1090         if (noti->sound_type == NOTIFICATION_SOUND_TYPE_USER_DATA
1091             && path != NULL) {
1092                 *path = noti->sound_path;
1093         }
1094
1095         return NOTIFICATION_ERROR_NONE;
1096 }
1097
1098 EXPORT_API int notification_set_vibration(notification_h noti,
1099                                                            notification_vibration_type_e type,
1100                                                            const char *path)
1101 {
1102         /* Check noti is valid data */
1103         if (noti == NULL) {
1104                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1105         }
1106
1107         /* Check type is valid */
1108         if (type < NOTIFICATION_VIBRATION_TYPE_NONE
1109             || type >= NOTIFICATION_VIBRATION_TYPE_MAX) {
1110                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1111         }
1112
1113         /* Save vibration type */
1114         noti->vibration_type = type;
1115
1116         /* Save sound path if user data type */
1117         if (type == NOTIFICATION_VIBRATION_TYPE_USER_DATA && path != NULL) {
1118                 if (noti->vibration_path != NULL) {
1119                         free(noti->vibration_path);
1120                 }
1121
1122                 noti->vibration_path = strdup(path);
1123         } else {
1124                 if (noti->vibration_path != NULL) {
1125                         free(noti->vibration_path);
1126                         noti->vibration_path = NULL;
1127                 }
1128                 if (type == NOTIFICATION_VIBRATION_TYPE_USER_DATA) {
1129                         noti->vibration_type = NOTIFICATION_VIBRATION_TYPE_DEFAULT;
1130                         return NOTIFICATION_ERROR_INVALID_PARAMETER;
1131                 }
1132         }
1133
1134         return NOTIFICATION_ERROR_NONE;
1135
1136 }
1137
1138 EXPORT_API int notification_get_vibration(notification_h noti,
1139                                                            notification_vibration_type_e *type,
1140                                                            const char **path)
1141 {
1142         /* check noti and type is valid data */
1143         if (noti == NULL || type == NULL) {
1144                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1145         }
1146
1147         /* Set vibration type */
1148         *type = noti->vibration_type;
1149
1150         /* Set sound path if user data type */
1151         if (noti->vibration_type == NOTIFICATION_VIBRATION_TYPE_USER_DATA
1152             && path != NULL) {
1153                 *path = noti->vibration_path;
1154         }
1155
1156         return NOTIFICATION_ERROR_NONE;
1157 }
1158
1159 EXPORT_API int notification_set_led(notification_h noti,
1160                                                            notification_led_op_e operation,
1161                                                            int led_argb)
1162 {
1163         /* Check noti is valid data */
1164         if (noti == NULL) {
1165                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1166         }
1167
1168         /* Check operation is valid */
1169         if (operation < NOTIFICATION_LED_OP_OFF
1170             || operation >= NOTIFICATION_LED_OP_MAX) {
1171                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1172         }
1173
1174         /* Save led operation */
1175         noti->led_operation = operation;
1176
1177         /* Save led argb if operation is turning on LED with custom color */
1178         if (operation == NOTIFICATION_LED_OP_ON_CUSTOM_COLOR) {
1179                 noti->led_argb = led_argb;
1180         }
1181
1182         return NOTIFICATION_ERROR_NONE;
1183 }
1184
1185 EXPORT_API int notification_get_led(notification_h noti,
1186                                                            notification_led_op_e *operation,
1187                                                            int *led_argb)
1188 {
1189         /* check noti and operation is valid data */
1190         if (noti == NULL || operation == NULL) {
1191                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1192         }
1193
1194         /* Set led operation */
1195         *operation = noti->led_operation;
1196
1197         /* Save led argb if operation is turning on LED with custom color */
1198         if (noti->led_operation == NOTIFICATION_LED_OP_ON_CUSTOM_COLOR
1199             && led_argb != NULL) {
1200                 *led_argb = noti->led_argb;
1201         }
1202
1203         return NOTIFICATION_ERROR_NONE;
1204 }
1205
1206 EXPORT_API int notification_set_led_time_period(notification_h noti,
1207                                                                         int on_ms, int off_ms)
1208 {
1209         /* Check noti is valid data */
1210         if (noti == NULL || on_ms < 0 || off_ms < 0) {
1211                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1212         }
1213
1214         /* Save led operation */
1215         noti->led_on_ms = on_ms;
1216         noti->led_off_ms = off_ms;
1217
1218         return NOTIFICATION_ERROR_NONE;
1219 }
1220
1221 EXPORT_API int notification_get_led_time_period(notification_h noti,
1222                                                                         int *on_ms, int *off_ms)
1223 {
1224         /* check noti and operation is valid data */
1225         if (noti == NULL) {
1226                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1227         }
1228
1229         if (on_ms)
1230                 *(on_ms) = noti->led_on_ms;
1231         if (off_ms)
1232                 *(off_ms) = noti->led_off_ms;
1233
1234         return NOTIFICATION_ERROR_NONE;
1235 }
1236
1237 EXPORT_API int notification_set_launch_option(notification_h noti,
1238                                                                 notification_launch_option_type type, void *option)
1239 {
1240         int err = NOTIFICATION_ERROR_NONE;
1241         int ret = 0;
1242         bundle *b = NULL;
1243         app_control_h app_control = option;
1244
1245         if (noti == NULL || app_control == NULL || type != NOTIFICATION_LAUNCH_OPTION_APP_CONTROL) {
1246                 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
1247                 goto out;
1248         }
1249
1250         if ((ret = app_control_export_as_bundle(app_control, &b)) != APP_CONTROL_ERROR_NONE) {
1251                 NOTIFICATION_ERR("Failed to convert appcontrol to bundle:%d", ret);
1252                 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
1253                 goto out;
1254         }
1255
1256         err = notification_set_execute_option(noti, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, NULL, b);
1257
1258 out:
1259         if (b)
1260                 bundle_free(b);
1261
1262         return err;
1263 }
1264
1265 EXPORT_API int notification_get_launch_option(notification_h noti,
1266                                                                 notification_launch_option_type type, void *option)
1267 {
1268         int ret = 0;
1269         bundle *b = NULL;
1270         app_control_h *app_control = (app_control_h *)option;
1271         app_control_h app_control_new = NULL;
1272
1273         if (noti == NULL) {
1274                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1275         }
1276         if (app_control == NULL) {
1277                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1278         }
1279         if (type != NOTIFICATION_LAUNCH_OPTION_APP_CONTROL) {
1280                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1281         }
1282
1283         ret = notification_get_execute_option(noti,
1284                                 NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH,
1285                                 NULL,
1286                                 &b);
1287         if (ret == NOTIFICATION_ERROR_NONE && b != NULL) {
1288                 ret = app_control_create(&app_control_new);
1289                 if (ret == APP_CONTROL_ERROR_NONE && app_control_new != NULL) {
1290                         ret = app_control_import_from_bundle(app_control_new, b);
1291                         if (ret == APP_CONTROL_ERROR_NONE) {
1292                                 *app_control = app_control_new;
1293                         } else {
1294                                 app_control_destroy(app_control_new);
1295                                 NOTIFICATION_ERR("Failed to import app control from bundle:%d", ret);
1296                                 return NOTIFICATION_ERROR_IO_ERROR;
1297                         }
1298                 } else {
1299                         NOTIFICATION_ERR("Failed to create app control:%d", ret);
1300                         return NOTIFICATION_ERROR_IO_ERROR;
1301                 }
1302         } else {
1303                 NOTIFICATION_ERR("Failed to get execute option:%d", ret);
1304                 return ret;
1305         }
1306
1307         return NOTIFICATION_ERROR_NONE;
1308 }
1309
1310 EXPORT_API int notification_set_event_handler(notification_h noti, notification_event_type_e event_type, app_control_h event_handler)
1311 {
1312         int err = NOTIFICATION_ERROR_NONE;
1313         bundle *app_control_bundle = NULL;
1314
1315         if (noti == NULL) {
1316                 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
1317                 NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
1318                 goto out;
1319         }
1320
1321         if (event_type < NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1
1322                 || event_type > NOTIFICATION_EVENT_TYPE_CLICK_ON_THUMBNAIL) {
1323                 NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
1324                 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
1325                 goto out;
1326         }
1327
1328         if ((err = app_control_export_as_bundle(event_handler, &app_control_bundle)) != APP_CONTROL_ERROR_NONE) {
1329                 NOTIFICATION_ERR("app_control_to_bundle failed [%d]", err);
1330                 goto out;
1331         }
1332
1333         if (noti->b_event_handler[event_type] != NULL) {
1334                 bundle_free(noti->b_event_handler[event_type]);
1335         }
1336
1337         noti->b_event_handler[event_type] = app_control_bundle;
1338
1339 out:
1340         return err;
1341 }
1342
1343 EXPORT_API int notification_get_event_handler(notification_h noti, notification_event_type_e event_type, app_control_h *event_handler)
1344 {
1345         int err = NOTIFICATION_ERROR_NONE;
1346         bundle *b = NULL;
1347         app_control_h app_control_new = NULL;
1348
1349         if (noti == NULL) {
1350                 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
1351                 NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
1352                 goto out;
1353         }
1354         if (event_handler == NULL) {
1355                 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
1356                 NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
1357                 goto out;
1358         }
1359         if (event_type < NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1
1360                 || event_type > NOTIFICATION_EVENT_TYPE_CLICK_ON_THUMBNAIL) {
1361                 NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
1362                 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
1363                 goto out;
1364         }
1365
1366         b = noti->b_event_handler[event_type];
1367
1368         if (b == NULL) {
1369                 NOTIFICATION_DBG("No event handler\n");
1370                 err = NOTIFICATION_ERROR_NOT_EXIST_ID;
1371                 goto out;
1372         }
1373
1374         err = app_control_create(&app_control_new);
1375         if (err != APP_CONTROL_ERROR_NONE || app_control_new == NULL) {
1376                 NOTIFICATION_ERR("app_control_create failed [%d]", err);
1377                 err = NOTIFICATION_ERROR_IO_ERROR;
1378                 goto out;
1379         }
1380
1381         err = app_control_import_from_bundle(app_control_new, b);
1382         if (err == APP_CONTROL_ERROR_NONE) {
1383                 *event_handler = app_control_new;
1384         }
1385         else {
1386                 app_control_destroy(app_control_new);
1387                 app_control_new = NULL;
1388                 NOTIFICATION_ERR("Failed to import app control from bundle [%d]", err);
1389                 err = NOTIFICATION_ERROR_IO_ERROR;
1390                 goto out;
1391         }
1392
1393 out:
1394         if (event_handler)
1395                 *event_handler = app_control_new;
1396
1397         return err;
1398 }
1399
1400
1401
1402
1403
1404 EXPORT_API int notification_set_property(notification_h noti,
1405                                                           int flags)
1406 {
1407         /* Check noti is valid data */
1408         if (noti == NULL) {
1409                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1410         }
1411
1412         /* Set flags */
1413         noti->flags_for_property = flags;
1414
1415         return NOTIFICATION_ERROR_NONE;
1416 }
1417
1418 EXPORT_API int notification_get_property(notification_h noti,
1419                                                           int *flags)
1420 {
1421         /* Check noti and flags are valid data */
1422         if (noti == NULL || flags == NULL) {
1423                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1424         }
1425
1426         /* Set flags */
1427         *flags = noti->flags_for_property;
1428
1429         return NOTIFICATION_ERROR_NONE;
1430 }
1431
1432 EXPORT_API int notification_set_display_applist(notification_h noti,
1433                                                                  int applist)
1434 {
1435         /* Check noti is valid data */
1436         if (noti == NULL) {
1437                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1438         }
1439
1440         /* Set app list */
1441         if (applist == 0xffffffff) { /* 0xffffffff means old NOTIFICATION_DISPLAY_APP_ALL */
1442                 applist = NOTIFICATION_DISPLAY_APP_ALL;
1443         }
1444         noti->display_applist = applist;
1445
1446         return NOTIFICATION_ERROR_NONE;
1447 }
1448
1449 EXPORT_API int notification_get_display_applist(notification_h noti,
1450                                                                  int *applist)
1451 {
1452         /* Check noti and applist are valid data */
1453         if (noti == NULL || applist == NULL) {
1454                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1455         }
1456
1457         /* Set app list */
1458         *applist = noti->display_applist;
1459
1460         return NOTIFICATION_ERROR_NONE;
1461 }
1462
1463 EXPORT_API int notification_set_size(notification_h noti,
1464                                                       double size)
1465 {
1466         /* Check noti is valid data */
1467         if (noti == NULL) {
1468                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1469         }
1470
1471         /* Save progress size */
1472         noti->progress_size = size;
1473
1474         return NOTIFICATION_ERROR_NONE;
1475 }
1476
1477 EXPORT_API int notification_get_size(notification_h noti,
1478                                                       double *size)
1479 {
1480         /* Check noti and size is valid data */
1481         if (noti == NULL || size == NULL) {
1482                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1483         }
1484
1485         /* Set progress size */
1486         *size = noti->progress_size;
1487
1488         return NOTIFICATION_ERROR_NONE;
1489 }
1490
1491 EXPORT_API int notification_set_progress(notification_h noti,
1492                                                           double percentage)
1493 {
1494         /* Check noti is valid data */
1495         if (noti == NULL) {
1496                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1497         }
1498
1499         /* Save progress percentage */
1500         noti->progress_percentage = percentage;
1501
1502         return NOTIFICATION_ERROR_NONE;
1503 }
1504
1505 EXPORT_API int notification_get_progress(notification_h noti,
1506                                                           double *percentage)
1507 {
1508         /* Check noti and percentage are valid data */
1509         if (noti == NULL || percentage == NULL) {
1510                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1511         }
1512
1513         /* Set progress percentage */
1514         *percentage = noti->progress_percentage;
1515
1516         return NOTIFICATION_ERROR_NONE;
1517 }
1518
1519 EXPORT_API int notification_get_pkgname(notification_h noti,
1520                                                          char **pkgname)
1521 {
1522         /* Check noti and pkgname are valid data */
1523         if (noti == NULL || pkgname == NULL) {
1524                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1525         }
1526
1527         /* Get caller pkgname */
1528         if (noti->caller_pkgname) {
1529                 *pkgname = noti->caller_pkgname;
1530         } else {
1531                 *pkgname = NULL;
1532         }
1533
1534         return NOTIFICATION_ERROR_NONE;
1535 }
1536
1537 EXPORT_API int notification_set_layout(notification_h noti,
1538                 notification_ly_type_e layout)
1539 {
1540         /* check noti and pkgname are valid data */
1541         if (noti == NULL || (layout < NOTIFICATION_LY_NONE || layout >= NOTIFICATION_LY_MAX)) {
1542                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1543         }
1544
1545         noti->layout = layout;
1546
1547         return NOTIFICATION_ERROR_NONE;
1548 }
1549
1550 EXPORT_API int notification_get_layout(notification_h noti,
1551                 notification_ly_type_e *layout)
1552 {
1553         /* Check noti and pkgname are valid data */
1554         if (noti == NULL || layout == NULL) {
1555                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1556         }
1557
1558         *layout = noti->layout;
1559
1560         return NOTIFICATION_ERROR_NONE;
1561 }
1562
1563
1564
1565 EXPORT_API int notification_get_type(notification_h noti,
1566                                                       notification_type_e *type)
1567 {
1568         /* Check noti and type is valid data */
1569         if (noti == NULL || type == NULL) {
1570                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1571         }
1572
1573         /* Set noti type */
1574         *type = noti->type;
1575
1576         return NOTIFICATION_ERROR_NONE;
1577 }
1578
1579 EXPORT_API int notification_post(notification_h noti)
1580 {
1581         int ret = 0;
1582         int id = 0;
1583
1584         /* Check noti is vaild data */
1585         if (noti == NULL) {
1586                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1587         }
1588
1589         /* Check noti type is valid type */
1590         if (noti->type <= NOTIFICATION_TYPE_NONE
1591             || noti->type >= NOTIFICATION_TYPE_MAX) {
1592                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1593         }
1594
1595         /* Save insert time */
1596         noti->insert_time = time(NULL);
1597
1598         ret = notification_ipc_request_insert(noti, &id);
1599         if (ret != NOTIFICATION_ERROR_NONE) {
1600                 return ret;
1601         }
1602         noti->priv_id = id;
1603         NOTIFICATION_DBG("from master:%d", id);
1604
1605         return NOTIFICATION_ERROR_NONE;
1606 }
1607
1608
1609
1610 EXPORT_API int notification_update(notification_h noti)
1611 {
1612         int ret = 0;
1613
1614         /* Check noti is valid data */
1615         if (noti != NULL) {
1616                 /* Update insert time ? */
1617                 noti->insert_time = time(NULL);
1618                 ret = notification_ipc_request_update(noti);
1619         } else {
1620                 notification_ipc_request_refresh();
1621                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1622         }
1623         return ret;
1624 }
1625
1626 EXPORT_API int notification_delete_all(notification_type_e type)
1627 {
1628         int ret = 0;
1629         char *caller_pkgname = NULL;
1630
1631         if (type <= NOTIFICATION_TYPE_NONE || type >= NOTIFICATION_TYPE_MAX) {
1632                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1633         }
1634
1635         caller_pkgname = notification_get_pkgname_by_pid();
1636
1637         ret = notification_ipc_request_delete_multiple(type, caller_pkgname);
1638
1639         if (caller_pkgname) {
1640                 free(caller_pkgname);
1641         }
1642
1643         return ret;
1644 }
1645
1646 EXPORT_API int notification_delete(notification_h noti)
1647 {
1648         int ret = 0;
1649
1650         if (noti == NULL) {
1651                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1652         }
1653
1654         ret = notification_ipc_request_delete_single(NOTIFICATION_TYPE_NONE, noti->caller_pkgname, noti->priv_id);
1655
1656         return ret;
1657 }
1658
1659 static notification_h _notification_create(notification_type_e type)
1660 {
1661         notification_h noti = NULL;
1662         package_info_h package_info = NULL;
1663         char *app_id = NULL;
1664         char *domain_name = NULL;
1665         char *app_root_path = NULL;
1666         char locale_directory[PATH_MAX] = { 0, }; /* PATH_MAX 4096 */
1667         int err_app_manager = APP_MANAGER_ERROR_NONE;
1668
1669         if (type <= NOTIFICATION_TYPE_NONE || type >= NOTIFICATION_TYPE_MAX) {
1670                 NOTIFICATION_ERR("INVALID TYPE : %d", type);
1671                 set_last_result(NOTIFICATION_ERROR_INVALID_PARAMETER);
1672                 return NULL;
1673         }
1674
1675         noti = (notification_h) calloc(1, sizeof(struct _notification));
1676         if (noti == NULL) {
1677                 NOTIFICATION_ERR("NO MEMORY : noti == NULL");
1678                 set_last_result(NOTIFICATION_ERROR_OUT_OF_MEMORY);
1679                 return NULL;
1680         }
1681
1682         noti->type = type;
1683
1684         if (type == NOTIFICATION_TYPE_NOTI)
1685                 noti->layout = NOTIFICATION_LY_NOTI_EVENT_SINGLE;
1686         else if (type == NOTIFICATION_TYPE_ONGOING)
1687                 noti->layout = NOTIFICATION_LY_ONGOING_PROGRESS;
1688
1689         noti->caller_pkgname = notification_get_pkgname_by_pid();
1690         noti->group_id = NOTIFICATION_GROUP_ID_NONE;
1691         noti->priv_id = NOTIFICATION_PRIV_ID_NONE;
1692         noti->sound_type = NOTIFICATION_SOUND_TYPE_NONE;
1693         noti->vibration_type = NOTIFICATION_VIBRATION_TYPE_NONE;
1694         noti->led_operation = NOTIFICATION_LED_OP_OFF;
1695         noti->display_applist = NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY | NOTIFICATION_DISPLAY_APP_TICKER | NOTIFICATION_DISPLAY_APP_INDICATOR;
1696
1697
1698         err_app_manager = app_manager_get_app_id(getpid(), &app_id);
1699         if (err_app_manager != APP_MANAGER_ERROR_NONE || app_id == NULL) {
1700                 NOTIFICATION_WARN("app_manager_get_app_id failed err[%d] app_id[%p]", err_app_manager, app_id);
1701                 goto out;
1702         }
1703
1704         /* app name is used as domain name */
1705         /* domain_name is allocated by app_get_package_app_name */
1706         err_app_manager = app_get_package_app_name(app_id, &domain_name);
1707
1708         if (err_app_manager != APP_ERROR_NONE || domain_name == NULL) {
1709                 NOTIFICATION_WARN("app_get_package_app_name failed err[%d] domain_name[%p]", err_app_manager, domain_name);
1710                 goto out;
1711         }
1712
1713         err_app_manager = package_info_create(noti->caller_pkgname, &package_info);
1714
1715         if (err_app_manager != PACKAGE_MANAGER_ERROR_NONE || package_info == NULL) {
1716                 NOTIFICATION_WARN("package_info_create failed err[%d] package_info[%p]", err_app_manager, package_info);
1717                 goto out;
1718         }
1719
1720         err_app_manager = package_info_get_root_path(package_info, &app_root_path);
1721
1722         if (err_app_manager != PACKAGE_MANAGER_ERROR_NONE || app_root_path == NULL) {
1723                 NOTIFICATION_WARN("package_info_get_root_path failed err[%d] app_root_path[%p]", err_app_manager, app_root_path);
1724                 goto out;
1725         }
1726
1727         snprintf(locale_directory, PATH_MAX, "%s/res/locale", app_root_path);
1728
1729         noti->domain = strdup(domain_name);
1730         noti->dir    = strdup(locale_directory);
1731
1732 out:
1733         if (domain_name) {
1734                 free(domain_name);
1735         }
1736
1737         if (app_id) {
1738                 free(app_id);
1739         }
1740
1741         if (app_root_path) {
1742                 free(app_root_path);
1743         }
1744
1745         if (package_info) {
1746                 package_info_destroy(package_info);
1747         }
1748
1749         /*!
1750          * \NOTE
1751          * Other fields are already initialized with ZERO.
1752          */
1753         set_last_result(NOTIFICATION_ERROR_NONE);
1754         return noti;
1755 }
1756
1757 EXPORT_API notification_h notification_create(notification_type_e type)
1758 {
1759         return _notification_create(type);
1760 }
1761
1762 EXPORT_API notification_h  notification_load_by_tag(const char *tag)
1763 {
1764         int ret = 0;
1765         notification_h noti = NULL;
1766         char *caller_pkgname = NULL;
1767
1768         if (tag == NULL) {
1769                 NOTIFICATION_ERR("Invalid parameter");
1770                 set_last_result(NOTIFICATION_ERROR_INVALID_PARAMETER);
1771                 return NULL;
1772         }
1773
1774         caller_pkgname = notification_get_pkgname_by_pid();
1775         if (!caller_pkgname) {
1776                 NOTIFICATION_ERR("Failed to get a package name");
1777                 set_last_result(NOTIFICATION_ERROR_OUT_OF_MEMORY);
1778                 return NULL;
1779         }
1780
1781         noti = (notification_h) calloc(1, sizeof(struct _notification));
1782         if (noti == NULL) {
1783                 NOTIFICATION_ERR("Failed to alloc a new notification");
1784                 set_last_result(NOTIFICATION_ERROR_OUT_OF_MEMORY);
1785                 free(caller_pkgname);
1786
1787                 return NULL;
1788         }
1789
1790         ret = notification_noti_get_by_tag(noti, caller_pkgname, (char*)tag);
1791
1792         free(caller_pkgname);
1793
1794         set_last_result(ret);
1795
1796         if (ret != NOTIFICATION_ERROR_NONE) {
1797                 notification_free(noti);
1798                 return NULL;
1799         }
1800
1801         return noti;
1802 }
1803
1804 EXPORT_API int notification_clone(notification_h noti, notification_h *clone)
1805 {
1806         int i = 0;
1807         notification_h new_noti = NULL;
1808
1809         if (noti == NULL || clone == NULL) {
1810                 NOTIFICATION_ERR("INVALID PARAMETER.");
1811                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1812         }
1813
1814         new_noti = (notification_h) calloc(1, sizeof(struct _notification));
1815         if (new_noti == NULL) {
1816                 NOTIFICATION_ERR("NO MEMORY : noti == NULL");
1817                 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
1818         }
1819
1820         new_noti->type = noti->type;
1821         new_noti->layout = noti->layout;
1822
1823         new_noti->group_id = noti->group_id;
1824         new_noti->internal_group_id = noti->internal_group_id;
1825         new_noti->priv_id = noti->priv_id;
1826
1827         if(noti->caller_pkgname != NULL) {
1828                 new_noti->caller_pkgname = strdup(noti->caller_pkgname);
1829         } else {
1830                 new_noti->caller_pkgname = notification_get_pkgname_by_pid();
1831         }
1832         if(noti->launch_pkgname != NULL) {
1833                 new_noti->launch_pkgname = strdup(noti->launch_pkgname);
1834         } else {
1835                 new_noti->launch_pkgname = NULL;
1836         }
1837
1838         if(noti->args != NULL) {
1839                 new_noti->args = bundle_dup(noti->args);
1840         } else {
1841                 new_noti->args = NULL;
1842         }
1843         if(noti->group_args != NULL) {
1844                 new_noti->group_args = bundle_dup(noti->group_args);
1845         } else {
1846                 new_noti->group_args = NULL;
1847         }
1848
1849         if(noti->b_execute_option != NULL) {
1850                 new_noti->b_execute_option = bundle_dup(noti->b_execute_option);
1851         } else {
1852                 new_noti->b_execute_option = NULL;
1853         }
1854         if(noti->b_service_responding != NULL) {
1855                 new_noti->b_service_responding = bundle_dup(noti->b_service_responding);
1856         } else {
1857                 new_noti->b_service_responding = NULL;
1858         }
1859         if(noti->b_service_single_launch != NULL) {
1860                 new_noti->b_service_single_launch = bundle_dup(noti->b_service_single_launch);
1861         } else {
1862                 new_noti->b_service_single_launch = NULL;
1863         }
1864         if(noti->b_service_multi_launch != NULL) {
1865                 new_noti->b_service_multi_launch = bundle_dup(noti->b_service_multi_launch);
1866         } else {
1867                 new_noti->b_service_multi_launch = NULL;
1868         }
1869
1870         for (i = 0; i < NOTIFICATION_EVENT_TYPE_MAX; i++) {
1871                 if(noti->b_event_handler[i] != NULL) {
1872                         new_noti->b_event_handler[i] = bundle_dup(noti->b_event_handler[i]);
1873                 } else {
1874                         new_noti->b_event_handler[i] = NULL;
1875                 }
1876         }
1877
1878         new_noti->sound_type = noti->sound_type;
1879         if(noti->sound_path != NULL) {
1880                 new_noti->sound_path = strdup(noti->sound_path);
1881         } else {
1882                 new_noti->sound_path = NULL;
1883         }
1884         new_noti->vibration_type = noti->vibration_type;
1885         if(noti->vibration_path != NULL) {
1886                 new_noti->vibration_path = strdup(noti->vibration_path);
1887         } else {
1888                 new_noti->vibration_path = NULL;
1889         }
1890         new_noti->led_operation = noti->led_operation;
1891         new_noti->led_argb = noti->led_argb;
1892         new_noti->led_on_ms = noti->led_on_ms;
1893         new_noti->led_off_ms = noti->led_off_ms;
1894
1895         if(noti->domain != NULL) {
1896                 new_noti->domain = strdup(noti->domain);
1897         } else {
1898                 new_noti->domain = NULL;
1899         }
1900         if(noti->dir != NULL) {
1901                 new_noti->dir = strdup(noti->dir);
1902         } else {
1903                 new_noti->dir = NULL;
1904         }
1905
1906         if(noti->b_text != NULL) {
1907                 new_noti->b_text = bundle_dup(noti->b_text);
1908         } else {
1909                 new_noti->b_text = NULL;
1910         }
1911         if(noti->b_key != NULL) {
1912                 new_noti->b_key = bundle_dup(noti->b_key);
1913         } else {
1914                 new_noti->b_key = NULL;
1915         }
1916         if(noti->b_format_args != NULL) {
1917                 new_noti->b_format_args = bundle_dup(noti->b_format_args);
1918         } else {
1919                 new_noti->b_format_args = NULL;
1920         }
1921         new_noti->num_format_args = noti->num_format_args;
1922
1923         if(noti->b_image_path != NULL) {
1924                 new_noti->b_image_path = bundle_dup(noti->b_image_path);
1925         } else {
1926                 new_noti->b_image_path = NULL;
1927         }
1928
1929         new_noti->time = noti->time;
1930         new_noti->insert_time = noti->insert_time;
1931
1932         new_noti->flags_for_property = noti->flags_for_property;
1933         new_noti->display_applist = noti->display_applist;
1934
1935         new_noti->progress_size = noti->progress_size;
1936         new_noti->progress_percentage = noti->progress_percentage;
1937
1938         new_noti->app_icon_path = NULL;
1939         new_noti->app_name = NULL;
1940         new_noti->temp_title = NULL;
1941         new_noti->temp_content = NULL;
1942
1943         *clone = new_noti;
1944
1945         return NOTIFICATION_ERROR_NONE;
1946 }
1947
1948
1949 EXPORT_API int notification_free(notification_h noti)
1950 {
1951         int i = 0;
1952         if (noti == NULL) {
1953                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1954         }
1955
1956         if (noti->caller_pkgname) {
1957                 free(noti->caller_pkgname);
1958         }
1959         if (noti->launch_pkgname) {
1960                 free(noti->launch_pkgname);
1961         }
1962         if (noti->args) {
1963                 bundle_free(noti->args);
1964         }
1965         if (noti->group_args) {
1966                 bundle_free(noti->group_args);
1967         }
1968
1969         if (noti->b_execute_option) {
1970                 bundle_free(noti->b_execute_option);
1971         }
1972         if (noti->b_service_responding) {
1973                 bundle_free(noti->b_service_responding);
1974         }
1975         if (noti->b_service_single_launch) {
1976                 bundle_free(noti->b_service_single_launch);
1977         }
1978         if (noti->b_service_multi_launch) {
1979                 bundle_free(noti->b_service_multi_launch);
1980         }
1981
1982         for (i = 0; i < NOTIFICATION_EVENT_TYPE_MAX; i++) {
1983                 if(noti->b_event_handler[i] != NULL) {
1984                         bundle_free(noti->b_event_handler[i]);
1985                 }
1986         }
1987
1988         if (noti->sound_path) {
1989                 free(noti->sound_path);
1990         }
1991         if (noti->vibration_path) {
1992                 free(noti->vibration_path);
1993         }
1994
1995         if (noti->domain) {
1996                 free(noti->domain);
1997         }
1998         if (noti->dir) {
1999                 free(noti->dir);
2000         }
2001
2002         if (noti->b_text) {
2003                 bundle_free(noti->b_text);
2004         }
2005         if (noti->b_key) {
2006                 bundle_free(noti->b_key);
2007         }
2008         if (noti->b_format_args) {
2009                 bundle_free(noti->b_format_args);
2010         }
2011
2012         if (noti->b_image_path) {
2013                 bundle_free(noti->b_image_path);
2014         }
2015
2016         if (noti->app_icon_path) {
2017                 free(noti->app_icon_path);
2018         }
2019         if (noti->app_name) {
2020                 free(noti->app_name);
2021         }
2022         if (noti->temp_title) {
2023                 free(noti->temp_title);
2024         }
2025         if (noti->temp_content) {
2026                 free(noti->temp_content);
2027         }
2028
2029         if (noti->tag) {
2030                 free(noti->tag);
2031         }
2032
2033         free(noti);
2034
2035         return NOTIFICATION_ERROR_NONE;
2036 }
2037
2038 EXPORT_API int notification_set_tag(notification_h noti, const char *tag)
2039 {
2040         /* Check noti is valid data */
2041         if (noti == NULL) {
2042                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2043         }
2044
2045         if (tag != NULL) {
2046                 /* save input TAG */
2047                 if (noti->tag != NULL) {
2048                         free(noti->tag);
2049                 }
2050                 noti->tag = strdup(tag);
2051         }
2052
2053         return NOTIFICATION_ERROR_NONE;
2054
2055 }
2056
2057 EXPORT_API int notification_get_tag(notification_h noti, const char **tag)
2058 {
2059         /* Check noti is valid data */
2060         if (noti == NULL) {
2061                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2062         }
2063
2064         *tag = noti->tag;
2065         return NOTIFICATION_ERROR_NONE;
2066 }
2067
2068 void notification_call_posted_toast_cb(const char *message)
2069 {
2070         if (posted_toast_message_cb != NULL) {
2071                 posted_toast_message_cb((void*)message);
2072         }
2073 }
2074
2075 EXPORT_API int notification_set_ongoing_flag(notification_h noti, bool ongoing_flag)
2076 {
2077         if (noti == NULL)
2078                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2079
2080         noti->ongoing_flag = ongoing_flag;
2081
2082         return NOTIFICATION_ERROR_NONE;
2083 }
2084
2085 EXPORT_API int notification_get_ongoing_flag(notification_h noti, bool *ongoing_flag)
2086 {
2087         if (noti == NULL || ongoing_flag == NULL)
2088                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2089
2090         *ongoing_flag = noti->ongoing_flag;
2091
2092         return NOTIFICATION_ERROR_NONE;
2093 }
2094
2095
2096 EXPORT_API int notification_add_button(notification_h noti, notification_button_index_e button_index)
2097 {
2098         if (noti == NULL || button_index < NOTIFICATION_BUTTON_1 || button_index > NOTIFICATION_BUTTON_6)
2099                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2100
2101         return NOTIFICATION_ERROR_NONE;
2102 }
2103
2104 EXPORT_API int notification_remove_button(notification_h noti, notification_button_index_e button_index)
2105 {
2106         if (noti == NULL || button_index < NOTIFICATION_BUTTON_1 || button_index > NOTIFICATION_BUTTON_6)
2107                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2108
2109         if (noti->b_event_handler[button_index - 1]) {
2110                 bundle_free(noti->b_event_handler[button_index - 1]);
2111                 noti->b_event_handler[button_index - 1] = NULL;
2112         }
2113
2114         return NOTIFICATION_ERROR_NONE;
2115 }
2116
2117 EXPORT_API int notification_set_auto_remove(notification_h noti, bool auto_remove)
2118 {
2119         if (noti == NULL)
2120                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2121
2122         noti->auto_remove = auto_remove;
2123
2124         return NOTIFICATION_ERROR_NONE;
2125 }
2126
2127 EXPORT_API int notification_get_auto_remove(notification_h noti, bool *auto_remove)
2128 {
2129         if (noti == NULL || auto_remove == NULL)
2130                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2131
2132         *auto_remove = noti->auto_remove;
2133
2134         return NOTIFICATION_ERROR_NONE;
2135 }