add a routine to check external pkg
[framework/appfw/pkgmgr-info.git] / src / pkgmgr-info.c
1 /*
2  * pkgmgr-info
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 <db-util.h>
28 #include <sqlite3.h>
29 #include <vconf.h>
30 #include <glib.h>
31 #include <ctype.h>
32 #include <assert.h>
33 #include <dlfcn.h>
34
35 #include <libxml/parser.h>
36 #include <libxml/xmlreader.h>
37 #include <libxml/xmlschemas.h>
38
39 #include <dbus/dbus.h>
40 #include <dbus/dbus-glib-lowlevel.h>
41
42 #include "pkgmgr_parser.h"
43 #include "pkgmgr-info-internal.h"
44 #include "pkgmgr-info-debug.h"
45 #include "pkgmgr-info.h"
46 #include "pkgmgr_parser_db.h"
47 #include <dirent.h>
48 #include <sys/stat.h>
49 #include <dd-mmc.h>
50
51 #ifdef LOG_TAG
52 #undef LOG_TAG
53 #endif
54 #define LOG_TAG "PKGMGR_INFO"
55
56 #define ASC_CHAR(s) (const char *)s
57 #define XML_CHAR(s) (const xmlChar *)s
58
59 #define MANIFEST_DB     "/opt/dbspace/.pkgmgr_parser.db"
60 #define MAX_QUERY_LEN   4096
61 #define MAX_CERT_TYPE   9
62 #define CERT_DB         "/opt/dbspace/.pkgmgr_cert.db"
63 #define DATACONTROL_DB  "/opt/usr/dbspace/.app-package.db"
64 #define PKG_TYPE_STRING_LEN_MAX         128
65 #define PKG_VERSION_STRING_LEN_MAX      128
66 #define PKG_VALUE_STRING_LEN_MAX                512
67 #define PKG_LOCALE_STRING_LEN_MAX               8
68 #define PKG_RW_PATH "/opt/usr/apps/"
69 #define PKG_RO_PATH "/usr/apps/"
70 #define BLOCK_SIZE      4096 /*in bytes*/
71
72 #define MMC_PATH "/opt/storage/sdcard"
73 #define PKG_SD_PATH MMC_PATH"/app2sd/"
74 #define PKG_INSTALLATION_PATH "/opt/usr/apps/"
75
76 #define FILTER_QUERY_COUNT_PACKAGE      "select count(DISTINCT package_info.package) " \
77                                 "from package_info LEFT OUTER JOIN package_localized_info " \
78                                 "ON package_info.package=package_localized_info.package " \
79                                 "and package_localized_info.package_locale='%s' where "
80
81 #define FILTER_QUERY_LIST_PACKAGE       "select DISTINCT package_info.package " \
82                                 "from package_info LEFT OUTER JOIN package_localized_info " \
83                                 "ON package_info.package=package_localized_info.package " \
84                                 "and package_localized_info.package_locale='%s' where "
85
86 #define FILTER_QUERY_COUNT_APP  "select count(DISTINCT package_app_info.app_id) " \
87                                 "from package_app_info LEFT OUTER JOIN package_app_localized_info " \
88                                 "ON package_app_info.app_id=package_app_localized_info.app_id " \
89                                 "and package_app_localized_info.app_locale='%s' " \
90                                 "LEFT OUTER JOIN package_app_app_svc " \
91                                 "ON package_app_info.app_id=package_app_app_svc.app_id " \
92                                 "LEFT OUTER JOIN package_app_app_category " \
93                                 "ON package_app_info.app_id=package_app_app_category.app_id where "
94
95 #define FILTER_QUERY_LIST_APP   "select DISTINCT package_app_info.app_id, package_app_info.app_component " \
96                                 "from package_app_info LEFT OUTER JOIN package_app_localized_info " \
97                                 "ON package_app_info.app_id=package_app_localized_info.app_id " \
98                                 "and package_app_localized_info.app_locale='%s' " \
99                                 "LEFT OUTER JOIN package_app_app_svc " \
100                                 "ON package_app_info.app_id=package_app_app_svc.app_id " \
101                                 "LEFT OUTER JOIN package_app_app_category " \
102                                 "ON package_app_info.app_id=package_app_app_category.app_id where "
103
104 #define METADATA_FILTER_QUERY_SELECT_CLAUSE     "select DISTINCT package_app_info.app_id, package_app_info.app_component " \
105                                 "from package_app_info LEFT OUTER JOIN package_app_app_metadata " \
106                                 "ON package_app_info.app_id=package_app_app_metadata.app_id where "
107
108 #define METADATA_FILTER_QUERY_UNION_CLAUSE      " UNION "METADATA_FILTER_QUERY_SELECT_CLAUSE
109
110 #define LANGUAGE_LENGTH 2
111 #define LIBAIL_PATH "/usr/lib/libail.so.0"
112
113 #define SERVICE_NAME "org.tizen.system.deviced"
114 #define PATH_NAME "/Org/Tizen/System/DeviceD/Mmc"
115 #define INTERFACE_NAME "org.tizen.system.deviced.Mmc"
116 #define METHOD_NAME "RequestMountApp2ext"
117
118 typedef struct _pkgmgr_instcertinfo_x {
119         char *pkgid;
120         char *cert_info[MAX_CERT_TYPE]; /*certificate data*/
121         int is_new[MAX_CERT_TYPE];              /*whether already exist in table or not*/
122         int ref_count[MAX_CERT_TYPE];           /*reference count of certificate data*/
123         int cert_id[MAX_CERT_TYPE];             /*certificate ID in index table*/
124 } pkgmgr_instcertinfo_x;
125
126 typedef struct _pkgmgr_certindexinfo_x {
127         int cert_id;
128         int cert_ref_count;
129 } pkgmgr_certindexinfo_x;
130
131 typedef struct _pkgmgr_pkginfo_x {
132         manifest_x *manifest_info;
133         char *locale;
134
135         struct _pkgmgr_pkginfo_x *prev;
136         struct _pkgmgr_pkginfo_x *next;
137 } pkgmgr_pkginfo_x;
138
139 typedef struct _pkgmgr_cert_x {
140         char *pkgid;
141         int cert_id;
142 } pkgmgr_cert_x;
143
144 typedef struct _pkgmgr_datacontrol_x {
145         char *appid;
146         char *access;
147 } pkgmgr_datacontrol_x;
148
149 typedef struct _pkgmgr_iconpath_x {
150         char *appid;
151         char *iconpath;
152 } pkgmgr_iconpath_x;
153
154 typedef struct _pkgmgr_image_x {
155         char *imagepath;
156 } pkgmgr_image_x;
157
158 typedef struct _pkgmgr_locale_x {
159         char *locale;
160 } pkgmgr_locale_x;
161
162 typedef struct _pkgmgr_appinfo_x {
163         const char *package;
164         char *locale;
165         pkgmgrinfo_app_component app_component;
166         union {
167                 uiapplication_x *uiapp_info;
168                 serviceapplication_x *svcapp_info;
169         };
170 } pkgmgr_appinfo_x;
171
172 typedef struct _pkgmgr_certinfo_x {
173         char *pkgid;
174         char *cert_value;
175         char *cert_info[MAX_CERT_TYPE]; /*certificate info*/
176         int cert_id[MAX_CERT_TYPE];             /*certificate ID in index table*/
177 } pkgmgr_certinfo_x;
178
179 /*For filter APIs*/
180 typedef struct _pkgmgrinfo_filter_x {
181         GSList *list;
182 } pkgmgrinfo_filter_x;
183
184 typedef struct _pkgmgrinfo_node_x {
185         int prop;
186         char *key;
187         char *value;
188 } pkgmgrinfo_node_x;
189
190 typedef struct _pkgmgrinfo_appcontrol_x {
191         int operation_count;
192         int uri_count;
193         int mime_count;
194         int subapp_count;
195         char **operation;
196         char **uri;
197         char **mime;
198         char **subapp;
199 } pkgmgrinfo_appcontrol_x;
200
201 typedef int (*sqlite_query_callback)(void *data, int ncols, char **coltxt, char **colname);
202
203 typedef int (*pkgmgr_handler)(int req_id, const char *pkg_type,
204                                 const char *pkgid, const char *key,
205                                 const char *val, const void *pmsg, void *data);
206
207 typedef void pkgmgr_client;
208 typedef void pkgmgr_info;
209
210 typedef enum {
211         PM_REQUEST_CSC = 0,
212         PM_REQUEST_MOVE = 1,
213         PM_REQUEST_GET_SIZE = 2,
214         PM_REQUEST_KILL_APP = 3,
215         PM_REQUEST_CHECK_APP = 4,
216         PM_REQUEST_MAX
217 }pkgmgr_request_service_type;
218
219 typedef enum {
220         PM_GET_TOTAL_SIZE= 0,
221         PM_GET_DATA_SIZE = 1,
222         PM_GET_ALL_PKGS = 2,
223         PM_GET_SIZE_INFO = 3,
224         PM_GET_TOTAL_AND_DATA = 4,
225         PM_GET_MAX
226 }pkgmgr_getsize_type;
227
228 typedef enum {
229         PC_REQUEST = 0,
230         PC_LISTENING,
231         PC_BROADCAST,
232 }client_type;
233
234 #define PKG_SIZE_INFO_FILE "/tmp/pkgmgr_size_info.txt"
235 #define MAX_PKG_BUF_LEN         1024
236 #define MAX_PKG_INFO_LEN        10
237
238 char *pkgtype = "rpm";
239
240 __thread sqlite3 *cert_db = NULL;
241
242 static int __exec_certinfo_query(char *query, void *data);
243 static int __exec_certindexinfo_query(char *query, void *data);
244 static int __pkginfo_cb(void *data, int ncols, char **coltxt, char **colname);
245 static int __appinfo_cb(void *data, int ncols, char **coltxt, char **colname);
246 static int __certinfo_cb(void *data, int ncols, char **coltxt, char **colname);
247 static int __certindexinfo_cb(void *data, int ncols, char **coltxt, char **colname);
248 static int __validate_cb(void *data, int ncols, char **coltxt, char **colname);
249 static int __maxid_cb(void *data, int ncols, char **coltxt, char **colname);
250 static int __count_cb(void *data, int ncols, char **coltxt, char **colname);
251 static int __uiapp_list_cb(void *data, int ncols, char **coltxt, char **colname);
252 static int __svcapp_list_cb(void *data, int ncols, char **coltxt, char **colname);
253 static int __pkg_list_cb(void *data, int ncols, char **coltxt, char **colname);
254 static int __app_list_cb(void *data, int ncols, char **coltxt, char **colname);
255 static void __cleanup_pkginfo(pkgmgr_pkginfo_x *data);
256 static void __cleanup_appinfo(pkgmgr_appinfo_x *data);
257 static char* __convert_system_locale_to_manifest_locale(char *syslocale);
258 static void __destroy_each_node(gpointer data, gpointer user_data);
259 static void __get_filter_condition(gpointer data, char **condition);
260 static void __get_metadata_filter_condition(gpointer data, char **condition);
261 static gint __compare_func(gconstpointer data1, gconstpointer data2);
262 static int __delete_certinfo(const char *pkgid);
263
264 static gint __compare_func(gconstpointer data1, gconstpointer data2)
265 {
266         pkgmgrinfo_node_x *node1 = (pkgmgrinfo_node_x*)data1;
267         pkgmgrinfo_node_x *node2 = (pkgmgrinfo_node_x*)data2;
268         if (node1->prop == node2->prop)
269                 return 0;
270         else if (node1->prop > node2->prop)
271                 return 1;
272         else
273                 return -1;
274 }
275
276 static int __count_cb(void *data, int ncols, char **coltxt, char **colname)
277 {
278         int *p = (int*)data;
279         *p = atoi(coltxt[0]);
280         _LOGE("count value is %d\n", *p);
281         return 0;
282 }
283
284 static void __destroy_each_node(gpointer data, gpointer user_data)
285 {
286         ret_if(data == NULL);
287         pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)data;
288         if (node->value) {
289                 free(node->value);
290                 node->value = NULL;
291         }
292         if (node->key) {
293                 free(node->key);
294                 node->key = NULL;
295         }
296         free(node);
297         node = NULL;
298 }
299
300 static void __get_metadata_filter_condition(gpointer data, char **condition)
301 {
302         pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)data;
303         char key[MAX_QUERY_LEN] = {'\0'};
304         char value[MAX_QUERY_LEN] = {'\0'};
305         if (node->key) {
306                 snprintf(key, MAX_QUERY_LEN, "(package_app_app_metadata.md_key='%s'", node->key);
307         }
308         if (node->value) {
309                 snprintf(value, MAX_QUERY_LEN, " AND package_app_app_metadata.md_value='%s')", node->value);
310                 strcat(key, value);
311         } else {
312                 strcat(key, ")");
313         }
314         *condition = strdup(key);
315         return;
316 }
317
318 static void __get_filter_condition(gpointer data, char **condition)
319 {
320         pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)data;
321         char buf[MAX_QUERY_LEN + 1] = {'\0'};
322         char temp[PKG_STRING_LEN_MAX] = {'\0'};
323         switch (node->prop) {
324         case E_PMINFO_PKGINFO_PROP_PACKAGE_ID:
325                 snprintf(buf, MAX_QUERY_LEN, "package_info.package='%s'", node->value);
326                 break;
327         case E_PMINFO_PKGINFO_PROP_PACKAGE_TYPE:
328                 snprintf(buf, MAX_QUERY_LEN, "package_info.package_type='%s'", node->value);
329                 break;
330         case E_PMINFO_PKGINFO_PROP_PACKAGE_VERSION:
331                 snprintf(buf, MAX_QUERY_LEN, "package_info.package_version='%s'", node->value);
332                 break;
333         case E_PMINFO_PKGINFO_PROP_PACKAGE_INSTALL_LOCATION:
334                 snprintf(buf, MAX_QUERY_LEN, "package_info.install_location='%s'", node->value);
335                 break;
336         case E_PMINFO_PKGINFO_PROP_PACKAGE_INSTALLED_STORAGE:
337                 snprintf(buf, MAX_QUERY_LEN, "package_info.installed_storage='%s'", node->value);
338                 break;
339         case E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_NAME:
340                 snprintf(buf, MAX_QUERY_LEN, "package_info.author_name='%s'", node->value);
341                 break;
342         case E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_HREF:
343                 snprintf(buf, MAX_QUERY_LEN, "package_info.author_href='%s'", node->value);
344                 break;
345         case E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_EMAIL:
346                 snprintf(buf, MAX_QUERY_LEN, "package_info.author_email='%s'", node->value);
347                 break;
348         case E_PMINFO_PKGINFO_PROP_PACKAGE_SIZE:
349                 snprintf(buf, MAX_QUERY_LEN, "package_info.package_size='%s'", node->value);
350                 break;
351         case E_PMINFO_PKGINFO_PROP_PACKAGE_REMOVABLE:
352                 snprintf(buf, MAX_QUERY_LEN, "package_info.package_removable IN %s", node->value);
353                 break;
354         case E_PMINFO_PKGINFO_PROP_PACKAGE_PRELOAD:
355                 snprintf(buf, MAX_QUERY_LEN, "package_info.package_preload IN %s", node->value);
356                 break;
357         case E_PMINFO_PKGINFO_PROP_PACKAGE_READONLY:
358                 snprintf(buf, MAX_QUERY_LEN, "package_info.package_readonly IN %s", node->value);
359                 break;
360         case E_PMINFO_PKGINFO_PROP_PACKAGE_UPDATE:
361                 snprintf(buf, MAX_QUERY_LEN, "package_info.package_update IN %s", node->value);
362                 break;
363         case E_PMINFO_PKGINFO_PROP_PACKAGE_APPSETTING:
364                 snprintf(buf, MAX_QUERY_LEN, "package_info.package_appsetting IN %s", node->value);
365                 break;
366         case E_PMINFO_PKGINFO_PROP_PACKAGE_NODISPLAY_SETTING:
367                 snprintf(buf, MAX_QUERY_LEN, "package_info.package_nodisplay IN %s", node->value);
368                 break;
369
370         case E_PMINFO_APPINFO_PROP_APP_ID:
371                 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_id='%s'", node->value);
372                 break;
373         case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
374                 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_component='%s'", node->value);
375                 break;
376         case E_PMINFO_APPINFO_PROP_APP_EXEC:
377                 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_exec='%s'", node->value);
378                 break;
379         case E_PMINFO_APPINFO_PROP_APP_ICON:
380                 snprintf(buf, MAX_QUERY_LEN, "package_app_localized_info.app_icon='%s'", node->value);
381                 break;
382         case E_PMINFO_APPINFO_PROP_APP_TYPE:
383                 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_type='%s'", node->value);
384                 break;
385         case E_PMINFO_APPINFO_PROP_APP_OPERATION:
386                 snprintf(temp, PKG_STRING_LEN_MAX, "(%s)", node->value);
387                 snprintf(buf, MAX_QUERY_LEN, "package_app_app_svc.operation IN %s", temp);
388                 break;
389         case E_PMINFO_APPINFO_PROP_APP_URI:
390                 snprintf(temp, PKG_STRING_LEN_MAX, "(%s)", node->value);
391                 snprintf(buf, MAX_QUERY_LEN, "package_app_app_svc.uri_scheme IN %s", temp);
392                 break;
393         case E_PMINFO_APPINFO_PROP_APP_MIME:
394                 snprintf(temp, PKG_STRING_LEN_MAX, "(%s)", node->value);
395                 snprintf(buf, MAX_QUERY_LEN, "package_app_app_svc.mime_type IN %s", temp);
396                 break;
397         case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
398                 snprintf(temp, PKG_STRING_LEN_MAX, "(%s)", node->value);
399                 snprintf(buf, MAX_QUERY_LEN, "package_app_app_category.category IN %s", temp);
400                 break;
401         case E_PMINFO_APPINFO_PROP_APP_NODISPLAY:
402                 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_nodisplay IN %s", node->value);
403                 break;
404         case E_PMINFO_APPINFO_PROP_APP_MULTIPLE:
405                 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_multiple IN %s", node->value);
406                 break;
407         case E_PMINFO_APPINFO_PROP_APP_ONBOOT:
408                 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_onboot IN %s", node->value);
409                 break;
410         case E_PMINFO_APPINFO_PROP_APP_AUTORESTART:
411                 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_autorestart IN %s", node->value);
412                 break;
413         case E_PMINFO_APPINFO_PROP_APP_TASKMANAGE:
414                 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_taskmanage IN %s", node->value);
415                 break;
416         case E_PMINFO_APPINFO_PROP_APP_HWACCELERATION:
417                 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_hwacceleration='%s'", node->value);
418                 break;
419         case E_PMINFO_APPINFO_PROP_APP_SCREENREADER:
420                 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_screenreader='%s'", node->value);
421                 break;
422         case E_PMINFO_APPINFO_PROP_APP_LAUNCHCONDITION:
423                 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_launchcondition IN %s", node->value);
424                 break;
425         default:
426                 _LOGE("Invalid Property Type\n");
427                 *condition = NULL;
428                 return;
429         }
430         *condition = strdup(buf);
431         return;
432 }
433
434 static char* __convert_system_locale_to_manifest_locale(char *syslocale)
435 {
436         if (syslocale == NULL)
437                 return strdup(DEFAULT_LOCALE);
438         char *locale = NULL;
439         locale = (char *)calloc(1, 6);
440         retvm_if(!locale, NULL, "Malloc Failed\n");
441
442         strncpy(locale, syslocale, 2);
443         strncat(locale, "-", 1);
444         locale[3] = syslocale[3] + 32;
445         locale[4] = syslocale[4] + 32;
446         return locale;
447 }
448
449 static void __cleanup_pkginfo(pkgmgr_pkginfo_x *data)
450 {
451         ret_if(data == NULL);
452         if (data->locale){
453                 free((void *)data->locale);
454                 data->locale = NULL;
455         }
456
457         pkgmgr_parser_free_manifest_xml(data->manifest_info);
458         free((void *)data);
459         data = NULL;
460         return;
461 }
462
463 static void __cleanup_appinfo(pkgmgr_appinfo_x *data)
464 {
465         ret_if(data == NULL);
466         if (data->package){
467                 free((void *)data->package);
468                 data->package = NULL;
469         }
470         if (data->locale){
471                 free((void *)data->locale);
472                 data->locale = NULL;
473         }
474
475         manifest_x *mfx = calloc(1, sizeof(manifest_x));
476         if (data->app_component == PMINFO_UI_APP)
477                 mfx->uiapplication = data->uiapp_info;
478         else if (data->app_component == PMINFO_SVC_APP)
479                 mfx->serviceapplication = data->svcapp_info;
480         pkgmgr_parser_free_manifest_xml(mfx);
481         free((void *)data);
482         data = NULL;
483         return;
484 }
485
486 static int __pkg_list_cb(void *data, int ncols, char **coltxt, char **colname)
487 {
488         pkgmgr_pkginfo_x *udata = (pkgmgr_pkginfo_x *)data;
489         int i = 0;
490         pkgmgr_pkginfo_x *info = NULL;
491         info = calloc(1, sizeof(pkgmgr_pkginfo_x));
492         info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
493
494         LISTADD(udata, info);
495         for(i = 0; i < ncols; i++)
496         {
497                 if (strcmp(colname[i], "package") == 0) {
498                         if (coltxt[i])
499                                 info->manifest_info->package = strdup(coltxt[i]);
500                         else
501                                 info->manifest_info->package = NULL;
502                 } else
503                         continue;
504         }
505
506         return 0;
507 }
508
509 static int __app_list_cb(void *data, int ncols, char **coltxt, char **colname)
510 {
511         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
512         int i = 0;
513         int j = 0;
514         uiapplication_x *uiapp = NULL;
515         serviceapplication_x *svcapp = NULL;
516         for(i = 0; i < ncols; i++)
517         {
518                 if ((strcmp(colname[i], "app_component") == 0) ||
519                         (strcmp(colname[i], "package_app_info.app_component") == 0)) {
520                         if (coltxt[i]) {
521                                 if (strcmp(coltxt[i], "uiapp") == 0) {
522                                         uiapp = calloc(1, sizeof(uiapplication_x));
523                                         if (uiapp == NULL) {
524                                                 _LOGE("Out of Memory!!!\n");
525                                                 return -1;
526                                         }
527                                         LISTADD(info->manifest_info->uiapplication, uiapp);
528                                         for(j = 0; j < ncols; j++)
529                                         {
530                                                 if ((strcmp(colname[j], "app_id") == 0) ||
531                                                         (strcmp(colname[j], "package_app_info.app_id") == 0)) {
532                                                         if (coltxt[j])
533                                                                 info->manifest_info->uiapplication->appid = strdup(coltxt[j]);
534                                                 } else if (strcmp(colname[j], "package") == 0) {
535                                                         if (coltxt[j])
536                                                                 info->manifest_info->uiapplication->package = strdup(coltxt[j]);
537                                                 } else
538                                                         continue;
539                                         }
540                                 } else {
541                                         svcapp = calloc(1, sizeof(serviceapplication_x));
542                                         if (svcapp == NULL) {
543                                                 _LOGE("Out of Memory!!!\n");
544                                                 return -1;
545                                         }
546                                         LISTADD(info->manifest_info->serviceapplication, svcapp);
547                                         for(j = 0; j < ncols; j++)
548                                         {
549                                                 if ((strcmp(colname[j], "app_id") == 0) ||
550                                                         (strcmp(colname[j], "package_app_info.app_id") == 0)) {
551                                                         if (coltxt[j])
552                                                                 info->manifest_info->serviceapplication->appid = strdup(coltxt[j]);
553                                                 } else if (strcmp(colname[j], "package") == 0) {
554                                                         if (coltxt[j])
555                                                                 info->manifest_info->serviceapplication->package = strdup(coltxt[j]);
556                                                 } else
557                                                         continue;
558                                         }
559                                 }
560                         }
561                 } else
562                         continue;
563         }
564
565         return 0;
566 }
567
568
569 static int __uiapp_list_cb(void *data, int ncols, char **coltxt, char **colname)
570 {
571         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
572         int i = 0;
573         uiapplication_x *uiapp = NULL;
574         icon_x *icon = NULL;
575         label_x *label = NULL;
576
577         uiapp = calloc(1, sizeof(uiapplication_x));
578         LISTADD(info->manifest_info->uiapplication, uiapp);
579         icon = calloc(1, sizeof(icon_x));
580         LISTADD(info->manifest_info->uiapplication->icon, icon);
581         label = calloc(1, sizeof(label_x));
582         LISTADD(info->manifest_info->uiapplication->label, label);
583
584         for(i = 0; i < ncols; i++)
585         {
586                 if (strcmp(colname[i], "app_id") == 0) {
587                         if (coltxt[i])
588                                 info->manifest_info->uiapplication->appid = strdup(coltxt[i]);
589                         else
590                                 info->manifest_info->uiapplication->appid = NULL;
591                 } else if (strcmp(colname[i], "app_exec") == 0) {
592                         if (coltxt[i])
593                                 info->manifest_info->uiapplication->exec = strdup(coltxt[i]);
594                         else
595                                 info->manifest_info->uiapplication->exec = NULL;
596                 } else if (strcmp(colname[i], "app_type") == 0 ){
597                         if (coltxt[i])
598                                 info->manifest_info->uiapplication->type = strdup(coltxt[i]);
599                         else
600                                 info->manifest_info->uiapplication->type = NULL;
601                 } else if (strcmp(colname[i], "app_nodisplay") == 0 ){
602                         if (coltxt[i])
603                                 info->manifest_info->uiapplication->nodisplay = strdup(coltxt[i]);
604                         else
605                                 info->manifest_info->uiapplication->nodisplay = NULL;
606                 } else if (strcmp(colname[i], "app_multiple") == 0 ){
607                         if (coltxt[i])
608                                 info->manifest_info->uiapplication->multiple = strdup(coltxt[i]);
609                         else
610                                 info->manifest_info->uiapplication->multiple = NULL;
611                 } else if (strcmp(colname[i], "app_taskmanage") == 0 ){
612                         if (coltxt[i])
613                                 info->manifest_info->uiapplication->taskmanage = strdup(coltxt[i]);
614                         else
615                                 info->manifest_info->uiapplication->taskmanage = NULL;
616                 } else if (strcmp(colname[i], "app_hwacceleration") == 0 ){
617                         if (coltxt[i])
618                                 info->manifest_info->uiapplication->hwacceleration = strdup(coltxt[i]);
619                         else
620                                 info->manifest_info->uiapplication->hwacceleration = NULL;
621                 } else if (strcmp(colname[i], "app_screenreader") == 0 ){
622                         if (coltxt[i])
623                                 info->manifest_info->uiapplication->screenreader = strdup(coltxt[i]);
624                         else
625                                 info->manifest_info->uiapplication->screenreader = NULL;
626                 } else if (strcmp(colname[i], "app_indicatordisplay") == 0 ){
627                         if (coltxt[i])
628                                 info->manifest_info->uiapplication->indicatordisplay = strdup(coltxt[i]);
629                         else
630                                 info->manifest_info->uiapplication->indicatordisplay = NULL;
631                 } else if (strcmp(colname[i], "app_portraitimg") == 0 ){
632                         if (coltxt[i])
633                                 info->manifest_info->uiapplication->portraitimg = strdup(coltxt[i]);
634                         else
635                                 info->manifest_info->uiapplication->portraitimg = NULL;
636                 } else if (strcmp(colname[i], "app_landscapeimg") == 0 ){
637                         if (coltxt[i])
638                                 info->manifest_info->uiapplication->landscapeimg = strdup(coltxt[i]);
639                         else
640                                 info->manifest_info->uiapplication->landscapeimg = NULL;
641                 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0 ){
642                         if (coltxt[i])
643                                 info->manifest_info->uiapplication->guestmode_visibility = strdup(coltxt[i]);
644                         else
645                                 info->manifest_info->uiapplication->guestmode_visibility = NULL;
646                 } else if (strcmp(colname[i], "package") == 0 ){
647                         if (coltxt[i])
648                                 info->manifest_info->uiapplication->package = strdup(coltxt[i]);
649                         else
650                                 info->manifest_info->uiapplication->package = NULL;
651                 } else if (strcmp(colname[i], "app_icon") == 0) {
652                         if (coltxt[i])
653                                 info->manifest_info->uiapplication->icon->text = strdup(coltxt[i]);
654                         else
655                                 info->manifest_info->uiapplication->icon->text = NULL;
656                 } else if (strcmp(colname[i], "app_enabled") == 0 ) {
657                         if (coltxt[i])
658                                 info->manifest_info->uiapplication->enabled= strdup(coltxt[i]);
659                         else
660                                 info->manifest_info->uiapplication->enabled = NULL;
661                 } else if (strcmp(colname[i], "app_label") == 0 ) {
662                         if (coltxt[i])
663                                 info->manifest_info->uiapplication->label->text = strdup(coltxt[i]);
664                         else
665                                 info->manifest_info->uiapplication->label->text = NULL;
666                 } else if (strcmp(colname[i], "app_recentimage") == 0 ) {
667                         if (coltxt[i])
668                                 info->manifest_info->uiapplication->recentimage = strdup(coltxt[i]);
669                         else
670                                 info->manifest_info->uiapplication->recentimage = NULL;
671                 } else if (strcmp(colname[i], "app_mainapp") == 0 ) {
672                         if (coltxt[i])
673                                 info->manifest_info->uiapplication->mainapp = strdup(coltxt[i]);
674                         else
675                                 info->manifest_info->uiapplication->mainapp = NULL;
676                 } else if (strcmp(colname[i], "app_locale") == 0 ) {
677                         if (coltxt[i]) {
678                                 info->manifest_info->uiapplication->icon->lang = strdup(coltxt[i]);
679                                 info->manifest_info->uiapplication->label->lang = strdup(coltxt[i]);
680                         }
681                         else {
682                                 info->manifest_info->uiapplication->icon->lang = NULL;
683                                 info->manifest_info->uiapplication->label->lang = NULL;
684                         }
685                 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
686                         if (coltxt[i])
687                                 info->manifest_info->uiapplication->permission_type = strdup(coltxt[i]);
688                         else
689                                 info->manifest_info->uiapplication->permission_type = NULL;
690                 } else if (strcmp(colname[i], "component_type") == 0 ) {
691                         if (coltxt[i])
692                                 info->manifest_info->uiapplication->component_type = strdup(coltxt[i]);
693                         else
694                                 info->manifest_info->uiapplication->component_type = NULL;
695                 } else if (strcmp(colname[i], "app_preload") == 0 ) {
696                         if (coltxt[i])
697                                 info->manifest_info->uiapplication->preload = strdup(coltxt[i]);
698                         else
699                                 info->manifest_info->uiapplication->preload = NULL;
700                 } else if (strcmp(colname[i], "app_submode") == 0 ) {
701                         if (coltxt[i])
702                                 info->manifest_info->uiapplication->submode = strdup(coltxt[i]);
703                         else
704                                 info->manifest_info->uiapplication->submode = NULL;
705                 } else if (strcmp(colname[i], "app_submode_mainid") == 0 ) {
706                         if (coltxt[i])
707                                 info->manifest_info->uiapplication->submode_mainid = strdup(coltxt[i]);
708                         else
709                                 info->manifest_info->uiapplication->submode_mainid = NULL;
710                 } else if (strcmp(colname[i], "app_installed_storage") == 0 ) {
711                         if (coltxt[i])
712                                 info->manifest_info->uiapplication->installed_storage = strdup(coltxt[i]);
713                         else
714                                 info->manifest_info->uiapplication->installed_storage = NULL;
715                 } else
716                         continue;
717         }
718         return 0;
719 }
720
721 static int __svcapp_list_cb(void *data, int ncols, char **coltxt, char **colname)
722 {
723         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
724         int i = 0;
725         serviceapplication_x *svcapp = NULL;
726         icon_x *icon = NULL;
727         label_x *label = NULL;
728
729         svcapp = calloc(1, sizeof(serviceapplication_x));
730         LISTADD(info->manifest_info->serviceapplication, svcapp);
731         icon = calloc(1, sizeof(icon_x));
732         LISTADD(info->manifest_info->serviceapplication->icon, icon);
733         label = calloc(1, sizeof(label_x));
734         LISTADD(info->manifest_info->serviceapplication->label, label);
735         for(i = 0; i < ncols; i++)
736         {
737                 if (strcmp(colname[i], "app_id") == 0) {
738                         if (coltxt[i])
739                                 info->manifest_info->serviceapplication->appid = strdup(coltxt[i]);
740                         else
741                                 info->manifest_info->serviceapplication->appid = NULL;
742                 } else if (strcmp(colname[i], "app_exec") == 0) {
743                         if (coltxt[i])
744                                 info->manifest_info->serviceapplication->exec = strdup(coltxt[i]);
745                         else
746                                 info->manifest_info->serviceapplication->exec = NULL;
747                 } else if (strcmp(colname[i], "app_type") == 0 ){
748                         if (coltxt[i])
749                                 info->manifest_info->serviceapplication->type = strdup(coltxt[i]);
750                         else
751                                 info->manifest_info->serviceapplication->type = NULL;
752                 } else if (strcmp(colname[i], "app_onboot") == 0 ){
753                         if (coltxt[i])
754                                 info->manifest_info->serviceapplication->onboot = strdup(coltxt[i]);
755                         else
756                                 info->manifest_info->serviceapplication->onboot = NULL;
757                 } else if (strcmp(colname[i], "app_autorestart") == 0 ){
758                         if (coltxt[i])
759                                 info->manifest_info->serviceapplication->autorestart = strdup(coltxt[i]);
760                         else
761                                 info->manifest_info->serviceapplication->autorestart = NULL;
762                 } else if (strcmp(colname[i], "package") == 0 ){
763                         if (coltxt[i])
764                                 info->manifest_info->serviceapplication->package = strdup(coltxt[i]);
765                         else
766                                 info->manifest_info->serviceapplication->package = NULL;
767                 } else if (strcmp(colname[i], "app_icon") == 0) {
768                         if (coltxt[i])
769                                 info->manifest_info->serviceapplication->icon->text = strdup(coltxt[i]);
770                         else
771                                 info->manifest_info->serviceapplication->icon->text = NULL;
772                 } else if (strcmp(colname[i], "app_label") == 0 ) {
773                         if (coltxt[i])
774                                 info->manifest_info->serviceapplication->label->text = strdup(coltxt[i]);
775                         else
776                                 info->manifest_info->serviceapplication->label->text = NULL;
777                 } else if (strcmp(colname[i], "app_locale") == 0 ) {
778                         if (coltxt[i]) {
779                                 info->manifest_info->serviceapplication->icon->lang = strdup(coltxt[i]);
780                                 info->manifest_info->serviceapplication->label->lang = strdup(coltxt[i]);
781                         }
782                         else {
783                                 info->manifest_info->serviceapplication->icon->lang = NULL;
784                                 info->manifest_info->serviceapplication->label->lang = NULL;
785                         }
786                 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
787                         if (coltxt[i])
788                                 info->manifest_info->serviceapplication->permission_type = strdup(coltxt[i]);
789                         else
790                                 info->manifest_info->serviceapplication->permission_type = NULL;
791                 } else
792                         continue;
793         }
794         return 0;
795 }
796
797 static int __allapp_list_cb(void *data, int ncols, char **coltxt, char **colname)
798 {
799         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
800         int i = 0;
801         int j = 0;
802         uiapplication_x *uiapp = NULL;
803         serviceapplication_x *svcapp = NULL;
804         for(j = 0; j < ncols; j++)
805         {
806                 if (strcmp(colname[j], "app_component") == 0) {
807                         if (coltxt[j]) {
808                                 if (strcmp(coltxt[j], "uiapp") == 0) {
809                                         uiapp = calloc(1, sizeof(uiapplication_x));
810                                         if (uiapp == NULL) {
811                                                 _LOGE("Out of Memory!!!\n");
812                                                 return -1;
813                                         }
814                                         LISTADD(info->manifest_info->uiapplication, uiapp);
815                                         for(i = 0; i < ncols; i++)
816                                         {
817                                                 if (strcmp(colname[i], "app_id") == 0) {
818                                                         if (coltxt[i])
819                                                                 info->manifest_info->uiapplication->appid = strdup(coltxt[i]);
820                                                         else
821                                                                 info->manifest_info->uiapplication->appid = NULL;
822                                                 } else if (strcmp(colname[i], "app_exec") == 0) {
823                                                         if (coltxt[i])
824                                                                 info->manifest_info->uiapplication->exec = strdup(coltxt[i]);
825                                                         else
826                                                                 info->manifest_info->uiapplication->exec = NULL;
827                                                 } else if (strcmp(colname[i], "app_type") == 0 ){
828                                                         if (coltxt[i])
829                                                                 info->manifest_info->uiapplication->type = strdup(coltxt[i]);
830                                                         else
831                                                                 info->manifest_info->uiapplication->type = NULL;
832                                                 } else if (strcmp(colname[i], "app_nodisplay") == 0 ){
833                                                         if (coltxt[i])
834                                                                 info->manifest_info->uiapplication->nodisplay = strdup(coltxt[i]);
835                                                         else
836                                                                 info->manifest_info->uiapplication->nodisplay = NULL;
837                                                 } else if (strcmp(colname[i], "app_multiple") == 0 ){
838                                                         if (coltxt[i])
839                                                                 info->manifest_info->uiapplication->multiple = strdup(coltxt[i]);
840                                                         else
841                                                                 info->manifest_info->uiapplication->multiple = NULL;
842                                                 } else if (strcmp(colname[i], "app_taskmanage") == 0 ){
843                                                         if (coltxt[i])
844                                                                 info->manifest_info->uiapplication->taskmanage = strdup(coltxt[i]);
845                                                         else
846                                                                 info->manifest_info->uiapplication->taskmanage = NULL;
847                                                 } else if (strcmp(colname[i], "app_hwacceleration") == 0 ){
848                                                         if (coltxt[i])
849                                                                 info->manifest_info->uiapplication->hwacceleration = strdup(coltxt[i]);
850                                                         else
851                                                                 info->manifest_info->uiapplication->hwacceleration = NULL;
852                                                 } else if (strcmp(colname[i], "app_screenreader") == 0 ){
853                                                         if (coltxt[i])
854                                                                 info->manifest_info->uiapplication->screenreader = strdup(coltxt[i]);
855                                                         else
856                                                                 info->manifest_info->uiapplication->screenreader = NULL;
857                                                 } else if (strcmp(colname[i], "app_indicatordisplay") == 0 ){
858                                                         if (coltxt[i])
859                                                                 info->manifest_info->uiapplication->indicatordisplay = strdup(coltxt[i]);
860                                                         else
861                                                                 info->manifest_info->uiapplication->indicatordisplay = NULL;
862                                                 } else if (strcmp(colname[i], "app_portraitimg") == 0 ){
863                                                         if (coltxt[i])
864                                                                 info->manifest_info->uiapplication->portraitimg = strdup(coltxt[i]);
865                                                         else
866                                                                 info->manifest_info->uiapplication->portraitimg = NULL;
867                                                 } else if (strcmp(colname[i], "app_landscapeimg") == 0 ){
868                                                         if (coltxt[i])
869                                                                 info->manifest_info->uiapplication->landscapeimg = strdup(coltxt[i]);
870                                                         else
871                                                                 info->manifest_info->uiapplication->landscapeimg = NULL;
872                                                 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0 ){
873                                                         if (coltxt[i])
874                                                                 info->manifest_info->uiapplication->guestmode_visibility = strdup(coltxt[i]);
875                                                         else
876                                                                 info->manifest_info->uiapplication->guestmode_visibility = NULL;
877                                                 } else if (strcmp(colname[i], "package") == 0 ){
878                                                         if (coltxt[i])
879                                                                 info->manifest_info->uiapplication->package = strdup(coltxt[i]);
880                                                         else
881                                                                 info->manifest_info->uiapplication->package = NULL;
882                                                 } else if (strcmp(colname[i], "app_icon") == 0) {
883                                                         if (coltxt[i])
884                                                                 info->manifest_info->uiapplication->icon->text = strdup(coltxt[i]);
885                                                         else
886                                                                 info->manifest_info->uiapplication->icon->text = NULL;
887                                                 } else if (strcmp(colname[i], "app_label") == 0 ) {
888                                                         if (coltxt[i])
889                                                                 info->manifest_info->uiapplication->label->text = strdup(coltxt[i]);
890                                                         else
891                                                                 info->manifest_info->uiapplication->label->text = NULL;
892                                                 } else if (strcmp(colname[i], "app_recentimage") == 0 ) {
893                                                         if (coltxt[i])
894                                                                 info->manifest_info->uiapplication->recentimage = strdup(coltxt[i]);
895                                                         else
896                                                                 info->manifest_info->uiapplication->recentimage = NULL;
897                                                 } else if (strcmp(colname[i], "app_mainapp") == 0 ) {
898                                                         if (coltxt[i])
899                                                                 info->manifest_info->uiapplication->mainapp= strdup(coltxt[i]);
900                                                         else
901                                                                 info->manifest_info->uiapplication->mainapp = NULL;
902                                                 } else if (strcmp(colname[i], "app_locale") == 0 ) {
903                                                         if (coltxt[i]) {
904                                                                 info->manifest_info->uiapplication->icon->lang = strdup(coltxt[i]);
905                                                                 info->manifest_info->uiapplication->label->lang = strdup(coltxt[i]);
906                                                         }
907                                                         else {
908                                                                 info->manifest_info->uiapplication->icon->lang = NULL;
909                                                                 info->manifest_info->uiapplication->label->lang = NULL;
910                                                         }
911                                                 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
912                                                         if (coltxt[i])
913                                                                 info->manifest_info->uiapplication->permission_type = strdup(coltxt[i]);
914                                                         else
915                                                                 info->manifest_info->uiapplication->permission_type = NULL;
916                                                 } else
917                                                         continue;
918                                         }
919                                 } else {
920                                         svcapp = calloc(1, sizeof(serviceapplication_x));
921                                         if (svcapp == NULL) {
922                                                 _LOGE("Out of Memory!!!\n");
923                                                 return -1;
924                                         }
925                                         LISTADD(info->manifest_info->serviceapplication, svcapp);
926                                         for(i = 0; i < ncols; i++)
927                                         {
928                                                 if (strcmp(colname[i], "app_id") == 0) {
929                                                         if (coltxt[i])
930                                                                 info->manifest_info->serviceapplication->appid = strdup(coltxt[i]);
931                                                         else
932                                                                 info->manifest_info->serviceapplication->appid = NULL;
933                                                 } else if (strcmp(colname[i], "app_exec") == 0) {
934                                                         if (coltxt[i])
935                                                                 info->manifest_info->serviceapplication->exec = strdup(coltxt[i]);
936                                                         else
937                                                                 info->manifest_info->serviceapplication->exec = NULL;
938                                                 } else if (strcmp(colname[i], "app_type") == 0 ){
939                                                         if (coltxt[i])
940                                                                 info->manifest_info->serviceapplication->type = strdup(coltxt[i]);
941                                                         else
942                                                                 info->manifest_info->serviceapplication->type = NULL;
943                                                 } else if (strcmp(colname[i], "app_onboot") == 0 ){
944                                                         if (coltxt[i])
945                                                                 info->manifest_info->serviceapplication->onboot = strdup(coltxt[i]);
946                                                         else
947                                                                 info->manifest_info->serviceapplication->onboot = NULL;
948                                                 } else if (strcmp(colname[i], "app_autorestart") == 0 ){
949                                                         if (coltxt[i])
950                                                                 info->manifest_info->serviceapplication->autorestart = strdup(coltxt[i]);
951                                                         else
952                                                                 info->manifest_info->serviceapplication->autorestart = NULL;
953                                                 } else if (strcmp(colname[i], "package") == 0 ){
954                                                         if (coltxt[i])
955                                                                 info->manifest_info->serviceapplication->package = strdup(coltxt[i]);
956                                                         else
957                                                                 info->manifest_info->serviceapplication->package = NULL;
958                                                 } else if (strcmp(colname[i], "app_icon") == 0) {
959                                                         if (coltxt[i])
960                                                                 info->manifest_info->serviceapplication->icon->text = strdup(coltxt[i]);
961                                                         else
962                                                                 info->manifest_info->serviceapplication->icon->text = NULL;
963                                                 } else if (strcmp(colname[i], "app_label") == 0 ) {
964                                                         if (coltxt[i])
965                                                                 info->manifest_info->serviceapplication->label->text = strdup(coltxt[i]);
966                                                         else
967                                                                 info->manifest_info->serviceapplication->label->text = NULL;
968                                                 } else if (strcmp(colname[i], "app_locale") == 0 ) {
969                                                         if (coltxt[i]) {
970                                                                 info->manifest_info->serviceapplication->icon->lang = strdup(coltxt[i]);
971                                                                 info->manifest_info->serviceapplication->label->lang = strdup(coltxt[i]);
972                                                         }
973                                                         else {
974                                                                 info->manifest_info->serviceapplication->icon->lang = NULL;
975                                                                 info->manifest_info->serviceapplication->label->lang = NULL;
976                                                         }
977                                                 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
978                                                         if (coltxt[i])
979                                                                 info->manifest_info->serviceapplication->permission_type = strdup(coltxt[i]);
980                                                         else
981                                                                 info->manifest_info->serviceapplication->permission_type = NULL;
982                                                 } else
983                                                         continue;
984                                         }
985                                 }
986                         }
987                 } else
988                         continue;
989         }
990
991         return 0;
992 }
993
994
995
996 static int __validate_cb(void *data, int ncols, char **coltxt, char **colname)
997 {
998         int *p = (int*)data;
999         *p = atoi(coltxt[0]);
1000         return 0;
1001 }
1002
1003 static int __maxid_cb(void *data, int ncols, char **coltxt, char **colname)
1004 {
1005         int *p = (int*)data;
1006         if (coltxt[0])
1007                 *p = atoi(coltxt[0]);
1008         return 0;
1009 }
1010
1011 static int __pkginfo_cb(void *data, int ncols, char **coltxt, char **colname)
1012 {
1013         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
1014         int i = 0;
1015         author_x *author = NULL;
1016         icon_x *icon = NULL;
1017         label_x *label = NULL;
1018         description_x *description = NULL;
1019         privilege_x *privilege = NULL;
1020
1021         author = calloc(1, sizeof(author_x));
1022         LISTADD(info->manifest_info->author, author);
1023         icon = calloc(1, sizeof(icon_x));
1024         LISTADD(info->manifest_info->icon, icon);
1025         label = calloc(1, sizeof(label_x));
1026         LISTADD(info->manifest_info->label, label);
1027         description = calloc(1, sizeof(description_x));
1028         LISTADD(info->manifest_info->description, description);
1029         privilege = calloc(1, sizeof(privilege_x));
1030         LISTADD(info->manifest_info->privileges->privilege, privilege);
1031         for(i = 0; i < ncols; i++)
1032         {
1033                 if (strcmp(colname[i], "package_version") == 0) {
1034                         if (coltxt[i])
1035                                 info->manifest_info->version = strdup(coltxt[i]);
1036                         else
1037                                 info->manifest_info->version = NULL;
1038                 } else if (strcmp(colname[i], "package_type") == 0) {
1039                         if (coltxt[i])
1040                                 info->manifest_info->type = strdup(coltxt[i]);
1041                         else
1042                                 info->manifest_info->type = NULL;
1043                 } else if (strcmp(colname[i], "install_location") == 0) {
1044                         if (coltxt[i])
1045                                 info->manifest_info->installlocation = strdup(coltxt[i]);
1046                         else
1047                                 info->manifest_info->installlocation = NULL;
1048                 } else if (strcmp(colname[i], "package_size") == 0) {
1049                         if (coltxt[i])
1050                                 info->manifest_info->package_size = strdup(coltxt[i]);
1051                         else
1052                                 info->manifest_info->package_size = NULL;
1053                 } else if (strcmp(colname[i], "author_email") == 0 ){
1054                         if (coltxt[i])
1055                                 info->manifest_info->author->email = strdup(coltxt[i]);
1056                         else
1057                                 info->manifest_info->author->email = NULL;
1058                 } else if (strcmp(colname[i], "author_href") == 0 ){
1059                         if (coltxt[i])
1060                                 info->manifest_info->author->href = strdup(coltxt[i]);
1061                         else
1062                                 info->manifest_info->author->href = NULL;
1063                 } else if (strcmp(colname[i], "package_label") == 0 ){
1064                         if (coltxt[i])
1065                                 info->manifest_info->label->text = strdup(coltxt[i]);
1066                         else
1067                                 info->manifest_info->label->text = NULL;
1068                 } else if (strcmp(colname[i], "package_icon") == 0 ){
1069                         if (coltxt[i])
1070                                 info->manifest_info->icon->text = strdup(coltxt[i]);
1071                         else
1072                                 info->manifest_info->icon->text = NULL;
1073                 } else if (strcmp(colname[i], "package_description") == 0 ){
1074                         if (coltxt[i])
1075                                 info->manifest_info->description->text = strdup(coltxt[i]);
1076                         else
1077                                 info->manifest_info->description->text = NULL;
1078                 } else if (strcmp(colname[i], "package_author") == 0 ){
1079                         if (coltxt[i])
1080                                 info->manifest_info->author->text = strdup(coltxt[i]);
1081                         else
1082                                 info->manifest_info->author->text = NULL;
1083                 } else if (strcmp(colname[i], "package_removable") == 0 ){
1084                         if (coltxt[i])
1085                                 info->manifest_info->removable = strdup(coltxt[i]);
1086                         else
1087                                 info->manifest_info->removable = NULL;
1088                 } else if (strcmp(colname[i], "package_preload") == 0 ){
1089                         if (coltxt[i])
1090                                 info->manifest_info->preload = strdup(coltxt[i]);
1091                         else
1092                                 info->manifest_info->preload = NULL;
1093                 } else if (strcmp(colname[i], "package_readonly") == 0 ){
1094                         if (coltxt[i])
1095                                 info->manifest_info->readonly = strdup(coltxt[i]);
1096                         else
1097                                 info->manifest_info->readonly = NULL;
1098                 } else if (strcmp(colname[i], "package_update") == 0 ){
1099                         if (coltxt[i])
1100                                 info->manifest_info->update= strdup(coltxt[i]);
1101                         else
1102                                 info->manifest_info->update = NULL;
1103                 } else if (strcmp(colname[i], "package_system") == 0 ){
1104                         if (coltxt[i])
1105                                 info->manifest_info->system= strdup(coltxt[i]);
1106                         else
1107                                 info->manifest_info->system = NULL;
1108                 } else if (strcmp(colname[i], "package_appsetting") == 0 ){
1109                         if (coltxt[i])
1110                                 info->manifest_info->appsetting = strdup(coltxt[i]);
1111                         else
1112                                 info->manifest_info->appsetting = NULL;
1113                 } else if (strcmp(colname[i], "installed_time") == 0 ){
1114                         if (coltxt[i])
1115                                 info->manifest_info->installed_time = strdup(coltxt[i]);
1116                         else
1117                                 info->manifest_info->installed_time = NULL;
1118                 } else if (strcmp(colname[i], "installed_storage") == 0 ){
1119                         if (coltxt[i])
1120                                 info->manifest_info->installed_storage = strdup(coltxt[i]);
1121                         else
1122                                 info->manifest_info->installed_storage = NULL;
1123                 } else if (strcmp(colname[i], "mainapp_id") == 0 ){
1124                         if (coltxt[i])
1125                                 info->manifest_info->mainapp_id = strdup(coltxt[i]);
1126                         else
1127                                 info->manifest_info->mainapp_id = NULL;
1128                 } else if (strcmp(colname[i], "storeclient_id") == 0 ){
1129                         if (coltxt[i])
1130                                 info->manifest_info->storeclient_id = strdup(coltxt[i]);
1131                         else
1132                                 info->manifest_info->storeclient_id = NULL;
1133                 } else if (strcmp(colname[i], "root_path") == 0 ){
1134                         if (coltxt[i])
1135                                 info->manifest_info->root_path = strdup(coltxt[i]);
1136                         else
1137                                 info->manifest_info->root_path = NULL;
1138                 } else if (strcmp(colname[i], "csc_path") == 0 ){
1139                         if (coltxt[i])
1140                                 info->manifest_info->csc_path = strdup(coltxt[i]);
1141                         else
1142                                 info->manifest_info->csc_path = NULL;
1143                 } else if (strcmp(colname[i], "privilege") == 0 ){
1144                         if (coltxt[i])
1145                                 info->manifest_info->privileges->privilege->text = strdup(coltxt[i]);
1146                         else
1147                                 info->manifest_info->privileges->privilege->text = NULL;
1148                 } else if (strcmp(colname[i], "package_locale") == 0 ){
1149                         if (coltxt[i]) {
1150                                 info->manifest_info->author->lang = strdup(coltxt[i]);
1151                                 info->manifest_info->icon->lang = strdup(coltxt[i]);
1152                                 info->manifest_info->label->lang = strdup(coltxt[i]);
1153                                 info->manifest_info->description->lang = strdup(coltxt[i]);
1154                         }
1155                         else {
1156                                 info->manifest_info->author->lang = NULL;
1157                                 info->manifest_info->icon->lang = NULL;
1158                                 info->manifest_info->label->lang = NULL;
1159                                 info->manifest_info->description->lang = NULL;
1160                         }
1161                 } else if (strcmp(colname[i], "package_url") == 0 ){
1162                         if (coltxt[i])
1163                                 info->manifest_info->package_url = strdup(coltxt[i]);
1164                         else
1165                                 info->manifest_info->package_url = NULL;
1166                 } else
1167                         continue;
1168         }
1169         return 0;
1170 }
1171
1172
1173 static pkgmgrinfo_app_component __appcomponent_convert(const char *comp)
1174 {
1175         if ( strcasecmp(comp, "uiapp") == 0)
1176                 return PMINFO_UI_APP;
1177         else if ( strcasecmp(comp, "svcapp") == 0)
1178                 return PMINFO_SVC_APP;
1179         else
1180                 return -1;
1181 }
1182
1183 static int __certindexinfo_cb(void *data, int ncols, char **coltxt, char **colname)
1184 {
1185         pkgmgr_certindexinfo_x *info = (pkgmgr_certindexinfo_x *)data;
1186         int i = 0;
1187         for(i = 0; i < ncols; i++) {
1188                 if (strcmp(colname[i], "cert_id") == 0) {
1189                         if (coltxt[i])
1190                                 info->cert_id = atoi(coltxt[i]);
1191                         else
1192                                 info->cert_id = 0;
1193                 } else if (strcmp(colname[i], "cert_ref_count") == 0) {
1194                         if (coltxt[i])
1195                                 info->cert_ref_count = atoi(coltxt[i]);
1196                         else
1197                                 info->cert_ref_count = 0;
1198                 } else
1199                         continue;
1200         }
1201         return 0;
1202 }
1203 static int __certinfo_cb(void *data, int ncols, char **coltxt, char **colname)
1204 {
1205         pkgmgr_certinfo_x *info = (pkgmgr_certinfo_x *)data;
1206         int i = 0;
1207         for(i = 0; i < ncols; i++)
1208         {
1209                 if (strcmp(colname[i], "package") == 0) {
1210                         if (coltxt[i])
1211                                 info->pkgid = strdup(coltxt[i]);
1212                         else
1213                                 info->pkgid = NULL;
1214                 } else if (strcmp(colname[i], "author_signer_cert") == 0) {
1215                         if (coltxt[i])
1216                                 (info->cert_id)[PMINFO_AUTHOR_SIGNER_CERT] = atoi(coltxt[i]);
1217                         else
1218                                 (info->cert_id)[PMINFO_AUTHOR_SIGNER_CERT] = 0;
1219                 } else if (strcmp(colname[i], "author_im_cert") == 0) {
1220                         if (coltxt[i])
1221                                 (info->cert_id)[PMINFO_AUTHOR_INTERMEDIATE_CERT] = atoi(coltxt[i]);
1222                         else
1223                                 (info->cert_id)[PMINFO_AUTHOR_INTERMEDIATE_CERT] = 0;
1224                 } else if (strcmp(colname[i], "author_root_cert") == 0) {
1225                         if (coltxt[i])
1226                                 (info->cert_id)[PMINFO_AUTHOR_ROOT_CERT] = atoi(coltxt[i]);
1227                         else
1228                                 (info->cert_id)[PMINFO_AUTHOR_ROOT_CERT] = 0;
1229                 } else if (strcmp(colname[i], "dist_signer_cert") == 0 ){
1230                         if (coltxt[i])
1231                                 (info->cert_id)[PMINFO_DISTRIBUTOR_SIGNER_CERT] = atoi(coltxt[i]);
1232                         else
1233                                 (info->cert_id)[PMINFO_DISTRIBUTOR_SIGNER_CERT] = 0;
1234                 } else if (strcmp(colname[i], "dist_im_cert") == 0 ){
1235                         if (coltxt[i])
1236                                 (info->cert_id)[PMINFO_DISTRIBUTOR_INTERMEDIATE_CERT] = atoi(coltxt[i]);
1237                         else
1238                                 (info->cert_id)[PMINFO_DISTRIBUTOR_INTERMEDIATE_CERT] = 0;
1239                 } else if (strcmp(colname[i], "dist_root_cert") == 0 ){
1240                         if (coltxt[i])
1241                                 (info->cert_id)[PMINFO_DISTRIBUTOR_ROOT_CERT] = atoi(coltxt[i]);
1242                         else
1243                                 (info->cert_id)[PMINFO_DISTRIBUTOR_ROOT_CERT] = 0;
1244                 } else if (strcmp(colname[i], "dist2_signer_cert") == 0 ){
1245                         if (coltxt[i])
1246                                 (info->cert_id)[PMINFO_DISTRIBUTOR2_SIGNER_CERT] = atoi(coltxt[i]);
1247                         else
1248                                 (info->cert_id)[PMINFO_DISTRIBUTOR2_SIGNER_CERT] = 0;
1249                 } else if (strcmp(colname[i], "dist2_im_cert") == 0 ){
1250                         if (coltxt[i])
1251                                 (info->cert_id)[PMINFO_DISTRIBUTOR2_INTERMEDIATE_CERT] = atoi(coltxt[i]);
1252                         else
1253                                 (info->cert_id)[PMINFO_DISTRIBUTOR2_INTERMEDIATE_CERT] = 0;
1254                 } else if (strcmp(colname[i], "dist2_root_cert") == 0 ){
1255                         if (coltxt[i])
1256                                 (info->cert_id)[PMINFO_DISTRIBUTOR2_ROOT_CERT] = atoi(coltxt[i]);
1257                         else
1258                                 (info->cert_id)[PMINFO_DISTRIBUTOR2_ROOT_CERT] = 0;
1259                 } else if (strcmp(colname[i], "cert_info") == 0 ){
1260                         if (coltxt[i])
1261                                 info->cert_value = strdup(coltxt[i]);
1262                         else
1263                                 info->cert_value = NULL;
1264                 } else
1265                         continue;
1266         }
1267         return 0;
1268 }
1269
1270 static int __mini_appinfo_cb(void *data, int ncols, char **coltxt, char **colname)
1271 {
1272         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
1273         int i = 0;
1274         int j = 0;
1275         uiapplication_x *uiapp = NULL;
1276         serviceapplication_x *svcapp = NULL;
1277         for(i = 0; i < ncols; i++)
1278         {
1279                 if (strcmp(colname[i], "app_component") == 0) {
1280                         if (coltxt[i]) {
1281                                 if (strcmp(coltxt[i], "uiapp") == 0) {
1282                                         uiapp = calloc(1, sizeof(uiapplication_x));
1283                                         if (uiapp == NULL) {
1284                                                 _LOGE("Out of Memory!!!\n");
1285                                                 return -1;
1286                                         }
1287                                         LISTADD(info->manifest_info->uiapplication, uiapp);
1288                                         for(j = 0; j < ncols; j++)
1289                                         {
1290                                                 if (strcmp(colname[j], "app_id") == 0) {
1291                                                         if (coltxt[j])
1292                                                                 info->manifest_info->uiapplication->appid = strdup(coltxt[j]);
1293                                                 } else if (strcmp(colname[j], "app_exec") == 0) {
1294                                                         if (coltxt[j])
1295                                                                 info->manifest_info->uiapplication->exec = strdup(coltxt[j]);
1296                                                         else
1297                                                                 info->manifest_info->uiapplication->exec = NULL;
1298                                                 } else if (strcmp(colname[j], "app_nodisplay") == 0) {
1299                                                         if (coltxt[j])
1300                                                                 info->manifest_info->uiapplication->nodisplay = strdup(coltxt[j]);
1301                                                         else
1302                                                                 info->manifest_info->uiapplication->nodisplay = NULL;
1303                                                 } else if (strcmp(colname[j], "app_type") == 0 ) {
1304                                                         if (coltxt[j])
1305                                                                 info->manifest_info->uiapplication->type = strdup(coltxt[j]);
1306                                                         else
1307                                                                 info->manifest_info->uiapplication->type = NULL;
1308                                                 } else if (strcmp(colname[j], "app_multiple") == 0 ) {
1309                                                         if (coltxt[j])
1310                                                                 info->manifest_info->uiapplication->multiple = strdup(coltxt[j]);
1311                                                         else
1312                                                                 info->manifest_info->uiapplication->multiple = NULL;
1313                                                 } else if (strcmp(colname[j], "app_taskmanage") == 0 ) {
1314                                                         if (coltxt[j])
1315                                                                 info->manifest_info->uiapplication->taskmanage = strdup(coltxt[j]);
1316                                                         else
1317                                                                 info->manifest_info->uiapplication->taskmanage = NULL;
1318                                                 } else if (strcmp(colname[j], "app_hwacceleration") == 0 ) {
1319                                                         if (coltxt[j])
1320                                                                 info->manifest_info->uiapplication->hwacceleration = strdup(coltxt[j]);
1321                                                         else
1322                                                                 info->manifest_info->uiapplication->hwacceleration = NULL;
1323                                                 } else if (strcmp(colname[j], "app_screenreader") == 0 ) {
1324                                                         if (coltxt[j])
1325                                                                 info->manifest_info->uiapplication->screenreader = strdup(coltxt[j]);
1326                                                         else
1327                                                                 info->manifest_info->uiapplication->screenreader = NULL;
1328                                                 } else if (strcmp(colname[j], "app_enabled") == 0 ) {
1329                                                         if (coltxt[j])
1330                                                                 info->manifest_info->uiapplication->enabled= strdup(coltxt[j]);
1331                                                         else
1332                                                                 info->manifest_info->uiapplication->enabled = NULL;
1333                                                 } else if (strcmp(colname[j], "app_indicatordisplay") == 0){
1334                                                         if (coltxt[j])
1335                                                                 info->manifest_info->uiapplication->indicatordisplay = strdup(coltxt[j]);
1336                                                         else
1337                                                                 info->manifest_info->uiapplication->indicatordisplay = NULL;
1338                                                 } else if (strcmp(colname[j], "app_portraitimg") == 0){
1339                                                         if (coltxt[j])
1340                                                                 info->manifest_info->uiapplication->portraitimg = strdup(coltxt[j]);
1341                                                         else
1342                                                                 info->manifest_info->uiapplication->portraitimg = NULL;
1343                                                 } else if (strcmp(colname[j], "app_landscapeimg") == 0){
1344                                                         if (coltxt[j])
1345                                                                 info->manifest_info->uiapplication->landscapeimg = strdup(coltxt[j]);
1346                                                         else
1347                                                                 info->manifest_info->uiapplication->landscapeimg = NULL;
1348                                                 } else if (strcmp(colname[j], "app_guestmodevisibility") == 0){
1349                                                         if (coltxt[j])
1350                                                                 info->manifest_info->uiapplication->guestmode_visibility = strdup(coltxt[j]);
1351                                                         else
1352                                                                 info->manifest_info->uiapplication->guestmode_visibility = NULL;
1353                                                 } else if (strcmp(colname[j], "app_recentimage") == 0 ) {
1354                                                         if (coltxt[j])
1355                                                                 info->manifest_info->uiapplication->recentimage = strdup(coltxt[j]);
1356                                                         else
1357                                                                 info->manifest_info->uiapplication->recentimage = NULL;
1358                                                 } else if (strcmp(colname[j], "app_mainapp") == 0 ) {
1359                                                         if (coltxt[j])
1360                                                                 info->manifest_info->uiapplication->mainapp = strdup(coltxt[j]);
1361                                                         else
1362                                                                 info->manifest_info->uiapplication->mainapp = NULL;
1363                                                 } else if (strcmp(colname[j], "package") == 0 ) {
1364                                                         if (coltxt[j])
1365                                                                 info->manifest_info->uiapplication->package = strdup(coltxt[j]);
1366                                                         else
1367                                                                 info->manifest_info->uiapplication->package = NULL;
1368                                                 } else if (strcmp(colname[j], "app_component") == 0) {
1369                                                         if (coltxt[j])
1370                                                                 info->manifest_info->uiapplication->app_component = strdup(coltxt[j]);
1371                                                         else
1372                                                                 info->manifest_info->uiapplication->app_component = NULL;
1373                                                 } else if (strcmp(colname[j], "app_permissiontype") == 0 ) {
1374                                                         if (coltxt[j])
1375                                                                 info->manifest_info->uiapplication->permission_type = strdup(coltxt[j]);
1376                                                         else
1377                                                                 info->manifest_info->uiapplication->permission_type = NULL;
1378                                                 } else if (strcmp(colname[j], "component_type") == 0 ) {
1379                                                         if (coltxt[j])
1380                                                                 info->manifest_info->uiapplication->component_type = strdup(coltxt[j]);
1381                                                         else
1382                                                                 info->manifest_info->uiapplication->component_type = NULL;
1383                                                 } else if (strcmp(colname[j], "app_preload") == 0 ) {
1384                                                         if (coltxt[j])
1385                                                                 info->manifest_info->uiapplication->preload = strdup(coltxt[j]);
1386                                                         else
1387                                                                 info->manifest_info->uiapplication->preload = NULL;
1388                                                 } else if (strcmp(colname[j], "app_submode") == 0 ) {
1389                                                         if (coltxt[j])
1390                                                                 info->manifest_info->uiapplication->submode = strdup(coltxt[j]);
1391                                                         else
1392                                                                 info->manifest_info->uiapplication->submode = NULL;
1393                                                 } else if (strcmp(colname[j], "app_submode_mainid") == 0 ) {
1394                                                         if (coltxt[j])
1395                                                                 info->manifest_info->uiapplication->submode_mainid = strdup(coltxt[j]);
1396                                                         else
1397                                                                 info->manifest_info->uiapplication->submode_mainid = NULL;
1398                                                 } else if (strcmp(colname[j], "app_installed_storage") == 0 ) {
1399                                                         if (coltxt[j])
1400                                                                 info->manifest_info->uiapplication->installed_storage = strdup(coltxt[j]);
1401                                                         else
1402                                                                 info->manifest_info->uiapplication->installed_storage = NULL;
1403                                                 } else
1404                                                         continue;
1405                                         }
1406                                 } else {
1407                                         svcapp = calloc(1, sizeof(serviceapplication_x));
1408                                         if (svcapp == NULL) {
1409                                                 _LOGE("Out of Memory!!!\n");
1410                                                 return -1;
1411                                         }
1412                                         LISTADD(info->manifest_info->serviceapplication, svcapp);
1413                                         for(j = 0; j < ncols; j++)
1414                                         {
1415                                                 if (strcmp(colname[j], "app_id") == 0) {
1416                                                         if (coltxt[j])
1417                                                                 info->manifest_info->serviceapplication->appid = strdup(coltxt[j]);
1418                                                 } else if (strcmp(colname[j], "app_exec") == 0) {
1419                                                         if (coltxt[j])
1420                                                                 info->manifest_info->serviceapplication->exec = strdup(coltxt[j]);
1421                                                         else
1422                                                                 info->manifest_info->serviceapplication->exec = NULL;
1423                                                 } else if (strcmp(colname[j], "app_type") == 0 ){
1424                                                         if (coltxt[j])
1425                                                                 info->manifest_info->serviceapplication->type = strdup(coltxt[j]);
1426                                                         else
1427                                                                 info->manifest_info->serviceapplication->type = NULL;
1428                                                 } else if (strcmp(colname[j], "app_onboot") == 0 ){
1429                                                         if (coltxt[j])
1430                                                                 info->manifest_info->serviceapplication->onboot = strdup(coltxt[j]);
1431                                                         else
1432                                                                 info->manifest_info->serviceapplication->onboot = NULL;
1433                                                 } else if (strcmp(colname[j], "app_autorestart") == 0 ){
1434                                                         if (coltxt[j])
1435                                                                 info->manifest_info->serviceapplication->autorestart = strdup(coltxt[j]);
1436                                                         else
1437                                                                 info->manifest_info->serviceapplication->autorestart = NULL;
1438                                                 } else if (strcmp(colname[j], "package") == 0 ){
1439                                                         if (coltxt[j])
1440                                                                 info->manifest_info->serviceapplication->package = strdup(coltxt[j]);
1441                                                         else
1442                                                                 info->manifest_info->serviceapplication->package = NULL;
1443                                                 } else if (strcmp(colname[j], "app_permissiontype") == 0 ) {
1444                                                         if (coltxt[j])
1445                                                                 info->manifest_info->serviceapplication->permission_type = strdup(coltxt[j]);
1446                                                         else
1447                                                                 info->manifest_info->serviceapplication->permission_type = NULL;
1448                                                 } else
1449                                                         continue;
1450                                         }
1451                                 }
1452                         }
1453                 } else
1454                         continue;
1455         }
1456
1457         return 0;
1458 }
1459
1460 static int __appinfo_cb(void *data, int ncols, char **coltxt, char **colname)
1461 {
1462         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)data;
1463         int i = 0;
1464         icon_x *icon = NULL;
1465         label_x *label = NULL;
1466         category_x *category = NULL;
1467         metadata_x *metadata = NULL;
1468         permission_x *permission = NULL;
1469         image_x *image = NULL;
1470
1471         switch (info->app_component) {
1472         case PMINFO_UI_APP:
1473                 icon = calloc(1, sizeof(icon_x));
1474                 LISTADD(info->uiapp_info->icon, icon);
1475                 label = calloc(1, sizeof(label_x));
1476                 LISTADD(info->uiapp_info->label, label);
1477                 category = calloc(1, sizeof(category_x));
1478                 LISTADD(info->uiapp_info->category, category);
1479                 metadata = calloc(1, sizeof(metadata_x));
1480                 LISTADD(info->uiapp_info->metadata, metadata);
1481                 permission = calloc(1, sizeof(permission_x));
1482                 LISTADD(info->uiapp_info->permission, permission);
1483                 image = calloc(1, sizeof(image_x));
1484                 LISTADD(info->uiapp_info->image, image);
1485
1486                 for(i = 0; i < ncols; i++)
1487                 {
1488                         if (strcmp(colname[i], "app_id") == 0) {
1489                                 /*appid being foreign key, is column in every table
1490                                 Hence appid gets strduped every time leading to memory leak.
1491                                 If appid is already set, just continue.*/
1492                                 if (info->uiapp_info->appid)
1493                                         continue;
1494                                 if (coltxt[i])
1495                                         info->uiapp_info->appid = strdup(coltxt[i]);
1496                                 else
1497                                         info->uiapp_info->appid = NULL;
1498                         } else if (strcmp(colname[i], "app_exec") == 0) {
1499                                 if (coltxt[i])
1500                                         info->uiapp_info->exec = strdup(coltxt[i]);
1501                                 else
1502                                         info->uiapp_info->exec = NULL;
1503                         } else if (strcmp(colname[i], "app_nodisplay") == 0) {
1504                                 if (coltxt[i])
1505                                         info->uiapp_info->nodisplay = strdup(coltxt[i]);
1506                                 else
1507                                         info->uiapp_info->nodisplay = NULL;
1508                         } else if (strcmp(colname[i], "app_type") == 0 ) {
1509                                 if (coltxt[i])
1510                                         info->uiapp_info->type = strdup(coltxt[i]);
1511                                 else
1512                                         info->uiapp_info->type = NULL;
1513                         } else if (strcmp(colname[i], "app_icon_section") == 0 ) {
1514                                 if (coltxt[i])
1515                                         info->uiapp_info->icon->section= strdup(coltxt[i]);
1516                                 else
1517                                         info->uiapp_info->icon->section = NULL;
1518                         } else if (strcmp(colname[i], "app_icon") == 0) {
1519                                 if (coltxt[i])
1520                                         info->uiapp_info->icon->text = strdup(coltxt[i]);
1521                                 else
1522                                         info->uiapp_info->icon->text = NULL;
1523                         } else if (strcmp(colname[i], "app_label") == 0 ) {
1524                                 if (coltxt[i])
1525                                         info->uiapp_info->label->text = strdup(coltxt[i]);
1526                                 else
1527                                         info->uiapp_info->label->text = NULL;
1528                         } else if (strcmp(colname[i], "app_multiple") == 0 ) {
1529                                 if (coltxt[i])
1530                                         info->uiapp_info->multiple = strdup(coltxt[i]);
1531                                 else
1532                                         info->uiapp_info->multiple = NULL;
1533                         } else if (strcmp(colname[i], "app_taskmanage") == 0 ) {
1534                                 if (coltxt[i])
1535                                         info->uiapp_info->taskmanage = strdup(coltxt[i]);
1536                                 else
1537                                         info->uiapp_info->taskmanage = NULL;
1538                         } else if (strcmp(colname[i], "app_hwacceleration") == 0 ) {
1539                                 if (coltxt[i])
1540                                         info->uiapp_info->hwacceleration = strdup(coltxt[i]);
1541                                 else
1542                                         info->uiapp_info->hwacceleration = NULL;
1543                         } else if (strcmp(colname[i], "app_screenreader") == 0 ) {
1544                                 if (coltxt[i])
1545                                         info->uiapp_info->screenreader = strdup(coltxt[i]);
1546                                 else
1547                                         info->uiapp_info->screenreader = NULL;
1548                         } else if (strcmp(colname[i], "app_enabled") == 0 ) {
1549                                 if (coltxt[i])
1550                                         info->uiapp_info->enabled= strdup(coltxt[i]);
1551                                 else
1552                                         info->uiapp_info->enabled = NULL;
1553                         } else if (strcmp(colname[i], "app_indicatordisplay") == 0){
1554                                 if (coltxt[i])
1555                                         info->uiapp_info->indicatordisplay = strdup(coltxt[i]);
1556                                 else
1557                                         info->uiapp_info->indicatordisplay = NULL;
1558                         } else if (strcmp(colname[i], "app_portraitimg") == 0){
1559                                 if (coltxt[i])
1560                                         info->uiapp_info->portraitimg = strdup(coltxt[i]);
1561                                 else
1562                                         info->uiapp_info->portraitimg = NULL;
1563                         } else if (strcmp(colname[i], "app_landscapeimg") == 0){
1564                                 if (coltxt[i])
1565                                         info->uiapp_info->landscapeimg = strdup(coltxt[i]);
1566                                 else
1567                                         info->uiapp_info->landscapeimg = NULL;
1568                         } else if (strcmp(colname[i], "app_guestmodevisibility") == 0){
1569                                 if (coltxt[i])
1570                                         info->uiapp_info->guestmode_visibility = strdup(coltxt[i]);
1571                                 else
1572                                         info->uiapp_info->guestmode_visibility = NULL;
1573                         } else if (strcmp(colname[i], "category") == 0 ) {
1574                                 if (coltxt[i])
1575                                         info->uiapp_info->category->name = strdup(coltxt[i]);
1576                                 else
1577                                         info->uiapp_info->category->name = NULL;
1578                         } else if (strcmp(colname[i], "md_key") == 0 ) {
1579                                 if (coltxt[i])
1580                                         info->uiapp_info->metadata->key = strdup(coltxt[i]);
1581                                 else
1582                                         info->uiapp_info->metadata->key = NULL;
1583                         } else if (strcmp(colname[i], "md_value") == 0 ) {
1584                                 if (coltxt[i])
1585                                         info->uiapp_info->metadata->value = strdup(coltxt[i]);
1586                                 else
1587                                         info->uiapp_info->metadata->value = NULL;
1588                         } else if (strcmp(colname[i], "pm_type") == 0 ) {
1589                                 if (coltxt[i])
1590                                         info->uiapp_info->permission->type= strdup(coltxt[i]);
1591                                 else
1592                                         info->uiapp_info->permission->type = NULL;
1593                         } else if (strcmp(colname[i], "pm_value") == 0 ) {
1594                                 if (coltxt[i])
1595                                         info->uiapp_info->permission->value = strdup(coltxt[i]);
1596                                 else
1597                                         info->uiapp_info->permission->value = NULL;
1598                         } else if (strcmp(colname[i], "app_recentimage") == 0 ) {
1599                                 if (coltxt[i])
1600                                         info->uiapp_info->recentimage = strdup(coltxt[i]);
1601                                 else
1602                                         info->uiapp_info->recentimage = NULL;
1603                         } else if (strcmp(colname[i], "app_mainapp") == 0 ) {
1604                                 if (coltxt[i])
1605                                         info->uiapp_info->mainapp = strdup(coltxt[i]);
1606                                 else
1607                                         info->uiapp_info->mainapp = NULL;
1608                         } else if (strcmp(colname[i], "app_locale") == 0 ) {
1609                                 if (coltxt[i]) {
1610                                         info->uiapp_info->icon->lang = strdup(coltxt[i]);
1611                                         info->uiapp_info->label->lang = strdup(coltxt[i]);
1612                                 }
1613                                 else {
1614                                         info->uiapp_info->icon->lang = NULL;
1615                                         info->uiapp_info->label->lang = NULL;
1616                                 }
1617                         } else if (strcmp(colname[i], "app_image") == 0) {
1618                                         if (coltxt[i])
1619                                                 info->uiapp_info->image->text= strdup(coltxt[i]);
1620                                         else
1621                                                 info->uiapp_info->image->text = NULL;
1622                         } else if (strcmp(colname[i], "app_image_section") == 0) {
1623                                         if (coltxt[i])
1624                                                 info->uiapp_info->image->section= strdup(coltxt[i]);
1625                                         else
1626                                                 info->uiapp_info->image->section = NULL;
1627                         } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
1628                                 if (coltxt[i])
1629                                         info->uiapp_info->permission_type = strdup(coltxt[i]);
1630                                 else
1631                                         info->uiapp_info->permission_type = NULL;
1632                         } else if (strcmp(colname[i], "component_type") == 0 ) {
1633                                 if (coltxt[i])
1634                                         info->uiapp_info->component_type = strdup(coltxt[i]);
1635                                 else
1636                                         info->uiapp_info->component_type = NULL;
1637                         } else if (strcmp(colname[i], "app_preload") == 0 ) {
1638                                 if (coltxt[i])
1639                                         info->uiapp_info->preload = strdup(coltxt[i]);
1640                                 else
1641                                         info->uiapp_info->preload = NULL;
1642                         } else if (strcmp(colname[i], "app_submode") == 0 ) {
1643                                 if (coltxt[i])
1644                                         info->uiapp_info->submode = strdup(coltxt[i]);
1645                                 else
1646                                         info->uiapp_info->submode = NULL;
1647                         } else if (strcmp(colname[i], "app_submode_mainid") == 0 ) {
1648                                 if (coltxt[i])
1649                                         info->uiapp_info->submode_mainid = strdup(coltxt[i]);
1650                                 else
1651                                         info->uiapp_info->submode_mainid = NULL;
1652                         } else if (strcmp(colname[i], "app_installed_storage") == 0 ) {
1653                                 if (coltxt[i])
1654                                         info->uiapp_info->installed_storage = strdup(coltxt[i]);
1655                                 else
1656                                         info->uiapp_info->installed_storage = NULL;
1657                         } else
1658                                 continue;
1659                 }
1660                 break;
1661         case PMINFO_SVC_APP:
1662                 icon = calloc(1, sizeof(icon_x));
1663                 LISTADD(info->svcapp_info->icon, icon);
1664                 label = calloc(1, sizeof(label_x));
1665                 LISTADD(info->svcapp_info->label, label);
1666                 category = calloc(1, sizeof(category_x));
1667                 LISTADD(info->svcapp_info->category, category);
1668                 metadata = calloc(1, sizeof(metadata_x));
1669                 LISTADD(info->svcapp_info->metadata, metadata);
1670                 permission = calloc(1, sizeof(permission_x));
1671                 LISTADD(info->svcapp_info->permission, permission);
1672                 for(i = 0; i < ncols; i++)
1673                 {
1674                         if (strcmp(colname[i], "app_id") == 0) {
1675                                 /*appid being foreign key, is column in every table
1676                                 Hence appid gets strduped every time leading to memory leak.
1677                                 If appid is already set, just continue.*/
1678                                 if (info->svcapp_info->appid)
1679                                         continue;
1680                                 if (coltxt[i])
1681                                         info->svcapp_info->appid = strdup(coltxt[i]);
1682                                 else
1683                                         info->svcapp_info->appid = NULL;
1684                         } else if (strcmp(colname[i], "app_exec") == 0) {
1685                                 if (coltxt[i])
1686                                         info->svcapp_info->exec = strdup(coltxt[i]);
1687                                 else
1688                                         info->svcapp_info->exec = NULL;
1689                         } else if (strcmp(colname[i], "app_icon") == 0) {
1690                                 if (coltxt[i])
1691                                         info->svcapp_info->icon->text = strdup(coltxt[i]);
1692                                 else
1693                                         info->svcapp_info->icon->text = NULL;
1694                         } else if (strcmp(colname[i], "app_label") == 0 ) {
1695                                 if (coltxt[i])
1696                                         info->svcapp_info->label->text = strdup(coltxt[i]);
1697                                 else
1698                                         info->svcapp_info->label->text = NULL;
1699                         } else if (strcmp(colname[i], "app_type") == 0 ) {
1700                                 if (coltxt[i])
1701                                         info->svcapp_info->type = strdup(coltxt[i]);
1702                                 else
1703                                         info->svcapp_info->type = NULL;
1704                         } else if (strcmp(colname[i], "app_onboot") == 0 ) {
1705                                 if (coltxt[i])
1706                                         info->svcapp_info->onboot = strdup(coltxt[i]);
1707                                 else
1708                                         info->svcapp_info->onboot = NULL;
1709                         } else if (strcmp(colname[i], "app_autorestart") == 0 ) {
1710                                 if (coltxt[i])
1711                                         info->svcapp_info->autorestart = strdup(coltxt[i]);
1712                                 else
1713                                         info->svcapp_info->autorestart = NULL;
1714                         } else if (strcmp(colname[i], "app_enabled") == 0 ) {
1715                                 if (coltxt[i])
1716                                         info->svcapp_info->enabled= strdup(coltxt[i]);
1717                                 else
1718                                         info->svcapp_info->enabled = NULL;
1719                         } else if (strcmp(colname[i], "category") == 0 ) {
1720                                 if (coltxt[i])
1721                                         info->svcapp_info->category->name = strdup(coltxt[i]);
1722                                 else
1723                                         info->svcapp_info->category->name = NULL;
1724                         } else if (strcmp(colname[i], "md_key") == 0 ) {
1725                                 if (coltxt[i])
1726                                         info->svcapp_info->metadata->key = strdup(coltxt[i]);
1727                                 else
1728                                         info->svcapp_info->metadata->key = NULL;
1729                         } else if (strcmp(colname[i], "md_value") == 0 ) {
1730                                 if (coltxt[i])
1731                                         info->svcapp_info->metadata->value = strdup(coltxt[i]);
1732                                 else
1733                                         info->svcapp_info->metadata->value = NULL;
1734                         } else if (strcmp(colname[i], "pm_type") == 0 ) {
1735                                 if (coltxt[i])
1736                                         info->svcapp_info->permission->type= strdup(coltxt[i]);
1737                                 else
1738                                         info->svcapp_info->permission->type = NULL;
1739                         } else if (strcmp(colname[i], "pm_value") == 0 ) {
1740                                 if (coltxt[i])
1741                                         info->svcapp_info->permission->value = strdup(coltxt[i]);
1742                                 else
1743                                         info->svcapp_info->permission->value = NULL;
1744                         } else if (strcmp(colname[i], "app_locale") == 0 ) {
1745                                 if (coltxt[i]) {
1746                                         info->svcapp_info->icon->lang = strdup(coltxt[i]);
1747                                         info->svcapp_info->label->lang = strdup(coltxt[i]);
1748                                 }
1749                                 else {
1750                                         info->svcapp_info->icon->lang = NULL;
1751                                         info->svcapp_info->label->lang = NULL;
1752                                 }
1753                         } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
1754                                 if (coltxt[i])
1755                                         info->svcapp_info->permission_type = strdup(coltxt[i]);
1756                                 else
1757                                         info->svcapp_info->permission_type = NULL;
1758                         } else
1759                                 continue;
1760                 }
1761                 break;
1762         default:
1763                 break;
1764         }
1765
1766         return 0;
1767 }
1768
1769
1770 static int __appcomponent_cb(void *data, int ncols, char **coltxt, char **colname)
1771 {
1772         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)data;
1773         int i = 0;
1774         for(i = 0; i < ncols; i++)
1775         {
1776                 if (strcmp(colname[i], "app_component") == 0) {
1777                         info->app_component = __appcomponent_convert(coltxt[i]);
1778                 } else if (strcmp(colname[i], "package") == 0) {
1779                         info->package = strdup(coltxt[i]);
1780                 }
1781         }
1782
1783         return 0;
1784 }
1785
1786 static int __datacontrol_cb(void *data, int ncols, char **coltxt, char **colname)
1787 {
1788         pkgmgr_datacontrol_x *info = (pkgmgr_datacontrol_x *)data;
1789         int i = 0;
1790         for(i = 0; i < ncols; i++)
1791         {
1792                 if (strcmp(colname[i], "PACKAGE_NAME") == 0) {
1793                         if (coltxt[i])
1794                                 info->appid = strdup(coltxt[i]);
1795                         else
1796                                 info->appid = NULL;
1797                 } else if (strcmp(colname[i], "ACCESS") == 0 ){
1798                         if (coltxt[i])
1799                                 info->access = strdup(coltxt[i]);
1800                         else
1801                                 info->access = NULL;
1802                 } else
1803                         continue;
1804         }
1805         return 0;
1806 }
1807
1808 static int __cert_cb(void *data, int ncols, char **coltxt, char **colname)
1809 {
1810         pkgmgr_cert_x *info = (pkgmgr_cert_x *)data;
1811         int i = 0;
1812
1813         for(i = 0; i < ncols; i++)
1814         {
1815                 if (strcmp(colname[i], "author_signer_cert") == 0) {
1816                         if (coltxt[i])
1817                                 info->cert_id = atoi(coltxt[i]);
1818                         else
1819                                 info->cert_id = 0;
1820                 } else if (strcmp(colname[i], "package") == 0) {
1821                         if (coltxt[i])
1822                                 info->pkgid= strdup(coltxt[i]);
1823                         else
1824                                 info->pkgid = NULL;
1825                 } else
1826                         continue;
1827         }
1828         return 0;
1829 }
1830
1831 /* get the first locale value*/
1832 static int __fallback_locale_cb(void *data, int ncols, char **coltxt, char **colname)
1833 {
1834         pkgmgr_locale_x *info = (pkgmgr_locale_x *)data;
1835
1836         if (ncols >= 1)
1837                 info->locale = strdup(coltxt[0]);
1838         else
1839                 info->locale = NULL;
1840
1841         return 0;
1842 }
1843
1844 static int __exec_certinfo_query(char *query, void *data)
1845 {
1846         char *error_message = NULL;
1847         if (SQLITE_OK !=
1848             sqlite3_exec(cert_db, query, __certinfo_cb, data, &error_message)) {
1849                 _LOGE("Don't execute query = %s error message = %s\n", query,
1850                        error_message);
1851                 sqlite3_free(error_message);
1852                 return -1;
1853         }
1854         sqlite3_free(error_message);
1855         return 0;
1856 }
1857
1858 static int __exec_certindexinfo_query(char *query, void *data)
1859 {
1860         char *error_message = NULL;
1861         if (SQLITE_OK !=
1862             sqlite3_exec(cert_db, query, __certindexinfo_cb, data, &error_message)) {
1863                 _LOGE("Don't execute query = %s error message = %s\n", query,
1864                        error_message);
1865                 sqlite3_free(error_message);
1866                 return -1;
1867         }
1868         sqlite3_free(error_message);
1869         return 0;
1870 }
1871
1872 static int __exec_db_query(sqlite3 *db, char *query, sqlite_query_callback callback, void *data)
1873 {
1874         char *error_message = NULL;
1875         if (SQLITE_OK !=
1876             sqlite3_exec(db, query, callback, data, &error_message)) {
1877                 _LOGE("Don't execute query = %s error message = %s\n", query,
1878                        error_message);
1879                 sqlite3_free(error_message);
1880                 return -1;
1881         }
1882         sqlite3_free(error_message);
1883         return 0;
1884 }
1885
1886
1887 static int __child_element(xmlTextReaderPtr reader, int depth)
1888 {
1889         int ret = xmlTextReaderRead(reader);
1890         int cur = xmlTextReaderDepth(reader);
1891         while (ret == 1) {
1892
1893                 switch (xmlTextReaderNodeType(reader)) {
1894                 case XML_READER_TYPE_ELEMENT:
1895                         if (cur == depth + 1)
1896                                 return 1;
1897                         break;
1898                 case XML_READER_TYPE_TEXT:
1899                         /*text is handled by each function separately*/
1900                         if (cur == depth + 1)
1901                                 return 0;
1902                         break;
1903                 case XML_READER_TYPE_END_ELEMENT:
1904                         if (cur == depth)
1905                                 return 0;
1906                         break;
1907                 default:
1908                         if (cur <= depth)
1909                                 return 0;
1910                         break;
1911                 }
1912                 ret = xmlTextReaderRead(reader);
1913                 cur = xmlTextReaderDepth(reader);
1914         }
1915         return ret;
1916 }
1917
1918 static int __check_validation_of_qurey_cb(void *data, int ncols, char **coltxt, char **colname)
1919 {
1920         int *p = (int*)data;
1921         *p = atoi(coltxt[0]);
1922         return 0;
1923 }
1924
1925 static int __check_app_locale_from_app_localized_info_by_exact(sqlite3 *db, const char *appid, const char *locale)
1926 {
1927         int result_query = -1;
1928         int ret = 0;
1929         char query[MAX_QUERY_LEN];
1930
1931         snprintf(query, MAX_QUERY_LEN, "select exists(select app_locale from package_app_localized_info where app_id='%s' and app_locale='%s')", appid, locale);
1932         ret = __exec_db_query(db, query, __check_validation_of_qurey_cb, (void *)&result_query);
1933         retvm_if(ret == -1, PMINFO_R_ERROR, "Exec DB query failed");
1934         return result_query;
1935 }
1936
1937 static int __check_app_locale_from_app_localized_info_by_fallback(sqlite3 *db, const char *appid, const char *locale)
1938 {
1939         int result_query = -1;
1940         int ret = 0;
1941         char wildcard[2] = {'%','\0'};
1942         char query[MAX_QUERY_LEN];
1943         char lang[3] = {'\0'};
1944         strncpy(lang, locale, LANGUAGE_LENGTH);
1945
1946         snprintf(query, MAX_QUERY_LEN, "select exists(select app_locale from package_app_localized_info where app_id='%s' and app_locale like '%s%s')", appid, lang, wildcard);
1947         ret = __exec_db_query(db, query, __check_validation_of_qurey_cb, (void *)&result_query);
1948         retvm_if(ret == -1, PMINFO_R_ERROR, "Exec DB query failed");
1949         return result_query;
1950 }
1951
1952 static char* __get_app_locale_from_app_localized_info_by_fallback(sqlite3 *db, const char *appid, const char *locale)
1953 {
1954         int ret = 0;
1955         char wildcard[2] = {'%','\0'};
1956         char lang[3] = {'\0'};
1957         char query[MAX_QUERY_LEN];
1958         char *locale_new = NULL;
1959         pkgmgr_locale_x *info = NULL;
1960
1961         info = (pkgmgr_locale_x *)malloc(sizeof(pkgmgr_locale_x));
1962         if (info == NULL) {
1963                 _LOGE("Out of Memory!!!\n");
1964                 return NULL;
1965         }
1966         memset(info, '\0', sizeof(*info));
1967
1968         strncpy(lang, locale, 2);
1969         snprintf(query, MAX_QUERY_LEN, "select app_locale from package_app_localized_info where app_id='%s' and app_locale like '%s%s'", appid, lang, wildcard);
1970         ret = __exec_db_query(db, query, __fallback_locale_cb, (void *)info);
1971         tryvm_if(ret == -1, PMINFO_R_ERROR, "Exec DB query failed");
1972         locale_new = info->locale;
1973         free(info);
1974         return locale_new;
1975 catch:
1976         if (info) {
1977                 free(info);
1978                 info = NULL;
1979         }
1980         return NULL;
1981 }
1982
1983 static char* __convert_syslocale_to_manifest_locale(char *syslocale)
1984 {
1985         char *locale = malloc(6);
1986         if (!locale) {
1987                 _LOGE("Malloc Failed\n");
1988                 return NULL;
1989         }
1990
1991         sprintf(locale, "%c%c-%c%c", syslocale[0], syslocale[1], tolower(syslocale[3]), tolower(syslocale[4]));
1992         return locale;
1993 }
1994
1995 static char* __get_app_locale_by_fallback(sqlite3 *db, const char *appid, const char *syslocale)
1996 {
1997         assert(appid);
1998         assert(syslocale);
1999
2000         char *locale = NULL;
2001         char *locale_new = NULL;
2002         int check_result = 0;
2003
2004         locale = __convert_syslocale_to_manifest_locale((char *)syslocale);
2005
2006         /*check exact matching */
2007         check_result = __check_app_locale_from_app_localized_info_by_exact(db, appid, locale);
2008
2009         /* Exact found */
2010         if (check_result == 1) {
2011 //              _LOGD("%s find exact locale(%s)\n", appid, locale);
2012                 return locale;
2013         }
2014
2015         /* fallback matching */
2016         check_result = __check_app_locale_from_app_localized_info_by_fallback(db, appid, locale);
2017         if(check_result == 1) {
2018                    locale_new = __get_app_locale_from_app_localized_info_by_fallback(db, appid, locale);
2019                    free(locale);
2020                    if (locale_new == NULL)
2021                            locale_new =  strdup(DEFAULT_LOCALE);
2022                    return locale_new;
2023         }
2024
2025         /* default locale */
2026         free(locale);
2027         return  strdup(DEFAULT_LOCALE);
2028 }
2029
2030 static int __delete_certinfo(const char *pkgid)
2031 {
2032         int ret = -1;
2033         int i = 0;
2034         int j = 0;
2035         int c = 0;
2036         int unique_id[MAX_CERT_TYPE] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
2037         char *error_message = NULL;
2038         char query[MAX_QUERY_LEN] = {'\0'};
2039         pkgmgr_certinfo_x *certinfo = NULL;
2040         pkgmgr_certindexinfo_x *indexinfo = NULL;
2041         certinfo = calloc(1, sizeof(pkgmgr_certinfo_x));
2042         retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
2043         indexinfo = calloc(1, sizeof(pkgmgr_certindexinfo_x));
2044         if (indexinfo == NULL) {
2045                 _LOGE("Out of Memory!!!");
2046                 ret = PMINFO_R_ERROR;
2047                 goto err;
2048         }
2049         /*populate certinfo from DB*/
2050         snprintf(query, MAX_QUERY_LEN, "select * from package_cert_info where package='%s' ", pkgid);
2051         ret = __exec_certinfo_query(query, (void *)certinfo);
2052         if (ret == -1) {
2053                 _LOGE("Package Cert Info DB Information retrieval failed\n");
2054                 ret = PMINFO_R_ERROR;
2055                 goto err;
2056         }
2057         /*Update cert index table*/
2058         for (i = 0; i < MAX_CERT_TYPE; i++) {
2059                 if ((certinfo->cert_id)[i]) {
2060                         for (j = 0; j < MAX_CERT_TYPE; j++) {
2061                                 if ((certinfo->cert_id)[i] == unique_id[j]) {
2062                                         /*Ref count has already been updated. Just continue*/
2063                                         break;
2064                                 }
2065                         }
2066                         if (j == MAX_CERT_TYPE)
2067                                 unique_id[c++] = (certinfo->cert_id)[i];
2068                         else
2069                                 continue;
2070                         memset(query, '\0', MAX_QUERY_LEN);
2071                         snprintf(query, MAX_QUERY_LEN, "select * from package_cert_index_info where cert_id=%d ", (certinfo->cert_id)[i]);
2072                         ret = __exec_certindexinfo_query(query, (void *)indexinfo);
2073                         if (ret == -1) {
2074                                 _LOGE("Cert Info DB Information retrieval failed\n");
2075                                 ret = PMINFO_R_ERROR;
2076                                 goto err;
2077                         }
2078                         memset(query, '\0', MAX_QUERY_LEN);
2079                         if (indexinfo->cert_ref_count > 1) {
2080                                 /*decrease ref count*/
2081                                 snprintf(query, MAX_QUERY_LEN, "update package_cert_index_info set cert_ref_count=%d where cert_id=%d ",
2082                                 indexinfo->cert_ref_count - 1, (certinfo->cert_id)[i]);
2083                         } else {
2084                                 /*delete this certificate as ref count is 1 and it will become 0*/
2085                                 snprintf(query, MAX_QUERY_LEN, "delete from  package_cert_index_info where cert_id=%d ", (certinfo->cert_id)[i]);
2086                         }
2087                         if (SQLITE_OK !=
2088                             sqlite3_exec(cert_db, query, NULL, NULL, &error_message)) {
2089                                 _LOGE("Don't execute query = %s error message = %s\n", query,
2090                                        error_message);
2091                                 sqlite3_free(error_message);
2092                                 ret = PMINFO_R_ERROR;
2093                                 goto err;
2094                         }
2095                 }
2096         }
2097         /*Now delete the entry from db*/
2098         snprintf(query, MAX_QUERY_LEN, "delete from package_cert_info where package='%s'", pkgid);
2099         if (SQLITE_OK !=
2100             sqlite3_exec(cert_db, query, NULL, NULL, &error_message)) {
2101                 _LOGE("Don't execute query = %s error message = %s\n", query,
2102                        error_message);
2103                 sqlite3_free(error_message);
2104                 ret = PMINFO_R_ERROR;
2105                 goto err;
2106         }
2107         ret = PMINFO_R_OK;
2108 err:
2109         if (indexinfo) {
2110                 free(indexinfo);
2111                 indexinfo = NULL;
2112         }
2113         if (certinfo->pkgid) {
2114                 free(certinfo->pkgid);
2115                 certinfo->pkgid = NULL;
2116         }
2117         for (i = 0; i < MAX_CERT_TYPE; i++) {
2118                 if ((certinfo->cert_info)[i]) {
2119                         free((certinfo->cert_info)[i]);
2120                         (certinfo->cert_info)[i] = NULL;
2121                 }
2122         }
2123         free(certinfo);
2124         certinfo = NULL;
2125         return ret;
2126 }
2127
2128
2129 int __reqeust_get_size(const char *pkgid, int type)
2130 {
2131         int ret = 0;
2132         int size = 0;
2133         char *errmsg = NULL;
2134         void *pc = NULL;
2135         void *handle = NULL;
2136         FILE *fp = NULL;
2137         pkgmgr_client *(*__pkgmgr_client_new)(client_type ctype) = NULL;
2138         int (*__pkgmgr_client_get_size)(pkgmgr_client * pc, const char *pkgid, pkgmgr_getsize_type get_type, pkgmgr_handler event_cb, void *data) = NULL;
2139         int (*__pkgmgr_client_request_service)(pkgmgr_request_service_type service_type, int service_mode,
2140                                           pkgmgr_client * pc, const char *pkg_type, const char *pkgid,
2141                                           const char *custom_info, pkgmgr_handler event_cb, void *data) = NULL;
2142
2143         retvm_if(pkgid == NULL, PMINFO_R_ERROR, "pkgid is NULL");
2144
2145         handle = dlopen("libpkgmgr-client.so.0", RTLD_LAZY | RTLD_GLOBAL);
2146         retvm_if(!handle, PMINFO_R_ERROR, "dlopen() failed. [%s]", dlerror());
2147
2148         __pkgmgr_client_new = dlsym(handle, "pkgmgr_client_new");
2149         errmsg = dlerror();
2150         tryvm_if((errmsg != NULL) || (__pkgmgr_client_new == NULL), ret = PMINFO_R_ERROR, "dlsym() failed. [%s]", errmsg);
2151
2152         __pkgmgr_client_request_service = dlsym(handle, "pkgmgr_client_request_service");
2153         errmsg = dlerror();
2154         tryvm_if((errmsg != NULL) || (__pkgmgr_client_request_service == NULL), ret = PMINFO_R_ERROR, "dlsym() failed. [%s]", errmsg);
2155
2156         pc = __pkgmgr_client_new(PC_REQUEST);
2157         tryvm_if(pc == NULL, ret = PMINFO_R_ERROR, "pkgmgr_client_new failed.");
2158
2159         size = __pkgmgr_client_request_service(PM_REQUEST_GET_SIZE, type, pc, NULL, pkgid, NULL, NULL, NULL);
2160         tryvm_if(size < 0, ret = PMINFO_R_ERROR, "get size failed.");
2161
2162         ret = size;
2163
2164 catch:
2165         dlclose(handle);
2166         return ret;
2167 }
2168
2169 void __get_package_size(const char *size_info, const char *pkgid, int *total_size, int *data_size)
2170 {
2171         char *p = NULL;
2172         p = strstr(size_info, pkgid);
2173         if (p == NULL)
2174                 return;
2175
2176         p += strlen(pkgid);
2177         if (*p == '=') {
2178                 *total_size = atoi(p+1);
2179
2180                 while (*p)
2181                 {
2182                         if (*p == '/') {
2183                                 *data_size = atoi(p+1);
2184                                 break;
2185                         } else {
2186                                 p++;
2187                         }
2188                 }
2189         } else {
2190                 return;
2191         }
2192
2193         return;
2194 }
2195
2196 int __get_package_size_info(char **size_info)
2197 {
2198         int ret = 0;
2199         char *pInfo = NULL;
2200         FILE *fp = NULL;
2201         pInfo = (char *)malloc(MAX_PKG_BUF_LEN * MAX_PKG_INFO_LEN);
2202         memset(pInfo, 0, MAX_PKG_BUF_LEN * MAX_PKG_INFO_LEN);
2203
2204         fp = fopen(PKG_SIZE_INFO_FILE, "r");
2205         if (fp != NULL) {
2206                 fread(pInfo, 1, MAX_PKG_BUF_LEN * MAX_PKG_INFO_LEN, fp);
2207                 fclose(fp);
2208         }
2209
2210         *size_info = pInfo;
2211         return PMINFO_R_OK;
2212 }
2213
2214 int __set_package_size_info(manifest_x *manifest, const char* size_info)
2215 {
2216         int total_size = 0;
2217         int data_size = 0;
2218         int ret = 0;
2219         char total_buf[PKG_TYPE_STRING_LEN_MAX] = {'\0'};
2220         char data_buf[PKG_TYPE_STRING_LEN_MAX] = {'\0'};
2221
2222         __get_package_size(size_info, manifest->package, &total_size, &data_size);
2223
2224         manifest->package_size = strdup("true");
2225
2226         snprintf(total_buf, PKG_TYPE_STRING_LEN_MAX - 1, "%d", total_size);
2227         manifest->package_total_size = strndup(total_buf, PKG_TYPE_STRING_LEN_MAX - 1);
2228
2229         snprintf(data_buf, PKG_TYPE_STRING_LEN_MAX - 1, "%d", data_size);
2230         manifest->package_data_size = strndup(data_buf, PKG_TYPE_STRING_LEN_MAX - 1);
2231
2232         return 0;
2233 }
2234
2235 static int __pkginfo_check_installed_storage(pkgmgr_pkginfo_x *pkginfo)
2236 {
2237         char buf[MAX_QUERY_LEN] = {'\0'};
2238         retvm_if(pkginfo->manifest_info->package == NULL, PMINFO_R_OK, "pkgid is NULL\n");
2239
2240         if (strcmp(pkginfo->manifest_info->installed_storage,"installed_external") == 0) {
2241                 snprintf(buf, MAX_QUERY_LEN - 1, "%s%s", PKG_SD_PATH, pkginfo->manifest_info->package);
2242                 if (access(buf, R_OK) != 0) {
2243                         _LOGE("can not access [%s]", buf);
2244                         return PMINFO_R_OK;//tmep, it will be fixed to ::  return PMINFO_R_ERROR;
2245                 }
2246         }
2247
2248         return PMINFO_R_OK;
2249 }
2250
2251 static int __appinfo_check_installed_storage(pkgmgr_appinfo_x *appinfo)
2252 {
2253         char buf[MAX_QUERY_LEN] = {'\0'};
2254         char *pkgid = NULL;
2255
2256         pkgid = appinfo->package;
2257         if(pkgid == NULL)
2258                 pkgid = appinfo->uiapp_info->package;
2259         retvm_if(pkgid == NULL, PMINFO_R_OK, "pkgid is NULL\n");
2260
2261         if (strcmp(appinfo->uiapp_info->installed_storage,"installed_external") == 0) {
2262                 snprintf(buf, MAX_QUERY_LEN - 1, "%s%s", PKG_SD_PATH, pkgid);
2263                 if (access(buf, R_OK) != 0) {
2264                         _LOGE("can not access [%s]", buf);
2265                         return PMINFO_R_OK;//tmep, it will be fixed to ::  return PMINFO_R_ERROR;
2266                 }
2267         }
2268
2269         return PMINFO_R_OK;
2270 }
2271
2272 static int __update_ail_appinfo(manifest_x * mfx)
2273 {
2274         int ret = -1;
2275         uiapplication_x *uiapplication = mfx->uiapplication;
2276         void *lib_handle = NULL;
2277         int (*ail_desktop_operation) (const char *appid, const char *property, const char *value, bool broadcast);
2278         char *aop = NULL;
2279
2280         if ((lib_handle = dlopen(LIBAIL_PATH, RTLD_LAZY)) == NULL) {
2281                 _LOGE("dlopen is failed LIBAIL_PATH[%s]\n", LIBAIL_PATH);
2282                 goto END;
2283         }
2284
2285         aop  = "ail_desktop_appinfo_modify_str";
2286
2287         if ((ail_desktop_operation =
2288              dlsym(lib_handle, aop)) == NULL || dlerror() != NULL) {
2289                 _LOGE("can not find symbol \n");
2290                 goto END;
2291         }
2292
2293         for(; uiapplication; uiapplication=uiapplication->next) {
2294                 ret = ail_desktop_operation(uiapplication->appid, "AIL_PROP_X_SLP_INSTALLEDSTORAGE_STR", mfx->installed_storage, FALSE);
2295                 if (ret != 0)
2296                         _LOGE("Failed to store info in DB\n");
2297         }
2298
2299 END:
2300         if (lib_handle)
2301                 dlclose(lib_handle);
2302
2303         return ret;
2304 }
2305
2306 static int __get_pkg_location(const char *pkgid)
2307 {
2308         retvm_if(pkgid == NULL, PMINFO_R_OK, "pkginfo handle is NULL");
2309
2310         FILE *fp = NULL;
2311         char pkg_mmc_path[FILENAME_MAX] = { 0, };
2312         snprintf(pkg_mmc_path, FILENAME_MAX, "%s%s", PKG_SD_PATH, pkgid);
2313
2314         /*check whether application is in external memory or not */
2315         fp = fopen(pkg_mmc_path, "r");
2316         if (fp != NULL) {
2317                 fclose(fp);
2318                 fp = NULL;
2319                 return PMINFO_EXTERNAL_STORAGE;
2320         }
2321
2322         return PMINFO_INTERNAL_STORAGE;
2323 }
2324
2325 API int pkgmgrinfo_pkginfo_get_list(pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data)
2326 {
2327         retvm_if(pkg_list_cb == NULL, PMINFO_R_EINVAL, "callback function is NULL\n");
2328         int ret = PMINFO_R_OK;
2329         char query[MAX_QUERY_LEN] = {'\0'};
2330         char *syslocale = NULL;
2331         char *locale = NULL;
2332         pkgmgr_pkginfo_x *pkginfo = NULL;
2333         label_x *tmp1 = NULL;
2334         icon_x *tmp2 = NULL;
2335         description_x *tmp3 = NULL;
2336         author_x *tmp4 = NULL;
2337         privilege_x *tmp5 = NULL;
2338         sqlite3 *pkginfo_db = NULL;
2339
2340         /*open db*/
2341         ret = db_util_open(MANIFEST_DB, &pkginfo_db, 0);
2342         retvm_if(ret != SQLITE_OK, PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
2343
2344         /*get system locale*/
2345         syslocale = vconf_get_str(VCONFKEY_LANGSET);
2346         locale = __convert_system_locale_to_manifest_locale(syslocale);
2347         tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
2348
2349         pkgmgr_pkginfo_x *tmphead = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
2350         pkgmgr_pkginfo_x *node = NULL;
2351         pkgmgr_pkginfo_x *temp_node = NULL;
2352
2353         snprintf(query, MAX_QUERY_LEN, "select * from package_info");
2354         ret = __exec_db_query(pkginfo_db, query, __pkg_list_cb, (void *)tmphead);
2355         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
2356
2357         LISTHEAD(tmphead, node);
2358
2359         for(node = node->next; node ; node = node->next) {
2360                 pkginfo = node;
2361                 pkginfo->locale = strdup(locale);
2362                 pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
2363                 tryvm_if(pkginfo->manifest_info->privileges == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for privileges info\n");
2364
2365                 /*populate manifest_info from DB*/
2366                 snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkginfo->manifest_info->package);
2367                 ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
2368                 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
2369
2370                 memset(query, '\0', MAX_QUERY_LEN);
2371                 /*populate privilege_info from DB*/
2372                 snprintf(query, MAX_QUERY_LEN, "select * from package_privilege_info where package='%s' ", pkginfo->manifest_info->package);
2373                 ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
2374                 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package privilege Info DB Information retrieval failed");
2375
2376                 memset(query, '\0', MAX_QUERY_LEN);
2377                 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
2378                         " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, locale);
2379                 ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
2380                 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
2381
2382                 /*Also store the values corresponding to default locales*/
2383                 memset(query, '\0', MAX_QUERY_LEN);
2384                 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
2385                         " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, DEFAULT_LOCALE);
2386                 ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
2387                 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
2388
2389                 if (pkginfo->manifest_info->label) {
2390                         LISTHEAD(pkginfo->manifest_info->label, tmp1);
2391                         pkginfo->manifest_info->label = tmp1;
2392                 }
2393                 if (pkginfo->manifest_info->icon) {
2394                         LISTHEAD(pkginfo->manifest_info->icon, tmp2);
2395                         pkginfo->manifest_info->icon = tmp2;
2396                 }
2397                 if (pkginfo->manifest_info->description) {
2398                         LISTHEAD(pkginfo->manifest_info->description, tmp3);
2399                         pkginfo->manifest_info->description = tmp3;
2400                 }
2401                 if (pkginfo->manifest_info->author) {
2402                         LISTHEAD(pkginfo->manifest_info->author, tmp4);
2403                         pkginfo->manifest_info->author = tmp4;
2404                 }
2405                 if (pkginfo->manifest_info->privileges->privilege) {
2406                         LISTHEAD(pkginfo->manifest_info->privileges->privilege, tmp5);
2407                         pkginfo->manifest_info->privileges->privilege = tmp5;
2408                 }
2409         }
2410
2411         LISTHEAD(tmphead, node);
2412
2413         for(node = node->next; node ; node = node->next) {
2414                 pkginfo = node;
2415
2416                 ret = __pkginfo_check_installed_storage(pkginfo);
2417                 if(ret < 0)
2418                         continue;
2419
2420                 ret = pkg_list_cb( (void *)pkginfo, user_data);
2421                 if(ret < 0)
2422                         break;
2423         }
2424
2425         ret = PMINFO_R_OK;
2426
2427 catch:
2428         sqlite3_close(pkginfo_db);
2429         if (syslocale) {
2430                 free(syslocale);
2431                 syslocale = NULL;
2432         }
2433         if (locale) {
2434                 free(locale);
2435                 locale = NULL;
2436         }
2437         LISTHEAD(tmphead, node);
2438         temp_node = node->next;
2439         node = temp_node;
2440         while (node) {
2441                 temp_node = node->next;
2442                 __cleanup_pkginfo(node);
2443                 node = temp_node;
2444         }
2445         __cleanup_pkginfo(tmphead);
2446         return ret;
2447 }
2448
2449
2450 API int pkgmgrinfo_pkginfo_get_pkginfo(const char *pkgid, pkgmgrinfo_pkginfo_h *handle)
2451 {
2452         retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "pkgid is NULL\n");
2453         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2454         pkgmgr_pkginfo_x *pkginfo = NULL;
2455         int ret = PMINFO_R_OK;
2456         char query[MAX_QUERY_LEN] = {'\0'};
2457         char *syslocale = NULL;
2458         char *locale = NULL;
2459         int exist = 0;
2460         label_x *tmp1 = NULL;
2461         icon_x *tmp2 = NULL;
2462         description_x *tmp3 = NULL;
2463         author_x *tmp4 = NULL;
2464         privilege_x *tmp5 = NULL;
2465         sqlite3 *pkginfo_db = NULL;
2466
2467         /*validate pkgid*/
2468         ret = db_util_open(MANIFEST_DB, &pkginfo_db, 0);
2469         retvm_if(ret != SQLITE_OK, PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
2470
2471         /*check pkgid exist on db*/
2472         snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_info where package='%s')", pkgid);
2473         ret = __exec_db_query(pkginfo_db, query, __validate_cb, (void *)&exist);
2474         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "sqlite3_exec[%s] fail", pkgid);
2475         tryvm_if(exist == 0, ret = PMINFO_R_ERROR, "pkgid[%s] not found in DB", pkgid);
2476
2477         /*get system locale*/
2478         syslocale = vconf_get_str(VCONFKEY_LANGSET);
2479         locale = __convert_system_locale_to_manifest_locale(syslocale);
2480         tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
2481
2482         pkginfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
2483         tryvm_if(pkginfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for pkginfo");
2484
2485         pkginfo->locale = strdup(locale);
2486
2487         pkginfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
2488         tryvm_if(pkginfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for manifest info");
2489
2490         pkginfo->manifest_info->package = strdup(pkgid);
2491         pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
2492         tryvm_if(pkginfo->manifest_info->privileges == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for privileges info");
2493
2494         /*populate manifest_info from DB*/
2495         snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkgid);
2496         ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
2497         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
2498
2499         memset(query, '\0', MAX_QUERY_LEN);
2500         /*populate privilege_info from DB*/
2501         snprintf(query, MAX_QUERY_LEN, "select * from package_privilege_info where package='%s' ", pkgid);
2502         ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
2503         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Privilege Info DB Information retrieval failed");
2504
2505         memset(query, '\0', MAX_QUERY_LEN);
2506         snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
2507                 " package='%s' and package_locale='%s'", pkgid, locale);
2508         ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
2509         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
2510
2511         /*Also store the values corresponding to default locales*/
2512         memset(query, '\0', MAX_QUERY_LEN);
2513         snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
2514                 " package='%s' and package_locale='%s'", pkgid, DEFAULT_LOCALE);
2515         ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
2516         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
2517
2518         if (pkginfo->manifest_info->label) {
2519                 LISTHEAD(pkginfo->manifest_info->label, tmp1);
2520                 pkginfo->manifest_info->label = tmp1;
2521         }
2522         if (pkginfo->manifest_info->icon) {
2523                 LISTHEAD(pkginfo->manifest_info->icon, tmp2);
2524                 pkginfo->manifest_info->icon = tmp2;
2525         }
2526         if (pkginfo->manifest_info->description) {
2527                 LISTHEAD(pkginfo->manifest_info->description, tmp3);
2528                 pkginfo->manifest_info->description = tmp3;
2529         }
2530         if (pkginfo->manifest_info->author) {
2531                 LISTHEAD(pkginfo->manifest_info->author, tmp4);
2532                 pkginfo->manifest_info->author = tmp4;
2533         }
2534         if (pkginfo->manifest_info->privileges->privilege) {
2535                 LISTHEAD(pkginfo->manifest_info->privileges->privilege, tmp5);
2536                 pkginfo->manifest_info->privileges->privilege = tmp5;
2537         }
2538
2539         ret = __pkginfo_check_installed_storage(pkginfo);
2540         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "[%s] is installed external, but is not in mmc", pkgid);
2541
2542 catch:
2543         if (ret == PMINFO_R_OK)
2544                 *handle = (void*)pkginfo;
2545         else {
2546                 *handle = NULL;
2547                 __cleanup_pkginfo(pkginfo);
2548         }
2549         sqlite3_close(pkginfo_db);
2550
2551         if (syslocale) {
2552                 free(syslocale);
2553                 syslocale = NULL;
2554         }
2555         if (locale) {
2556                 free(locale);
2557                 locale = NULL;
2558         }
2559         return ret;
2560 }
2561
2562
2563 API int pkgmgrinfo_pkginfo_get_pkgname(pkgmgrinfo_pkginfo_h handle, char **pkg_name)
2564 {
2565         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2566         retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2567         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2568         if (info->manifest_info->package)
2569                 *pkg_name = (char *)info->manifest_info->package;
2570         else
2571                 return PMINFO_R_ERROR;
2572
2573         return PMINFO_R_OK;
2574 }
2575
2576 API int pkgmgrinfo_pkginfo_get_pkgid(pkgmgrinfo_pkginfo_h handle, char **pkgid)
2577 {
2578         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2579         retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2580         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2581         if (info->manifest_info->package)
2582                 *pkgid = (char *)info->manifest_info->package;
2583         else
2584                 return PMINFO_R_ERROR;
2585
2586         return PMINFO_R_OK;
2587 }
2588
2589 API int pkgmgrinfo_pkginfo_get_type(pkgmgrinfo_pkginfo_h handle, char **type)
2590 {
2591         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2592         retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2593         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2594         if (info->manifest_info->type)
2595                 *type = (char *)info->manifest_info->type;
2596         else
2597                 *type = pkgtype;
2598         return PMINFO_R_OK;
2599 }
2600
2601 API int pkgmgrinfo_pkginfo_get_version(pkgmgrinfo_pkginfo_h handle, char **version)
2602 {
2603         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2604         retvm_if(version == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2605         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2606         *version = (char *)info->manifest_info->version;
2607         return PMINFO_R_OK;
2608 }
2609
2610 API int pkgmgrinfo_pkginfo_get_install_location(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_install_location *location)
2611 {
2612         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2613         retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2614         char *val = NULL;
2615         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2616         val = (char *)info->manifest_info->installlocation;
2617         if (val) {
2618                 if (strcmp(val, "internal-only") == 0)
2619                         *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
2620                 else if (strcmp(val, "prefer-external") == 0)
2621                         *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
2622                 else
2623                         *location = PMINFO_INSTALL_LOCATION_AUTO;
2624         }
2625         return PMINFO_R_OK;
2626 }
2627
2628 API int pkgmgrinfo_pkginfo_get_package_size(pkgmgrinfo_pkginfo_h handle, int *size)
2629 {
2630         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2631         retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2632         char *val = NULL;
2633         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2634         val = (char *)info->manifest_info->package_size;
2635         if (val) {
2636                 *size = atoi(val);
2637         } else {
2638                 *size = 0;
2639                 _LOGE("package size is not specified\n");
2640                 return PMINFO_R_ERROR;
2641         }
2642         return PMINFO_R_OK;
2643 }
2644
2645 API int pkgmgrinfo_pkginfo_get_total_size(pkgmgrinfo_pkginfo_h handle, int *size)
2646 {
2647         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2648         retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2649
2650         int ret = -1;
2651         char *pkgid = NULL;
2652         char *val = NULL;
2653
2654         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2655         val = (char *)info->manifest_info->package_size;
2656         if (strcmp(val, "true") == 0) {
2657                 *size = atoi(info->manifest_info->package_total_size);
2658                 return 0;
2659         } else {
2660                 *size = 0;
2661                 return 0;
2662         }
2663 }
2664
2665 API int pkgmgrinfo_pkginfo_get_data_size(pkgmgrinfo_pkginfo_h handle, int *size)
2666 {
2667         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2668         retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2669
2670         int ret = -1;
2671         char *pkgid = NULL;
2672         char *val = NULL;
2673
2674         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2675         val = (char *)info->manifest_info->package_size;
2676         if (strcmp(val, "true") == 0) {
2677                 *size = atoi(info->manifest_info->package_data_size);
2678                 return 0;
2679         } else {
2680                 *size = 0;
2681                 return 0;
2682         }
2683 }
2684
2685 API int pkgmgrinfo_pkginfo_get_size_info(pkgmgrinfo_pkginfo_h handle, int *total_size, int *data_size)
2686 {
2687         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2688         retvm_if(total_size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2689         retvm_if(data_size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2690
2691         int ret = -1;
2692         int total_tmp = 0;
2693         int data_tmp = 0;
2694         char *val = NULL;
2695         char *pkgid = NULL;
2696         char* package_size_info = NULL;
2697
2698         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2699
2700         val = (char *)info->manifest_info->package_size;
2701         if (strcmp(val, "true") == 0) {
2702                 *total_size = atoi(info->manifest_info->package_total_size);
2703                 *data_size = atoi(info->manifest_info->package_data_size);
2704                 return 0;
2705         } else {
2706                 *total_size = 0;
2707                 *data_size = 0;
2708
2709                 return 0;
2710         }
2711         return -1;
2712 }
2713
2714 API int pkgmgrinfo_pkginfo_get_icon(pkgmgrinfo_pkginfo_h handle, char **icon)
2715 {
2716         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
2717         retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2718         int ret = PMINFO_R_OK;
2719         char *locale = NULL;
2720         icon_x *ptr = NULL;
2721         *icon = NULL;
2722
2723         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2724
2725         locale = info->locale;
2726         retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
2727
2728         for(ptr = info->manifest_info->icon; ptr != NULL; ptr = ptr->next)
2729         {
2730                 if (ptr->lang) {
2731                         if (strcmp(ptr->lang, locale) == 0) {
2732                                 *icon = (char *)ptr->text;
2733                                 if (strcasecmp(*icon, "(null)") == 0) {
2734                                         locale = DEFAULT_LOCALE;
2735                                         continue;
2736                                 } else
2737                                         break;
2738                         } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
2739                                 *icon = (char *)ptr->text;
2740                                 break;
2741                         }
2742                 }
2743         }
2744
2745         return ret;
2746 }
2747
2748 API int pkgmgrinfo_pkginfo_get_label(pkgmgrinfo_pkginfo_h handle, char **label)
2749 {
2750         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
2751         retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2752         int ret = PMINFO_R_OK;
2753         char *locale = NULL;
2754         label_x *ptr = NULL;
2755         *label = NULL;
2756
2757         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2758         locale = info->locale;
2759         retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
2760
2761         for(ptr = info->manifest_info->label; ptr != NULL; ptr = ptr->next)
2762         {
2763                 if (ptr->lang) {
2764                         if (strcmp(ptr->lang, locale) == 0) {
2765                                 *label = (char *)ptr->text;
2766                                 if (strcasecmp(*label, "(null)") == 0) {
2767                                         locale = DEFAULT_LOCALE;
2768                                         continue;
2769                                 } else
2770                                         break;
2771                         } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
2772                                 *label = (char *)ptr->text;
2773                                 break;
2774                         }
2775                 }
2776         }
2777
2778         return ret;
2779 }
2780
2781 API int pkgmgrinfo_pkginfo_get_description(pkgmgrinfo_pkginfo_h handle, char **description)
2782 {
2783         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2784         retvm_if(description == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2785         char *locale = NULL;
2786         description_x *ptr = NULL;
2787         *description = NULL;
2788
2789         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2790         locale = info->locale;
2791         retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
2792
2793         for(ptr = info->manifest_info->description; ptr != NULL; ptr = ptr->next)
2794         {
2795                 if (ptr->lang) {
2796                         if (strcmp(ptr->lang, locale) == 0) {
2797                                 *description = (char *)ptr->text;
2798                                 if (strcasecmp(*description, PKGMGR_PARSER_EMPTY_STR) == 0) {
2799                                         locale = DEFAULT_LOCALE;
2800                                         continue;
2801                                 } else
2802                                         break;
2803                         } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
2804                                 *description = (char *)ptr->text;
2805                                 break;
2806                         }
2807                 }
2808         }
2809         return PMINFO_R_OK;
2810 }
2811
2812 API int pkgmgrinfo_pkginfo_get_author_name(pkgmgrinfo_pkginfo_h handle, char **author_name)
2813 {
2814         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2815         retvm_if(author_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2816         char *locale = NULL;
2817         author_x *ptr = NULL;
2818         *author_name = NULL;
2819
2820         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2821         locale = info->locale;
2822         retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
2823
2824         for(ptr = info->manifest_info->author; ptr != NULL; ptr = ptr->next)
2825         {
2826                 if (ptr->lang) {
2827                         if (strcmp(ptr->lang, locale) == 0) {
2828                                 *author_name = (char *)ptr->text;
2829                                 if (strcasecmp(*author_name, PKGMGR_PARSER_EMPTY_STR) == 0) {
2830                                         locale = DEFAULT_LOCALE;
2831                                         continue;
2832                                 } else
2833                                         break;
2834                         } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
2835                                 *author_name = (char *)ptr->text;
2836                                 break;
2837                         }
2838                 }
2839         }
2840         return PMINFO_R_OK;
2841 }
2842
2843 API int pkgmgrinfo_pkginfo_get_author_email(pkgmgrinfo_pkginfo_h handle, char **author_email)
2844 {
2845         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2846         retvm_if(author_email == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2847         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2848         *author_email = (char *)info->manifest_info->author->email;
2849         return PMINFO_R_OK;
2850 }
2851
2852 API int pkgmgrinfo_pkginfo_get_author_href(pkgmgrinfo_pkginfo_h handle, char **author_href)
2853 {
2854         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2855         retvm_if(author_href == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2856         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2857         *author_href = (char *)info->manifest_info->author->href;
2858         return PMINFO_R_OK;
2859 }
2860
2861 API int pkgmgrinfo_pkginfo_get_installed_storage(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_installed_storage *storage)
2862 {
2863         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2864         retvm_if(storage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2865
2866         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2867
2868          if (strcmp(info->manifest_info->installed_storage,"installed_internal") == 0)
2869                 *storage = PMINFO_INTERNAL_STORAGE;
2870          else if (strcmp(info->manifest_info->installed_storage,"installed_external") == 0)
2871                  *storage = PMINFO_EXTERNAL_STORAGE;
2872          else
2873                  return PMINFO_R_ERROR;
2874
2875         return PMINFO_R_OK;
2876 }
2877
2878 API int pkgmgrinfo_pkginfo_get_installed_time(pkgmgrinfo_pkginfo_h handle, int *installed_time)
2879 {
2880         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2881         retvm_if(installed_time == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2882         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2883         if (info->manifest_info->installed_time)
2884                 *installed_time = atoi(info->manifest_info->installed_time);
2885         else
2886                 return PMINFO_R_ERROR;
2887
2888         return PMINFO_R_OK;
2889 }
2890
2891 API int pkgmgrinfo_pkginfo_get_storeclientid(pkgmgrinfo_pkginfo_h handle, char **storeclientid)
2892 {
2893         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2894         retvm_if(storeclientid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2895         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2896         *storeclientid = (char *)info->manifest_info->storeclient_id;
2897         return PMINFO_R_OK;
2898 }
2899
2900 API int pkgmgrinfo_pkginfo_get_mainappid(pkgmgrinfo_pkginfo_h handle, char **mainappid)
2901 {
2902         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2903         retvm_if(mainappid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2904         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2905         *mainappid = (char *)info->manifest_info->mainapp_id;
2906         return PMINFO_R_OK;
2907 }
2908
2909 API int pkgmgrinfo_pkginfo_get_url(pkgmgrinfo_pkginfo_h handle, char **url)
2910 {
2911         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2912         retvm_if(url == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2913         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2914         *url = (char *)info->manifest_info->package_url;
2915         return PMINFO_R_OK;
2916 }
2917
2918 API int pkgmgrinfo_pkginfo_get_size_from_xml(const char *manifest, int *size)
2919 {
2920         const char *val = NULL;
2921         const xmlChar *node;
2922         xmlTextReaderPtr reader;
2923         retvm_if(manifest == NULL, PMINFO_R_EINVAL, "Input argument is NULL\n");
2924         retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2925
2926         xmlInitParser();
2927         reader = xmlReaderForFile(manifest, NULL, 0);
2928
2929         if (reader){
2930                 if (__child_element(reader, -1)) {
2931                         node = xmlTextReaderConstName(reader);
2932                         if (!node) {
2933                                 _LOGE("xmlTextReaderConstName value is NULL\n");
2934                                 xmlFreeTextReader(reader);
2935                                 xmlCleanupParser();
2936                                 return PMINFO_R_ERROR;
2937                         }
2938
2939                         if (!strcmp(ASC_CHAR(node), "manifest")) {
2940                                 if (xmlTextReaderGetAttribute(reader, XML_CHAR("size")))
2941                                         val = ASC_CHAR(xmlTextReaderGetAttribute(reader, XML_CHAR("size")));
2942
2943                                 if (val) {
2944                                         *size = atoi(val);
2945                                 } else {
2946                                         *size = 0;
2947                                         _LOGE("package size is not specified\n");
2948                                         xmlFreeTextReader(reader);
2949                                         xmlCleanupParser();
2950                                         return PMINFO_R_ERROR;
2951                                 }
2952                         } else {
2953                                 _LOGE("Unable to create xml reader\n");
2954                                 xmlFreeTextReader(reader);
2955                                 xmlCleanupParser();
2956                                 return PMINFO_R_ERROR;
2957                         }
2958                 }
2959         } else {
2960                 _LOGE("xmlReaderForFile value is NULL\n");
2961                 xmlCleanupParser();
2962                 return PMINFO_R_ERROR;
2963         }
2964
2965         xmlFreeTextReader(reader);
2966         xmlCleanupParser();
2967
2968         return PMINFO_R_OK;
2969 }
2970
2971 API int pkgmgrinfo_pkginfo_get_location_from_xml(const char *manifest, pkgmgrinfo_install_location *location)
2972 {
2973         const char *val = NULL;
2974         const xmlChar *node;
2975         xmlTextReaderPtr reader;
2976         retvm_if(manifest == NULL, PMINFO_R_EINVAL, "Input argument is NULL\n");
2977         retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2978
2979         xmlInitParser();
2980         reader = xmlReaderForFile(manifest, NULL, 0);
2981
2982         if (reader){
2983                 if ( __child_element(reader, -1)) {
2984                         node = xmlTextReaderConstName(reader);
2985                         if (!node) {
2986                                 _LOGE("xmlTextReaderConstName value is NULL\n");
2987                                 xmlFreeTextReader(reader);
2988                                 xmlCleanupParser();
2989                                 return PMINFO_R_ERROR;
2990                         }
2991
2992                         if (!strcmp(ASC_CHAR(node), "manifest")) {
2993                                 if (xmlTextReaderGetAttribute(reader, XML_CHAR("install-location")))
2994                                         val = ASC_CHAR(xmlTextReaderGetAttribute(reader, XML_CHAR("install-location")));
2995
2996                                 if (val) {
2997                                         if (strcmp(val, "internal-only") == 0)
2998                                                 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
2999                                         else if (strcmp(val, "prefer-external") == 0)
3000                                                 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
3001                                         else
3002                                                 *location = PMINFO_INSTALL_LOCATION_AUTO;
3003                                 }
3004                         } else {
3005                                 _LOGE("Unable to create xml reader\n");
3006                                 xmlFreeTextReader(reader);
3007                                 xmlCleanupParser();
3008                                 return PMINFO_R_ERROR;
3009                         }
3010                 }
3011         } else {
3012                 _LOGE("xmlReaderForFile value is NULL\n");
3013                 xmlCleanupParser();
3014                 return PMINFO_R_ERROR;
3015         }
3016
3017         xmlFreeTextReader(reader);
3018         xmlCleanupParser();
3019
3020         return PMINFO_R_OK;
3021 }
3022
3023
3024 API int pkgmgrinfo_pkginfo_get_root_path(pkgmgrinfo_pkginfo_h handle, char **path)
3025 {
3026         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3027         retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3028
3029         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3030         if (info->manifest_info->root_path)
3031                 *path = (char *)info->manifest_info->root_path;
3032         else
3033                 return PMINFO_R_ERROR;
3034
3035         return PMINFO_R_OK;
3036 }
3037
3038 API int pkgmgrinfo_pkginfo_get_csc_path(pkgmgrinfo_pkginfo_h handle, char **path)
3039 {
3040         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3041         retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3042
3043         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3044         if (info->manifest_info->csc_path)
3045                 *path = (char *)info->manifest_info->csc_path;
3046         else
3047                 *path = (char *)info->manifest_info->csc_path;
3048
3049         return PMINFO_R_OK;
3050 }
3051
3052 API int pkgmgrinfo_pkginfo_compare_pkg_cert_info(const char *lhs_package_id, const char *rhs_package_id, pkgmgrinfo_cert_compare_result_type_e *compare_result)
3053 {
3054         retvm_if(lhs_package_id == NULL, PMINFO_R_EINVAL, "lhs package ID is NULL");
3055         retvm_if(rhs_package_id == NULL, PMINFO_R_EINVAL, "rhs package ID is NULL");
3056         retvm_if(compare_result == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3057
3058         int ret = PMINFO_R_OK;
3059         char query[MAX_QUERY_LEN] = {'\0'};
3060         char *error_message = NULL;
3061         pkgmgr_cert_x *info= NULL;
3062         int lcert = 0;
3063         int rcert = 0;
3064         int exist = -1;
3065         *compare_result = PMINFO_CERT_COMPARE_ERROR;
3066         info = (pkgmgr_cert_x *)calloc(1, sizeof(pkgmgr_cert_x));
3067         retvm_if(info == NULL, PMINFO_R_ERROR, "Out of Memory!!!");
3068
3069         ret = db_util_open_with_options(CERT_DB, &cert_db, SQLITE_OPEN_READONLY, NULL);
3070         if (ret != SQLITE_OK) {
3071                 _LOGE("connect db [%s] failed!\n", CERT_DB);
3072                 ret = PMINFO_R_ERROR;
3073                 goto err;
3074         }
3075
3076         snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", lhs_package_id);
3077         if (SQLITE_OK !=
3078             sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
3079                 _LOGE("Don't execute query = %s error message = %s\n", query,
3080                        error_message);
3081                 ret = PMINFO_R_ERROR;
3082                 goto err;
3083         }
3084
3085         if (exist == 0) {
3086                 lcert = 0;
3087         } else {
3088                 snprintf(query, MAX_QUERY_LEN, "select author_signer_cert from package_cert_info where package='%s'", lhs_package_id);
3089                 if (SQLITE_OK !=
3090                         sqlite3_exec(cert_db, query, __cert_cb, (void *)info, &error_message)) {
3091                         _LOGE("Don't execute query = %s error message = %s\n", query,
3092                                    error_message);
3093                         ret = PMINFO_R_ERROR;
3094                         goto err;
3095                 }
3096                 lcert = info->cert_id;
3097         }
3098
3099         snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", rhs_package_id);
3100         if (SQLITE_OK !=
3101                 sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
3102                 _LOGE("Don't execute query = %s error message = %s\n", query,
3103                            error_message);
3104                 ret = PMINFO_R_ERROR;
3105                 goto err;
3106         }
3107
3108         if (exist == 0) {
3109                 rcert = 0;
3110         } else {
3111                 snprintf(query, MAX_QUERY_LEN, "select author_signer_cert from package_cert_info where package='%s'", rhs_package_id);
3112                 if (SQLITE_OK !=
3113                         sqlite3_exec(cert_db, query, __cert_cb, (void *)info, &error_message)) {
3114                         _LOGE("Don't execute query = %s error message = %s\n", query,
3115                                    error_message);
3116                         ret = PMINFO_R_ERROR;
3117                         goto err;
3118                 }
3119                 rcert = info->cert_id;
3120         }
3121
3122         if ((lcert == 0) || (rcert == 0))
3123         {
3124                 if ((lcert == 0) && (rcert == 0))
3125                         *compare_result = PMINFO_CERT_COMPARE_BOTH_NO_CERT;
3126                 else if (lcert == 0)
3127                         *compare_result = PMINFO_CERT_COMPARE_LHS_NO_CERT;
3128                 else if (rcert == 0)
3129                         *compare_result = PMINFO_CERT_COMPARE_RHS_NO_CERT;
3130         } else {
3131                 if (lcert == rcert)
3132                         *compare_result = PMINFO_CERT_COMPARE_MATCH;
3133                 else
3134                         *compare_result = PMINFO_CERT_COMPARE_MISMATCH;
3135         }
3136
3137 err:
3138         sqlite3_free(error_message);
3139         sqlite3_close(cert_db);
3140         if (info) {
3141                 if (info->pkgid) {
3142                         free(info->pkgid);
3143                         info->pkgid = NULL;
3144                 }
3145                 free(info);
3146                 info = NULL;
3147         }
3148         return ret;
3149 }
3150
3151
3152 API int pkgmgrinfo_pkginfo_compare_app_cert_info(const char *lhs_app_id, const char *rhs_app_id, pkgmgrinfo_cert_compare_result_type_e *compare_result)
3153 {
3154         retvm_if(lhs_app_id == NULL, PMINFO_R_EINVAL, "lhs app ID is NULL");
3155         retvm_if(rhs_app_id == NULL, PMINFO_R_EINVAL, "rhs app ID is NULL");
3156         retvm_if(compare_result == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3157
3158         int ret = PMINFO_R_OK;
3159         char query[MAX_QUERY_LEN] = {'\0'};
3160         char *error_message = NULL;
3161         pkgmgr_cert_x *info= NULL;
3162         int exist = -1;
3163         char *lpkgid = NULL;
3164         char *rpkgid = NULL;
3165         sqlite3 *pkginfo_db = NULL;
3166
3167         info = (pkgmgr_cert_x *)calloc(1, sizeof(pkgmgr_cert_x));
3168         retvm_if(info == NULL, PMINFO_R_ERROR, "Out of Memory!!!");
3169
3170         ret = db_util_open(MANIFEST_DB, &pkginfo_db, 0);
3171         tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
3172
3173         snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", lhs_app_id);
3174         if (SQLITE_OK !=
3175             sqlite3_exec(pkginfo_db, query, __validate_cb, (void *)&exist, &error_message)) {
3176                 _LOGE("Don't execute query = %s error message = %s\n", query,
3177                        error_message);
3178                 ret = PMINFO_R_ERROR;
3179                 goto catch;
3180         }
3181
3182         if (exist == 0) {
3183                 lpkgid = NULL;
3184         } else {
3185                 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", lhs_app_id);
3186                 if (SQLITE_OK !=
3187                         sqlite3_exec(pkginfo_db, query, __cert_cb, (void *)info, &error_message)) {
3188                         _LOGE("Don't execute query = %s error message = %s\n", query,
3189                                    error_message);
3190                         ret = PMINFO_R_ERROR;
3191                         goto catch;
3192                 }
3193                 lpkgid = strdup(info->pkgid);
3194                 if (lpkgid == NULL) {
3195                         _LOGE("Out of Memory\n");
3196                         ret = PMINFO_R_ERROR;
3197                         goto catch;
3198                 }
3199                 free(info->pkgid);
3200                 info->pkgid = NULL;
3201         }
3202
3203         snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", rhs_app_id);
3204         if (SQLITE_OK !=
3205             sqlite3_exec(pkginfo_db, query, __validate_cb, (void *)&exist, &error_message)) {
3206                 _LOGE("Don't execute query = %s error message = %s\n", query,
3207                        error_message);
3208                 ret = PMINFO_R_ERROR;
3209                 goto catch;
3210         }
3211
3212         if (exist == 0) {
3213                 rpkgid = NULL;
3214         } else {
3215                 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", rhs_app_id);
3216                 if (SQLITE_OK !=
3217                         sqlite3_exec(pkginfo_db, query, __cert_cb, (void *)info, &error_message)) {
3218                         _LOGE("Don't execute query = %s error message = %s\n", query,
3219                                    error_message);
3220                         ret = PMINFO_R_ERROR;
3221                         goto catch;
3222                 }
3223                 rpkgid = strdup(info->pkgid);
3224                 if (rpkgid == NULL) {
3225                         _LOGE("Out of Memory\n");
3226                         ret = PMINFO_R_ERROR;
3227                         goto catch;
3228                 }
3229                 free(info->pkgid);
3230                 info->pkgid = NULL;
3231         }
3232         ret = pkgmgrinfo_pkginfo_compare_pkg_cert_info(lpkgid, rpkgid, compare_result);
3233
3234  catch:
3235         sqlite3_free(error_message);
3236         sqlite3_close(pkginfo_db);
3237         if (info) {
3238                 if (info->pkgid) {
3239                         free(info->pkgid);
3240                         info->pkgid = NULL;
3241                 }
3242                 free(info);
3243                 info = NULL;
3244         }
3245         if (lpkgid) {
3246                 free(lpkgid);
3247                 lpkgid = NULL;
3248         }
3249         if (rpkgid) {
3250                 free(rpkgid);
3251                 rpkgid = NULL;
3252         }
3253         return ret;
3254 }
3255
3256 API int pkgmgrinfo_pkginfo_is_accessible(pkgmgrinfo_pkginfo_h handle, bool *accessible)
3257 {
3258         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3259         retvm_if(accessible == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3260
3261 #if 0 //smack issue occured, check later
3262         char *pkgid = NULL;
3263         pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
3264         if (pkgid == NULL){
3265                  _LOGD("invalid func parameters\n");
3266                  return PMINFO_R_ERROR;
3267         }
3268          _LOGD("pkgmgr_get_pkg_external_validation() called\n");
3269
3270         FILE *fp = NULL;
3271         char app_mmc_path[FILENAME_MAX] = { 0, };
3272         char app_dir_path[FILENAME_MAX] = { 0, };
3273         char app_mmc_internal_path[FILENAME_MAX] = { 0, };
3274         snprintf(app_dir_path, FILENAME_MAX,"%s%s", PKG_INSTALLATION_PATH, pkgid);
3275         snprintf(app_mmc_path, FILENAME_MAX,"%s%s", PKG_SD_PATH, pkgid);
3276         snprintf(app_mmc_internal_path, FILENAME_MAX,"%s%s/.mmc", PKG_INSTALLATION_PATH, pkgid);
3277
3278         /*check whether application is in external memory or not */
3279         fp = fopen(app_mmc_path, "r");
3280         if (fp == NULL){
3281                 _LOGD(" app path in external memory not accesible\n");
3282         } else {
3283                 fclose(fp);
3284                 fp = NULL;
3285                 *accessible = 1;
3286                 _LOGD("pkgmgr_get_pkg_external_validation() : SD_CARD \n");
3287                 return PMINFO_R_OK;
3288         }
3289
3290         /*check whether application is in internal or not */
3291         fp = fopen(app_dir_path, "r");
3292         if (fp == NULL) {
3293                 _LOGD(" app path in internal memory not accesible\n");
3294                 *accessible = 0;
3295                 return PMINFO_R_ERROR;
3296         } else {
3297                 fclose(fp);
3298                 /*check whether the application is installed in SD card
3299                 but SD card is not present*/
3300                 fp = fopen(app_mmc_internal_path, "r");
3301                 if (fp == NULL){
3302                         *accessible = 1;
3303                         _LOGD("pkgmgr_get_pkg_external_validation() : INTERNAL_MEM \n");
3304                         return PMINFO_R_OK;
3305                 }
3306                 else{
3307                         *accessible = 0;
3308                         _LOGD("pkgmgr_get_pkg_external_validation() : ERROR_MMC_STATUS \n");
3309                 }
3310                 fclose(fp);
3311         }
3312
3313         _LOGD("pkgmgr_get_pkg_external_validation() end\n");
3314 #endif
3315
3316         *accessible = 1;
3317         return PMINFO_R_OK;
3318 }
3319
3320 API int pkgmgrinfo_pkginfo_is_removable(pkgmgrinfo_pkginfo_h handle, bool *removable)
3321 {
3322         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3323         retvm_if(removable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3324         char *val = NULL;
3325         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3326         val = (char *)info->manifest_info->removable;
3327         if (val) {
3328                 if (strcasecmp(val, "true") == 0)
3329                         *removable = 1;
3330                 else if (strcasecmp(val, "false") == 0)
3331                         *removable = 0;
3332                 else
3333                         *removable = 1;
3334         }
3335         return PMINFO_R_OK;
3336 }
3337
3338 API int pkgmgrinfo_pkginfo_is_movable(pkgmgrinfo_pkginfo_h handle, bool *movable)
3339 {
3340         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3341         retvm_if(movable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3342
3343         char *val = NULL;
3344         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3345
3346         val = (char *)info->manifest_info->installlocation;
3347         if (val) {
3348                 if (strcmp(val, "internal-only") == 0)
3349                         *movable = 0;
3350                 else if (strcmp(val, "prefer-external") == 0)
3351                         *movable = 1;
3352                 else
3353                         *movable = 1;
3354         }
3355
3356         return PMINFO_R_OK;
3357 }
3358
3359 API int pkgmgrinfo_pkginfo_is_preload(pkgmgrinfo_pkginfo_h handle, bool *preload)
3360 {
3361         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3362         retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3363         char *val = NULL;
3364         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3365         val = (char *)info->manifest_info->preload;
3366         if (val) {
3367                 if (strcasecmp(val, "true") == 0)
3368                         *preload = 1;
3369                 else if (strcasecmp(val, "false") == 0)
3370                         *preload = 0;
3371                 else
3372                         *preload = 0;
3373         }
3374         return PMINFO_R_OK;
3375 }
3376
3377 API int pkgmgrinfo_pkginfo_is_system(pkgmgrinfo_pkginfo_h handle, bool *system)
3378 {
3379         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3380         retvm_if(system == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3381
3382         char *val = NULL;
3383         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3384         val = (char *)info->manifest_info->system;
3385         if (val) {
3386                 if (strcasecmp(val, "true") == 0)
3387                         *system = 1;
3388                 else if (strcasecmp(val, "false") == 0)
3389                         *system = 0;
3390                 else
3391                         *system = 0;
3392         }
3393
3394         return PMINFO_R_OK;
3395 }
3396
3397 API int pkgmgrinfo_pkginfo_is_readonly(pkgmgrinfo_pkginfo_h handle, bool *readonly)
3398 {
3399         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3400         retvm_if(readonly == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3401         char *val = NULL;
3402         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3403         val = (char *)info->manifest_info->readonly;
3404         if (val) {
3405                 if (strcasecmp(val, "true") == 0)
3406                         *readonly = 1;
3407                 else if (strcasecmp(val, "false") == 0)
3408                         *readonly = 0;
3409                 else
3410                         *readonly = 0;
3411         }
3412         return PMINFO_R_OK;
3413 }
3414
3415 API int pkgmgrinfo_pkginfo_is_update(pkgmgrinfo_pkginfo_h handle, bool *update)
3416 {
3417         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3418         retvm_if(update == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3419
3420         char *val = NULL;
3421         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3422         val = (char *)info->manifest_info->update;
3423         if (val) {
3424                 if (strcasecmp(val, "true") == 0)
3425                         *update = 1;
3426                 else if (strcasecmp(val, "false") == 0)
3427                         *update = 0;
3428                 else
3429                         *update = 1;
3430         }
3431         return PMINFO_R_OK;
3432 }
3433
3434 API int pkgmgrinfo_pkginfo_destroy_pkginfo(pkgmgrinfo_pkginfo_h handle)
3435 {
3436         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3437         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3438         __cleanup_pkginfo(info);
3439         return PMINFO_R_OK;
3440 }
3441
3442 API int pkgmgrinfo_pkginfo_filter_create(pkgmgrinfo_pkginfo_filter_h *handle)
3443 {
3444         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle output parameter is NULL\n");
3445         *handle = NULL;
3446         pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)calloc(1, sizeof(pkgmgrinfo_filter_x));
3447         if (filter == NULL) {
3448                 _LOGE("Out of Memory!!!");
3449                 return PMINFO_R_ERROR;
3450         }
3451         *handle = filter;
3452         return PMINFO_R_OK;
3453 }
3454
3455 API int pkgmgrinfo_pkginfo_filter_destroy(pkgmgrinfo_pkginfo_filter_h handle)
3456 {
3457         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3458         pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3459         if (filter->list){
3460                 g_slist_foreach(filter->list, __destroy_each_node, NULL);
3461                 g_slist_free(filter->list);
3462         }
3463         free(filter);
3464         filter = NULL;
3465
3466         if (access(PKG_SIZE_INFO_FILE, F_OK) == 0) {
3467                 char info_file[PKG_VALUE_STRING_LEN_MAX] = { 0, };
3468                 snprintf(info_file, PKG_VALUE_STRING_LEN_MAX, "%s", PKG_SIZE_INFO_FILE);
3469                 remove(info_file);
3470         }
3471
3472         return PMINFO_R_OK;
3473 }
3474
3475 API int pkgmgrinfo_pkginfo_filter_add_int(pkgmgrinfo_pkginfo_filter_h handle,
3476                                 const char *property, const int value)
3477 {
3478         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3479         retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3480         char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
3481         char *val = NULL;
3482         GSList *link = NULL;
3483         int prop = -1;
3484         prop = _pminfo_pkginfo_convert_to_prop_int(property);
3485         if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_INT ||
3486                 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_INT) {
3487                 _LOGE("Invalid Integer Property\n");
3488                 return PMINFO_R_EINVAL;
3489         }
3490         pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3491         pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
3492         if (node == NULL) {
3493                 _LOGE("Out of Memory!!!\n");
3494                 return PMINFO_R_ERROR;
3495         }
3496         snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
3497         val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
3498         if (val == NULL) {
3499                 _LOGE("Out of Memory\n");
3500                 free(node);
3501                 node = NULL;
3502                 return PMINFO_R_ERROR;
3503         }
3504         node->prop = prop;
3505         node->value = val;
3506         /*If API is called multiple times for same property, we should override the previous values.
3507         Last value set will be used for filtering.*/
3508         link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
3509         if (link)
3510                 filter->list = g_slist_delete_link(filter->list, link);
3511         filter->list = g_slist_append(filter->list, (gpointer)node);
3512         return PMINFO_R_OK;
3513
3514 }
3515
3516 API int pkgmgrinfo_pkginfo_filter_add_bool(pkgmgrinfo_pkginfo_filter_h handle,
3517                                 const char *property, const bool value)
3518 {
3519         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3520         retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3521         char *val = NULL;
3522         GSList *link = NULL;
3523         int prop = -1;
3524         prop = _pminfo_pkginfo_convert_to_prop_bool(property);
3525         if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_BOOL ||
3526                 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_BOOL) {
3527                 _LOGE("Invalid Boolean Property\n");
3528                 return PMINFO_R_EINVAL;
3529         }
3530         pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3531         pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
3532         if (node == NULL) {
3533                 _LOGE("Out of Memory!!!\n");
3534                 return PMINFO_R_ERROR;
3535         }
3536         if (value)
3537                 val = strndup("('true','True')", 15);
3538         else
3539                 val = strndup("('false','False')", 17);
3540         if (val == NULL) {
3541                 _LOGE("Out of Memory\n");
3542                 free(node);
3543                 node = NULL;
3544                 return PMINFO_R_ERROR;
3545         }
3546         node->prop = prop;
3547         node->value = val;
3548         /*If API is called multiple times for same property, we should override the previous values.
3549         Last value set will be used for filtering.*/
3550         link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
3551         if (link)
3552                 filter->list = g_slist_delete_link(filter->list, link);
3553         filter->list = g_slist_append(filter->list, (gpointer)node);
3554         return PMINFO_R_OK;
3555
3556 }
3557
3558 API int pkgmgrinfo_pkginfo_filter_add_string(pkgmgrinfo_pkginfo_filter_h handle,
3559                                 const char *property, const char *value)
3560 {
3561         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3562         retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3563         retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3564         char *val = NULL;
3565         GSList *link = NULL;
3566         int prop = -1;
3567         prop = _pminfo_pkginfo_convert_to_prop_str(property);
3568         if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_STR ||
3569                 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_STR) {
3570                 _LOGE("Invalid String Property\n");
3571                 return PMINFO_R_EINVAL;
3572         }
3573         pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3574         pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
3575         if (node == NULL) {
3576                 _LOGE("Out of Memory!!!\n");
3577                 return PMINFO_R_ERROR;
3578         }
3579         if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_AUTO) == 0)
3580                 val = strndup("auto", PKG_STRING_LEN_MAX - 1);
3581         else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_INTERNAL) == 0)
3582                 val = strndup("internal-only", PKG_STRING_LEN_MAX - 1);
3583         else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_EXTERNAL) == 0)
3584                 val = strndup("prefer-external", PKG_STRING_LEN_MAX - 1);
3585         else if (strcmp(value, "installed_internal") == 0)
3586                 val = strndup("installed_internal", PKG_STRING_LEN_MAX - 1);
3587         else if (strcmp(value, "installed_external") == 0)
3588                 val = strndup("installed_external", PKG_STRING_LEN_MAX - 1);
3589         else
3590                 val = strndup(value, PKG_STRING_LEN_MAX - 1);
3591         if (val == NULL) {
3592                 _LOGE("Out of Memory\n");
3593                 free(node);
3594                 node = NULL;
3595                 return PMINFO_R_ERROR;
3596         }
3597         node->prop = prop;
3598         node->value = val;
3599         /*If API is called multiple times for same property, we should override the previous values.
3600         Last value set will be used for filtering.*/
3601         link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
3602         if (link)
3603                 filter->list = g_slist_delete_link(filter->list, link);
3604         filter->list = g_slist_append(filter->list, (gpointer)node);
3605         return PMINFO_R_OK;
3606
3607 }
3608
3609 API int pkgmgrinfo_pkginfo_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count)
3610 {
3611         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3612         retvm_if(count == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3613         char *syslocale = NULL;
3614         char *locale = NULL;
3615         char *condition = NULL;
3616         char query[MAX_QUERY_LEN] = {'\0'};
3617         char where[MAX_QUERY_LEN] = {'\0'};
3618         GSList *list;
3619         int ret = 0;
3620         pkgmgr_pkginfo_x *node = NULL;
3621         pkgmgr_pkginfo_x *tmphead = NULL;
3622         pkgmgr_pkginfo_x *pkginfo = NULL;
3623         pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3624         sqlite3 *pkginfo_db = NULL;
3625         int filter_count = 0;
3626
3627         /*open db*/
3628         ret = db_util_open(MANIFEST_DB, &pkginfo_db, 0);
3629         retvm_if(ret != SQLITE_OK, PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
3630
3631         /*get system locale*/
3632         syslocale = vconf_get_str(VCONFKEY_LANGSET);
3633         locale = __convert_system_locale_to_manifest_locale(syslocale);
3634         tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
3635
3636         /*Start constructing query*/
3637         snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_LIST_PACKAGE, locale);
3638
3639         /*Get where clause*/
3640         for (list = filter->list; list; list = g_slist_next(list)) {
3641                 __get_filter_condition(list->data, &condition);
3642                 if (condition) {
3643                         strncat(where, condition, sizeof(where) - strlen(where) -1);
3644                         where[sizeof(where) - 1] = '\0';
3645                         free(condition);
3646                         condition = NULL;
3647                 }
3648                 if (g_slist_next(list)) {
3649                         strncat(where, " and ", sizeof(where) - strlen(where) - 1);
3650                         where[sizeof(where) - 1] = '\0';
3651                 }
3652         }
3653         _LOGE("where = %s\n", where);
3654         if (strlen(where) > 0) {
3655                 strncat(query, where, sizeof(query) - strlen(query) - 1);
3656                 query[sizeof(query) - 1] = '\0';
3657         }
3658         _LOGE("query = %s\n", query);
3659
3660         tmphead = calloc(1, sizeof(pkgmgr_pkginfo_x));
3661         tryvm_if(tmphead == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
3662
3663         ret = __exec_db_query(pkginfo_db, query, __pkg_list_cb, (void *)tmphead);
3664         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
3665
3666         LISTHEAD(tmphead, node);
3667         for(node = node->next ; node ; node = node->next) {
3668                 pkginfo = node;
3669                 pkginfo->locale = strdup(locale);
3670                 pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
3671                 tryvm_if(pkginfo->manifest_info->privileges == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for privileges info\n");
3672
3673                 /*populate manifest_info from DB*/
3674                 snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkginfo->manifest_info->package);
3675                 ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
3676                 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
3677
3678                 memset(query, '\0', MAX_QUERY_LEN);
3679                 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
3680                         " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, locale);
3681                 ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
3682                 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
3683
3684                 /*Also store the values corresponding to default locales*/
3685                 memset(query, '\0', MAX_QUERY_LEN);
3686                 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
3687                         " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, DEFAULT_LOCALE);
3688                 ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
3689                 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
3690         }
3691
3692         LISTHEAD(tmphead, node);
3693
3694         for(node = node->next ; node ; node = node->next) {
3695                 pkginfo = node;
3696                 ret = __pkginfo_check_installed_storage(pkginfo);
3697                 if(ret < 0)
3698                         continue;
3699                 filter_count++;
3700         }
3701
3702         *count = filter_count;
3703         ret = PMINFO_R_OK;
3704
3705 catch:
3706         if (locale) {
3707                 free(locale);
3708                 locale = NULL;
3709         }
3710         if (syslocale) {
3711                 free(syslocale);
3712                 syslocale = NULL;
3713         }
3714         sqlite3_close(pkginfo_db);
3715         __cleanup_pkginfo(tmphead);
3716         return ret;
3717 }
3718
3719 API int pkgmgrinfo_pkginfo_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h handle,
3720                                 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data)
3721 {
3722         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3723         retvm_if(pkg_cb == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3724         char *syslocale = NULL;
3725         char *locale = NULL;
3726         char *condition = NULL;
3727         char query[MAX_QUERY_LEN] = {'\0'};
3728         char where[MAX_QUERY_LEN] = {'\0'};
3729         GSList *list;
3730         int ret = 0;
3731         label_x *tmp1 = NULL;
3732         icon_x *tmp2 = NULL;
3733         description_x *tmp3 = NULL;
3734         author_x *tmp4 = NULL;
3735         privilege_x *tmp5 = NULL;
3736         pkgmgr_pkginfo_x *node = NULL;
3737         pkgmgr_pkginfo_x *tmphead = NULL;
3738         pkgmgr_pkginfo_x *pkginfo = NULL;
3739         pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3740         sqlite3 *pkginfo_db = NULL;
3741         const char* package_size_info = NULL;
3742         bool is_setting = false;
3743
3744         /*open db*/
3745         ret = db_util_open(MANIFEST_DB, &pkginfo_db, 0);
3746         retvm_if(ret != SQLITE_OK, PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
3747
3748         /*get system locale*/
3749         syslocale = vconf_get_str(VCONFKEY_LANGSET);
3750         locale = __convert_system_locale_to_manifest_locale(syslocale);
3751         tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
3752
3753         /*Start constructing query*/
3754         snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_LIST_PACKAGE, locale);
3755
3756         /*Get where clause*/
3757         for (list = filter->list; list; list = g_slist_next(list)) {
3758                 __get_filter_condition(list->data, &condition);
3759                 if (condition) {
3760                         strncat(where, condition, sizeof(where) - strlen(where) -1);
3761                         where[sizeof(where) - 1] = '\0';
3762
3763                         if (strstr(condition, "package_info.package_nodisplay"))
3764                                 is_setting = true;
3765
3766                         free(condition);
3767                         condition = NULL;
3768                 }
3769                 if (g_slist_next(list)) {
3770                         strncat(where, " and ", sizeof(where) - strlen(where) - 1);
3771                         where[sizeof(where) - 1] = '\0';
3772                 }
3773         }
3774         _LOGE("where = %s\n", where);
3775         if (strlen(where) > 0) {
3776                 strncat(query, where, sizeof(query) - strlen(query) - 1);
3777                 query[sizeof(query) - 1] = '\0';
3778         }
3779         _LOGE("query = %s\n", query);
3780
3781         tmphead = calloc(1, sizeof(pkgmgr_pkginfo_x));
3782         tryvm_if(tmphead == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
3783
3784         ret = __exec_db_query(pkginfo_db, query, __pkg_list_cb, (void *)tmphead);
3785         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
3786
3787         if (is_setting) {
3788                 ret = __reqeust_get_size("size_info", PM_GET_SIZE_INFO);
3789                 tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "fail reqeust size info");
3790
3791                 ret = __get_package_size_info(&package_size_info);
3792                 tryvm_if(ret != 0 || package_size_info == NULL, ret = PMINFO_R_ERROR, "__get_package_size_info() failed");
3793                 _LOGD("is_setting is true, get package size info success!! ");
3794         }
3795
3796         LISTHEAD(tmphead, node);
3797         for(node = node->next ; node ; node = node->next) {
3798                 pkginfo = node;
3799                 pkginfo->locale = strdup(locale);
3800                 pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
3801                 tryvm_if(pkginfo->manifest_info->privileges == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for privileges info\n");
3802
3803                 /*populate manifest_info from DB*/
3804                 snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkginfo->manifest_info->package);
3805                 ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
3806                 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
3807
3808                 memset(query, '\0', MAX_QUERY_LEN);
3809                 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
3810                         " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, locale);
3811                 ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
3812                 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
3813
3814                 /*Also store the values corresponding to default locales*/
3815                 memset(query, '\0', MAX_QUERY_LEN);
3816                 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
3817                         " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, DEFAULT_LOCALE);
3818                 ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
3819                 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
3820
3821                 if (pkginfo->manifest_info->label) {
3822                         LISTHEAD(pkginfo->manifest_info->label, tmp1);
3823                         pkginfo->manifest_info->label = tmp1;
3824                 }
3825                 if (pkginfo->manifest_info->icon) {
3826                         LISTHEAD(pkginfo->manifest_info->icon, tmp2);
3827                         pkginfo->manifest_info->icon = tmp2;
3828                 }
3829                 if (pkginfo->manifest_info->description) {
3830                         LISTHEAD(pkginfo->manifest_info->description, tmp3);
3831                         pkginfo->manifest_info->description = tmp3;
3832                 }
3833                 if (pkginfo->manifest_info->author) {
3834                         LISTHEAD(pkginfo->manifest_info->author, tmp4);
3835                         pkginfo->manifest_info->author = tmp4;
3836                 }
3837                 if (pkginfo->manifest_info->privileges->privilege) {
3838                         LISTHEAD(pkginfo->manifest_info->privileges->privilege, tmp5);
3839                         pkginfo->manifest_info->privileges->privilege = tmp5;
3840                 }
3841                 if (is_setting) {
3842                         __set_package_size_info(pkginfo->manifest_info, package_size_info);
3843                 }
3844         }
3845
3846         LISTHEAD(tmphead, node);
3847
3848         for(node = node->next ; node ; node = node->next) {
3849                 pkginfo = node;
3850
3851                 ret = __pkginfo_check_installed_storage(pkginfo);
3852                 if(ret < 0)
3853                         continue;
3854
3855                 ret = pkg_cb( (void *)pkginfo, user_data);
3856                 if(ret < 0)
3857                         break;
3858         }
3859         ret = PMINFO_R_OK;
3860
3861 catch:
3862         if (locale) {
3863                 free(locale);
3864                 locale = NULL;
3865         }
3866         if (syslocale) {
3867                 free(syslocale);
3868                 syslocale = NULL;
3869         }
3870         if (package_size_info) {
3871                 free(package_size_info);
3872         }
3873
3874         sqlite3_close(pkginfo_db);
3875         __cleanup_pkginfo(tmphead);
3876         return ret;
3877 }
3878
3879 API int pkgmgrinfo_pkginfo_foreach_privilege(pkgmgrinfo_pkginfo_h handle,
3880                         pkgmgrinfo_pkg_privilege_list_cb privilege_func, void *user_data)
3881 {
3882         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
3883         retvm_if(privilege_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
3884         int ret = -1;
3885         privilege_x *ptr = NULL;
3886         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3887         ptr = info->manifest_info->privileges->privilege;
3888         for (; ptr; ptr = ptr->next) {
3889                 if (ptr->text){
3890                         ret = privilege_func(ptr->text, user_data);
3891                         if (ret < 0)
3892                                 break;
3893                 }
3894         }
3895         return PMINFO_R_OK;
3896 }
3897
3898 API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_component component,
3899                                                 pkgmgrinfo_app_list_cb app_func, void *user_data)
3900 {
3901         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
3902         retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback pointer is NULL");
3903         retvm_if((component != PMINFO_UI_APP) && (component != PMINFO_SVC_APP) && (component != PMINFO_ALL_APP), PMINFO_R_EINVAL, "Invalid App Component Type");
3904
3905         char *syslocale = NULL;
3906         char *locale = NULL;
3907         int ret = -1;
3908         char query[MAX_QUERY_LEN] = {'\0'};
3909         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3910         pkgmgr_pkginfo_x *allinfo = NULL;
3911         pkgmgr_appinfo_x *appinfo = NULL;
3912         icon_x *ptr1 = NULL;
3913         label_x *ptr2 = NULL;
3914         category_x *ptr3 = NULL;
3915         metadata_x *ptr4 = NULL;
3916         permission_x *ptr5 = NULL;
3917         image_x *ptr6 = NULL;
3918         sqlite3 *appinfo_db = NULL;
3919
3920         /*check installed storage*/
3921         ret = __pkginfo_check_installed_storage(info);
3922         retvm_if(ret < 0, PMINFO_R_EINVAL, "[%s] is installed external, but is not in mmc", info->manifest_info->package);
3923
3924         /*get system locale*/
3925         syslocale = vconf_get_str(VCONFKEY_LANGSET);
3926         locale = __convert_system_locale_to_manifest_locale(syslocale);
3927         tryvm_if(locale == NULL, ret = PMINFO_R_EINVAL, "manifest locale is NULL");
3928
3929         /*calloc allinfo*/
3930         allinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
3931         tryvm_if(allinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
3932
3933         /*calloc manifest_info*/
3934         allinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
3935         tryvm_if(allinfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
3936
3937         /*calloc appinfo*/
3938         appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
3939         tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
3940
3941         /*set component type*/
3942         if (component == PMINFO_UI_APP)
3943                 appinfo->app_component = PMINFO_UI_APP;
3944         if (component == PMINFO_SVC_APP)
3945                 appinfo->app_component = PMINFO_SVC_APP;
3946         if (component == PMINFO_ALL_APP)
3947                 appinfo->app_component = PMINFO_ALL_APP;
3948
3949         /*open db */
3950         ret = db_util_open(MANIFEST_DB, &appinfo_db, 0);
3951         tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
3952
3953         appinfo->package = strdup(info->manifest_info->package);
3954         snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
3955                         "from package_app_info where " \
3956                         "package='%s' and app_component='%s'",
3957                         info->manifest_info->package,
3958                         (appinfo->app_component==PMINFO_UI_APP ? "uiapp" : "svcapp"));
3959
3960         switch(component) {
3961         case PMINFO_UI_APP:
3962                 /*Populate ui app info */
3963                 ret = __exec_db_query(appinfo_db, query, __uiapp_list_cb, (void *)info);
3964                 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
3965
3966                 uiapplication_x *tmp = NULL;
3967                 if (info->manifest_info->uiapplication) {
3968                         LISTHEAD(info->manifest_info->uiapplication, tmp);
3969                         info->manifest_info->uiapplication = tmp;
3970                 }
3971                 /*Populate localized info for default locales and call callback*/
3972                 /*If the callback func return < 0 we break and no more call back is called*/
3973                 while(tmp != NULL)
3974                 {
3975                         appinfo->locale = strdup(locale);
3976                         appinfo->uiapp_info = tmp;
3977                         if (strcmp(appinfo->uiapp_info->type,"c++app") == 0){
3978                                 if (locale) {
3979                                         free(locale);
3980                                 }
3981                                 locale = __get_app_locale_by_fallback(appinfo_db, appinfo->uiapp_info->appid, syslocale);
3982                         }
3983
3984                         memset(query, '\0', MAX_QUERY_LEN);
3985                         snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->uiapp_info->appid, locale);
3986                         ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3987                         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
3988
3989                         memset(query, '\0', MAX_QUERY_LEN);
3990                         snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->uiapp_info->appid, DEFAULT_LOCALE);
3991                         ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3992                         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
3993
3994                         /*store setting notification icon section*/
3995                         memset(query, '\0', MAX_QUERY_LEN);
3996                         snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appinfo->uiapp_info->appid);
3997                         ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3998                         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
3999                         
4000                         /*store app preview image info*/
4001                         memset(query, '\0', MAX_QUERY_LEN);
4002                         snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", appinfo->uiapp_info->appid);
4003                         ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4004                         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
4005
4006                         if (appinfo->uiapp_info->label) {
4007                                 LISTHEAD(appinfo->uiapp_info->label, ptr2);
4008                                 appinfo->uiapp_info->label = ptr2;
4009                         }
4010                         if (appinfo->uiapp_info->icon) {
4011                                 LISTHEAD(appinfo->uiapp_info->icon, ptr1);
4012                                 appinfo->uiapp_info->icon = ptr1;
4013                         }
4014                         if (appinfo->uiapp_info->category) {
4015                                 LISTHEAD(appinfo->uiapp_info->category, ptr3);
4016                                 appinfo->uiapp_info->category = ptr3;
4017                         }
4018                         if (appinfo->uiapp_info->metadata) {
4019                                 LISTHEAD(appinfo->uiapp_info->metadata, ptr4);
4020                                 appinfo->uiapp_info->metadata = ptr4;
4021                         }
4022                         if (appinfo->uiapp_info->permission) {
4023                                 LISTHEAD(appinfo->uiapp_info->permission, ptr5);
4024                                 appinfo->uiapp_info->permission = ptr5;
4025                         }
4026                         if (appinfo->uiapp_info->image) {
4027                                 LISTHEAD(appinfo->uiapp_info->image, ptr6);
4028                                 appinfo->uiapp_info->image = ptr6;
4029                         }
4030                         ret = app_func((void *)appinfo, user_data);
4031                         if (ret < 0)
4032                                 break;
4033                         tmp = tmp->next;
4034                 }
4035                 break;
4036         case PMINFO_SVC_APP:
4037                 /*Populate svc app info */
4038                 ret = __exec_db_query(appinfo_db, query, __svcapp_list_cb, (void *)info);
4039                 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
4040
4041                 serviceapplication_x *tmp1 = NULL;
4042                 if (info->manifest_info->serviceapplication) {
4043                         LISTHEAD(info->manifest_info->serviceapplication, tmp1);
4044                         info->manifest_info->serviceapplication = tmp1;
4045                 }
4046                 /*Populate localized info for default locales and call callback*/
4047                 /*If the callback func return < 0 we break and no more call back is called*/
4048                 while(tmp1 != NULL)
4049                 {
4050                         appinfo->locale = strdup(locale);
4051                         appinfo->svcapp_info = tmp1;
4052                         memset(query, '\0', MAX_QUERY_LEN);
4053                         snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->svcapp_info->appid, locale);
4054                         ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4055                         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4056
4057                         memset(query, '\0', MAX_QUERY_LEN);
4058                         snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->svcapp_info->appid, DEFAULT_LOCALE);
4059                         ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4060                         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4061
4062                         if (appinfo->svcapp_info->label) {
4063                                 LISTHEAD(appinfo->svcapp_info->label, ptr2);
4064                                 appinfo->svcapp_info->label = ptr2;
4065                         }
4066                         if (appinfo->svcapp_info->icon) {
4067                                 LISTHEAD(appinfo->svcapp_info->icon, ptr1);
4068                                 appinfo->svcapp_info->icon = ptr1;
4069                         }
4070                         if (appinfo->svcapp_info->category) {
4071                                 LISTHEAD(appinfo->svcapp_info->category, ptr3);
4072                                 appinfo->svcapp_info->category = ptr3;
4073                         }
4074                         if (appinfo->svcapp_info->metadata) {
4075                                 LISTHEAD(appinfo->svcapp_info->metadata, ptr4);
4076                                 appinfo->svcapp_info->metadata = ptr4;
4077                         }
4078                         if (appinfo->svcapp_info->permission) {
4079                                 LISTHEAD(appinfo->svcapp_info->permission, ptr5);
4080                                 appinfo->svcapp_info->permission = ptr5;
4081                         }
4082                         ret = app_func((void *)appinfo, user_data);
4083                         if (ret < 0)
4084                                 break;
4085                         tmp1 = tmp1->next;
4086                 }
4087                 break;
4088         case PMINFO_ALL_APP:
4089                 memset(query, '\0', MAX_QUERY_LEN);
4090                 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where package='%s'", info->manifest_info->package);
4091
4092                 /*Populate all app info */
4093                 ret = __exec_db_query(appinfo_db, query, __allapp_list_cb, (void *)allinfo);
4094                 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
4095
4096                 /*UI Apps*/
4097                 appinfo->app_component = PMINFO_UI_APP;
4098                 uiapplication_x *tmp2 = NULL;
4099                 if (allinfo->manifest_info->uiapplication) {
4100                         LISTHEAD(allinfo->manifest_info->uiapplication, tmp2);
4101                         allinfo->manifest_info->uiapplication = tmp2;
4102                 }
4103                 /*Populate localized info for default locales and call callback*/
4104                 /*If the callback func return < 0 we break and no more call back is called*/
4105                 while(tmp2 != NULL)
4106                 {
4107                         appinfo->locale = strdup(locale);
4108                         appinfo->uiapp_info = tmp2;
4109                         memset(query, '\0', MAX_QUERY_LEN);
4110                         snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->uiapp_info->appid, locale);
4111                         ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4112                         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4113
4114                         memset(query, '\0', MAX_QUERY_LEN);
4115                         snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->uiapp_info->appid, DEFAULT_LOCALE);
4116                         ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4117                         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4118
4119                         /*store setting notification icon section*/
4120                         memset(query, '\0', MAX_QUERY_LEN);
4121                         snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appinfo->uiapp_info->appid);
4122                         ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4123                         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
4124                         
4125                         /*store app preview image info*/
4126                         memset(query, '\0', MAX_QUERY_LEN);
4127                         snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", appinfo->uiapp_info->appid);
4128                         ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4129                         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
4130
4131                         if (appinfo->uiapp_info->label) {
4132                                 LISTHEAD(appinfo->uiapp_info->label, ptr2);
4133                                 appinfo->uiapp_info->label = ptr2;
4134                         }
4135                         if (appinfo->uiapp_info->icon) {
4136                                 LISTHEAD(appinfo->uiapp_info->icon, ptr1);
4137                                 appinfo->uiapp_info->icon = ptr1;
4138                         }
4139                         if (appinfo->uiapp_info->category) {
4140                                 LISTHEAD(appinfo->uiapp_info->category, ptr3);
4141                                 appinfo->uiapp_info->category = ptr3;
4142                         }
4143                         if (appinfo->uiapp_info->metadata) {
4144                                 LISTHEAD(appinfo->uiapp_info->metadata, ptr4);
4145                                 appinfo->uiapp_info->metadata = ptr4;
4146                         }
4147                         if (appinfo->uiapp_info->permission) {
4148                                 LISTHEAD(appinfo->uiapp_info->permission, ptr5);
4149                                 appinfo->uiapp_info->permission = ptr5;
4150                         }
4151                         if (appinfo->uiapp_info->image) {
4152                                 LISTHEAD(appinfo->uiapp_info->image, ptr6);
4153                                 appinfo->uiapp_info->image = ptr6;
4154                         }
4155                         ret = app_func((void *)appinfo, user_data);
4156                         if (ret < 0)
4157                                 break;
4158                         tmp2 = tmp2->next;
4159                 }
4160
4161                 /*SVC Apps*/
4162                 appinfo->app_component = PMINFO_SVC_APP;
4163                 serviceapplication_x *tmp3 = NULL;
4164                 if (allinfo->manifest_info->serviceapplication) {
4165                         LISTHEAD(allinfo->manifest_info->serviceapplication, tmp3);
4166                         allinfo->manifest_info->serviceapplication = tmp3;
4167                 }
4168                 /*Populate localized info for default locales and call callback*/
4169                 /*If the callback func return < 0 we break and no more call back is called*/
4170                 while(tmp3 != NULL)
4171                 {
4172                         appinfo->locale = strdup(locale);
4173                         appinfo->svcapp_info = tmp3;
4174                         memset(query, '\0', MAX_QUERY_LEN);
4175                         snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->svcapp_info->appid, locale);
4176                         ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4177                         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4178
4179                         memset(query, '\0', MAX_QUERY_LEN);
4180                         snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->svcapp_info->appid, DEFAULT_LOCALE);
4181                         ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4182                         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4183
4184                         if (appinfo->svcapp_info->label) {
4185                                 LISTHEAD(appinfo->svcapp_info->label, ptr2);
4186                                 appinfo->svcapp_info->label = ptr2;
4187                         }
4188                         if (appinfo->svcapp_info->icon) {
4189                                 LISTHEAD(appinfo->svcapp_info->icon, ptr1);
4190                                 appinfo->svcapp_info->icon = ptr1;
4191                         }
4192                         if (appinfo->svcapp_info->category) {
4193                                 LISTHEAD(appinfo->svcapp_info->category, ptr3);
4194                                 appinfo->svcapp_info->category = ptr3;
4195                         }
4196                         if (appinfo->svcapp_info->metadata) {
4197                                 LISTHEAD(appinfo->svcapp_info->metadata, ptr4);
4198                                 appinfo->svcapp_info->metadata = ptr4;
4199                         }
4200                         if (appinfo->svcapp_info->permission) {
4201                                 LISTHEAD(appinfo->svcapp_info->permission, ptr5);
4202                                 appinfo->svcapp_info->permission = ptr5;
4203                         }
4204                         ret = app_func((void *)appinfo, user_data);
4205                         if (ret < 0)
4206                                 break;
4207                         tmp3 = tmp3->next;
4208                 }
4209                 appinfo->app_component = PMINFO_ALL_APP;
4210                 break;
4211
4212         }
4213
4214         ret = PMINFO_R_OK;
4215 catch:
4216         if (locale) {
4217                 free(locale);
4218                 locale = NULL;
4219         }
4220         if (syslocale) {
4221                 free(syslocale);
4222                 syslocale = NULL;
4223         }
4224         if (appinfo) {
4225                 if (appinfo->package) {
4226                         free((void *)appinfo->package);
4227                         appinfo->package = NULL;
4228                 }
4229                 free(appinfo);
4230                 appinfo = NULL;
4231         }
4232         __cleanup_pkginfo(allinfo);
4233
4234         sqlite3_close(appinfo_db);
4235         return ret;
4236 }
4237
4238 API int pkgmgrinfo_appinfo_get_install_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
4239 {
4240         retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback function is NULL");
4241
4242         int ret = PMINFO_R_OK;
4243         char query[MAX_QUERY_LEN] = {'\0'};
4244         pkgmgr_appinfo_x *appinfo = NULL;
4245         uiapplication_x *ptr1 = NULL;
4246         serviceapplication_x *ptr2 = NULL;
4247         sqlite3 *appinfo_db = NULL;
4248
4249         /*open db*/
4250         ret = db_util_open(MANIFEST_DB, &appinfo_db, 0);
4251         retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
4252
4253         /*calloc pkginfo*/
4254         pkgmgr_pkginfo_x *info = NULL;
4255         info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
4256         tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4257
4258         /*calloc manifest_info*/
4259         info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
4260         tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4261
4262         /*calloc appinfo*/
4263         appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
4264         tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4265
4266         snprintf(query, MAX_QUERY_LEN, "select * from package_app_info");
4267         ret = __exec_db_query(appinfo_db, query, __mini_appinfo_cb, (void *)info);
4268         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4269
4270         if (info->manifest_info->uiapplication) {
4271                 LISTHEAD(info->manifest_info->uiapplication, ptr1);
4272                 info->manifest_info->uiapplication = ptr1;
4273         }
4274         if (info->manifest_info->serviceapplication) {
4275                 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
4276                 info->manifest_info->serviceapplication = ptr2;
4277         }
4278
4279         /*UI Apps*/
4280         for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
4281         {
4282                 appinfo->app_component = PMINFO_UI_APP;
4283                 appinfo->package = strdup(ptr1->package);
4284                 appinfo->uiapp_info = ptr1;
4285
4286                 ret = __appinfo_check_installed_storage(appinfo);
4287                 if(ret < 0)
4288                         continue;
4289
4290                 ret = app_func((void *)appinfo, user_data);
4291                 if (ret < 0)
4292                         break;
4293                 free((void *)appinfo->package);
4294                 appinfo->package = NULL;
4295         }
4296         /*Service Apps*/
4297         for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
4298         {
4299                 appinfo->app_component = PMINFO_SVC_APP;
4300                 appinfo->package = strdup(ptr2->package);
4301                 appinfo->svcapp_info = ptr2;
4302
4303                 ret = app_func((void *)appinfo, user_data);
4304                 if (ret < 0)
4305                         break;
4306                 free((void *)appinfo->package);
4307                 appinfo->package = NULL;
4308         }
4309         ret = PMINFO_R_OK;
4310
4311 catch:
4312         sqlite3_close(appinfo_db);
4313
4314         if (appinfo) {
4315                 free(appinfo);
4316                 appinfo = NULL;
4317         }
4318         __cleanup_pkginfo(info);
4319         return ret;
4320 }
4321
4322 API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
4323 {
4324         retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback function is NULL");
4325
4326         int ret = PMINFO_R_OK;
4327         char query[MAX_QUERY_LEN] = {'\0'};
4328         char *syslocale = NULL;
4329         char *locale = NULL;
4330         pkgmgr_appinfo_x *appinfo = NULL;
4331         uiapplication_x *ptr1 = NULL;
4332         serviceapplication_x *ptr2 = NULL;
4333         label_x *tmp1 = NULL;
4334         icon_x *tmp2 = NULL;
4335         category_x *tmp3 = NULL;
4336         metadata_x *tmp4 = NULL;
4337         permission_x *tmp5 = NULL;
4338         image_x *tmp6 = NULL;
4339         sqlite3 *appinfo_db = NULL;
4340
4341         /*get system locale*/
4342         syslocale = vconf_get_str(VCONFKEY_LANGSET);
4343         locale = __convert_system_locale_to_manifest_locale(syslocale);
4344         tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
4345
4346         /*open db*/
4347         ret = db_util_open(MANIFEST_DB, &appinfo_db, 0);
4348         retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
4349
4350         /*calloc pkginfo*/
4351         pkgmgr_pkginfo_x *info = NULL;
4352         info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
4353         tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4354
4355         /*calloc manifest_info*/
4356         info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
4357         tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4358
4359         /*calloc appinfo*/
4360         appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
4361         tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4362
4363         snprintf(query, MAX_QUERY_LEN, "select * from package_app_info");
4364         ret = __exec_db_query(appinfo_db, query, __app_list_cb, (void *)info);
4365         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4366
4367         if (info->manifest_info->uiapplication) {
4368                 LISTHEAD(info->manifest_info->uiapplication, ptr1);
4369                 info->manifest_info->uiapplication = ptr1;
4370         }
4371         if (info->manifest_info->serviceapplication) {
4372                 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
4373                 info->manifest_info->serviceapplication = ptr2;
4374         }
4375
4376         /*UI Apps*/
4377         for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
4378         {
4379                 appinfo->locale = strdup(locale);
4380                 appinfo->app_component = PMINFO_UI_APP;
4381                 appinfo->package = strdup(ptr1->package);
4382                 appinfo->uiapp_info = ptr1;
4383                 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4384                                 "from package_app_info where " \
4385                                 "app_id='%s'", ptr1->appid);
4386                 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4387                 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4388
4389                 if (strcmp(appinfo->uiapp_info->type,"c++app") == 0){
4390                         if (locale) {
4391                                 free(locale);
4392                         }
4393                         locale = __get_app_locale_by_fallback(appinfo_db, ptr1->appid, syslocale);
4394                 }
4395
4396                 memset(query, '\0', MAX_QUERY_LEN);
4397                 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4398                                 "from package_app_localized_info where " \
4399                                 "app_id='%s' and app_locale='%s'",
4400                                 ptr1->appid, locale);
4401                 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4402                 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4403
4404                 memset(query, '\0', MAX_QUERY_LEN);
4405                 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4406                                 "from package_app_localized_info where " \
4407                                 "app_id='%s' and app_locale='%s'",
4408                                 ptr1->appid, DEFAULT_LOCALE);
4409
4410                 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4411                 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4412
4413                 /*store setting notification icon section*/
4414                 memset(query, '\0', MAX_QUERY_LEN);
4415                 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", ptr1->appid);
4416                 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4417                 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
4418                 
4419                 /*store app preview image info*/
4420                 memset(query, '\0', MAX_QUERY_LEN);
4421                 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", ptr1->appid);
4422                 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4423                 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
4424
4425                 if (appinfo->uiapp_info->label) {
4426                         LISTHEAD(appinfo->uiapp_info->label, tmp1);
4427                         appinfo->uiapp_info->label = tmp1;
4428                 }
4429                 if (appinfo->uiapp_info->icon) {
4430                         LISTHEAD(appinfo->uiapp_info->icon, tmp2);
4431                         appinfo->uiapp_info->icon= tmp2;
4432                 }
4433                 if (appinfo->uiapp_info->category) {
4434                         LISTHEAD(appinfo->uiapp_info->category, tmp3);
4435                         appinfo->uiapp_info->category = tmp3;
4436                 }
4437                 if (appinfo->uiapp_info->metadata) {
4438                         LISTHEAD(appinfo->uiapp_info->metadata, tmp4);
4439                         appinfo->uiapp_info->metadata = tmp4;
4440                 }
4441                 if (appinfo->uiapp_info->permission) {
4442                         LISTHEAD(appinfo->uiapp_info->permission, tmp5);
4443                         appinfo->uiapp_info->permission = tmp5;
4444                 }
4445                 if (appinfo->uiapp_info->image) {
4446                         LISTHEAD(appinfo->uiapp_info->image, tmp6);
4447                         appinfo->uiapp_info->image = tmp6;
4448                 }
4449
4450                 ret = __appinfo_check_installed_storage(appinfo);
4451                 if(ret < 0)
4452                         continue;
4453
4454                 ret = app_func((void *)appinfo, user_data);
4455                 if (ret < 0)
4456                         break;
4457                 free((void *)appinfo->package);
4458                 appinfo->package = NULL;
4459         }
4460         /*Service Apps*/
4461         for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
4462         {
4463                 appinfo->locale = strdup(locale);
4464                 appinfo->app_component = PMINFO_SVC_APP;
4465                 appinfo->package = strdup(ptr2->package);
4466                 appinfo->svcapp_info = ptr2;
4467                 memset(query, '\0', MAX_QUERY_LEN);
4468                 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4469                                 "from package_app_info where " \
4470                                 "app_id='%s'", ptr2->appid);
4471                 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4472                 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4473
4474                 memset(query, '\0', MAX_QUERY_LEN);
4475                 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4476                                 "from package_app_localized_info where " \
4477                                 "app_id='%s' and app_locale='%s'",
4478                                 ptr2->appid, locale);
4479                 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4480                 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4481
4482                 memset(query, '\0', MAX_QUERY_LEN);
4483                 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4484                                 "from package_app_localized_info where " \
4485                                 "app_id='%s' and app_locale='%s'",
4486                                 ptr2->appid, DEFAULT_LOCALE);
4487                 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4488                 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4489
4490                 if (appinfo->svcapp_info->label) {
4491                         LISTHEAD(appinfo->svcapp_info->label, tmp1);
4492                         appinfo->svcapp_info->label = tmp1;
4493                 }
4494                 if (appinfo->svcapp_info->icon) {
4495                         LISTHEAD(appinfo->svcapp_info->icon, tmp2);
4496                         appinfo->svcapp_info->icon= tmp2;
4497                 }
4498                 if (appinfo->svcapp_info->category) {
4499                         LISTHEAD(appinfo->svcapp_info->category, tmp3);
4500                         appinfo->svcapp_info->category = tmp3;
4501                 }
4502                 if (appinfo->svcapp_info->metadata) {
4503                         LISTHEAD(appinfo->svcapp_info->metadata, tmp4);
4504                         appinfo->svcapp_info->metadata = tmp4;
4505                 }
4506                 if (appinfo->svcapp_info->permission) {
4507                         LISTHEAD(appinfo->svcapp_info->permission, tmp5);
4508                         appinfo->svcapp_info->permission = tmp5;
4509                 }
4510                 ret = app_func((void *)appinfo, user_data);
4511                 if (ret < 0)
4512                         break;
4513                 free((void *)appinfo->package);
4514                 appinfo->package = NULL;
4515         }
4516         ret = PMINFO_R_OK;
4517
4518 catch:
4519         if (locale) {
4520                 free(locale);
4521                 locale = NULL;
4522         }
4523         if (syslocale) {
4524                 free(syslocale);
4525                 syslocale = NULL;
4526         }
4527         sqlite3_close(appinfo_db);
4528         if (appinfo) {
4529                 free(appinfo);
4530                 appinfo = NULL;
4531         }
4532         __cleanup_pkginfo(info);
4533         return ret;
4534 }
4535
4536 API int pkgmgrinfo_appinfo_get_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
4537 {
4538         retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL");
4539         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4540
4541         pkgmgr_appinfo_x *appinfo = NULL;
4542         char *syslocale = NULL;
4543         char *locale = NULL;
4544         int ret = -1;
4545         int exist = 0;
4546         label_x *tmp1 = NULL;
4547         icon_x *tmp2 = NULL;
4548         category_x *tmp3 = NULL;
4549         metadata_x *tmp4 = NULL;
4550         permission_x *tmp5 = NULL;
4551         image_x *tmp6 = NULL;
4552         char query[MAX_QUERY_LEN] = {'\0'};
4553         sqlite3 *appinfo_db = NULL;
4554
4555         /*open db*/
4556         ret = db_util_open(MANIFEST_DB, &appinfo_db, 0);
4557         retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
4558
4559         /*check appid exist on db*/
4560         snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", appid);
4561         ret = __exec_db_query(appinfo_db, query, __validate_cb, (void *)&exist);
4562         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "sqlite3_exec fail");
4563         tryvm_if(exist == 0, ret = PMINFO_R_ERROR, "Appid[%s] not found in DB", appid);
4564
4565         /*get system locale*/
4566         syslocale = vconf_get_str(VCONFKEY_LANGSET);
4567         locale = __convert_system_locale_to_manifest_locale(syslocale);
4568         tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
4569
4570         /*calloc appinfo*/
4571         appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
4572         tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
4573
4574         /*check app_component from DB*/
4575         memset(query, '\0', MAX_QUERY_LEN);
4576         snprintf(query, MAX_QUERY_LEN, "select app_component, package from package_app_info where app_id='%s' ", appid);
4577         ret = __exec_db_query(appinfo_db, query, __appcomponent_cb, (void *)appinfo);
4578         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4579
4580         /*calloc app_component*/
4581         if (appinfo->app_component == PMINFO_UI_APP) {
4582                 appinfo->uiapp_info = (uiapplication_x *)calloc(1, sizeof(uiapplication_x));
4583                 tryvm_if(appinfo->uiapp_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for uiapp info");
4584         } else {
4585                 appinfo->svcapp_info = (serviceapplication_x *)calloc(1, sizeof(serviceapplication_x));
4586                 tryvm_if(appinfo->svcapp_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for svcapp info");
4587         }
4588         appinfo->locale = strdup(locale);
4589
4590         /*populate app_info from DB*/
4591         memset(query, '\0', MAX_QUERY_LEN);
4592         snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' ", appid);
4593         ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4594         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4595
4596         memset(query, '\0', MAX_QUERY_LEN);
4597         snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appid, locale);
4598         ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4599         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4600
4601         /*Also store the values corresponding to default locales*/
4602         memset(query, '\0', MAX_QUERY_LEN);
4603         snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appid, DEFAULT_LOCALE);
4604         ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4605         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4606
4607         /*Populate app category*/
4608         memset(query, '\0', MAX_QUERY_LEN);
4609         snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_category where app_id='%s'", appid);
4610         ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4611         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Category Info DB Information retrieval failed");
4612
4613         /*Populate app metadata*/
4614         memset(query, '\0', MAX_QUERY_LEN);
4615         snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_metadata where app_id='%s'", appid);
4616         ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4617         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Metadata Info DB Information retrieval failed");
4618
4619         /*Populate app permission*/
4620         memset(query, '\0', MAX_QUERY_LEN);
4621         snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_permission where app_id='%s'", appid);
4622         ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4623         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App permission Info DB Information retrieval failed");
4624
4625         /*store setting notification icon section*/
4626         memset(query, '\0', MAX_QUERY_LEN);
4627         snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appid);
4628         ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4629         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
4630
4631         /*store app preview image info*/
4632         memset(query, '\0', MAX_QUERY_LEN);
4633         snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", appid);
4634         ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4635         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
4636
4637         ret = __appinfo_check_installed_storage(appinfo);
4638         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "[%s] is installed external, but is not in mmc", appinfo->package);
4639
4640         switch (appinfo->app_component) {
4641         case PMINFO_UI_APP:
4642                 if (appinfo->uiapp_info->label) {
4643                         LISTHEAD(appinfo->uiapp_info->label, tmp1);
4644                         appinfo->uiapp_info->label = tmp1;
4645                 }
4646                 if (appinfo->uiapp_info->icon) {
4647                         LISTHEAD(appinfo->uiapp_info->icon, tmp2);
4648                         appinfo->uiapp_info->icon = tmp2;
4649                 }
4650                 if (appinfo->uiapp_info->category) {
4651                         LISTHEAD(appinfo->uiapp_info->category, tmp3);
4652                         appinfo->uiapp_info->category = tmp3;
4653                 }
4654                 if (appinfo->uiapp_info->metadata) {
4655                         LISTHEAD(appinfo->uiapp_info->metadata, tmp4);
4656                         appinfo->uiapp_info->metadata = tmp4;
4657                 }
4658                 if (appinfo->uiapp_info->permission) {
4659                         LISTHEAD(appinfo->uiapp_info->permission, tmp5);
4660                         appinfo->uiapp_info->permission = tmp5;
4661                 }
4662                 if (appinfo->uiapp_info->image) {
4663                         LISTHEAD(appinfo->uiapp_info->image, tmp6);
4664                         appinfo->uiapp_info->image = tmp6;
4665                 }
4666                 break;
4667         case PMINFO_SVC_APP:
4668                 if (appinfo->svcapp_info->label) {
4669                         LISTHEAD(appinfo->svcapp_info->label, tmp1);
4670                         appinfo->svcapp_info->label = tmp1;
4671                 }
4672                 if (appinfo->svcapp_info->icon) {
4673                         LISTHEAD(appinfo->svcapp_info->icon, tmp2);
4674                         appinfo->svcapp_info->icon = tmp2;
4675                 }
4676                 if (appinfo->svcapp_info->category) {
4677                         LISTHEAD(appinfo->svcapp_info->category, tmp3);
4678                         appinfo->svcapp_info->category = tmp3;
4679                 }
4680                 if (appinfo->svcapp_info->metadata) {
4681                         LISTHEAD(appinfo->svcapp_info->metadata, tmp4);
4682                         appinfo->svcapp_info->metadata = tmp4;
4683                 }
4684                 if (appinfo->svcapp_info->permission) {
4685                         LISTHEAD(appinfo->svcapp_info->permission, tmp5);
4686                         appinfo->svcapp_info->permission = tmp5;
4687                 }
4688                 break;
4689         default:
4690                 break;
4691         }
4692
4693         ret = PMINFO_R_OK;
4694
4695 catch:
4696         if (ret == PMINFO_R_OK)
4697                 *handle = (void*)appinfo;
4698         else {
4699                 *handle = NULL;
4700                 __cleanup_appinfo(appinfo);
4701         }
4702
4703         sqlite3_close(appinfo_db);
4704         if (syslocale) {
4705                 free(syslocale);
4706                 syslocale = NULL;
4707         }
4708         if (locale) {
4709                 free(locale);
4710                 locale = NULL;
4711         }
4712         return ret;
4713 }
4714
4715
4716 API int pkgmgrinfo_appinfo_get_appid(pkgmgrinfo_appinfo_h  handle, char **appid)
4717 {
4718         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4719         retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4720         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4721
4722         if (info->app_component == PMINFO_UI_APP)
4723                 *appid = (char *)info->uiapp_info->appid;
4724         else if (info->app_component == PMINFO_SVC_APP)
4725                 *appid = (char *)info->svcapp_info->appid;
4726
4727         return PMINFO_R_OK;
4728 }
4729
4730 API int pkgmgrinfo_appinfo_get_pkgname(pkgmgrinfo_appinfo_h  handle, char **pkg_name)
4731 {
4732         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4733         retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4734         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4735
4736         *pkg_name = (char *)info->package;
4737
4738         return PMINFO_R_OK;
4739 }
4740
4741 API int pkgmgrinfo_appinfo_get_pkgid(pkgmgrinfo_appinfo_h  handle, char **pkgid)
4742 {
4743         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4744         retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4745         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4746
4747         *pkgid = (char *)info->package;
4748
4749         return PMINFO_R_OK;
4750 }
4751
4752 API int pkgmgrinfo_appinfo_get_exec(pkgmgrinfo_appinfo_h  handle, char **exec)
4753 {
4754         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4755         retvm_if(exec == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4756         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4757
4758         if (info->app_component == PMINFO_UI_APP)
4759                 *exec = (char *)info->uiapp_info->exec;
4760         if (info->app_component == PMINFO_SVC_APP)
4761                 *exec = (char *)info->svcapp_info->exec;
4762
4763         return PMINFO_R_OK;
4764 }
4765
4766
4767 API int pkgmgrinfo_appinfo_get_icon(pkgmgrinfo_appinfo_h  handle, char **icon)
4768 {
4769         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4770         retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4771         char *locale = NULL;
4772         icon_x *ptr = NULL;
4773         icon_x *start = NULL;
4774         *icon = NULL;
4775
4776         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4777                 locale = info->locale;
4778                 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
4779
4780         if (info->app_component == PMINFO_UI_APP)
4781                 start = info->uiapp_info->icon;
4782         if (info->app_component == PMINFO_SVC_APP)
4783                 start = info->svcapp_info->icon;
4784         for(ptr = start; ptr != NULL; ptr = ptr->next)
4785         {
4786                 if (ptr->lang) {
4787                         if (strcmp(ptr->lang, locale) == 0) {
4788                                 *icon = (char *)ptr->text;
4789                                 if (strcasecmp(*icon, "(null)") == 0) {
4790                                         locale = DEFAULT_LOCALE;
4791                                         continue;
4792                                 } else
4793                                         break;
4794                         } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
4795                                 *icon = (char *)ptr->text;
4796                                 break;
4797                         }
4798                 }
4799         }
4800         return PMINFO_R_OK;
4801 }
4802
4803
4804 API int pkgmgrinfo_appinfo_get_label(pkgmgrinfo_appinfo_h  handle, char **label)
4805 {
4806         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4807         retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4808         char *locale = NULL;
4809         label_x *ptr = NULL;
4810         label_x *start = NULL;
4811         *label = NULL;
4812
4813         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4814         locale = info->locale;
4815         retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
4816
4817         if (info->app_component == PMINFO_UI_APP)
4818                 start = info->uiapp_info->label;
4819         if (info->app_component == PMINFO_SVC_APP)
4820                 start = info->svcapp_info->label;
4821         for(ptr = start; ptr != NULL; ptr = ptr->next)
4822         {
4823                 if (ptr->lang) {
4824                         if (strcmp(ptr->lang, locale) == 0) {
4825                                 *label = (char *)ptr->text;
4826                                 if (strcasecmp(*label, "(null)") == 0) {
4827                                         locale = DEFAULT_LOCALE;
4828                                         continue;
4829                                 } else
4830                                         break;
4831                         } else if (strncasecmp(ptr->lang, locale, 2) == 0) {
4832                                 *label = (char *)ptr->text;
4833                                 if (strcasecmp(*label, "(null)") == 0) {
4834                                                 locale = DEFAULT_LOCALE;
4835                                                 continue;
4836                                 } else
4837                                                 break;
4838                         } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
4839                                 *label = (char *)ptr->text;
4840                                 break;
4841                         }
4842                 }
4843         }
4844         return PMINFO_R_OK;
4845 }
4846
4847
4848 API int pkgmgrinfo_appinfo_get_component(pkgmgrinfo_appinfo_h  handle, pkgmgrinfo_app_component *component)
4849 {
4850         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4851         retvm_if(component == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4852         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4853
4854         if (info->app_component == PMINFO_UI_APP)
4855                 *component = PMINFO_UI_APP;
4856         else if (info->app_component == PMINFO_SVC_APP)
4857                 *component = PMINFO_SVC_APP;
4858         else
4859                 return PMINFO_R_ERROR;
4860
4861         return PMINFO_R_OK;
4862 }
4863
4864 API int pkgmgrinfo_appinfo_get_apptype(pkgmgrinfo_appinfo_h  handle, char **app_type)
4865 {
4866         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4867         retvm_if(app_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4868         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4869
4870         if (info->app_component == PMINFO_UI_APP)
4871                 *app_type = (char *)info->uiapp_info->type;
4872         if (info->app_component == PMINFO_SVC_APP)
4873                 *app_type = (char *)info->svcapp_info->type;
4874
4875         return PMINFO_R_OK;
4876 }
4877
4878 API int pkgmgrinfo_appinfo_get_operation(pkgmgrinfo_appcontrol_h  handle,
4879                                         int *operation_count, char ***operation)
4880 {
4881         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4882         retvm_if(operation == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4883         retvm_if(operation_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4884         pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
4885         *operation_count = data->operation_count;
4886         *operation = data->operation;
4887         return PMINFO_R_OK;
4888 }
4889
4890 API int pkgmgrinfo_appinfo_get_uri(pkgmgrinfo_appcontrol_h  handle,
4891                                         int *uri_count, char ***uri)
4892 {
4893         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4894         retvm_if(uri == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4895         retvm_if(uri_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4896         pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
4897         *uri_count = data->uri_count;
4898         *uri = data->uri;
4899         return PMINFO_R_OK;
4900 }
4901
4902 API int pkgmgrinfo_appinfo_get_mime(pkgmgrinfo_appcontrol_h  handle,
4903                                         int *mime_count, char ***mime)
4904 {
4905         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4906         retvm_if(mime == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4907         retvm_if(mime_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4908         pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
4909         *mime_count = data->mime_count;
4910         *mime = data->mime;
4911         return PMINFO_R_OK;
4912 }
4913
4914 API int pkgmgrinfo_appinfo_get_subapp(pkgmgrinfo_appcontrol_h  handle,
4915                                         int *subapp_count, char ***subapp)
4916 {
4917         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4918         retvm_if(subapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4919         retvm_if(subapp_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4920         pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
4921         *subapp_count = data->subapp_count;
4922         *subapp = data->subapp;
4923         return PMINFO_R_OK;
4924 }
4925
4926 API int pkgmgrinfo_appinfo_get_setting_icon(pkgmgrinfo_appinfo_h  handle, char **icon)
4927 {
4928         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
4929         retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4930
4931         char *val = NULL;
4932         icon_x *ptr = NULL;
4933         icon_x *start = NULL;
4934         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4935
4936         start = info->uiapp_info->icon;
4937
4938         for(ptr = start; ptr != NULL; ptr = ptr->next)
4939         {
4940                 if (ptr->section) {
4941                         val = (char *)ptr->section;
4942                         if (strcmp(val, "setting") == 0){
4943                                 *icon = (char *)ptr->text;
4944                                 break;
4945                         }
4946                 }
4947         }
4948         return PMINFO_R_OK;
4949 }
4950
4951
4952 API int pkgmgrinfo_appinfo_get_notification_icon(pkgmgrinfo_appinfo_h  handle, char **icon)
4953 {
4954         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
4955         retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4956
4957         char *val = NULL;
4958         icon_x *ptr = NULL;
4959         icon_x *start = NULL;
4960         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4961
4962         start = info->uiapp_info->icon;
4963
4964         for(ptr = start; ptr != NULL; ptr = ptr->next)
4965         {
4966                 if (ptr->section) {
4967                         val = (char *)ptr->section;
4968
4969                         if (strcmp(val, "notification") == 0){
4970                                 *icon = (char *)ptr->text;
4971                                 break;
4972                         }
4973                 }
4974         }
4975
4976         return PMINFO_R_OK;
4977 }
4978
4979 API int pkgmgrinfo_appinfo_get_recent_image_type(pkgmgrinfo_appinfo_h  handle, pkgmgrinfo_app_recentimage *type)
4980 {
4981         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4982         retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4983         char *val = NULL;
4984         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4985         val = (char *)info->uiapp_info->recentimage;
4986         if (val) {
4987                 if (strcasecmp(val, "capture") == 0)
4988                         *type = PMINFO_RECENTIMAGE_USE_CAPTURE;
4989                 else if (strcasecmp(val, "icon") == 0)
4990                         *type = PMINFO_RECENTIMAGE_USE_ICON;
4991                 else
4992                         *type = PMINFO_RECENTIMAGE_USE_NOTHING;
4993         }
4994
4995         return PMINFO_R_OK;
4996 }
4997
4998 API int pkgmgrinfo_appinfo_get_preview_image(pkgmgrinfo_appinfo_h  handle, char **preview_img)
4999 {
5000         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
5001         retvm_if(preview_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5002
5003         char *val = NULL;
5004         image_x *ptr = NULL;
5005         image_x *start = NULL;
5006         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5007
5008         start = info->uiapp_info->image;
5009
5010         for(ptr = start; ptr != NULL; ptr = ptr->next)
5011         {
5012                 if (ptr->section) {
5013                         val = (char *)ptr->section;
5014
5015                         if (strcmp(val, "preview") == 0)
5016                                 *preview_img = (char *)ptr->text;
5017
5018                         break;
5019                 }
5020         }
5021         return PMINFO_R_OK;
5022 }
5023
5024 API int pkgmgrinfo_appinfo_get_permission_type(pkgmgrinfo_appinfo_h  handle, pkgmgrinfo_permission_type *permission)
5025 {
5026         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
5027         retvm_if(permission == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5028
5029         char *val = NULL;
5030         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5031
5032         if (info->app_component == PMINFO_UI_APP)
5033                 val = info->uiapp_info->permission_type;
5034         else if (info->app_component == PMINFO_SVC_APP)
5035                 val = info->svcapp_info->permission_type;
5036         else
5037                 return PMINFO_R_ERROR;
5038
5039         if (strcmp(val, "signature") == 0)
5040                 *permission = PMINFO_PERMISSION_SIGNATURE;
5041         else if (strcmp(val, "privilege") == 0)
5042                 *permission = PMINFO_PERMISSION_PRIVILEGE;
5043         else
5044                 *permission = PMINFO_PERMISSION_NORMAL;
5045
5046         return PMINFO_R_OK;
5047 }
5048
5049 API int pkgmgrinfo_appinfo_get_component_type(pkgmgrinfo_appinfo_h  handle, char **component_type)
5050 {
5051         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5052         retvm_if(component_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5053         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5054
5055         *component_type = (char *)info->uiapp_info->component_type;
5056
5057         return PMINFO_R_OK;
5058 }
5059
5060 API int pkgmgrinfo_appinfo_get_hwacceleration(pkgmgrinfo_appinfo_h  handle, pkgmgrinfo_app_hwacceleration *hwacceleration)
5061 {
5062         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5063         retvm_if(hwacceleration == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5064         char *val = NULL;
5065         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5066         val = (char *)info->uiapp_info->hwacceleration;
5067         if (val) {
5068                 if (strcasecmp(val, "not-use-GL") == 0)
5069                         *hwacceleration = PMINFO_HWACCELERATION_NOT_USE_GL;
5070                 else if (strcasecmp(val, "use-GL") == 0)
5071                         *hwacceleration = PMINFO_HWACCELERATION_USE_GL;
5072                 else
5073                         *hwacceleration = PMINFO_HWACCELERATION_USE_SYSTEM_SETTING;
5074         }
5075         return PMINFO_R_OK;
5076 }
5077
5078 API int pkgmgrinfo_appinfo_get_screenreader(pkgmgrinfo_appinfo_h  handle, pkgmgrinfo_app_screenreader *screenreader)
5079 {
5080         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5081         retvm_if(screenreader == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5082         char *val = NULL;
5083         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5084         val = (char *)info->uiapp_info->screenreader;
5085         if (val) {
5086                 if (strcasecmp(val, "screenreader-off") == 0)
5087                         *screenreader = PMINFO_SCREENREADER_OFF;
5088                 else if (strcasecmp(val, "screenreader-on") == 0)
5089                         *screenreader = PMINFO_SCREENREADER_ON;
5090                 else
5091                         *screenreader = PMINFO_SCREENREADER_USE_SYSTEM_SETTING;
5092         }
5093         return PMINFO_R_OK;
5094 }
5095
5096 API int pkgmgrinfo_appinfo_get_effectimage(pkgmgrinfo_appinfo_h  handle, char **portrait_img, char **landscape_img)
5097 {
5098         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5099         retvm_if(portrait_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5100         retvm_if(landscape_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5101         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5102
5103         if (info->app_component == PMINFO_UI_APP){
5104                 *portrait_img = (char *)info->uiapp_info->portraitimg;
5105                 *landscape_img = (char *)info->uiapp_info->landscapeimg;
5106         }
5107
5108         return PMINFO_R_OK;
5109 }
5110
5111 API int pkgmgrinfo_appinfo_get_submode_mainid(pkgmgrinfo_appinfo_h  handle, char **submode_mainid)
5112 {
5113         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5114         retvm_if(submode_mainid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5115         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5116
5117         *submode_mainid = (char *)info->uiapp_info->submode_mainid;
5118
5119         return PMINFO_R_OK;
5120 }
5121
5122 API int pkgmgrinfo_appinfo_foreach_permission(pkgmgrinfo_appinfo_h handle,
5123                         pkgmgrinfo_app_permission_list_cb permission_func, void *user_data)
5124 {
5125         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5126         retvm_if(permission_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
5127         int ret = -1;
5128         permission_x *ptr = NULL;
5129         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5130         if (info->app_component == PMINFO_UI_APP)
5131                 ptr = info->uiapp_info->permission;
5132         else if (info->app_component == PMINFO_SVC_APP)
5133                 ptr = info->svcapp_info->permission;
5134         else
5135                 return PMINFO_R_EINVAL;
5136         for (; ptr; ptr = ptr->next) {
5137                 if (ptr->value) {
5138                         ret = permission_func(ptr->value, user_data);
5139                         if (ret < 0)
5140                                 break;
5141                 }
5142         }
5143         return PMINFO_R_OK;
5144 }
5145
5146 API int pkgmgrinfo_appinfo_foreach_category(pkgmgrinfo_appinfo_h handle,
5147                         pkgmgrinfo_app_category_list_cb category_func, void *user_data)
5148 {
5149         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5150         retvm_if(category_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
5151         int ret = -1;
5152         category_x *ptr = NULL;
5153         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5154         if (info->app_component == PMINFO_UI_APP)
5155                 ptr = info->uiapp_info->category;
5156         else if (info->app_component == PMINFO_SVC_APP)
5157                 ptr = info->svcapp_info->category;
5158         else
5159                 return PMINFO_R_EINVAL;
5160         for (; ptr; ptr = ptr->next) {
5161                 if (ptr->name) {
5162                         ret = category_func(ptr->name, user_data);
5163                         if (ret < 0)
5164                                 break;
5165                 }
5166         }
5167         return PMINFO_R_OK;
5168 }
5169
5170 API int pkgmgrinfo_appinfo_foreach_metadata(pkgmgrinfo_appinfo_h handle,
5171                         pkgmgrinfo_app_metadata_list_cb metadata_func, void *user_data)
5172 {
5173         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5174         retvm_if(metadata_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
5175         int ret = -1;
5176         metadata_x *ptr = NULL;
5177         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5178         if (info->app_component == PMINFO_UI_APP)
5179                 ptr = info->uiapp_info->metadata;
5180         else if (info->app_component == PMINFO_SVC_APP)
5181                 ptr = info->svcapp_info->metadata;
5182         else
5183                 return PMINFO_R_EINVAL;
5184         for (; ptr; ptr = ptr->next) {
5185                 if (ptr->key) {
5186                         ret = metadata_func(ptr->key, ptr->value, user_data);
5187                         if (ret < 0)
5188                                 break;
5189                 }
5190         }
5191         return PMINFO_R_OK;
5192 }
5193
5194 API int pkgmgrinfo_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
5195                         pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data)
5196 {
5197         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5198         retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
5199         int i = 0;
5200         int ret = -1;
5201         int oc = 0;
5202         int mc = 0;
5203         int uc = 0;
5204         int sc = 0;
5205         char *pkgid = NULL;
5206         char *manifest = NULL;
5207         char **operation = NULL;
5208         char **uri = NULL;
5209         char **mime = NULL;
5210         char **subapp = NULL;
5211         appcontrol_x *appcontrol = NULL;
5212         manifest_x *mfx = NULL;
5213         operation_x *op = NULL;
5214         uri_x *ui = NULL;
5215         mime_x *mi = NULL;
5216         subapp_x *sa = NULL;
5217         pkgmgrinfo_app_component component;
5218         pkgmgrinfo_appcontrol_x *ptr = NULL;
5219         ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid);
5220         if (ret < 0) {
5221                 _LOGE("Failed to get package name\n");
5222                 return PMINFO_R_ERROR;
5223         }
5224         ret = pkgmgrinfo_appinfo_get_component(handle, &component);
5225         if (ret < 0) {
5226                 _LOGE("Failed to get app component name\n");
5227                 return PMINFO_R_ERROR;
5228         }
5229         manifest = pkgmgr_parser_get_manifest_file(pkgid);
5230         if (manifest == NULL) {
5231                 _LOGE("Failed to fetch package manifest file\n");
5232                 return PMINFO_R_ERROR;
5233         }
5234         mfx = pkgmgr_parser_process_manifest_xml(manifest);
5235         if (mfx == NULL) {
5236                 _LOGE("Failed to parse package manifest file\n");
5237                 free(manifest);
5238                 manifest = NULL;
5239                 return PMINFO_R_ERROR;
5240         }
5241         free(manifest);
5242         ptr  = calloc(1, sizeof(pkgmgrinfo_appcontrol_x));
5243         if (ptr == NULL) {
5244                 _LOGE("Out of Memory!!!\n");
5245                 pkgmgr_parser_free_manifest_xml(mfx);
5246                 return PMINFO_R_ERROR;
5247         }
5248         /*Get Operation, Uri, Mime*/
5249         switch (component) {
5250         case PMINFO_UI_APP:
5251                 if (mfx->uiapplication) {
5252                         if (mfx->uiapplication->appsvc) {
5253                                 appcontrol = mfx->uiapplication->appsvc;
5254                         }
5255                 }
5256                 break;
5257         case PMINFO_SVC_APP:
5258                 if (mfx->serviceapplication) {
5259                         if (mfx->serviceapplication->appsvc) {
5260                                 appcontrol = mfx->serviceapplication->appsvc;
5261                         }
5262                 }
5263                 break;
5264         default:
5265                 break;
5266         }
5267         for (; appcontrol; appcontrol = appcontrol->next) {
5268                 op = appcontrol->operation;
5269                 for (; op; op = op->next)
5270                         oc = oc + 1;
5271                 op = appcontrol->operation;
5272
5273                 ui = appcontrol->uri;
5274                 for (; ui; ui = ui->next)
5275                         uc = uc + 1;
5276                 ui = appcontrol->uri;
5277
5278                 mi = appcontrol->mime;
5279                 for (; mi; mi = mi->next)
5280                         mc = mc + 1;
5281                 mi = appcontrol->mime;
5282
5283                 sa = appcontrol->subapp;
5284                 for (; sa; sa = sa->next)
5285                         sc = sc + 1;
5286                 sa = appcontrol->subapp;
5287
5288                 operation = (char **)calloc(oc, sizeof(char *));
5289                 for (i = 0; i < oc; i++) {
5290                         operation[i] = strndup(op->name, PKG_STRING_LEN_MAX - 1);
5291                         op = op->next;
5292                 }
5293
5294                 uri = (char **)calloc(uc, sizeof(char *));
5295                 for (i = 0; i < uc; i++) {
5296                         uri[i] = strndup(ui->name, PKG_STRING_LEN_MAX - 1);
5297                         ui = ui->next;
5298                 }
5299
5300                 mime = (char **)calloc(mc, sizeof(char *));
5301                 for (i = 0; i < mc; i++) {
5302                         mime[i] = strndup(mi->name, PKG_STRING_LEN_MAX - 1);
5303                         mi = mi->next;
5304                 }
5305
5306                 subapp = (char **)calloc(sc, sizeof(char *));
5307                 for (i = 0; i < sc; i++) {
5308                         subapp[i] = strndup(sa->name, PKG_STRING_LEN_MAX - 1);
5309                         sa = sa->next;
5310                 }
5311
5312                 /*populate appcontrol handle*/
5313                 ptr->operation_count = oc;
5314                 ptr->uri_count = uc;
5315                 ptr->mime_count = mc;
5316                 ptr->subapp_count = sc;
5317                 ptr->operation = operation;
5318                 ptr->uri = uri;
5319                 ptr->mime = mime;
5320                 ptr->subapp = subapp;
5321
5322                 ret = appcontrol_func((void *)ptr, user_data);
5323                 for (i = 0; i < oc; i++) {
5324                         if (operation[i]) {
5325                                 free(operation[i]);
5326                                 operation[i] = NULL;
5327                         }
5328                 }
5329                 if (operation) {
5330                         free(operation);
5331                         operation = NULL;
5332                 }
5333                 for (i = 0; i < uc; i++) {
5334                         if (uri[i]) {
5335                                 free(uri[i]);
5336                                 uri[i] = NULL;
5337                         }
5338                 }
5339                 if (uri) {
5340                         free(uri);
5341                         uri = NULL;
5342                 }
5343                 for (i = 0; i < mc; i++) {
5344                         if (mime[i]) {
5345                                 free(mime[i]);
5346                                 mime[i] = NULL;
5347                         }
5348                 }
5349                 if (mime) {
5350                         free(mime);
5351                         mime = NULL;
5352                 }
5353                 for (i = 0; i < sc; i++) {
5354                         if (subapp[i]) {
5355                                 free(subapp[i]);
5356                                 subapp[i] = NULL;
5357                         }
5358                 }
5359                 if (subapp) {
5360                         free(subapp);
5361                         subapp = NULL;
5362                 }
5363                 if (ret < 0)
5364                         break;
5365                 uc = 0;
5366                 mc = 0;
5367                 oc = 0;
5368                 sc = 0;
5369         }
5370         pkgmgr_parser_free_manifest_xml(mfx);
5371         if (ptr) {
5372                 free(ptr);
5373                 ptr = NULL;
5374         }
5375         return PMINFO_R_OK;
5376 }
5377
5378 API int pkgmgrinfo_appinfo_is_nodisplay(pkgmgrinfo_appinfo_h  handle, bool *nodisplay)
5379 {
5380         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5381         retvm_if(nodisplay == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5382         char *val = NULL;
5383         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5384         val = (char *)info->uiapp_info->nodisplay;
5385         if (val) {
5386                 if (strcasecmp(val, "true") == 0)
5387                         *nodisplay = 1;
5388                 else if (strcasecmp(val, "false") == 0)
5389                         *nodisplay = 0;
5390                 else
5391                         *nodisplay = 0;
5392         }
5393         return PMINFO_R_OK;
5394 }
5395
5396 API int pkgmgrinfo_appinfo_is_multiple(pkgmgrinfo_appinfo_h  handle, bool *multiple)
5397 {
5398         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5399         retvm_if(multiple == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5400         char *val = NULL;
5401         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5402         val = (char *)info->uiapp_info->multiple;
5403         if (val) {
5404                 if (strcasecmp(val, "true") == 0)
5405                         *multiple = 1;
5406                 else if (strcasecmp(val, "false") == 0)
5407                         *multiple = 0;
5408                 else
5409                         *multiple = 0;
5410         }
5411         return PMINFO_R_OK;
5412 }
5413
5414 API int pkgmgrinfo_appinfo_is_indicator_display_allowed(pkgmgrinfo_appinfo_h handle, bool *indicator_disp)
5415 {
5416         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5417         retvm_if(indicator_disp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5418         char *val = NULL;
5419         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5420         val = (char *)info->uiapp_info->indicatordisplay;
5421         if (val) {
5422                 if (strcasecmp(val, "true") == 0){
5423                         *indicator_disp = 1;
5424                 }else if (strcasecmp(val, "false") == 0){
5425                         *indicator_disp = 0;
5426                 }else{
5427                         *indicator_disp = 0;
5428                 }
5429         }
5430         return PMINFO_R_OK;
5431 }
5432
5433 API int pkgmgrinfo_appinfo_is_taskmanage(pkgmgrinfo_appinfo_h  handle, bool *taskmanage)
5434 {
5435         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5436         retvm_if(taskmanage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5437         char *val = NULL;
5438         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5439         val = (char *)info->uiapp_info->taskmanage;
5440         if (val) {
5441                 if (strcasecmp(val, "true") == 0)
5442                         *taskmanage = 1;
5443                 else if (strcasecmp(val, "false") == 0)
5444                         *taskmanage = 0;
5445                 else
5446                         *taskmanage = 0;
5447         }
5448         return PMINFO_R_OK;
5449 }
5450
5451 API int pkgmgrinfo_appinfo_is_enabled(pkgmgrinfo_appinfo_h  handle, bool *enabled)
5452 {
5453         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5454         retvm_if(enabled == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5455         char *val = NULL;
5456         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5457         if (info->app_component == PMINFO_UI_APP)
5458                 val = (char *)info->uiapp_info->enabled;
5459         else if (info->app_component == PMINFO_SVC_APP)
5460                 val = (char *)info->uiapp_info->enabled;
5461         else {
5462                 _LOGE("invalid component type\n");
5463                 return PMINFO_R_EINVAL;
5464         }
5465
5466         if (val) {
5467                 if (strcasecmp(val, "true") == 0)
5468                         *enabled = 1;
5469                 else if (strcasecmp(val, "false") == 0)
5470                         *enabled = 0;
5471                 else
5472                         *enabled = 1;
5473         }
5474         return PMINFO_R_OK;
5475
5476 }
5477
5478 API int pkgmgrinfo_appinfo_is_onboot(pkgmgrinfo_appinfo_h  handle, bool *onboot)
5479 {
5480         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5481         retvm_if(onboot == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5482         char *val = NULL;
5483         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5484         val = (char *)info->svcapp_info->onboot;
5485         if (val) {
5486                 if (strcasecmp(val, "true") == 0)
5487                         *onboot = 1;
5488                 else if (strcasecmp(val, "false") == 0)
5489                         *onboot = 0;
5490                 else
5491                         *onboot = 0;
5492         }
5493         return PMINFO_R_OK;
5494 }
5495
5496 API int pkgmgrinfo_appinfo_is_autorestart(pkgmgrinfo_appinfo_h  handle, bool *autorestart)
5497 {
5498         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5499         retvm_if(autorestart == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5500         char *val = NULL;
5501         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5502         val = (char *)info->svcapp_info->autorestart;
5503         if (val) {
5504                 if (strcasecmp(val, "true") == 0)
5505                         *autorestart = 1;
5506                 else if (strcasecmp(val, "false") == 0)
5507                         *autorestart = 0;
5508                 else
5509                         *autorestart = 0;
5510         }
5511         return PMINFO_R_OK;
5512 }
5513
5514 API int pkgmgrinfo_appinfo_is_mainapp(pkgmgrinfo_appinfo_h  handle, bool *mainapp)
5515 {
5516         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5517         retvm_if(mainapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5518         char *val = NULL;
5519         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5520         val = (char *)info->uiapp_info->mainapp;
5521         if (val) {
5522                 if (strcasecmp(val, "true") == 0)
5523                         *mainapp = 1;
5524                 else if (strcasecmp(val, "false") == 0)
5525                         *mainapp = 0;
5526                 else
5527                         *mainapp = 0;
5528         }
5529         return PMINFO_R_OK;
5530 }
5531
5532 API int pkgmgrinfo_appinfo_is_preload(pkgmgrinfo_appinfo_h handle, bool *preload)
5533 {
5534         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
5535         retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5536         char *val = NULL;
5537         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5538         val = (char *)info->uiapp_info->preload;
5539         if (val) {
5540                 if (strcasecmp(val, "true") == 0)
5541                         *preload = 1;
5542                 else if (strcasecmp(val, "false") == 0)
5543                         *preload = 0;
5544                 else
5545                         *preload = 0;
5546         }
5547         return PMINFO_R_OK;
5548 }
5549
5550 API int pkgmgrinfo_appinfo_is_submode(pkgmgrinfo_appinfo_h handle, bool *submode)
5551 {
5552         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
5553         retvm_if(submode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5554         char *val = NULL;
5555         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5556         val = (char *)info->uiapp_info->submode;
5557         if (val) {
5558                 if (strcasecmp(val, "true") == 0)
5559                         *submode = 1;
5560                 else if (strcasecmp(val, "false") == 0)
5561                         *submode = 0;
5562                 else
5563                         *submode = 0;
5564         }
5565         return PMINFO_R_OK;
5566 }
5567
5568 API int pkgmgrinfo_appinfo_destroy_appinfo(pkgmgrinfo_appinfo_h  handle)
5569 {
5570         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5571         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5572         __cleanup_appinfo(info);
5573         return PMINFO_R_OK;
5574 }
5575
5576 API int pkgmgrinfo_appinfo_filter_create(pkgmgrinfo_appinfo_filter_h *handle)
5577 {
5578         return (pkgmgrinfo_pkginfo_filter_create(handle));
5579 }
5580
5581 API int pkgmgrinfo_appinfo_filter_destroy(pkgmgrinfo_appinfo_filter_h handle)
5582 {
5583         return (pkgmgrinfo_pkginfo_filter_destroy(handle));
5584 }
5585
5586 API int pkgmgrinfo_appinfo_filter_add_int(pkgmgrinfo_appinfo_filter_h handle,
5587                                 const char *property, const int value)
5588 {
5589         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5590         retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5591         char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
5592         char *val = NULL;
5593         GSList *link = NULL;
5594         int prop = -1;
5595         prop = _pminfo_appinfo_convert_to_prop_int(property);
5596         if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_INT ||
5597                 prop > E_PMINFO_APPINFO_PROP_APP_MAX_INT) {
5598                 _LOGE("Invalid Integer Property\n");
5599                 return PMINFO_R_EINVAL;
5600         }
5601         pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5602         pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
5603         if (node == NULL) {
5604                 _LOGE("Out of Memory!!!\n");
5605                 return PMINFO_R_ERROR;
5606         }
5607         snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
5608         val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
5609         if (val == NULL) {
5610                 _LOGE("Out of Memory\n");
5611                 free(node);
5612                 node = NULL;
5613                 return PMINFO_R_ERROR;
5614         }
5615         node->prop = prop;
5616         node->value = val;
5617         /*If API is called multiple times for same property, we should override the previous values.
5618         Last value set will be used for filtering.*/
5619         link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
5620         if (link)
5621                 filter->list = g_slist_delete_link(filter->list, link);
5622         filter->list = g_slist_append(filter->list, (gpointer)node);
5623         return PMINFO_R_OK;
5624
5625 }
5626
5627 API int pkgmgrinfo_appinfo_filter_add_bool(pkgmgrinfo_appinfo_filter_h handle,
5628                                 const char *property, const bool value)
5629 {
5630         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5631         retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5632         char *val = NULL;
5633         GSList *link = NULL;
5634         int prop = -1;
5635         prop = _pminfo_appinfo_convert_to_prop_bool(property);
5636         if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_BOOL ||
5637                 prop > E_PMINFO_APPINFO_PROP_APP_MAX_BOOL) {
5638                 _LOGE("Invalid Boolean Property\n");
5639                 return PMINFO_R_EINVAL;
5640         }
5641         pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5642         pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
5643         if (node == NULL) {
5644                 _LOGE("Out of Memory!!!\n");
5645                 return PMINFO_R_ERROR;
5646         }
5647         if (value)
5648                 val = strndup("('true','True')", 15);
5649         else
5650                 val = strndup("('false','False')", 17);
5651         if (val == NULL) {
5652                 _LOGE("Out of Memory\n");
5653                 free(node);
5654                 node = NULL;
5655                 return PMINFO_R_ERROR;
5656         }
5657         node->prop = prop;
5658         node->value = val;
5659         /*If API is called multiple times for same property, we should override the previous values.
5660         Last value set will be used for filtering.*/
5661         link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
5662         if (link)
5663                 filter->list = g_slist_delete_link(filter->list, link);
5664         filter->list = g_slist_append(filter->list, (gpointer)node);
5665         return PMINFO_R_OK;
5666
5667 }
5668
5669 API int pkgmgrinfo_appinfo_filter_add_string(pkgmgrinfo_appinfo_filter_h handle,
5670                                 const char *property, const char *value)
5671 {
5672         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5673         retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5674         retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5675         char *val = NULL;
5676         pkgmgrinfo_node_x *ptr = NULL;
5677         char prev[PKG_STRING_LEN_MAX] = {'\0'};
5678         char temp[PKG_STRING_LEN_MAX] = {'\0'};
5679         GSList *link = NULL;
5680         int prop = -1;
5681         prop = _pminfo_appinfo_convert_to_prop_str(property);
5682         if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_STR ||
5683                 prop > E_PMINFO_APPINFO_PROP_APP_MAX_STR) {
5684                 _LOGE("Invalid String Property\n");
5685                 return PMINFO_R_EINVAL;
5686         }
5687         pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5688         pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
5689         if (node == NULL) {
5690                 _LOGE("Out of Memory!!!\n");
5691                 return PMINFO_R_ERROR;
5692         }
5693         node->prop = prop;
5694         switch (prop) {
5695         case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
5696                 if (strcmp(value, PMINFO_APPINFO_UI_APP) == 0)
5697                         val = strndup("uiapp", PKG_STRING_LEN_MAX - 1);
5698                 else
5699                         val = strndup("svcapp", PKG_STRING_LEN_MAX - 1);
5700                 node->value = val;
5701                 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
5702                 if (link)
5703                         filter->list = g_slist_delete_link(filter->list, link);
5704                 filter->list = g_slist_append(filter->list, (gpointer)node);
5705                 break;
5706         case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
5707         case E_PMINFO_APPINFO_PROP_APP_OPERATION:
5708         case E_PMINFO_APPINFO_PROP_APP_URI:
5709         case E_PMINFO_APPINFO_PROP_APP_MIME:
5710                 val = (char *)calloc(1, PKG_STRING_LEN_MAX);
5711                 if (val == NULL) {
5712                         _LOGE("Out of Memory\n");
5713                         free(node);
5714                         node = NULL;
5715                         return PMINFO_R_ERROR;
5716                 }
5717                 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
5718                 if (link) {
5719                         ptr = (pkgmgrinfo_node_x *)link->data;
5720                         strncpy(prev, ptr->value, PKG_STRING_LEN_MAX - 1);
5721                         _LOGS("Previous value is %s\n", prev);
5722                         filter->list = g_slist_delete_link(filter->list, link);
5723                         snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s , '%s'", prev, value);
5724                         strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
5725                         _LOGS("New value is %s\n", val);
5726                         node->value = val;
5727                         filter->list = g_slist_append(filter->list, (gpointer)node);
5728                         memset(temp, '\0', PKG_STRING_LEN_MAX);
5729                 } else {
5730                         snprintf(temp, PKG_STRING_LEN_MAX - 1, "'%s'", value);
5731                         strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
5732                         _LOGS("First value is %s\n", val);
5733                         node->value = val;
5734                         filter->list = g_slist_append(filter->list, (gpointer)node);
5735                         memset(temp, '\0', PKG_STRING_LEN_MAX);
5736                 }
5737                 break;
5738         default:
5739                 node->value = strndup(value, PKG_STRING_LEN_MAX - 1);
5740                 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
5741                 if (link)
5742                         filter->list = g_slist_delete_link(filter->list, link);
5743                 filter->list = g_slist_append(filter->list, (gpointer)node);
5744                 break;
5745         }
5746         return PMINFO_R_OK;
5747 }
5748
5749 API int pkgmgrinfo_appinfo_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count)
5750 {
5751         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5752         retvm_if(count == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5753         char *syslocale = NULL;
5754         char *locale = NULL;
5755         char *condition = NULL;
5756         char query[MAX_QUERY_LEN] = {'\0'};
5757         char where[MAX_QUERY_LEN] = {'\0'};
5758         GSList *list;
5759         int ret = 0;
5760         uiapplication_x *ptr1 = NULL;
5761         serviceapplication_x *ptr2 = NULL;
5762         pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5763         sqlite3 *pkginfo_db = NULL;
5764         int filter_count = 0;
5765
5766         /*open db*/
5767         ret = db_util_open(MANIFEST_DB, &pkginfo_db, 0);
5768         retvm_if(ret != SQLITE_OK, PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
5769
5770         /*get system locale*/
5771         syslocale = vconf_get_str(VCONFKEY_LANGSET);
5772         locale = __convert_system_locale_to_manifest_locale(syslocale);
5773         tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
5774
5775         /*Start constructing query*/
5776         snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_LIST_APP, locale);
5777         /*Get where clause*/
5778         for (list = filter->list; list; list = g_slist_next(list)) {
5779                 __get_filter_condition(list->data, &condition);
5780                 if (condition) {
5781                         strncat(where, condition, sizeof(where) - strlen(where) -1);
5782                         where[sizeof(where) - 1] = '\0';
5783                         free(condition);
5784                         condition = NULL;
5785                 }
5786                 if (g_slist_next(list)) {
5787                         strncat(where, " and ", sizeof(where) - strlen(where) - 1);
5788                         where[sizeof(where) - 1] = '\0';
5789                 }
5790         }
5791         _LOGS("where = %s\n", where);
5792         if (strlen(where) > 0) {
5793                 strncat(query, where, sizeof(query) - strlen(query) - 1);
5794                 query[sizeof(query) - 1] = '\0';
5795         }
5796         _LOGS("query = %s\n", query);
5797         /*To get filtered list*/
5798         pkgmgr_pkginfo_x *info = NULL;
5799         info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
5800         tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5801
5802         info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
5803         tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5804
5805         /*To get detail app info for each member of filtered list*/
5806         pkgmgr_pkginfo_x *filtinfo = NULL;
5807         filtinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
5808         tryvm_if(filtinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5809
5810         filtinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
5811         tryvm_if(filtinfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5812
5813         pkgmgr_appinfo_x *appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
5814         tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5815
5816         ret = __exec_db_query(pkginfo_db, query, __app_list_cb, (void *)info);
5817         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
5818
5819         memset(query, '\0', MAX_QUERY_LEN);
5820         if (info->manifest_info->uiapplication) {
5821                 LISTHEAD(info->manifest_info->uiapplication, ptr1);
5822                 info->manifest_info->uiapplication = ptr1;
5823         }
5824         if (info->manifest_info->serviceapplication) {
5825                 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
5826                 info->manifest_info->serviceapplication = ptr2;
5827         }
5828         /*Filtered UI Apps*/
5829         for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
5830         {
5831                 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
5832                                                         ptr1->appid, "uiapp");
5833                 ret = __exec_db_query(pkginfo_db, query, __uiapp_list_cb, (void *)filtinfo);
5834                 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
5835         }
5836         for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
5837         {
5838                 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
5839                                                         ptr2->appid, "svcapp");
5840                 ret = __exec_db_query(pkginfo_db, query, __svcapp_list_cb, (void *)filtinfo);
5841                 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
5842         }
5843         if (filtinfo->manifest_info->uiapplication) {
5844                 LISTHEAD(filtinfo->manifest_info->uiapplication, ptr1);
5845                 filtinfo->manifest_info->uiapplication = ptr1;
5846         }
5847         /*If the callback func return < 0 we break and no more call back is called*/
5848         while(ptr1 != NULL)
5849         {
5850                 appinfo->locale = strdup(locale);
5851                 appinfo->uiapp_info = ptr1;
5852                 appinfo->app_component = PMINFO_UI_APP;
5853
5854                 ret = __appinfo_check_installed_storage(appinfo);
5855                 if(ret < 0) {
5856                         ptr1 = ptr1->next;
5857                         continue;
5858                 }
5859
5860                 filter_count++;
5861
5862                 ptr1 = ptr1->next;
5863         }
5864         /*Filtered Service Apps*/
5865         if (filtinfo->manifest_info->serviceapplication) {
5866                 LISTHEAD(filtinfo->manifest_info->serviceapplication, ptr2);
5867                 filtinfo->manifest_info->serviceapplication = ptr2;
5868         }
5869         /*If the callback func return < 0 we break and no more call back is called*/
5870         while(ptr2 != NULL)
5871         {
5872                 appinfo->locale = strdup(locale);
5873                 appinfo->svcapp_info = ptr2;
5874                 appinfo->app_component = PMINFO_SVC_APP;
5875                 filter_count++;
5876                 ptr2 = ptr2->next;
5877         }
5878         *count = filter_count;
5879
5880         ret = PMINFO_R_OK;
5881 catch:
5882         if (locale) {
5883                 free(locale);
5884                 locale = NULL;
5885         }
5886         if (syslocale) {
5887                 free(syslocale);
5888                 syslocale = NULL;
5889         }
5890         sqlite3_close(pkginfo_db);
5891         if (appinfo) {
5892                 free(appinfo);
5893                 appinfo = NULL;
5894         }
5895         __cleanup_pkginfo(info);
5896         __cleanup_pkginfo(filtinfo);
5897         return ret;
5898 }
5899
5900 API int pkgmgrinfo_appinfo_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h handle,
5901                                 pkgmgrinfo_app_list_cb app_cb, void * user_data)
5902 {
5903         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5904         retvm_if(app_cb == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5905         char *syslocale = NULL;
5906         char *locale = NULL;
5907         char *condition = NULL;
5908         char query[MAX_QUERY_LEN] = {'\0'};
5909         char where[MAX_QUERY_LEN] = {'\0'};
5910         GSList *list;
5911         int ret = 0;
5912         uiapplication_x *ptr1 = NULL;
5913         serviceapplication_x *ptr2 = NULL;
5914         pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5915         sqlite3 *pkginfo_db = NULL;
5916
5917         /*open db*/
5918         ret = db_util_open(MANIFEST_DB, &pkginfo_db, 0);
5919         retvm_if(ret != SQLITE_OK, PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
5920
5921         /*get system locale*/
5922         syslocale = vconf_get_str(VCONFKEY_LANGSET);
5923         locale = __convert_system_locale_to_manifest_locale(syslocale);
5924         tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
5925
5926         /*Start constructing query*/
5927         snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_LIST_APP, locale);
5928         /*Get where clause*/
5929         for (list = filter->list; list; list = g_slist_next(list)) {
5930                 __get_filter_condition(list->data, &condition);
5931                 if (condition) {
5932                         strncat(where, condition, sizeof(where) - strlen(where) -1);
5933                         where[sizeof(where) - 1] = '\0';
5934                         free(condition);
5935                         condition = NULL;
5936                 }
5937                 if (g_slist_next(list)) {
5938                         strncat(where, " and ", sizeof(where) - strlen(where) - 1);
5939                         where[sizeof(where) - 1] = '\0';
5940                 }
5941         }
5942         _LOGS("where = %s\n", where);
5943         if (strlen(where) > 0) {
5944                 strncat(query, where, sizeof(query) - strlen(query) - 1);
5945                 query[sizeof(query) - 1] = '\0';
5946         }
5947         _LOGS("query = %s\n", query);
5948         /*To get filtered list*/
5949         pkgmgr_pkginfo_x *info = NULL;
5950         info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
5951         tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5952
5953         info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
5954         tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5955
5956         /*To get detail app info for each member of filtered list*/
5957         pkgmgr_pkginfo_x *filtinfo = NULL;
5958         filtinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
5959         tryvm_if(filtinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5960
5961         filtinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
5962         tryvm_if(filtinfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5963
5964         pkgmgr_appinfo_x *appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
5965         tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5966
5967         ret = __exec_db_query(pkginfo_db, query, __app_list_cb, (void *)info);
5968         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
5969
5970         memset(query, '\0', MAX_QUERY_LEN);
5971         if (info->manifest_info->uiapplication) {
5972                 LISTHEAD(info->manifest_info->uiapplication, ptr1);
5973                 info->manifest_info->uiapplication = ptr1;
5974         }
5975         if (info->manifest_info->serviceapplication) {
5976                 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
5977                 info->manifest_info->serviceapplication = ptr2;
5978         }
5979         /*Filtered UI Apps*/
5980         for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
5981         {
5982                 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
5983                                                         ptr1->appid, "uiapp");
5984                 ret = __exec_db_query(pkginfo_db, query, __uiapp_list_cb, (void *)filtinfo);
5985                 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
5986         }
5987         for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
5988         {
5989                 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
5990                                                         ptr2->appid, "svcapp");
5991                 ret = __exec_db_query(pkginfo_db, query, __svcapp_list_cb, (void *)filtinfo);
5992                 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
5993         }
5994         if (filtinfo->manifest_info->uiapplication) {
5995                 LISTHEAD(filtinfo->manifest_info->uiapplication, ptr1);
5996                 filtinfo->manifest_info->uiapplication = ptr1;
5997         }
5998         /*If the callback func return < 0 we break and no more call back is called*/
5999         while(ptr1 != NULL)
6000         {
6001                 appinfo->locale = strdup(locale);
6002                 appinfo->uiapp_info = ptr1;
6003                 appinfo->app_component = PMINFO_UI_APP;
6004
6005                 ret = __appinfo_check_installed_storage(appinfo);
6006                 if(ret < 0) {
6007                         ptr1 = ptr1->next;
6008                         continue;
6009                 }
6010
6011                 ret = app_cb((void *)appinfo, user_data);
6012                 if (ret < 0)
6013                         break;
6014                 ptr1 = ptr1->next;
6015         }
6016         /*Filtered Service Apps*/
6017         if (filtinfo->manifest_info->serviceapplication) {
6018                 LISTHEAD(filtinfo->manifest_info->serviceapplication, ptr2);
6019                 filtinfo->manifest_info->serviceapplication = ptr2;
6020         }
6021         /*If the callback func return < 0 we break and no more call back is called*/
6022         while(ptr2 != NULL)
6023         {
6024                 appinfo->locale = strdup(locale);
6025                 appinfo->svcapp_info = ptr2;
6026                 appinfo->app_component = PMINFO_SVC_APP;
6027                 ret = app_cb((void *)appinfo, user_data);
6028                 if (ret < 0)
6029                         break;
6030                 ptr2 = ptr2->next;
6031         }
6032         ret = PMINFO_R_OK;
6033 catch:
6034         if (locale) {
6035                 free(locale);
6036                 locale = NULL;
6037         }
6038         if (syslocale) {
6039                 free(syslocale);
6040                 syslocale = NULL;
6041         }
6042         sqlite3_close(pkginfo_db);
6043         if (appinfo) {
6044                 free(appinfo);
6045                 appinfo = NULL;
6046         }
6047         __cleanup_pkginfo(info);
6048         __cleanup_pkginfo(filtinfo);
6049         return ret;
6050 }
6051
6052 API int pkgmgrinfo_appinfo_metadata_filter_create(pkgmgrinfo_appinfo_metadata_filter_h *handle)
6053 {
6054         return (pkgmgrinfo_pkginfo_filter_create(handle));
6055 }
6056
6057 API int pkgmgrinfo_appinfo_metadata_filter_destroy(pkgmgrinfo_appinfo_metadata_filter_h handle)
6058 {
6059         return (pkgmgrinfo_pkginfo_filter_destroy(handle));
6060 }
6061
6062 API int pkgmgrinfo_appinfo_metadata_filter_add(pkgmgrinfo_appinfo_metadata_filter_h handle,
6063                 const char *key, const char *value)
6064 {
6065         retvm_if(handle == NULL, PMINFO_R_EINVAL, "filter handle is NULL\n");
6066         retvm_if(key == NULL, PMINFO_R_EINVAL, "metadata key supplied is NULL\n");
6067         /*value can be NULL. In that case all apps with specified key should be displayed*/
6068         int ret = 0;
6069         char *k = NULL;
6070         char *v = NULL;
6071         pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6072         pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
6073         retvm_if(node == NULL, PMINFO_R_ERROR, "Out of Memory!!!\n");
6074         k = strdup(key);
6075         tryvm_if(k == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
6076         node->key = k;
6077         if (value) {
6078                 v = strdup(value);
6079                 tryvm_if(v == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
6080         }
6081         node->value = v;
6082         /*If API is called multiple times, we should OR all conditions.*/
6083         filter->list = g_slist_append(filter->list, (gpointer)node);
6084         /*All memory will be freed in destroy API*/
6085         return PMINFO_R_OK;
6086 catch:
6087         if (node) {
6088                 if (node->key) {
6089                         free(node->key);
6090                         node->key = NULL;
6091                 }
6092                 if (node->value) {
6093                         free(node->value);
6094                         node->value = NULL;
6095                 }
6096                 free(node);
6097                 node = NULL;
6098         }
6099         return ret;
6100 }
6101
6102 API int pkgmgrinfo_appinfo_metadata_filter_foreach(pkgmgrinfo_appinfo_metadata_filter_h handle,
6103                 pkgmgrinfo_app_list_cb app_cb, void *user_data)
6104 {
6105         retvm_if(handle == NULL, PMINFO_R_EINVAL, "filter handle is NULL\n");
6106         retvm_if(app_cb == NULL, PMINFO_R_EINVAL, "Callback function supplied is NULL\n");
6107         char *syslocale = NULL;
6108         char *locale = NULL;
6109         char *condition = NULL;
6110         char *error_message = NULL;
6111         char query[MAX_QUERY_LEN] = {'\0'};
6112         char where[MAX_QUERY_LEN] = {'\0'};
6113         GSList *list;
6114         int ret = 0;
6115         pkgmgr_pkginfo_x *info = NULL;
6116         pkgmgr_pkginfo_x *filtinfo = NULL;
6117         pkgmgr_appinfo_x *appinfo = NULL;
6118         uiapplication_x *ptr1 = NULL;
6119         serviceapplication_x *ptr2 = NULL;
6120         pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6121         sqlite3 *pkginfo_db = NULL;
6122
6123         /*open db*/
6124         ret = db_util_open(MANIFEST_DB, &pkginfo_db, 0);
6125         retvm_if(ret != SQLITE_OK, PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
6126
6127         /*Get current locale*/
6128         syslocale = vconf_get_str(VCONFKEY_LANGSET);
6129         locale = __convert_system_locale_to_manifest_locale(syslocale);
6130         tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL\n");
6131
6132         /*Start constructing query*/
6133         memset(where, '\0', MAX_QUERY_LEN);
6134         memset(query, '\0', MAX_QUERY_LEN);
6135         snprintf(query, MAX_QUERY_LEN - 1, METADATA_FILTER_QUERY_SELECT_CLAUSE);
6136         /*Get where clause*/
6137         for (list = filter->list; list; list = g_slist_next(list)) {
6138                 __get_metadata_filter_condition(list->data, &condition);
6139                 if (condition) {
6140                         strncat(where, condition, sizeof(where) - strlen(where) -1);
6141                         free(condition);
6142                         condition = NULL;
6143                 }
6144                 if (g_slist_next(list)) {
6145                         strncat(where, METADATA_FILTER_QUERY_UNION_CLAUSE, sizeof(where) - strlen(where) - 1);
6146                 }
6147         }
6148         _LOGE("where = %s (%d)\n", where, strlen(where));
6149         if (strlen(where) > 0) {
6150                 strncat(query, where, sizeof(query) - strlen(query) - 1);
6151         }
6152         _LOGE("query = %s (%d)\n", query, strlen(query));
6153         /*To get filtered list*/
6154         info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
6155         tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
6156
6157         info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
6158         tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
6159
6160         /*To get detail app info for each member of filtered list*/
6161         filtinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
6162         tryvm_if(filtinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
6163
6164         filtinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
6165         tryvm_if(filtinfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
6166
6167         appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
6168         tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
6169
6170         ret = sqlite3_exec(pkginfo_db, query, __app_list_cb, (void *)info, &error_message);
6171         tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
6172         memset(query, '\0', MAX_QUERY_LEN);
6173
6174         if (info->manifest_info->uiapplication) {
6175                 LISTHEAD(info->manifest_info->uiapplication, ptr1);
6176                 info->manifest_info->uiapplication = ptr1;
6177         }
6178         if (info->manifest_info->serviceapplication) {
6179                 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
6180                 info->manifest_info->serviceapplication = ptr2;
6181         }
6182
6183         /*UI Apps*/
6184         for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
6185         {
6186                 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
6187                                                         ptr1->appid, "uiapp");
6188                 ret = sqlite3_exec(pkginfo_db, query, __uiapp_list_cb, (void *)filtinfo, &error_message);
6189                 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
6190                 memset(query, '\0', MAX_QUERY_LEN);
6191         }
6192         /*Service Apps*/
6193         for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
6194         {
6195                 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
6196                                                         ptr2->appid, "svcapp");
6197                 ret = sqlite3_exec(pkginfo_db, query, __svcapp_list_cb, (void *)filtinfo, &error_message);
6198                 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
6199                 memset(query, '\0', MAX_QUERY_LEN);
6200         }
6201         /*Filtered UI Apps*/
6202         if (filtinfo->manifest_info->uiapplication) {
6203                 LISTHEAD(filtinfo->manifest_info->uiapplication, ptr1);
6204                 filtinfo->manifest_info->uiapplication = ptr1;
6205         }
6206         /*If the callback func return < 0 we break and no more call back is called*/
6207         while(ptr1 != NULL)
6208         {
6209                 appinfo->locale = strdup(locale);
6210                 appinfo->uiapp_info = ptr1;
6211                 appinfo->app_component = PMINFO_UI_APP;
6212                 ret = app_cb((void *)appinfo, user_data);
6213                 if (ret < 0)
6214                         break;
6215                 ptr1 = ptr1->next;
6216         }
6217         /*Filtered Service Apps*/
6218         if (filtinfo->manifest_info->serviceapplication) {
6219                 LISTHEAD(filtinfo->manifest_info->serviceapplication, ptr2);
6220                 filtinfo->manifest_info->serviceapplication = ptr2;
6221         }
6222         /*If the callback func return < 0 we break and no more call back is called*/
6223         while(ptr2 != NULL)
6224         {
6225                 appinfo->locale = strdup(locale);
6226                 appinfo->svcapp_info = ptr2;
6227                 appinfo->app_component = PMINFO_SVC_APP;
6228                 ret = app_cb((void *)appinfo, user_data);
6229                 if (ret < 0)
6230                         break;
6231                 ptr2 = ptr2->next;
6232         }
6233         ret = PMINFO_R_OK;
6234 catch:
6235         if (locale) {
6236                 free(locale);
6237                 locale = NULL;
6238         }
6239         if (syslocale) {
6240                 free(syslocale);
6241                 syslocale = NULL;
6242         }
6243         sqlite3_free(error_message);
6244         sqlite3_close(pkginfo_db);
6245         if (appinfo) {
6246                 free(appinfo);
6247                 appinfo = NULL;
6248         }
6249         __cleanup_pkginfo(info);
6250         __cleanup_pkginfo(filtinfo);
6251         return ret;
6252 }
6253
6254 API int pkgmgrinfo_pkginfo_create_certinfo(pkgmgrinfo_certinfo_h *handle)
6255 {
6256         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
6257         pkgmgr_certinfo_x *certinfo = NULL;
6258         certinfo = calloc(1, sizeof(pkgmgr_certinfo_x));
6259         retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
6260         *handle = (void *)certinfo;
6261         return PMINFO_R_OK;
6262 }
6263
6264 API int pkgmgrinfo_pkginfo_load_certinfo(const char *pkgid, pkgmgrinfo_certinfo_h handle)
6265 {
6266         retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "package ID is NULL\n");
6267         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Certinfo handle is NULL\n");
6268         pkgmgr_certinfo_x *certinfo = NULL;
6269         char *error_message = NULL;
6270         int ret = PMINFO_R_OK;
6271         char query[MAX_QUERY_LEN] = {'\0'};
6272         int exist = 0;
6273         int i = 0;
6274
6275         /*Open db.*/
6276         ret = db_util_open_with_options(CERT_DB, &cert_db, SQLITE_OPEN_READONLY, NULL);
6277         if (ret != SQLITE_OK) {
6278                 _LOGE("connect db [%s] failed!\n", CERT_DB);
6279                 return PMINFO_R_ERROR;
6280         }
6281         /*validate pkgid*/
6282         snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", pkgid);
6283         if (SQLITE_OK !=
6284             sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
6285                 _LOGE("Don't execute query = %s error message = %s\n", query,
6286                        error_message);
6287                 sqlite3_free(error_message);
6288                 ret = PMINFO_R_ERROR;
6289                 goto err;
6290         }
6291         if (exist == 0) {
6292                 _LOGE("Package not found in DB\n");
6293                 ret = PMINFO_R_ERROR;
6294                 goto err;
6295         }
6296         certinfo = (pkgmgr_certinfo_x *)handle;
6297         /*populate certinfo from DB*/
6298         snprintf(query, MAX_QUERY_LEN, "select * from package_cert_info where package='%s' ", pkgid);
6299         ret = __exec_certinfo_query(query, (void *)certinfo);
6300         if (ret == -1) {
6301                 _LOGE("Package Cert Info DB Information retrieval failed\n");
6302                 ret = PMINFO_R_ERROR;
6303                 goto err;
6304         }
6305         for (i = 0; i < MAX_CERT_TYPE; i++) {
6306                 memset(query, '\0', MAX_QUERY_LEN);
6307                 snprintf(query, MAX_QUERY_LEN, "select cert_info from package_cert_index_info where cert_id=%d ", (certinfo->cert_id)[i]);
6308                 ret = __exec_certinfo_query(query, (void *)certinfo);
6309                 if (ret == -1) {
6310                         _LOGE("Cert Info DB Information retrieval failed\n");
6311                         ret = PMINFO_R_ERROR;
6312                         goto err;
6313                 }
6314                 if (certinfo->cert_value) {
6315                         (certinfo->cert_info)[i] = strdup(certinfo->cert_value);
6316                         free(certinfo->cert_value);
6317                         certinfo->cert_value = NULL;
6318                 }
6319         }
6320 err:
6321         sqlite3_close(cert_db);
6322         return ret;
6323 }
6324
6325 API int pkgmgrinfo_pkginfo_get_cert_value(pkgmgrinfo_certinfo_h handle, pkgmgrinfo_cert_type cert_type, const char **cert_value)
6326 {
6327         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
6328         retvm_if(cert_value == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
6329         retvm_if(cert_type < PMINFO_AUTHOR_ROOT_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
6330         retvm_if(cert_type > PMINFO_DISTRIBUTOR2_SIGNER_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
6331         pkgmgr_certinfo_x *certinfo = NULL;
6332         certinfo = (pkgmgr_certinfo_x *)handle;
6333         if ((certinfo->cert_info)[cert_type])
6334                 *cert_value = (certinfo->cert_info)[cert_type];
6335         else
6336                 *cert_value = NULL;
6337         return PMINFO_R_OK;
6338 }
6339
6340 API int pkgmgrinfo_pkginfo_destroy_certinfo(pkgmgrinfo_certinfo_h handle)
6341 {
6342         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
6343         int i = 0;
6344         pkgmgr_certinfo_x *certinfo = NULL;
6345         certinfo = (pkgmgr_certinfo_x *)handle;
6346         if (certinfo->pkgid) {
6347                 free(certinfo->pkgid);
6348                 certinfo->pkgid = NULL;
6349         }
6350         for (i = 0; i < MAX_CERT_TYPE; i++) {
6351                 if ((certinfo->cert_info)[i]) {
6352                         free((certinfo->cert_info)[i]);
6353                         (certinfo->cert_info)[i] = NULL;
6354                 }
6355         }
6356         free(certinfo);
6357         certinfo = NULL;
6358         return PMINFO_R_OK;
6359 }
6360
6361 API int pkgmgrinfo_create_certinfo_set_handle(pkgmgrinfo_instcertinfo_h *handle)
6362 {
6363         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
6364         pkgmgr_instcertinfo_x *certinfo = NULL;
6365         certinfo = calloc(1, sizeof(pkgmgr_instcertinfo_x));
6366         retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
6367         *handle = (void *)certinfo;
6368         return PMINFO_R_OK;
6369 }
6370
6371 API int pkgmgrinfo_set_cert_value(pkgmgrinfo_instcertinfo_h handle, pkgmgrinfo_instcert_type cert_type, char *cert_value)
6372 {
6373         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
6374         retvm_if(cert_value == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
6375         retvm_if(cert_type < PMINFO_SET_AUTHOR_ROOT_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
6376         retvm_if(cert_type > PMINFO_SET_DISTRIBUTOR2_SIGNER_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
6377         pkgmgr_instcertinfo_x *certinfo = NULL;
6378         certinfo = (pkgmgr_instcertinfo_x *)handle;
6379         (certinfo->cert_info)[cert_type] = strdup(cert_value);
6380         return PMINFO_R_OK;
6381 }
6382
6383 API int pkgmgrinfo_save_certinfo(const char *pkgid, pkgmgrinfo_instcertinfo_h handle)
6384 {
6385         retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "package ID is NULL\n");
6386         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Certinfo handle is NULL\n");
6387         char *error_message = NULL;
6388         char query[MAX_QUERY_LEN] = {'\0'};
6389         char *vquery = NULL;
6390         int len = 0;
6391         int i = 0;
6392         int j = 0;
6393         int c = 0;
6394         int unique_id[MAX_CERT_TYPE] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
6395         int newid = 0;
6396         int is_new = 0;
6397         int exist = -1;
6398         int ret = -1;
6399         int maxid = 0;
6400         int flag = 0;
6401         pkgmgr_instcertinfo_x *info = (pkgmgr_instcertinfo_x *)handle;
6402         pkgmgr_certindexinfo_x *indexinfo = NULL;
6403         indexinfo = calloc(1, sizeof(pkgmgr_certindexinfo_x));
6404         if (indexinfo == NULL) {
6405                 _LOGE("Out of Memory!!!");
6406                 return PMINFO_R_ERROR;
6407         }
6408         info->pkgid = strdup(pkgid);
6409
6410         /*Open db.*/
6411         ret = db_util_open_with_options(CERT_DB, &cert_db, SQLITE_OPEN_READWRITE, NULL);
6412         if (ret != SQLITE_OK) {
6413                 _LOGE("connect db [%s] failed!\n", CERT_DB);
6414                 ret = PMINFO_R_ERROR;
6415                 goto err;
6416         }
6417         /*Begin Transaction*/
6418         ret = sqlite3_exec(cert_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
6419         if (ret != SQLITE_OK) {
6420                 _LOGE("Failed to begin transaction\n");
6421                 ret = PMINFO_R_ERROR;
6422                 goto err;
6423         }
6424         _LOGE("Transaction Begin\n");
6425         /*Check if request is to insert/update*/
6426         snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", pkgid);
6427         if (SQLITE_OK !=
6428             sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
6429                 _LOGE("Don't execute query = %s error message = %s\n", query,
6430                        error_message);
6431                 sqlite3_free(error_message);
6432                 ret = PMINFO_R_ERROR;
6433                 goto err;
6434         }
6435         if (exist) {
6436                 /*Update request.
6437                 We cant just issue update query directly. We need to manage index table also.
6438                 Hence it is better to delete and insert again in case of update*/
6439                 ret = __delete_certinfo(pkgid);
6440                 if (ret < 0)
6441                         _LOGE("Certificate Deletion Failed\n");
6442         }
6443         for (i = 0; i < MAX_CERT_TYPE; i++) {
6444                 if ((info->cert_info)[i]) {
6445                         for (j = 0; j < i; j++) {
6446                                 if ( (info->cert_info)[j]) {
6447                                         if (strcmp((info->cert_info)[i], (info->cert_info)[j]) == 0) {
6448                                                 (info->cert_id)[i] = (info->cert_id)[j];
6449                                                 (info->is_new)[i] = 0;
6450                                                 (info->ref_count)[i] = (info->ref_count)[j];
6451                                                 break;
6452                                         }
6453                                 }
6454                         }
6455                         if (j < i)
6456                                 continue;
6457                         memset(query, '\0', MAX_QUERY_LEN);
6458                         snprintf(query, MAX_QUERY_LEN, "select * from package_cert_index_info " \
6459                                 "where cert_info='%s'",(info->cert_info)[i]);
6460                         ret = __exec_certindexinfo_query(query, (void *)indexinfo);
6461                         if (ret == -1) {
6462                                 _LOGE("Cert Info DB Information retrieval failed\n");
6463                                 ret = PMINFO_R_ERROR;
6464                                 goto err;
6465                         }
6466                         if (indexinfo->cert_id == 0) {
6467                                 /*New certificate. Get newid*/
6468                                 memset(query, '\0', MAX_QUERY_LEN);
6469                                 snprintf(query, MAX_QUERY_LEN, "select MAX(cert_id) from package_cert_index_info ");
6470                                 if (SQLITE_OK !=
6471                                     sqlite3_exec(cert_db, query, __maxid_cb, (void *)&newid, &error_message)) {
6472                                         _LOGE("Don't execute query = %s error message = %s\n", query,
6473                                                error_message);
6474                                         sqlite3_free(error_message);
6475                                         ret = PMINFO_R_ERROR;
6476                                         goto err;
6477                                 }
6478                                 newid = newid + 1;
6479                                 if (flag == 0) {
6480                                         maxid = newid;
6481                                         flag = 1;
6482                                 }
6483                                 indexinfo->cert_id = maxid;
6484                                 indexinfo->cert_ref_count = 1;
6485                                 is_new = 1;
6486                                 maxid = maxid + 1;
6487                         }
6488                         (info->cert_id)[i] = indexinfo->cert_id;
6489                         (info->is_new)[i] = is_new;
6490                         (info->ref_count)[i] = indexinfo->cert_ref_count;
6491                         _LOGE("Id:Count = %d %d\n", indexinfo->cert_id, indexinfo->cert_ref_count);
6492                         indexinfo->cert_id = 0;
6493                         indexinfo->cert_ref_count = 0;
6494                         is_new = 0;
6495                 }
6496         }
6497         len = MAX_QUERY_LEN;
6498         for (i = 0; i < MAX_CERT_TYPE; i++) {
6499                 if ((info->cert_info)[i])
6500                         len+= strlen((info->cert_info)[i]);
6501         }
6502         vquery = (char *)calloc(1, len);
6503         /*insert*/
6504         snprintf(vquery, len,
6505                  "insert into package_cert_info(package, author_root_cert, author_im_cert, author_signer_cert, dist_root_cert, " \
6506                 "dist_im_cert, dist_signer_cert, dist2_root_cert, dist2_im_cert, dist2_signer_cert) " \
6507                 "values('%s', %d, %d, %d, %d, %d, %d, %d, %d, %d)",\
6508                  info->pkgid,(info->cert_id)[PMINFO_SET_AUTHOR_ROOT_CERT],(info->cert_id)[PMINFO_SET_AUTHOR_INTERMEDIATE_CERT],
6509                 (info->cert_id)[PMINFO_SET_AUTHOR_SIGNER_CERT], (info->cert_id)[PMINFO_SET_DISTRIBUTOR_ROOT_CERT],
6510                 (info->cert_id)[PMINFO_SET_DISTRIBUTOR_INTERMEDIATE_CERT], (info->cert_id)[PMINFO_SET_DISTRIBUTOR_SIGNER_CERT],
6511                 (info->cert_id)[PMINFO_SET_DISTRIBUTOR2_ROOT_CERT],(info->cert_id)[PMINFO_SET_DISTRIBUTOR2_INTERMEDIATE_CERT],
6512                 (info->cert_id)[PMINFO_SET_DISTRIBUTOR2_SIGNER_CERT]);
6513         if (SQLITE_OK !=
6514             sqlite3_exec(cert_db, vquery, NULL, NULL, &error_message)) {
6515                 _LOGE("Don't execute query = %s error message = %s\n", vquery,
6516                        error_message);
6517                 sqlite3_free(error_message);
6518                 ret = PMINFO_R_ERROR;
6519                 goto err;
6520         }
6521         /*Update index table info*/
6522         /*If cert_id exists and is repeated for current package, ref count should only be increased once*/
6523         for (i = 0; i < MAX_CERT_TYPE; i++) {
6524                 if ((info->cert_info)[i]) {
6525                         memset(vquery, '\0', len);
6526                         if ((info->is_new)[i]) {
6527                                 snprintf(vquery, len, "insert into package_cert_index_info(cert_info, cert_id, cert_ref_count) " \
6528                                 "values('%s', '%d', '%d') ", (info->cert_info)[i], (info->cert_id)[i], 1);
6529                                 unique_id[c++] = (info->cert_id)[i];
6530                         } else {
6531                                 /*Update*/
6532                                 for (j = 0; j < MAX_CERT_TYPE; j++) {
6533                                         if ((info->cert_id)[i] == unique_id[j]) {
6534                                                 /*Ref count has already been increased. Just continue*/
6535                                                 break;
6536                                         }
6537                                 }
6538                                 if (j == MAX_CERT_TYPE)
6539                                         unique_id[c++] = (info->cert_id)[i];
6540                                 else
6541                                         continue;
6542                                 snprintf(vquery, len, "update package_cert_index_info set cert_ref_count=%d " \
6543                                 "where cert_id=%d",  (info->ref_count)[i] + 1, (info->cert_id)[i]);
6544                         }
6545                         if (SQLITE_OK !=
6546                             sqlite3_exec(cert_db, vquery, NULL, NULL, &error_message)) {
6547                                 _LOGE("Don't execute query = %s error message = %s\n", vquery,
6548                                        error_message);
6549                                 sqlite3_free(error_message);
6550                                 ret = PMINFO_R_ERROR;
6551                                 goto err;
6552                         }
6553                 }
6554         }
6555         /*Commit transaction*/
6556         ret = sqlite3_exec(cert_db, "COMMIT", NULL, NULL, NULL);
6557         if (ret != SQLITE_OK) {
6558                 _LOGE("Failed to commit transaction, Rollback now\n");
6559                 sqlite3_exec(cert_db, "ROLLBACK", NULL, NULL, NULL);
6560                 ret = PMINFO_R_ERROR;
6561                 goto err;
6562         }
6563         _LOGE("Transaction Commit and End\n");
6564         ret =  PMINFO_R_OK;
6565 err:
6566         sqlite3_close(cert_db);
6567         if (vquery) {
6568                 free(vquery);
6569                 vquery = NULL;
6570         }
6571         if (indexinfo) {
6572                 free(indexinfo);
6573                 indexinfo = NULL;
6574         }
6575         return ret;
6576 }
6577
6578 API int pkgmgrinfo_destroy_certinfo_set_handle(pkgmgrinfo_instcertinfo_h handle)
6579 {
6580         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
6581         int i = 0;
6582         pkgmgr_instcertinfo_x *certinfo = NULL;
6583         certinfo = (pkgmgr_instcertinfo_x *)handle;
6584         if (certinfo->pkgid) {
6585                 free(certinfo->pkgid);
6586                 certinfo->pkgid = NULL;
6587         }
6588         for (i = 0; i < MAX_CERT_TYPE; i++) {
6589                 if ((certinfo->cert_info)[i]) {
6590                         free((certinfo->cert_info)[i]);
6591                         (certinfo->cert_info)[i] = NULL;
6592                 }
6593         }
6594         free(certinfo);
6595         certinfo = NULL;
6596         return PMINFO_R_OK;
6597 }
6598
6599 API int pkgmgrinfo_delete_certinfo(const char *pkgid)
6600 {
6601         retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
6602         int ret = -1;
6603         /*Open db.*/
6604         ret = db_util_open_with_options(CERT_DB, &cert_db, SQLITE_OPEN_READWRITE, NULL);
6605         if (ret != SQLITE_OK) {
6606                 _LOGE("connect db [%s] failed!\n", CERT_DB);
6607                 ret = PMINFO_R_ERROR;
6608                 goto err;
6609         }
6610         /*Begin Transaction*/
6611         ret = sqlite3_exec(cert_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
6612         if (ret != SQLITE_OK) {
6613                 _LOGE("Failed to begin transaction\n");
6614                 ret = PMINFO_R_ERROR;
6615                 goto err;
6616         }
6617         _LOGE("Transaction Begin\n");
6618         ret = __delete_certinfo(pkgid);
6619         if (ret < 0) {
6620                 _LOGE("Certificate Deletion Failed\n");
6621         } else {
6622                 _LOGE("Certificate Deletion Success\n");
6623         }
6624         /*Commit transaction*/
6625         ret = sqlite3_exec(cert_db, "COMMIT", NULL, NULL, NULL);
6626         if (ret != SQLITE_OK) {
6627                 _LOGE("Failed to commit transaction, Rollback now\n");
6628                 sqlite3_exec(cert_db, "ROLLBACK", NULL, NULL, NULL);
6629                 ret = PMINFO_R_ERROR;
6630                 goto err;
6631         }
6632         _LOGE("Transaction Commit and End\n");
6633         ret = PMINFO_R_OK;
6634 err:
6635         sqlite3_close(cert_db);
6636         return ret;
6637 }
6638
6639 API int pkgmgrinfo_create_pkgdbinfo(const char *pkgid, pkgmgrinfo_pkgdbinfo_h *handle)
6640 {
6641         retvm_if(!pkgid, PMINFO_R_EINVAL, "pkgid is NULL");
6642         retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6643
6644         char *manifest = NULL;
6645         manifest_x *mfx = NULL;
6646
6647         manifest = pkgmgr_parser_get_manifest_file(pkgid);
6648         retvm_if(manifest == NULL, PMINFO_R_EINVAL, "pkg[%s] dont have manifest file", pkgid);
6649
6650         mfx = pkgmgr_parser_process_manifest_xml(manifest);
6651         if (manifest) {
6652                 free(manifest);
6653                 manifest = NULL;
6654         }
6655         retvm_if(mfx == NULL, PMINFO_R_EINVAL, "pkg[%s] parsing fail", pkgid);
6656
6657         *handle = (void *)mfx;
6658
6659         return PMINFO_R_OK;
6660 }
6661
6662 API int pkgmgrinfo_set_type_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *type)
6663 {
6664         retvm_if(!type, PMINFO_R_EINVAL, "Argument supplied is NULL");
6665         retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6666
6667         int len = strlen(type);
6668         retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
6669
6670         manifest_x *mfx = (manifest_x *)handle;
6671
6672         mfx->type = strndup(type, PKG_TYPE_STRING_LEN_MAX);
6673         return PMINFO_R_OK;
6674 }
6675
6676 API int pkgmgrinfo_set_version_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *version)
6677 {
6678         retvm_if(!version, PMINFO_R_EINVAL, "Argument supplied is NULL");
6679         retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6680
6681         int len = strlen(version);
6682         retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
6683
6684         manifest_x *mfx = (manifest_x *)handle;
6685
6686         mfx->version = strndup(version, PKG_VERSION_STRING_LEN_MAX);
6687         return PMINFO_R_OK;
6688 }
6689
6690 API int pkgmgrinfo_set_install_location_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, INSTALL_LOCATION location)
6691 {
6692         retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6693         retvm_if((location < 0) || (location > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
6694
6695         manifest_x *mfx = (manifest_x *)handle;
6696
6697         if (location == INSTALL_INTERNAL)
6698                 strcpy(mfx->installlocation, "internal-only");
6699         else if (location == INSTALL_EXTERNAL)
6700                 strcpy(mfx->installlocation, "prefer-external");
6701
6702         return PMINFO_R_OK;
6703 }
6704
6705 API int pkgmgrinfo_set_size_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *size)
6706 {
6707         retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6708         retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL");
6709
6710         manifest_x *mfx = (manifest_x *)handle;
6711
6712         mfx->package_size = strdup(size);
6713
6714         return PMINFO_R_OK;
6715 }
6716
6717 API int pkgmgrinfo_set_label_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *label_txt, const char *locale)
6718 {
6719         retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6720         retvm_if(!label_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
6721
6722         int len = strlen(label_txt);
6723         retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
6724
6725         manifest_x *mfx = (manifest_x *)handle;
6726
6727         label_x *label = calloc(1, sizeof(label_x));
6728         retvm_if(label == NULL, PMINFO_R_EINVAL, "Malloc Failed");
6729
6730         LISTADD(mfx->label, label);
6731         if (locale)
6732                 mfx->label->lang = strdup(locale);
6733         else
6734                 mfx->label->lang = strdup(DEFAULT_LOCALE);
6735         mfx->label->text = strdup(label_txt);
6736
6737         return PMINFO_R_OK;
6738 }
6739
6740 API int pkgmgrinfo_set_icon_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *icon_txt, const char *locale)
6741 {
6742         retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6743         retvm_if(!icon_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
6744
6745         int len = strlen(icon_txt);
6746         retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
6747
6748         manifest_x *mfx = (manifest_x *)handle;
6749
6750         icon_x *icon = calloc(1, sizeof(icon_x));
6751         retvm_if(icon == NULL, PMINFO_R_EINVAL, "Malloc Failed");
6752
6753         LISTADD(mfx->icon, icon);
6754         if (locale)
6755                 mfx->icon->lang = strdup(locale);
6756         else
6757                 mfx->icon->lang = strdup(DEFAULT_LOCALE);
6758         mfx->icon->text = strdup(icon_txt);
6759
6760         return PMINFO_R_OK;
6761 }
6762
6763 API int pkgmgrinfo_set_description_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *desc_txt, const char *locale)
6764 {
6765         retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6766         retvm_if(!desc_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
6767
6768         int len = strlen(desc_txt);
6769         retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
6770
6771         manifest_x *mfx = (manifest_x *)handle;
6772
6773         description_x *description = calloc(1, sizeof(description_x));
6774         retvm_if(description == NULL, PMINFO_R_EINVAL, "Malloc Failed");
6775
6776         LISTADD(mfx->description, description);
6777         if (locale)
6778                 mfx->description->lang = strdup(locale);
6779         else
6780                 mfx->description->lang = strdup(DEFAULT_LOCALE);
6781         mfx->description->text = strdup(desc_txt);
6782
6783         return PMINFO_R_OK;
6784 }
6785
6786 API int pkgmgrinfo_set_author_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *author_name,
6787                 const char *author_email, const char *author_href, const char *locale)
6788 {
6789         retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6790         manifest_x *mfx = (manifest_x *)handle;
6791         author_x *author = calloc(1, sizeof(author_x));
6792         retvm_if(author == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL");
6793
6794         LISTADD(mfx->author, author);
6795         if (author_name)
6796                 mfx->author->text = strdup(author_name);
6797         if (author_email)
6798                 mfx->author->email = strdup(author_email);
6799         if (author_href)
6800                 mfx->author->href = strdup(author_href);
6801         if (locale)
6802                 mfx->author->lang = strdup(locale);
6803         else
6804                 mfx->author->lang = strdup(DEFAULT_LOCALE);
6805         return PMINFO_R_OK;
6806 }
6807
6808 API int pkgmgrinfo_set_removable_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, int removable)
6809 {
6810         retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6811         retvm_if((removable < 0) || (removable > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
6812
6813         manifest_x *mfx = (manifest_x *)handle;
6814
6815         if (removable == 0)
6816                 strcpy(mfx->removable, "false");
6817         else if (removable == 1)
6818                 strcpy(mfx->removable, "true");
6819
6820         return PMINFO_R_OK;
6821 }
6822
6823 API int pkgmgrinfo_set_preload_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, int preload)
6824 {
6825         retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6826         retvm_if((preload < 0) || (preload > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
6827
6828         manifest_x *mfx = (manifest_x *)handle;
6829
6830         if (preload == 0)
6831                 strcpy(mfx->preload, "false");
6832         else if (preload == 1)
6833                 strcpy(mfx->preload, "true");
6834
6835         return PMINFO_R_OK;
6836 }
6837
6838 API int pkgmgrinfo_set_installed_storage_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, INSTALL_LOCATION location)
6839 {
6840         retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6841         retvm_if((location < 0) || (location > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
6842
6843         manifest_x *mfx = (manifest_x *)handle;
6844
6845         if (location == INSTALL_INTERNAL)
6846                 strcpy(mfx->installed_storage, "installed_internal");
6847         else if (location == INSTALL_EXTERNAL)
6848                 strcpy(mfx->installed_storage, "installed_external");
6849
6850         return PMINFO_R_OK;
6851 }
6852
6853 API int pkgmgrinfo_save_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle)
6854 {
6855         retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6856
6857         int ret = 0;
6858         manifest_x *mfx = NULL;
6859         mfx = (manifest_x *)handle;
6860
6861         ret = pkgmgr_parser_update_manifest_info_in_db(mfx);
6862         retvm_if(ret != 0, PMINFO_R_ERROR, "Failed to store info in DB\n");
6863         
6864         ret = __update_ail_appinfo(mfx);
6865         retvm_if(ret != 0, PMINFO_R_ERROR, "Failed to store info in DB\n");
6866
6867         _LOGE("Successfully stored info in DB\n");
6868         return PMINFO_R_OK;
6869 }
6870
6871 API int pkgmgrinfo_destroy_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle)
6872 {
6873         retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6874
6875         manifest_x *mfx = NULL;
6876         mfx = (manifest_x *)handle;
6877         pkgmgr_parser_free_manifest_xml(mfx);
6878         return PMINFO_R_OK;
6879 }
6880
6881 API int pkgmgrinfo_pkginfo_set_state_enabled(const char *pkgid, bool enabled)
6882 {
6883         /* Should be implemented later */
6884         return 0;
6885 }
6886
6887 API int pkgmgrinfo_appinfo_set_state_enabled(const char *appid, bool enabled)
6888 {
6889         retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL\n");
6890         int ret = -1;
6891         char query[MAX_QUERY_LEN] = {'\0'};
6892         sqlite3 *pkginfo_db = NULL;
6893
6894         ret = db_util_open(MANIFEST_DB, &pkginfo_db, 0);
6895         retvm_if(ret != SQLITE_OK, PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
6896
6897         /*Begin transaction*/
6898         ret = sqlite3_exec(pkginfo_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
6899         if (ret != SQLITE_OK) {
6900                 _LOGE("Failed to begin transaction\n");
6901                 sqlite3_close(pkginfo_db);
6902                 return PMINFO_R_ERROR;
6903         }
6904         _LOGD("Transaction Begin\n");
6905
6906         memset(query, '\0', MAX_QUERY_LEN);
6907         snprintf(query, MAX_QUERY_LEN,
6908                 "update package_app_info set app_enabled='%s' where app_id='%s'", enabled?"true":"false", appid);
6909
6910         char *error_message = NULL;
6911         if (SQLITE_OK !=
6912             sqlite3_exec(pkginfo_db, query, NULL, NULL, &error_message)) {
6913                 _LOGE("Don't execute query = %s error message = %s\n", query,
6914                        error_message);
6915                 sqlite3_free(error_message);
6916                 return PMINFO_R_ERROR;
6917         }
6918         sqlite3_free(error_message);
6919
6920         /*Commit transaction*/
6921         ret = sqlite3_exec(pkginfo_db, "COMMIT", NULL, NULL, NULL);
6922         if (ret != SQLITE_OK) {
6923                 _LOGE("Failed to commit transaction. Rollback now\n");
6924                 sqlite3_exec(pkginfo_db, "ROLLBACK", NULL, NULL, NULL);
6925                 sqlite3_close(pkginfo_db);
6926                 return PMINFO_R_ERROR;
6927         }
6928         _LOGD("Transaction Commit and End\n");
6929         sqlite3_close(pkginfo_db);
6930
6931         return PMINFO_R_OK;
6932 }
6933
6934
6935 API int pkgmgrinfo_datacontrol_get_info(const char *providerid, const char * type, char **appid, char **access)
6936 {
6937         retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
6938         retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
6939         retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
6940         retvm_if(access == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
6941         int ret = PMINFO_R_OK;
6942         char query[MAX_QUERY_LEN] = {'\0'};
6943         char *error_message = NULL;
6944         pkgmgr_datacontrol_x *data = NULL;
6945
6946         sqlite3 *datacontrol_info_db = NULL;
6947
6948         /*open db*/
6949         ret = db_util_open(DATACONTROL_DB, &datacontrol_info_db, 0);
6950         retvm_if(ret != SQLITE_OK, PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
6951
6952         data = (pkgmgr_datacontrol_x *)calloc(1, sizeof(pkgmgr_datacontrol_x));
6953         if (data == NULL) {
6954                 _LOGE("Failed to allocate memory for pkgmgr_datacontrol_x\n");
6955                 sqlite3_close(datacontrol_info_db);
6956                 return PMINFO_R_ERROR;
6957         }
6958
6959         snprintf(query, MAX_QUERY_LEN, 
6960                 "select appinfo.package_name, datacontrol.access from appinfo, datacontrol where datacontrol.id=appinfo.unique_id and datacontrol.provider_id = '%s' and datacontrol.type='%s' COLLATE NOCASE",
6961                 providerid, type);
6962
6963         if (SQLITE_OK !=
6964                 sqlite3_exec(datacontrol_info_db, query, __datacontrol_cb, (void *)data, &error_message)) {
6965                 _LOGE("Don't execute query = %s error message = %s\n", query,
6966                            error_message);
6967                 sqlite3_free(error_message);
6968                 sqlite3_close(datacontrol_info_db);
6969                 return PMINFO_R_ERROR;
6970         }
6971
6972         *appid = (char *)data->appid;
6973         *access = (char *)data->access;
6974         free(data);
6975         sqlite3_close(datacontrol_info_db);
6976
6977         return PMINFO_R_OK;
6978 }
6979
6980 API int pkgmgrinfo_appinfo_set_default_label(const char *appid, const char *label)
6981 {
6982         retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL\n");
6983         int ret = -1;
6984         char query[MAX_QUERY_LEN] = {'\0'};
6985         char *error_message = NULL;
6986         sqlite3 *pkginfo_db = NULL;
6987
6988         /*open db*/
6989         ret = db_util_open(MANIFEST_DB, &pkginfo_db, 0);
6990         retvm_if(ret != SQLITE_OK, PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
6991
6992         /*Begin transaction*/
6993         ret = sqlite3_exec(pkginfo_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
6994         if (ret != SQLITE_OK) {
6995                 _LOGE("Failed to begin transaction\n");
6996                 sqlite3_close(pkginfo_db);
6997                 return PMINFO_R_ERROR;
6998         }
6999         _LOGD("Transaction Begin\n");
7000
7001         memset(query, '\0', MAX_QUERY_LEN);
7002         snprintf(query, MAX_QUERY_LEN, "update package_app_localized_info set app_label='%s' where app_id='%s'", label, appid);
7003
7004         ret = sqlite3_exec(pkginfo_db, query, NULL, NULL, &error_message);
7005         if (ret != SQLITE_OK) {
7006                 _LOGE("Don't execute query = %s error message = %s\n", query, error_message);
7007                 sqlite3_free(error_message);
7008                 return PMINFO_R_ERROR;
7009         }
7010
7011         /*Commit transaction*/
7012         ret = sqlite3_exec(pkginfo_db, "COMMIT", NULL, NULL, NULL);
7013         if (ret != SQLITE_OK) {
7014                 _LOGE("Failed to commit transaction. Rollback now\n");
7015                 sqlite3_exec(pkginfo_db, "ROLLBACK", NULL, NULL, NULL);
7016                 sqlite3_close(pkginfo_db);
7017                 return PMINFO_R_ERROR;
7018         }
7019         _LOGD("Transaction Commit and End\n");
7020         sqlite3_close(pkginfo_db);
7021
7022         return PMINFO_R_OK;
7023 }
7024
7025 API int pkgmgrinfo_appinfo_is_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool *status)
7026 {
7027         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
7028         retvm_if(status == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
7029         char *val = NULL;
7030         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
7031         val = (char *)info->uiapp_info->guestmode_visibility;
7032         if (val) {
7033                 if (strcasecmp(val, "true") == 0){
7034                         *status = 1;
7035                 }else if (strcasecmp(val, "false") == 0){
7036                         *status = 0;
7037                 }else{
7038                         *status = 1;
7039                 }
7040         }
7041         return PMINFO_R_OK;
7042 }
7043
7044 API int pkgmgrinfo_appinfo_set_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool status)
7045 {
7046         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
7047         char *val = NULL;
7048         int ret = 0;
7049         char *noti_string = NULL;
7050         int len = 0;
7051         char query[MAX_QUERY_LEN] = {'\0'};
7052         char *errmsg = NULL;
7053         sqlite3 *pkgmgr_parser_db;
7054
7055         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
7056         val = (char *)info->uiapp_info->guestmode_visibility;
7057         if (val ) {
7058                 ret =
7059                     db_util_open_with_options(MANIFEST_DB, &pkgmgr_parser_db, SQLITE_OPEN_READWRITE, NULL);
7060
7061                 if (ret != SQLITE_OK) {
7062                         _LOGE("DB Open Failed\n");
7063                         return PMINFO_R_ERROR;
7064                 }
7065
7066                 /*TODO: Write to DB here*/
7067                 if (status == true)
7068                         snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_guestmodevisibility = 'true' where app_id = '%s'", (char *)info->uiapp_info->appid);
7069                 else
7070                         snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_guestmodevisibility = 'false' where app_id = '%s'", (char *)info->uiapp_info->appid);
7071
7072                 if (SQLITE_OK != sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &errmsg)) {
7073                         _LOGE("DB update [%s] failed, error message = %s\n", query, errmsg);
7074                         free(errmsg);
7075                         sqlite3_close(pkgmgr_parser_db);
7076                         return PMINFO_R_ERROR;
7077                 }else{
7078                         sqlite3_close(pkgmgr_parser_db);
7079                         len = strlen((char *)info->uiapp_info->appid) + 8;
7080                         noti_string = calloc(1, len);
7081                         if (noti_string == NULL){
7082                                 return PMINFO_R_ERROR;
7083                         }
7084                         snprintf(noti_string, len, "update:%s", (char *)info->uiapp_info->appid);
7085                 vconf_set_str(VCONFKEY_AIL_INFO_STATE, noti_string);
7086                         vconf_set_str(VCONFKEY_MENUSCREEN_DESKTOP, noti_string); // duplicate, will be removed
7087                         free(noti_string);
7088                 }
7089         }
7090         return PMINFO_R_OK;
7091 }
7092
7093 /* pkgmgrinfo client start*/
7094 API pkgmgrinfo_client *pkgmgrinfo_client_new(pkgmgrinfo_client_type ctype)
7095 {
7096         int ret = 0;
7097         char *errmsg = NULL;
7098         void *pc = NULL;
7099         void *handle = NULL;
7100         pkgmgrinfo_client *(*__pkgmgr_client_new)(pkgmgrinfo_client_type ctype) = NULL;
7101
7102         handle = dlopen("libpkgmgr-client.so.0", RTLD_LAZY | RTLD_GLOBAL);
7103         retvm_if(!handle, PMINFO_R_ERROR, "dlopen() failed. [%s]", dlerror());
7104
7105         __pkgmgr_client_new = dlsym(handle, "pkgmgr_client_new");
7106         errmsg = dlerror();
7107         tryvm_if((errmsg != NULL) || (__pkgmgr_client_new == NULL), ret = PMINFO_R_ERROR, "dlsym() failed. [%s]", errmsg);
7108
7109         pc = __pkgmgr_client_new(ctype);
7110         tryvm_if(pc == NULL, ret = PMINFO_R_ERROR, "pkgmgr_client_new failed.");
7111
7112 catch:
7113 //      dlclose(handle);
7114         return (pkgmgrinfo_client *) pc;
7115 }
7116
7117 API int pkgmgrinfo_client_set_status_type(pkgmgrinfo_client *pc, int status_type)
7118 {
7119         int ret = 0;
7120         char *errmsg = NULL;
7121         void *handle = NULL;
7122         int (*__pkgmgr_client_set_status_type)(pkgmgrinfo_client *pc, int status_type) = NULL;
7123
7124         handle = dlopen("libpkgmgr-client.so.0", RTLD_LAZY | RTLD_GLOBAL);
7125         retvm_if(!handle, PMINFO_R_ERROR, "dlopen() failed. [%s]", dlerror());
7126
7127         __pkgmgr_client_set_status_type = dlsym(handle, "pkgmgr_client_set_status_type");
7128         errmsg = dlerror();
7129         tryvm_if((errmsg != NULL) || (__pkgmgr_client_set_status_type == NULL), ret = PMINFO_R_ERROR, "dlsym() failed. [%s]", errmsg);
7130
7131         ret = __pkgmgr_client_set_status_type(pc, status_type);
7132         tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgr_client_new failed.");
7133
7134 catch:
7135 //      dlclose(handle);
7136         return ret;
7137 }
7138
7139 API int pkgmgrinfo_client_listen_status(pkgmgrinfo_client *pc, pkgmgrinfo_handler event_cb, void *data)
7140 {
7141         int ret = 0;
7142         char *errmsg = NULL;
7143         void *handle = NULL;
7144         int (*__pkgmgr_client_listen_status)(pkgmgrinfo_client *pc, pkgmgrinfo_handler event_cb, void *data) = NULL;
7145
7146         handle = dlopen("libpkgmgr-client.so.0", RTLD_LAZY | RTLD_GLOBAL);
7147         retvm_if(!handle, PMINFO_R_ERROR, "dlopen() failed. [%s]", dlerror());
7148
7149         __pkgmgr_client_listen_status = dlsym(handle, "pkgmgr_client_listen_status");
7150         errmsg = dlerror();
7151         tryvm_if((errmsg != NULL) || (__pkgmgr_client_listen_status == NULL), ret = PMINFO_R_ERROR, "dlsym() failed. [%s]", errmsg);
7152
7153         ret = __pkgmgr_client_listen_status(pc, event_cb, data);
7154         tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgr_client_new failed.");
7155
7156 catch:
7157 //      dlclose(handle);
7158         return ret;
7159 }
7160
7161 API int pkgmgrinfo_client_free(pkgmgrinfo_client *pc)
7162 {
7163         int ret = 0;
7164         char *errmsg = NULL;
7165         void *handle = NULL;
7166         int (*__pkgmgr_client_free)(pkgmgrinfo_client *pc) = NULL;
7167
7168         handle = dlopen("libpkgmgr-client.so.0", RTLD_LAZY | RTLD_GLOBAL);
7169         retvm_if(!handle, PMINFO_R_ERROR, "dlopen() failed. [%s]", dlerror());
7170
7171         __pkgmgr_client_free = dlsym(handle, "pkgmgr_client_free");
7172         errmsg = dlerror();
7173         tryvm_if((errmsg != NULL) || (__pkgmgr_client_free == NULL), ret = PMINFO_R_ERROR, "dlsym() failed. [%s]", errmsg);
7174
7175         ret = __pkgmgr_client_free(pc);
7176         tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgr_client_new failed.");
7177
7178 catch:
7179 //      dlclose(handle);
7180         return ret;
7181 }
7182
7183 API int pkgmgrinfo_client_request_enable_external_pkg(char *pkgid)
7184 {
7185         retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "pkgid is NULL\n");
7186
7187         if(__get_pkg_location(pkgid) != PMINFO_EXTERNAL_STORAGE)
7188                 return PMINFO_R_OK;
7189
7190         _LOGD("call system server to enable app2ext");
7191         return mmc_mount_app2ext(pkgid);
7192 }
7193
7194 /* pkgmgrinfo client end*/
7195