delete livebox db during fota upgrade
[framework/appfw/slp-pkgmgr.git] / client / src / pkgmgr.c
1 /*
2  * slp-pkgmgr
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
7  * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  */
22
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include <unistd.h>
27 #include <dlfcn.h>
28 #include <dirent.h>
29 #include <fcntl.h>
30 #include <sys/wait.h>
31 #include <sys/time.h>
32 #include <dbus/dbus.h>
33 #include <dbus/dbus-glib-lowlevel.h>
34 #include <ail.h>
35 #include <aul.h>
36 #include <vconf.h>
37 #include <db-util.h>
38 #include <pkgmgr-info.h>
39 #include <iniparser.h>
40 #include <security-server.h>
41
42 #include "package-manager.h"
43 #include "pkgmgr-internal.h"
44 #include "pkgmgr-debug.h"
45 #include "pkgmgr-api.h"
46 #include "comm_client.h"
47 #include "comm_status_broadcast_server.h"
48
49 #undef LOG_TAG
50 #ifndef LOG_TAG
51 #define LOG_TAG "PKGMGR"
52 #endif                          /* LOG_TAG */
53
54 #define PKG_TMP_PATH "/opt/usr/apps/tmp"
55
56 static int _get_request_id()
57 {
58         static int internal_req_id = 1;
59
60         return internal_req_id++;
61 }
62
63 typedef struct _req_cb_info {
64         int request_id;
65         char *req_key;
66         pkgmgr_handler event_cb;
67         void *data;
68         struct _req_cb_info *next;
69 } req_cb_info;
70
71 typedef struct _listen_cb_info {
72         int request_id;
73         pkgmgr_handler event_cb;
74         void *data;
75         struct _listen_cb_info *next;
76 } listen_cb_info;
77
78 typedef struct _pkgmgr_client_t {
79         client_type ctype;
80         union {
81                 struct _request {
82                         comm_client *cc;
83                         req_cb_info *rhead;
84                 } request;
85                 struct _listening {
86                         comm_client *cc;
87                         listen_cb_info *lhead;
88                 } listening;
89                 struct _broadcast {
90                         DBusConnection *bc;
91                 } broadcast;
92         } info;
93 } pkgmgr_client_t;
94
95 typedef struct _iter_data {
96         pkgmgr_iter_fn iter_fn;
97         void *data;
98 } iter_data;
99
100 static char *__get_cookie_from_security_server(void)
101 {
102         int ret = 0;
103         size_t cookie_size = 0;
104         char *e_cookie = NULL;
105
106         //calculage cookie size
107         cookie_size = security_server_get_cookie_size();
108         retvm_if(cookie_size <= 0, NULL, "security_server_get_cookie_size : cookie_size is %d", cookie_size);
109
110         //get cookie from security server
111         char cookie[cookie_size];
112         cookie[0] = '\0';
113         ret = security_server_request_cookie(cookie, cookie_size);
114         retvm_if(ret < 0, NULL, "security_server_request_cookie fail (%d)", ret);
115
116         //encode cookie
117         e_cookie = g_base64_encode((const guchar *)cookie, cookie_size);
118         retvm_if(e_cookie == NULL, NULL, "g_base64_encode e_cookie is NULL");
119
120         return e_cookie;
121 }
122
123 static int __xsystem(const char *argv[])
124 {
125         int status = 0;
126         pid_t pid;
127         pid = fork();
128         switch (pid) {
129         case -1:
130                 perror("fork failed");
131                 return -1;
132         case 0:
133                 /* child */
134                 execvp(argv[0], (char *const *)argv);
135                 _exit(-1);
136         default:
137                 /* parent */
138                 break;
139         }
140         if (waitpid(pid, &status, 0) == -1) {
141                 perror("waitpid failed");
142                 return -1;
143         }
144         if (WIFSIGNALED(status)) {
145                 perror("signal");
146                 return -1;
147         }
148         if (!WIFEXITED(status)) {
149                 /* shouldn't happen */
150                 perror("should not happen");
151                 return -1;
152         }
153         return WEXITSTATUS(status);
154 }
155
156 static void __error_to_string(int errnumber, char **errstr)
157 {
158         if (errstr == NULL)
159                 return;
160         switch (errnumber) {
161         case PKGCMD_ERR_PACKAGE_NOT_FOUND:
162                 *errstr = PKGCMD_ERR_PACKAGE_NOT_FOUND_STR;
163                 break;
164         case PKGCMD_ERR_PACKAGE_INVALID:
165                 *errstr = PKGCMD_ERR_PACKAGE_INVALID_STR;
166                 break;
167         case PKGCMD_ERR_PACKAGE_LOWER_VERSION:
168                 *errstr = PKGCMD_ERR_PACKAGE_LOWER_VERSION_STR;
169                 break;
170         case PKGCMD_ERR_PACKAGE_EXECUTABLE_NOT_FOUND:
171                 *errstr = PKGCMD_ERR_PACKAGE_EXECUTABLE_NOT_FOUND_STR;
172                 break;
173         case PKGCMD_ERR_MANIFEST_INVALID:
174                 *errstr = PKGCMD_ERR_MANIFEST_INVALID_STR;
175                 break;
176         case PKGCMD_ERR_CONFIG_NOT_FOUND:
177                 *errstr = PKGCMD_ERR_CONFIG_NOT_FOUND_STR;
178                 break;
179         case PKGCMD_ERR_CONFIG_INVALID:
180                 *errstr = PKGCMD_ERR_CONFIG_INVALID_STR;
181                 break;
182         case PKGCMD_ERR_SIGNATURE_NOT_FOUND:
183                 *errstr = PKGCMD_ERR_SIGNATURE_NOT_FOUND_STR;
184                 break;
185         case PKGCMD_ERR_SIGNATURE_INVALID:
186                 *errstr = PKGCMD_ERR_SIGNATURE_INVALID_STR;
187                 break;
188         case PKGCMD_ERR_SIGNATURE_VERIFICATION_FAILED:
189                 *errstr = PKGCMD_ERR_SIGNATURE_VERIFICATION_FAILED_STR;
190                 break;
191         case PKGCMD_ERR_ROOT_CERTIFICATE_NOT_FOUND:
192                 *errstr = PKGCMD_ERR_ROOT_CERTIFICATE_NOT_FOUND_STR;
193                 break;
194         case PKGCMD_ERR_CERTIFICATE_INVALID:
195                 *errstr = PKGCMD_ERR_CERTIFICATE_INVALID_STR;
196                 break;
197         case PKGCMD_ERR_CERTIFICATE_CHAIN_VERIFICATION_FAILED:
198                 *errstr = PKGCMD_ERR_CERTIFICATE_CHAIN_VERIFICATION_FAILED_STR;
199                 break;
200         case PKGCMD_ERR_CERTIFICATE_EXPIRED:
201                 *errstr = PKGCMD_ERR_CERTIFICATE_EXPIRED_STR;
202                 break;
203         case PKGCMD_ERR_INVALID_PRIVILEGE:
204                 *errstr = PKGCMD_ERR_INVALID_PRIVILEGE_STR;
205                 break;
206         case PKGCMD_ERR_MENU_ICON_NOT_FOUND:
207                 *errstr = PKGCMD_ERR_MENU_ICON_NOT_FOUND_STR;
208                 break;
209         case PKGCMD_ERR_FATAL_ERROR:
210                 *errstr = PKGCMD_ERR_FATAL_ERROR_STR;
211                 break;
212         case PKGCMD_ERR_OUT_OF_STORAGE:
213                 *errstr = PKGCMD_ERR_OUT_OF_STORAGE_STR;
214                 break;
215         case PKGCMD_ERR_OUT_OF_MEMORY:
216                 *errstr = PKGCMD_ERR_OUT_OF_MEMORY_STR;
217                 break;
218         case PKGCMD_ERR_ARGUMENT_INVALID:
219                 *errstr = PKGCMD_ERR_ARGUMENT_INVALID_STR;
220                 break;
221         default:
222                 *errstr = PKGCMD_ERR_UNKNOWN_STR;
223                 break;
224         }
225 }
226
227 static void __add_op_cbinfo(pkgmgr_client_t * pc, int request_id,
228                             const char *req_key, pkgmgr_handler event_cb,
229                             void *data)
230 {
231         req_cb_info *cb_info;
232         req_cb_info *current;
233         req_cb_info *prev;
234
235         cb_info = (req_cb_info *) calloc(1, sizeof(req_cb_info));
236         if (cb_info == NULL) {
237                 _LOGD("calloc failed");
238                 return;
239         }
240         cb_info->request_id = request_id;
241         cb_info->req_key = strdup(req_key);
242         cb_info->event_cb = event_cb;
243         cb_info->data = data;
244         cb_info->next = NULL;
245
246         if (pc->info.request.rhead == NULL)
247                 pc->info.request.rhead = cb_info;
248         else {
249                 current = prev = pc->info.request.rhead;
250                 while (current) {
251                         prev = current;
252                         current = current->next;
253                 }
254
255                 prev->next = cb_info;
256         }
257 }
258
259 static req_cb_info *__find_op_cbinfo(pkgmgr_client_t *pc, const char *req_key)
260 {
261         req_cb_info *tmp;
262
263         tmp = pc->info.request.rhead;
264
265         if (tmp == NULL) {
266                 _LOGE("tmp is NULL");
267                 return NULL;
268         }
269
270         _LOGD("tmp->req_key %s, req_key %s", tmp->req_key, req_key);
271
272         while (tmp) {
273                 if (strncmp(tmp->req_key, req_key, strlen(tmp->req_key)) == 0)
274                         return tmp;
275                 tmp = tmp->next;
276         }
277         return NULL;
278 }
279
280 static void __remove_op_cbinfo(pkgmgr_client_t *pc, req_cb_info *info)
281 {
282         req_cb_info *tmp;
283
284         if (pc == NULL || pc->info.request.rhead == NULL || info == NULL)
285                 return;
286
287         tmp = pc->info.request.rhead;
288         while (tmp) {
289                 if (tmp->next == info) {
290                         tmp->next = info->next;
291                         free(info);
292                         return;
293                 }
294                 tmp = tmp->next;
295         }
296 }
297
298
299 static void __add_stat_cbinfo(pkgmgr_client_t *pc, int request_id,
300                               pkgmgr_handler event_cb, void *data)
301 {
302         listen_cb_info *cb_info;
303         listen_cb_info *current;
304         listen_cb_info *prev;
305
306         cb_info = (listen_cb_info *) calloc(1, sizeof(listen_cb_info));
307         if (cb_info == NULL) {
308                 _LOGD("calloc failed");
309                 return;
310         }
311         cb_info->request_id = request_id;
312         cb_info->event_cb = event_cb;
313         cb_info->data = data;
314         cb_info->next = NULL;
315
316         /* TODO - check the order of callback - FIFO or LIFO => Should be changed to LIFO */
317         if (pc->info.listening.lhead == NULL)
318                 pc->info.listening.lhead = cb_info;
319         else {
320                 current = prev = pc->info.listening.lhead;
321                 while (current) {
322                         prev = current;
323                         current = current->next;
324                 }
325
326                 prev->next = cb_info;
327         }
328 }
329
330 static void __operation_callback(void *cb_data, const char *req_id,
331                                  const char *pkg_type, const char *pkgid,
332                                  const char *key, const char *val)
333 {
334         pkgmgr_client_t *pc;
335         req_cb_info *cb_info;
336
337         _LOGD("__operation_callback() req_id[%s] pkg_type[%s] pkgid[%s]"
338               "key[%s] val[%s]\n", req_id, pkg_type, pkgid, key, val);
339
340         pc = (pkgmgr_client_t *) cb_data;
341
342         /* find callback info */
343         cb_info = __find_op_cbinfo(pc, req_id);
344         if (cb_info == NULL)
345                 return;
346
347         _LOGD("__find_op_cbinfo");
348
349         /* call callback */
350         if (cb_info->event_cb) {
351                 cb_info->event_cb(cb_info->request_id, pkg_type, pkgid, key,
352                                   val, NULL, cb_info->data);
353                 _LOGD("event_cb is called");
354         }
355
356         /*remove callback for last call 
357            if (strcmp(key, "end") == 0) {
358            __remove_op_cbinfo(pc, cb_info);
359            _LOGD("__remove_op_cbinfo");
360            }
361          */
362
363         return;
364 }
365
366 static void __status_callback(void *cb_data, const char *req_id,
367                               const char *pkg_type, const char *pkgid,
368                               const char *key, const char *val)
369 {
370         pkgmgr_client_t *pc;
371         listen_cb_info *tmp;
372
373         _LOGD("__status_callback() req_id[%s] pkg_type[%s] pkgid[%s]"
374               "key[%s] val[%s]\n", req_id, pkg_type, pkgid, key, val);
375
376         pc = (pkgmgr_client_t *) cb_data;
377
378         tmp = pc->info.listening.lhead;
379         while (tmp) {
380                 if (tmp->event_cb(tmp->request_id, pkg_type, pkgid, key, val,
381                                   NULL, tmp->data) != 0)
382                         break;
383                 tmp = tmp->next;
384         }
385
386         return;
387 }
388
389 static char *__get_req_key(const char *pkg_path)
390 {
391         struct timeval tv;
392         long curtime;
393         char timestr[PKG_STRING_LEN_MAX];
394         char *str_req_key;
395         int size;
396
397         gettimeofday(&tv, NULL);
398         curtime = tv.tv_sec * 1000000 + tv.tv_usec;
399         snprintf(timestr, sizeof(timestr), "%ld", curtime);
400
401         size = strlen(pkg_path) + strlen(timestr) + 2;
402         str_req_key = (char *)calloc(size, sizeof(char));
403         if (str_req_key == NULL) {
404                 _LOGD("calloc failed");
405                 return NULL;
406         }
407         snprintf(str_req_key, size, "%s_%s", pkg_path, timestr);
408
409         return str_req_key;
410 }
411
412 static char *__get_type_from_path(const char *pkg_path)
413 {
414         int ret;
415         char mimetype[255] = { '\0', };
416         char extlist[256] = { '\0', };
417         char *pkg_type;
418
419         ret = _get_mime_from_file(pkg_path, mimetype, sizeof(mimetype));
420         if (ret) {
421                 _LOGE("_get_mime_from_file() failed - error code[%d]\n",
422                       ret);
423                 return NULL;
424         }
425
426         ret = _get_mime_extension(mimetype, extlist, sizeof(extlist));
427         if (ret) {
428                 _LOGE("_get_mime_extension() failed - error code[%d]\n",
429                       ret);
430                 return NULL;
431         }
432
433         if (strlen(extlist) == 0)
434                 return NULL;
435
436         if (strchr(extlist, ',')) {
437                 extlist[strlen(extlist) - strlen(strchr(extlist, ','))] = '\0';
438         }
439         pkg_type = strchr(extlist, '.') + 1;
440         return strdup(pkg_type);
441 }
442
443 static inline int __pkgmgr_read_proc(const char *path, char *buf, int size)
444 {
445         int fd;
446         int ret;
447
448         if (buf == NULL || path == NULL)
449                 return -1;
450
451         fd = open(path, O_RDONLY);
452         if (fd < 0)
453                 return -1;
454
455         ret = read(fd, buf, size - 1);
456         if (ret <= 0) {
457                 close(fd);
458                 return -1;
459         } else
460                 buf[ret] = 0;
461
462         close(fd);
463
464         return ret;
465 }
466
467 static inline int __pkgmgr_find_pid_by_cmdline(const char *dname,
468                                       const char *cmdline, const char *apppath)
469 {
470         int pid = 0;
471
472         if (strncmp(cmdline, apppath, PKG_STRING_LEN_MAX-1) == 0) {
473                 pid = atoi(dname);
474                 if (pid != getpgid(pid))
475                         pid = 0;
476         }
477
478         return pid;
479 }
480
481
482 static int __pkgmgr_proc_iter_kill_cmdline(const char *apppath)
483 {
484         DIR *dp;
485         struct dirent *dentry;
486         int pid;
487         int ret;
488         char buf[PKG_STRING_LEN_MAX];
489
490         dp = opendir("/proc");
491         if (dp == NULL) {
492                 return -1;
493         }
494
495         while ((dentry = readdir(dp)) != NULL) {
496                 if (!isdigit(dentry->d_name[0]))
497                         continue;
498
499                 snprintf(buf, sizeof(buf), "/proc/%s/cmdline", dentry->d_name);
500                 ret = __pkgmgr_read_proc(buf, buf, sizeof(buf));
501                 if (ret <= 0)
502                         continue;
503
504                 pid = __pkgmgr_find_pid_by_cmdline(dentry->d_name, buf, apppath);
505
506                 if (pid > 0) {
507                         int pgid;
508
509                         pgid = getpgid(pid);
510                         if (pgid <= 1) {
511                                 closedir(dp);
512                                 return -1;
513                         }
514
515                         if (killpg(pgid, SIGKILL) < 0) {
516                                 closedir(dp);
517                                 return -1;
518                         }
519                 }
520         }
521
522         closedir(dp);
523         return 0;
524 }
525
526
527 static int __app_list_cb (const pkgmgr_appinfo_h handle,
528                                                 void *user_data)
529 {
530         char *exec = NULL;
531         pkgmgr_appinfo_get_exec(handle, &exec);
532
533         __pkgmgr_proc_iter_kill_cmdline(exec);
534
535         return 0;
536 }
537
538 static int __sync_process(char *req_key)
539 {
540         int ret =0;
541         char info_file[PKG_STRING_LEN_MAX] = {'\0', };
542         int result = 0;
543         int check_cnt = 0;
544         FILE *fp;
545         char buffer[PKG_ARGC_MAX] = {'\0', };
546
547         snprintf(info_file, PKG_STRING_LEN_MAX, "%s/%s", PKG_TMP_PATH, req_key);
548         while(1)
549         {
550                 check_cnt ++;
551
552                 vconf_get_int(VCONFKEY_PKGMGR_STATUS, &result);
553                 if (result < 0) {
554                         _LOGD("file is not generated yet.... wait\n");
555                         usleep(10 * 1000);      /* 10ms sleep*/
556                 } else {
557                         _LOGD("info_file file is generated, result = %d. \n", result);
558                         break;
559                 }
560
561                 if (check_cnt > 500) {  /* 5s time over*/
562                         _LOGD("wait time over!!\n");
563                         break;
564                 }
565         }
566
567         vconf_set_int(VCONFKEY_PKGMGR_STATUS, -1);
568
569         return result;
570 }
571 static int __csc_process(const char *csc_path, char *result_path)
572 {
573         int ret = 0;
574         int cnt = 0;
575         int count = 0;
576         int csc_fail = 0;
577         int fd = 0;
578         char *pkgtype = NULL;
579         char *des = NULL;
580         char buf[PKG_STRING_LEN_MAX] = {0,};
581         char type_buf[1024] = { 0 };
582         char des_buf[1024] = { 0 };
583         dictionary *csc = NULL;
584         FILE* file = NULL;
585
586         csc = iniparser_load(csc_path);
587         retvm_if(csc == NULL, PKGMGR_R_EINVAL, "cannot open parse file [%s]", csc_path);
588
589         file = fopen(result_path, "w");
590         tryvm_if(file == NULL, ret = PKGMGR_R_EINVAL, "cannot open result file [%s]", result_path);
591
592         count = iniparser_getint(csc, "csc packages:count", -1);
593         tryvm_if(count == 0, ret = PKGMGR_R_ERROR, "csc [%s] dont have packages", csc_path);
594
595         snprintf(buf, PKG_STRING_LEN_MAX, "[result]\n");
596         fwrite(buf, 1, strlen(buf), file);
597         snprintf(buf, PKG_STRING_LEN_MAX, "count = %d\n", count);
598         fwrite(buf, 1, strlen(buf), file);
599
600         for(cnt = 1 ; cnt <= count ; cnt++)
601         {
602                 snprintf(type_buf, PKG_STRING_LEN_MAX - 1, "csc packages:type_%03d", cnt);
603                 snprintf(des_buf, PKG_STRING_LEN_MAX - 1, "csc packages:description_%03d", cnt);
604
605                 pkgtype = iniparser_getstr(csc, type_buf);
606                 des = iniparser_getstr(csc, des_buf);
607                 ret = 0;
608
609                 if (pkgtype == NULL) {
610                         csc_fail++;
611                         snprintf(buf, PKG_STRING_LEN_MAX, "%s = Fail to get pkgtype\n", type_buf);
612                         fwrite(buf, 1, strlen(buf), file);
613                         continue;
614                 } else if (des == NULL) {
615                         csc_fail++;
616                         snprintf(buf, PKG_STRING_LEN_MAX, "%s = Fail to get description\n", des_buf);
617                         fwrite(buf, 1, strlen(buf), file);
618                         continue;
619                 }
620
621                 snprintf(buf, PKG_STRING_LEN_MAX, "type_%03d = %s\n", cnt, pkgtype);
622                 fwrite(buf, 1, strlen(buf), file);
623                 snprintf(buf, PKG_STRING_LEN_MAX, "description_%03d = %s\n", cnt, des);
624                 fwrite(buf, 1, strlen(buf), file);
625
626                 if (strcmp(pkgtype, "tpk") == 0) {
627                         const char *ospinstaller_argv[] = { "/usr/bin/osp-installer", "-c", des, NULL };
628                         ret = __xsystem(ospinstaller_argv);
629                 } else if (strcmp(pkgtype, "wgt")== 0) {
630                         const char *wrtinstaller_argv[] = { "/usr/bin/wrt-installer", "-c", des, NULL };
631                         ret = __xsystem(wrtinstaller_argv);
632                 } else {
633                         csc_fail++;
634                         ret = -1;
635                 }
636
637                 if (ret != 0) {
638                         char *errstr = NULL;
639                         __error_to_string(ret, &errstr);
640                         snprintf(buf, PKG_STRING_LEN_MAX, "result_%03d = fail[%s]\n", cnt, errstr);
641                 }
642                 else
643                         snprintf(buf, PKG_STRING_LEN_MAX, "result_%03d = success\n", cnt);
644
645                 fwrite(buf, 1, strlen(buf), file);
646         }
647
648 catch:
649         iniparser_freedict(csc);
650         if (file != NULL) {
651                 fflush(file);
652                 fd = fileno(file);
653                 fsync(fd);
654                 fclose(file);
655         }
656         return ret;
657 }
658
659 static int __get_size_process(pkgmgr_client * pc, const char *pkgid, pkgmgr_getsize_type get_type, pkgmgr_handler event_cb, void *data)
660 {
661         char *req_key = NULL;
662         int req_id = 0;
663         int ret =0;
664         pkgmgrinfo_pkginfo_h handle;
665         char *pkgtype = NULL;
666         char *installer_path = NULL;
667         char *argv[PKG_ARGC_MAX] = { NULL, };
668         char *args = NULL;
669         int argcnt = 0;
670         int len = 0;
671         char *temp = NULL;
672         int i = 0;
673         char buf[128] = {'\0'};
674         char *cookie = NULL;
675
676         pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
677         retvm_if(mpc->ctype != PC_REQUEST, PKGMGR_R_EINVAL, "mpc->ctype is not PC_REQUEST\n");
678
679         ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle);
680         retvm_if(ret < 0, PKGMGR_R_ERROR, "pkgmgr_pkginfo_get_pkginfo failed");
681
682         ret = pkgmgrinfo_pkginfo_get_type(handle, &pkgtype);
683         tryvm_if(ret < 0, ret = PKGMGR_R_ERROR, "pkgmgr_pkginfo_get_type failed");
684
685         installer_path = _get_backend_path_with_type(pkgtype);
686         req_key = __get_req_key(pkgid);
687         req_id = _get_request_id();
688
689         snprintf(buf, 128, "%d", get_type);
690         argv[argcnt++] = installer_path;
691         /* argv[1] */
692         argv[argcnt++] = strdup("-k");
693         /* argv[2] */
694         argv[argcnt++] = req_key;
695         /* argv[3] */
696         argv[argcnt++] = strdup("-d");
697         /* argv[4] */
698         argv[argcnt++] = strdup(pkgid);
699         /* argv[5] */
700         argv[argcnt++] = strdup("-t");
701         /* argv[6] */
702         argv[argcnt++] = strdup(buf);
703
704         /*** add quote in all string for special charactor like '\n'***   FIX */
705         for (i = 0; i < argcnt; i++) {
706                 temp = g_shell_quote(argv[i]);
707                 len += (strlen(temp) + 1);
708                 g_free(temp);
709         }
710
711         args = (char *)calloc(len, sizeof(char));
712         tryvm_if(args == NULL, ret = PKGMGR_R_EINVAL, "installer_path fail");
713
714         strncpy(args, argv[0], len - 1);
715
716         for (i = 1; i < argcnt; i++) {
717                 strncat(args, " ", strlen(" "));
718                 temp = g_shell_quote(argv[i]);
719                 strncat(args, temp, strlen(temp));
720                 g_free(temp);
721         }
722         _LOGD("[args] %s [len] %d\n", args, len);
723
724         /* get cookie from security-server */
725         cookie = __get_cookie_from_security_server();
726         tryvm_if(cookie == NULL, ret = PKGMGR_R_ERROR, "__get_cookie_from_security_server is NULL");
727
728         /* request */
729         ret = comm_client_request(mpc->info.request.cc, req_key, COMM_REQ_GET_SIZE, pkgtype, pkgid, args, cookie, 1);
730         if (ret < 0)
731                 _LOGE("comm_client_request failed, ret=%d\n", ret);
732
733         ret = __sync_process(req_key);
734         if (ret < 0)
735                 _LOGE("get size failed, ret=%d\n", ret);
736
737 catch:
738         for (i = 0; i < argcnt; i++)
739                 free(argv[i]);
740
741         if(args)
742                 free(args);
743         if (cookie)
744                 free(cookie);
745
746         pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
747         return ret;
748 }
749
750 static int __move_pkg_process(pkgmgr_client * pc, const char *pkgid, pkgmgr_move_type move_type, pkgmgr_handler event_cb, void *data)
751 {
752         char *req_key = NULL;
753         int req_id = 0;
754         int ret =0;
755         pkgmgrinfo_pkginfo_h handle;
756         char *pkgtype = NULL;
757         char *installer_path = NULL;
758         char *argv[PKG_ARGC_MAX] = { NULL, };
759         char *args = NULL;
760         int argcnt = 0;
761         int len = 0;
762         char *temp = NULL;
763         int i = 0;
764         char buf[128] = {'\0'};
765         char info_file[PKG_STRING_LEN_MAX] = {'\0', };
766         char *cookie = NULL;
767
768         pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
769         retvm_if(mpc->ctype != PC_REQUEST, PKGMGR_R_EINVAL, "mpc->ctype is not PC_REQUEST\n");
770
771         ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle);
772         retvm_if(ret < 0, PKGMGR_R_ERROR, "pkgmgr_pkginfo_get_pkginfo failed");
773
774         ret = pkgmgrinfo_pkginfo_get_type(handle, &pkgtype);
775         tryvm_if(ret < 0, ret = PKGMGR_R_ERROR, "pkgmgr_pkginfo_get_type failed");
776
777         installer_path = _get_backend_path_with_type(pkgtype);
778         req_key = __get_req_key(pkgid);
779         req_id = _get_request_id();
780
781         /* generate argv */
782         snprintf(buf, 128, "%d", move_type);
783         /* argv[0] installer path */
784         argv[argcnt++] = installer_path;
785         /* argv[1] */
786         argv[argcnt++] = strdup("-k");
787         /* argv[2] */
788         argv[argcnt++] = req_key;
789         /* argv[3] */
790         argv[argcnt++] = strdup("-m");
791         /* argv[4] */
792         argv[argcnt++] = strdup(pkgid);
793         /* argv[5] */
794         argv[argcnt++] = strdup("-t");
795         /* argv[6] */
796         argv[argcnt++] = strdup(buf);
797         /* argv[7] */
798         argv[argcnt++] = strdup("-q");
799
800         /*** add quote in all string for special charactor like '\n'***   FIX */
801         for (i = 0; i < argcnt; i++) {
802                 temp = g_shell_quote(argv[i]);
803                 len += (strlen(temp) + 1);
804                 g_free(temp);
805         }
806
807         args = (char *)calloc(len, sizeof(char));
808         tryvm_if(args == NULL, ret = PKGMGR_R_EINVAL, "installer_path fail");
809
810         strncpy(args, argv[0], len - 1);
811
812         for (i = 1; i < argcnt; i++) {
813                 strncat(args, " ", strlen(" "));
814                 temp = g_shell_quote(argv[i]);
815                 strncat(args, temp, strlen(temp));
816                 g_free(temp);
817         }
818         _LOGD("[args] %s [len] %d\n", args, len);
819
820         /* get cookie from security-server */
821         cookie = __get_cookie_from_security_server();
822         tryvm_if(cookie == NULL, ret = PKGMGR_R_ERROR, "__get_cookie_from_security_server is NULL");
823
824         /* 6. request */
825         ret = comm_client_request(mpc->info.request.cc, req_key, COMM_REQ_TO_MOVER, pkgtype, pkgid, args, cookie, 1);
826         if (ret < 0)
827                 _LOGE("comm_client_request failed, ret=%d\n", ret);
828
829         snprintf(info_file, PKG_STRING_LEN_MAX, "app2sd_%s", pkgid);
830         ret = __sync_process(info_file);
831         if (ret != 0)
832                 _LOGE("move pkg failed, ret=%d\n", ret);
833
834 catch:
835         for (i = 0; i < argcnt; i++)
836                 free(argv[i]);
837
838         if(args)
839                 free(args);
840         if (cookie)
841                 free(cookie);
842
843         pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
844         return ret;
845 }
846
847 static int __kill_app_process(pkgmgr_client * pc, const char *pkgid)
848 {
849         const char *pkgtype;
850         char *req_key;
851         char *cookie = NULL;
852         int ret;
853         pkgmgrinfo_pkginfo_h handle;
854
855         /* Check for NULL value of pc */
856         pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
857         retvm_if(mpc->ctype != PC_REQUEST, PKGMGR_R_EINVAL, "mpc->ctype is not PC_REQUEST\n");
858
859         ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle);
860         retvm_if(ret < 0, PKGMGR_R_ERROR, "pkgmgr_pkginfo_get_pkginfo failed");
861
862         ret = pkgmgrinfo_pkginfo_get_type(handle, &pkgtype);
863         tryvm_if(ret < 0, ret = PKGMGR_R_ERROR, "pkgmgr_pkginfo_get_type failed");
864
865         /* 2. generate req_key */
866         req_key = __get_req_key(pkgid);
867
868         /* 3. request activate */
869         ret = comm_client_request(mpc->info.request.cc, req_key, COMM_REQ_KILL_APP, pkgtype, pkgid, NULL, NULL, 1);
870         if (ret < 0)
871                 _LOGE("request failed, ret=%d\n", ret);
872
873 catch:
874         free(req_key);
875         pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
876
877         return ret;
878
879 }
880
881 API pkgmgr_client *pkgmgr_client_new(client_type ctype)
882 {
883         pkgmgr_client_t *pc = NULL;
884         int ret = -1;
885
886         if (ctype != PC_REQUEST && ctype != PC_LISTENING
887             && ctype != PC_BROADCAST)
888                 return NULL;
889
890         /* Allocate memory for ADT:pkgmgr_client */
891         pc = calloc(1, sizeof(pkgmgr_client_t));
892         if (pc == NULL) {
893                 _LOGE("No memory");
894                 return NULL;
895         }
896
897         /* Manage pc */
898         pc->ctype = ctype;
899
900         if (pc->ctype == PC_REQUEST) {
901                 pc->info.request.cc = comm_client_new();
902                 if (pc->info.request.cc == NULL) {
903                         _LOGE("client creation failed");
904                         goto err;
905                 }
906                 ret = comm_client_set_status_callback(pc->info.request.cc,
907                                                       __operation_callback, pc);
908                 if (ret < 0) {
909                         _LOGE("comm_client_set_status_callback() failed - %d",
910                               ret);
911                         goto err;
912                 }
913         } else if (pc->ctype == PC_LISTENING) {
914                 pc->info.listening.cc = comm_client_new();
915                 if (pc->info.listening.cc == NULL) {
916                         _LOGE("client creation failed");
917                         goto err;
918                 }
919                 ret = comm_client_set_status_callback(pc->info.listening.cc,
920                                                       __status_callback, pc);
921                 if (ret < 0) {
922                         _LOGE("comm_client_set_status_callback() failed - %d",
923                               ret);
924                         goto err;
925                 }
926         } else if (pc->ctype == PC_BROADCAST) {
927                 pc->info.broadcast.bc = comm_status_broadcast_server_connect();
928                 if (pc->info.broadcast.bc == NULL) {
929                         _LOGE("client creation failed");
930                         goto err;
931                 }
932                 ret = 0;
933         }
934
935         return (pkgmgr_client *) pc;
936
937  err:
938         if (pc)
939                 free(pc);
940         return NULL;
941 }
942
943 API int pkgmgr_client_free(pkgmgr_client *pc)
944 {
945         int ret = -1;
946         pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
947
948         if (mpc == NULL) {
949                 _LOGE("Invalid argument");
950                 return PKGMGR_R_EINVAL;
951         }
952
953         if (mpc->ctype == PC_REQUEST) {
954                 req_cb_info *tmp;
955                 req_cb_info *prev;
956                 for (tmp = mpc->info.request.rhead; tmp;) {
957                         prev = tmp;
958                         tmp = tmp->next;
959                         free(prev);
960                 }
961
962                 ret = comm_client_free(mpc->info.request.cc);
963                 if (ret < 0) {
964                         _LOGE("comm_client_free() failed - %d", ret);
965                         goto err;
966                 }
967         } else if (mpc->ctype == PC_LISTENING) {
968                 listen_cb_info *tmp;
969                 listen_cb_info *prev;
970                 for (tmp = mpc->info.listening.lhead; tmp;) {
971                         prev = tmp;
972                         tmp = tmp->next;
973                         free(prev);
974                 }
975
976                 ret = comm_client_free(mpc->info.listening.cc);
977                 if (ret < 0) {
978                         _LOGE("comm_client_free() failed - %d", ret);
979                         goto err;
980                 }
981         } else if (mpc->ctype == PC_BROADCAST) {
982                 comm_status_broadcast_server_disconnect(mpc->info.broadcast.bc);
983                 ret = 0;
984         } else {
985                 _LOGE("Invalid client type\n");
986                 return PKGMGR_R_EINVAL;
987         }
988
989         free(mpc);
990         mpc = NULL;
991         return PKGMGR_R_OK;
992
993  err:
994         if (mpc) {
995                 free(mpc);
996                 mpc = NULL;
997         }
998         return PKGMGR_R_ERROR;
999 }
1000
1001 API int pkgmgr_client_install(pkgmgr_client * pc, const char *pkg_type,
1002                               const char *descriptor_path, const char *pkg_path,
1003                               const char *optional_file, pkgmgr_mode mode,
1004                               pkgmgr_handler event_cb, void *data)
1005 {
1006         char *pkgtype = NULL;
1007         char *installer_path = NULL;
1008         char *req_key = NULL;
1009         int req_id = 0;
1010         int i = 0;
1011         char *argv[PKG_ARGC_MAX] = { NULL, };
1012         char *args = NULL;
1013         int argcnt = 0;
1014         int len = 0;
1015         char *temp = NULL;
1016         int ret = 0;
1017         char *cookie = NULL;
1018
1019         /* Check for NULL value of pc */
1020         retvm_if(pc == NULL, PKGMGR_R_EINVAL, "package manager client handle is NULL");
1021
1022         /* 0. check the pc type */
1023         pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
1024         retvm_if(mpc->ctype != PC_REQUEST, PKGMGR_R_EINVAL, "mpc->ctype is not PC_REQUEST");
1025
1026         /* 1. check argument */
1027         if (descriptor_path) {
1028                 retvm_if(strlen(descriptor_path) >= PKG_STRING_LEN_MAX, PKGMGR_R_EINVAL, "descriptor_path over PKG_STRING_LEN_MAX");
1029                 retvm_if(access(descriptor_path, F_OK) != 0, PKGMGR_R_EINVAL, "descriptor_path access fail");
1030         }
1031
1032         retvm_if(pkg_path == NULL, PKGMGR_R_EINVAL, "pkg_path is NULL");
1033         retvm_if(strlen(pkg_path) >= PKG_STRING_LEN_MAX, PKGMGR_R_EINVAL, "pkg_path over PKG_STRING_LEN_MAX");
1034         retvm_if(access(pkg_path, F_OK) != 0, PKGMGR_R_EINVAL, "pkg_path access fail");
1035
1036         if (optional_file)
1037                 retvm_if(strlen(optional_file) >= PKG_STRING_LEN_MAX, PKGMGR_R_EINVAL, "optional_file over PKG_STRING_LEN_MAX");
1038
1039         /* 2. get installer path using pkg_path */
1040         if (pkg_type) {
1041                 installer_path = _get_backend_path_with_type(pkg_type);
1042                 pkgtype = strdup(pkg_type);
1043         } else {
1044                 installer_path = _get_backend_path(pkg_path);
1045                 pkgtype = __get_type_from_path(pkg_path);
1046         }
1047         if (installer_path == NULL) {
1048                 free(pkgtype);
1049                 _LOGE("installer_path is NULL\n");
1050                 return PKGMGR_R_EINVAL;
1051         }
1052
1053         /* 3. generate req_key */
1054         req_key = __get_req_key(pkg_path);
1055
1056         /* 4. add callback info - add callback info to pkgmgr_client */
1057         req_id = _get_request_id();
1058         __add_op_cbinfo(mpc, req_id, req_key, event_cb, data);
1059
1060         /* 5. generate argv */
1061
1062         /*  argv[0] installer path */
1063         argv[argcnt++] = installer_path;
1064         /* argv[1] */
1065         argv[argcnt++] = strdup("-k");
1066         /* argv[2] */
1067         argv[argcnt++] = req_key;
1068         /* argv[3] */
1069         argv[argcnt++] = strdup("-i");
1070         /* argv[(4)] if exists */
1071         if (descriptor_path)
1072                 argv[argcnt++] = strdup(descriptor_path);
1073         /* argv[4] */
1074         argv[argcnt++] = strdup(pkg_path);
1075         /* argv[(5)] if exists */
1076         if (optional_file){
1077                 argv[argcnt++] = strdup("-o");
1078                 argv[argcnt++] = strdup(optional_file);
1079         }
1080         /* argv[6] -q option should be located at the end of command !! */
1081         if (mode == PM_QUIET)
1082                 argv[argcnt++] = strdup("-q");
1083
1084         /*** add quote in all string for special charactor like '\n'***   FIX */
1085         for (i = 0; i < argcnt; i++) {
1086                 temp = g_shell_quote(argv[i]);
1087                 len += (strlen(temp) + 1);
1088                 g_free(temp);
1089         }
1090
1091         args = (char *)calloc(len, sizeof(char));
1092         tryvm_if(args == NULL, ret = PKGMGR_R_ERROR, "calloc failed");
1093
1094         strncpy(args, argv[0], len - 1);
1095
1096         for (i = 1; i < argcnt; i++) {
1097                 strncat(args, " ", strlen(" "));
1098                 temp = g_shell_quote(argv[i]);
1099                 strncat(args, temp, strlen(temp));
1100                 g_free(temp);
1101         }
1102         _LOGD("[args] %s [len] %d\n", args, len);
1103
1104         /* get cookie from security-server */
1105         cookie = __get_cookie_from_security_server();
1106         tryvm_if(cookie == NULL, ret = PKGMGR_R_ERROR, "__get_cookie_from_security_server is NULL");
1107         /******************* end of quote ************************/
1108
1109         /* 6. request install */
1110         ret = comm_client_request(mpc->info.request.cc, req_key, COMM_REQ_TO_INSTALLER, pkgtype, pkg_path, args, cookie, 1);
1111         tryvm_if(ret < 0, ret = PKGMGR_R_ECOMM, "request failed, ret=%d", ret);
1112
1113         ret = req_id;
1114
1115 catch:
1116         for (i = 0; i < argcnt; i++)
1117                 free(argv[i]);
1118
1119         if (args)
1120                 free(args);
1121         if (pkgtype)
1122                 free(pkgtype);
1123         if (cookie)
1124                 free(cookie);
1125
1126         return ret;
1127 }
1128
1129 API int pkgmgr_client_reinstall(pkgmgr_client * pc, const char *pkg_type, const char *pkgid,
1130                                   const char *optional_file, pkgmgr_mode mode,
1131                               pkgmgr_handler event_cb, void *data)
1132 {
1133         char *pkgtype = NULL;
1134         char *installer_path = NULL;
1135         char *req_key = NULL;
1136         int req_id = 0;
1137         int i = 0;
1138         char *argv[PKG_ARGC_MAX] = { NULL, };
1139         char *args = NULL;
1140         int argcnt = 0;
1141         int len = 0;
1142         char *temp = NULL;
1143         int ret = 0;
1144         char *cookie = NULL;
1145
1146         /* Check for NULL value of pc */
1147         retvm_if(pc == NULL, PKGMGR_R_EINVAL, "package manager client handle is NULL\n");
1148
1149         pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
1150
1151         /* 0. check the pc type */
1152         retv_if(mpc->ctype != PC_REQUEST, PKGMGR_R_EINVAL);
1153
1154
1155         /* 1. check argument */
1156         retv_if(pkgid == NULL, PKGMGR_R_EINVAL);
1157         retv_if(strlen(pkgid) >= PKG_STRING_LEN_MAX, PKGMGR_R_EINVAL);
1158         if (optional_file) {
1159                 if (strlen(optional_file) >= PKG_STRING_LEN_MAX)
1160                         return PKGMGR_R_EINVAL;
1161         }
1162
1163         /* 2. get installer path using pkg_path */
1164         installer_path = _get_backend_path_with_type(pkg_type);
1165         pkgtype = strdup(pkg_type);
1166         tryvm_if(installer_path == NULL, ret = PKGMGR_R_EINVAL, "installer_path is null");
1167
1168         /* 3. generate req_key */
1169         req_key = __get_req_key(pkgid);
1170
1171         /* 4. add callback info - add callback info to pkgmgr_client */
1172         req_id = _get_request_id();
1173         __add_op_cbinfo(mpc, req_id, req_key, event_cb, data);
1174
1175         /* 5. generate argv */
1176
1177         /*  argv[0] installer path */
1178         argv[argcnt++] = installer_path;
1179         /* argv[1] */
1180         argv[argcnt++] = strdup("-k");
1181         /* argv[2] */
1182         argv[argcnt++] = req_key;
1183         /* argv[3] */
1184         argv[argcnt++] = strdup("-r");
1185         /* argv[4] */
1186         argv[argcnt++] = strdup(pkgid);
1187         /* argv[(5)] if exists */
1188         if (optional_file){
1189                 argv[argcnt++] = strdup("-o");
1190                 argv[argcnt++] = strdup(optional_file);
1191         }
1192
1193         /* argv[5] -q option should be located at the end of command !! */
1194         if (mode == PM_QUIET)
1195                 argv[argcnt++] = strdup("-q");
1196
1197         /*** add quote in all string for special charactor like '\n'***   FIX */
1198         for (i = 0; i < argcnt; i++) {
1199                 temp = g_shell_quote(argv[i]);
1200                 len += (strlen(temp) + 1);
1201                 g_free(temp);
1202         }
1203
1204         args = (char *)calloc(len, sizeof(char));
1205         tryvm_if(args == NULL, ret = PKGMGR_R_ERROR, "calloc failed");
1206
1207         strncpy(args, argv[0], len - 1);
1208
1209         for (i = 1; i < argcnt; i++) {
1210                 strncat(args, " ", strlen(" "));
1211                 temp = g_shell_quote(argv[i]);
1212                 strncat(args, temp, strlen(temp));
1213                 g_free(temp);
1214         }
1215         _LOGD("[args] %s [len] %d\n", args, len);
1216
1217         /* get cookie from security-server */
1218         cookie = __get_cookie_from_security_server();
1219         tryvm_if(cookie == NULL, ret = PKGMGR_R_ERROR, "__get_cookie_from_security_server is NULL");
1220         /******************* end of quote ************************/
1221
1222         /* 6. request install */
1223         ret = comm_client_request(mpc->info.request.cc, req_key, COMM_REQ_TO_INSTALLER, pkgtype, pkgid, args, cookie, 1);
1224         tryvm_if(ret < 0, ret = PKGMGR_R_ECOMM, "request failed");
1225
1226         ret = req_id;
1227
1228 catch:
1229         for (i = 0; i < argcnt; i++)
1230                 free(argv[i]);
1231
1232         if (args)
1233                 free(args);
1234         if (pkgtype)
1235                 free(pkgtype);
1236         if (cookie)
1237                 free(cookie);
1238
1239         return ret;
1240 }
1241
1242 API int pkgmgr_client_uninstall(pkgmgr_client *pc, const char *pkg_type,
1243                                 const char *pkgid, pkgmgr_mode mode,
1244                                 pkgmgr_handler event_cb, void *data)
1245 {
1246         char *pkgtype;
1247         char *installer_path;
1248         char *req_key;
1249         int req_id;
1250         int i = 0;
1251         char *argv[PKG_ARGC_MAX] = { NULL, };
1252         char *args = NULL;
1253         int argcnt = 0;
1254         int len = 0;
1255         char *temp = NULL;
1256         int ret = -1;
1257         char *cookie = NULL;
1258
1259         /* Check for NULL value of pc */
1260         retvm_if(pc == NULL, PKGMGR_R_EINVAL, "package manager client handle is NULL\n");
1261
1262         pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
1263
1264         /* 0. check the pc type */
1265         retv_if(mpc->ctype != PC_REQUEST, PKGMGR_R_EINVAL);
1266
1267         /* 1. check argument */
1268         retv_if(pkgid == NULL, PKGMGR_R_EINVAL);
1269
1270         pkgmgr_pkginfo_h handle;
1271         ret = pkgmgr_pkginfo_get_pkginfo(pkgid, &handle);
1272
1273         /*check package id      */
1274         tryvm_if(ret < 0, ret = PKGMGR_R_EINVAL, "pkgmgr_pkginfo_get_pkginfo fail");
1275         tryvm_if(handle == NULL, ret = PKGMGR_R_EINVAL, "Pkgid(%s) can not find in installed pkg DB! \n", pkgid);
1276
1277         /*check running app , terminate app if it is running*/
1278         ret = pkgmgr_appinfo_get_list(handle, PM_UI_APP, __app_list_cb, NULL);
1279         tryvm_if(ret < 0, ret = PKGMGR_R_EINVAL, "pkgmgr_appinfo_get_list : PM_UI_APP fail");
1280
1281         /*check running app , terminate app if it is running*/
1282         ret = pkgmgr_appinfo_get_list(handle, PM_SVC_APP, __app_list_cb, NULL);
1283         tryvm_if(ret < 0, ret = PKGMGR_R_EINVAL, "pkgmgr_appinfo_get_list : PM_SVC_APP fail");
1284
1285         /*check type    */
1286         ret = pkgmgr_pkginfo_get_type(handle, &pkgtype);
1287         tryvm_if(ret < 0, ret = PKGMGR_R_EINVAL, "pkgmgr_pkginfo_get_type fail");
1288         tryvm_if(pkgtype == NULL, ret = PKGMGR_R_ERROR, "pkgtype is NULL");
1289
1290         /*check pkgid length    */
1291         tryvm_if(strlen(pkgid) >= PKG_STRING_LEN_MAX, ret = PKGMGR_R_EINVAL, "pkgid is too long");
1292
1293         /* 2. get installer path using pkgtype */
1294         installer_path = _get_backend_path_with_type(pkgtype);
1295         tryvm_if(installer_path == NULL, ret = PKGMGR_R_EINVAL, "installer_path fail");
1296
1297         /* 3. generate req_key */
1298         req_key = __get_req_key(pkgid);
1299
1300         /* 4. add callback info - add callback info to pkgmgr_client */
1301         req_id = _get_request_id();
1302         __add_op_cbinfo(mpc, req_id, req_key, event_cb, data);
1303
1304         /* 5. generate argv */
1305
1306         /* argv[0] installer path */
1307         argv[argcnt++] = installer_path;
1308         /* argv[1] */
1309         argv[argcnt++] = strdup("-k");
1310         /* argv[2] */
1311         argv[argcnt++] = req_key;
1312         /* argv[3] */
1313         argv[argcnt++] = strdup("-d");
1314         /* argv[4] */
1315         argv[argcnt++] = strdup(pkgid);
1316         /* argv[5] -q option should be located at the end of command !! */
1317         if (mode == PM_QUIET)
1318                 argv[argcnt++] = strdup("-q");
1319
1320         /*** add quote in all string for special charactor like '\n'***   FIX */
1321         for (i = 0; i < argcnt; i++) {
1322                 temp = g_shell_quote(argv[i]);
1323                 len += (strlen(temp) + 1);
1324                 g_free(temp);
1325         }
1326
1327         args = (char *)calloc(len, sizeof(char));
1328         tryvm_if(args == NULL, ret = PKGMGR_R_ERROR, "calloc failed");
1329
1330         strncpy(args, argv[0], len - 1);
1331
1332         for (i = 1; i < argcnt; i++) {
1333                 strncat(args, " ", strlen(" "));
1334                 temp = g_shell_quote(argv[i]);
1335                 strncat(args, temp, strlen(temp));
1336                 g_free(temp);
1337         }
1338         _LOGD("[args] %s [len] %d\n", args, len);
1339
1340         /* get cookie from security-server */
1341         cookie = __get_cookie_from_security_server();
1342         tryvm_if(cookie == NULL, ret = PKGMGR_R_ERROR, "__get_cookie_from_security_server is NULL");
1343         /******************* end of quote ************************/
1344
1345         /* 6. request install */
1346         ret = comm_client_request(mpc->info.request.cc, req_key, COMM_REQ_TO_INSTALLER, pkgtype, pkgid, args, cookie, 1);
1347         tryvm_if(ret < 0, ret = PKGMGR_R_ECOMM, "calloc failed");
1348
1349         ret = req_id;
1350
1351 catch:
1352         for (i = 0; i < argcnt; i++)
1353                 free(argv[i]);
1354
1355         if(args)
1356                 free(args);
1357         if (cookie)
1358                 free(cookie);
1359
1360         pkgmgr_pkginfo_destroy_pkginfo(handle);
1361         PKGMGR_END();\
1362         return ret;
1363 }
1364
1365 API int pkgmgr_client_move(pkgmgr_client *pc, const char *pkg_type,
1366                                 const char *pkgid, pkgmgr_move_type move_type, pkgmgr_mode mode)
1367 {
1368         const char *pkgtype = NULL;
1369         char *installer_path = NULL;
1370         char *req_key = NULL;
1371         int i = 0;
1372         char *argv[PKG_ARGC_MAX] = { NULL, };
1373         char *args = NULL;
1374         int argcnt = 0;
1375         int len = 0;
1376         char *temp = NULL;
1377         int ret = 0;
1378         int req_id = 0;
1379         char *cookie = NULL;
1380         char buf[128] = {'\0'};
1381
1382         /* Check for NULL value of pc */
1383         if (pc == NULL) {
1384                 _LOGD("package manager client handle is NULL\n");
1385                 return PKGMGR_R_EINVAL;
1386         }
1387         pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
1388         /*check the pc type */
1389         if (mpc->ctype != PC_REQUEST)
1390                 return PKGMGR_R_EINVAL;
1391
1392         /*check argument */
1393         if (pkgid == NULL)
1394                 return PKGMGR_R_EINVAL;
1395
1396         if (pkg_type == NULL) {
1397                 pkgtype = _get_pkg_type_from_desktop_file(pkgid);
1398                 if (pkgtype == NULL)
1399                         return PKGMGR_R_EINVAL;
1400         } else
1401                 pkgtype = pkg_type;
1402
1403         if (strlen(pkgid) >= PKG_STRING_LEN_MAX)
1404                 return PKGMGR_R_EINVAL;
1405
1406         if ((move_type < PM_MOVE_TO_INTERNAL) || (move_type > PM_MOVE_TO_SDCARD))
1407                 return PKGMGR_R_EINVAL;
1408
1409         /* get installer path using pkg_path */
1410         installer_path = _get_backend_path_with_type(pkgtype);
1411         if (installer_path == NULL)
1412                 return PKGMGR_R_EINVAL;
1413
1414         /* generate req_key */
1415         req_key = __get_req_key(pkgid);
1416         req_id = _get_request_id();
1417
1418         /* generate argv */
1419         snprintf(buf, 128, "%d", move_type);
1420         /* argv[0] installer path */
1421         argv[argcnt++] = installer_path;
1422         /* argv[1] */
1423         argv[argcnt++] = strdup("-k");
1424         /* argv[2] */
1425         argv[argcnt++] = req_key;
1426         /* argv[3] */
1427         argv[argcnt++] = strdup("-m");
1428         /* argv[4] */
1429         argv[argcnt++] = strdup(pkgid);
1430         /* argv[5] */
1431         argv[argcnt++] = strdup("-t");
1432         /* argv[6] */
1433         argv[argcnt++] = strdup(buf);
1434         /* argv[7] -q option should be located at the end of command !! */
1435         if (mode == PM_QUIET)
1436                 argv[argcnt++] = strdup("-q");
1437
1438         /*** add quote in all string for special charactor like '\n'***   FIX */
1439         for (i = 0; i < argcnt; i++) {
1440                 temp = g_shell_quote(argv[i]);
1441                 len += (strlen(temp) + 1);
1442                 g_free(temp);
1443         }
1444
1445         args = (char *)calloc(len, sizeof(char));
1446         if (args == NULL) {
1447                 _LOGD("calloc failed");
1448
1449                 for (i = 0; i < argcnt; i++)
1450                         free(argv[i]);
1451
1452                 return PKGMGR_R_ERROR;
1453         }
1454         strncpy(args, argv[0], len - 1);
1455
1456         for (i = 1; i < argcnt; i++) {
1457                 strncat(args, " ", strlen(" "));
1458                 temp = g_shell_quote(argv[i]);
1459                 strncat(args, temp, strlen(temp));
1460                 g_free(temp);
1461         }
1462         _LOGD("[args] %s [len] %d\n", args, len);
1463         /******************* end of quote ************************/
1464
1465         /* 6. request install */
1466         ret = comm_client_request(mpc->info.request.cc, req_key,
1467                                   COMM_REQ_TO_MOVER, pkgtype, pkgid,
1468                                   args, cookie, 1);
1469         if (ret < 0) {
1470                 _LOGE("request failed, ret=%d\n", ret);
1471
1472                 for (i = 0; i < argcnt; i++)
1473                         free(argv[i]);
1474
1475                 free(args);
1476                 return PKGMGR_R_ECOMM;
1477         }
1478
1479         for (i = 0; i < argcnt; i++)
1480                 free(argv[i]);
1481
1482         if (args)
1483                 free(args);
1484
1485         return req_id;
1486 }
1487
1488 API int pkgmgr_client_move_pkg(pkgmgr_client *pc, const char *pkg_type,
1489                                 const char *pkgid, pkgmgr_move_type move_type, pkgmgr_mode mode,
1490                                 pkgmgr_handler event_cb, void *data)
1491 {
1492         char *pkgtype;
1493         char *installer_path;
1494         char *req_key;
1495         int req_id;
1496         int i = 0;
1497         char *argv[PKG_ARGC_MAX] = { NULL, };
1498         char *args = NULL;
1499         int argcnt = 0;
1500         int len = 0;
1501         char *temp = NULL;
1502         int ret = -1;
1503         char *cookie = NULL;
1504         char buf[128] = {'\0'};
1505
1506         /* Check for NULL value of pc */
1507         retvm_if(pc == NULL, PKGMGR_R_EINVAL, "package manager client handle is NULL\n");
1508
1509         pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
1510
1511         /* 0. check the pc type */
1512         retv_if(mpc->ctype != PC_REQUEST, PKGMGR_R_EINVAL);
1513
1514         /* 1. check argument */
1515         retv_if(pkgid == NULL, PKGMGR_R_EINVAL);
1516
1517         pkgmgr_pkginfo_h handle;
1518         ret = pkgmgr_pkginfo_get_pkginfo(pkgid, &handle);
1519
1520         /*check package id      */
1521         tryvm_if(ret < 0, ret = PKGMGR_R_EINVAL, "pkgmgr_pkginfo_get_pkginfo fail");
1522         tryvm_if(handle == NULL, ret = PKGMGR_R_EINVAL, "Pkgid(%s) can not find in installed pkg DB! \n", pkgid);
1523
1524         /*check running app , terminate app if it is running*/
1525         ret = pkgmgr_appinfo_get_list(handle, PM_UI_APP, __app_list_cb, NULL);
1526         tryvm_if(ret < 0, ret = PKGMGR_R_EINVAL, "pkgmgr_appinfo_get_list : PM_UI_APP fail");
1527
1528         /*check running app , terminate app if it is running*/
1529         ret = pkgmgr_appinfo_get_list(handle, PM_SVC_APP, __app_list_cb, NULL);
1530         tryvm_if(ret < 0, ret = PKGMGR_R_EINVAL, "pkgmgr_appinfo_get_list : PM_SVC_APP fail");
1531
1532         /*check type    */
1533         ret = pkgmgr_pkginfo_get_type(handle, &pkgtype);
1534         tryvm_if(ret < 0, ret = PKGMGR_R_EINVAL, "pkgmgr_pkginfo_get_type fail");
1535         tryvm_if(pkgtype == NULL, ret = PKGMGR_R_ERROR, "pkgtype is NULL");
1536
1537         /*check pkgid length    */
1538         tryvm_if(strlen(pkgid) >= PKG_STRING_LEN_MAX, ret = PKGMGR_R_EINVAL, "pkgid is too long");
1539
1540         /*check move_type       */
1541         tryvm_if((move_type < PM_MOVE_TO_INTERNAL) || (move_type > PM_MOVE_TO_SDCARD), ret = PKGMGR_R_EINVAL, "move_type is not supported");
1542
1543         /* 2. get installer path using pkgtype */
1544         installer_path = _get_backend_path_with_type(pkgtype);
1545         tryvm_if(installer_path == NULL, ret = PKGMGR_R_EINVAL, "installer_path fail");
1546
1547         /* 3. generate req_key */
1548         req_key = __get_req_key(pkgid);
1549
1550         /* 4. add callback info - add callback info to pkgmgr_client */
1551         req_id = _get_request_id();
1552         __add_op_cbinfo(mpc, req_id, req_key, event_cb, data);
1553
1554         /* 5. generate argv */
1555         snprintf(buf, 128, "%d", move_type);
1556         /* argv[0] installer path */
1557         argv[argcnt++] = installer_path;
1558         /* argv[1] */
1559         argv[argcnt++] = strdup("-k");
1560         /* argv[2] */
1561         argv[argcnt++] = req_key;
1562         /* argv[3] */
1563         argv[argcnt++] = strdup("-m");
1564         /* argv[4] */
1565         argv[argcnt++] = strdup(pkgid);
1566         /* argv[5] */
1567         argv[argcnt++] = strdup("-t");
1568         /* argv[6] */
1569         argv[argcnt++] = strdup(buf);
1570         /* argv[5] -q option should be located at the end of command !! */
1571         if (mode == PM_QUIET)
1572                 argv[argcnt++] = strdup("-q");
1573
1574         /*** add quote in all string for special charactor like '\n'***   FIX */
1575         for (i = 0; i < argcnt; i++) {
1576                 temp = g_shell_quote(argv[i]);
1577                 len += (strlen(temp) + 1);
1578                 g_free(temp);
1579         }
1580
1581         args = (char *)calloc(len, sizeof(char));
1582         tryvm_if(args == NULL, ret = PKGMGR_R_ERROR, "calloc failed");
1583
1584         strncpy(args, argv[0], len - 1);
1585
1586         for (i = 1; i < argcnt; i++) {
1587                 strncat(args, " ", strlen(" "));
1588                 temp = g_shell_quote(argv[i]);
1589                 strncat(args, temp, strlen(temp));
1590                 g_free(temp);
1591         }
1592         _LOGD("[args] %s [len] %d\n", args, len);
1593
1594         /* get cookie from security-server */
1595         cookie = __get_cookie_from_security_server();
1596         tryvm_if(cookie == NULL, ret = PKGMGR_R_ERROR, "__get_cookie_from_security_server is NULL");
1597         /******************* end of quote ************************/
1598
1599         /* 6. request install */
1600         ret = comm_client_request(mpc->info.request.cc, req_key, COMM_REQ_TO_MOVER, pkgtype, pkgid, args, cookie, 1);
1601         tryvm_if(ret < 0, ret = PKGMGR_R_ECOMM, "calloc failed");
1602
1603         ret = req_id;
1604
1605 catch:
1606         for (i = 0; i < argcnt; i++)
1607                 free(argv[i]);
1608
1609         if(args)
1610                 free(args);
1611         if (cookie)
1612                 free(cookie);
1613
1614         pkgmgr_pkginfo_destroy_pkginfo(handle);
1615         PKGMGR_END();\
1616         return ret;
1617 }
1618
1619 API int pkgmgr_client_activate(pkgmgr_client * pc, const char *pkg_type,
1620                                const char *pkgid)
1621 {
1622         const char *pkgtype;
1623         char *req_key;
1624         char *cookie = NULL;
1625         int ret;
1626         /* Check for NULL value of pc */
1627         if (pc == NULL) {
1628                 _LOGD("package manager client handle is NULL\n");
1629                 return PKGMGR_R_EINVAL;
1630         }
1631         pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
1632
1633         /* 0. check the pc type */
1634         if (mpc->ctype != PC_REQUEST)
1635                 return PKGMGR_R_EINVAL;
1636
1637         /* 1. check argument */
1638         if (pkgid == NULL)
1639                 return PKGMGR_R_EINVAL;
1640
1641         if (pkg_type == NULL) {
1642                 pkgtype = _get_pkg_type_from_desktop_file(pkgid);
1643                 if (pkgtype == NULL)
1644                         return PKGMGR_R_EINVAL;
1645         } else
1646                 pkgtype = pkg_type;
1647
1648         if (strlen(pkgid) >= PKG_STRING_LEN_MAX)
1649                 return PKGMGR_R_EINVAL;
1650
1651         /* 2. generate req_key */
1652         req_key = __get_req_key(pkgid);
1653
1654         /* 3. request activate */
1655         ret = comm_client_request(mpc->info.request.cc, req_key,
1656                                   COMM_REQ_TO_ACTIVATOR, pkgtype,
1657                                   pkgid, "1 PKG", cookie, 1);
1658         if (ret < 0) {
1659                 _LOGE("request failed, ret=%d\n", ret);
1660                 free(req_key);
1661                 return PKGMGR_R_ECOMM;
1662         }
1663
1664         free(req_key);
1665
1666         return PKGMGR_R_OK;
1667 }
1668
1669 API int pkgmgr_client_deactivate(pkgmgr_client *pc, const char *pkg_type,
1670                                  const char *pkgid)
1671 {
1672         const char *pkgtype;
1673         char *req_key;
1674         char *cookie = NULL;
1675         int ret;
1676         /* Check for NULL value of pc */
1677         if (pc == NULL) {
1678                 _LOGD("package manager client handle is NULL\n");
1679                 return PKGMGR_R_EINVAL;
1680         }
1681         pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
1682
1683         /* 0. check the pc type */
1684         if (mpc->ctype != PC_REQUEST)
1685                 return PKGMGR_R_EINVAL;
1686
1687         /* 1. check argument */
1688         if (pkgid == NULL)
1689                 return PKGMGR_R_EINVAL;
1690
1691         if (pkg_type == NULL) {
1692                 pkgtype = _get_pkg_type_from_desktop_file(pkgid);
1693                 if (pkgtype == NULL)
1694                         return PKGMGR_R_EINVAL;
1695         } else
1696                 pkgtype = pkg_type;
1697
1698         if (strlen(pkgid) >= PKG_STRING_LEN_MAX)
1699                 return PKGMGR_R_EINVAL;
1700
1701         /* 2. generate req_key */
1702         req_key = __get_req_key(pkgid);
1703
1704         /* 3. request activate */
1705         ret = comm_client_request(mpc->info.request.cc, req_key,
1706                                   COMM_REQ_TO_ACTIVATOR, pkgtype,
1707                                   pkgid, "0 PKG", cookie, 1);
1708         if (ret < 0) {
1709                 _LOGE("request failed, ret=%d\n", ret);
1710                 free(req_key);
1711                 return PKGMGR_R_ECOMM;
1712         }
1713
1714         free(req_key);
1715
1716         return PKGMGR_R_OK;
1717 }
1718
1719 API int pkgmgr_client_activate_app(pkgmgr_client * pc, const char *appid)
1720 {
1721         const char *pkgtype;
1722         char *req_key;
1723         char *cookie = NULL;
1724         int ret;
1725         /* Check for NULL value of pc */
1726         if (pc == NULL) {
1727                 _LOGD("package manager client handle is NULL\n");
1728                 return PKGMGR_R_EINVAL;
1729         }
1730         pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
1731
1732         /* 0. check the pc type */
1733         if (mpc->ctype != PC_REQUEST)
1734                 return PKGMGR_R_EINVAL;
1735
1736         /* 1. check argument */
1737         if (appid == NULL)
1738                 return PKGMGR_R_EINVAL;
1739
1740         if (strlen(appid) >= PKG_STRING_LEN_MAX)
1741                 return PKGMGR_R_EINVAL;
1742
1743         pkgtype = _get_pkg_type_from_desktop_file(appid);
1744
1745         /* 2. generate req_key */
1746         req_key = __get_req_key(appid);
1747
1748         /* 3. request activate */
1749         ret = comm_client_request(mpc->info.request.cc, req_key,
1750                                   COMM_REQ_TO_ACTIVATOR, pkgtype,
1751                                   appid, "1 APP", cookie, 1);
1752         if (ret < 0) {
1753                 _LOGE("request failed, ret=%d\n", ret);
1754                 free(req_key);
1755                 return PKGMGR_R_ECOMM;
1756         }
1757
1758         free(req_key);
1759
1760         return PKGMGR_R_OK;
1761 }
1762
1763 API int pkgmgr_client_activate_appv(pkgmgr_client * pc, const char *appid, char *const argv[])
1764 {
1765         const char *pkgtype;
1766         char *req_key;
1767         char *cookie = NULL;
1768         int ret;
1769         int i = 0;
1770         char *temp = NULL;
1771         int len = 0;
1772         int argcnt = 0;
1773         char *args = NULL;
1774         char *argsr = NULL;
1775         /* Check for NULL value of pc */
1776         if (pc == NULL) {
1777                 _LOGD("package manager client handle is NULL\n");
1778                 return PKGMGR_R_EINVAL;
1779         }
1780         pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
1781
1782         /* 0. check the pc type */
1783         if (mpc->ctype != PC_REQUEST)
1784                 return PKGMGR_R_EINVAL;
1785
1786         /* 1. check argument */
1787         if (appid == NULL)
1788                 return PKGMGR_R_EINVAL;
1789
1790         if (strlen(appid) >= PKG_STRING_LEN_MAX)
1791                 return PKGMGR_R_EINVAL;
1792
1793         pkgtype = _get_pkg_type_from_desktop_file(appid);
1794
1795         /* 2. generate req_key */
1796         req_key = __get_req_key(appid);
1797
1798         /*** add quote in all string for special charactor like '\n'***   FIX */
1799         if (argv) {
1800                 for (i = 0; argv[i]; i++) {
1801                         temp = g_shell_quote(argv[i]);
1802                         len += (strlen(temp) + 1);
1803                         g_free(temp);
1804                         argcnt++;
1805                 }
1806
1807                 if (argcnt) {
1808                         args = (char *)calloc(len, sizeof(char));
1809                         if (args == NULL) {
1810                                 _LOGE("calloc failed");
1811                                 free(req_key);
1812                                 return PKGMGR_R_ERROR;
1813                         }
1814                         strncpy(args, argv[0], len - 1);
1815
1816                         for (i = 1; i < argcnt; i++) {
1817                                 strncat(args, " ", strlen(" "));
1818                                 temp = g_shell_quote(argv[i]);
1819                                 strncat(args, temp, strlen(temp));
1820                                 g_free(temp);
1821                         }
1822                 }
1823         }
1824
1825         argsr = (char *)calloc(strlen("1 APP")+2+len, sizeof(char));
1826         if (argsr == NULL) {
1827                 _LOGE("calloc failed");
1828                 free(req_key);
1829                 free(args);
1830                 return PKGMGR_R_ERROR;
1831         }
1832         strncpy(argsr, "1 APP", strlen("1 APP"));
1833         if (argcnt) {
1834                 strncat(argsr, " ", strlen(" "));
1835                 strncat(argsr, args, strlen(args));
1836         }
1837
1838         _LOGD("argsr [%s]\n", argsr);
1839         /******************* end of quote ************************/
1840
1841         /* 3. request activate */
1842         ret = comm_client_request(mpc->info.request.cc, req_key,
1843                                   COMM_REQ_TO_ACTIVATOR, pkgtype,
1844                                   appid, argsr, cookie, 1);
1845         if (ret < 0) {
1846                 _LOGE("request failed, ret=%d\n", ret);
1847                 free(req_key);
1848                 free(args);
1849                 free(argsr);
1850                 return PKGMGR_R_ECOMM;
1851         }
1852
1853         free(req_key);
1854         free(args);
1855         free(argsr);
1856
1857         return PKGMGR_R_OK;
1858 }
1859
1860 API int pkgmgr_client_deactivate_app(pkgmgr_client *pc, const char *appid)
1861 {
1862         const char *pkgtype;
1863         char *req_key;
1864         char *cookie = NULL;
1865         int ret;
1866         /* Check for NULL value of pc */
1867         if (pc == NULL) {
1868                 _LOGD("package manager client handle is NULL\n");
1869                 return PKGMGR_R_EINVAL;
1870         }
1871         pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
1872
1873         /* 0. check the pc type */
1874         if (mpc->ctype != PC_REQUEST)
1875                 return PKGMGR_R_EINVAL;
1876
1877         /* 1. check argument */
1878         if (appid == NULL)
1879                 return PKGMGR_R_EINVAL;
1880
1881         if (strlen(appid) >= PKG_STRING_LEN_MAX)
1882                 return PKGMGR_R_EINVAL;
1883
1884         pkgtype = _get_pkg_type_from_desktop_file(appid);
1885
1886         /* 2. generate req_key */
1887         req_key = __get_req_key(appid);
1888
1889         /* 3. request activate */
1890         ret = comm_client_request(mpc->info.request.cc, req_key,
1891                                   COMM_REQ_TO_ACTIVATOR, pkgtype,
1892                                   appid, "0 APP", cookie, 1);
1893         if (ret < 0) {
1894                 _LOGE("request failed, ret=%d\n", ret);
1895                 free(req_key);
1896                 return PKGMGR_R_ECOMM;
1897         }
1898
1899         free(req_key);
1900
1901         return PKGMGR_R_OK;
1902 }
1903
1904
1905 API int pkgmgr_client_clear_user_data(pkgmgr_client *pc, const char *pkg_type,
1906                                       const char *appid, pkgmgr_mode mode)
1907 {
1908         const char *pkgtype;
1909         char *installer_path;
1910         char *req_key;
1911         int i = 0;
1912         char *argv[PKG_ARGC_MAX] = { NULL, };
1913         char *args = NULL;
1914         int argcnt = 0;
1915         int len = 0;
1916         char *temp = NULL;
1917         int ret;
1918         char *cookie = NULL;
1919
1920         /* Check for NULL value of pc */
1921         if (pc == NULL) {
1922                 _LOGD("package manager client handle is NULL\n");
1923                 return PKGMGR_R_EINVAL;
1924         }
1925         pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
1926
1927         /* 0. check the pc type */
1928         if (mpc->ctype != PC_REQUEST)
1929                 return PKGMGR_R_EINVAL;
1930
1931         /* 1. check argument */
1932         if (appid == NULL)
1933                 return PKGMGR_R_EINVAL;
1934
1935
1936         if (pkg_type == NULL) {
1937                 pkgtype = _get_pkg_type_from_desktop_file(appid);
1938                 if (pkgtype == NULL)
1939                         return PKGMGR_R_EINVAL;
1940         } else
1941                 pkgtype = pkg_type;
1942
1943         if (strlen(appid) >= PKG_STRING_LEN_MAX)
1944                 return PKGMGR_R_EINVAL;
1945
1946         /* 2. get installer path using pkg_path */
1947         installer_path = _get_backend_path_with_type(pkgtype);
1948         if (installer_path == NULL)
1949                 return PKGMGR_R_EINVAL;
1950
1951         /* 3. generate req_key */
1952         req_key = __get_req_key(appid);
1953
1954         /* 4. generate argv */
1955
1956         /* argv[0] installer path */
1957         argv[argcnt++] = installer_path;
1958         /* argv[1] */
1959         argv[argcnt++] = strdup("-k");
1960         /* argv[2] */
1961         argv[argcnt++] = req_key;
1962         /* argv[3] */
1963         argv[argcnt++] = strdup("-c");
1964         /* argv[4] */
1965         argv[argcnt++] = strdup(appid);
1966         /* argv[5] -q option should be located at the end of command !! */
1967         if (mode == PM_QUIET)
1968                 argv[argcnt++] = strdup("-q");
1969
1970         /*** add quote in all string for special charactor like '\n'***   FIX */
1971         for (i = 0; i < argcnt; i++) {
1972                 temp = g_shell_quote(argv[i]);
1973                 len += (strlen(temp) + 1);
1974                 g_free(temp);
1975         }
1976
1977         args = (char *)calloc(len, sizeof(char));
1978         if (args == NULL) {
1979                 _LOGD("calloc failed");
1980
1981                 for (i = 0; i < argcnt; i++)
1982                         free(argv[i]);
1983
1984                 return PKGMGR_R_ERROR;
1985         }
1986         strncpy(args, argv[0], len - 1);
1987
1988         for (i = 1; i < argcnt; i++) {
1989                 strncat(args, " ", strlen(" "));
1990                 temp = g_shell_quote(argv[i]);
1991                 strncat(args, temp, strlen(temp));
1992                 g_free(temp);
1993         }
1994         _LOGD("[args] %s [len] %d\n", args, len);
1995         /******************* end of quote ************************/
1996
1997         /* 6. request clear */
1998         ret = comm_client_request(mpc->info.request.cc, req_key,
1999                                   COMM_REQ_TO_CLEARER, pkgtype, appid,
2000                                   args, cookie, 1);
2001         if (ret < 0) {
2002                 _LOGE("request failed, ret=%d\n", ret);
2003
2004                 for (i = 0; i < argcnt; i++)
2005                         free(argv[i]);
2006
2007                 free(args);
2008                 return PKGMGR_R_ECOMM;
2009         }
2010
2011         for (i = 0; i < argcnt; i++)
2012                 free(argv[i]);
2013
2014         free(args);
2015
2016         return PKGMGR_R_OK;
2017 }
2018
2019 API int pkgmgr_client_listen_status(pkgmgr_client *pc, pkgmgr_handler event_cb,
2020                                     void *data)
2021 {
2022         int req_id;
2023         /* Check for NULL value of pc */
2024         if (pc == NULL) {
2025                 _LOGD("package manager client handle is NULL\n");
2026                 return PKGMGR_R_EINVAL;
2027         }
2028         pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
2029
2030         /* 0. check the pc type */
2031         if (mpc->ctype != PC_LISTENING)
2032                 return PKGMGR_R_EINVAL;
2033
2034         /* 1. check argument */
2035         if (event_cb == NULL)
2036                 return PKGMGR_R_EINVAL;
2037
2038         /* 2. add callback info to pkgmgr_client */
2039         req_id = _get_request_id();
2040         __add_stat_cbinfo(mpc, req_id, event_cb, data);
2041
2042         return req_id;
2043 }
2044
2045 API int pkgmgr_client_broadcast_status(pkgmgr_client *pc, const char *pkg_type,
2046                                        const char *pkgid, const char *key,
2047                                        const char *val)
2048 {
2049         /* Check for NULL value of pc */
2050         if (pc == NULL) {
2051                 _LOGD("package manager client handle is NULL\n");
2052                 return PKGMGR_R_EINVAL;
2053         }
2054         /* Check for valid arguments. NULL parameter causes DBUS to abort */
2055         if (pkgid == NULL || pkg_type == NULL || key == NULL || val == NULL) {
2056                 _LOGD("Argument supplied is NULL\n");
2057                 return PKGMGR_R_EINVAL;
2058         }
2059         pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
2060
2061         /* 0. check the pc type */
2062         if (mpc->ctype != PC_BROADCAST)
2063                 return PKGMGR_R_EINVAL;
2064
2065         comm_status_broadcast_server_send_signal(mpc->info.broadcast.bc,
2066                                                  PKG_STATUS, pkg_type,
2067                                                  pkgid, key, val);
2068
2069         return PKGMGR_R_OK;
2070 }
2071
2072 API pkgmgr_info *pkgmgr_client_check_pkginfo_from_file(const char *pkg_path)
2073 {
2074         return pkgmgr_info_new_from_file(NULL, pkg_path);
2075 }
2076
2077 API int pkgmgr_client_free_pkginfo(pkgmgr_info * pkg_info)
2078 {
2079         if (pkg_info == NULL)
2080                 return PKGMGR_R_EINVAL;
2081
2082         package_manager_pkg_detail_info_t *info = (package_manager_pkg_detail_info_t *)pkg_info;
2083
2084         if (info->icon_buf)
2085                 free(info->icon_buf);
2086
2087         free(info);
2088         info = NULL;
2089
2090         return PKGMGR_R_OK;
2091 }
2092
2093 API int pkgmgr_client_request_service(pkgmgr_request_service_type service_type, int service_mode,
2094                                   pkgmgr_client * pc, const char *pkg_type, const char *pkgid,
2095                               const char *custom_info, pkgmgr_handler event_cb, void *data)
2096 {
2097         int ret =0;
2098
2099         /* Check for NULL value of service type */
2100         retvm_if(service_type > PM_REQUEST_MAX, PKGMGR_R_EINVAL, "service type is not defined\n");
2101         retvm_if(service_type < 0, PKGMGR_R_EINVAL, "service type is error\n");
2102         vconf_set_int(VCONFKEY_PKGMGR_STATUS, -1);
2103
2104         switch (service_type) {
2105         case PM_REQUEST_CSC:
2106                 tryvm_if(custom_info == NULL, ret = PKGMGR_R_EINVAL, "custom_info is NULL\n");
2107                 tryvm_if(strlen(custom_info) >= PKG_STRING_LEN_MAX, ret = PKGMGR_R_EINVAL, "optional_file over PKG_STRING_LEN_MAX");
2108                 tryvm_if(data == NULL, ret = PKGMGR_R_EINVAL, "data is NULL\n");
2109
2110                 ret = __csc_process(custom_info, (char *)data);
2111                 if (ret < 0)
2112                         _LOGE("__csc_process fail \n");
2113                 else
2114                         ret = PKGMGR_R_OK;
2115
2116                 break;
2117
2118         case PM_REQUEST_MOVE:
2119                 tryvm_if(pkgid == NULL, ret = PKGMGR_R_EINVAL, "pkgid is NULL\n");
2120                 tryvm_if(pc == NULL, ret = PKGMGR_R_EINVAL, "pc is NULL\n");
2121                 tryvm_if((service_mode < PM_MOVE_TO_INTERNAL) || (service_mode > PM_MOVE_TO_SDCARD), ret = PKGMGR_R_EINVAL, "service_mode is wrong\n");
2122
2123                 ret = __move_pkg_process(pc, pkgid, (pkgmgr_move_type)service_mode, event_cb, data);
2124                 break;
2125
2126         case PM_REQUEST_GET_SIZE:
2127                 tryvm_if(pkgid == NULL, ret = PKGMGR_R_EINVAL, "pkgid is NULL\n");
2128                 tryvm_if(pc == NULL, ret = PKGMGR_R_EINVAL, "pc is NULL\n");
2129                 tryvm_if((service_mode < PM_GET_TOTAL_SIZE) || (service_mode > PM_GET_DATA_SIZE), ret = PKGMGR_R_EINVAL, "service_mode is wrong\n");
2130
2131                 ret = __get_size_process(pc, pkgid, (pkgmgr_getsize_type)service_mode, event_cb, data);
2132                 break;
2133
2134         case PM_REQUEST_KILL_APP:
2135                 tryvm_if(pkgid == NULL, ret = PKGMGR_R_EINVAL, "pkgid is NULL\n");
2136                 tryvm_if(pc == NULL, ret = PKGMGR_R_EINVAL, "pc is NULL\n");
2137
2138                 ret = __kill_app_process(pc, pkgid);
2139                 if (ret < 0)
2140                         _LOGE("__kill_app_process fail \n");
2141                 else
2142                         ret = PKGMGR_R_OK;
2143
2144                 break;
2145
2146         default:
2147                 _LOGE("Wrong Request\n");
2148                 ret = -1;
2149                 break;
2150         }
2151
2152 catch:
2153
2154         return ret;
2155 }
2156
2157
2158 #define __START_OF_OLD_API
2159 ail_cb_ret_e __appinfo_func(const ail_appinfo_h appinfo, void *user_data)
2160 {
2161         char *type;
2162         char *package;
2163         char *version;
2164
2165         iter_data *udata = (iter_data *) user_data;
2166
2167         ail_appinfo_get_str(appinfo, AIL_PROP_X_SLP_PACKAGETYPE_STR, &type);
2168         if (type == NULL)
2169                 type = "";
2170         ail_appinfo_get_str(appinfo, AIL_PROP_PACKAGE_STR, &package);
2171         if (package == NULL)
2172                 package = "";
2173         ail_appinfo_get_str(appinfo, AIL_PROP_VERSION_STR, &version);
2174         if (version == NULL)
2175                 version = "";
2176
2177         if (udata->iter_fn(type, package, version, udata->data) != 0)
2178                 return AIL_CB_RET_CANCEL;
2179
2180         return AIL_CB_RET_CONTINUE;
2181 }
2182
2183 API int pkgmgr_get_pkg_list(pkgmgr_iter_fn iter_fn, void *data)
2184 {
2185         int cnt = -1;
2186         ail_filter_h filter;
2187         ail_error_e ret;
2188
2189         if (iter_fn == NULL)
2190                 return PKGMGR_R_EINVAL;
2191
2192         ret = ail_filter_new(&filter);
2193         if (ret != AIL_ERROR_OK) {
2194                 return PKGMGR_R_ERROR;
2195         }
2196
2197         ret = ail_filter_add_str(filter, AIL_PROP_TYPE_STR, "Application");
2198         if (ret != AIL_ERROR_OK) {
2199                 ail_filter_destroy(filter);
2200                 return PKGMGR_R_ERROR;
2201         }
2202
2203         ret = ail_filter_add_bool(filter, AIL_PROP_X_SLP_REMOVABLE_BOOL, true);
2204         if (ret != AIL_ERROR_OK) {
2205                 ail_filter_destroy(filter);
2206                 return PKGMGR_R_ERROR;
2207         }
2208
2209         ret = ail_filter_count_appinfo(filter, &cnt);
2210         if (ret != AIL_ERROR_OK) {
2211                 ail_filter_destroy(filter);
2212                 return PKGMGR_R_ERROR;
2213         }
2214
2215         iter_data *udata = calloc(1, sizeof(iter_data));
2216         if (udata == NULL) {
2217                 _LOGE("calloc failed");
2218                 ail_filter_destroy(filter);
2219
2220                 return PKGMGR_R_ERROR;
2221         }
2222         udata->iter_fn = iter_fn;
2223         udata->data = data;
2224
2225         ail_filter_list_appinfo_foreach(filter, __appinfo_func, udata);
2226
2227         free(udata);
2228
2229         ret = ail_filter_destroy(filter);
2230         if (ret != AIL_ERROR_OK) {
2231                 return PKGMGR_R_ERROR;
2232         }
2233
2234         return PKGMGR_R_OK;
2235 }
2236
2237 API pkgmgr_info *pkgmgr_info_new(const char *pkg_type, const char *pkgid)
2238 {
2239         const char *pkgtype;
2240         pkg_plugin_set *plugin_set = NULL;
2241         package_manager_pkg_detail_info_t *pkg_detail_info = NULL;
2242
2243         /* 1. check argument */
2244         if (pkgid == NULL)
2245                 return NULL;
2246
2247         if (pkg_type == NULL) {
2248                 pkgtype = _get_pkg_type_from_desktop_file(pkgid);
2249                 if (pkgtype == NULL)
2250                         return NULL;
2251         } else
2252                 pkgtype = pkg_type;
2253
2254         if (strlen(pkgid) >= PKG_STRING_LEN_MAX)
2255                 return NULL;
2256
2257         pkg_detail_info = calloc(1, sizeof(package_manager_pkg_detail_info_t));
2258         if (pkg_detail_info == NULL) {
2259                 _LOGE("*** Failed to alloc package_handler_info.\n");
2260                 return NULL;
2261         }
2262
2263         plugin_set = _package_manager_load_library(pkgtype);
2264         if (plugin_set == NULL) {
2265                 _LOGE("*** Failed to load library");
2266                 free(pkg_detail_info);
2267                 return NULL;
2268         }
2269
2270         if (plugin_set->pkg_is_installed) {
2271                 if (plugin_set->pkg_is_installed(pkgid) != 0) {
2272                         _LOGE("*** Failed to call pkg_is_installed()");
2273                         free(pkg_detail_info);
2274                         return NULL;
2275                 }
2276
2277                 if (plugin_set->get_pkg_detail_info) {
2278                         if (plugin_set->get_pkg_detail_info(pkgid,
2279                                                             pkg_detail_info) != 0) {
2280                                 _LOGE("*** Failed to call get_pkg_detail_info()");
2281                                 free(pkg_detail_info);
2282                                 return NULL;
2283                         }
2284                 }
2285         }
2286
2287         return (pkgmgr_info *) pkg_detail_info;
2288 }
2289
2290 API char * pkgmgr_info_get_string(pkgmgr_info * pkg_info, const char *key)
2291 {
2292         package_manager_pkg_detail_info_t *pkg_detail_info;
2293
2294         if (pkg_info == NULL)
2295                 return NULL;
2296         if (key == NULL)
2297                 return NULL;
2298
2299         pkg_detail_info = (package_manager_pkg_detail_info_t *) pkg_info;
2300
2301         return _get_info_string(key, pkg_detail_info);
2302 }
2303
2304 API pkgmgr_info *pkgmgr_info_new_from_file(const char *pkg_type,
2305                                            const char *pkg_path)
2306 {
2307         pkg_plugin_set *plugin_set = NULL;
2308         package_manager_pkg_detail_info_t *pkg_detail_info = NULL;
2309         char *pkgtype;
2310         if (pkg_path == NULL) {
2311                 _LOGE("pkg_path is NULL\n");
2312                 return NULL;
2313         }
2314
2315         if (strlen(pkg_path) > PKG_URL_STRING_LEN_MAX) {
2316                 _LOGE("length of pkg_path is too long - %d.\n",
2317                       strlen(pkg_path));
2318                 return NULL;
2319         }
2320
2321         pkg_detail_info = calloc(1, sizeof(package_manager_pkg_detail_info_t));
2322         if (pkg_detail_info == NULL) {
2323                 _LOGE("*** Failed to alloc package_handler_info.\n");
2324                 return NULL;
2325         }
2326
2327         if (pkg_type == NULL)
2328                 pkgtype = __get_type_from_path(pkg_path);
2329         else
2330                 pkgtype = strdup(pkg_type);
2331
2332         plugin_set = _package_manager_load_library(pkgtype);
2333         if (plugin_set == NULL) {
2334                 free(pkg_detail_info);
2335                 free(pkgtype);
2336                 return NULL;
2337         }
2338
2339         if (plugin_set->get_pkg_detail_info_from_package) {
2340                 if (plugin_set->get_pkg_detail_info_from_package(pkg_path,
2341                                                                  pkg_detail_info) != 0) {
2342                         free(pkg_detail_info);
2343                         free(pkgtype);
2344                         return NULL;
2345                 }
2346         }
2347
2348         free(pkgtype);
2349         return (pkgmgr_info *) pkg_detail_info;
2350 }
2351
2352 API int pkgmgr_info_free(pkgmgr_info * pkg_info)
2353 {
2354         if (pkg_info == NULL)
2355                 return PKGMGR_R_EINVAL;
2356
2357         free(pkg_info);
2358         pkg_info = NULL;
2359
2360         return 0;
2361 }
2362
2363 #define __END_OF_OLD_API
2364
2365 API int pkgmgr_pkginfo_get_list(pkgmgr_info_pkg_list_cb pkg_list_cb, void *user_data)
2366 {
2367         int ret = 0;
2368         ret = pkgmgrinfo_pkginfo_get_list(pkg_list_cb, user_data);
2369         return ret;
2370 }
2371
2372 API int pkgmgr_pkginfo_get_pkginfo(const char *pkgid, pkgmgr_pkginfo_h *handle)
2373 {
2374         int ret = 0;
2375         ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, handle);
2376         return ret;
2377 }
2378
2379 API int pkgmgr_pkginfo_get_pkgname(pkgmgr_pkginfo_h handle, char **pkg_name)
2380 {
2381         int ret = 0;
2382         ret = pkgmgrinfo_pkginfo_get_pkgname(handle, pkg_name);
2383         return ret;
2384 }
2385
2386
2387 API int pkgmgr_pkginfo_get_pkgid(pkgmgr_pkginfo_h handle, char **pkgid)
2388 {
2389         int ret = 0;
2390         ret = pkgmgrinfo_pkginfo_get_pkgid(handle, pkgid);
2391         return ret;
2392 }
2393
2394 API int pkgmgr_pkginfo_get_type(pkgmgr_pkginfo_h handle, char **type)
2395 {
2396         int ret = 0;
2397         ret = pkgmgrinfo_pkginfo_get_type(handle, type);
2398         return ret;
2399 }
2400
2401 API int pkgmgr_pkginfo_get_version(pkgmgr_pkginfo_h handle, char **version)
2402 {
2403         int ret = 0;
2404         ret = pkgmgrinfo_pkginfo_get_version(handle, version);
2405         return ret;
2406 }
2407
2408 API int pkgmgr_pkginfo_get_install_location(pkgmgr_pkginfo_h handle, pkgmgr_install_location *location)
2409 {
2410         int ret = 0;
2411         pkgmgrinfo_install_location loc;
2412         ret = pkgmgrinfo_pkginfo_get_install_location(handle, &loc);
2413         *location = loc;
2414         return ret;
2415 }
2416
2417 API int pkgmgr_pkginfo_get_package_size(pkgmgr_pkginfo_h handle, int *size)
2418 {
2419         int ret = 0;
2420         ret = pkgmgrinfo_pkginfo_get_package_size(handle, size);
2421         return ret;
2422 }
2423
2424 API int pkgmgr_pkginfo_get_icon(pkgmgr_pkginfo_h handle, char **icon)
2425 {
2426         int ret = 0;
2427         ret = pkgmgrinfo_pkginfo_get_icon(handle, icon);
2428         return ret;
2429 }
2430
2431 API int pkgmgr_pkginfo_get_label(pkgmgr_pkginfo_h handle, char **label)
2432 {
2433         int ret = 0;
2434         ret = pkgmgrinfo_pkginfo_get_label(handle, label);
2435         return ret;
2436 }
2437
2438 API int pkgmgr_pkginfo_get_description(pkgmgr_pkginfo_h handle, char **description)
2439 {
2440         int ret = 0;
2441         ret = pkgmgrinfo_pkginfo_get_description(handle, description);
2442         return ret;
2443 }
2444
2445 API int pkgmgr_pkginfo_get_author_name(pkgmgr_pkginfo_h handle, char **author_name)
2446 {
2447         int ret = 0;
2448         ret = pkgmgrinfo_pkginfo_get_author_name(handle, author_name);
2449         return ret;
2450 }
2451
2452 API int pkgmgr_pkginfo_get_author_email(pkgmgr_pkginfo_h handle, char **author_email)
2453 {
2454         int ret = 0;
2455         ret = pkgmgrinfo_pkginfo_get_author_email(handle, author_email);
2456         return ret;
2457 }
2458
2459 API int pkgmgr_pkginfo_get_author_href(pkgmgr_pkginfo_h handle, char **author_href)
2460 {
2461         int ret = 0;
2462         ret = pkgmgrinfo_pkginfo_get_author_href(handle, author_href);
2463         return ret;
2464 }
2465
2466 API int pkgmgr_pkginfo_is_removable(pkgmgr_pkginfo_h handle, bool *removable)
2467 {
2468         int ret = 0;
2469         ret = pkgmgrinfo_pkginfo_is_removable(handle, removable);
2470         return ret;
2471 }
2472
2473 API int pkgmgr_pkginfo_is_preload(pkgmgr_pkginfo_h handle, bool *preload)
2474 {
2475         int ret = 0;
2476         ret = pkgmgrinfo_pkginfo_is_preload(handle, preload);
2477         return ret;
2478 }
2479
2480 API int pkgmgr_pkginfo_is_readonly(pkgmgr_pkginfo_h handle, bool *readonly)
2481 {
2482         int ret = 0;
2483         ret = pkgmgrinfo_pkginfo_is_readonly(handle, readonly);
2484         return ret;
2485 }
2486
2487 API int pkgmgr_pkginfo_is_accessible(pkgmgr_pkginfo_h handle, bool *accessible)
2488 {
2489         int ret = 0;
2490         ret = pkgmgrinfo_pkginfo_is_accessible(handle, accessible);
2491         return ret;
2492 }
2493
2494 API int pkgmgr_pkginfo_destroy_pkginfo(pkgmgr_pkginfo_h handle)
2495 {
2496         int ret = 0;
2497         ret = pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
2498         return ret;
2499 }
2500
2501 API int pkgmgr_pkginfo_get_installed_storage(pkgmgr_pkginfo_h handle, pkgmgr_installed_storage *storage)
2502 {
2503         int ret = 0;
2504         pkgmgrinfo_installed_storage sto;
2505         ret = pkgmgrinfo_pkginfo_get_installed_storage(handle, &sto);
2506         *storage = sto;
2507         return ret;
2508 }
2509
2510 API int pkgmgr_pkginfo_get_installed_time(pkgmgr_pkginfo_h handle, int *installed_time)
2511 {
2512         int ret = 0;
2513         ret = pkgmgrinfo_pkginfo_get_installed_time(handle, installed_time);
2514         return ret;
2515 }
2516
2517 API int pkgmgr_appinfo_get_list(pkgmgr_pkginfo_h handle, pkgmgr_app_component component,
2518                                                         pkgmgr_info_app_list_cb app_func, void *user_data)
2519 {
2520         int ret = 0;
2521         ret = pkgmgrinfo_appinfo_get_list(handle, component, app_func, user_data);
2522         return ret;
2523 }
2524
2525 API int pkgmgr_appinfo_foreach_category(pkgmgr_appinfo_h handle, pkgmgr_info_app_category_list_cb category_func,
2526                                                         void *user_data)
2527 {
2528         int ret = 0;
2529         ret = pkgmgrinfo_appinfo_foreach_category(handle, category_func, user_data);
2530         return ret;
2531 }
2532
2533 API int pkgmgr_appinfo_get_appinfo(const char *appid, pkgmgr_appinfo_h *handle)
2534 {
2535         int ret = 0;
2536         ret = pkgmgrinfo_appinfo_get_appinfo(appid, handle);
2537         return ret;
2538 }
2539
2540 API int pkgmgr_appinfo_get_appid(pkgmgr_appinfo_h  handle, char **appid)
2541 {
2542         int ret = 0;
2543         ret = pkgmgrinfo_appinfo_get_appid(handle, appid);
2544         return ret;
2545 }
2546
2547 API int pkgmgr_appinfo_get_pkgname(pkgmgr_appinfo_h  handle, char **pkg_name)
2548 {
2549         int ret = 0;
2550         ret = pkgmgrinfo_appinfo_get_pkgname(handle, pkg_name);
2551         return ret;
2552 }
2553
2554 API int pkgmgr_appinfo_get_pkgid(pkgmgr_appinfo_h  handle, char **pkgid)
2555 {
2556         int ret = 0;
2557         ret = pkgmgrinfo_appinfo_get_pkgid(handle, pkgid);
2558         return ret;
2559 }
2560
2561 API int pkgmgr_appinfo_get_icon(pkgmgr_appinfo_h handle, char **icon)
2562 {
2563         int ret = 0;
2564         ret = pkgmgrinfo_appinfo_get_icon(handle, icon);
2565         return ret;
2566 }
2567
2568 API int pkgmgr_appinfo_get_label(pkgmgr_appinfo_h handle, char **label)
2569 {
2570         int ret = 0;
2571         ret = pkgmgrinfo_appinfo_get_label(handle, label);
2572         return ret;
2573 }
2574
2575 API int pkgmgr_appinfo_get_exec(pkgmgr_appinfo_h  handle, char **exec)
2576 {
2577         int ret = 0;
2578         ret = pkgmgrinfo_appinfo_get_exec(handle, exec);
2579         return ret;
2580 }
2581
2582 API int pkgmgr_appinfo_get_component(pkgmgr_appinfo_h  handle, pkgmgr_app_component *component)
2583 {
2584         int ret = 0;
2585         pkgmgrinfo_app_component comp;
2586         ret = pkgmgrinfo_appinfo_get_component(handle, &comp);
2587         *component = comp;
2588         return ret;
2589 }
2590
2591 API int pkgmgr_appinfo_get_apptype(pkgmgr_appinfo_h  handle, char **app_type)
2592 {
2593         int ret = 0;
2594         ret = pkgmgrinfo_appinfo_get_apptype(handle, app_type);
2595         return ret;
2596 }
2597
2598 API int pkgmgr_appinfo_is_nodisplay(pkgmgr_appinfo_h  handle, bool *nodisplay)
2599 {
2600         int ret = 0;
2601         ret = pkgmgrinfo_appinfo_is_nodisplay(handle, nodisplay);
2602         return ret;
2603 }
2604
2605 API int pkgmgr_appinfo_is_multiple(pkgmgr_appinfo_h  handle, bool *multiple)
2606 {
2607         int ret = 0;
2608         ret = pkgmgrinfo_appinfo_is_multiple(handle, multiple);
2609         return ret;
2610 }
2611
2612 API int pkgmgr_appinfo_is_taskmanage(pkgmgr_appinfo_h  handle, bool *taskmanage)
2613 {
2614         int ret = 0;
2615         ret = pkgmgrinfo_appinfo_is_taskmanage(handle, taskmanage);
2616         return ret;
2617 }
2618
2619 API int pkgmgr_appinfo_get_hwacceleration(pkgmgr_appinfo_h  handle, pkgmgr_hwacceleration_type *hwacceleration)
2620 {
2621         int ret = 0;
2622         pkgmgrinfo_app_hwacceleration hwacc;
2623         ret = pkgmgrinfo_appinfo_get_hwacceleration(handle, &hwacc);
2624         *hwacceleration = hwacc;
2625         return ret;
2626 }
2627
2628 API int pkgmgr_appinfo_is_onboot(pkgmgr_appinfo_h  handle, bool *onboot)
2629 {
2630         int ret = 0;
2631         ret = pkgmgrinfo_appinfo_is_onboot(handle, onboot);
2632         return ret;
2633 }
2634
2635 API int pkgmgr_appinfo_is_autorestart(pkgmgr_appinfo_h  handle, bool *autorestart)
2636 {
2637         int ret = 0;
2638         ret = pkgmgrinfo_appinfo_is_autorestart(handle, autorestart);
2639         return ret;
2640 }
2641
2642 API int pkgmgr_appinfo_destroy_appinfo(pkgmgr_appinfo_h  handle)
2643 {
2644         int ret = 0;
2645         ret = pkgmgrinfo_appinfo_destroy_appinfo(handle);
2646         return ret;
2647 }
2648
2649 API int pkgmgr_pkginfo_create_certinfo(pkgmgr_certinfo_h *handle)
2650 {
2651         int ret = 0;
2652         ret = pkgmgrinfo_pkginfo_create_certinfo(handle);
2653         return ret;
2654 }
2655
2656 API int pkgmgr_pkginfo_load_certinfo(const char *pkgid, pkgmgr_certinfo_h handle)
2657 {
2658         int ret = 0;
2659         ret = pkgmgrinfo_pkginfo_load_certinfo(pkgid, handle);
2660         return ret;
2661 }
2662
2663 API int pkgmgr_pkginfo_get_cert_value(pkgmgr_certinfo_h handle, pkgmgr_cert_type cert_type, const char **cert_value)
2664 {
2665         int ret = 0;
2666         ret = pkgmgrinfo_pkginfo_get_cert_value(handle, cert_type, cert_value);
2667         return ret;
2668 }
2669
2670 API int pkgmgr_pkginfo_destroy_certinfo(pkgmgr_certinfo_h handle)
2671 {
2672         int ret = 0;
2673         ret = pkgmgrinfo_pkginfo_destroy_certinfo(handle);
2674         return ret;
2675 }
2676
2677 API int pkgmgr_datacontrol_get_info(const char *providerid, const char * type, char **appid, char **access)
2678 {
2679         int ret = 0;
2680         ret = pkgmgrinfo_datacontrol_get_info(providerid, type, appid, access);
2681         return ret;
2682 }