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