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