update issues
[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
41 #include "package-manager.h"
42 #include "pkgmgr-internal.h"
43 #include "pkgmgr-api.h"
44 #include "comm_client.h"
45 #include "comm_status_broadcast_server.h"
46
47
48 static int _get_request_id()
49 {
50         static int internal_req_id = 1;
51
52         return internal_req_id++;
53 }
54
55 typedef struct _req_cb_info {
56         int request_id;
57         char *req_key;
58         pkgmgr_handler event_cb;
59         void *data;
60         struct _req_cb_info *next;
61 } req_cb_info;
62
63 typedef struct _listen_cb_info {
64         int request_id;
65         pkgmgr_handler event_cb;
66         void *data;
67         struct _listen_cb_info *next;
68 } listen_cb_info;
69
70 typedef struct _pkgmgr_client_t {
71         client_type ctype;
72         union {
73                 struct _request {
74                         comm_client *cc;
75                         req_cb_info *rhead;
76                 } request;
77                 struct _listening {
78                         comm_client *cc;
79                         listen_cb_info *lhead;
80                 } listening;
81                 struct _broadcast {
82                         DBusConnection *bc;
83                 } broadcast;
84         } info;
85 } pkgmgr_client_t;
86
87 typedef struct _iter_data {
88         pkgmgr_iter_fn iter_fn;
89         void *data;
90 } iter_data;
91
92 typedef struct _csc_info {
93         int                             count ;                 /** Number of csc packages */
94         char            **      type ;                  /** package type */
95         char            **  description ;       /** description */
96 } csc_info ;
97
98 static int __xsystem(const char *argv[])
99 {
100         int status = 0;
101         pid_t pid;
102         pid = fork();
103         switch (pid) {
104         case -1:
105                 perror("fork failed");
106                 return -1;
107         case 0:
108                 /* child */
109                 execvp(argv[0], (char *const *)argv);
110                 _exit(-1);
111         default:
112                 /* parent */
113                 break;
114         }
115         if (waitpid(pid, &status, 0) == -1) {
116                 perror("waitpid failed");
117                 return -1;
118         }
119         if (WIFSIGNALED(status)) {
120                 perror("signal");
121                 return -1;
122         }
123         if (!WIFEXITED(status)) {
124                 /* shouldn't happen */
125                 perror("should not happen");
126                 return -1;
127         }
128         return WEXITSTATUS(status);
129 }
130
131 static int __csc_process(const char *csc_path, const char *result_path)
132 {
133         int ret = 0;
134         int cnt = 0;
135         int count = 0;
136         int csc_fail = 0;
137         int fd = 0;
138         char *pkgtype = NULL;
139         char *des = NULL;
140         char buf[PKG_STRING_LEN_MAX] = {0,};
141         char type_buf[1024] = { 0 };
142         char des_buf[1024] = { 0 };
143         csc_info *csc = NULL;
144         FILE* file = NULL;
145
146         csc = iniparser_load(csc_path);
147         retvm_if(csc == NULL, PKGMGR_R_EINVAL, "cannot open parse file [%s]", csc_path);
148
149         file = fopen(result_path, "w");
150         retvm_if(file == NULL, PKGMGR_R_EINVAL, "cannot open result file [%s]", result_path);
151
152         count = iniparser_getint(csc, "csc packages:count", -1);
153         retvm_if(count == 0, PKGMGR_R_ERROR, "csc [%s] dont have packages", csc_path);
154
155         snprintf(buf, PKG_STRING_LEN_MAX, "[csc %d packages]\n", count);
156         fwrite(buf, 1, strlen(buf), file);
157
158         for(cnt = 1 ; cnt <= count ; cnt++)
159         {
160                 snprintf(type_buf, PKG_STRING_LEN_MAX - 1, "csc packages:type_%03d", cnt);
161                 snprintf(des_buf, PKG_STRING_LEN_MAX - 1, "csc packages:description_%03d", cnt);
162
163                 pkgtype = iniparser_getstr(csc, type_buf);
164                 des = iniparser_getstr(csc, des_buf);
165                 ret = 0;
166
167                 if (pkgtype == NULL) {
168                         csc_fail++;
169                         snprintf(buf, PKG_STRING_LEN_MAX, "[%03d]Fail to get information[%s]\n", cnt, type_buf);
170                         fwrite(buf, 1, strlen(buf), file);
171                         continue;
172                 } else if (des == NULL) {
173                         csc_fail++;
174                         snprintf(buf, PKG_STRING_LEN_MAX, "[%03d]Fail to get information[%s]\n", cnt, des_buf);
175                         fwrite(buf, 1, strlen(buf), file);
176                         continue;
177                 }
178
179                 if (strcmp(pkgtype, "tpk") == 0) {
180                         const char *ospinstaller_argv[] = { "/usr/bin/osp-installer", "-c", des, NULL };
181                         ret = __xsystem(ospinstaller_argv);
182                 } else if (strcmp(pkgtype, "wgt")== 0) {
183                         const char *wrtinstaller_argv[] = { "/usr/bin/wrt-installer", "-c", des, NULL };
184                         ret = __xsystem(wrtinstaller_argv);
185                 } else {
186                         csc_fail++;
187                         ret = -1;
188                 }
189
190                 if (ret != 0)
191                         snprintf(buf, PKG_STRING_LEN_MAX, "[%03d][%s] csc result : Fail\n", cnt, pkgtype);
192                 else
193                         snprintf(buf, PKG_STRING_LEN_MAX, "[%03d][%s] csc result : Sucess\n", cnt, pkgtype);
194
195                 fwrite(buf, 1, strlen(buf), file);
196         }
197
198         if (csc_fail > 0) {
199                 ret = PKGMGR_R_ERROR;
200                 snprintf(buf, PKG_STRING_LEN_MAX, "[csc result] total : [%d], sucess : [%d]packages, fail : [%d]packages\n", count,  count-csc_fail, csc_fail);
201
202         } else {
203                 ret = PKGMGR_R_OK;
204                 snprintf(buf, PKG_STRING_LEN_MAX, "[csc result] total : [%d], sucess : all packages\n", count);
205
206         }
207         fwrite(buf, 1, strlen(buf), file);
208
209         iniparser_freedict(csc);
210         fflush(file);
211         fd = fileno(file);
212         fsync(fd);
213         fclose(file);
214
215         return ret;
216 }
217
218 static void __add_op_cbinfo(pkgmgr_client_t * pc, int request_id,
219                             const char *req_key, pkgmgr_handler event_cb,
220                             void *data)
221 {
222         req_cb_info *cb_info;
223         req_cb_info *current;
224         req_cb_info *prev;
225
226         cb_info = (req_cb_info *) calloc(1, sizeof(req_cb_info));
227         if (cb_info == NULL) {
228                 _LOGD("calloc failed");
229                 return;
230         }
231         cb_info->request_id = request_id;
232         cb_info->req_key = strdup(req_key);
233         cb_info->event_cb = event_cb;
234         cb_info->data = data;
235         cb_info->next = NULL;
236
237         if (pc->info.request.rhead == NULL)
238                 pc->info.request.rhead = cb_info;
239         else {
240                 current = prev = pc->info.request.rhead;
241                 while (current) {
242                         prev = current;
243                         current = current->next;
244                 }
245
246                 prev->next = cb_info;
247         }
248 }
249
250 static req_cb_info *__find_op_cbinfo(pkgmgr_client_t *pc, const char *req_key)
251 {
252         req_cb_info *tmp;
253
254         tmp = pc->info.request.rhead;
255
256         if (tmp == NULL) {
257                 _LOGE("tmp is NULL");
258                 return NULL;
259         }
260
261         _LOGD("tmp->req_key %s, req_key %s", tmp->req_key, req_key);
262
263         while (tmp) {
264                 if (strncmp(tmp->req_key, req_key, strlen(tmp->req_key)) == 0)
265                         return tmp;
266                 tmp = tmp->next;
267         }
268         return NULL;
269 }
270
271 static void __remove_op_cbinfo(pkgmgr_client_t *pc, req_cb_info *info)
272 {
273         req_cb_info *tmp;
274
275         if (pc == NULL || pc->info.request.rhead == NULL || info == NULL)
276                 return;
277
278         tmp = pc->info.request.rhead;
279         while (tmp) {
280                 if (tmp->next == info) {
281                         tmp->next = info->next;
282                         free(info);
283                         return;
284                 }
285                 tmp = tmp->next;
286         }
287 }
288
289
290 static void __add_stat_cbinfo(pkgmgr_client_t *pc, int request_id,
291                               pkgmgr_handler event_cb, void *data)
292 {
293         listen_cb_info *cb_info;
294         listen_cb_info *current;
295         listen_cb_info *prev;
296
297         cb_info = (listen_cb_info *) calloc(1, sizeof(listen_cb_info));
298         if (cb_info == NULL) {
299                 _LOGD("calloc failed");
300                 return;
301         }
302         cb_info->request_id = request_id;
303         cb_info->event_cb = event_cb;
304         cb_info->data = data;
305         cb_info->next = NULL;
306
307         /* TODO - check the order of callback - FIFO or LIFO => Should be changed to LIFO */
308         if (pc->info.listening.lhead == NULL)
309                 pc->info.listening.lhead = cb_info;
310         else {
311                 current = prev = pc->info.listening.lhead;
312                 while (current) {
313                         prev = current;
314                         current = current->next;
315                 }
316
317                 prev->next = cb_info;
318         }
319 }
320
321 static void __operation_callback(void *cb_data, const char *req_id,
322                                  const char *pkg_type, const char *pkgid,
323                                  const char *key, const char *val)
324 {
325         pkgmgr_client_t *pc;
326         req_cb_info *cb_info;
327
328         _LOGD("__operation_callback() req_id[%s] pkg_type[%s] pkgid[%s]"
329               "key[%s] val[%s]\n", req_id, pkg_type, pkgid, key, val);
330
331         pc = (pkgmgr_client_t *) cb_data;
332
333         /* find callback info */
334         cb_info = __find_op_cbinfo(pc, req_id);
335         if (cb_info == NULL)
336                 return;
337
338         _LOGD("__find_op_cbinfo");
339
340         /* call callback */
341         if (cb_info->event_cb) {
342                 cb_info->event_cb(cb_info->request_id, pkg_type, pkgid, key,
343                                   val, NULL, cb_info->data);
344                 _LOGD("event_cb is called");
345         }
346
347         /*remove callback for last call 
348            if (strcmp(key, "end") == 0) {
349            __remove_op_cbinfo(pc, cb_info);
350            _LOGD("__remove_op_cbinfo");
351            }
352          */
353
354         return;
355 }
356
357 static void __status_callback(void *cb_data, const char *req_id,
358                               const char *pkg_type, const char *pkgid,
359                               const char *key, const char *val)
360 {
361         pkgmgr_client_t *pc;
362         listen_cb_info *tmp;
363
364         _LOGD("__status_callback() req_id[%s] pkg_type[%s] pkgid[%s]"
365               "key[%s] val[%s]\n", req_id, pkg_type, pkgid, key, val);
366
367         pc = (pkgmgr_client_t *) cb_data;
368
369         tmp = pc->info.listening.lhead;
370         while (tmp) {
371                 if (tmp->event_cb(tmp->request_id, pkg_type, pkgid, key, val,
372                                   NULL, tmp->data) != 0)
373                         break;
374                 tmp = tmp->next;
375         }
376
377         return;
378 }
379
380 API pkgmgr_client *pkgmgr_client_new(client_type ctype)
381 {
382         pkgmgr_client_t *pc = NULL;
383         int ret = -1;
384
385         if (ctype != PC_REQUEST && ctype != PC_LISTENING
386             && ctype != PC_BROADCAST)
387                 return NULL;
388
389         /* Allocate memory for ADT:pkgmgr_client */
390         pc = calloc(1, sizeof(pkgmgr_client_t));
391         if (pc == NULL) {
392                 _LOGE("No memory");
393                 return NULL;
394         }
395
396         /* Manage pc */
397         pc->ctype = ctype;
398
399         if (pc->ctype == PC_REQUEST) {
400                 pc->info.request.cc = comm_client_new();
401                 if (pc->info.request.cc == NULL) {
402                         _LOGE("client creation failed");
403                         goto err;
404                 }
405                 ret = comm_client_set_status_callback(pc->info.request.cc,
406                                                       __operation_callback, pc);
407                 if (ret < 0) {
408                         _LOGE("comm_client_set_status_callback() failed - %d",
409                               ret);
410                         goto err;
411                 }
412         } else if (pc->ctype == PC_LISTENING) {
413                 pc->info.listening.cc = comm_client_new();
414                 if (pc->info.listening.cc == NULL) {
415                         _LOGE("client creation failed");
416                         goto err;
417                 }
418                 ret = comm_client_set_status_callback(pc->info.request.cc,
419                                                       __status_callback, pc);
420                 if (ret < 0) {
421                         _LOGE("comm_client_set_status_callback() failed - %d",
422                               ret);
423                         goto err;
424                 }
425         } else if (pc->ctype == PC_BROADCAST) {
426                 pc->info.broadcast.bc = comm_status_broadcast_server_connect();
427                 if (pc->info.broadcast.bc == NULL) {
428                         _LOGE("client creation failed");
429                         goto err;
430                 }
431                 ret = 0;
432         }
433
434         return (pkgmgr_client *) pc;
435
436  err:
437         if (pc)
438                 free(pc);
439         return NULL;
440 }
441
442 API int pkgmgr_client_free(pkgmgr_client *pc)
443 {
444         int ret = -1;
445         pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
446
447         if (mpc == NULL) {
448                 _LOGE("Invalid argument");
449                 return PKGMGR_R_EINVAL;
450         }
451
452         if (mpc->ctype == PC_REQUEST) {
453                 req_cb_info *tmp;
454                 req_cb_info *prev;
455                 for (tmp = mpc->info.request.rhead; tmp;) {
456                         prev = tmp;
457                         tmp = tmp->next;
458                         free(prev);
459                 }
460
461                 ret = comm_client_free(mpc->info.request.cc);
462                 if (ret < 0) {
463                         _LOGE("comm_client_free() failed - %d", ret);
464                         goto err;
465                 }
466         } else if (mpc->ctype == PC_LISTENING) {
467                 listen_cb_info *tmp;
468                 listen_cb_info *prev;
469                 for (tmp = mpc->info.listening.lhead; tmp;) {
470                         prev = tmp;
471                         tmp = tmp->next;
472                         free(prev);
473                 }
474
475                 ret = comm_client_free(mpc->info.listening.cc);
476                 if (ret < 0) {
477                         _LOGE("comm_client_free() failed - %d", ret);
478                         goto err;
479                 }
480         } else if (mpc->ctype == PC_BROADCAST) {
481                 comm_status_broadcast_server_disconnect(mpc->info.broadcast.bc);
482                 ret = 0;
483         } else {
484                 _LOGE("Invalid client type\n");
485                 return PKGMGR_R_EINVAL;
486         }
487
488         free(mpc);
489         mpc = NULL;
490         return PKGMGR_R_OK;
491
492  err:
493         if (mpc) {
494                 free(mpc);
495                 mpc = NULL;
496         }
497         return PKGMGR_R_ERROR;
498 }
499
500 static char *__get_req_key(const char *pkg_path)
501 {
502         struct timeval tv;
503         long curtime;
504         char timestr[PKG_STRING_LEN_MAX];
505         char *str_req_key;
506         int size;
507
508         gettimeofday(&tv, NULL);
509         curtime = tv.tv_sec * 1000000 + tv.tv_usec;
510         snprintf(timestr, sizeof(timestr), "%ld", curtime);
511
512         size = strlen(pkg_path) + strlen(timestr) + 2;
513         str_req_key = (char *)calloc(size, sizeof(char));
514         if (str_req_key == NULL) {
515                 _LOGD("calloc failed");
516                 return NULL;
517         }
518         snprintf(str_req_key, size, "%s_%s", pkg_path, timestr);
519
520         return str_req_key;
521 }
522
523 static char *__get_type_from_path(const char *pkg_path)
524 {
525         int ret;
526         char mimetype[255] = { '\0', };
527         char extlist[256] = { '\0', };
528         char *pkg_type;
529
530         ret = _get_mime_from_file(pkg_path, mimetype, sizeof(mimetype));
531         if (ret) {
532                 _LOGE("_get_mime_from_file() failed - error code[%d]\n",
533                       ret);
534                 return NULL;
535         }
536
537         ret = _get_mime_extension(mimetype, extlist, sizeof(extlist));
538         if (ret) {
539                 _LOGE("_get_mime_extension() failed - error code[%d]\n",
540                       ret);
541                 return NULL;
542         }
543
544         if (strlen(extlist) == 0)
545                 return NULL;
546
547         if (strchr(extlist, ',')) {
548                 extlist[strlen(extlist) - strlen(strchr(extlist, ','))] = '\0';
549         }
550         pkg_type = strchr(extlist, '.') + 1;
551         return strdup(pkg_type);
552 }
553
554 API int pkgmgr_client_install(pkgmgr_client * pc, const char *pkg_type,
555                               const char *descriptor_path, const char *pkg_path,
556                               const char *optional_file, pkgmgr_mode mode,
557                               pkgmgr_handler event_cb, void *data)
558 {
559         char *pkgtype;
560         char *installer_path;
561         char *req_key;
562         int req_id;
563         int i = 0;
564         char *argv[PKG_ARGC_MAX] = { NULL, };
565         char *args = NULL;
566         int argcnt = 0;
567         int len = 0;
568         char *temp = NULL;
569         int ret;
570         char *cookie = NULL;
571
572         /* Check for NULL value of pc */
573         if (pc == NULL) {
574                 _LOGD("package manager client handle is NULL\n");
575                 return PKGMGR_R_EINVAL;
576         }
577         pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
578
579         /* 0. check the pc type */
580         if (mpc->ctype != PC_REQUEST)
581                 return PKGMGR_R_EINVAL;
582
583         /* 1. check argument */
584         if (descriptor_path) {
585                 if (strlen(descriptor_path) >= PKG_STRING_LEN_MAX)
586                         return PKGMGR_R_EINVAL;
587
588                 if (access(descriptor_path, F_OK) != 0)
589                         return PKGMGR_R_EINVAL;
590         }
591
592         if (pkg_path == NULL)
593                 return PKGMGR_R_EINVAL;
594         else {
595                 if (strlen(pkg_path) >= PKG_STRING_LEN_MAX)
596                         return PKGMGR_R_EINVAL;
597
598                 if (access(pkg_path, F_OK) != 0)
599                         return PKGMGR_R_EINVAL;
600         }
601
602         if (optional_file) {
603                 if (strlen(optional_file) >= PKG_STRING_LEN_MAX)
604                         return PKGMGR_R_EINVAL;
605         }
606
607         /* 2. get installer path using pkg_path */
608         if (pkg_type) {
609                 installer_path = _get_backend_path_with_type(pkg_type);
610                 pkgtype = strdup(pkg_type);
611         } else {
612                 installer_path = _get_backend_path(pkg_path);
613                 pkgtype = __get_type_from_path(pkg_path);
614         }
615
616         if (installer_path == NULL) {
617                 free(pkgtype);
618                 return PKGMGR_R_EINVAL;
619         }
620
621         /* 3. generate req_key */
622         req_key = __get_req_key(pkg_path);
623
624         /* 4. add callback info - add callback info to pkgmgr_client */
625         req_id = _get_request_id();
626         __add_op_cbinfo(mpc, req_id, req_key, event_cb, data);
627
628         /* 5. generate argv */
629
630         /*  argv[0] installer path */
631         argv[argcnt++] = installer_path;
632         /* argv[1] */
633         argv[argcnt++] = strdup("-k");
634         /* argv[2] */
635         argv[argcnt++] = req_key;
636         /* argv[3] */
637         argv[argcnt++] = strdup("-i");
638         /* argv[(4)] if exists */
639         if (descriptor_path)
640                 argv[argcnt++] = strdup(descriptor_path);
641         /* argv[4] */
642         argv[argcnt++] = strdup(pkg_path);
643         /* argv[(5)] if exists */
644         if (optional_file){
645                 argv[argcnt++] = strdup("-o");
646                 argv[argcnt++] = strdup(optional_file);
647         }
648         /* argv[6] -q option should be located at the end of command !! */
649         if (mode == PM_QUIET)
650                 argv[argcnt++] = strdup("-q");
651
652         /*** add quote in all string for special charactor like '\n'***   FIX */
653         for (i = 0; i < argcnt; i++) {
654                 temp = g_shell_quote(argv[i]);
655                 len += (strlen(temp) + 1);
656                 g_free(temp);
657         }
658
659         args = (char *)calloc(len, sizeof(char));
660         if (args == NULL) {
661                 _LOGD("calloc failed");
662
663                 for (i = 0; i < argcnt; i++)
664                         free(argv[i]);
665
666                 free(pkgtype);
667                 return PKGMGR_R_ERROR;
668         }
669         strncpy(args, argv[0], len - 1);
670
671         for (i = 1; i < argcnt; i++) {
672                 strncat(args, " ", strlen(" "));
673                 temp = g_shell_quote(argv[i]);
674                 strncat(args, temp, strlen(temp));
675                 g_free(temp);
676         }
677         _LOGD("[args] %s [len] %d\n", args, len);
678         /******************* end of quote ************************/
679
680         /* 6. request install */
681         ret = comm_client_request(mpc->info.request.cc, req_key,
682                                   COMM_REQ_TO_INSTALLER, pkgtype, pkg_path,
683                                   args, cookie, 1);
684         if (ret < 0) {
685                 _LOGE("request failed, ret=%d\n", ret);
686
687                 for (i = 0; i < argcnt; i++)
688                         free(argv[i]);
689                 free(args);
690                 free(pkgtype);
691                 return PKGMGR_R_ECOMM;
692         }
693
694         for (i = 0; i < argcnt; i++)
695                 free(argv[i]);
696
697         free(args);
698         free(pkgtype);
699
700         return req_id;
701 }
702
703 API int pkgmgr_client_reinstall(pkgmgr_client * pc, const char *pkg_type, const char *pkgid,
704                                   const char *optional_file, pkgmgr_mode mode,
705                               pkgmgr_handler event_cb, void *data)
706 {
707         char *pkgtype = NULL;
708         char *installer_path = NULL;
709         char *req_key = NULL;
710         int req_id = 0;
711         int i = 0;
712         char *argv[PKG_ARGC_MAX] = { NULL, };
713         char *args = NULL;
714         int argcnt = 0;
715         int len = 0;
716         char *temp = NULL;
717         int ret = 0;
718         char *cookie = NULL;
719
720         /* Check for NULL value of pc */
721         retvm_if(pc == NULL, PKGMGR_R_EINVAL, "package manager client handle is NULL\n");
722
723         pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
724
725         /* 0. check the pc type */
726         retv_if(mpc->ctype != PC_REQUEST, PKGMGR_R_EINVAL);
727
728
729         /* 1. check argument */
730         retv_if(pkgid == NULL, PKGMGR_R_EINVAL);
731         retv_if(strlen(pkgid) >= PKG_STRING_LEN_MAX, PKGMGR_R_EINVAL);
732         if (optional_file) {
733                 if (strlen(optional_file) >= PKG_STRING_LEN_MAX)
734                         return PKGMGR_R_EINVAL;
735         }
736
737         /* 2. get installer path using pkg_path */
738         installer_path = _get_backend_path_with_type(pkg_type);
739         pkgtype = strdup(pkg_type);
740         tryvm_if(installer_path == NULL, ret = PKGMGR_R_EINVAL, "installer_path is null");
741
742         /* 3. generate req_key */
743         req_key = __get_req_key(pkgid);
744
745         /* 4. add callback info - add callback info to pkgmgr_client */
746         req_id = _get_request_id();
747         __add_op_cbinfo(mpc, req_id, req_key, event_cb, data);
748
749         /* 5. generate argv */
750
751         /*  argv[0] installer path */
752         argv[argcnt++] = installer_path;
753         /* argv[1] */
754         argv[argcnt++] = strdup("-k");
755         /* argv[2] */
756         argv[argcnt++] = req_key;
757         /* argv[3] */
758         argv[argcnt++] = strdup("-r");
759         /* argv[4] */
760         argv[argcnt++] = strdup(pkgid);
761         /* argv[(5)] if exists */
762         if (optional_file){
763                 argv[argcnt++] = strdup("-o");
764                 argv[argcnt++] = strdup(optional_file);
765         }
766
767         /* argv[5] -q option should be located at the end of command !! */
768         if (mode == PM_QUIET)
769                 argv[argcnt++] = strdup("-q");
770
771         /*** add quote in all string for special charactor like '\n'***   FIX */
772         for (i = 0; i < argcnt; i++) {
773                 temp = g_shell_quote(argv[i]);
774                 len += (strlen(temp) + 1);
775                 g_free(temp);
776         }
777
778         args = (char *)calloc(len, sizeof(char));
779         tryvm_if(args == NULL, ret = PKGMGR_R_ERROR, "calloc failed");
780
781         strncpy(args, argv[0], len - 1);
782
783         for (i = 1; i < argcnt; i++) {
784                 strncat(args, " ", strlen(" "));
785                 temp = g_shell_quote(argv[i]);
786                 strncat(args, temp, strlen(temp));
787                 g_free(temp);
788         }
789         _LOGD("[args] %s [len] %d\n", args, len);
790         /******************* end of quote ************************/
791
792         /* 6. request install */
793         ret = comm_client_request(mpc->info.request.cc, req_key, COMM_REQ_TO_INSTALLER, pkgtype, pkgid, args, cookie, 1);
794         tryvm_if(ret < 0, ret = PKGMGR_R_ECOMM, "request failed");
795
796         ret = req_id;
797
798 catch:
799         for (i = 0; i < argcnt; i++)
800                 free(argv[i]);
801
802         free(args);
803         free(pkgtype);
804
805         return ret;
806 }
807
808 static inline int __pkgmgr_read_proc(const char *path, char *buf, int size)
809 {
810         int fd;
811         int ret;
812
813         if (buf == NULL || path == NULL)
814                 return -1;
815
816         fd = open(path, O_RDONLY);
817         if (fd < 0)
818                 return -1;
819
820         ret = read(fd, buf, size - 1);
821         if (ret <= 0) {
822                 close(fd);
823                 return -1;
824         } else
825                 buf[ret] = 0;
826
827         close(fd);
828
829         return ret;
830 }
831
832 static inline int __pkgmgr_find_pid_by_cmdline(const char *dname,
833                                       const char *cmdline, const char *apppath)
834 {
835         int pid = 0;
836
837         if (strncmp(cmdline, apppath, PKG_STRING_LEN_MAX-1) == 0) {
838                 pid = atoi(dname);
839                 if (pid != getpgid(pid))
840                         pid = 0;
841         }
842
843         return pid;
844 }
845
846
847 static int __pkgmgr_proc_iter_kill_cmdline(const char *apppath)
848 {
849         DIR *dp;
850         struct dirent *dentry;
851         int pid;
852         int ret;
853         char buf[PKG_STRING_LEN_MAX];
854
855         dp = opendir("/proc");
856         if (dp == NULL) {
857                 return -1;
858         }
859
860         while ((dentry = readdir(dp)) != NULL) {
861                 if (!isdigit(dentry->d_name[0]))
862                         continue;
863
864                 snprintf(buf, sizeof(buf), "/proc/%s/cmdline", dentry->d_name);
865                 ret = __pkgmgr_read_proc(buf, buf, sizeof(buf));
866                 if (ret <= 0)
867                         continue;
868
869                 pid = __pkgmgr_find_pid_by_cmdline(dentry->d_name, buf, apppath);
870
871                 if (pid > 0) {
872                         int pgid;
873
874                         pgid = getpgid(pid);
875                         if (pgid <= 1) {
876                                 closedir(dp);
877                                 return -1;
878                         }
879
880                         if (killpg(pgid, SIGKILL) < 0) {
881                                 closedir(dp);
882                                 return -1;
883                         }
884                 }
885         }
886
887         closedir(dp);
888         return 0;
889 }
890
891
892 static int __app_list_cb (const pkgmgr_appinfo_h handle,
893                                                 void *user_data)
894 {
895         char *exec = NULL;
896         pkgmgr_appinfo_get_exec(handle, &exec);
897
898         __pkgmgr_proc_iter_kill_cmdline(exec);
899
900         return 0;
901 }
902
903
904 API int pkgmgr_client_uninstall(pkgmgr_client *pc, const char *pkg_type,
905                                 const char *pkgid, pkgmgr_mode mode,
906                                 pkgmgr_handler event_cb, void *data)
907 {
908         char *pkgtype;
909         char *installer_path;
910         char *req_key;
911         int req_id;
912         int i = 0;
913         char *argv[PKG_ARGC_MAX] = { NULL, };
914         char *args = NULL;
915         int argcnt = 0;
916         int len = 0;
917         char *temp = NULL;
918         int ret = -1;
919         char *cookie = NULL;
920
921         /* Check for NULL value of pc */
922         retvm_if(pc == NULL, PKGMGR_R_EINVAL, "package manager client handle is NULL\n");
923
924         pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
925
926         /* 0. check the pc type */
927         retv_if(mpc->ctype != PC_REQUEST, PKGMGR_R_EINVAL);
928
929         /* 1. check argument */
930         retv_if(pkgid == NULL, PKGMGR_R_EINVAL);
931
932         pkgmgr_pkginfo_h handle;
933         ret = pkgmgr_pkginfo_get_pkginfo(pkgid, &handle);
934
935         /*check package id      */
936         tryvm_if(ret < 0, ret = PKGMGR_R_EINVAL, "pkgmgr_pkginfo_get_pkginfo fail");
937         tryvm_if(handle == NULL, ret = PKGMGR_R_EINVAL, "Pkgid(%s) can not find in installed pkg DB! \n", pkgid);
938
939         /*check running app , terminate app if it is running*/
940         ret = pkgmgr_appinfo_get_list(handle, PM_UI_APP, __app_list_cb, NULL);
941         tryvm_if(ret < 0, ret = PKGMGR_R_EINVAL, "pkgmgr_appinfo_get_list : PM_UI_APP fail");
942
943         /*check running app , terminate app if it is running*/
944         ret = pkgmgr_appinfo_get_list(handle, PM_SVC_APP, __app_list_cb, NULL);
945         tryvm_if(ret < 0, ret = PKGMGR_R_EINVAL, "pkgmgr_appinfo_get_list : PM_SVC_APP fail");
946
947         /*check type    */
948         ret = pkgmgr_pkginfo_get_type(handle, &pkgtype);
949         tryvm_if(ret < 0, ret = PKGMGR_R_EINVAL, "pkgmgr_pkginfo_get_type fail");
950         tryvm_if(pkgtype == NULL, ret = PKGMGR_R_ERROR, "pkgtype is NULL");
951
952         /*check pkgid length    */
953         tryvm_if(strlen(pkgid) >= PKG_STRING_LEN_MAX, ret = PKGMGR_R_EINVAL, "pkgid is too long");
954
955         /* 2. get installer path using pkgtype */
956         installer_path = _get_backend_path_with_type(pkgtype);
957         tryvm_if(installer_path == NULL, ret = PKGMGR_R_EINVAL, "installer_path fail");
958
959         /* 3. generate req_key */
960         req_key = __get_req_key(pkgid);
961
962         /* 4. add callback info - add callback info to pkgmgr_client */
963         req_id = _get_request_id();
964         __add_op_cbinfo(mpc, req_id, req_key, event_cb, data);
965
966         /* 5. generate argv */
967
968         /* argv[0] installer path */
969         argv[argcnt++] = installer_path;
970         /* argv[1] */
971         argv[argcnt++] = strdup("-k");
972         /* argv[2] */
973         argv[argcnt++] = req_key;
974         /* argv[3] */
975         argv[argcnt++] = strdup("-d");
976         /* argv[4] */
977         argv[argcnt++] = strdup(pkgid);
978         /* argv[5] -q option should be located at the end of command !! */
979         if (mode == PM_QUIET)
980                 argv[argcnt++] = strdup("-q");
981
982         /*** add quote in all string for special charactor like '\n'***   FIX */
983         for (i = 0; i < argcnt; i++) {
984                 temp = g_shell_quote(argv[i]);
985                 len += (strlen(temp) + 1);
986                 g_free(temp);
987         }
988
989         args = (char *)calloc(len, sizeof(char));
990         tryvm_if(args == NULL, ret = PKGMGR_R_ERROR, "calloc failed");
991
992         strncpy(args, argv[0], len - 1);
993
994         for (i = 1; i < argcnt; i++) {
995                 strncat(args, " ", strlen(" "));
996                 temp = g_shell_quote(argv[i]);
997                 strncat(args, temp, strlen(temp));
998                 g_free(temp);
999         }
1000         _LOGD("[args] %s [len] %d\n", args, len);
1001         /******************* end of quote ************************/
1002
1003         /* 6. request install */
1004         ret = comm_client_request(mpc->info.request.cc, req_key, COMM_REQ_TO_INSTALLER, pkgtype, pkgid, args, cookie, 1);
1005         tryvm_if(ret < 0, ret = PKGMGR_R_ECOMM, "calloc failed");
1006
1007         for (i = 0; i < argcnt; i++)
1008                 free(argv[i]);
1009
1010         free(args);
1011
1012         pkgmgr_pkginfo_destroy_pkginfo(handle);
1013         return req_id;
1014
1015 catch:
1016         for (i = 0; i < argcnt; i++)
1017                 free(argv[i]);
1018
1019         if(args)
1020                 free(args);
1021
1022         pkgmgr_pkginfo_destroy_pkginfo(handle);
1023         PKGMGR_END();\
1024         return ret;
1025 }
1026
1027 API int pkgmgr_client_move(pkgmgr_client *pc, const char *pkg_type,
1028                                 const char *pkgid, pkgmgr_move_type move_type, pkgmgr_mode mode)
1029 {
1030         const char *pkgtype = NULL;
1031         char *installer_path = NULL;
1032         char *req_key = NULL;
1033         int i = 0;
1034         char *argv[PKG_ARGC_MAX] = { NULL, };
1035         char *args = NULL;
1036         int argcnt = 0;
1037         int len = 0;
1038         char *temp = NULL;
1039         int ret = 0;
1040         int req_id = 0;
1041         char *cookie = NULL;
1042         char buf[128] = {'\0'};
1043
1044         /* Check for NULL value of pc */
1045         if (pc == NULL) {
1046                 _LOGD("package manager client handle is NULL\n");
1047                 return PKGMGR_R_EINVAL;
1048         }
1049         pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
1050         /*check the pc type */
1051         if (mpc->ctype != PC_REQUEST)
1052                 return PKGMGR_R_EINVAL;
1053
1054         /*check argument */
1055         if (pkgid == NULL)
1056                 return PKGMGR_R_EINVAL;
1057
1058         if (pkg_type == NULL) {
1059                 pkgtype = _get_pkg_type_from_desktop_file(pkgid);
1060                 if (pkgtype == NULL)
1061                         return PKGMGR_R_EINVAL;
1062         } else
1063                 pkgtype = pkg_type;
1064
1065         if (strlen(pkgid) >= PKG_STRING_LEN_MAX)
1066                 return PKGMGR_R_EINVAL;
1067
1068         if ((move_type < PM_MOVE_TO_INTERNAL) || (move_type > PM_MOVE_TO_SDCARD))
1069                 return PKGMGR_R_EINVAL;
1070
1071         /* get installer path using pkg_path */
1072         installer_path = _get_backend_path_with_type(pkgtype);
1073         if (installer_path == NULL)
1074                 return PKGMGR_R_EINVAL;
1075
1076         /* generate req_key */
1077         req_key = __get_req_key(pkgid);
1078         req_id = _get_request_id();
1079
1080         /* generate argv */
1081         snprintf(buf, 128, "%d", move_type);
1082         /* argv[0] installer path */
1083         argv[argcnt++] = installer_path;
1084         /* argv[1] */
1085         argv[argcnt++] = strdup("-k");
1086         /* argv[2] */
1087         argv[argcnt++] = req_key;
1088         /* argv[3] */
1089         argv[argcnt++] = strdup("-m");
1090         /* argv[4] */
1091         argv[argcnt++] = strdup(pkgid);
1092         /* argv[5] */
1093         argv[argcnt++] = strdup("-t");
1094         /* argv[6] */
1095         argv[argcnt++] = strdup(buf);
1096         /* argv[7] -q option should be located at the end of command !! */
1097         if (mode == PM_QUIET)
1098                 argv[argcnt++] = strdup("-q");
1099
1100         /*** add quote in all string for special charactor like '\n'***   FIX */
1101         for (i = 0; i < argcnt; i++) {
1102                 temp = g_shell_quote(argv[i]);
1103                 len += (strlen(temp) + 1);
1104                 g_free(temp);
1105         }
1106
1107         args = (char *)calloc(len, sizeof(char));
1108         if (args == NULL) {
1109                 _LOGD("calloc failed");
1110
1111                 for (i = 0; i < argcnt; i++)
1112                         free(argv[i]);
1113
1114                 return PKGMGR_R_ERROR;
1115         }
1116         strncpy(args, argv[0], len - 1);
1117
1118         for (i = 1; i < argcnt; i++) {
1119                 strncat(args, " ", strlen(" "));
1120                 temp = g_shell_quote(argv[i]);
1121                 strncat(args, temp, strlen(temp));
1122                 g_free(temp);
1123         }
1124         _LOGD("[args] %s [len] %d\n", args, len);
1125         /******************* end of quote ************************/
1126
1127         /* 6. request install */
1128         ret = comm_client_request(mpc->info.request.cc, req_key,
1129                                   COMM_REQ_TO_MOVER, pkgtype, pkgid,
1130                                   args, cookie, 1);
1131         if (ret < 0) {
1132                 _LOGE("request failed, ret=%d\n", ret);
1133
1134                 for (i = 0; i < argcnt; i++)
1135                         free(argv[i]);
1136
1137                 free(args);
1138                 return PKGMGR_R_ECOMM;
1139         }
1140
1141         for (i = 0; i < argcnt; i++)
1142                 free(argv[i]);
1143
1144         free(args);
1145
1146         return req_id;
1147 }
1148
1149 API int pkgmgr_client_activate(pkgmgr_client * pc, const char *pkg_type,
1150                                const char *pkgid)
1151 {
1152         const char *pkgtype;
1153         char *req_key;
1154         char *cookie = NULL;
1155         int ret;
1156         /* Check for NULL value of pc */
1157         if (pc == NULL) {
1158                 _LOGD("package manager client handle is NULL\n");
1159                 return PKGMGR_R_EINVAL;
1160         }
1161         pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
1162
1163         /* 0. check the pc type */
1164         if (mpc->ctype != PC_REQUEST)
1165                 return PKGMGR_R_EINVAL;
1166
1167         /* 1. check argument */
1168         if (pkgid == NULL)
1169                 return PKGMGR_R_EINVAL;
1170
1171         if (pkg_type == NULL) {
1172                 pkgtype = _get_pkg_type_from_desktop_file(pkgid);
1173                 if (pkgtype == NULL)
1174                         return PKGMGR_R_EINVAL;
1175         } else
1176                 pkgtype = pkg_type;
1177
1178         if (strlen(pkgid) >= PKG_STRING_LEN_MAX)
1179                 return PKGMGR_R_EINVAL;
1180
1181         /* 2. generate req_key */
1182         req_key = __get_req_key(pkgid);
1183
1184         /* 3. request activate */
1185         ret = comm_client_request(mpc->info.request.cc, req_key,
1186                                   COMM_REQ_TO_ACTIVATOR, pkgtype,
1187                                   pkgid, "1 PKG", cookie, 1);
1188         if (ret < 0) {
1189                 _LOGE("request failed, ret=%d\n", ret);
1190                 free(req_key);
1191                 return PKGMGR_R_ECOMM;
1192         }
1193
1194         free(req_key);
1195
1196         return PKGMGR_R_OK;
1197 }
1198
1199 API int pkgmgr_client_deactivate(pkgmgr_client *pc, const char *pkg_type,
1200                                  const char *pkgid)
1201 {
1202         const char *pkgtype;
1203         char *req_key;
1204         char *cookie = NULL;
1205         int ret;
1206         /* Check for NULL value of pc */
1207         if (pc == NULL) {
1208                 _LOGD("package manager client handle is NULL\n");
1209                 return PKGMGR_R_EINVAL;
1210         }
1211         pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
1212
1213         /* 0. check the pc type */
1214         if (mpc->ctype != PC_REQUEST)
1215                 return PKGMGR_R_EINVAL;
1216
1217         /* 1. check argument */
1218         if (pkgid == NULL)
1219                 return PKGMGR_R_EINVAL;
1220
1221         if (pkg_type == NULL) {
1222                 pkgtype = _get_pkg_type_from_desktop_file(pkgid);
1223                 if (pkgtype == NULL)
1224                         return PKGMGR_R_EINVAL;
1225         } else
1226                 pkgtype = pkg_type;
1227
1228         if (strlen(pkgid) >= PKG_STRING_LEN_MAX)
1229                 return PKGMGR_R_EINVAL;
1230
1231         /* 2. generate req_key */
1232         req_key = __get_req_key(pkgid);
1233
1234         /* 3. request activate */
1235         ret = comm_client_request(mpc->info.request.cc, req_key,
1236                                   COMM_REQ_TO_ACTIVATOR, pkgtype,
1237                                   pkgid, "0 PKG", cookie, 1);
1238         if (ret < 0) {
1239                 _LOGE("request failed, ret=%d\n", ret);
1240                 free(req_key);
1241                 return PKGMGR_R_ECOMM;
1242         }
1243
1244         free(req_key);
1245
1246         return PKGMGR_R_OK;
1247 }
1248
1249 API int pkgmgr_client_activate_app(pkgmgr_client * pc, const char *appid)
1250 {
1251         const char *pkgtype;
1252         char *req_key;
1253         char *cookie = NULL;
1254         int ret;
1255         /* Check for NULL value of pc */
1256         if (pc == NULL) {
1257                 _LOGD("package manager client handle is NULL\n");
1258                 return PKGMGR_R_EINVAL;
1259         }
1260         pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
1261
1262         /* 0. check the pc type */
1263         if (mpc->ctype != PC_REQUEST)
1264                 return PKGMGR_R_EINVAL;
1265
1266         /* 1. check argument */
1267         if (appid == NULL)
1268                 return PKGMGR_R_EINVAL;
1269
1270         if (strlen(appid) >= PKG_STRING_LEN_MAX)
1271                 return PKGMGR_R_EINVAL;
1272
1273         pkgtype = _get_pkg_type_from_desktop_file(appid);
1274
1275         /* 2. generate req_key */
1276         req_key = __get_req_key(appid);
1277
1278         /* 3. request activate */
1279         ret = comm_client_request(mpc->info.request.cc, req_key,
1280                                   COMM_REQ_TO_ACTIVATOR, pkgtype,
1281                                   appid, "1 APP", cookie, 1);
1282         if (ret < 0) {
1283                 _LOGE("request failed, ret=%d\n", ret);
1284                 free(req_key);
1285                 return PKGMGR_R_ECOMM;
1286         }
1287
1288         free(req_key);
1289
1290         return PKGMGR_R_OK;
1291 }
1292
1293 API int pkgmgr_client_activate_appv(pkgmgr_client * pc, const char *appid, char *const argv[])
1294 {
1295         const char *pkgtype;
1296         char *req_key;
1297         char *cookie = NULL;
1298         int ret;
1299         int i = 0;
1300         char *temp = NULL;
1301         int len = 0;
1302         int argcnt = 0;
1303         char *args = NULL;
1304         char *argsr = NULL;
1305         /* Check for NULL value of pc */
1306         if (pc == NULL) {
1307                 _LOGD("package manager client handle is NULL\n");
1308                 return PKGMGR_R_EINVAL;
1309         }
1310         pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
1311
1312         /* 0. check the pc type */
1313         if (mpc->ctype != PC_REQUEST)
1314                 return PKGMGR_R_EINVAL;
1315
1316         /* 1. check argument */
1317         if (appid == NULL)
1318                 return PKGMGR_R_EINVAL;
1319
1320         if (strlen(appid) >= PKG_STRING_LEN_MAX)
1321                 return PKGMGR_R_EINVAL;
1322
1323         pkgtype = _get_pkg_type_from_desktop_file(appid);
1324
1325         /* 2. generate req_key */
1326         req_key = __get_req_key(appid);
1327
1328         /*** add quote in all string for special charactor like '\n'***   FIX */
1329         if (argv) {
1330                 for (i = 0; argv[i]; i++) {
1331                         temp = g_shell_quote(argv[i]);
1332                         len += (strlen(temp) + 1);
1333                         g_free(temp);
1334                         argcnt++;
1335                 }
1336
1337                 if (argcnt) {
1338                         args = (char *)calloc(len, sizeof(char));
1339                         if (args == NULL) {
1340                                 _LOGE("calloc failed");
1341                                 free(req_key);
1342                                 return PKGMGR_R_ERROR;
1343                         }
1344                         strncpy(args, argv[0], len - 1);
1345
1346                         for (i = 1; i < argcnt; i++) {
1347                                 strncat(args, " ", strlen(" "));
1348                                 temp = g_shell_quote(argv[i]);
1349                                 strncat(args, temp, strlen(temp));
1350                                 g_free(temp);
1351                         }
1352                 }
1353         }
1354
1355         argsr = (char *)calloc(strlen("1 APP")+2+len, sizeof(char));
1356         if (argsr == NULL) {
1357                 _LOGE("calloc failed");
1358                 free(req_key);
1359                 free(args);
1360                 return PKGMGR_R_ERROR;
1361         }
1362         strncpy(argsr, "1 APP", strlen("1 APP"));
1363         if (argcnt) {
1364                 strncat(argsr, " ", strlen(" "));
1365                 strncat(argsr, args, strlen(args));
1366         }
1367
1368         _LOGD("argsr [%s]\n", argsr);
1369         /******************* end of quote ************************/
1370
1371         /* 3. request activate */
1372         ret = comm_client_request(mpc->info.request.cc, req_key,
1373                                   COMM_REQ_TO_ACTIVATOR, pkgtype,
1374                                   appid, argsr, cookie, 1);
1375         if (ret < 0) {
1376                 _LOGE("request failed, ret=%d\n", ret);
1377                 free(req_key);
1378                 free(args);
1379                 free(argsr);
1380                 return PKGMGR_R_ECOMM;
1381         }
1382
1383         free(req_key);
1384         free(args);
1385         free(argsr);
1386
1387         return PKGMGR_R_OK;
1388 }
1389
1390 API int pkgmgr_client_deactivate_app(pkgmgr_client *pc, const char *appid)
1391 {
1392         const char *pkgtype;
1393         char *req_key;
1394         char *cookie = NULL;
1395         int ret;
1396         /* Check for NULL value of pc */
1397         if (pc == NULL) {
1398                 _LOGD("package manager client handle is NULL\n");
1399                 return PKGMGR_R_EINVAL;
1400         }
1401         pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
1402
1403         /* 0. check the pc type */
1404         if (mpc->ctype != PC_REQUEST)
1405                 return PKGMGR_R_EINVAL;
1406
1407         /* 1. check argument */
1408         if (appid == NULL)
1409                 return PKGMGR_R_EINVAL;
1410
1411         if (strlen(appid) >= PKG_STRING_LEN_MAX)
1412                 return PKGMGR_R_EINVAL;
1413
1414         pkgtype = _get_pkg_type_from_desktop_file(appid);
1415
1416         /* 2. generate req_key */
1417         req_key = __get_req_key(appid);
1418
1419         /* 3. request activate */
1420         ret = comm_client_request(mpc->info.request.cc, req_key,
1421                                   COMM_REQ_TO_ACTIVATOR, pkgtype,
1422                                   appid, "0 APP", cookie, 1);
1423         if (ret < 0) {
1424                 _LOGE("request failed, ret=%d\n", ret);
1425                 free(req_key);
1426                 return PKGMGR_R_ECOMM;
1427         }
1428
1429         free(req_key);
1430
1431         return PKGMGR_R_OK;
1432 }
1433
1434
1435 API int pkgmgr_client_clear_user_data(pkgmgr_client *pc, const char *pkg_type,
1436                                       const char *appid, pkgmgr_mode mode)
1437 {
1438         const char *pkgtype;
1439         char *installer_path;
1440         char *req_key;
1441         int i = 0;
1442         char *argv[PKG_ARGC_MAX] = { NULL, };
1443         char *args = NULL;
1444         int argcnt = 0;
1445         int len = 0;
1446         char *temp = NULL;
1447         int ret;
1448         char *cookie = NULL;
1449
1450         /* Check for NULL value of pc */
1451         if (pc == NULL) {
1452                 _LOGD("package manager client handle is NULL\n");
1453                 return PKGMGR_R_EINVAL;
1454         }
1455         pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
1456
1457         /* 0. check the pc type */
1458         if (mpc->ctype != PC_REQUEST)
1459                 return PKGMGR_R_EINVAL;
1460
1461         /* 1. check argument */
1462         if (appid == NULL)
1463                 return PKGMGR_R_EINVAL;
1464
1465
1466         if (pkg_type == NULL) {
1467                 pkgtype = _get_pkg_type_from_desktop_file(appid);
1468                 if (pkgtype == NULL)
1469                         return PKGMGR_R_EINVAL;
1470         } else
1471                 pkgtype = pkg_type;
1472
1473         if (strlen(appid) >= PKG_STRING_LEN_MAX)
1474                 return PKGMGR_R_EINVAL;
1475
1476         /* 2. get installer path using pkg_path */
1477         installer_path = _get_backend_path_with_type(pkgtype);
1478         if (installer_path == NULL)
1479                 return PKGMGR_R_EINVAL;
1480
1481         /* 3. generate req_key */
1482         req_key = __get_req_key(appid);
1483
1484         /* 4. generate argv */
1485
1486         /* argv[0] installer path */
1487         argv[argcnt++] = installer_path;
1488         /* argv[1] */
1489         argv[argcnt++] = strdup("-k");
1490         /* argv[2] */
1491         argv[argcnt++] = req_key;
1492         /* argv[3] */
1493         argv[argcnt++] = strdup("-c");
1494         /* argv[4] */
1495         argv[argcnt++] = strdup(appid);
1496         /* argv[5] -q option should be located at the end of command !! */
1497         if (mode == PM_QUIET)
1498                 argv[argcnt++] = strdup("-q");
1499
1500         /*** add quote in all string for special charactor like '\n'***   FIX */
1501         for (i = 0; i < argcnt; i++) {
1502                 temp = g_shell_quote(argv[i]);
1503                 len += (strlen(temp) + 1);
1504                 g_free(temp);
1505         }
1506
1507         args = (char *)calloc(len, sizeof(char));
1508         if (args == NULL) {
1509                 _LOGD("calloc failed");
1510
1511                 for (i = 0; i < argcnt; i++)
1512                         free(argv[i]);
1513
1514                 return PKGMGR_R_ERROR;
1515         }
1516         strncpy(args, argv[0], len - 1);
1517
1518         for (i = 1; i < argcnt; i++) {
1519                 strncat(args, " ", strlen(" "));
1520                 temp = g_shell_quote(argv[i]);
1521                 strncat(args, temp, strlen(temp));
1522                 g_free(temp);
1523         }
1524         _LOGD("[args] %s [len] %d\n", args, len);
1525         /******************* end of quote ************************/
1526
1527         /* 6. request clear */
1528         ret = comm_client_request(mpc->info.request.cc, req_key,
1529                                   COMM_REQ_TO_CLEARER, pkgtype, appid,
1530                                   args, cookie, 1);
1531         if (ret < 0) {
1532                 _LOGE("request failed, ret=%d\n", ret);
1533
1534                 for (i = 0; i < argcnt; i++)
1535                         free(argv[i]);
1536
1537                 free(args);
1538                 return PKGMGR_R_ECOMM;
1539         }
1540
1541         for (i = 0; i < argcnt; i++)
1542                 free(argv[i]);
1543
1544         free(args);
1545
1546         return PKGMGR_R_OK;
1547 }
1548
1549 API int pkgmgr_client_listen_status(pkgmgr_client *pc, pkgmgr_handler event_cb,
1550                                     void *data)
1551 {
1552         int req_id;
1553         /* Check for NULL value of pc */
1554         if (pc == NULL) {
1555                 _LOGD("package manager client handle is NULL\n");
1556                 return PKGMGR_R_EINVAL;
1557         }
1558         pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
1559
1560         /* 0. check the pc type */
1561         if (mpc->ctype != PC_LISTENING)
1562                 return PKGMGR_R_EINVAL;
1563
1564         /* 1. check argument */
1565         if (event_cb == NULL)
1566                 return PKGMGR_R_EINVAL;
1567
1568         /* 2. add callback info to pkgmgr_client */
1569         req_id = _get_request_id();
1570         __add_stat_cbinfo(mpc, req_id, event_cb, data);
1571
1572         return req_id;
1573 }
1574
1575 API int pkgmgr_client_broadcast_status(pkgmgr_client *pc, const char *pkg_type,
1576                                        const char *pkgid, const char *key,
1577                                        const char *val)
1578 {
1579         /* Check for NULL value of pc */
1580         if (pc == NULL) {
1581                 _LOGD("package manager client handle is NULL\n");
1582                 return PKGMGR_R_EINVAL;
1583         }
1584         /* Check for valid arguments. NULL parameter causes DBUS to abort */
1585         if (pkgid == NULL || pkg_type == NULL || key == NULL || val == NULL) {
1586                 _LOGD("Argument supplied is NULL\n");
1587                 return PKGMGR_R_EINVAL;
1588         }
1589         pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
1590
1591         /* 0. check the pc type */
1592         if (mpc->ctype != PC_BROADCAST)
1593                 return PKGMGR_R_EINVAL;
1594
1595         comm_status_broadcast_server_send_signal(mpc->info.broadcast.bc,
1596                                                  PKG_STATUS, pkg_type,
1597                                                  pkgid, key, val);
1598
1599         return PKGMGR_R_OK;
1600 }
1601
1602 API pkgmgr_info *pkgmgr_client_check_pkginfo_from_file(const char *pkg_path)
1603 {
1604         return pkgmgr_info_new_from_file(NULL, pkg_path);
1605 }
1606
1607 API int pkgmgr_client_free_pkginfo(pkgmgr_info * pkg_info)
1608 {
1609         if (pkg_info == NULL)
1610                 return PKGMGR_R_EINVAL;
1611
1612         package_manager_pkg_detail_info_t *info = (package_manager_pkg_detail_info_t *)pkg_info;
1613
1614         if (info->icon_buf)
1615                 free(info->icon_buf);
1616
1617         if (info->privilege_list)
1618                 g_list_free(info->privilege_list);
1619
1620         free(info);
1621         info = NULL;
1622
1623         return PKGMGR_R_OK;
1624 }
1625
1626 API int pkgmgr_client_request_service(pkgmgr_request_service_type service_type, 
1627                                   pkgmgr_client * pc, const char *pkg_type, const char *pkgid,
1628                               const char *optional_file, void *optional_mode,
1629                               pkgmgr_handler event_cb, void *data)
1630 {
1631         char *installer_path;
1632         char *req_key;
1633         int req_id;
1634         int ret;
1635
1636         /* Check for NULL value of service type */
1637         retvm_if(service_type > PM_REQUEST_MAX, PKGMGR_R_EINVAL, "service type is not defined\n");
1638
1639         /* check optional_file length */
1640         if (optional_file)
1641                 retvm_if(strlen(optional_file) >= PKG_STRING_LEN_MAX, PKGMGR_R_EINVAL, "optional_file over PKG_STRING_LEN_MAX");
1642
1643         /* add callback info - add callback info to pkgmgr_client if there is pc and pkgid */
1644         if (pc && pkgid) {
1645                 pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
1646                 retv_if(mpc->ctype != PC_REQUEST, PKGMGR_R_EINVAL);
1647                 req_key = __get_req_key(pkgid);
1648                 req_id = _get_request_id();
1649                 __add_op_cbinfo(mpc, req_id, req_key, event_cb, data);
1650         }
1651
1652         switch (service_type) {
1653         case PM_REQUEST_CSC:
1654                 ret = __csc_process(optional_file, (char *)data);
1655                 if (ret < 0)
1656                         _LOGE("__csc_process fail \n");
1657                 break;
1658
1659         case PM_REQUEST_MOVE:
1660                 ret = 0;
1661                 break;
1662
1663         case PM_REQUEST_GET_SIZE:
1664                 ret = 0;
1665                 break;
1666
1667         default:
1668                 printf("Wrong Request\n");
1669                 ret = -1;
1670                 break;
1671         }
1672
1673         return req_id;
1674 }
1675
1676
1677 #define __START_OF_OLD_API
1678 ail_cb_ret_e __appinfo_func(const ail_appinfo_h appinfo, void *user_data)
1679 {
1680         char *type;
1681         char *package;
1682         char *version;
1683
1684         iter_data *udata = (iter_data *) user_data;
1685
1686         ail_appinfo_get_str(appinfo, AIL_PROP_X_SLP_PACKAGETYPE_STR, &type);
1687         if (type == NULL)
1688                 type = "";
1689         ail_appinfo_get_str(appinfo, AIL_PROP_PACKAGE_STR, &package);
1690         if (package == NULL)
1691                 package = "";
1692         ail_appinfo_get_str(appinfo, AIL_PROP_VERSION_STR, &version);
1693         if (version == NULL)
1694                 version = "";
1695
1696         if (udata->iter_fn(type, package, version, udata->data) != 0)
1697                 return AIL_CB_RET_CANCEL;
1698
1699         return AIL_CB_RET_CONTINUE;
1700 }
1701
1702 API int pkgmgr_get_pkg_list(pkgmgr_iter_fn iter_fn, void *data)
1703 {
1704         int cnt = -1;
1705         ail_filter_h filter;
1706         ail_error_e ret;
1707
1708         if (iter_fn == NULL)
1709                 return PKGMGR_R_EINVAL;
1710
1711         ret = ail_filter_new(&filter);
1712         if (ret != AIL_ERROR_OK) {
1713                 return PKGMGR_R_ERROR;
1714         }
1715
1716         ret = ail_filter_add_str(filter, AIL_PROP_TYPE_STR, "Application");
1717         if (ret != AIL_ERROR_OK) {
1718                 ail_filter_destroy(filter);
1719                 return PKGMGR_R_ERROR;
1720         }
1721
1722         ret = ail_filter_add_bool(filter, AIL_PROP_X_SLP_REMOVABLE_BOOL, true);
1723         if (ret != AIL_ERROR_OK) {
1724                 ail_filter_destroy(filter);
1725                 return PKGMGR_R_ERROR;
1726         }
1727
1728         ret = ail_filter_count_appinfo(filter, &cnt);
1729         if (ret != AIL_ERROR_OK) {
1730                 ail_filter_destroy(filter);
1731                 return PKGMGR_R_ERROR;
1732         }
1733
1734         iter_data *udata = calloc(1, sizeof(iter_data));
1735         if (udata == NULL) {
1736                 _LOGE("calloc failed");
1737                 ail_filter_destroy(filter);
1738
1739                 return PKGMGR_R_ERROR;
1740         }
1741         udata->iter_fn = iter_fn;
1742         udata->data = data;
1743
1744         ail_filter_list_appinfo_foreach(filter, __appinfo_func, udata);
1745
1746         free(udata);
1747
1748         ret = ail_filter_destroy(filter);
1749         if (ret != AIL_ERROR_OK) {
1750                 return PKGMGR_R_ERROR;
1751         }
1752
1753         return PKGMGR_R_OK;
1754 }
1755
1756 API pkgmgr_info *pkgmgr_info_new(const char *pkg_type, const char *pkgid)
1757 {
1758         const char *pkgtype;
1759         pkg_plugin_set *plugin_set = NULL;
1760         package_manager_pkg_detail_info_t *pkg_detail_info = NULL;
1761
1762         /* 1. check argument */
1763         if (pkgid == NULL)
1764                 return NULL;
1765
1766         if (pkg_type == NULL) {
1767                 pkgtype = _get_pkg_type_from_desktop_file(pkgid);
1768                 if (pkgtype == NULL)
1769                         return NULL;
1770         } else
1771                 pkgtype = pkg_type;
1772
1773         if (strlen(pkgid) >= PKG_STRING_LEN_MAX)
1774                 return NULL;
1775
1776         pkg_detail_info = calloc(1, sizeof(package_manager_pkg_detail_info_t));
1777         if (pkg_detail_info == NULL) {
1778                 _LOGE("*** Failed to alloc package_handler_info.\n");
1779                 return NULL;
1780         }
1781
1782         plugin_set = _package_manager_load_library(pkgtype);
1783         if (plugin_set == NULL) {
1784                 _LOGE("*** Failed to load library");
1785                 free(pkg_detail_info);
1786                 return NULL;
1787         }
1788
1789         if (plugin_set->pkg_is_installed) {
1790                 if (plugin_set->pkg_is_installed(pkgid) != 0) {
1791                         _LOGE("*** Failed to call pkg_is_installed()");
1792                         free(pkg_detail_info);
1793                         return NULL;
1794                 }
1795
1796                 if (plugin_set->get_pkg_detail_info) {
1797                         if (plugin_set->get_pkg_detail_info(pkgid,
1798                                                             pkg_detail_info) != 0) {
1799                                 _LOGE("*** Failed to call get_pkg_detail_info()");
1800                                 free(pkg_detail_info);
1801                                 return NULL;
1802                         }
1803                 }
1804         }
1805
1806         return (pkgmgr_info *) pkg_detail_info;
1807 }
1808
1809 API char * pkgmgr_info_get_string(pkgmgr_info * pkg_info, const char *key)
1810 {
1811         package_manager_pkg_detail_info_t *pkg_detail_info;
1812
1813         if (pkg_info == NULL)
1814                 return NULL;
1815         if (key == NULL)
1816                 return NULL;
1817
1818         pkg_detail_info = (package_manager_pkg_detail_info_t *) pkg_info;
1819
1820         return _get_info_string(key, pkg_detail_info);
1821 }
1822
1823 API pkgmgr_info *pkgmgr_info_new_from_file(const char *pkg_type,
1824                                            const char *pkg_path)
1825 {
1826         pkg_plugin_set *plugin_set = NULL;
1827         package_manager_pkg_detail_info_t *pkg_detail_info = NULL;
1828         char *pkgtype;
1829         if (pkg_path == NULL) {
1830                 _LOGE("pkg_path is NULL\n");
1831                 return NULL;
1832         }
1833
1834         if (strlen(pkg_path) > PKG_URL_STRING_LEN_MAX) {
1835                 _LOGE("length of pkg_path is too long - %d.\n",
1836                       strlen(pkg_path));
1837                 return NULL;
1838         }
1839
1840         pkg_detail_info = calloc(1, sizeof(package_manager_pkg_detail_info_t));
1841         if (pkg_detail_info == NULL) {
1842                 _LOGE("*** Failed to alloc package_handler_info.\n");
1843                 return NULL;
1844         }
1845
1846         if (pkg_type == NULL)
1847                 pkgtype = __get_type_from_path(pkg_path);
1848         else
1849                 pkgtype = strdup(pkg_type);
1850
1851         plugin_set = _package_manager_load_library(pkgtype);
1852         if (plugin_set == NULL) {
1853                 free(pkg_detail_info);
1854                 free(pkgtype);
1855                 return NULL;
1856         }
1857
1858         if (plugin_set->get_pkg_detail_info_from_package) {
1859                 if (plugin_set->get_pkg_detail_info_from_package(pkg_path,
1860                                                                  pkg_detail_info) != 0) {
1861                         free(pkg_detail_info);
1862                         free(pkgtype);
1863                         return NULL;
1864                 }
1865         }
1866
1867         free(pkgtype);
1868         return (pkgmgr_info *) pkg_detail_info;
1869 }
1870
1871 API int pkgmgr_info_free(pkgmgr_info * pkg_info)
1872 {
1873         if (pkg_info == NULL)
1874                 return PKGMGR_R_EINVAL;
1875
1876         free(pkg_info);
1877         pkg_info = NULL;
1878
1879         return 0;
1880 }
1881
1882 #define __END_OF_OLD_API
1883
1884 API int pkgmgr_pkginfo_get_list(pkgmgr_info_pkg_list_cb pkg_list_cb, void *user_data)
1885 {
1886         int ret = 0;
1887         ret = pkgmgrinfo_pkginfo_get_list(pkg_list_cb, user_data);
1888         return ret;
1889 }
1890
1891 API int pkgmgr_pkginfo_get_pkginfo(const char *pkgid, pkgmgr_pkginfo_h *handle)
1892 {
1893         int ret = 0;
1894         ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, handle);
1895         return ret;
1896 }
1897
1898 API int pkgmgr_pkginfo_get_pkgname(pkgmgr_pkginfo_h handle, char **pkg_name)
1899 {
1900         int ret = 0;
1901         ret = pkgmgrinfo_pkginfo_get_pkgname(handle, pkg_name);
1902         return ret;
1903 }
1904
1905
1906 API int pkgmgr_pkginfo_get_pkgid(pkgmgr_pkginfo_h handle, char **pkgid)
1907 {
1908         int ret = 0;
1909         ret = pkgmgrinfo_pkginfo_get_pkgid(handle, pkgid);
1910         return ret;
1911 }
1912
1913 API int pkgmgr_pkginfo_get_type(pkgmgr_pkginfo_h handle, char **type)
1914 {
1915         int ret = 0;
1916         ret = pkgmgrinfo_pkginfo_get_type(handle, type);
1917         return ret;
1918 }
1919
1920 API int pkgmgr_pkginfo_get_version(pkgmgr_pkginfo_h handle, char **version)
1921 {
1922         int ret = 0;
1923         ret = pkgmgrinfo_pkginfo_get_version(handle, version);
1924         return ret;
1925 }
1926
1927 API int pkgmgr_pkginfo_get_install_location(pkgmgr_pkginfo_h handle, pkgmgr_install_location *location)
1928 {
1929         int ret = 0;
1930         pkgmgrinfo_install_location loc;
1931         ret = pkgmgrinfo_pkginfo_get_install_location(handle, &loc);
1932         *location = loc;
1933         return ret;
1934 }
1935
1936 API int pkgmgr_pkginfo_get_package_size(pkgmgr_pkginfo_h handle, int *size)
1937 {
1938         int ret = 0;
1939         ret = pkgmgrinfo_pkginfo_get_package_size(handle, size);
1940         return ret;
1941 }
1942
1943 API int pkgmgr_pkginfo_get_icon(pkgmgr_pkginfo_h handle, char **icon)
1944 {
1945         int ret = 0;
1946         ret = pkgmgrinfo_pkginfo_get_icon(handle, icon);
1947         return ret;
1948 }
1949
1950 API int pkgmgr_pkginfo_get_label(pkgmgr_pkginfo_h handle, char **label)
1951 {
1952         int ret = 0;
1953         ret = pkgmgrinfo_pkginfo_get_label(handle, label);
1954         return ret;
1955 }
1956
1957 API int pkgmgr_pkginfo_get_description(pkgmgr_pkginfo_h handle, char **description)
1958 {
1959         int ret = 0;
1960         ret = pkgmgrinfo_pkginfo_get_description(handle, description);
1961         return ret;
1962 }
1963
1964 API int pkgmgr_pkginfo_get_author_name(pkgmgr_pkginfo_h handle, char **author_name)
1965 {
1966         int ret = 0;
1967         ret = pkgmgrinfo_pkginfo_get_author_name(handle, author_name);
1968         return ret;
1969 }
1970
1971 API int pkgmgr_pkginfo_get_author_email(pkgmgr_pkginfo_h handle, char **author_email)
1972 {
1973         int ret = 0;
1974         ret = pkgmgrinfo_pkginfo_get_author_email(handle, author_email);
1975         return ret;
1976 }
1977
1978 API int pkgmgr_pkginfo_get_author_href(pkgmgr_pkginfo_h handle, char **author_href)
1979 {
1980         int ret = 0;
1981         ret = pkgmgrinfo_pkginfo_get_author_href(handle, author_href);
1982         return ret;
1983 }
1984
1985 API int pkgmgr_pkginfo_is_removable(pkgmgr_pkginfo_h handle, bool *removable)
1986 {
1987         int ret = 0;
1988         ret = pkgmgrinfo_pkginfo_is_removable(handle, removable);
1989         return ret;
1990 }
1991
1992 API int pkgmgr_pkginfo_is_preload(pkgmgr_pkginfo_h handle, bool *preload)
1993 {
1994         int ret = 0;
1995         ret = pkgmgrinfo_pkginfo_is_preload(handle, preload);
1996         return ret;
1997 }
1998
1999 API int pkgmgr_pkginfo_is_readonly(pkgmgr_pkginfo_h handle, bool *readonly)
2000 {
2001         int ret = 0;
2002         ret = pkgmgrinfo_pkginfo_is_readonly(handle, readonly);
2003         return ret;
2004 }
2005
2006 API int pkgmgr_pkginfo_is_accessible(pkgmgr_pkginfo_h handle, bool *accessible)
2007 {
2008         int ret = 0;
2009         ret = pkgmgrinfo_pkginfo_is_accessible(handle, accessible);
2010         return ret;
2011 }
2012
2013 API int pkgmgr_pkginfo_destroy_pkginfo(pkgmgr_pkginfo_h handle)
2014 {
2015         int ret = 0;
2016         ret = pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
2017         return ret;
2018 }
2019
2020 API int pkgmgr_pkginfo_get_installed_storage(pkgmgr_pkginfo_h handle, pkgmgr_installed_storage *storage)
2021 {
2022         int ret = 0;
2023         pkgmgrinfo_installed_storage sto;
2024         ret = pkgmgrinfo_pkginfo_get_installed_storage(handle, &sto);
2025         *storage = sto;
2026         return ret;
2027 }
2028
2029 API int pkgmgr_pkginfo_get_installed_time(pkgmgr_pkginfo_h handle, int *installed_time)
2030 {
2031         int ret = 0;
2032         ret = pkgmgrinfo_pkginfo_get_installed_time(handle, installed_time);
2033         return ret;
2034 }
2035
2036 API int pkgmgr_appinfo_get_list(pkgmgr_pkginfo_h handle, pkgmgr_app_component component,
2037                                                         pkgmgr_info_app_list_cb app_func, void *user_data)
2038 {
2039         int ret = 0;
2040         ret = pkgmgrinfo_appinfo_get_list(handle, component, app_func, user_data);
2041         return ret;
2042 }
2043
2044 API int pkgmgr_appinfo_foreach_category(pkgmgr_appinfo_h handle, pkgmgr_info_app_category_list_cb category_func,
2045                                                         void *user_data)
2046 {
2047         int ret = 0;
2048         ret = pkgmgrinfo_appinfo_foreach_category(handle, category_func, user_data);
2049         return ret;
2050 }
2051
2052 API int pkgmgr_appinfo_get_appinfo(const char *appid, pkgmgr_appinfo_h *handle)
2053 {
2054         int ret = 0;
2055         ret = pkgmgrinfo_appinfo_get_appinfo(appid, handle);
2056         return ret;
2057 }
2058
2059 API int pkgmgr_appinfo_get_appid(pkgmgr_appinfo_h  handle, char **appid)
2060 {
2061         int ret = 0;
2062         ret = pkgmgrinfo_appinfo_get_appid(handle, appid);
2063         return ret;
2064 }
2065
2066 API int pkgmgr_appinfo_get_pkgname(pkgmgr_appinfo_h  handle, char **pkg_name)
2067 {
2068         int ret = 0;
2069         ret = pkgmgrinfo_appinfo_get_pkgname(handle, pkg_name);
2070         return ret;
2071 }
2072
2073 API int pkgmgr_appinfo_get_pkgid(pkgmgr_appinfo_h  handle, char **pkgid)
2074 {
2075         int ret = 0;
2076         ret = pkgmgrinfo_appinfo_get_pkgid(handle, pkgid);
2077         return ret;
2078 }
2079
2080 API int pkgmgr_appinfo_get_icon(pkgmgr_appinfo_h handle, char **icon)
2081 {
2082         int ret = 0;
2083         ret = pkgmgrinfo_appinfo_get_icon(handle, icon);
2084         return ret;
2085 }
2086
2087 API int pkgmgr_appinfo_get_label(pkgmgr_appinfo_h handle, char **label)
2088 {
2089         int ret = 0;
2090         ret = pkgmgrinfo_appinfo_get_label(handle, label);
2091         return ret;
2092 }
2093
2094 API int pkgmgr_appinfo_get_exec(pkgmgr_appinfo_h  handle, char **exec)
2095 {
2096         int ret = 0;
2097         ret = pkgmgrinfo_appinfo_get_exec(handle, exec);
2098         return ret;
2099 }
2100
2101 API int pkgmgr_appinfo_get_component(pkgmgr_appinfo_h  handle, pkgmgr_app_component *component)
2102 {
2103         int ret = 0;
2104         pkgmgrinfo_app_component comp;
2105         ret = pkgmgrinfo_appinfo_get_component(handle, &comp);
2106         *component = comp;
2107         return ret;
2108 }
2109
2110 API int pkgmgr_appinfo_get_apptype(pkgmgr_appinfo_h  handle, char **app_type)
2111 {
2112         int ret = 0;
2113         ret = pkgmgrinfo_appinfo_get_apptype(handle, app_type);
2114         return ret;
2115 }
2116
2117 API int pkgmgr_appinfo_is_nodisplay(pkgmgr_appinfo_h  handle, bool *nodisplay)
2118 {
2119         int ret = 0;
2120         ret = pkgmgrinfo_appinfo_is_nodisplay(handle, nodisplay);
2121         return ret;
2122 }
2123
2124 API int pkgmgr_appinfo_is_multiple(pkgmgr_appinfo_h  handle, bool *multiple)
2125 {
2126         int ret = 0;
2127         ret = pkgmgrinfo_appinfo_is_multiple(handle, multiple);
2128         return ret;
2129 }
2130
2131 API int pkgmgr_appinfo_is_taskmanage(pkgmgr_appinfo_h  handle, bool *taskmanage)
2132 {
2133         int ret = 0;
2134         ret = pkgmgrinfo_appinfo_is_taskmanage(handle, taskmanage);
2135         return ret;
2136 }
2137
2138 API int pkgmgr_appinfo_get_hwacceleration(pkgmgr_appinfo_h  handle, pkgmgr_hwacceleration_type *hwacceleration)
2139 {
2140         int ret = 0;
2141         pkgmgrinfo_app_hwacceleration hwacc;
2142         ret = pkgmgrinfo_appinfo_get_hwacceleration(handle, &hwacc);
2143         *hwacceleration = hwacc;
2144         return ret;
2145 }
2146
2147 API int pkgmgr_appinfo_is_onboot(pkgmgr_appinfo_h  handle, bool *onboot)
2148 {
2149         int ret = 0;
2150         ret = pkgmgrinfo_appinfo_is_onboot(handle, onboot);
2151         return ret;
2152 }
2153
2154 API int pkgmgr_appinfo_is_autorestart(pkgmgr_appinfo_h  handle, bool *autorestart)
2155 {
2156         int ret = 0;
2157         ret = pkgmgrinfo_appinfo_is_autorestart(handle, autorestart);
2158         return ret;
2159 }
2160
2161 API int pkgmgr_appinfo_destroy_appinfo(pkgmgr_appinfo_h  handle)
2162 {
2163         int ret = 0;
2164         ret = pkgmgrinfo_appinfo_destroy_appinfo(handle);
2165         return ret;
2166 }
2167
2168 API int pkgmgr_pkginfo_create_certinfo(pkgmgr_certinfo_h *handle)
2169 {
2170         int ret = 0;
2171         ret = pkgmgrinfo_pkginfo_create_certinfo(handle);
2172         return ret;
2173 }
2174
2175 API int pkgmgr_pkginfo_load_certinfo(const char *pkgid, pkgmgr_certinfo_h handle)
2176 {
2177         int ret = 0;
2178         ret = pkgmgrinfo_pkginfo_load_certinfo(pkgid, handle);
2179         return ret;
2180 }
2181
2182 API int pkgmgr_pkginfo_get_cert_value(pkgmgr_certinfo_h handle, pkgmgr_cert_type cert_type, const char **cert_value)
2183 {
2184         int ret = 0;
2185         ret = pkgmgrinfo_pkginfo_get_cert_value(handle, cert_type, cert_value);
2186         return ret;
2187 }
2188
2189 API int pkgmgr_pkginfo_destroy_certinfo(pkgmgr_certinfo_h handle)
2190 {
2191         int ret = 0;
2192         ret = pkgmgrinfo_pkginfo_destroy_certinfo(handle);
2193         return ret;
2194 }
2195
2196 API int pkgmgr_datacontrol_get_info(const char *providerid, const char * type, char **appid, char **access)
2197 {
2198         int ret = 0;
2199         ret = pkgmgrinfo_datacontrol_get_info(providerid, type, appid, access);
2200         return ret;
2201 }