tizen 2.4 release
[framework/appfw/aul-1.git] / src / service.c
1 /*
2  * Copyright (c) 2015 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 #define _GNU_SOURCE
18 #include <sys/types.h>
19 #include <sys/stat.h>
20 #include <stdlib.h>
21 #include <stdio.h>
22 #include <string.h>
23 #include <bundle.h>
24 #include <bundle_internal.h>
25 #include <glib.h>
26 #include <string.h>
27 #include <pthread.h>
28 #include <dlfcn.h>
29 #include <Ecore_X.h>
30 #include <Ecore.h>
31 #include <iniparser.h>
32 #include <pkgmgr-info.h>
33 #include <pkgmgrinfo_zone.h>
34 #include "aul.h"
35 #include "aul_api.h"
36 #include "aul_svc.h"
37 #include "aul_svc_db.h"
38 #include "simple_util.h"
39 #include "aul_svc_priv_key.h"
40 #include "aul_zone.h"
41 #include "delegator_client.h"
42 #include "launch.h"
43
44 /* callback handling */
45 typedef struct _aul_svc_cb_info_t {
46         aul_svc_res_fn cb_func;
47         int request_code;
48         void *data;
49 } aul_svc_cb_info_t;
50
51 typedef struct _aul_svc_resolve_info_t {
52         char *pkgname;
53         char *op;
54         char *uri;
55         char *scheme;
56         char *host;
57         char *uri_r_info;
58         char *origin_mime;
59         char *mime;
60         char *m_type;
61         char *s_type;
62         char *category;
63         char *win_id;
64         int mime_set;
65 } aul_svc_resolve_info_t;
66
67 typedef struct _aul_svc_transient_cb_info_t {
68         aul_svc_host_res_fn cb_func;
69         Ecore_X_Window win_id;
70         void *data;
71 } aul_svc_transient_cb_info_t;
72
73 pthread_mutex_t iniparser_lock = PTHREAD_MUTEX_INITIALIZER;
74 GSList *tmp_list;
75
76 static aul_svc_cb_info_t *__create_rescb(int request_code,
77         aul_svc_res_fn cbfunc,
78         void *data);
79 static void __remove_rescb(aul_svc_cb_info_t *info);
80 static int __set_bundle(bundle *b, const char *key, const char *value);
81 static void __aul_cb(bundle *b, int is_cancel, void *data);
82 static int __run_svc_with_pkgname(char *pkgname, bundle *b, int request_code,
83                                   aul_svc_res_fn cbfunc, void *data);
84 static int __get_resolve_info(bundle *b, aul_svc_resolve_info_t *info);
85 static int __free_resolve_info_data(aul_svc_resolve_info_t *info);
86
87 static void __set_transient_for(Ecore_X_Window callee, Ecore_X_Window caller,
88                                 void *data);
89
90 static char *white_list[] = {
91         APP_SELECTOR,
92         SHARE_PANEL,
93         NULL
94 };
95
96 static bool __is_special_app(const char *appid)
97 {
98         const char *id;
99         int i = 0;
100
101         if (appid == NULL)
102                 return false;
103
104         while ((id = white_list[i]) != NULL) {
105                 if (strcmp(id, appid) == 0)
106                         return true;
107                 i++;
108         }
109         return false;
110 }
111
112 static Eina_Bool __transient_cb(void *data, int type, void *event)
113 {
114         Ecore_X_Event_Window_Hide *ev;
115         aul_svc_transient_cb_info_t*  cb_info;
116
117         if ((!event) || (!data)) {
118                 _E("input param of transient cb is null");
119                 return ECORE_CALLBACK_CANCEL;
120         }
121
122         ev = event;
123         cb_info = (aul_svc_transient_cb_info_t*) data;
124
125         if (ev->win == cb_info->win_id) {
126                 if (cb_info->cb_func)
127                         cb_info->cb_func(cb_info->data);
128                 ecore_main_loop_quit();
129         }
130
131         return ECORE_CALLBACK_RENEW;
132 }
133
134 static int __aul_subapp_cb(void *data)
135 {
136         aul_svc_transient_cb_info_t*  cb_info;
137
138         cb_info = (aul_svc_transient_cb_info_t*) data;
139
140         cb_info->cb_func(cb_info->data);
141         ecore_main_loop_quit();
142
143         return 0;
144 }
145
146 static aul_svc_cb_info_t *__create_rescb(int request_code,
147         aul_svc_res_fn cbfunc,
148         void *data)
149 {
150         aul_svc_cb_info_t* info;
151
152         info = (aul_svc_cb_info_t*)calloc(1, sizeof(aul_svc_cb_info_t));
153         if (info == NULL)
154                 return NULL;
155
156         info->request_code = request_code;
157         info->cb_func = cbfunc;
158         info->data = data;
159
160         return info;
161 }
162
163 static void __remove_rescb(aul_svc_cb_info_t *info)
164 {
165         if (info) free(info);
166 }
167
168 static int __set_bundle(bundle *b, const char *key, const char *value)
169 {
170         const char *val = NULL;
171
172         val = bundle_get_val(b, key);
173         if (val) {
174                 if ( bundle_del(b, key) != 0 ) {
175                         return AUL_SVC_RET_ERROR;
176                 }
177         }
178
179         if (!value)
180                 return AUL_SVC_RET_EINVAL;
181
182         if ( bundle_add(b, key, value) != 0 ) {
183                 return AUL_SVC_RET_ERROR;
184         }
185
186         _D("__set_bundle");
187
188         return AUL_SVC_RET_OK;
189 }
190
191 static int __set_bundle_array(bundle *b, const char *key, const char **value,
192                               int len)
193 {
194
195         int type;
196         type = aul_svc_data_is_array(b, key);
197
198         if (type == 1) {
199                 if ( bundle_del(b, key) != 0 ) {
200                         return AUL_SVC_RET_ERROR;
201                 }
202         }
203
204         if (!value)
205                 return AUL_SVC_RET_EINVAL;
206
207         if ( bundle_add_str_array(b, key, value, len) != 0 ) {
208                 return AUL_SVC_RET_ERROR;
209         }
210
211         _D("__set_bundle_array");
212
213         return AUL_SVC_RET_OK;
214 }
215
216 static void __aul_cb(bundle *b, int is_cancel, void *data)
217 {
218         const char *val = NULL;
219         aul_svc_cb_info_t*  cb_info;
220         int res;
221
222         if (is_cancel)
223                 res = AUL_SVC_RES_CANCEL;
224         else {
225                 /* get result_code from bundle */
226                 val = bundle_get_val(b, AUL_SVC_K_RES_VAL);
227                 res = (val == NULL) ? AUL_SVC_RES_NOT_OK : atoi(val);
228         }
229
230         /* remove result_code from bundle */
231         bundle_del(b, AUL_SVC_K_RES_VAL);
232
233         /* find corresponding callback */
234         cb_info = (aul_svc_cb_info_t*)data;
235
236         cb_info->cb_func(b, cb_info->request_code, (aul_svc_result_val)res,
237                          cb_info->data);
238         __remove_rescb(cb_info);
239
240
241         return;
242 }
243
244 static int __run_svc_with_pkgname(char *pkgname, bundle *b, int request_code,
245                                   aul_svc_res_fn cbfunc, void *data)
246 {
247         aul_svc_cb_info_t *cb_info = NULL;
248         int ret = -1;
249
250         if ( bundle_get_type(b, AUL_SVC_K_SELECTOR_EXTRA_LIST) != BUNDLE_TYPE_NONE ) {
251                 if ( !aul_svc_get_pkgname(b) ) {
252                         pkgname = APP_SELECTOR;
253                 }
254         }
255
256         if ( bundle_get_val(b, AUL_K_FORCE_LAUNCH_APP_SELECTOR) ) {
257                 pkgname = APP_SELECTOR;
258         }
259
260         if ( __is_special_app(pkgname)) {
261                 bundle_del(b, AUL_SVC_K_CAN_BE_LEADER);
262                 bundle_add_str(b, AUL_SVC_K_CAN_BE_LEADER, "true");
263                 bundle_del(b, AUL_SVC_K_REROUTE);
264                 bundle_add_str(b, AUL_SVC_K_REROUTE, "true");
265                 bundle_del(b, AUL_SVC_K_RECYCLE);
266                 bundle_add_str(b, AUL_SVC_K_RECYCLE, "true");
267
268         }
269
270         if (cbfunc) {
271                 SECURE_LOGD("pkg_name : %s - with result", pkgname);
272
273                 cb_info = __create_rescb(request_code, cbfunc, data);
274                 ret = aul_launch_app_with_result(pkgname, b, __aul_cb, cb_info);
275         } else {
276                 SECURE_LOGD("pkg_name : %s - no result", pkgname);
277
278 #ifdef _APPFW_FEATURE_MULTI_INSTANCE
279                 const char* data = bundle_get_val(b, AUL_SVC_K_MULTI_INSTANCE);
280                 if (data) {
281                         SECURE_LOGD("multi_instance value = %s", data);
282                 }
283
284                 if (data && strncmp(data, "TRUE", strlen("TRUE")) == 0) {
285                         ret = aul_launch_app_for_multi_instance(pkgname, b);
286                 } else {
287                         ret = aul_launch_app(pkgname, b);
288                 }
289 #else
290                 ret = aul_launch_app(pkgname, b);
291 #endif
292         }
293
294         if (ret < 0) {
295                 switch (ret) {
296                 case AUL_R_EILLACC:
297                         ret = AUL_SVC_RET_EILLACC;
298                         break;
299                 case AUL_R_EINVAL:
300                         ret = AUL_SVC_RET_EINVAL;
301                         break;
302                 case AUL_R_ETERMINATING:
303                         ret = AUL_SVC_RET_ETERMINATING;
304                         break;
305                 case AUL_R_EREJECTED:
306                         ret = AUL_SVC_RET_EREJECTED;
307                         break;
308                 case AUL_R_ENOAPP:
309                         ret = AUL_SVC_RET_ENOMATCH;
310                         break;
311                 default:
312                         ret = AUL_SVC_RET_ELAUNCH;
313                 }
314         }
315
316         return ret;
317 }
318
319 static int __get_resolve_info(bundle *b, aul_svc_resolve_info_t *info)
320 {
321         char *tmp = NULL;
322         char *strtok_buf = NULL;
323         int ret = -1;
324
325         info->op = (char *)aul_svc_get_operation(b);
326         info->uri = (char *)aul_svc_get_uri(b);
327
328         if ((info->uri) && (strcmp(info->uri, "") == 0)) {
329                 _E("Uri is empty");
330                 return AUL_SVC_RET_EINVAL;
331         }
332
333         info->origin_mime = info->mime = (char *)aul_svc_get_mime(b);
334         info->pkgname = (char *)aul_svc_get_pkgname(b);
335         info->category = (char *)aul_svc_get_category(b);
336         info->win_id = (char *)bundle_get_val(b, AUL_SVC_K_WIN_ID);
337
338         _D("getting resolve info for: operation - %s / uri - %s / mime - %s\n",
339                         info->op, info->uri, info->mime);
340
341         if (info->uri) {
342                 if (strncmp(info->uri, "/", 1) == 0) {
343                         if (!info->mime) {
344                                 info->origin_mime = info->mime = malloc(MAX_MIME_STR_SIZE);
345                                 if (info->mime == NULL) {
346                                         _E("out of memory");
347                                         return AUL_SVC_RET_ERROR;
348                                 }
349
350                                 ret = aul_get_mime_from_file(info->uri, info->mime, MAX_MIME_STR_SIZE);
351                                 info->mime_set = 1;
352                         }
353                         info->uri = NULL;
354                 } else if (strncmp(info->uri, "file:///", 8) == 0) {
355                         if (!info->mime) {
356                                 info->origin_mime = info->mime = malloc(MAX_MIME_STR_SIZE);
357                                 if (info->mime == NULL) {
358                                         _E("out of memory");
359                                         return AUL_SVC_RET_ERROR;
360                                 }
361
362                                 ret = aul_get_mime_from_file(&info->uri[7], info->mime, MAX_MIME_STR_SIZE);
363                                 info->mime_set = 1;
364                         }
365                 } else if (strncmp(info->uri, "file:/", 6) == 0) {
366                         if (!info->mime) {
367                                 info->origin_mime = info->mime = malloc(MAX_MIME_STR_SIZE);
368                                 if (info->mime == NULL) {
369                                         _E("out of memory");
370                                         return AUL_SVC_RET_ERROR;
371                                 }
372
373                                 ret = aul_get_mime_from_file(&info->uri[5], info->mime, MAX_MIME_STR_SIZE);
374                                 info->mime_set = 1;
375                         }
376                 }
377
378                 if (info->mime_set == 1 && ret < 0) {
379                         _E("aul_get_mime_from_file : %d", ret);
380                         free(info->mime);
381                         info->origin_mime = info->mime = NULL;
382                         info->mime_set = 0;
383                 }
384         }
385
386         if (info->uri) {
387                 GRegex *regex;
388                 GMatchInfo *match_info;
389                 GError *error = NULL;
390
391                 regex = g_regex_new ("^(([^:/?#]+):)?(//([^/?#]*))?", 0, 0, &error);
392                 if (g_regex_match (regex, info->uri, 0, &match_info) == FALSE) {
393                         g_regex_unref (regex);
394                         return AUL_SVC_RET_EINVAL;
395                 }
396
397                 info->scheme = g_match_info_fetch (match_info, 2);
398                 info->host = g_match_info_fetch (match_info, 4);
399
400                 if (info->scheme && info->host) {
401                         info->uri_r_info = malloc(MAX_SCHEME_STR_SIZE + MAX_HOST_STR_SIZE + 2);
402                         if (info->uri_r_info == NULL) {
403                                 _E("out of memory");
404                                 g_match_info_free(match_info);
405                                 g_regex_unref(regex);
406                                 return AUL_SVC_RET_ERROR;
407                         }
408
409                         snprintf(info->uri_r_info, MAX_SCHEME_STR_SIZE + MAX_HOST_STR_SIZE + 1,
410                                  "%s://%s", info->scheme, info->host);
411                 }
412
413                 g_match_info_free (match_info);
414                 g_regex_unref (regex);
415
416         } else {
417                 info->scheme = strdup("NULL");
418         }
419
420         if (!info->mime)
421                 info->mime = strdup("NULL");
422         else {
423                 info->m_type = malloc(MAX_LOCAL_BUFSZ);
424                 if (info->m_type == NULL) {
425                         _E("ouf of memory");
426                         return AUL_SVC_RET_ERROR;
427                 }
428
429                 info->s_type = malloc(MAX_LOCAL_BUFSZ);
430                 if (info->s_type == NULL) {
431                         _E("out of memory");
432                         free(info->m_type);
433                         return AUL_SVC_RET_ERROR;
434                 }
435
436                 tmp = strdup(info->mime);
437                 strtok_buf = strtok(tmp, "/");
438                 if (strtok_buf)
439                         strncpy(info->m_type, strtok_buf, MAX_LOCAL_BUFSZ - 1);
440                 strtok_buf = strtok(NULL, "/");
441                 if (strtok_buf)
442                         strncpy(info->s_type, strtok_buf, MAX_LOCAL_BUFSZ - 1);
443                 free(tmp);
444
445                 if (strncmp(info->m_type, "*", 1) == 0) {
446                         strncpy(info->m_type, "%", MAX_LOCAL_BUFSZ - 1);
447                 }
448                 if (strncmp(info->s_type, "*", 1) == 0) {
449                         strncpy(info->s_type, "%", MAX_LOCAL_BUFSZ - 1);
450                 }
451
452                 info->mime = malloc(MAX_MIME_STR_SIZE);
453                 if (info->mime == NULL) {
454                         _E("out of memory");
455                         free(info->s_type);
456                         free(info->m_type);
457                         return AUL_SVC_RET_ERROR;
458                 }
459
460                 snprintf(info->mime, MAX_MIME_STR_SIZE - 1, "%s/%s", info->m_type,
461                          info->s_type);
462         }
463
464         return 0;
465 }
466
467 static int __free_resolve_info_data(aul_svc_resolve_info_t *info)
468 {
469         if (info->mime)
470                 free(info->mime);
471         if (info->scheme)
472                 free(info->scheme);
473         if (info->host)
474                 free(info->host);
475         if (info->m_type)
476                 free(info->m_type);
477         if (info->s_type)
478                 free(info->s_type);
479         if (info->uri_r_info)
480                 free(info->uri_r_info);
481         if (info->mime_set)
482                 free(info->origin_mime);
483
484         return 0;
485 }
486
487 static void __set_transient_for(Ecore_X_Window callee, Ecore_X_Window caller,
488                                 void *data)
489 {
490         void (*ecore_x_icccm_transient_for_set) (Ecore_X_Window, Ecore_X_Window);
491         void (*ecore_x_window_client_manage) (Ecore_X_Window);
492         int* ecore_x_event_window_destroy;
493
494         void *handle = dlopen("libecore_x.so.1", RTLD_LAZY | RTLD_LOCAL);
495         if (!handle) {
496                 _E("dlopen error %s", dlerror());
497                 return;
498         }
499
500         ecore_x_icccm_transient_for_set = dlsym(handle,
501                                                 "ecore_x_icccm_transient_for_set");
502         if (ecore_x_icccm_transient_for_set == NULL)  {
503                 _E("dlsym error");
504                 dlclose(handle);
505                 return;
506         }
507
508         ecore_x_icccm_transient_for_set(callee, caller);
509
510         ecore_x_window_client_manage = dlsym(handle, "ecore_x_window_client_manage");
511         if (ecore_x_window_client_manage == NULL)  {
512                 _E("dlsym error");
513                 dlclose(handle);
514                 return;
515         }
516
517         ecore_x_window_client_manage(caller);
518
519         ecore_x_event_window_destroy = dlsym(handle, "ECORE_X_EVENT_WINDOW_DESTROY");
520         if (ecore_x_event_window_destroy == NULL)  {
521                 _E("dlsym error");
522                 dlclose(handle);
523                 return;
524         }
525
526         ecore_event_handler_add(*ecore_x_event_window_destroy, __transient_cb, data);;
527
528         dlclose(handle);
529 }
530
531 static char* __get_alias_appid(char *appid)
532 {
533         char *alias_id = NULL;
534         char *val = NULL;
535         char key_string[MAX_PACKAGE_STR_SIZE + 5];
536         dictionary *dic;
537
538         dic = iniparser_load("/usr/share/appsvc/alias.ini");
539
540         if (dic == NULL)
541                 return NULL;
542
543         snprintf(key_string, sizeof(key_string), "Alias:%s", appid);
544         pthread_mutex_lock(&iniparser_lock);
545         val = iniparser_getstr(dic, key_string);
546         pthread_mutex_unlock(&iniparser_lock);
547
548         SECURE_LOGD("alias_id : %s", val);
549
550         if (val != NULL) {
551                 alias_id = malloc(MAX_PACKAGE_STR_SIZE);
552                 if (alias_id == NULL) {
553                         _E("out of memory");
554                         iniparser_freedict(dic);
555                         return NULL;
556                 }
557
558                 strncpy(alias_id, val, MAX_PACKAGE_STR_SIZE - 1);
559         }
560
561         iniparser_freedict(dic);
562
563         return alias_id;
564 }
565
566 static int __get_list_with_condition_mime_extened(char *op, char *uri,
567         char *mime, char *m_type, char *s_type, GSList **pkg_list)
568 {
569         char *tmp;
570
571         tmp = malloc(MAX_MIME_STR_SIZE);
572         if (tmp == NULL) {
573                 _E("out of memory");
574                 return -1;
575         }
576
577         _svc_db_get_list_with_condition(op, uri, mime, pkg_list);
578         if ((strncmp(mime, "NULL", 4) != 0) && (strncmp(s_type, "%", 1) != 0)) {
579                 snprintf(tmp, MAX_MIME_STR_SIZE - 1, "%s/*", m_type);
580                 _svc_db_get_list_with_condition(op, uri, tmp, pkg_list);
581         }
582         if ((strncmp(mime, "NULL", 4) != 0) && (strncmp(m_type, "%", 1) != 0)) {
583                 snprintf(tmp, MAX_MIME_STR_SIZE - 1, "*/*");
584                 _svc_db_get_list_with_condition(op, uri, tmp, pkg_list);
585         }
586
587         free(tmp);
588
589         return 0;
590 }
591
592 static int __get_list_with_condition_mime_extened_with_collation(char *op,
593         char *uri, char *mime, char *m_type, char *s_type, GSList **pkg_list)
594 {
595         char *tmp;
596
597         tmp = malloc(MAX_MIME_STR_SIZE);
598         if (tmp == NULL) {
599                 _E("out of memory");
600                 return -1;
601         }
602
603         _svc_db_get_list_with_collation(op, uri, mime, pkg_list);
604         if ((strncmp(mime, "NULL", 4) != 0) && (strncmp(s_type, "%", 1) != 0)) {
605                 snprintf(tmp, MAX_MIME_STR_SIZE - 1, "%s/*", m_type);
606                 _svc_db_get_list_with_collation(op, uri, tmp, pkg_list);
607         }
608         if ((strncmp(mime, "NULL", 4) != 0) && (strncmp(m_type, "%", 1) != 0)) {
609                 snprintf(tmp, MAX_MIME_STR_SIZE - 1, "*/*");
610                 _svc_db_get_list_with_collation(op, uri, tmp, pkg_list);
611         }
612
613         free(tmp);
614
615         return 0;
616 }
617
618
619 static int __app_list_cb(pkgmgrinfo_appinfo_h handle, void *user_data)
620 {
621         char *appid = NULL;
622         GSList **app_list = (GSList **)user_data;
623         char *str = NULL;
624         GSList *iter = NULL;
625
626         pkgmgrinfo_appinfo_get_appid(handle, &str);
627         _D("Matching application is %s", str);
628
629         for (iter = tmp_list; iter != NULL; iter = g_slist_next(iter)) {
630                 if (strncmp(str, (char *)iter->data, MAX_PACKAGE_STR_SIZE - 1) == 0) {
631                         appid = strdup(str);
632                         *app_list = g_slist_append(*app_list, (void *)appid);
633                         _D("%s is added", appid);
634                 }
635         }
636
637         return 0;
638 }
639
640 static int __get_list_with_category(char *category, GSList **pkg_list)
641 {
642         int ret;
643         pkgmgrinfo_appinfo_filter_h handle;
644         GSList *app_list = NULL;
645         GSList *iter = NULL;
646         char *list_item = NULL;
647
648         ret = pkgmgrinfo_appinfo_filter_create(&handle);
649         ret = pkgmgrinfo_appinfo_filter_add_string(handle,
650                 PMINFO_APPINFO_PROP_APP_CATEGORY, category);
651
652         tmp_list = *pkg_list;
653         ret = pkgmgrinfo_appinfo_filter_foreach_appinfo(handle, __app_list_cb,
654                 &app_list);
655         if (ret != PMINFO_R_OK) {
656                 pkgmgrinfo_appinfo_filter_destroy(handle);
657                 return -1;
658         }
659         pkgmgrinfo_appinfo_filter_destroy(handle);
660
661         for (iter = *pkg_list; iter != NULL; iter = g_slist_next(iter)) {
662                 list_item = (char *)iter->data;
663                 g_free(list_item);
664         }
665         g_slist_free(*pkg_list);
666
667         *pkg_list = app_list;
668
669         return 0;
670 }
671
672 static int __appid_compare(gconstpointer data1, gconstpointer data2)
673 {
674         char *a = (char *)data1;
675         char *b = (char *)data2;
676         return strcmp(a, b);
677 }
678
679 static int __check_mainapp_mode(char *operation)
680 {
681         return 0;
682 }
683
684 static int __get_list_with_submode(char *operation, char *win_id,
685                                    GSList **pkg_list)
686 {
687         int ret = 0;
688         int mainapp_mode = 0;
689
690         mainapp_mode = __check_mainapp_mode(operation);
691
692         SECURE_LOGD("mainapp_mode : %d", mainapp_mode);
693
694         ret = _svc_db_adjust_list_with_submode(mainapp_mode, win_id, pkg_list);
695
696         if (ret < 0) {
697                 _E("error on get_list_with_submode :%d", ret);
698                 return -1;
699         }
700
701         return 0;
702 }
703
704 SLPAPI int aul_svc_set_operation(bundle *b, const char *operation)
705 {
706         if (b == NULL) {
707                 _E("bundle for aul_svc_set_operation is NULL");
708                 return AUL_SVC_RET_EINVAL;
709         }
710
711         return __set_bundle(b, AUL_SVC_K_OPERATION, operation);
712 }
713
714 SLPAPI int aul_svc_set_uri(bundle *b, const char *uri)
715 {
716         if (b == NULL) {
717                 _E("bundle for aul_svc_set_uri is NULL");
718                 return AUL_SVC_RET_EINVAL;
719         }
720
721         return __set_bundle(b, AUL_SVC_K_URI, uri);
722 }
723
724 SLPAPI int aul_svc_set_mime(bundle *b, const char *mime)
725 {
726         if (b == NULL) {
727                 _E("bundle for aul_svc_set_mime is NULL");
728                 return AUL_SVC_RET_EINVAL;
729         }
730
731         return __set_bundle(b, AUL_SVC_K_MIME, mime);
732 }
733
734 SLPAPI int aul_svc_add_data(bundle *b, const char *key, const char *val)
735 {
736         if (b == NULL || key == NULL) {
737                 return AUL_SVC_RET_EINVAL;
738         }
739
740         /* check key for data */
741         /******************/
742
743         return __set_bundle(b, key, val);
744 }
745
746 SLPAPI int aul_svc_add_data_array(bundle *b, const char *key,
747                                   const char **val_array, int len)
748 {
749         if (b == NULL || key == NULL) {
750                 return AUL_SVC_RET_EINVAL;
751         }
752
753         /* check key for data */
754         /******************/
755
756         return __set_bundle_array(b, key, val_array, len);
757 }
758
759
760 SLPAPI int aul_svc_set_pkgname(bundle *b, const char *pkg_name)
761 {
762         if (b == NULL) {
763                 _E("bundle for aul_svc_set_pkgname is NULL");
764                 return AUL_SVC_RET_EINVAL;
765         }
766
767         return __set_bundle(b, AUL_SVC_K_PKG_NAME, pkg_name);
768 }
769
770
771 SLPAPI int aul_svc_set_appid(bundle *b, const char *appid)
772 {
773         char *alias_id = NULL;
774         int ret;
775
776         if (b == NULL || appid == NULL) {
777                 _E("bundle for aul_svc_set_appid is NULL");
778                 return AUL_SVC_RET_EINVAL;
779         }
780
781         alias_id = __get_alias_appid((char *)appid);
782         if (alias_id == NULL) {
783                 ret = __set_bundle(b, AUL_SVC_K_PKG_NAME, appid);
784         } else {
785                 ret = __set_bundle(b, AUL_SVC_K_PKG_NAME, alias_id);
786                 free(alias_id);
787         }
788
789         return ret;
790 }
791
792 SLPAPI int aul_svc_set_category(bundle *b, const char *category)
793 {
794         if (b == NULL) {
795                 _E("bundle for aul_svc_set_category is NULL");
796                 return AUL_SVC_RET_EINVAL;
797         }
798
799         return __set_bundle(b, AUL_SVC_K_CATEGORY, category);
800 }
801
802 SLPAPI int aul_svc_set_launch_mode(bundle *b, const char *mode)
803 {
804         if (b == NULL) {
805                 _E("bundle for aul_svc_set_launch_mode is NULL");
806                 return AUL_SVC_RET_EINVAL;
807         }
808
809         return __set_bundle(b, AUL_SVC_K_LAUNCH_MODE, mode);
810 }
811
812 SLPAPI int aul_svc_run_service(bundle *b, int request_code,
813                                aul_svc_res_fn cbfunc,
814                                void *data)
815 {
816         aul_svc_resolve_info_t info;
817         char *pkgname;
818         char *operation;
819         int pkg_count = 0;
820         int ret = -1;
821         char oldZone[64] = { 0, };
822
823         GSList *pkg_list = NULL;
824         GSList *iter = NULL;
825         char *list_item;
826
827         if (b == NULL) {
828                 _E("bundle for aul_svc_set_appid is NULL");
829                 return AUL_SVC_RET_EINVAL;
830         }
831
832         pkgmgrinfo_pkginfo_set_zone(_cur_zone, oldZone, 64);
833         pkgname = (char *)aul_svc_get_pkgname(b);
834         operation = (char *)aul_svc_get_operation(b);
835
836         char *zone = NULL;
837
838         if (delegator_client_can_jump(&zone, b) == AUL_SVC_RET_OK) {
839                 ret = delegator_client_launch(zone, b);
840                 if (zone != NULL)
841                         free(zone);
842                 return ret;
843         }
844
845         /* explict*/
846         if (pkgname) {
847                 if (operation == NULL)
848                         aul_svc_set_operation(b, AUL_SVC_OPERATION_DEFAULT);
849                 ret = __run_svc_with_pkgname(pkgname, b, request_code, cbfunc, data);
850                 pkgmgrinfo_pkginfo_set_zone(oldZone, NULL, 0);
851                 return ret;
852         }
853
854         /* share panel */
855         if (operation && (strcmp(operation, AUL_SVC_OPERATION_SHARE) == 0
856                 || strcmp(operation, AUL_SVC_OPERATION_MULTI_SHARE) == 0
857                 || strcmp(operation, AUL_SVC_OPERATION_SHARE_TEXT) == 0)) {
858                 ret = __run_svc_with_pkgname(SHARE_PANEL, b, request_code, cbfunc, data);
859                 pkgmgrinfo_pkginfo_set_zone(oldZone, NULL, 0);
860                 return ret;
861         }
862
863         memset(&info, 0, sizeof(aul_svc_resolve_info_t));
864         ret = __get_resolve_info(b, &info);
865         if (ret < 0) {
866                 __free_resolve_info_data(&info);
867                 pkgmgrinfo_pkginfo_set_zone(oldZone, NULL, 0);
868                 return ret;
869         }
870
871         SECURE_LOGD("op - %s / mime - %s / scheme - %s\n", info.op, info.origin_mime,
872                     info.scheme);
873
874         ret = _svc_db_check_perm();
875         if (ret < 0) {
876                 _E("permission error : %d", ret);
877                 ret = AUL_SVC_RET_EILLACC;
878                 goto end;
879         }
880
881         /*uri*/
882         pkgname = _svc_db_get_app(info.op, info.origin_mime, info.uri);
883         if (pkgname == NULL) {
884                 __get_list_with_condition_mime_extened_with_collation(info.op, info.uri,
885                         info.mime, info.m_type, info.s_type, &pkg_list);
886                 pkg_count = g_slist_length(pkg_list);
887                 if (pkg_count > 0) {
888
889                         if (info.uri_r_info) {
890                                 __get_list_with_condition_mime_extened(info.op, info.uri_r_info,
891                                         info.mime, info.m_type, info.s_type, &pkg_list);
892                         }
893
894                         __get_list_with_condition_mime_extened(info.op, info.scheme,
895                                 info.mime, info.m_type, info.s_type, &pkg_list);
896
897                         __get_list_with_condition_mime_extened(info.op, "*",
898                                 info.mime, info.m_type, info.s_type, &pkg_list);
899
900                         if (info.scheme && (strcmp(info.scheme, "file") == 0)
901                                 && info.mime && (strcmp(info.mime, "NULL") != 0)) {
902                                 __get_list_with_condition_mime_extened(info.op, "NULL",
903                                         info.mime, info.m_type, info.s_type, &pkg_list);
904                         }
905
906                         if (info.category) {
907                                 __get_list_with_category(info.category, &pkg_list);
908                         }
909
910                         __get_list_with_submode(info.op, info.win_id, &pkg_list);
911
912                         pkg_count = g_slist_length(pkg_list);
913                         _D("pkg_count : %d", pkg_count);
914
915                         if (pkg_count == 1) {
916                                 pkgname = (char *)pkg_list->data;
917                                 if (pkgname != NULL) {
918                                         ret = __run_svc_with_pkgname(pkgname, b, request_code, cbfunc, data);
919                                         goto end;
920                                 }
921                         } else {
922                                 bundle_add(b, AUL_SVC_K_URI_R_INFO, info.uri);
923                                 ret = __run_svc_with_pkgname(APP_SELECTOR, b, request_code, cbfunc, data);
924                                 goto end;
925                         }
926                         for (iter = pkg_list; iter != NULL; iter = g_slist_next(iter)) {
927                                 list_item = (char *)iter->data;
928                                 g_free(list_item);
929                         }
930                         g_slist_free(pkg_list);
931                         pkg_list = NULL;
932                 }
933         } else {
934                 ret = __run_svc_with_pkgname(pkgname, b, request_code, cbfunc, data);
935                 free(pkgname);
936                 goto end;
937         }
938
939         /*scheme & host*/
940         if (info.uri_r_info) {
941                 pkgname = _svc_db_get_app(info.op, info.origin_mime, info.uri_r_info);
942
943                 if (pkgname == NULL) {
944                         __get_list_with_condition_mime_extened(info.op, info.uri_r_info,
945                                                                info.mime, info.m_type, info.s_type, &pkg_list);
946                         pkg_count = g_slist_length(pkg_list);
947                         if (pkg_count > 0) {
948                                 __get_list_with_condition_mime_extened(info.op, info.scheme,
949                                         info.mime, info.m_type, info.s_type, &pkg_list);
950
951                                 __get_list_with_condition_mime_extened(info.op, "*",
952                                         info.mime, info.m_type, info.s_type, &pkg_list);
953
954                                 if (info.scheme && (strcmp(info.scheme, "file") == 0)
955                                         && info.mime && (strcmp(info.mime, "NULL") != 0)) {
956                                         __get_list_with_condition_mime_extened(info.op, "NULL",
957                                                 info.mime, info.m_type, info.s_type, &pkg_list);
958                                 }
959
960                                 if (info.category) {
961                                         __get_list_with_category(info.category, &pkg_list);
962                                 }
963
964                                 __get_list_with_submode(info.op, info.win_id, &pkg_list);
965
966                                 pkg_count = g_slist_length(pkg_list);
967                                 _D("pkg_count : %d", pkg_count);
968
969                                 if (pkg_count == 1) {
970                                         pkgname = (char *)pkg_list->data;
971                                         if (pkgname != NULL) {
972                                                 ret = __run_svc_with_pkgname(pkgname, b, request_code, cbfunc, data);
973                                                 goto end;
974                                         }
975                                 } else {
976                                         bundle_add(b, AUL_SVC_K_URI_R_INFO, info.uri_r_info);
977                                         ret = __run_svc_with_pkgname(APP_SELECTOR, b, request_code, cbfunc, data);
978                                         goto end;
979                                 }
980                         }
981                         for (iter = pkg_list; iter != NULL; iter = g_slist_next(iter)) {
982                                 list_item = (char *)iter->data;
983                                 g_free(list_item);
984                         }
985                         g_slist_free(pkg_list);
986                         pkg_list = NULL;
987                 }  else {
988                         ret = __run_svc_with_pkgname(pkgname, b, request_code, cbfunc, data);
989                         free(pkgname);
990                         goto end;
991                 }
992         }
993
994         /*scheme*/
995         pkgname = _svc_db_get_app(info.op, info.origin_mime, info.scheme);
996
997         if (pkgname == NULL) {
998                 __get_list_with_condition_mime_extened(info.op, info.scheme,
999                         info.mime, info.m_type, info.s_type, &pkg_list);
1000
1001                 __get_list_with_condition_mime_extened(info.op, "*",
1002                         info.mime, info.m_type, info.s_type, &pkg_list);
1003
1004                 if (info.scheme && (strcmp(info.scheme, "file") == 0)
1005                         && info.mime && (strcmp(info.mime, "NULL") != 0)) {
1006                         __get_list_with_condition_mime_extened(info.op, "NULL",
1007                                 info.mime, info.m_type, info.s_type, &pkg_list);
1008                 }
1009
1010                 if (info.category) {
1011                         __get_list_with_category(info.category, &pkg_list);
1012                 }
1013
1014                 __get_list_with_submode(info.op, info.win_id, &pkg_list);
1015
1016                 pkg_count = g_slist_length(pkg_list);
1017                 _D("pkg_count : %d", pkg_count);
1018
1019                 if (pkg_count == 1) {
1020                         pkgname = (char *)pkg_list->data;
1021                         if (pkgname != NULL) {
1022                                 ret = __run_svc_with_pkgname(pkgname, b, request_code, cbfunc, data);
1023                         }
1024                 } else if (pkg_count < 1) {
1025                         __free_resolve_info_data(&info);
1026                         pkgmgrinfo_pkginfo_set_zone(oldZone, NULL, 0);
1027                         return AUL_SVC_RET_ENOMATCH;
1028                 } else {
1029                         bundle_add(b, AUL_SVC_K_URI_R_INFO, info.scheme);
1030                         ret = __run_svc_with_pkgname(APP_SELECTOR, b, request_code, cbfunc, data);
1031                 }
1032
1033                 for (iter = pkg_list; iter != NULL; iter = g_slist_next(iter)) {
1034                         list_item = (char *)iter->data;
1035                         g_free(list_item);
1036                 }
1037                 g_slist_free(pkg_list);
1038         } else {
1039                 ret = __run_svc_with_pkgname(pkgname, b, request_code, cbfunc, data);
1040                 free(pkgname);
1041         }
1042
1043 end:
1044         __free_resolve_info_data(&info);
1045
1046         pkgmgrinfo_pkginfo_set_zone(oldZone, NULL, 0);
1047         return ret;
1048 }
1049
1050 SLPAPI int aul_svc_get_list(bundle *b, aul_svc_info_iter_fn iter_fn, void *data)
1051 {
1052         aul_svc_resolve_info_t info;
1053         char *pkgname = NULL;
1054         int pkg_count;
1055         int ret = -1;
1056         char oldZone[64] = { 0, };
1057
1058         GSList *pkg_list = NULL;
1059         GSList *iter = NULL;
1060
1061         if (b == NULL) {
1062                 _E("bundle for aul_svc_run_service is NULL");
1063                 return AUL_SVC_RET_EINVAL;
1064         }
1065
1066         if (iter_fn == NULL) {
1067                 _E("iter_fn for aul_svc_run_service is NULL");
1068                 return AUL_SVC_RET_EINVAL;
1069         }
1070
1071         pkgmgrinfo_pkginfo_set_zone(_cur_zone, oldZone, 64);
1072
1073         /* parse bundle */
1074         memset(&info, 0, sizeof(aul_svc_resolve_info_t));
1075         ret = __get_resolve_info(b, &info);
1076         if (ret < 0) {
1077                 __free_resolve_info_data(&info);
1078                 return ret;
1079         }
1080
1081         _D("operation - %s / shceme - %s / mime - %s\n", info.op, info.scheme,
1082            info.mime);
1083
1084         __get_list_with_condition_mime_extened_with_collation(info.op, info.uri,
1085                 info.mime, info.m_type, info.s_type, &pkg_list);
1086
1087         if (info.uri_r_info) {
1088                 __get_list_with_condition_mime_extened(info.op, info.uri_r_info,
1089                         info.mime, info.m_type, info.s_type, &pkg_list);
1090         }
1091
1092         __get_list_with_condition_mime_extened(info.op, info.scheme,
1093                 info.mime, info.m_type, info.s_type, &pkg_list);
1094
1095         __get_list_with_condition_mime_extened(info.op, "*",
1096                 info.mime, info.m_type, info.s_type, &pkg_list);
1097
1098         if (info.scheme && (strcmp(info.scheme, "file") == 0)
1099                 && info.mime && (strcmp(info.mime, "NULL") != 0)) {
1100                 __get_list_with_condition_mime_extened(info.op, "NULL",
1101                         info.mime, info.m_type, info.s_type, &pkg_list);
1102         }
1103
1104         if (info.category) {
1105                 __get_list_with_category(info.category, &pkg_list);
1106         }
1107
1108         __get_list_with_submode(info.op, info.win_id, &pkg_list);
1109
1110         pkg_count = g_slist_length(pkg_list);
1111         if (pkg_count == 0) {
1112                 _E("Cannot find associated application");
1113
1114                 __free_resolve_info_data(&info);
1115                 pkgmgrinfo_pkginfo_set_zone(oldZone, NULL, 0);
1116                 return AUL_SVC_RET_ENOMATCH;
1117         }
1118
1119         for (iter = pkg_list; iter != NULL; iter = g_slist_next(iter)) {
1120                 pkgname = iter->data;
1121                 SECURE_LOGD("PKGNAME : %s\n", pkgname);
1122                 if ( iter_fn(pkgname, data) != 0)
1123                         break;
1124                 g_free(pkgname);
1125         }
1126
1127         g_slist_free(pkg_list);
1128         __free_resolve_info_data(&info);
1129
1130         pkgmgrinfo_pkginfo_set_zone(oldZone, NULL, 0);
1131         return AUL_SVC_RET_OK;
1132 }
1133
1134 SLPAPI int aul_svc_get_all_defapps(aul_svc_info_iter_fn iter_fn, void *data)
1135 {
1136         char *pkgname = NULL;
1137         int ret = -1;
1138         char oldZone[64] = { 0, };
1139
1140         GSList *pkg_list = NULL;
1141         GSList *iter = NULL;
1142
1143         pkgmgrinfo_pkginfo_set_zone(_cur_zone, oldZone, 64);
1144
1145         ret = _svc_db_check_perm();
1146         if (ret < 0) {
1147                 _E("permission error : %d", ret);
1148                 return AUL_SVC_RET_EILLACC;
1149         }
1150
1151         ret = _svc_db_get_list_with_all_defapps(&pkg_list);
1152         if (ret < 0)
1153                 return ret;
1154
1155         for (iter = pkg_list; iter != NULL; iter = g_slist_next(iter)) {
1156                 pkgname = iter->data;
1157                 if ( iter_fn(pkgname, data) != 0)
1158                         break;
1159                 g_free(pkgname);
1160         }
1161
1162         g_slist_free(pkg_list);
1163
1164         pkgmgrinfo_pkginfo_set_zone(oldZone, NULL, 0);
1165         return AUL_SVC_RET_OK;
1166 }
1167
1168 SLPAPI const char *aul_svc_get_operation(bundle *b)
1169 {
1170         return bundle_get_val(b, AUL_SVC_K_OPERATION);
1171 }
1172
1173 SLPAPI const char *aul_svc_get_uri(bundle *b)
1174 {
1175         return bundle_get_val(b, AUL_SVC_K_URI);
1176 }
1177
1178 SLPAPI const char *aul_svc_get_mime(bundle *b)
1179 {
1180         return bundle_get_val(b, AUL_SVC_K_MIME);
1181 }
1182
1183 SLPAPI const char *aul_svc_get_data(bundle *b, const char *key)
1184 {
1185         return bundle_get_val(b, key);
1186 }
1187
1188 SLPAPI const char **aul_svc_get_data_array(bundle *b, const char *key, int *len)
1189 {
1190         return bundle_get_str_array(b, key, len);
1191 }
1192
1193 SLPAPI const char *aul_svc_get_pkgname(bundle *b)
1194 {
1195         return bundle_get_val(b, AUL_SVC_K_PKG_NAME);
1196 }
1197
1198 SLPAPI const char *aul_svc_get_appid(bundle *b)
1199 {
1200         return bundle_get_val(b, AUL_SVC_K_PKG_NAME);
1201 }
1202
1203 SLPAPI const char *aul_svc_get_category(bundle *b)
1204 {
1205         return bundle_get_val(b, AUL_SVC_K_CATEGORY);
1206 }
1207
1208 SLPAPI const char *aul_svc_get_launch_mode(bundle *b)
1209 {
1210         return bundle_get_val(b, AUL_SVC_K_LAUNCH_MODE);
1211 }
1212
1213 SLPAPI int aul_svc_create_result_bundle(bundle *inb, bundle **outb)
1214 {
1215         int ret = -1;
1216
1217         if (inb == NULL || outb == NULL) {
1218                 _E("bundle is NULL");
1219                 return AUL_SVC_RET_EINVAL;
1220         }
1221
1222         ret = aul_create_result_bundle(inb, outb);
1223
1224         /* add additional bundle */
1225         /*  bundle_add(outb, " ", " ");  */
1226
1227         if (ret == AUL_R_OK)
1228                 ret = AUL_SVC_RET_OK;
1229         else if (ret == AUL_R_EINVAL)
1230                 ret = AUL_SVC_RET_EINVAL;
1231         else
1232                 ret = AUL_SVC_RET_ERROR;
1233
1234         return ret;
1235 }
1236
1237 SLPAPI int aul_svc_send_result(bundle *b, aul_svc_result_val result)
1238 {
1239         int ret;
1240         char tmp[MAX_LOCAL_BUFSZ];
1241
1242         if (b == NULL) {
1243                 _E("aul_svc_send_result is NULL");
1244                 return AUL_SVC_RET_EINVAL;
1245         }
1246
1247         if (result != AUL_SVC_RES_OK && result != AUL_SVC_RES_NOT_OK) {
1248                 _E("invalid result %d", (int)result);
1249                 return AUL_SVC_RET_EINVAL;
1250         }
1251
1252         /* add result_code to bundle */
1253         snprintf(tmp, MAX_LOCAL_BUFSZ, "%d", (int)result);
1254         ret = __set_bundle(b, AUL_SVC_K_RES_VAL, tmp);
1255         if (ret < 0)
1256                 return AUL_SVC_RET_ERROR;
1257
1258         ret = aul_send_service_result(b);
1259
1260         /* remove result_code from bundle */
1261         bundle_del(b, AUL_SVC_K_RES_VAL);
1262
1263         return ret;
1264 }
1265
1266 SLPAPI int aul_svc_set_defapp(const char *op, const char *mime_type,
1267                               const char *uri,
1268                               const char *defapp)
1269 {
1270         int ret;
1271
1272         if (op == NULL || defapp == NULL)
1273                 return AUL_SVC_RET_EINVAL;
1274
1275         ret = _svc_db_check_perm();
1276         if (ret < 0) {
1277                 _E("permission error : %d", ret);
1278                 return AUL_SVC_RET_EILLACC;
1279         }
1280
1281         ret = _svc_db_add_app(op, mime_type, uri, defapp);
1282
1283         if (ret < 0)
1284                 return AUL_SVC_RET_ERROR;
1285
1286         return AUL_SVC_RET_OK;
1287 }
1288
1289 SLPAPI int aul_svc_unset_defapp(const char *defapp)
1290 {
1291         int ret;
1292
1293         if (defapp == NULL)
1294                 return AUL_SVC_RET_EINVAL;
1295
1296         ret = _svc_db_check_perm();
1297         if (ret < 0) {
1298                 _E("permission error : %d", ret);
1299                 return AUL_SVC_RET_EILLACC;
1300         }
1301
1302         ret = _svc_db_delete_with_pkgname(defapp);
1303
1304         if (ret < 0)
1305                 return AUL_SVC_RET_ERROR;
1306
1307         return AUL_SVC_RET_OK;
1308 }
1309
1310 SLPAPI int aul_svc_unset_all_defapps()
1311 {
1312         int ret;
1313
1314         ret = _svc_db_check_perm();
1315         if (ret < 0) {
1316                 _E("permission error : %d", ret);
1317                 return AUL_SVC_RET_EILLACC;
1318         }
1319
1320         ret = _svc_db_delete_all();
1321
1322         if (ret < 0)
1323                 return AUL_SVC_RET_ERROR;
1324
1325         return AUL_SVC_RET_OK;
1326 }
1327
1328 SLPAPI int aul_svc_is_defapp(const char *pkg_name)
1329 {
1330         int ret;
1331
1332         ret = _svc_db_check_perm();
1333         if (ret < 0) {
1334                 _E("permission error : %d", ret);
1335                 return AUL_SVC_RET_EILLACC;
1336         }
1337
1338         return _svc_db_is_defapp(pkg_name);
1339 }
1340
1341 SLPAPI int aul_svc_data_is_array(bundle *b, const char *key)
1342 {
1343         int type;
1344         type = bundle_get_type(b, key);
1345
1346         if (type <= 0)
1347                 return 0;
1348
1349         if (type & BUNDLE_TYPE_ARRAY)
1350                 return 1;
1351         return 0;
1352 }
1353
1354 SLPAPI int aul_svc_allow_transient_app(bundle *b, int wid)
1355 {
1356         char win_id[MAX_LOCAL_BUFSZ];
1357
1358         snprintf(win_id, MAX_LOCAL_BUFSZ, "%d", wid);
1359
1360         if (b == NULL) {
1361                 _E("bundle for aul_svc_allow_transient_app is NULL");
1362                 return AUL_SVC_RET_EINVAL;
1363         }
1364
1365         return __set_bundle(b, AUL_SVC_K_WIN_ID, win_id);
1366 }
1367
1368 SLPAPI int aul_svc_request_transient_app(bundle *b, int callee_wid,
1369         aul_svc_host_res_fn cbfunc, void *data)
1370 {
1371         const char *caller = NULL;
1372         Ecore_X_Window caller_wid;
1373         aul_svc_transient_cb_info_t* info;
1374
1375         caller = bundle_get_val(b, AUL_SVC_K_WIN_ID);
1376         if (caller == NULL)
1377                 return AUL_SVC_RET_ERROR;
1378
1379         caller_wid = atoi(caller);
1380
1381         if (callee_wid == caller_wid) {
1382                 _E("callee window id is same as calleer window id. request will be ignored");
1383                 return AUL_SVC_RET_EINVAL;
1384         }
1385
1386         info = (aul_svc_transient_cb_info_t*)calloc(1,
1387                 sizeof(aul_svc_transient_cb_info_t));
1388         if (info == NULL)
1389                 return AUL_SVC_RET_ERROR;
1390
1391         info->win_id = caller_wid;
1392         info->cb_func = cbfunc;
1393         info->data = data;
1394
1395         __set_transient_for(callee_wid, caller_wid, info);
1396
1397         aul_set_subapp(__aul_subapp_cb, info);
1398
1399         return 0;
1400 }
1401
1402 SLPAPI int aul_svc_subapp_terminate_request_pid(int pid)
1403 {
1404         int cpid = getpid();
1405         int lcnt;
1406         int *lpids = NULL;
1407         int i;
1408
1409         aul_app_group_get_leader_pids(&lcnt, &lpids);
1410         for (i = 0; i < lcnt; i++) {
1411                 if (lpids[i] == cpid) {
1412                         int cnt;
1413                         int *pids = NULL;
1414
1415                         aul_app_group_get_group_pids(cpid, &cnt, &pids);
1416
1417                         if (cnt == 0) {
1418                                 free(lpids);
1419                                 if (pids)
1420                                         free(pids);
1421
1422                                 return aul_subapp_terminate_request_pid(pid);
1423                         }
1424
1425                         if (pids != NULL)
1426                                 free(pids);
1427                         break;
1428                 }
1429         }
1430
1431         if (lpids != NULL)
1432                 free(lpids);
1433
1434         return aul_app_group_clear_top();
1435 }
1436
1437 SLPAPI int aul_send_service_result(bundle *b)
1438 {
1439         return aul_send_result(b, 0);
1440 }
1441
1442 SLPAPI int aul_svc_subscribe_launch_result(bundle *b, const char *result)
1443 {
1444         if (b == NULL) {
1445                 _E("bundle for aul_svc_subscribe_launch_result is NULL");
1446                 return AUL_SVC_RET_EINVAL;
1447         }
1448
1449         return __set_bundle(b, result, "1");
1450 }