4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
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>
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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.
28 #include <sys/socket.h>
29 #include <sys/syscall.h>
33 #include <dbus/dbus.h>
34 #include <dbus/dbus-glib-lowlevel.h>
39 #include <vconf-keys.h>
42 #include <notification.h>
43 #include <notification_list.h>
44 #include <notification_debug.h>
45 #include <notification_internal.h>
46 #include <notification_noti.h>
47 #include <notification_ongoing.h>
48 #include <notification_group.h>
49 #include <notification_ipc.h>
51 typedef struct _notification_cb_list notification_cb_list_s;
53 typedef enum __notification_cb_type {
54 NOTIFICATION_CB_NORMAL = 1,
55 NOTIFICATION_CB_DETAILED,
56 } _notification_cb_type_e;
58 struct _notification_cb_list {
59 notification_cb_list_s *prev;
60 notification_cb_list_s *next;
62 _notification_cb_type_e cb_type;
63 void (*changed_cb) (void *data, notification_type_e type);
64 void (*detailed_changed_cb) (void *data, notification_type_e type, notification_op *op_list, int num_op);
68 static notification_cb_list_s *g_notification_cb_list = NULL;
70 #define NOTI_TEXT_RESULT_LEN 2048
71 #define NOTI_PKGNAME_LEN 512
73 static char *_notification_get_pkgname_by_pid(void)
75 char pkgname[NOTI_PKGNAME_LEN + 1] = { 0, };
76 int pid = 0, ret = AUL_R_OK;
82 ret = aul_app_get_pkgname_bypid(pid, pkgname, sizeof(pkgname));
83 if (ret != AUL_R_OK) {
84 char buf[NOTI_PKGNAME_LEN + 1] = { 0, };
86 snprintf(buf, sizeof(buf), "/proc/%d/cmdline", pid);
88 fd = open(buf, O_RDONLY);
93 ret = read(fd, pkgname, sizeof(pkgname) - 1);
103 * "ret" is not able to be larger than "sizeof(pkgname) - 1",
104 * if the system is not going wrong.
107 if (strlen(pkgname) <= 0) {
112 dup_pkgname = strdup(pkgname);
114 NOTIFICATION_ERR("Heap: %s\n", strerror(errno));
119 static void _notification_get_text_domain(notification_h noti)
121 if (noti->domain != NULL) {
125 if (noti->dir != NULL) {
130 EXPORT_API notification_error_e notification_set_image(notification_h noti,
131 notification_image_type_e type,
132 const char *image_path)
135 char buf_key[32] = { 0, };
136 const char *ret_val = NULL;
138 /* Check noti and image_path are valid data */
139 if (noti == NULL || image_path == NULL) {
140 return NOTIFICATION_ERROR_INVALID_DATA;
143 /* Check image type is valid type */
144 if (type <= NOTIFICATION_IMAGE_TYPE_NONE
145 || type >= NOTIFICATION_IMAGE_TYPE_MAX) {
146 return NOTIFICATION_ERROR_INVALID_DATA;
149 /* Check image path bundle is exist */
150 if (noti->b_image_path) {
151 /* If image path bundle is exist, store local bundle value */
152 b = noti->b_image_path;
154 /* Set image type to key as char string type */
155 snprintf(buf_key, sizeof(buf_key), "%d", type);
157 /* Get value using key */
158 ret_val = bundle_get_val(b, buf_key);
159 if (ret_val != NULL) {
160 /* If key is exist, remove this value to store new image path */
161 bundle_del(b, buf_key);
164 /* Add new image path with type key */
165 bundle_add(b, buf_key, image_path);
167 /* If image path bundle is not exist, create new one */
170 /* Set image type to key as char string type */
171 snprintf(buf_key, sizeof(buf_key), "%d", type);
173 /* Add new image path with type key */
174 bundle_add(b, buf_key, image_path);
176 /* Save to image path bundle */
177 noti->b_image_path = b;
180 return NOTIFICATION_ERROR_NONE;
183 EXPORT_API notification_error_e notification_get_image(notification_h noti,
184 notification_image_type_e type,
188 char buf_key[32] = { 0, };
189 const char *ret_val = NULL;
191 /* Check noti and image_path is valid data */
192 if (noti == NULL || image_path == NULL) {
193 return NOTIFICATION_ERROR_INVALID_DATA;
196 /* Check image type is valid data */
197 if (type <= NOTIFICATION_IMAGE_TYPE_NONE
198 || type >= NOTIFICATION_IMAGE_TYPE_MAX) {
199 return NOTIFICATION_ERROR_INVALID_DATA;
202 /* Check image path bundle exist */
203 if (noti->b_image_path) {
204 /* If image path bundle exist, store local bundle data */
205 b = noti->b_image_path;
207 /* Set image type to key as char string type */
208 snprintf(buf_key, sizeof(buf_key), "%d", type);
210 /* Get value of key */
211 ret_val = bundle_get_val(b, buf_key);
213 *image_path = (char *)ret_val;
215 /* If image path bundle does not exist, image path is NULL */
219 /* If image path is NULL and type is ICON, icon path set from AIL */
220 /* order : user icon -> launch_pkgname icon -> caller_pkgname icon -> service app icon */
221 if (*image_path == NULL && type == NOTIFICATION_IMAGE_TYPE_ICON) {
222 /* Check App icon path is already set */
223 if (noti->app_icon_path != NULL) {
224 /* image path will be app icon path */
225 *image_path = noti->app_icon_path;
231 return NOTIFICATION_ERROR_NONE;
234 EXPORT_API notification_error_e notification_set_time(notification_h noti,
237 /* Check noti is valid data */
239 return NOTIFICATION_ERROR_INVALID_DATA;
242 if (input_time == 0) {
243 /* If input time is 0, set current time */
244 noti->time = time(NULL);
246 /* save input time */
247 noti->time = input_time;
250 return NOTIFICATION_ERROR_NONE;
253 EXPORT_API notification_error_e notification_get_time(notification_h noti,
256 /* Check noti and time is valid data */
257 if (noti == NULL || ret_time == NULL) {
258 return NOTIFICATION_ERROR_INVALID_DATA;
261 /* Set time infomation */
262 *ret_time = noti->time;
264 return NOTIFICATION_ERROR_NONE;
267 EXPORT_API notification_error_e notification_get_insert_time(notification_h noti,
270 /* Check noti and ret_time is valid data */
271 if (noti == NULL || ret_time == NULL) {
272 return NOTIFICATION_ERROR_INVALID_DATA;
275 /* Set insert time information */
276 *ret_time = noti->insert_time;
278 return NOTIFICATION_ERROR_NONE;
281 EXPORT_API notification_error_e notification_set_text(notification_h noti,
282 notification_text_type_e type,
288 char buf_key[32] = { 0, };
289 char buf_val[1024] = { 0, };
290 const char *ret_val = NULL;
292 notification_variable_type_e var_type;
294 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
295 int var_value_int = 0;
296 double var_value_double = 0.0;
297 char *var_value_string = NULL;
298 notification_count_pos_type_e var_value_count =
299 NOTIFICATION_COUNT_POS_NONE;
301 /* Check noti is valid data */
303 return NOTIFICATION_ERROR_INVALID_DATA;
306 /* Check text type is valid type */
307 if (type <= NOTIFICATION_TEXT_TYPE_NONE
308 || type >= NOTIFICATION_TEXT_TYPE_MAX) {
309 return NOTIFICATION_ERROR_INVALID_DATA;
312 /* Check text bundle exist */
314 if (noti->b_text != NULL) {
315 /* If text bundle exist, store local bundle data */
318 /* Make type to key as char string */
319 snprintf(buf_key, sizeof(buf_key), "%d", type);
321 /* Get value using type key */
322 ret_val = bundle_get_val(b, buf_key);
323 if (ret_val != NULL) {
324 /* If value exist, remove this to add new value */
325 bundle_del(b, buf_key);
328 snprintf(buf_val, sizeof(buf_val), "%s", text);
330 /* Add new text value */
331 bundle_add(b, buf_key, buf_val);
333 /* If text bundle does not exist, create new one */
336 /* Make type to key as char string */
337 snprintf(buf_key, sizeof(buf_key), "%d", type);
339 snprintf(buf_val, sizeof(buf_val), "%s", text);
341 /* Add new text value */
342 bundle_add(b, buf_key, buf_val);
344 /* Save text bundle */
348 /* Reset if text is NULL */
349 if (noti->b_text != NULL) {
350 /* If text bundle exist, store local bundle data */
353 /* Make type to key as char string */
354 snprintf(buf_key, sizeof(buf_key), "%d", type);
356 /* Get value using type key */
357 ret_val = bundle_get_val(b, buf_key);
358 if (ret_val != NULL) {
359 /* If value exist, remove this */
360 bundle_del(b, buf_key);
365 /* Save key if key is valid data */
367 /* Check key bundle exist */
368 if (noti->b_key != NULL) {
369 /* If key bundle exist, store local bundle data */
372 /* Make type to key as char string */
373 snprintf(buf_key, sizeof(buf_key), "%d", type);
375 /* Get value using type key */
376 ret_val = bundle_get_val(b, buf_key);
377 if (ret_val != NULL) {
378 /* If value exist, remove this to add new value */
379 bundle_del(b, buf_key);
382 snprintf(buf_val, sizeof(buf_val), "%s", key);
384 /* Add new key value */
385 bundle_add(b, buf_key, buf_val);
387 /* If key bundle does not exist, create new one */
390 /* Make type to key as char string */
391 snprintf(buf_key, sizeof(buf_key), "%d", type);
393 snprintf(buf_val, sizeof(buf_val), "%s", key);
395 /* Add new key value */
396 bundle_add(b, buf_key, buf_val);
398 /* Save key bundle */
402 /* Reset if key is NULL */
403 if (noti->b_key != NULL) {
404 /* If key bundle exist, store local bundle data */
407 /* Make type to key as char string */
408 snprintf(buf_key, sizeof(buf_key), "%d", type);
410 /* Get value using type key */
411 ret_val = bundle_get_val(b, buf_key);
412 if (ret_val != NULL) {
413 /* If value exist, remove this */
414 bundle_del(b, buf_key);
419 if (noti->b_format_args != NULL) {
420 b = noti->b_format_args;
425 va_start(var_args, args_type);
427 var_type = args_type;
430 while (var_type != NOTIFICATION_VARIABLE_TYPE_NONE) {
432 snprintf(buf_key, sizeof(buf_key), "%dtype%d", type, num_args);
433 snprintf(buf_val, sizeof(buf_val), "%d", var_type);
435 ret_val = bundle_get_val(b, buf_key);
436 if (ret_val != NULL) {
437 bundle_del(b, buf_key);
440 bundle_add(b, buf_key, buf_val);
443 case NOTIFICATION_VARIABLE_TYPE_INT:
444 var_value_int = va_arg(var_args, int);
447 snprintf(buf_key, sizeof(buf_key), "%dvalue%d", type,
449 snprintf(buf_val, sizeof(buf_val), "%d", var_value_int);
451 ret_val = bundle_get_val(b, buf_key);
452 if (ret_val != NULL) {
453 bundle_del(b, buf_key);
456 bundle_add(b, buf_key, buf_val);
458 case NOTIFICATION_VARIABLE_TYPE_DOUBLE:
459 var_value_double = va_arg(var_args, double);
462 snprintf(buf_key, sizeof(buf_key), "%dvalue%d", type,
464 snprintf(buf_val, sizeof(buf_val), "%.2f",
467 ret_val = bundle_get_val(b, buf_key);
468 if (ret_val != NULL) {
469 bundle_del(b, buf_key);
472 bundle_add(b, buf_key, buf_val);
474 case NOTIFICATION_VARIABLE_TYPE_STRING:
475 var_value_string = va_arg(var_args, char *);
478 snprintf(buf_key, sizeof(buf_key), "%dvalue%d", type,
480 snprintf(buf_val, sizeof(buf_val), "%s",
483 ret_val = bundle_get_val(b, buf_key);
484 if (ret_val != NULL) {
485 bundle_del(b, buf_key);
488 bundle_add(b, buf_key, buf_val);
490 case NOTIFICATION_VARIABLE_TYPE_COUNT:
492 va_arg(var_args, notification_count_pos_type_e);
495 snprintf(buf_key, sizeof(buf_key), "%dvalue%d", type,
497 snprintf(buf_val, sizeof(buf_val), "%d",
500 ret_val = bundle_get_val(b, buf_key);
501 if (ret_val != NULL) {
502 bundle_del(b, buf_key);
505 bundle_add(b, buf_key, buf_val);
508 NOTIFICATION_ERR("Error. invalid variable type. : %d",
510 noti_err = NOTIFICATION_ERROR_INVALID_DATA;
515 var_type = va_arg(var_args, notification_variable_type_e);
519 if (noti_err == NOTIFICATION_ERROR_NONE) {
520 noti->num_format_args = num_args;
522 noti->num_format_args = 0;
525 snprintf(buf_key, sizeof(buf_key), "num%d", type);
526 snprintf(buf_val, sizeof(buf_val), "%d", noti->num_format_args);
528 ret_val = bundle_get_val(b, buf_key);
529 if (ret_val != NULL) {
530 bundle_del(b, buf_key);
533 bundle_add(b, buf_key, buf_val);
535 noti->b_format_args = b;
540 EXPORT_API notification_error_e notification_get_text(notification_h noti,
541 notification_text_type_e type,
545 char buf_key[32] = { 0, };
546 const char *ret_val = NULL;
547 const char *get_str = NULL;
548 const char *get_check_type_str = NULL;
549 notification_text_type_e check_type = NOTIFICATION_TEXT_TYPE_NONE;
550 int display_option_flag = 0;
552 char *temp_str = NULL;
553 char result_str[NOTI_TEXT_RESULT_LEN] = { 0, };
554 char buf_str[1024] = { 0, };
556 notification_variable_type_e ret_var_type = 0;
557 int ret_variable_int = 0;
558 double ret_variable_double = 0.0;
560 /* Check noti is valid data */
561 if (noti == NULL || text == NULL) {
562 return NOTIFICATION_ERROR_INVALID_DATA;
565 /* Check text type is valid type */
566 if (type <= NOTIFICATION_TEXT_TYPE_NONE
567 || type >= NOTIFICATION_TEXT_TYPE_MAX) {
568 return NOTIFICATION_ERROR_INVALID_DATA;
572 if (noti->b_key != NULL) {
575 /* Get text domain and dir */
576 _notification_get_text_domain(noti);
578 snprintf(buf_key, sizeof(buf_key), "%d", type);
580 ret_val = bundle_get_val(b, buf_key);
581 if (ret_val != NULL && noti->domain != NULL
582 && noti->dir != NULL) {
583 /* Get application string */
584 bindtextdomain(noti->domain, noti->dir);
586 get_str = dgettext(noti->domain, ret_val);
587 } else if (ret_val != NULL) {
588 /* Get system string */
589 get_str = dgettext("sys_string", ret_val);
595 if (get_str == NULL && noti->b_text != NULL) {
598 snprintf(buf_key, sizeof(buf_key), "%d", type);
600 get_str = bundle_get_val(b, buf_key);
605 /* Set display option is off type when option is off, type is noti */
606 if (get_str != NULL && display_option_flag == 1
607 && noti->type == NOTIFICATION_TYPE_NOTI) {
608 if (type == NOTIFICATION_TEXT_TYPE_CONTENT
609 || type == NOTIFICATION_TEXT_TYPE_GROUP_CONTENT) {
610 /* Set check_type to option content string */
611 if (type == NOTIFICATION_TEXT_TYPE_CONTENT) {
613 NOTIFICATION_TEXT_TYPE_CONTENT_FOR_DISPLAY_OPTION_IS_OFF;
614 } else if (type == NOTIFICATION_TEXT_TYPE_GROUP_CONTENT) {
616 NOTIFICATION_TEXT_TYPE_GROUP_CONTENT_FOR_DISPLAY_OPTION_IS_OFF;
620 if (noti->b_key != NULL) {
623 /* Get text domain and dir */
624 _notification_get_text_domain(noti);
626 snprintf(buf_key, sizeof(buf_key), "%d",
629 ret_val = bundle_get_val(b, buf_key);
630 if (ret_val != NULL && noti->domain != NULL
631 && noti->dir != NULL) {
632 /* Get application string */
633 bindtextdomain(noti->domain, noti->dir);
636 dgettext(noti->domain, ret_val);
637 } else if (ret_val != NULL) {
638 /* Get system string */
640 dgettext("sys_string", ret_val);
642 get_check_type_str = NULL;
646 if (get_check_type_str == NULL && noti->b_text != NULL) {
649 snprintf(buf_key, sizeof(buf_key), "%d",
652 get_check_type_str = bundle_get_val(b, buf_key);
656 if (get_check_type_str != NULL) {
657 /* Replace option off type string */
658 get_str = get_check_type_str;
660 /* Set default string */
662 dgettext("sys_string", "IDS_COM_POP_MISSED_EVENT");
666 if (get_str != NULL) {
667 /* Get number format args */
668 b = noti->b_format_args;
669 noti->num_format_args = 0;
672 snprintf(buf_key, sizeof(buf_key), "num%d", check_type);
673 ret_val = bundle_get_val(b, buf_key);
674 if (ret_val != NULL) {
675 noti->num_format_args = atoi(ret_val);
679 if (noti->num_format_args == 0) {
680 *text = (char *)get_str;
682 /* Check first variable is count, LEFT pos */
683 snprintf(buf_key, sizeof(buf_key), "%dtype%d",
684 check_type, num_args);
685 ret_val = bundle_get_val(b, buf_key);
686 ret_var_type = atoi(ret_val);
688 if (ret_var_type == NOTIFICATION_VARIABLE_TYPE_COUNT) {
690 snprintf(buf_key, sizeof(buf_key), "%dvalue%d",
691 check_type, num_args);
692 ret_val = bundle_get_val(b, buf_key);
693 ret_variable_int = atoi(ret_val);
695 if (ret_variable_int ==
696 NOTIFICATION_COUNT_POS_LEFT) {
697 notification_noti_get_count(noti->type,
698 noti->caller_pkgname,
702 snprintf(buf_str, sizeof(buf_str),
703 "%d ", ret_variable_int);
705 int src_len = strlen(result_str);
706 int max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
708 strncat(result_str, buf_str,
716 /* Check variable IN pos */
717 for (temp_str = (char *)get_str; *temp_str != '\0';
719 if (*temp_str != '%') {
720 strncat(result_str, temp_str, 1);
722 if (*(temp_str + 1) == '%') {
723 strncat(result_str, temp_str,
725 } else if (*(temp_str + 1) == 'd') {
727 ret_variable_int = 0;
731 "%dtype%d", check_type,
734 bundle_get_val(b, buf_key);
735 ret_var_type = atoi(ret_val);
737 NOTIFICATION_VARIABLE_TYPE_COUNT)
739 /* Get notification count */
740 notification_noti_get_count
742 noti->caller_pkgname,
762 sizeof(buf_str), "%d",
765 int src_len = strlen(result_str);
766 int max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
768 strncat(result_str, buf_str,
774 } else if (*(temp_str + 1) == 's') {
779 check_type, num_args);
781 bundle_get_val(b, buf_key);
784 sizeof(buf_str), "%s",
787 int src_len = strlen(result_str);
788 int max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
790 strncat(result_str, buf_str,
796 } else if (*(temp_str + 1) == 'f') {
801 check_type, num_args);
803 bundle_get_val(b, buf_key);
804 ret_variable_double =
810 ret_variable_double);
812 int src_len = strlen(result_str);
813 int max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
815 strncat(result_str, buf_str,
826 /* Check last variable is count, LEFT pos */
827 if (num_args < noti->num_format_args) {
828 snprintf(buf_key, sizeof(buf_key), "%dtype%d",
829 check_type, num_args);
830 ret_val = bundle_get_val(b, buf_key);
831 ret_var_type = atoi(ret_val);
833 NOTIFICATION_VARIABLE_TYPE_COUNT) {
835 snprintf(buf_key, sizeof(buf_key),
836 "%dvalue%d", check_type,
838 ret_val = bundle_get_val(b, buf_key);
839 ret_variable_int = atoi(ret_val);
841 if (ret_variable_int ==
842 NOTIFICATION_COUNT_POS_RIGHT) {
843 notification_noti_get_count
845 noti->caller_pkgname,
850 sizeof(buf_str), " %d",
853 int src_len = strlen(result_str);
854 int max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
856 strncat(result_str, buf_str,
865 switch (check_type) {
866 case NOTIFICATION_TEXT_TYPE_TITLE:
867 case NOTIFICATION_TEXT_TYPE_GROUP_TITLE:
868 if (noti->temp_title != NULL)
869 free(noti->temp_title);
871 noti->temp_title = strdup(result_str);
873 *text = noti->temp_title;
875 case NOTIFICATION_TEXT_TYPE_CONTENT:
876 case NOTIFICATION_TEXT_TYPE_CONTENT_FOR_DISPLAY_OPTION_IS_OFF:
877 case NOTIFICATION_TEXT_TYPE_GROUP_CONTENT:
878 case NOTIFICATION_TEXT_TYPE_GROUP_CONTENT_FOR_DISPLAY_OPTION_IS_OFF:
879 if (noti->temp_content !=
881 free(noti->temp_content);
883 noti->temp_content = strdup(result_str);
885 *text = noti->temp_content;
897 return NOTIFICATION_ERROR_NONE;
900 EXPORT_API notification_error_e notification_set_text_domain(notification_h noti,
904 /* check noti and domain is valid data */
905 if (noti == NULL || domain == NULL) {
906 return NOTIFICATION_ERROR_INVALID_DATA;
911 /* Remove previous domain */
915 noti->domain = strdup(domain);
917 /* Check locale dir */
919 /* Remove previous locale dir */
922 /* Copy locale dir */
923 noti->dir = strdup(dir);
925 return NOTIFICATION_ERROR_NONE;
928 EXPORT_API notification_error_e notification_get_text_domain(notification_h noti,
932 /* Check noti is valid data */
934 return NOTIFICATION_ERROR_INVALID_DATA;
938 if (domain != NULL && noti->domain != NULL) {
939 *domain = noti->domain;
943 if (dir != NULL && noti->dir != NULL) {
947 return NOTIFICATION_ERROR_NONE;
950 EXPORT_API notification_error_e notification_set_time_to_text(notification_h noti, notification_text_type_e type,
953 notification_error_e ret = NOTIFICATION_ERROR_NONE;
954 char buf[256] = { 0, };
955 char buf_tag[512] = { 0, };
958 return NOTIFICATION_ERROR_INVALID_DATA;
961 return NOTIFICATION_ERROR_INVALID_DATA;
964 snprintf(buf, sizeof(buf), "%lu", time);
965 ret = notification_noti_set_tag(TAG_TIME, buf, buf_tag, sizeof(buf_tag));
967 if (ret != NOTIFICATION_ERROR_NONE) {
971 return notification_set_text(noti, type, buf_tag, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
974 EXPORT_API notification_error_e notification_get_time_from_text(notification_h noti, notification_text_type_e type,
977 notification_error_e ret = NOTIFICATION_ERROR_NONE;
980 return NOTIFICATION_ERROR_INVALID_DATA;
983 return NOTIFICATION_ERROR_INVALID_DATA;
986 char *ret_text = NULL;
987 ret = notification_get_text(noti, type, &ret_text);
989 if (ret != NOTIFICATION_ERROR_NONE || ret_text == NULL) {
990 return NOTIFICATION_ERROR_INVALID_DATA;
993 if (notification_noti_get_tag_type(ret_text) == TAG_TYPE_INVALID) {
994 return NOTIFICATION_ERROR_INVALID_DATA;
997 char *tag_value = NULL;
998 tag_value = notification_noti_strip_tag(ret_text);
999 if (tag_value == NULL) {
1000 return NOTIFICATION_ERROR_INVALID_DATA;
1003 *time = atol(tag_value);
1006 return NOTIFICATION_ERROR_NONE;
1009 EXPORT_API notification_error_e notification_set_sound(notification_h noti,
1010 notification_sound_type_e type,
1013 /* Check noti is valid data */
1015 return NOTIFICATION_ERROR_INVALID_DATA;
1018 /* Check type is valid */
1019 if (type < NOTIFICATION_SOUND_TYPE_NONE
1020 || type >= NOTIFICATION_SOUND_TYPE_MAX) {
1021 return NOTIFICATION_ERROR_INVALID_DATA;
1024 /* Save sound type */
1025 noti->sound_type = type;
1027 /* Save sound path if user data type */
1028 if (type == NOTIFICATION_SOUND_TYPE_USER_DATA && path != NULL) {
1029 if (noti->sound_path != NULL) {
1030 free(noti->sound_path);
1033 noti->sound_path = strdup(path);
1035 if (noti->sound_path != NULL) {
1036 free(noti->sound_path);
1037 noti->sound_path = NULL;
1041 return NOTIFICATION_ERROR_NONE;
1044 EXPORT_API notification_error_e notification_get_sound(notification_h noti,
1045 notification_sound_type_e *type,
1048 /* check noti and type is valid data */
1049 if (noti == NULL || type == NULL) {
1050 return NOTIFICATION_ERROR_INVALID_DATA;
1053 /* Set sound type */
1054 *type = noti->sound_type;
1056 /* Set sound path if user data type */
1057 if (noti->sound_type == NOTIFICATION_SOUND_TYPE_USER_DATA
1059 *path = noti->sound_path;
1062 return NOTIFICATION_ERROR_NONE;
1065 EXPORT_API notification_error_e notification_set_vibration(notification_h noti,
1066 notification_vibration_type_e type,
1069 /* Check noti is valid data */
1071 return NOTIFICATION_ERROR_INVALID_DATA;
1074 /* Check type is valid */
1075 if (type < NOTIFICATION_VIBRATION_TYPE_NONE
1076 || type >= NOTIFICATION_VIBRATION_TYPE_MAX) {
1077 return NOTIFICATION_ERROR_INVALID_DATA;
1080 /* Save vibration type */
1081 noti->vibration_type = type;
1083 /* Save sound path if user data type */
1084 if (type == NOTIFICATION_VIBRATION_TYPE_USER_DATA && path != NULL) {
1085 if (noti->vibration_path != NULL) {
1086 free(noti->vibration_path);
1089 noti->vibration_path = strdup(path);
1091 if (noti->vibration_path != NULL) {
1092 free(noti->vibration_path);
1093 noti->vibration_path = NULL;
1097 return NOTIFICATION_ERROR_NONE;
1101 EXPORT_API notification_error_e notification_get_vibration(notification_h noti,
1102 notification_vibration_type_e *type,
1105 /* check noti and type is valid data */
1106 if (noti == NULL || type == NULL) {
1107 return NOTIFICATION_ERROR_INVALID_DATA;
1110 /* Set vibration type */
1111 *type = noti->vibration_type;
1113 /* Set sound path if user data type */
1114 if (noti->vibration_type == NOTIFICATION_VIBRATION_TYPE_USER_DATA
1116 *path = noti->vibration_path;
1119 return NOTIFICATION_ERROR_NONE;
1122 EXPORT_API notification_error_e notification_set_led(notification_h noti,
1123 notification_led_op_e operation,
1126 /* Check noti is valid data */
1128 return NOTIFICATION_ERROR_INVALID_DATA;
1131 /* Check operation is valid */
1132 if (operation < NOTIFICATION_LED_OP_OFF
1133 || operation >= NOTIFICATION_LED_OP_MAX) {
1134 return NOTIFICATION_ERROR_INVALID_DATA;
1137 /* Save led operation */
1138 noti->led_operation = operation;
1140 /* Save led argb if operation is turning on LED with custom color */
1141 if (operation == NOTIFICATION_LED_OP_ON_CUSTOM_COLOR) {
1142 noti->led_argb = led_argb;
1145 return NOTIFICATION_ERROR_NONE;
1148 EXPORT_API notification_error_e notification_get_led(notification_h noti,
1149 notification_led_op_e *operation,
1152 /* check noti and operation is valid data */
1153 if (noti == NULL || operation == NULL) {
1154 return NOTIFICATION_ERROR_INVALID_DATA;
1157 /* Set led operation */
1158 *operation = noti->led_operation;
1160 /* Save led argb if operation is turning on LED with custom color */
1161 if (noti->led_operation == NOTIFICATION_LED_OP_ON_CUSTOM_COLOR
1162 && led_argb != NULL) {
1163 *led_argb = noti->led_argb;
1166 return NOTIFICATION_ERROR_NONE;
1169 EXPORT_API notification_error_e notification_set_led_time_period(notification_h noti,
1170 int on_ms, int off_ms)
1172 /* Check noti is valid data */
1174 return NOTIFICATION_ERROR_INVALID_DATA;
1177 /* Save led operation */
1178 noti->led_on_ms = on_ms;
1179 noti->led_off_ms = off_ms;
1181 return NOTIFICATION_ERROR_NONE;
1184 EXPORT_API notification_error_e notification_get_led_time_period(notification_h noti,
1185 int *on_ms, int *off_ms)
1187 /* check noti and operation is valid data */
1189 return NOTIFICATION_ERROR_INVALID_DATA;
1193 *(on_ms) = noti->led_on_ms;
1195 *(off_ms) = noti->led_off_ms;
1197 return NOTIFICATION_ERROR_NONE;
1200 EXPORT_API notification_error_e notification_set_application(notification_h noti,
1201 const char *pkgname)
1203 if (noti == NULL || pkgname == NULL) {
1204 return NOTIFICATION_ERROR_INVALID_DATA;
1207 if (noti->launch_pkgname) {
1208 free(noti->launch_pkgname);
1211 noti->launch_pkgname = strdup(pkgname);
1213 return NOTIFICATION_ERROR_NONE;
1216 EXPORT_API notification_error_e notification_get_application(notification_h noti,
1219 if (noti == NULL || pkgname == NULL) {
1220 return NOTIFICATION_ERROR_INVALID_DATA;
1223 if (noti->launch_pkgname) {
1224 *pkgname = noti->launch_pkgname;
1226 *pkgname = noti->caller_pkgname;
1229 return NOTIFICATION_ERROR_NONE;
1232 EXPORT_API notification_error_e notification_set_execute_option(notification_h noti,
1233 notification_execute_type_e type,
1236 bundle *service_handle)
1238 char buf_key[32] = { 0, };
1239 const char *ret_val = NULL;
1243 return NOTIFICATION_ERROR_INVALID_DATA;
1246 if (type <= NOTIFICATION_EXECUTE_TYPE_NONE
1247 || type >= NOTIFICATION_EXECUTE_TYPE_MAX) {
1248 return NOTIFICATION_ERROR_INVALID_DATA;
1251 /* Create execute option bundle if does not exist */
1252 if (noti->b_execute_option != NULL) {
1253 noti->b_execute_option = bundle_create();
1256 b = noti->b_execute_option;
1261 snprintf(buf_key, sizeof(buf_key), "text%d", type);
1263 /* Check text key exist */
1264 ret_val = bundle_get_val(b, buf_key);
1265 if (ret_val != NULL) {
1266 /* Remove previous data */
1267 bundle_del(b, buf_key);
1271 bundle_add(b, buf_key, text);
1277 snprintf(buf_key, sizeof(buf_key), "key%d", type);
1279 /* Check key key exist */
1280 ret_val = bundle_get_val(b, buf_key);
1281 if (ret_val != NULL) {
1282 /* Remove previous data */
1283 bundle_del(b, buf_key);
1287 bundle_add(b, buf_key, key);
1290 switch ((int)type) {
1291 case NOTIFICATION_EXECUTE_TYPE_RESPONDING:
1292 /* Remove previous data if exist */
1293 if (noti->b_service_responding != NULL) {
1294 bundle_free(noti->b_service_responding);
1295 noti->b_service_responding = NULL;
1298 /* Save service handle */
1299 if (service_handle != NULL) {
1300 noti->b_service_responding = bundle_dup(service_handle);
1303 case NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH:
1304 /* Remove previous data if exist */
1305 if (noti->b_service_single_launch != NULL) {
1306 bundle_free(noti->b_service_single_launch);
1307 noti->b_service_single_launch = NULL;
1310 /* Save service handle */
1311 if (service_handle != NULL) {
1312 noti->b_service_single_launch =
1313 bundle_dup(service_handle);
1316 case NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH:
1317 /* Remove previous data if exist */
1318 if (noti->b_service_multi_launch != NULL) {
1319 bundle_free(noti->b_service_multi_launch);
1320 noti->b_service_multi_launch = NULL;
1323 /* Save service handle */
1324 if (service_handle != NULL) {
1325 noti->b_service_multi_launch =
1326 bundle_dup(service_handle);
1331 return NOTIFICATION_ERROR_NONE;
1334 EXPORT_API notification_error_e notification_get_execute_option(notification_h noti,
1335 notification_execute_type_e type,
1337 bundle **service_handle)
1339 char buf_key[32] = { 0, };
1340 const char *ret_val = NULL;
1341 char *get_str = NULL;
1345 return NOTIFICATION_ERROR_INVALID_DATA;
1348 if (type <= NOTIFICATION_EXECUTE_TYPE_NONE
1349 || type >= NOTIFICATION_EXECUTE_TYPE_MAX) {
1350 return NOTIFICATION_ERROR_INVALID_DATA;
1354 case NOTIFICATION_EXECUTE_TYPE_RESPONDING:
1355 b = noti->b_service_responding;
1357 case NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH:
1358 b = noti->b_service_single_launch;
1360 case NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH:
1361 b = noti->b_service_multi_launch;
1371 // Get text domain and dir
1372 if (noti->domain == NULL || noti->dir == NULL) {
1373 _notification_get_text_domain(noti);
1377 snprintf(buf_key, sizeof(buf_key), "key%d", type);
1379 /* Check key key exist */
1380 ret_val = bundle_get_val(b, buf_key);
1381 if (ret_val != NULL && noti->domain != NULL
1382 && noti->dir != NULL) {
1383 /* Get application string */
1384 bindtextdomain(noti->domain, noti->dir);
1386 get_str = dgettext(noti->domain, ret_val);
1389 } else if (ret_val != NULL) {
1390 /* Get system string */
1391 get_str = dgettext("sys_string", ret_val);
1395 /* Get basic text */
1396 snprintf(buf_key, sizeof(buf_key), "text%d",
1399 ret_val = bundle_get_val(b, buf_key);
1407 case NOTIFICATION_EXECUTE_TYPE_RESPONDING:
1408 b = noti->b_service_responding;
1410 case NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH:
1411 b = noti->b_service_single_launch;
1413 case NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH:
1414 b = noti->b_service_multi_launch;
1421 if (service_handle != NULL) {
1422 *service_handle = b;
1425 return NOTIFICATION_ERROR_NONE;
1428 EXPORT_API notification_error_e notification_set_property(notification_h noti,
1431 /* Check noti is valid data */
1433 return NOTIFICATION_ERROR_INVALID_DATA;
1437 noti->flags_for_property = flags;
1439 return NOTIFICATION_ERROR_NONE;
1442 EXPORT_API notification_error_e notification_get_property(notification_h noti,
1445 /* Check noti and flags are valid data */
1446 if (noti == NULL || flags == NULL) {
1447 return NOTIFICATION_ERROR_INVALID_DATA;
1451 *flags = noti->flags_for_property;
1453 return NOTIFICATION_ERROR_NONE;
1456 EXPORT_API notification_error_e notification_set_display_applist(notification_h noti,
1459 /* Check noti is valid data */
1461 return NOTIFICATION_ERROR_INVALID_DATA;
1465 noti->display_applist = applist;
1467 return NOTIFICATION_ERROR_NONE;
1470 EXPORT_API notification_error_e notification_get_display_applist(notification_h noti,
1473 /* Check noti and applist are valid data */
1474 if (noti == NULL || applist == NULL) {
1475 return NOTIFICATION_ERROR_INVALID_DATA;
1479 *applist = noti->display_applist;
1481 return NOTIFICATION_ERROR_NONE;
1484 EXPORT_API notification_error_e notification_set_size(notification_h noti,
1487 /* Check noti is valid data */
1489 return NOTIFICATION_ERROR_INVALID_DATA;
1492 /* Save progress size */
1493 noti->progress_size = size;
1495 return NOTIFICATION_ERROR_NONE;
1498 EXPORT_API notification_error_e notification_get_size(notification_h noti,
1501 /* Check noti and size is valid data */
1502 if (noti == NULL || size == NULL) {
1503 return NOTIFICATION_ERROR_INVALID_DATA;
1506 /* Set progress size */
1507 *size = noti->progress_size;
1509 return NOTIFICATION_ERROR_NONE;
1512 EXPORT_API notification_error_e notification_set_progress(notification_h noti,
1515 /* Check noti is valid data */
1517 return NOTIFICATION_ERROR_INVALID_DATA;
1520 /* Save progress percentage */
1521 noti->progress_percentage = percentage;
1523 return NOTIFICATION_ERROR_NONE;
1526 EXPORT_API notification_error_e notification_get_progress(notification_h noti,
1529 /* Check noti and percentage are valid data */
1530 if (noti == NULL || percentage == NULL) {
1531 return NOTIFICATION_ERROR_INVALID_DATA;
1534 /* Set progress percentage */
1535 *percentage = noti->progress_percentage;
1537 return NOTIFICATION_ERROR_NONE;
1540 EXPORT_API notification_error_e notification_set_pkgname(notification_h noti,
1541 const char *pkgname)
1543 /* check noti and pkgname are valid data */
1544 if (noti == NULL || pkgname == NULL) {
1545 return NOTIFICATION_ERROR_INVALID_DATA;
1548 /* Remove previous caller pkgname */
1549 if (noti->caller_pkgname) {
1550 free(noti->caller_pkgname);
1551 noti->caller_pkgname = NULL;
1554 noti->caller_pkgname = strdup(pkgname);
1556 return NOTIFICATION_ERROR_NONE;
1559 EXPORT_API notification_error_e notification_get_pkgname(notification_h noti,
1562 /* Check noti and pkgname are valid data */
1563 if (noti == NULL || pkgname == NULL) {
1564 return NOTIFICATION_ERROR_INVALID_DATA;
1567 /* Get caller pkgname */
1568 if (noti->caller_pkgname) {
1569 *pkgname = noti->caller_pkgname;
1574 return NOTIFICATION_ERROR_NONE;
1577 EXPORT_API notification_error_e notification_set_layout(notification_h noti,
1578 notification_ly_type_e layout)
1580 /* check noti and pkgname are valid data */
1581 if (noti == NULL || (layout < NOTIFICATION_LY_NONE || layout >= NOTIFICATION_LY_MAX)) {
1582 return NOTIFICATION_ERROR_INVALID_DATA;
1585 noti->layout = layout;
1587 return NOTIFICATION_ERROR_NONE;
1590 EXPORT_API notification_error_e notification_get_layout(notification_h noti,
1591 notification_ly_type_e *layout)
1593 /* Check noti and pkgname are valid data */
1594 if (noti == NULL || layout == NULL) {
1595 return NOTIFICATION_ERROR_INVALID_DATA;
1598 *layout = noti->layout;
1600 return NOTIFICATION_ERROR_NONE;
1603 EXPORT_API notification_error_e notification_get_id(notification_h noti,
1604 int *group_id, int *priv_id)
1606 /* check noti is valid data */
1608 return NOTIFICATION_ERROR_INVALID_DATA;
1611 /* Check group_id is valid data */
1614 if (noti->group_id < NOTIFICATION_GROUP_ID_NONE) {
1615 *group_id = NOTIFICATION_GROUP_ID_NONE;
1617 *group_id = noti->group_id;
1621 /* Check priv_id is valid data */
1624 *priv_id = noti->priv_id;
1627 return NOTIFICATION_ERROR_NONE;
1630 EXPORT_API notification_error_e notification_get_type(notification_h noti,
1631 notification_type_e *type)
1633 /* Check noti and type is valid data */
1634 if (noti == NULL || type == NULL) {
1635 return NOTIFICATION_ERROR_INVALID_DATA;
1641 return NOTIFICATION_ERROR_NONE;
1644 EXPORT_API notification_error_e notification_insert(notification_h noti,
1650 /* Check noti is vaild data */
1652 return NOTIFICATION_ERROR_INVALID_DATA;
1655 /* Check noti type is valid type */
1656 if (noti->type <= NOTIFICATION_TYPE_NONE
1657 || noti->type >= NOTIFICATION_TYPE_MAX) {
1658 return NOTIFICATION_ERROR_INVALID_DATA;
1661 /* Save insert time */
1662 noti->insert_time = time(NULL);
1663 ret = notification_ipc_request_insert(noti, &id);
1664 if (ret != NOTIFICATION_ERROR_NONE) {
1668 NOTIFICATION_DBG("from master:%d", id);
1670 /* If priv_id is valid data, set priv_id */
1671 if (priv_id != NULL) {
1672 *priv_id = noti->priv_id;
1675 return NOTIFICATION_ERROR_NONE;
1678 EXPORT_API notification_error_e notification_update(notification_h noti)
1682 /* Check noti is valid data */
1684 /* Update insert time ? */
1685 noti->insert_time = time(NULL);
1686 ret = notification_ipc_request_update(noti);
1687 if (ret != NOTIFICATION_ERROR_NONE) {
1691 ret = notification_ipc_request_refresh();
1692 if (ret != NOTIFICATION_ERROR_NONE) {
1696 return NOTIFICATION_ERROR_NONE;
1699 EXPORT_API notification_error_e notification_update_async(notification_h noti,
1700 void (*result_cb)(int priv_id, int result, void *data), void *user_data)
1704 /* Check noti is valid data */
1706 /* Update insert time ? */
1707 noti->insert_time = time(NULL);
1708 ret = notification_ipc_request_update_async(noti, result_cb, user_data);
1709 if (ret != NOTIFICATION_ERROR_NONE) {
1713 return NOTIFICATION_ERROR_NONE;
1716 EXPORT_API notification_error_e notifiation_clear(notification_type_e type)
1720 ret = notification_ipc_request_delete_multiple(type, NULL);
1721 if (ret != NOTIFICATION_ERROR_NONE) {
1725 return NOTIFICATION_ERROR_NONE;
1728 EXPORT_API notification_error_e notification_delete_all_by_type(const char *pkgname,
1729 notification_type_e type)
1732 char *caller_pkgname = NULL;
1734 if (pkgname == NULL) {
1735 caller_pkgname = _notification_get_pkgname_by_pid();
1737 caller_pkgname = strdup(pkgname);
1740 ret = notification_ipc_request_delete_multiple(type, caller_pkgname);
1741 if (ret != NOTIFICATION_ERROR_NONE) {
1742 if (caller_pkgname) {
1743 free(caller_pkgname);
1748 if (caller_pkgname) {
1749 free(caller_pkgname);
1751 return NOTIFICATION_ERROR_NONE;
1754 EXPORT_API notification_error_e notification_delete_by_priv_id(const char *pkgname,
1755 notification_type_e type,
1759 char *caller_pkgname = NULL;
1761 if (priv_id <= NOTIFICATION_PRIV_ID_NONE) {
1762 return NOTIFICATION_ERROR_INVALID_DATA;
1765 if (pkgname == NULL) {
1766 caller_pkgname = _notification_get_pkgname_by_pid();
1768 caller_pkgname = strdup(pkgname);
1771 ret = notification_ipc_request_delete_single(type, caller_pkgname, priv_id);
1772 if (ret != NOTIFICATION_ERROR_NONE) {
1773 if (caller_pkgname) {
1774 free(caller_pkgname);
1779 if (caller_pkgname) {
1780 free(caller_pkgname);
1785 EXPORT_API notification_error_e notification_delete(notification_h noti)
1790 return NOTIFICATION_ERROR_INVALID_DATA;
1793 ret = notification_ipc_request_delete_single(NOTIFICATION_TYPE_NONE, noti->caller_pkgname, noti->priv_id);
1794 if (ret != NOTIFICATION_ERROR_NONE) {
1798 return NOTIFICATION_ERROR_NONE;
1801 EXPORT_API notification_error_e notification_update_progress(notification_h noti,
1805 char *caller_pkgname = NULL;
1806 int input_priv_id = 0;
1807 double input_progress = 0.0;
1809 if (priv_id <= NOTIFICATION_PRIV_ID_NONE) {
1811 return NOTIFICATION_ERROR_INVALID_DATA;
1813 input_priv_id = noti->priv_id;
1816 input_priv_id = priv_id;
1820 caller_pkgname = _notification_get_pkgname_by_pid();
1822 caller_pkgname = strdup(noti->caller_pkgname);
1825 if (progress < 0.0) {
1826 input_progress = 0.0;
1827 } else if (progress > 1.0) {
1828 input_progress = 1.0;
1830 input_progress = progress;
1833 notification_ongoing_update_progress(caller_pkgname, input_priv_id,
1836 if (caller_pkgname) {
1837 free(caller_pkgname);
1840 return NOTIFICATION_ERROR_NONE;
1843 EXPORT_API notification_error_e notification_update_size(notification_h noti,
1847 char *caller_pkgname = NULL;
1848 int input_priv_id = 0;
1849 double input_size = 0.0;
1851 if (priv_id <= NOTIFICATION_PRIV_ID_NONE) {
1853 return NOTIFICATION_ERROR_INVALID_DATA;
1855 input_priv_id = noti->priv_id;
1858 input_priv_id = priv_id;
1862 caller_pkgname = _notification_get_pkgname_by_pid();
1864 caller_pkgname = strdup(noti->caller_pkgname);
1873 notification_ongoing_update_size(caller_pkgname, input_priv_id,
1876 if (caller_pkgname) {
1877 free(caller_pkgname);
1880 return NOTIFICATION_ERROR_NONE;
1883 EXPORT_API notification_error_e notification_update_content(notification_h noti,
1885 const char *content)
1887 char *caller_pkgname = NULL;
1888 int input_priv_id = 0;
1890 if (priv_id <= NOTIFICATION_PRIV_ID_NONE) {
1892 return NOTIFICATION_ERROR_INVALID_DATA;
1894 input_priv_id = noti->priv_id;
1897 input_priv_id = priv_id;
1901 caller_pkgname = _notification_get_pkgname_by_pid();
1903 caller_pkgname = strdup(noti->caller_pkgname);
1906 notification_ongoing_update_content(caller_pkgname, input_priv_id,
1909 if (caller_pkgname) {
1910 free(caller_pkgname);
1913 return NOTIFICATION_ERROR_NONE;
1916 static notification_h _notification_create(notification_type_e type)
1918 notification_h noti = NULL;
1920 if (type <= NOTIFICATION_TYPE_NONE || type >= NOTIFICATION_TYPE_MAX) {
1921 NOTIFICATION_ERR("INVALID TYPE : %d", type);
1925 noti = (notification_h) calloc(1, sizeof(struct _notification));
1927 NOTIFICATION_ERR("NO MEMORY : noti == NULL");
1933 if (type == NOTIFICATION_TYPE_NOTI)
1934 noti->layout = NOTIFICATION_LY_NOTI_EVENT_SINGLE;
1935 else if (type == NOTIFICATION_TYPE_ONGOING)
1936 noti->layout = NOTIFICATION_LY_ONGOING_PROGRESS;
1938 noti->caller_pkgname = _notification_get_pkgname_by_pid();
1939 noti->group_id = NOTIFICATION_GROUP_ID_NONE;
1940 noti->priv_id = NOTIFICATION_PRIV_ID_NONE;
1941 noti->sound_type = NOTIFICATION_SOUND_TYPE_NONE;
1942 noti->vibration_type = NOTIFICATION_VIBRATION_TYPE_NONE;
1943 noti->led_operation = NOTIFICATION_LED_OP_OFF;
1944 noti->display_applist = NOTIFICATION_DISPLAY_APP_ALL;
1947 * Other fields are already initialized with ZERO.
1952 EXPORT_API notification_h notification_new(notification_type_e type,
1953 int group_id, int priv_id)
1955 return _notification_create(type);
1958 EXPORT_API notification_h notification_create(notification_type_e type)
1960 return _notification_create(type);
1963 EXPORT_API notification_h notification_load(char *pkgname,
1967 notification_h noti = NULL;
1969 noti = (notification_h) calloc(1, sizeof(struct _notification));
1971 NOTIFICATION_ERR("NO MEMORY : noti == NULL");
1975 ret = notification_noti_get_by_priv_id(noti, pkgname, priv_id);
1976 if (ret != NOTIFICATION_ERROR_NONE) {
1977 notification_free(noti);
1984 EXPORT_API notification_error_e notification_clone(notification_h noti, notification_h *clone)
1986 notification_h new_noti = NULL;
1988 if (noti == NULL || clone == NULL) {
1989 NOTIFICATION_ERR("INVALID PARAMETER.");
1990 return NOTIFICATION_ERROR_INVALID_DATA;
1993 new_noti = (notification_h) calloc(1, sizeof(struct _notification));
1994 if (new_noti == NULL) {
1995 NOTIFICATION_ERR("NO MEMORY : noti == NULL");
1996 return NOTIFICATION_ERROR_NO_MEMORY;
1999 new_noti->type = noti->type;
2000 new_noti->layout = noti->layout;
2002 new_noti->group_id = noti->group_id;
2003 new_noti->internal_group_id = noti->internal_group_id;
2004 new_noti->priv_id = noti->priv_id;
2006 if(noti->caller_pkgname != NULL) {
2007 new_noti->caller_pkgname = strdup(noti->caller_pkgname);
2009 new_noti->caller_pkgname = _notification_get_pkgname_by_pid();
2011 if(noti->launch_pkgname != NULL) {
2012 new_noti->launch_pkgname = strdup(noti->launch_pkgname);
2014 new_noti->launch_pkgname = NULL;
2017 if(noti->args != NULL) {
2018 new_noti->args = bundle_dup(noti->args);
2020 new_noti->args = NULL;
2022 if(noti->group_args != NULL) {
2023 new_noti->group_args = bundle_dup(noti->group_args);
2025 new_noti->group_args = NULL;
2028 if(noti->b_execute_option != NULL) {
2029 new_noti->b_execute_option = bundle_dup(noti->b_execute_option);
2031 new_noti->b_execute_option = NULL;
2033 if(noti->b_service_responding != NULL) {
2034 new_noti->b_service_responding = bundle_dup(noti->b_service_responding);
2036 new_noti->b_service_responding = NULL;
2038 if(noti->b_service_single_launch != NULL) {
2039 new_noti->b_service_single_launch = bundle_dup(noti->b_service_single_launch);
2041 new_noti->b_service_single_launch = NULL;
2043 if(noti->b_service_multi_launch != NULL) {
2044 new_noti->b_service_multi_launch = bundle_dup(noti->b_service_multi_launch);
2046 new_noti->b_service_multi_launch = NULL;
2049 new_noti->sound_type = noti->sound_type;
2050 if(noti->sound_path != NULL) {
2051 new_noti->sound_path = strdup(noti->sound_path);
2053 new_noti->sound_path = NULL;
2055 new_noti->vibration_type = noti->vibration_type;
2056 if(noti->vibration_path != NULL) {
2057 new_noti->vibration_path = strdup(noti->vibration_path);
2059 new_noti->vibration_path = NULL;
2061 new_noti->led_operation = noti->led_operation;
2062 new_noti->led_argb = noti->led_argb;
2063 new_noti->led_on_ms = noti->led_on_ms;
2064 new_noti->led_off_ms = noti->led_off_ms;
2066 if(noti->domain != NULL) {
2067 new_noti->domain = strdup(noti->domain);
2069 new_noti->domain = NULL;
2071 if(noti->dir != NULL) {
2072 new_noti->dir = strdup(noti->dir);
2074 new_noti->dir = NULL;
2077 if(noti->b_text != NULL) {
2078 new_noti->b_text = bundle_dup(noti->b_text);
2080 new_noti->b_text = NULL;
2082 if(noti->b_key != NULL) {
2083 new_noti->b_key = bundle_dup(noti->b_key);
2085 new_noti->b_key = NULL;
2087 if(noti->b_format_args != NULL) {
2088 new_noti->b_format_args = bundle_dup(noti->b_format_args);
2090 new_noti->b_format_args = NULL;
2092 new_noti->num_format_args = noti->num_format_args;
2094 if(noti->b_image_path != NULL) {
2095 new_noti->b_image_path = bundle_dup(noti->b_image_path);
2097 new_noti->b_image_path = NULL;
2100 new_noti->time = noti->time;
2101 new_noti->insert_time = noti->insert_time;
2103 new_noti->flags_for_property = noti->flags_for_property;
2104 new_noti->display_applist = noti->display_applist;
2106 new_noti->progress_size = noti->progress_size;
2107 new_noti->progress_percentage = noti->progress_percentage;
2109 new_noti->app_icon_path = NULL;
2110 new_noti->app_name = NULL;
2111 new_noti->temp_title = NULL;
2112 new_noti->temp_content = NULL;
2116 return NOTIFICATION_ERROR_NONE;
2120 EXPORT_API notification_error_e notification_free(notification_h noti)
2123 return NOTIFICATION_ERROR_INVALID_DATA;
2126 if (noti->caller_pkgname) {
2127 free(noti->caller_pkgname);
2129 if (noti->launch_pkgname) {
2130 free(noti->launch_pkgname);
2133 bundle_free(noti->args);
2135 if (noti->group_args) {
2136 bundle_free(noti->group_args);
2139 if (noti->b_execute_option) {
2140 bundle_free(noti->b_execute_option);
2142 if (noti->b_service_responding) {
2143 bundle_free(noti->b_service_responding);
2145 if (noti->b_service_single_launch) {
2146 bundle_free(noti->b_service_single_launch);
2148 if (noti->b_service_multi_launch) {
2149 bundle_free(noti->b_service_multi_launch);
2152 if (noti->sound_path) {
2153 free(noti->sound_path);
2155 if (noti->vibration_path) {
2156 free(noti->vibration_path);
2167 bundle_free(noti->b_text);
2170 bundle_free(noti->b_key);
2172 if (noti->b_format_args) {
2173 bundle_free(noti->b_format_args);
2176 if (noti->b_image_path) {
2177 bundle_free(noti->b_image_path);
2180 if (noti->app_icon_path) {
2181 free(noti->app_icon_path);
2183 if (noti->app_name) {
2184 free(noti->app_name);
2186 if (noti->temp_title) {
2187 free(noti->temp_title);
2189 if (noti->temp_content) {
2190 free(noti->temp_content);
2195 return NOTIFICATION_ERROR_NONE;
2198 EXPORT_API notification_error_e
2199 notification_resister_changed_cb(void (*changed_cb)
2200 (void *data, notification_type_e type),
2203 notification_cb_list_s *noti_cb_list_new = NULL;
2204 notification_cb_list_s *noti_cb_list = NULL;
2206 if (changed_cb == NULL) {
2207 return NOTIFICATION_ERROR_INVALID_DATA;
2209 if (notification_ipc_monitor_init() != NOTIFICATION_ERROR_NONE) {
2210 return NOTIFICATION_ERROR_IO;
2214 (notification_cb_list_s *) malloc(sizeof(notification_cb_list_s));
2216 noti_cb_list_new->next = NULL;
2217 noti_cb_list_new->prev = NULL;
2219 noti_cb_list_new->cb_type = NOTIFICATION_CB_NORMAL;
2220 noti_cb_list_new->changed_cb = changed_cb;
2221 noti_cb_list_new->detailed_changed_cb = NULL;
2222 noti_cb_list_new->data = user_data;
2224 if (g_notification_cb_list == NULL) {
2225 g_notification_cb_list = noti_cb_list_new;
2227 noti_cb_list = g_notification_cb_list;
2229 while (noti_cb_list->next != NULL) {
2230 noti_cb_list = noti_cb_list->next;
2233 noti_cb_list->next = noti_cb_list_new;
2234 noti_cb_list_new->prev = noti_cb_list;
2236 return NOTIFICATION_ERROR_NONE;
2239 EXPORT_API notification_error_e
2240 notification_unresister_changed_cb(void (*changed_cb)
2241 (void *data, notification_type_e type))
2243 notification_cb_list_s *noti_cb_list = NULL;
2244 notification_cb_list_s *noti_cb_list_prev = NULL;
2245 notification_cb_list_s *noti_cb_list_next = NULL;
2247 noti_cb_list = g_notification_cb_list;
2249 if (changed_cb == NULL) {
2250 return NOTIFICATION_ERROR_INVALID_DATA;
2252 if (noti_cb_list == NULL) {
2253 return NOTIFICATION_ERROR_INVALID_DATA;
2256 while (noti_cb_list->prev != NULL) {
2257 noti_cb_list = noti_cb_list->prev;
2261 if (noti_cb_list->changed_cb == changed_cb) {
2262 noti_cb_list_prev = noti_cb_list->prev;
2263 noti_cb_list_next = noti_cb_list->next;
2265 if (noti_cb_list_prev == NULL) {
2266 g_notification_cb_list = noti_cb_list_next;
2268 noti_cb_list_prev->next = noti_cb_list_next;
2271 if (noti_cb_list_next == NULL) {
2272 if (noti_cb_list_prev != NULL) {
2273 noti_cb_list_prev->next = NULL;
2276 noti_cb_list_next->prev = noti_cb_list_prev;
2281 if (g_notification_cb_list == NULL)
2282 notification_ipc_monitor_fini();
2284 return NOTIFICATION_ERROR_NONE;
2286 noti_cb_list = noti_cb_list->next;
2287 } while (noti_cb_list != NULL);
2289 return NOTIFICATION_ERROR_INVALID_DATA;
2292 EXPORT_API notification_error_e
2293 notification_register_detailed_changed_cb(
2294 void (*detailed_changed_cb)(void *data, notification_type_e type, notification_op *op_list, int num_op),
2297 notification_cb_list_s *noti_cb_list_new = NULL;
2298 notification_cb_list_s *noti_cb_list = NULL;
2300 if (detailed_changed_cb == NULL) {
2301 return NOTIFICATION_ERROR_INVALID_DATA;
2303 if (notification_ipc_monitor_init() != NOTIFICATION_ERROR_NONE) {
2304 return NOTIFICATION_ERROR_IO;
2308 (notification_cb_list_s *) malloc(sizeof(notification_cb_list_s));
2310 noti_cb_list_new->next = NULL;
2311 noti_cb_list_new->prev = NULL;
2313 noti_cb_list_new->cb_type = NOTIFICATION_CB_DETAILED;
2314 noti_cb_list_new->changed_cb = NULL;
2315 noti_cb_list_new->detailed_changed_cb = detailed_changed_cb;
2316 noti_cb_list_new->data = user_data;
2318 if (g_notification_cb_list == NULL) {
2319 g_notification_cb_list = noti_cb_list_new;
2321 noti_cb_list = g_notification_cb_list;
2323 while (noti_cb_list->next != NULL) {
2324 noti_cb_list = noti_cb_list->next;
2327 noti_cb_list->next = noti_cb_list_new;
2328 noti_cb_list_new->prev = noti_cb_list;
2330 return NOTIFICATION_ERROR_NONE;
2333 EXPORT_API notification_error_e
2334 notification_unregister_detailed_changed_cb(
2335 void (*detailed_changed_cb)(void *data, notification_type_e type, notification_op *op_list, int num_op),
2338 notification_cb_list_s *noti_cb_list = NULL;
2339 notification_cb_list_s *noti_cb_list_prev = NULL;
2340 notification_cb_list_s *noti_cb_list_next = NULL;
2342 noti_cb_list = g_notification_cb_list;
2344 if (detailed_changed_cb == NULL) {
2345 return NOTIFICATION_ERROR_INVALID_DATA;
2347 if (noti_cb_list == NULL) {
2348 return NOTIFICATION_ERROR_INVALID_DATA;
2351 while (noti_cb_list->prev != NULL) {
2352 noti_cb_list = noti_cb_list->prev;
2356 if (noti_cb_list->detailed_changed_cb == detailed_changed_cb) {
2357 noti_cb_list_prev = noti_cb_list->prev;
2358 noti_cb_list_next = noti_cb_list->next;
2360 if (noti_cb_list_prev == NULL) {
2361 g_notification_cb_list = noti_cb_list_next;
2363 noti_cb_list_prev->next = noti_cb_list_next;
2366 if (noti_cb_list_next == NULL) {
2367 if (noti_cb_list_prev != NULL) {
2368 noti_cb_list_prev->next = NULL;
2371 noti_cb_list_next->prev = noti_cb_list_prev;
2376 if (g_notification_cb_list == NULL)
2377 notification_ipc_monitor_fini();
2379 return NOTIFICATION_ERROR_NONE;
2381 noti_cb_list = noti_cb_list->next;
2382 } while (noti_cb_list != NULL);
2384 return NOTIFICATION_ERROR_INVALID_DATA;
2387 EXPORT_API notification_error_e notification_get_count(notification_type_e type,
2388 const char *pkgname,
2390 int priv_id, int *count)
2395 if (count == NULL) {
2396 return NOTIFICATION_ERROR_INVALID_DATA;
2400 notification_noti_get_count(type, pkgname, group_id, priv_id,
2402 if (ret != NOTIFICATION_ERROR_NONE) {
2406 *count = noti_count;
2408 return NOTIFICATION_ERROR_NONE;
2411 EXPORT_API notification_error_e notification_get_list(notification_type_e type,
2413 notification_list_h *list)
2415 notification_list_h get_list = NULL;
2419 return NOTIFICATION_ERROR_INVALID_DATA;
2422 ret = notification_noti_get_grouping_list(type, count, &get_list);
2423 if (ret != NOTIFICATION_ERROR_NONE) {
2429 return NOTIFICATION_ERROR_NONE;
2432 EXPORT_API notification_error_e
2433 notification_get_grouping_list(notification_type_e type, int count,
2434 notification_list_h * list)
2436 notification_list_h get_list = NULL;
2440 return NOTIFICATION_ERROR_INVALID_DATA;
2443 ret = notification_noti_get_grouping_list(type, count, &get_list);
2444 if (ret != NOTIFICATION_ERROR_NONE) {
2450 return NOTIFICATION_ERROR_NONE;
2453 EXPORT_API notification_error_e notification_get_detail_list(const char *pkgname,
2457 notification_list_h *list)
2459 notification_list_h get_list = NULL;
2463 return NOTIFICATION_ERROR_INVALID_DATA;
2467 notification_noti_get_detail_list(pkgname, group_id, priv_id, count,
2469 if (ret != NOTIFICATION_ERROR_NONE) {
2475 return NOTIFICATION_ERROR_NONE;
2478 EXPORT_API notification_error_e notification_free_list(notification_list_h list)
2480 notification_list_h cur_list = NULL;
2481 notification_h noti = NULL;
2484 return NOTIFICATION_ERROR_INVALID_DATA;
2487 cur_list = notification_list_get_head(list);
2489 while (cur_list != NULL) {
2490 noti = notification_list_get_data(cur_list);
2491 cur_list = notification_list_remove(cur_list, noti);
2493 notification_free(noti);
2496 return NOTIFICATION_ERROR_NONE;
2499 EXPORT_API notification_error_e notification_op_get_data(notification_op *noti_op, notification_op_data_type_e type,
2502 if (noti_op == NULL || data == NULL) {
2503 return NOTIFICATION_ERROR_INVALID_DATA;
2507 case NOTIFICATION_OP_DATA_TYPE:
2508 *((int*)data) = noti_op->type;
2510 case NOTIFICATION_OP_DATA_PRIV_ID:
2511 *((int*)data) = noti_op->priv_id;
2513 case NOTIFICATION_OP_DATA_NOTI:
2514 *((notification_h *)data) = noti_op->noti;
2516 case NOTIFICATION_OP_DATA_EXTRA_INFO_1:
2517 *((int*)data) = noti_op->extra_info_1;
2519 case NOTIFICATION_OP_DATA_EXTRA_INFO_2:
2520 *((int*)data) = noti_op->extra_info_2;
2523 return NOTIFICATION_ERROR_INVALID_DATA;
2527 return NOTIFICATION_ERROR_NONE;
2530 void notification_call_changed_cb(notification_op *op_list, int op_num)
2532 notification_cb_list_s *noti_cb_list = NULL;
2535 if (g_notification_cb_list == NULL) {
2538 noti_cb_list = g_notification_cb_list;
2540 while (noti_cb_list->prev != NULL) {
2541 noti_cb_list = noti_cb_list->prev;
2544 if (op_list == NULL) {
2545 NOTIFICATION_ERR("invalid data");
2549 while (noti_cb_list != NULL) {
2550 if (noti_cb_list->cb_type == NOTIFICATION_CB_NORMAL && noti_cb_list->changed_cb) {
2551 noti_cb_list->changed_cb(noti_cb_list->data,
2552 NOTIFICATION_TYPE_NOTI);
2554 if (noti_cb_list->cb_type == NOTIFICATION_CB_DETAILED && noti_cb_list->detailed_changed_cb) {
2555 noti_cb_list->detailed_changed_cb(noti_cb_list->data,
2556 NOTIFICATION_TYPE_NOTI, op_list, op_num);
2559 noti_cb_list = noti_cb_list->next;
2563 EXPORT_API int notification_is_service_ready(void)
2566 * The notification service is now socket activated so as far
2567 * as clients are concerned it is always ready
2572 EXPORT_API notification_error_e
2573 notification_add_deffered_task(
2574 void (*deffered_task_cb)(void *data), void *user_data)
2576 if (deffered_task_cb == NULL) {
2577 return NOTIFICATION_ERROR_INVALID_DATA;
2580 return notification_ipc_add_deffered_task(deffered_task_cb, user_data);
2583 EXPORT_API notification_error_e
2584 notification_del_deffered_task(
2585 void (*deffered_task_cb)(void *data))
2587 if (deffered_task_cb == NULL) {
2588 return NOTIFICATION_ERROR_INVALID_DATA;
2591 return notification_ipc_del_deffered_task(deffered_task_cb);
2594 /* notification_set_icon will be removed */
2595 EXPORT_API notification_error_e notification_set_icon(notification_h noti,
2596 const char *icon_path)
2598 int ret_err = NOTIFICATION_ERROR_NONE;
2601 notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON,
2607 /* notification_get_icon will be removed */
2608 EXPORT_API notification_error_e notification_get_icon(notification_h noti,
2611 int ret_err = NOTIFICATION_ERROR_NONE;
2612 char *ret_image_path = NULL;
2615 notification_get_image(noti, NOTIFICATION_IMAGE_TYPE_ICON,
2618 if (ret_err == NOTIFICATION_ERROR_NONE && icon_path != NULL) {
2619 *icon_path = ret_image_path;
2621 //NOTIFICATION_DBG("Get icon : %s", *icon_path);
2627 EXPORT_API notification_error_e notification_set_title(notification_h noti,
2629 const char *loc_title)
2631 int noti_err = NOTIFICATION_ERROR_NONE;
2633 noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE,
2635 NOTIFICATION_VARIABLE_TYPE_NONE);
2640 EXPORT_API notification_error_e notification_get_title(notification_h noti,
2644 int noti_err = NOTIFICATION_ERROR_NONE;
2645 char *ret_text = NULL;
2648 notification_get_text(noti, NOTIFICATION_TEXT_TYPE_TITLE,
2651 if (title != NULL) {
2655 if (loc_title != NULL) {
2662 EXPORT_API notification_error_e notification_set_content(notification_h noti,
2663 const char *content,
2664 const char *loc_content)
2666 int noti_err = NOTIFICATION_ERROR_NONE;
2668 noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT,
2669 content, loc_content,
2670 NOTIFICATION_VARIABLE_TYPE_NONE);
2675 EXPORT_API notification_error_e notification_get_content(notification_h noti,
2679 int noti_err = NOTIFICATION_ERROR_NONE;
2680 char *ret_text = NULL;
2683 notification_get_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT,
2686 if (content != NULL) {
2687 *content = ret_text;
2690 if (loc_content != NULL) {
2691 *loc_content = NULL;
2699 (VCONFKEY_SETAPPL_STATE_TICKER_NOTI_DISPLAY_CONTENT_BOOL, &boolval);
2701 if (ret == -1 || boolval == 0) {
2702 if (content != NULL && noti->default_content != NULL) {
2703 *content = noti->default_content;
2706 if (loc_content != NULL && noti->loc_default_content != NULL) {
2707 *loc_content = noti->loc_default_content;
2713 EXPORT_API notification_error_e notification_set_args(notification_h noti,
2715 bundle * group_args)
2717 if (noti == NULL || args == NULL) {
2718 return NOTIFICATION_ERROR_INVALID_DATA;
2722 bundle_free(noti->args);
2725 noti->args = bundle_dup(args);
2727 if (noti->group_args) {
2728 bundle_free(noti->group_args);
2729 noti->group_args = NULL;
2732 if (group_args != NULL) {
2733 noti->group_args = bundle_dup(group_args);
2736 return NOTIFICATION_ERROR_NONE;
2739 EXPORT_API notification_error_e notification_get_args(notification_h noti,
2741 bundle ** group_args)
2743 if (noti == NULL || args == NULL) {
2744 return NOTIFICATION_ERROR_INVALID_DATA;
2753 if (group_args != NULL && noti->group_args) {
2754 *group_args = noti->group_args;
2757 return NOTIFICATION_ERROR_NONE;
2760 EXPORT_API notification_error_e notification_delete_group_by_group_id(const char *pkgname,
2761 notification_type_e type,
2765 char *caller_pkgname = NULL;
2767 if (pkgname == NULL) {
2768 caller_pkgname = _notification_get_pkgname_by_pid();
2770 caller_pkgname = strdup(pkgname);
2773 ret = notification_ipc_request_delete_multiple(type, caller_pkgname);
2774 if (ret != NOTIFICATION_ERROR_NONE) {
2775 if (caller_pkgname) {
2776 free(caller_pkgname);
2781 if (caller_pkgname) {
2782 free(caller_pkgname);
2784 return NOTIFICATION_ERROR_NONE;
2787 EXPORT_API notification_error_e notification_delete_group_by_priv_id(const char *pkgname,
2788 notification_type_e type,
2792 char *caller_pkgname = NULL;
2794 if (pkgname == NULL) {
2795 caller_pkgname = _notification_get_pkgname_by_pid();
2797 caller_pkgname = strdup(pkgname);
2800 ret = notification_ipc_request_delete_single(type, caller_pkgname, priv_id);
2801 if (ret != NOTIFICATION_ERROR_NONE) {
2802 if (caller_pkgname) {
2803 free(caller_pkgname);
2808 if (caller_pkgname) {
2809 free(caller_pkgname);
2811 return NOTIFICATION_ERROR_NONE;
2814 EXPORT_API notification_error_e notification_wait_response(notification_h noti,
2819 bundle *b, *bc = NULL;
2822 int sock_fd, msg_fd;
2824 struct sockaddr_un sock_addr;
2825 char msg_buffer[1024];
2827 struct timeval timeout_tv;
2830 memset(msg_buffer, 0, sizeof(msg_buffer));
2832 /* a response packet *must* have an execute option TYPE_RESPONDING
2833 with an associated bundle.
2834 If its bundle does not already contain a "tid" hint (which
2835 complex applications such as xwalk may overwrite), we will
2836 try to find the TID and set it in the bundle ourselves. */
2837 notification_get_execute_option (noti, NOTIFICATION_EXECUTE_TYPE_RESPONDING,
2841 return NOTIFICATION_ERROR_INVALID_DATA;
2843 tid_c = bundle_get_val(b, "tid");
2844 if (tid_c == NULL) {
2845 tid = syscall(SYS_gettid);
2846 asprintf((char **)&tid_c, "%d", tid);
2848 bundle_add(bc, "tid", tid_c);
2849 notification_set_execute_option (noti, NOTIFICATION_EXECUTE_TYPE_RESPONDING,
2852 notification_update(noti);
2855 sock_fd = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0);
2857 return NOTIFICATION_ERROR_NO_MEMORY;
2859 sock_addr.sun_family = AF_UNIX;
2860 asprintf(&sock_path, "/tmp/.notification-%s", tid_c);
2861 strncpy(sock_addr.sun_path, sock_path, sizeof(sock_addr.sun_path) - 1);
2862 if (bind(sock_fd, (struct sockaddr *)&sock_addr, sizeof(sock_addr)) == -1) {
2865 free((char *)tid_c);
2866 return NOTIFICATION_ERROR_NO_MEMORY;
2870 timeout_tv.tv_sec = timeout;
2871 timeout_tv.tv_usec = 0;
2872 setsockopt(sock_fd, SOL_SOCKET, SO_RCVTIMEO, (char *)&timeout_tv, sizeof(timeout_tv));
2873 setsockopt(sock_fd, SOL_SOCKET, SO_SNDTIMEO, (char *)&timeout_tv, sizeof(timeout_tv));
2877 msg_fd = accept(sock_fd, NULL, 0);
2879 msg_size = read(msg_fd, msg_buffer, 1024);
2880 } while (msg_size > 0);
2882 resp = strtok(msg_buffer, "\n");
2884 *respi = atoi(resp);
2885 if (respc != NULL) {
2886 resp = strtok(NULL, "\n");
2901 free((char *)tid_c);
2903 return NOTIFICATION_ERROR_NONE;
2906 EXPORT_API notification_error_e notification_send_response(notification_h noti,
2911 notification_h notic;
2913 char *notic_pkgname;
2918 struct sockaddr_un sock_addr;
2921 notification_get_id(noti, NULL, ¬ic_id);
2922 notification_get_pkgname(noti, ¬ic_pkgname);
2923 notic = notification_load(notic_pkgname, notic_id);
2924 notification_get_execute_option (notic, NOTIFICATION_EXECUTE_TYPE_RESPONDING,
2928 return NOTIFICATION_ERROR_INVALID_DATA;
2930 tid_c = bundle_get_val(b, "tid");
2932 return NOTIFICATION_ERROR_INVALID_DATA;
2935 sock_fd = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0);
2937 return NOTIFICATION_ERROR_NO_MEMORY;
2939 sock_addr.sun_family = AF_UNIX;
2940 asprintf(&sock_path, "/tmp/.notification-%d", tid);
2941 strncpy(sock_addr.sun_path, sock_path, sizeof(sock_addr.sun_path) - 1);
2942 if (connect(sock_fd, (struct sockaddr *)&sock_addr, sizeof(sock_addr)) == -1) {
2945 return NOTIFICATION_ERROR_NO_MEMORY;
2949 asprintf(&msg_buffer, "%d\n%s\n", respi, respc);
2951 asprintf(&msg_buffer, "%d\n", respi);
2952 write(sock_fd, msg_buffer, strlen(msg_buffer) + 1);
2958 return NOTIFICATION_ERROR_NONE;