104ed77da78b23e1e72b5d37ef77c5d60057a4bd
[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         int src_len = 0;
534         int max_len = 0;
535
536         /* Check noti is valid data */
537         if (noti == NULL || text == NULL) {
538                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
539         }
540
541         /* Check text type is valid type */
542         if (type <= NOTIFICATION_TEXT_TYPE_NONE
543             || type >= NOTIFICATION_TEXT_TYPE_MAX) {
544                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
545         }
546
547         /* Check key */
548         if (noti->b_key != NULL) {
549                 b = noti->b_key;
550
551                 /* Get text domain and dir */
552                 //_notification_get_text_domain(noti);
553
554                 snprintf(buf_key, sizeof(buf_key), "%d", type);
555
556                 bundle_get_str(b, buf_key, &ret_val);
557                 if (ret_val != NULL && noti->domain != NULL
558                     && noti->dir != NULL) {
559                         /* Get application string */
560                         bindtextdomain(noti->domain, noti->dir);
561
562                         get_str = dgettext(noti->domain, ret_val);
563                 } else if (ret_val != NULL) {
564                         /* Get system string */
565                         get_str = dgettext("sys_string", ret_val);
566                 } else {
567                         get_str = NULL;
568                 }
569         }
570
571         if (get_str == NULL && noti->b_text != NULL) {
572                 b = noti->b_text;
573                 /* Get basic text */
574                 snprintf(buf_key, sizeof(buf_key), "%d", type);
575
576                 bundle_get_str(b, buf_key, &get_str);
577         }
578
579         check_type = type;
580
581         if (get_str != NULL) {
582                 /* Get number format args */
583                 b = noti->b_format_args;
584                 noti->num_format_args = 0;
585
586                 if (b != NULL) {
587                         snprintf(buf_key, sizeof(buf_key), "num%d", check_type);
588                         bundle_get_str(b, buf_key, &ret_val);
589                         if (ret_val != NULL) {
590                                 noti->num_format_args = atoi(ret_val);
591                         }
592                 }
593
594                 if (noti->num_format_args == 0) {
595                         *text = (char *)get_str;
596                 } else {
597                         /* Check first variable is count, LEFT pos */
598                         snprintf(buf_key, sizeof(buf_key), "%dtype%d",
599                                  check_type, num_args);
600                         bundle_get_str(b, buf_key, &ret_val);
601                         if (ret_val != NULL) {
602                                 ret_var_type = atoi(ret_val);
603                         }
604
605                         if (ret_var_type == NOTIFICATION_VARIABLE_TYPE_COUNT) {
606                                 /* Get var Value */
607                                 snprintf(buf_key, sizeof(buf_key), "%dvalue%d",
608                                          check_type, num_args);
609                                 bundle_get_str(b, buf_key, &ret_val);
610                                 if (ret_val != NULL) {
611                                         ret_variable_int = atoi(ret_val);
612                                 }
613
614                                 if (ret_variable_int ==
615                                     NOTIFICATION_COUNT_POS_LEFT) {
616                                         notification_noti_get_count(noti->type,
617                                                                     noti->caller_pkgname,
618                                                                     noti->group_id,
619                                                                     noti->priv_id,
620                                                                     &ret_variable_int);
621                                         snprintf(buf_str, sizeof(buf_str),
622                                                  "%d ", ret_variable_int);
623
624                                         src_len = strlen(result_str);
625                                         max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
626
627                                         strncat(result_str, buf_str,
628                                                         max_len);
629                                         num_args++;
630                                 }
631                         }
632
633                         /* Check variable IN pos */
634                         for (temp_str = (char *)get_str; *temp_str != '\0';
635                              temp_str++) {
636                                 if (*temp_str != '%') {
637                                         strncat(result_str, temp_str, 1);
638                                 } else {
639                                         if (*(temp_str + 1) == '%') {
640                                                 strncat(result_str, temp_str,
641                                                         1);
642                                         } else if (*(temp_str + 1) == 'd') {
643                                                 /* Get var Type */
644                                                 ret_variable_int = 0;
645
646                                                 snprintf(buf_key,
647                                                          sizeof(buf_key),
648                                                          "%dtype%d", check_type,
649                                                          num_args);
650                                                 bundle_get_str(b, buf_key, &ret_val);
651                                                 if (ret_val != NULL) {
652                                                         ret_var_type = atoi(ret_val);
653                                                 }
654                                                 if (ret_var_type ==
655                                                     NOTIFICATION_VARIABLE_TYPE_COUNT) {
656                                                         /* Get notification count */
657                                                         notification_noti_get_count
658                                                             (noti->type,
659                                                              noti->caller_pkgname,
660                                                              noti->group_id,
661                                                              noti->priv_id,
662                                                              &ret_variable_int);
663                                                 } else {
664                                                         /* Get var Value */
665                                                         snprintf(buf_key,
666                                                                  sizeof(buf_key),
667                                                                  "%dvalue%d",
668                                                                  check_type,
669                                                                  num_args);
670                                                         bundle_get_str(b, buf_key, &ret_val);
671                                                         if (ret_val != NULL) {
672                                                                 ret_variable_int = atoi(ret_val);
673                                                         }
674                                                 }
675
676                                                 snprintf(buf_str,
677                                                          sizeof(buf_str), "%d",
678                                                          ret_variable_int);
679
680                                                 src_len = strlen(result_str);
681                                                 max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
682
683                                                 strncat(result_str, buf_str,
684                                                                 max_len);
685
686                                                 temp_str++;
687
688                                                 num_args++;
689                                         } else if (*(temp_str + 1) == 's') {
690                                                 /* Get var Value */
691                                                 snprintf(buf_key,
692                                                          sizeof(buf_key),
693                                                          "%dvalue%d",
694                                                          check_type, num_args);
695                                                 bundle_get_str(b, buf_key, &ret_val);
696
697                                                 if (ret_val != NULL && noti->domain != NULL     && noti->dir != NULL) {
698                                                         /* Get application string */
699                                                         bindtextdomain(noti->domain, noti->dir);
700                                                         translated_str = dgettext(noti->domain, ret_val);
701                                                         NOTIFICATION_INFO("translated_str[%s]", translated_str);
702                                                 } else if (ret_val != NULL) {
703                                                         /* Get system string */
704                                                         translated_str = dgettext("sys_string", ret_val);
705                                                         NOTIFICATION_INFO("translated_str[%s]", translated_str);
706                                                 } else {
707                                                         translated_str = NULL;
708                                                 }
709
710                                                 if (translated_str != NULL) {
711                                                         strncpy(buf_str, translated_str, sizeof(buf_str) - 1);
712                                                         src_len = strlen(result_str);
713                                                         max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
714                                                         strncat(result_str, buf_str, max_len);
715                                                 }
716                                                 temp_str++;
717                                                 num_args++;
718                                         } else if (*(temp_str + 1) == 'f') {
719                                                 /* Get var Value */
720                                                 snprintf(buf_key,
721                                                          sizeof(buf_key),
722                                                          "%dvalue%d",
723                                                          check_type, num_args);
724                                                 bundle_get_str(b, buf_key, &ret_val);
725                                                 if (ret_val != NULL) {
726                                                         ret_variable_double = atof(ret_val);
727                                                 }
728
729                                                 snprintf(buf_str,
730                                                          sizeof(buf_str),
731                                                          "%.2f",
732                                                          ret_variable_double);
733
734                                                 src_len = strlen(result_str);
735                                                 max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
736                                                 strncat(result_str, buf_str, max_len);
737
738                                                 temp_str++;
739                                                 num_args++;
740                                         } else if (*(temp_str + 1) >= '1' && *(temp_str + 1) <= '9') {
741                                                 if (*(temp_str + 3) == 'd') {
742                                                         /* Get var Type */
743                                                         ret_variable_int = 0;
744
745                                                         snprintf(buf_key,
746                                                                  sizeof(buf_key),
747                                                                  "%dtype%d", check_type,
748                                                                  num_args + *(temp_str + 1) - 49);
749                                                         bundle_get_str(b, buf_key, &ret_val);
750                                                         if (ret_val != NULL) {
751                                                                 ret_var_type = atoi(ret_val);
752                                                         }
753                                                         if (ret_var_type ==
754                                                             NOTIFICATION_VARIABLE_TYPE_COUNT) {
755                                                                 /* Get notification count */
756                                                                 notification_noti_get_count
757                                                                     (noti->type,
758                                                                      noti->caller_pkgname,
759                                                                      noti->group_id,
760                                                                      noti->priv_id,
761                                                                      &ret_variable_int);
762                                                         } else {
763                                                                 /* Get var Value */
764                                                                 snprintf(buf_key,
765                                                                          sizeof
766                                                                          (buf_key),
767                                                                          "%dvalue%d",
768                                                                          check_type,
769                                                                          num_args + *(temp_str + 1) - 49);
770                                                                 bundle_get_str(b, buf_key, &ret_val);
771                                                                 if (ret_val != NULL) {
772                                                                         ret_variable_int = atoi(ret_val);
773                                                                 }
774                                                         }
775
776                                                         snprintf(buf_str,
777                                                                  sizeof(buf_str), "%d",
778                                                                  ret_variable_int);
779
780                                                         src_len = strlen(result_str);
781                                                         max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
782
783                                                         strncat(result_str, buf_str, max_len);
784
785                                                         temp_str += 3;
786                                                 } else if (*(temp_str + 3) == 's') {
787                                                         /* Get var Value */
788                                                         snprintf(buf_key,
789                                                                  sizeof(buf_key),
790                                                                  "%dvalue%d",
791                                                                  check_type, num_args + *(temp_str + 1) - 49);
792                                                         bundle_get_str(b, buf_key, &ret_val);
793
794                                                         snprintf(buf_str,
795                                                                  sizeof(buf_str), "%s",
796                                                                  ret_val);
797
798                                                         src_len = strlen(result_str);
799                                                         max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
800
801                                                         strncat(result_str, buf_str, max_len);
802
803                                                         temp_str += 3;
804                                                 } else if (*(temp_str + 3) == 'f') {
805                                                         /* Get var Value */
806                                                         snprintf(buf_key,
807                                                                  sizeof(buf_key),
808                                                                  "%dvalue%d",
809                                                                  check_type, num_args + *(temp_str + 1) - 49);
810                                                         bundle_get_str(b, buf_key, &ret_val);
811                                                         if (ret_val != NULL) {
812                                                                 ret_variable_double = atof(ret_val);
813                                                         }
814
815                                                         snprintf(buf_str,
816                                                                  sizeof(buf_str),
817                                                                  "%.2f",
818                                                                  ret_variable_double);
819
820                                                         src_len = strlen(result_str);
821                                                         max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
822
823                                                         strncat(result_str, buf_str, max_len);
824
825                                                         temp_str += 3;
826                                                 }
827                                         }
828                                 }
829
830                         }
831
832                         /* Check last variable is count, LEFT pos */
833                         if (num_args < noti->num_format_args) {
834                                 snprintf(buf_key, sizeof(buf_key), "%dtype%d",
835                                          check_type, num_args);
836                                 bundle_get_str(b, buf_key, &ret_val);
837                                 if (ret_val != NULL) {
838                                         ret_var_type = atoi(ret_val);
839                                 }
840
841                                 if (ret_var_type ==
842                                     NOTIFICATION_VARIABLE_TYPE_COUNT) {
843                                         /* Get var Value */
844                                         snprintf(buf_key, sizeof(buf_key),
845                                                  "%dvalue%d", check_type,
846                                                  num_args);
847                                         bundle_get_str(b, buf_key, &ret_val);
848                                         if (ret_val != NULL) {
849                                                 ret_variable_int = atoi(ret_val);
850                                         }
851
852                                         if (ret_variable_int ==
853                                             NOTIFICATION_COUNT_POS_RIGHT) {
854                                                 notification_noti_get_count
855                                                     (noti->type,
856                                                      noti->caller_pkgname,
857                                                      noti->group_id,
858                                                      noti->priv_id,
859                                                      &ret_variable_int);
860                                                 snprintf(buf_str,
861                                                          sizeof(buf_str), " %d",
862                                                          ret_variable_int);
863
864                                                 src_len = strlen(result_str);
865                                                 max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
866
867                                                 strncat(result_str, buf_str, max_len);
868
869                                                 num_args++;
870                                         }
871
872                                 }
873                         }
874
875                         switch (check_type) {
876                         case NOTIFICATION_TEXT_TYPE_TITLE:
877                         case NOTIFICATION_TEXT_TYPE_GROUP_TITLE:
878                                 if (noti->temp_title != NULL)
879                                         free(noti->temp_title);
880
881                                 noti->temp_title = strdup(result_str);
882
883                                 *text = noti->temp_title;
884                                 break;
885                         case NOTIFICATION_TEXT_TYPE_CONTENT:
886                         case NOTIFICATION_TEXT_TYPE_CONTENT_FOR_DISPLAY_OPTION_IS_OFF:
887                         case NOTIFICATION_TEXT_TYPE_GROUP_CONTENT:
888                         case NOTIFICATION_TEXT_TYPE_GROUP_CONTENT_FOR_DISPLAY_OPTION_IS_OFF:
889                                 if (noti->temp_content !=
890                                     NULL)
891                                         free(noti->temp_content);
892
893                                 noti->temp_content = strdup(result_str);
894
895                                 *text = noti->temp_content;
896                                 break;
897                         default:
898                                 break;
899                         }
900
901                 }
902
903         } else {
904                 *text = NULL;
905         }
906
907         return NOTIFICATION_ERROR_NONE;
908 }
909
910 EXPORT_API int notification_set_text_domain(notification_h noti,
911                                                              const char *domain,
912                                                              const char *dir)
913 {
914         /* check noti and domain is valid data */
915         if (noti == NULL || domain == NULL || dir == NULL) {
916                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
917         }
918
919         /* Check domain */
920         if (noti->domain) {
921                 /* Remove previous domain */
922                 free(noti->domain);
923         }
924         /* Copy domain */
925         noti->domain = strdup(domain);
926
927         /* Check locale dir */
928         if (noti->dir) {
929                 /* Remove previous locale dir */
930                 free(noti->dir);
931         }
932         /* Copy locale dir */
933         noti->dir = strdup(dir);
934
935         return NOTIFICATION_ERROR_NONE;
936 }
937
938 EXPORT_API int notification_get_text_domain(notification_h noti,
939                                                              char **domain,
940                                                              char **dir)
941 {
942         /* Check noti is valid data */
943         if (noti == NULL) {
944                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
945         }
946
947         /* Get domain */
948         if (domain != NULL && noti->domain != NULL) {
949                 *domain = noti->domain;
950         }
951
952         /* Get locale dir */
953         if (dir != NULL && noti->dir != NULL) {
954                 *dir = noti->dir;
955         }
956
957         return NOTIFICATION_ERROR_NONE;
958 }
959
960 EXPORT_API int notification_set_time_to_text(notification_h noti, notification_text_type_e type,
961                                                                 time_t time)
962 {
963         int ret = NOTIFICATION_ERROR_NONE;
964         char buf[256] = { 0, };
965         char buf_tag[512] = { 0, };
966
967         if (noti == NULL) {
968                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
969         }
970         if (time <= 0) {
971                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
972         }
973         if (type <= NOTIFICATION_TEXT_TYPE_NONE
974             || type >= NOTIFICATION_TEXT_TYPE_MAX) {
975                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
976         }
977
978
979         snprintf(buf, sizeof(buf), "%lu", time);
980         ret = notification_noti_set_tag(TAG_TIME, buf, buf_tag, sizeof(buf_tag));
981
982         if (ret != NOTIFICATION_ERROR_NONE) {
983                 return ret;
984         }
985
986         return notification_set_text(noti, type, buf_tag, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
987 }
988
989 EXPORT_API int notification_get_time_from_text(notification_h noti, notification_text_type_e type,
990                                                                 time_t *time)
991 {
992         int ret = NOTIFICATION_ERROR_NONE;
993
994         if (noti == NULL) {
995                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
996         }
997         if (time == NULL) {
998                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
999         }
1000         if (type <= NOTIFICATION_TEXT_TYPE_NONE
1001             || type >= NOTIFICATION_TEXT_TYPE_MAX) {
1002                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1003         }
1004
1005         char *ret_text = NULL;
1006         ret = notification_get_text(noti, type, &ret_text);
1007
1008         if (ret != NOTIFICATION_ERROR_NONE || ret_text == NULL) {
1009                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1010         }
1011
1012         if (notification_noti_get_tag_type(ret_text) == TAG_TYPE_INVALID) {
1013                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1014         }
1015
1016         char *tag_value = NULL;
1017         tag_value = notification_noti_strip_tag(ret_text);
1018         if (tag_value == NULL) {
1019                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1020         }
1021
1022         *time = atol(tag_value);
1023         free(tag_value);
1024
1025         return NOTIFICATION_ERROR_NONE;
1026 }
1027
1028 EXPORT_API int notification_set_sound(notification_h noti,
1029                                                        notification_sound_type_e type,
1030                                                        const char *path)
1031 {
1032         /* Check noti is valid data */
1033         if (noti == NULL) {
1034                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1035         }
1036
1037         /* Check type is valid */
1038         if (type < NOTIFICATION_SOUND_TYPE_NONE
1039             || type >= NOTIFICATION_SOUND_TYPE_MAX) {
1040                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1041         }
1042
1043         /* Save sound type */
1044         noti->sound_type = type;
1045
1046         /* Save sound path if user data type */
1047         if (type == NOTIFICATION_SOUND_TYPE_USER_DATA && path != NULL) {
1048                 if (noti->sound_path != NULL) {
1049                         free(noti->sound_path);
1050                 }
1051
1052                 noti->sound_path = strdup(path);
1053         } else {
1054                 if (noti->sound_path != NULL) {
1055                         free(noti->sound_path);
1056                         noti->sound_path = NULL;
1057                 }
1058                 if (type == NOTIFICATION_SOUND_TYPE_USER_DATA) {
1059                         noti->sound_type = NOTIFICATION_SOUND_TYPE_DEFAULT;
1060                         return NOTIFICATION_ERROR_INVALID_PARAMETER;
1061                 }
1062         }
1063
1064         return NOTIFICATION_ERROR_NONE;
1065 }
1066
1067 EXPORT_API int notification_get_sound(notification_h noti,
1068                                                        notification_sound_type_e *type,
1069                                                        const char **path)
1070 {
1071         /* check noti and type is valid data */
1072         if (noti == NULL || type == NULL) {
1073                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1074         }
1075
1076         /* Set sound type */
1077         *type = noti->sound_type;
1078
1079         /* Set sound path if user data type */
1080         if (noti->sound_type == NOTIFICATION_SOUND_TYPE_USER_DATA
1081             && path != NULL) {
1082                 *path = noti->sound_path;
1083         }
1084
1085         return NOTIFICATION_ERROR_NONE;
1086 }
1087
1088 EXPORT_API int notification_set_vibration(notification_h noti,
1089                                                            notification_vibration_type_e type,
1090                                                            const char *path)
1091 {
1092         /* Check noti is valid data */
1093         if (noti == NULL) {
1094                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1095         }
1096
1097         /* Check type is valid */
1098         if (type < NOTIFICATION_VIBRATION_TYPE_NONE
1099             || type >= NOTIFICATION_VIBRATION_TYPE_MAX) {
1100                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1101         }
1102
1103         /* Save vibration type */
1104         noti->vibration_type = type;
1105
1106         /* Save sound path if user data type */
1107         if (type == NOTIFICATION_VIBRATION_TYPE_USER_DATA && path != NULL) {
1108                 if (noti->vibration_path != NULL) {
1109                         free(noti->vibration_path);
1110                 }
1111
1112                 noti->vibration_path = strdup(path);
1113         } else {
1114                 if (noti->vibration_path != NULL) {
1115                         free(noti->vibration_path);
1116                         noti->vibration_path = NULL;
1117                 }
1118                 if (type == NOTIFICATION_VIBRATION_TYPE_USER_DATA) {
1119                         noti->vibration_type = NOTIFICATION_VIBRATION_TYPE_DEFAULT;
1120                         return NOTIFICATION_ERROR_INVALID_PARAMETER;
1121                 }
1122         }
1123
1124         return NOTIFICATION_ERROR_NONE;
1125
1126 }
1127
1128 EXPORT_API int notification_get_vibration(notification_h noti,
1129                                                            notification_vibration_type_e *type,
1130                                                            const char **path)
1131 {
1132         /* check noti and type is valid data */
1133         if (noti == NULL || type == NULL) {
1134                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1135         }
1136
1137         /* Set vibration type */
1138         *type = noti->vibration_type;
1139
1140         /* Set sound path if user data type */
1141         if (noti->vibration_type == NOTIFICATION_VIBRATION_TYPE_USER_DATA
1142             && path != NULL) {
1143                 *path = noti->vibration_path;
1144         }
1145
1146         return NOTIFICATION_ERROR_NONE;
1147 }
1148
1149 EXPORT_API int notification_set_led(notification_h noti,
1150                                                            notification_led_op_e operation,
1151                                                            int led_argb)
1152 {
1153         /* Check noti is valid data */
1154         if (noti == NULL) {
1155                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1156         }
1157
1158         /* Check operation is valid */
1159         if (operation < NOTIFICATION_LED_OP_OFF
1160             || operation >= NOTIFICATION_LED_OP_MAX) {
1161                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1162         }
1163
1164         /* Save led operation */
1165         noti->led_operation = operation;
1166
1167         /* Save led argb if operation is turning on LED with custom color */
1168         if (operation == NOTIFICATION_LED_OP_ON_CUSTOM_COLOR) {
1169                 noti->led_argb = led_argb;
1170         }
1171
1172         return NOTIFICATION_ERROR_NONE;
1173 }
1174
1175 EXPORT_API int notification_get_led(notification_h noti,
1176                                                            notification_led_op_e *operation,
1177                                                            int *led_argb)
1178 {
1179         /* check noti and operation is valid data */
1180         if (noti == NULL || operation == NULL) {
1181                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1182         }
1183
1184         /* Set led operation */
1185         *operation = noti->led_operation;
1186
1187         /* Save led argb if operation is turning on LED with custom color */
1188         if (noti->led_operation == NOTIFICATION_LED_OP_ON_CUSTOM_COLOR
1189             && led_argb != NULL) {
1190                 *led_argb = noti->led_argb;
1191         }
1192
1193         return NOTIFICATION_ERROR_NONE;
1194 }
1195
1196 EXPORT_API int notification_set_led_time_period(notification_h noti,
1197                                                                         int on_ms, int off_ms)
1198 {
1199         /* Check noti is valid data */
1200         if (noti == NULL || on_ms < 0 || off_ms < 0) {
1201                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1202         }
1203
1204         /* Save led operation */
1205         noti->led_on_ms = on_ms;
1206         noti->led_off_ms = off_ms;
1207
1208         return NOTIFICATION_ERROR_NONE;
1209 }
1210
1211 EXPORT_API int notification_get_led_time_period(notification_h noti,
1212                                                                         int *on_ms, int *off_ms)
1213 {
1214         /* check noti and operation is valid data */
1215         if (noti == NULL) {
1216                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1217         }
1218
1219         if (on_ms)
1220                 *(on_ms) = noti->led_on_ms;
1221         if (off_ms)
1222                 *(off_ms) = noti->led_off_ms;
1223
1224         return NOTIFICATION_ERROR_NONE;
1225 }
1226
1227 EXPORT_API int notification_set_launch_option(notification_h noti,
1228                                                                 notification_launch_option_type type, void *option)
1229 {
1230         int err = NOTIFICATION_ERROR_NONE;
1231         int ret = 0;
1232         bundle *b = NULL;
1233         app_control_h app_control = option;
1234
1235         if (noti == NULL || app_control == NULL || type != NOTIFICATION_LAUNCH_OPTION_APP_CONTROL) {
1236                 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
1237                 goto out;
1238         }
1239
1240         if ((ret = app_control_export_as_bundle(app_control, &b)) != APP_CONTROL_ERROR_NONE) {
1241                 NOTIFICATION_ERR("Failed to convert appcontrol to bundle:%d", ret);
1242                 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
1243                 goto out;
1244         }
1245
1246         err = notification_set_execute_option(noti, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, NULL, b);
1247
1248 out:
1249         if (b)
1250                 bundle_free(b);
1251
1252         return err;
1253 }
1254
1255 EXPORT_API int notification_get_launch_option(notification_h noti,
1256                                                                 notification_launch_option_type type, void *option)
1257 {
1258         int ret = 0;
1259         bundle *b = NULL;
1260         app_control_h *app_control = (app_control_h *)option;
1261         app_control_h app_control_new = NULL;
1262
1263         if (noti == NULL) {
1264                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1265         }
1266         if (app_control == NULL) {
1267                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1268         }
1269         if (type != NOTIFICATION_LAUNCH_OPTION_APP_CONTROL) {
1270                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1271         }
1272
1273         ret = notification_get_execute_option(noti,
1274                                 NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH,
1275                                 NULL,
1276                                 &b);
1277         if (ret == NOTIFICATION_ERROR_NONE && b != NULL) {
1278                 ret = app_control_create(&app_control_new);
1279                 if (ret == APP_CONTROL_ERROR_NONE && app_control_new != NULL) {
1280                         ret = app_control_import_from_bundle(app_control_new, b);
1281                         if (ret == APP_CONTROL_ERROR_NONE) {
1282                                 *app_control = app_control_new;
1283                         } else {
1284                                 app_control_destroy(app_control_new);
1285                                 NOTIFICATION_ERR("Failed to import app control from bundle:%d", ret);
1286                                 return NOTIFICATION_ERROR_IO_ERROR;
1287                         }
1288                 } else {
1289                         NOTIFICATION_ERR("Failed to create app control:%d", ret);
1290                         return NOTIFICATION_ERROR_IO_ERROR;
1291                 }
1292         } else {
1293                 NOTIFICATION_ERR("Failed to get execute option:%d", ret);
1294                 return ret;
1295         }
1296
1297         return NOTIFICATION_ERROR_NONE;
1298 }
1299
1300 EXPORT_API int notification_set_event_handler(notification_h noti, notification_event_type_e event_type, app_control_h event_handler)
1301 {
1302         int err = NOTIFICATION_ERROR_NONE;
1303         bundle *app_control_bundle = NULL;
1304
1305         if (noti == NULL) {
1306                 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
1307                 NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
1308                 goto out;
1309         }
1310
1311         if (event_type < NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1
1312                 || event_type > NOTIFICATION_EVENT_TYPE_CLICK_ON_THUMBNAIL) {
1313                 NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
1314                 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
1315                 goto out;
1316         }
1317
1318         if ((err = app_control_export_as_bundle(event_handler, &app_control_bundle)) != APP_CONTROL_ERROR_NONE) {
1319                 NOTIFICATION_ERR("app_control_to_bundle failed [%d]", err);
1320                 goto out;
1321         }
1322
1323         if (noti->b_event_handler[event_type] != NULL) {
1324                 bundle_free(noti->b_event_handler[event_type]);
1325         }
1326
1327         noti->b_event_handler[event_type] = app_control_bundle;
1328
1329 out:
1330         return err;
1331 }
1332
1333 EXPORT_API int notification_get_event_handler(notification_h noti, notification_event_type_e event_type, app_control_h *event_handler)
1334 {
1335         int err = NOTIFICATION_ERROR_NONE;
1336         bundle *b = NULL;
1337         app_control_h app_control_new = NULL;
1338
1339         if (noti == NULL) {
1340                 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
1341                 NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
1342                 goto out;
1343         }
1344         if (event_handler == NULL) {
1345                 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
1346                 NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
1347                 goto out;
1348         }
1349         if (event_type < NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1
1350                 || event_type > NOTIFICATION_EVENT_TYPE_CLICK_ON_THUMBNAIL) {
1351                 NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
1352                 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
1353                 goto out;
1354         }
1355
1356         b = noti->b_event_handler[event_type];
1357
1358         if (b == NULL) {
1359                 NOTIFICATION_DBG("No event handler\n");
1360                 err = NOTIFICATION_ERROR_NOT_EXIST_ID;
1361                 goto out;
1362         }
1363
1364         err = app_control_create(&app_control_new);
1365         if (err != APP_CONTROL_ERROR_NONE || app_control_new == NULL) {
1366                 NOTIFICATION_ERR("app_control_create failed [%d]", err);
1367                 err = NOTIFICATION_ERROR_IO_ERROR;
1368                 goto out;
1369         }
1370
1371         err = app_control_import_from_bundle(app_control_new, b);
1372         if (err == APP_CONTROL_ERROR_NONE) {
1373                 *event_handler = app_control_new;
1374         } else {
1375                 app_control_destroy(app_control_new);
1376                 app_control_new = NULL;
1377                 NOTIFICATION_ERR("Failed to import app control from bundle [%d]", err);
1378                 err = NOTIFICATION_ERROR_IO_ERROR;
1379                 goto out;
1380         }
1381
1382 out:
1383         if (event_handler)
1384                 *event_handler = app_control_new;
1385
1386         return err;
1387 }
1388
1389
1390
1391
1392
1393 EXPORT_API int notification_set_property(notification_h noti,
1394                                                           int flags)
1395 {
1396         /* Check noti is valid data */
1397         if (noti == NULL) {
1398                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1399         }
1400
1401         /* Set flags */
1402         noti->flags_for_property = flags;
1403
1404         return NOTIFICATION_ERROR_NONE;
1405 }
1406
1407 EXPORT_API int notification_get_property(notification_h noti,
1408                                                           int *flags)
1409 {
1410         /* Check noti and flags are valid data */
1411         if (noti == NULL || flags == NULL) {
1412                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1413         }
1414
1415         /* Set flags */
1416         *flags = noti->flags_for_property;
1417
1418         return NOTIFICATION_ERROR_NONE;
1419 }
1420
1421 EXPORT_API int notification_set_display_applist(notification_h noti,
1422                                                                  int applist)
1423 {
1424         /* Check noti is valid data */
1425         if (noti == NULL) {
1426                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1427         }
1428
1429         /* Set app list */
1430         if (applist == 0xffffffff) { /* 0xffffffff means old NOTIFICATION_DISPLAY_APP_ALL */
1431                 applist = NOTIFICATION_DISPLAY_APP_ALL;
1432         }
1433         noti->display_applist = applist;
1434
1435         return NOTIFICATION_ERROR_NONE;
1436 }
1437
1438 EXPORT_API int notification_get_display_applist(notification_h noti,
1439                                                                  int *applist)
1440 {
1441         /* Check noti and applist are valid data */
1442         if (noti == NULL || applist == NULL) {
1443                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1444         }
1445
1446         /* Set app list */
1447         *applist = noti->display_applist;
1448
1449         return NOTIFICATION_ERROR_NONE;
1450 }
1451
1452 EXPORT_API int notification_set_size(notification_h noti,
1453                                                       double size)
1454 {
1455         /* Check noti is valid data */
1456         if (noti == NULL) {
1457                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1458         }
1459
1460         /* Save progress size */
1461         noti->progress_size = size;
1462
1463         return NOTIFICATION_ERROR_NONE;
1464 }
1465
1466 EXPORT_API int notification_get_size(notification_h noti,
1467                                                       double *size)
1468 {
1469         /* Check noti and size is valid data */
1470         if (noti == NULL || size == NULL) {
1471                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1472         }
1473
1474         /* Set progress size */
1475         *size = noti->progress_size;
1476
1477         return NOTIFICATION_ERROR_NONE;
1478 }
1479
1480 EXPORT_API int notification_set_progress(notification_h noti,
1481                                                           double percentage)
1482 {
1483         /* Check noti is valid data */
1484         if (noti == NULL) {
1485                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1486         }
1487
1488         /* Save progress percentage */
1489         noti->progress_percentage = percentage;
1490
1491         return NOTIFICATION_ERROR_NONE;
1492 }
1493
1494 EXPORT_API int notification_get_progress(notification_h noti,
1495                                                           double *percentage)
1496 {
1497         /* Check noti and percentage are valid data */
1498         if (noti == NULL || percentage == NULL) {
1499                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1500         }
1501
1502         /* Set progress percentage */
1503         *percentage = noti->progress_percentage;
1504
1505         return NOTIFICATION_ERROR_NONE;
1506 }
1507
1508 EXPORT_API int notification_get_pkgname(notification_h noti,
1509                                                          char **pkgname)
1510 {
1511         /* Check noti and pkgname are valid data */
1512         if (noti == NULL || pkgname == NULL) {
1513                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1514         }
1515
1516         /* Get caller pkgname */
1517         if (noti->caller_pkgname) {
1518                 *pkgname = noti->caller_pkgname;
1519         } else {
1520                 *pkgname = NULL;
1521         }
1522
1523         return NOTIFICATION_ERROR_NONE;
1524 }
1525
1526 EXPORT_API int notification_set_layout(notification_h noti,
1527                 notification_ly_type_e layout)
1528 {
1529         /* check noti and pkgname are valid data */
1530         if (noti == NULL || (layout < NOTIFICATION_LY_NONE || layout >= NOTIFICATION_LY_MAX)) {
1531                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1532         }
1533
1534         noti->layout = layout;
1535
1536         return NOTIFICATION_ERROR_NONE;
1537 }
1538
1539 EXPORT_API int notification_get_layout(notification_h noti,
1540                 notification_ly_type_e *layout)
1541 {
1542         /* Check noti and pkgname are valid data */
1543         if (noti == NULL || layout == NULL) {
1544                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1545         }
1546
1547         *layout = noti->layout;
1548
1549         return NOTIFICATION_ERROR_NONE;
1550 }
1551
1552
1553
1554 EXPORT_API int notification_get_type(notification_h noti,
1555                                                       notification_type_e *type)
1556 {
1557         /* Check noti and type is valid data */
1558         if (noti == NULL || type == NULL) {
1559                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1560         }
1561
1562         /* Set noti type */
1563         *type = noti->type;
1564
1565         return NOTIFICATION_ERROR_NONE;
1566 }
1567
1568 EXPORT_API int notification_post(notification_h noti)
1569 {
1570         int ret = 0;
1571         int id = 0;
1572
1573         /* Check noti is vaild data */
1574         if (noti == NULL) {
1575                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1576         }
1577
1578         /* Check noti type is valid type */
1579         if (noti->type <= NOTIFICATION_TYPE_NONE
1580             || noti->type >= NOTIFICATION_TYPE_MAX) {
1581                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1582         }
1583
1584         /* Save insert time */
1585         noti->insert_time = time(NULL);
1586
1587         ret = notification_ipc_request_insert(noti, &id);
1588         if (ret != NOTIFICATION_ERROR_NONE) {
1589                 return ret;
1590         }
1591         noti->priv_id = id;
1592         NOTIFICATION_DBG("from master:%d", id);
1593
1594         return NOTIFICATION_ERROR_NONE;
1595 }
1596
1597
1598
1599 EXPORT_API int notification_update(notification_h noti)
1600 {
1601         int ret = 0;
1602
1603         /* Check noti is valid data */
1604         if (noti != NULL) {
1605                 /* Update insert time ? */
1606                 noti->insert_time = time(NULL);
1607                 ret = notification_ipc_request_update(noti);
1608         } else {
1609                 notification_ipc_request_refresh();
1610                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1611         }
1612         return ret;
1613 }
1614
1615 EXPORT_API int notification_delete_all(notification_type_e type)
1616 {
1617         int ret = 0;
1618         char *caller_pkgname = NULL;
1619
1620         if (type <= NOTIFICATION_TYPE_NONE || type >= NOTIFICATION_TYPE_MAX) {
1621                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1622         }
1623
1624         caller_pkgname = notification_get_pkgname_by_pid();
1625
1626         ret = notification_ipc_request_delete_multiple(type, caller_pkgname);
1627
1628         if (caller_pkgname) {
1629                 free(caller_pkgname);
1630         }
1631
1632         return ret;
1633 }
1634
1635 EXPORT_API int notification_delete(notification_h noti)
1636 {
1637         int ret = 0;
1638
1639         if (noti == NULL) {
1640                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1641         }
1642
1643         ret = notification_ipc_request_delete_single(NOTIFICATION_TYPE_NONE, noti->caller_pkgname, noti->priv_id);
1644
1645         return ret;
1646 }
1647
1648 static notification_h _notification_create(notification_type_e type)
1649 {
1650         notification_h noti = NULL;
1651         package_info_h package_info = NULL;
1652         char *app_id = NULL;
1653         char *domain_name = NULL;
1654         char *app_root_path = NULL;
1655         char locale_directory[PATH_MAX] = { 0, }; /* PATH_MAX 4096 */
1656         int err_app_manager = APP_MANAGER_ERROR_NONE;
1657
1658         if (type <= NOTIFICATION_TYPE_NONE || type >= NOTIFICATION_TYPE_MAX) {
1659                 NOTIFICATION_ERR("INVALID TYPE : %d", type);
1660                 set_last_result(NOTIFICATION_ERROR_INVALID_PARAMETER);
1661                 return NULL;
1662         }
1663
1664         noti = (notification_h) calloc(1, sizeof(struct _notification));
1665         if (noti == NULL) {
1666                 NOTIFICATION_ERR("NO MEMORY : noti == NULL");
1667                 set_last_result(NOTIFICATION_ERROR_OUT_OF_MEMORY);
1668                 return NULL;
1669         }
1670
1671         noti->type = type;
1672
1673         if (type == NOTIFICATION_TYPE_NOTI)
1674                 noti->layout = NOTIFICATION_LY_NOTI_EVENT_SINGLE;
1675         else if (type == NOTIFICATION_TYPE_ONGOING)
1676                 noti->layout = NOTIFICATION_LY_ONGOING_PROGRESS;
1677
1678         noti->caller_pkgname = notification_get_pkgname_by_pid();
1679         noti->group_id = NOTIFICATION_GROUP_ID_NONE;
1680         noti->priv_id = NOTIFICATION_PRIV_ID_NONE;
1681         noti->sound_type = NOTIFICATION_SOUND_TYPE_NONE;
1682         noti->vibration_type = NOTIFICATION_VIBRATION_TYPE_NONE;
1683         noti->led_operation = NOTIFICATION_LED_OP_OFF;
1684         noti->display_applist = NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY | NOTIFICATION_DISPLAY_APP_TICKER | NOTIFICATION_DISPLAY_APP_INDICATOR;
1685         noti->auto_remove = true;
1686
1687         err_app_manager = app_manager_get_app_id(getpid(), &app_id);
1688         if (err_app_manager != APP_MANAGER_ERROR_NONE || app_id == NULL) {
1689                 NOTIFICATION_WARN("app_manager_get_app_id failed err[%d] app_id[%p]", err_app_manager, app_id);
1690                 goto out;
1691         }
1692
1693         /* app name is used as domain name */
1694         /* domain_name is allocated by app_get_package_app_name */
1695         err_app_manager = app_get_package_app_name(app_id, &domain_name);
1696
1697         if (err_app_manager != APP_ERROR_NONE || domain_name == NULL) {
1698                 NOTIFICATION_WARN("app_get_package_app_name failed err[%d] domain_name[%p]", err_app_manager, domain_name);
1699                 goto out;
1700         }
1701
1702         err_app_manager = package_info_create(noti->caller_pkgname, &package_info);
1703
1704         if (err_app_manager != PACKAGE_MANAGER_ERROR_NONE || package_info == NULL) {
1705                 NOTIFICATION_WARN("package_info_create failed err[%d] package_info[%p] caller_pkgname[%s]",
1706                                 err_app_manager, package_info, noti->caller_pkgname);
1707                 goto out;
1708         }
1709
1710         err_app_manager = package_info_get_root_path(package_info, &app_root_path);
1711
1712         if (err_app_manager != PACKAGE_MANAGER_ERROR_NONE || app_root_path == NULL) {
1713                 NOTIFICATION_WARN("package_info_get_root_path failed err[%d] app_root_path[%p]", err_app_manager, app_root_path);
1714                 goto out;
1715         }
1716
1717         snprintf(locale_directory, PATH_MAX, "%s/res/locale", app_root_path);
1718
1719         noti->domain = strdup(domain_name);
1720         noti->dir    = strdup(locale_directory);
1721
1722 out:
1723         if (domain_name) {
1724                 free(domain_name);
1725         }
1726
1727         if (app_id) {
1728                 free(app_id);
1729         }
1730
1731         if (app_root_path) {
1732                 free(app_root_path);
1733         }
1734
1735         if (package_info) {
1736                 package_info_destroy(package_info);
1737         }
1738
1739         /*!
1740          * \NOTE
1741          * Other fields are already initialized with ZERO.
1742          */
1743         set_last_result(NOTIFICATION_ERROR_NONE);
1744         return noti;
1745 }
1746
1747 EXPORT_API notification_h notification_create(notification_type_e type)
1748 {
1749         return _notification_create(type);
1750 }
1751
1752 EXPORT_API notification_h  notification_load_by_tag(const char *tag)
1753 {
1754         int ret = 0;
1755         notification_h noti = NULL;
1756         char *caller_pkgname = NULL;
1757
1758         if (tag == NULL) {
1759                 NOTIFICATION_ERR("Invalid parameter");
1760                 set_last_result(NOTIFICATION_ERROR_INVALID_PARAMETER);
1761                 return NULL;
1762         }
1763
1764         caller_pkgname = notification_get_pkgname_by_pid();
1765         if (!caller_pkgname) {
1766                 NOTIFICATION_ERR("Failed to get a package name");
1767                 set_last_result(NOTIFICATION_ERROR_OUT_OF_MEMORY);
1768                 return NULL;
1769         }
1770
1771         noti = (notification_h) calloc(1, sizeof(struct _notification));
1772         if (noti == NULL) {
1773                 NOTIFICATION_ERR("Failed to alloc a new notification");
1774                 set_last_result(NOTIFICATION_ERROR_OUT_OF_MEMORY);
1775                 free(caller_pkgname);
1776
1777                 return NULL;
1778         }
1779
1780         ret = notification_noti_get_by_tag(noti, caller_pkgname, (char*)tag);
1781
1782         free(caller_pkgname);
1783
1784         set_last_result(ret);
1785
1786         if (ret != NOTIFICATION_ERROR_NONE) {
1787                 notification_free(noti);
1788                 return NULL;
1789         }
1790
1791         return noti;
1792 }
1793
1794 EXPORT_API int notification_clone(notification_h noti, notification_h *clone)
1795 {
1796         int i = 0;
1797         notification_h new_noti = NULL;
1798
1799         if (noti == NULL || clone == NULL) {
1800                 NOTIFICATION_ERR("INVALID PARAMETER.");
1801                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1802         }
1803
1804         new_noti = (notification_h) calloc(1, sizeof(struct _notification));
1805         if (new_noti == NULL) {
1806                 NOTIFICATION_ERR("NO MEMORY : noti == NULL");
1807                 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
1808         }
1809
1810         new_noti->type = noti->type;
1811         new_noti->layout = noti->layout;
1812
1813         new_noti->group_id = noti->group_id;
1814         new_noti->internal_group_id = noti->internal_group_id;
1815         new_noti->priv_id = noti->priv_id;
1816
1817         if (noti->caller_pkgname != NULL) {
1818                 new_noti->caller_pkgname = strdup(noti->caller_pkgname);
1819         } else {
1820                 new_noti->caller_pkgname = notification_get_pkgname_by_pid();
1821         }
1822         if (noti->launch_pkgname != NULL) {
1823                 new_noti->launch_pkgname = strdup(noti->launch_pkgname);
1824         } else {
1825                 new_noti->launch_pkgname = NULL;
1826         }
1827
1828         if (noti->args != NULL) {
1829                 new_noti->args = bundle_dup(noti->args);
1830         } else {
1831                 new_noti->args = NULL;
1832         }
1833         if (noti->group_args != NULL) {
1834                 new_noti->group_args = bundle_dup(noti->group_args);
1835         } else {
1836                 new_noti->group_args = NULL;
1837         }
1838
1839         if (noti->b_execute_option != NULL) {
1840                 new_noti->b_execute_option = bundle_dup(noti->b_execute_option);
1841         } else {
1842                 new_noti->b_execute_option = NULL;
1843         }
1844         if (noti->b_service_responding != NULL) {
1845                 new_noti->b_service_responding = bundle_dup(noti->b_service_responding);
1846         } else {
1847                 new_noti->b_service_responding = NULL;
1848         }
1849         if (noti->b_service_single_launch != NULL) {
1850                 new_noti->b_service_single_launch = bundle_dup(noti->b_service_single_launch);
1851         } else {
1852                 new_noti->b_service_single_launch = NULL;
1853         }
1854         if (noti->b_service_multi_launch != NULL) {
1855                 new_noti->b_service_multi_launch = bundle_dup(noti->b_service_multi_launch);
1856         } else {
1857                 new_noti->b_service_multi_launch = NULL;
1858         }
1859
1860         for (i = 0; i < NOTIFICATION_EVENT_TYPE_MAX; i++) {
1861                 if (noti->b_event_handler[i] != NULL) {
1862                         new_noti->b_event_handler[i] = bundle_dup(noti->b_event_handler[i]);
1863                 } else {
1864                         new_noti->b_event_handler[i] = NULL;
1865                 }
1866         }
1867
1868         new_noti->sound_type = noti->sound_type;
1869         if (noti->sound_path != NULL) {
1870                 new_noti->sound_path = strdup(noti->sound_path);
1871         } else {
1872                 new_noti->sound_path = NULL;
1873         }
1874         new_noti->vibration_type = noti->vibration_type;
1875         if (noti->vibration_path != NULL) {
1876                 new_noti->vibration_path = strdup(noti->vibration_path);
1877         } else {
1878                 new_noti->vibration_path = NULL;
1879         }
1880         new_noti->led_operation = noti->led_operation;
1881         new_noti->led_argb = noti->led_argb;
1882         new_noti->led_on_ms = noti->led_on_ms;
1883         new_noti->led_off_ms = noti->led_off_ms;
1884
1885         if (noti->domain != NULL) {
1886                 new_noti->domain = strdup(noti->domain);
1887         } else {
1888                 new_noti->domain = NULL;
1889         }
1890         if (noti->dir != NULL) {
1891                 new_noti->dir = strdup(noti->dir);
1892         } else {
1893                 new_noti->dir = NULL;
1894         }
1895
1896         if (noti->b_text != NULL) {
1897                 new_noti->b_text = bundle_dup(noti->b_text);
1898         } else {
1899                 new_noti->b_text = NULL;
1900         }
1901         if (noti->b_key != NULL) {
1902                 new_noti->b_key = bundle_dup(noti->b_key);
1903         } else {
1904                 new_noti->b_key = NULL;
1905         }
1906         if (noti->b_format_args != NULL) {
1907                 new_noti->b_format_args = bundle_dup(noti->b_format_args);
1908         } else {
1909                 new_noti->b_format_args = NULL;
1910         }
1911         new_noti->num_format_args = noti->num_format_args;
1912
1913         if (noti->b_image_path != NULL) {
1914                 new_noti->b_image_path = bundle_dup(noti->b_image_path);
1915         } else {
1916                 new_noti->b_image_path = NULL;
1917         }
1918
1919         new_noti->time = noti->time;
1920         new_noti->insert_time = noti->insert_time;
1921
1922         new_noti->flags_for_property = noti->flags_for_property;
1923         new_noti->display_applist = noti->display_applist;
1924
1925         new_noti->progress_size = noti->progress_size;
1926         new_noti->progress_percentage = noti->progress_percentage;
1927
1928         new_noti->ongoing_flag = noti->ongoing_flag;
1929         new_noti->auto_remove = noti->auto_remove;
1930
1931         new_noti->app_icon_path = NULL;
1932         new_noti->app_name = NULL;
1933         new_noti->temp_title = NULL;
1934         new_noti->temp_content = NULL;
1935
1936         *clone = new_noti;
1937
1938         return NOTIFICATION_ERROR_NONE;
1939 }
1940
1941
1942 EXPORT_API int notification_free(notification_h noti)
1943 {
1944         int i = 0;
1945         if (noti == NULL) {
1946                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1947         }
1948
1949         if (noti->caller_pkgname) {
1950                 free(noti->caller_pkgname);
1951         }
1952         if (noti->launch_pkgname) {
1953                 free(noti->launch_pkgname);
1954         }
1955         if (noti->args) {
1956                 bundle_free(noti->args);
1957         }
1958         if (noti->group_args) {
1959                 bundle_free(noti->group_args);
1960         }
1961
1962         if (noti->b_execute_option) {
1963                 bundle_free(noti->b_execute_option);
1964         }
1965         if (noti->b_service_responding) {
1966                 bundle_free(noti->b_service_responding);
1967         }
1968         if (noti->b_service_single_launch) {
1969                 bundle_free(noti->b_service_single_launch);
1970         }
1971         if (noti->b_service_multi_launch) {
1972                 bundle_free(noti->b_service_multi_launch);
1973         }
1974
1975         for (i = 0; i < NOTIFICATION_EVENT_TYPE_MAX; i++) {
1976                 if (noti->b_event_handler[i] != NULL) {
1977                         bundle_free(noti->b_event_handler[i]);
1978                 }
1979         }
1980
1981         if (noti->sound_path) {
1982                 free(noti->sound_path);
1983         }
1984         if (noti->vibration_path) {
1985                 free(noti->vibration_path);
1986         }
1987
1988         if (noti->domain) {
1989                 free(noti->domain);
1990         }
1991         if (noti->dir) {
1992                 free(noti->dir);
1993         }
1994
1995         if (noti->b_text) {
1996                 bundle_free(noti->b_text);
1997         }
1998         if (noti->b_key) {
1999                 bundle_free(noti->b_key);
2000         }
2001         if (noti->b_format_args) {
2002                 bundle_free(noti->b_format_args);
2003         }
2004
2005         if (noti->b_image_path) {
2006                 bundle_free(noti->b_image_path);
2007         }
2008
2009         if (noti->app_icon_path) {
2010                 free(noti->app_icon_path);
2011         }
2012         if (noti->app_name) {
2013                 free(noti->app_name);
2014         }
2015         if (noti->temp_title) {
2016                 free(noti->temp_title);
2017         }
2018         if (noti->temp_content) {
2019                 free(noti->temp_content);
2020         }
2021
2022         if (noti->tag) {
2023                 free(noti->tag);
2024         }
2025
2026         free(noti);
2027
2028         return NOTIFICATION_ERROR_NONE;
2029 }
2030
2031 EXPORT_API int notification_set_tag(notification_h noti, const char *tag)
2032 {
2033         /* Check noti is valid data */
2034         if (noti == NULL) {
2035                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2036         }
2037
2038         if (tag != NULL) {
2039                 /* save input TAG */
2040                 if (noti->tag != NULL) {
2041                         free(noti->tag);
2042                 }
2043                 noti->tag = strdup(tag);
2044         }
2045
2046         return NOTIFICATION_ERROR_NONE;
2047
2048 }
2049
2050 EXPORT_API int notification_get_tag(notification_h noti, const char **tag)
2051 {
2052         /* Check noti is valid data */
2053         if (noti == NULL) {
2054                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2055         }
2056
2057         *tag = noti->tag;
2058         return NOTIFICATION_ERROR_NONE;
2059 }
2060
2061 void notification_call_posted_toast_cb(const char *message)
2062 {
2063         if (posted_toast_message_cb != NULL) {
2064                 posted_toast_message_cb((void*)message);
2065         }
2066 }
2067
2068 EXPORT_API int notification_set_ongoing_flag(notification_h noti, bool ongoing_flag)
2069 {
2070         if (noti == NULL)
2071                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2072
2073         noti->ongoing_flag = ongoing_flag;
2074
2075         return NOTIFICATION_ERROR_NONE;
2076 }
2077
2078 EXPORT_API int notification_get_ongoing_flag(notification_h noti, bool *ongoing_flag)
2079 {
2080         if (noti == NULL || ongoing_flag == NULL)
2081                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2082
2083         *ongoing_flag = noti->ongoing_flag;
2084
2085         return NOTIFICATION_ERROR_NONE;
2086 }
2087
2088
2089 EXPORT_API int notification_add_button(notification_h noti, notification_button_index_e button_index)
2090 {
2091         if (noti == NULL || button_index < NOTIFICATION_BUTTON_1 || button_index > NOTIFICATION_BUTTON_6)
2092                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2093
2094         return NOTIFICATION_ERROR_NONE;
2095 }
2096
2097 EXPORT_API int notification_remove_button(notification_h noti, notification_button_index_e button_index)
2098 {
2099         if (noti == NULL || button_index < NOTIFICATION_BUTTON_1 || button_index > NOTIFICATION_BUTTON_6)
2100                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2101
2102         if (noti->b_event_handler[button_index - 1]) {
2103                 bundle_free(noti->b_event_handler[button_index - 1]);
2104                 noti->b_event_handler[button_index - 1] = NULL;
2105         }
2106
2107         return NOTIFICATION_ERROR_NONE;
2108 }
2109
2110 EXPORT_API int notification_set_auto_remove(notification_h noti, bool auto_remove)
2111 {
2112         if (noti == NULL)
2113                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2114
2115         noti->auto_remove = auto_remove;
2116
2117         return NOTIFICATION_ERROR_NONE;
2118 }
2119
2120 EXPORT_API int notification_get_auto_remove(notification_h noti, bool *auto_remove)
2121 {
2122         if (noti == NULL || auto_remove == NULL)
2123                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2124
2125         *auto_remove = noti->auto_remove;
2126
2127         return NOTIFICATION_ERROR_NONE;
2128 }