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