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