adeb350ac02a4b6edef3d48b6c1906d068d94cd1
[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                 ret = pkgmgrinfo_pkginfo_get_pkgid(handle,&pkgid);
2660                 retvm_if(ret < 0, PMINFO_R_ERROR, "get pkgid fail");
2661
2662                 *size = __reqeust_get_size(pkgid, PM_GET_TOTAL_SIZE);
2663                 return 0;
2664         }
2665 }
2666
2667 API int pkgmgrinfo_pkginfo_get_data_size(pkgmgrinfo_pkginfo_h handle, int *size)
2668 {
2669         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2670         retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2671
2672         int ret = -1;
2673         char *pkgid = NULL;
2674         char *val = NULL;
2675
2676         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2677         val = (char *)info->manifest_info->package_size;
2678         if (strcmp(val, "true") == 0) {
2679                 *size = atoi(info->manifest_info->package_data_size);
2680                 return 0;
2681         } else {
2682                 ret = pkgmgrinfo_pkginfo_get_pkgid(handle,&pkgid);
2683                 retvm_if(ret < 0, PMINFO_R_ERROR, "get pkgid fail");
2684
2685                 *size = __reqeust_get_size(pkgid, PM_GET_DATA_SIZE);
2686                 return 0;
2687         }
2688 }
2689
2690 API int pkgmgrinfo_pkginfo_get_size_info(pkgmgrinfo_pkginfo_h handle, int *total_size, int *data_size)
2691 {
2692         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2693         retvm_if(total_size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2694         retvm_if(data_size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2695
2696         int ret = -1;
2697         int total_tmp = 0;
2698         int data_tmp = 0;
2699         char *val = NULL;
2700         char *pkgid = NULL;
2701         char* package_size_info = NULL;
2702
2703         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2704
2705         val = (char *)info->manifest_info->package_size;
2706         if (strcmp(val, "true") == 0) {
2707                 *total_size = atoi(info->manifest_info->package_total_size);
2708                 *data_size = atoi(info->manifest_info->package_data_size);
2709                 return 0;
2710         } else {
2711                 ret = pkgmgrinfo_pkginfo_get_pkgid(handle,&pkgid);
2712                 retvm_if(ret < 0, PMINFO_R_ERROR, "get pkgid fail");
2713
2714                 ret = __reqeust_get_size(pkgid, PM_GET_TOTAL_AND_DATA);
2715                 retvm_if(ret < 0, PMINFO_R_ERROR, "fail reqeust size info");
2716
2717                 ret = __get_package_size_info(&package_size_info);
2718                 retvm_if(ret != 0 || package_size_info == NULL, PMINFO_R_ERROR, "__get_package_size_info() failed");
2719
2720                 __get_package_size(package_size_info, pkgid, &total_tmp, &data_tmp);
2721                 *total_size = total_tmp;
2722                 *data_size = data_tmp;
2723
2724                 free(package_size_info);
2725                 return 0;
2726         }
2727         return -1;
2728 }
2729
2730 API int pkgmgrinfo_pkginfo_get_icon(pkgmgrinfo_pkginfo_h handle, char **icon)
2731 {
2732         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
2733         retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2734         int ret = PMINFO_R_OK;
2735         char *locale = NULL;
2736         icon_x *ptr = NULL;
2737         *icon = NULL;
2738
2739         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2740
2741         locale = info->locale;
2742         retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
2743
2744         for(ptr = info->manifest_info->icon; ptr != NULL; ptr = ptr->next)
2745         {
2746                 if (ptr->lang) {
2747                         if (strcmp(ptr->lang, locale) == 0) {
2748                                 *icon = (char *)ptr->text;
2749                                 if (strcasecmp(*icon, "(null)") == 0) {
2750                                         locale = DEFAULT_LOCALE;
2751                                         continue;
2752                                 } else
2753                                         break;
2754                         } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
2755                                 *icon = (char *)ptr->text;
2756                                 break;
2757                         }
2758                 }
2759         }
2760
2761         return ret;
2762 }
2763
2764 API int pkgmgrinfo_pkginfo_get_label(pkgmgrinfo_pkginfo_h handle, char **label)
2765 {
2766         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
2767         retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2768         int ret = PMINFO_R_OK;
2769         char *locale = NULL;
2770         label_x *ptr = NULL;
2771         *label = NULL;
2772
2773         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2774         locale = info->locale;
2775         retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
2776
2777         for(ptr = info->manifest_info->label; ptr != NULL; ptr = ptr->next)
2778         {
2779                 if (ptr->lang) {
2780                         if (strcmp(ptr->lang, locale) == 0) {
2781                                 *label = (char *)ptr->text;
2782                                 if (strcasecmp(*label, "(null)") == 0) {
2783                                         locale = DEFAULT_LOCALE;
2784                                         continue;
2785                                 } else
2786                                         break;
2787                         } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
2788                                 *label = (char *)ptr->text;
2789                                 break;
2790                         }
2791                 }
2792         }
2793
2794         return ret;
2795 }
2796
2797 API int pkgmgrinfo_pkginfo_get_description(pkgmgrinfo_pkginfo_h handle, char **description)
2798 {
2799         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2800         retvm_if(description == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2801         char *locale = NULL;
2802         description_x *ptr = NULL;
2803         *description = NULL;
2804
2805         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2806         locale = info->locale;
2807         retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
2808
2809         for(ptr = info->manifest_info->description; ptr != NULL; ptr = ptr->next)
2810         {
2811                 if (ptr->lang) {
2812                         if (strcmp(ptr->lang, locale) == 0) {
2813                                 *description = (char *)ptr->text;
2814                                 if (strcasecmp(*description, PKGMGR_PARSER_EMPTY_STR) == 0) {
2815                                         locale = DEFAULT_LOCALE;
2816                                         continue;
2817                                 } else
2818                                         break;
2819                         } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
2820                                 *description = (char *)ptr->text;
2821                                 break;
2822                         }
2823                 }
2824         }
2825         return PMINFO_R_OK;
2826 }
2827
2828 API int pkgmgrinfo_pkginfo_get_author_name(pkgmgrinfo_pkginfo_h handle, char **author_name)
2829 {
2830         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2831         retvm_if(author_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2832         char *locale = NULL;
2833         author_x *ptr = NULL;
2834         *author_name = NULL;
2835
2836         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2837         locale = info->locale;
2838         retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
2839
2840         for(ptr = info->manifest_info->author; ptr != NULL; ptr = ptr->next)
2841         {
2842                 if (ptr->lang) {
2843                         if (strcmp(ptr->lang, locale) == 0) {
2844                                 *author_name = (char *)ptr->text;
2845                                 if (strcasecmp(*author_name, PKGMGR_PARSER_EMPTY_STR) == 0) {
2846                                         locale = DEFAULT_LOCALE;
2847                                         continue;
2848                                 } else
2849                                         break;
2850                         } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
2851                                 *author_name = (char *)ptr->text;
2852                                 break;
2853                         }
2854                 }
2855         }
2856         return PMINFO_R_OK;
2857 }
2858
2859 API int pkgmgrinfo_pkginfo_get_author_email(pkgmgrinfo_pkginfo_h handle, char **author_email)
2860 {
2861         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2862         retvm_if(author_email == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2863         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2864         *author_email = (char *)info->manifest_info->author->email;
2865         return PMINFO_R_OK;
2866 }
2867
2868 API int pkgmgrinfo_pkginfo_get_author_href(pkgmgrinfo_pkginfo_h handle, char **author_href)
2869 {
2870         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2871         retvm_if(author_href == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2872         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2873         *author_href = (char *)info->manifest_info->author->href;
2874         return PMINFO_R_OK;
2875 }
2876
2877 API int pkgmgrinfo_pkginfo_get_installed_storage(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_installed_storage *storage)
2878 {
2879         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2880         retvm_if(storage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2881
2882         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2883
2884          if (strcmp(info->manifest_info->installed_storage,"installed_internal") == 0)
2885                 *storage = PMINFO_INTERNAL_STORAGE;
2886          else if (strcmp(info->manifest_info->installed_storage,"installed_external") == 0)
2887                  *storage = PMINFO_EXTERNAL_STORAGE;
2888          else
2889                  return PMINFO_R_ERROR;
2890
2891         return PMINFO_R_OK;
2892 }
2893
2894 API int pkgmgrinfo_pkginfo_get_installed_time(pkgmgrinfo_pkginfo_h handle, int *installed_time)
2895 {
2896         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2897         retvm_if(installed_time == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2898         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2899         if (info->manifest_info->installed_time)
2900                 *installed_time = atoi(info->manifest_info->installed_time);
2901         else
2902                 return PMINFO_R_ERROR;
2903
2904         return PMINFO_R_OK;
2905 }
2906
2907 API int pkgmgrinfo_pkginfo_get_storeclientid(pkgmgrinfo_pkginfo_h handle, char **storeclientid)
2908 {
2909         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2910         retvm_if(storeclientid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2911         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2912         *storeclientid = (char *)info->manifest_info->storeclient_id;
2913         return PMINFO_R_OK;
2914 }
2915
2916 API int pkgmgrinfo_pkginfo_get_mainappid(pkgmgrinfo_pkginfo_h handle, char **mainappid)
2917 {
2918         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2919         retvm_if(mainappid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2920         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2921         *mainappid = (char *)info->manifest_info->mainapp_id;
2922         return PMINFO_R_OK;
2923 }
2924
2925 API int pkgmgrinfo_pkginfo_get_url(pkgmgrinfo_pkginfo_h handle, char **url)
2926 {
2927         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2928         retvm_if(url == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2929         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2930         *url = (char *)info->manifest_info->package_url;
2931         return PMINFO_R_OK;
2932 }
2933
2934 API int pkgmgrinfo_pkginfo_get_size_from_xml(const char *manifest, int *size)
2935 {
2936         const char *val = NULL;
2937         const xmlChar *node;
2938         xmlTextReaderPtr reader;
2939         retvm_if(manifest == NULL, PMINFO_R_EINVAL, "Input argument is NULL\n");
2940         retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2941
2942         xmlInitParser();
2943         reader = xmlReaderForFile(manifest, NULL, 0);
2944
2945         if (reader){
2946                 if (__child_element(reader, -1)) {
2947                         node = xmlTextReaderConstName(reader);
2948                         if (!node) {
2949                                 _LOGE("xmlTextReaderConstName value is NULL\n");
2950                                 xmlFreeTextReader(reader);
2951                                 xmlCleanupParser();
2952                                 return PMINFO_R_ERROR;
2953                         }
2954
2955                         if (!strcmp(ASC_CHAR(node), "manifest")) {
2956                                 if (xmlTextReaderGetAttribute(reader, XML_CHAR("size")))
2957                                         val = ASC_CHAR(xmlTextReaderGetAttribute(reader, XML_CHAR("size")));
2958
2959                                 if (val) {
2960                                         *size = atoi(val);
2961                                 } else {
2962                                         *size = 0;
2963                                         _LOGE("package size is not specified\n");
2964                                         xmlFreeTextReader(reader);
2965                                         xmlCleanupParser();
2966                                         return PMINFO_R_ERROR;
2967                                 }
2968                         } else {
2969                                 _LOGE("Unable to create xml reader\n");
2970                                 xmlFreeTextReader(reader);
2971                                 xmlCleanupParser();
2972                                 return PMINFO_R_ERROR;
2973                         }
2974                 }
2975         } else {
2976                 _LOGE("xmlReaderForFile value is NULL\n");
2977                 xmlCleanupParser();
2978                 return PMINFO_R_ERROR;
2979         }
2980
2981         xmlFreeTextReader(reader);
2982         xmlCleanupParser();
2983
2984         return PMINFO_R_OK;
2985 }
2986
2987 API int pkgmgrinfo_pkginfo_get_location_from_xml(const char *manifest, pkgmgrinfo_install_location *location)
2988 {
2989         const char *val = NULL;
2990         const xmlChar *node;
2991         xmlTextReaderPtr reader;
2992         retvm_if(manifest == NULL, PMINFO_R_EINVAL, "Input argument is NULL\n");
2993         retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2994
2995         xmlInitParser();
2996         reader = xmlReaderForFile(manifest, NULL, 0);
2997
2998         if (reader){
2999                 if ( __child_element(reader, -1)) {
3000                         node = xmlTextReaderConstName(reader);
3001                         if (!node) {
3002                                 _LOGE("xmlTextReaderConstName value is NULL\n");
3003                                 xmlFreeTextReader(reader);
3004                                 xmlCleanupParser();
3005                                 return PMINFO_R_ERROR;
3006                         }
3007
3008                         if (!strcmp(ASC_CHAR(node), "manifest")) {
3009                                 if (xmlTextReaderGetAttribute(reader, XML_CHAR("install-location")))
3010                                         val = ASC_CHAR(xmlTextReaderGetAttribute(reader, XML_CHAR("install-location")));
3011
3012                                 if (val) {
3013                                         if (strcmp(val, "internal-only") == 0)
3014                                                 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
3015                                         else if (strcmp(val, "prefer-external") == 0)
3016                                                 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
3017                                         else
3018                                                 *location = PMINFO_INSTALL_LOCATION_AUTO;
3019                                 }
3020                         } else {
3021                                 _LOGE("Unable to create xml reader\n");
3022                                 xmlFreeTextReader(reader);
3023                                 xmlCleanupParser();
3024                                 return PMINFO_R_ERROR;
3025                         }
3026                 }
3027         } else {
3028                 _LOGE("xmlReaderForFile value is NULL\n");
3029                 xmlCleanupParser();
3030                 return PMINFO_R_ERROR;
3031         }
3032
3033         xmlFreeTextReader(reader);
3034         xmlCleanupParser();
3035
3036         return PMINFO_R_OK;
3037 }
3038
3039
3040 API int pkgmgrinfo_pkginfo_get_root_path(pkgmgrinfo_pkginfo_h handle, char **path)
3041 {
3042         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3043         retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3044
3045         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3046         if (info->manifest_info->root_path)
3047                 *path = (char *)info->manifest_info->root_path;
3048         else
3049                 return PMINFO_R_ERROR;
3050
3051         return PMINFO_R_OK;
3052 }
3053
3054 API int pkgmgrinfo_pkginfo_get_csc_path(pkgmgrinfo_pkginfo_h handle, char **path)
3055 {
3056         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3057         retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3058
3059         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3060         if (info->manifest_info->csc_path)
3061                 *path = (char *)info->manifest_info->csc_path;
3062         else
3063                 *path = (char *)info->manifest_info->csc_path;
3064
3065         return PMINFO_R_OK;
3066 }
3067
3068 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)
3069 {
3070         retvm_if(lhs_package_id == NULL, PMINFO_R_EINVAL, "lhs package ID is NULL");
3071         retvm_if(rhs_package_id == NULL, PMINFO_R_EINVAL, "rhs package ID is NULL");
3072         retvm_if(compare_result == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3073
3074         int ret = PMINFO_R_OK;
3075         char query[MAX_QUERY_LEN] = {'\0'};
3076         char *error_message = NULL;
3077         pkgmgr_cert_x *info= NULL;
3078         int lcert = 0;
3079         int rcert = 0;
3080         int exist = -1;
3081         *compare_result = PMINFO_CERT_COMPARE_ERROR;
3082         info = (pkgmgr_cert_x *)calloc(1, sizeof(pkgmgr_cert_x));
3083         retvm_if(info == NULL, PMINFO_R_ERROR, "Out of Memory!!!");
3084
3085         ret = db_util_open_with_options(CERT_DB, &cert_db, SQLITE_OPEN_READONLY, NULL);
3086         if (ret != SQLITE_OK) {
3087                 _LOGE("connect db [%s] failed!\n", CERT_DB);
3088                 ret = PMINFO_R_ERROR;
3089                 goto err;
3090         }
3091
3092         snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", lhs_package_id);
3093         if (SQLITE_OK !=
3094             sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
3095                 _LOGE("Don't execute query = %s error message = %s\n", query,
3096                        error_message);
3097                 ret = PMINFO_R_ERROR;
3098                 goto err;
3099         }
3100
3101         if (exist == 0) {
3102                 lcert = 0;
3103         } else {
3104                 snprintf(query, MAX_QUERY_LEN, "select author_signer_cert from package_cert_info where package='%s'", lhs_package_id);
3105                 if (SQLITE_OK !=
3106                         sqlite3_exec(cert_db, query, __cert_cb, (void *)info, &error_message)) {
3107                         _LOGE("Don't execute query = %s error message = %s\n", query,
3108                                    error_message);
3109                         ret = PMINFO_R_ERROR;
3110                         goto err;
3111                 }
3112                 lcert = info->cert_id;
3113         }
3114
3115         snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", rhs_package_id);
3116         if (SQLITE_OK !=
3117                 sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
3118                 _LOGE("Don't execute query = %s error message = %s\n", query,
3119                            error_message);
3120                 ret = PMINFO_R_ERROR;
3121                 goto err;
3122         }
3123
3124         if (exist == 0) {
3125                 rcert = 0;
3126         } else {
3127                 snprintf(query, MAX_QUERY_LEN, "select author_signer_cert from package_cert_info where package='%s'", rhs_package_id);
3128                 if (SQLITE_OK !=
3129                         sqlite3_exec(cert_db, query, __cert_cb, (void *)info, &error_message)) {
3130                         _LOGE("Don't execute query = %s error message = %s\n", query,
3131                                    error_message);
3132                         ret = PMINFO_R_ERROR;
3133                         goto err;
3134                 }
3135                 rcert = info->cert_id;
3136         }
3137
3138         if ((lcert == 0) || (rcert == 0))
3139         {
3140                 if ((lcert == 0) && (rcert == 0))
3141                         *compare_result = PMINFO_CERT_COMPARE_BOTH_NO_CERT;
3142                 else if (lcert == 0)
3143                         *compare_result = PMINFO_CERT_COMPARE_LHS_NO_CERT;
3144                 else if (rcert == 0)
3145                         *compare_result = PMINFO_CERT_COMPARE_RHS_NO_CERT;
3146         } else {
3147                 if (lcert == rcert)
3148                         *compare_result = PMINFO_CERT_COMPARE_MATCH;
3149                 else
3150                         *compare_result = PMINFO_CERT_COMPARE_MISMATCH;
3151         }
3152
3153 err:
3154         sqlite3_free(error_message);
3155         sqlite3_close(cert_db);
3156         if (info) {
3157                 if (info->pkgid) {
3158                         free(info->pkgid);
3159                         info->pkgid = NULL;
3160                 }
3161                 free(info);
3162                 info = NULL;
3163         }
3164         return ret;
3165 }
3166
3167
3168 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)
3169 {
3170         retvm_if(lhs_app_id == NULL, PMINFO_R_EINVAL, "lhs app ID is NULL");
3171         retvm_if(rhs_app_id == NULL, PMINFO_R_EINVAL, "rhs app ID is NULL");
3172         retvm_if(compare_result == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3173
3174         int ret = PMINFO_R_OK;
3175         char query[MAX_QUERY_LEN] = {'\0'};
3176         char *error_message = NULL;
3177         pkgmgr_cert_x *info= NULL;
3178         int exist = -1;
3179         char *lpkgid = NULL;
3180         char *rpkgid = NULL;
3181         sqlite3 *pkginfo_db = NULL;
3182
3183         info = (pkgmgr_cert_x *)calloc(1, sizeof(pkgmgr_cert_x));
3184         retvm_if(info == NULL, PMINFO_R_ERROR, "Out of Memory!!!");
3185
3186         ret = db_util_open(MANIFEST_DB, &pkginfo_db, 0);
3187         tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
3188
3189         snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", lhs_app_id);
3190         if (SQLITE_OK !=
3191             sqlite3_exec(pkginfo_db, query, __validate_cb, (void *)&exist, &error_message)) {
3192                 _LOGE("Don't execute query = %s error message = %s\n", query,
3193                        error_message);
3194                 ret = PMINFO_R_ERROR;
3195                 goto catch;
3196         }
3197
3198         if (exist == 0) {
3199                 lpkgid = NULL;
3200         } else {
3201                 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", lhs_app_id);
3202                 if (SQLITE_OK !=
3203                         sqlite3_exec(pkginfo_db, query, __cert_cb, (void *)info, &error_message)) {
3204                         _LOGE("Don't execute query = %s error message = %s\n", query,
3205                                    error_message);
3206                         ret = PMINFO_R_ERROR;
3207                         goto catch;
3208                 }
3209                 lpkgid = strdup(info->pkgid);
3210                 if (lpkgid == NULL) {
3211                         _LOGE("Out of Memory\n");
3212                         ret = PMINFO_R_ERROR;
3213                         goto catch;
3214                 }
3215                 free(info->pkgid);
3216                 info->pkgid = NULL;
3217         }
3218
3219         snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", rhs_app_id);
3220         if (SQLITE_OK !=
3221             sqlite3_exec(pkginfo_db, query, __validate_cb, (void *)&exist, &error_message)) {
3222                 _LOGE("Don't execute query = %s error message = %s\n", query,
3223                        error_message);
3224                 ret = PMINFO_R_ERROR;
3225                 goto catch;
3226         }
3227
3228         if (exist == 0) {
3229                 rpkgid = NULL;
3230         } else {
3231                 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", rhs_app_id);
3232                 if (SQLITE_OK !=
3233                         sqlite3_exec(pkginfo_db, query, __cert_cb, (void *)info, &error_message)) {
3234                         _LOGE("Don't execute query = %s error message = %s\n", query,
3235                                    error_message);
3236                         ret = PMINFO_R_ERROR;
3237                         goto catch;
3238                 }
3239                 rpkgid = strdup(info->pkgid);
3240                 if (rpkgid == NULL) {
3241                         _LOGE("Out of Memory\n");
3242                         ret = PMINFO_R_ERROR;
3243                         goto catch;
3244                 }
3245                 free(info->pkgid);
3246                 info->pkgid = NULL;
3247         }
3248         ret = pkgmgrinfo_pkginfo_compare_pkg_cert_info(lpkgid, rpkgid, compare_result);
3249
3250  catch:
3251         sqlite3_free(error_message);
3252         sqlite3_close(pkginfo_db);
3253         if (info) {
3254                 if (info->pkgid) {
3255                         free(info->pkgid);
3256                         info->pkgid = NULL;
3257                 }
3258                 free(info);
3259                 info = NULL;
3260         }
3261         if (lpkgid) {
3262                 free(lpkgid);
3263                 lpkgid = NULL;
3264         }
3265         if (rpkgid) {
3266                 free(rpkgid);
3267                 rpkgid = NULL;
3268         }
3269         return ret;
3270 }
3271
3272 API int pkgmgrinfo_pkginfo_is_accessible(pkgmgrinfo_pkginfo_h handle, bool *accessible)
3273 {
3274         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3275         retvm_if(accessible == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3276
3277 #if 0 //smack issue occured, check later
3278         char *pkgid = NULL;
3279         pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
3280         if (pkgid == NULL){
3281                  _LOGD("invalid func parameters\n");
3282                  return PMINFO_R_ERROR;
3283         }
3284          _LOGD("pkgmgr_get_pkg_external_validation() called\n");
3285
3286         FILE *fp = NULL;
3287         char app_mmc_path[FILENAME_MAX] = { 0, };
3288         char app_dir_path[FILENAME_MAX] = { 0, };
3289         char app_mmc_internal_path[FILENAME_MAX] = { 0, };
3290         snprintf(app_dir_path, FILENAME_MAX,"%s%s", PKG_INSTALLATION_PATH, pkgid);
3291         snprintf(app_mmc_path, FILENAME_MAX,"%s%s", PKG_SD_PATH, pkgid);
3292         snprintf(app_mmc_internal_path, FILENAME_MAX,"%s%s/.mmc", PKG_INSTALLATION_PATH, pkgid);
3293
3294         /*check whether application is in external memory or not */
3295         fp = fopen(app_mmc_path, "r");
3296         if (fp == NULL){
3297                 _LOGD(" app path in external memory not accesible\n");
3298         } else {
3299                 fclose(fp);
3300                 fp = NULL;
3301                 *accessible = 1;
3302                 _LOGD("pkgmgr_get_pkg_external_validation() : SD_CARD \n");
3303                 return PMINFO_R_OK;
3304         }
3305
3306         /*check whether application is in internal or not */
3307         fp = fopen(app_dir_path, "r");
3308         if (fp == NULL) {
3309                 _LOGD(" app path in internal memory not accesible\n");
3310                 *accessible = 0;
3311                 return PMINFO_R_ERROR;
3312         } else {
3313                 fclose(fp);
3314                 /*check whether the application is installed in SD card
3315                 but SD card is not present*/
3316                 fp = fopen(app_mmc_internal_path, "r");
3317                 if (fp == NULL){
3318                         *accessible = 1;
3319                         _LOGD("pkgmgr_get_pkg_external_validation() : INTERNAL_MEM \n");
3320                         return PMINFO_R_OK;
3321                 }
3322                 else{
3323                         *accessible = 0;
3324                         _LOGD("pkgmgr_get_pkg_external_validation() : ERROR_MMC_STATUS \n");
3325                 }
3326                 fclose(fp);
3327         }
3328
3329         _LOGD("pkgmgr_get_pkg_external_validation() end\n");
3330 #endif
3331
3332         *accessible = 1;
3333         return PMINFO_R_OK;
3334 }
3335
3336 API int pkgmgrinfo_pkginfo_is_removable(pkgmgrinfo_pkginfo_h handle, bool *removable)
3337 {
3338         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3339         retvm_if(removable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3340         char *val = NULL;
3341         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3342         val = (char *)info->manifest_info->removable;
3343         if (val) {
3344                 if (strcasecmp(val, "true") == 0)
3345                         *removable = 1;
3346                 else if (strcasecmp(val, "false") == 0)
3347                         *removable = 0;
3348                 else
3349                         *removable = 1;
3350         }
3351         return PMINFO_R_OK;
3352 }
3353
3354 API int pkgmgrinfo_pkginfo_is_movable(pkgmgrinfo_pkginfo_h handle, bool *movable)
3355 {
3356         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3357         retvm_if(movable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3358
3359         char *val = NULL;
3360         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3361
3362         val = (char *)info->manifest_info->installlocation;
3363         if (val) {
3364                 if (strcmp(val, "internal-only") == 0)
3365                         *movable = 0;
3366                 else if (strcmp(val, "prefer-external") == 0)
3367                         *movable = 1;
3368                 else
3369                         *movable = 1;
3370         }
3371
3372         return PMINFO_R_OK;
3373 }
3374
3375 API int pkgmgrinfo_pkginfo_is_preload(pkgmgrinfo_pkginfo_h handle, bool *preload)
3376 {
3377         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3378         retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3379         char *val = NULL;
3380         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3381         val = (char *)info->manifest_info->preload;
3382         if (val) {
3383                 if (strcasecmp(val, "true") == 0)
3384                         *preload = 1;
3385                 else if (strcasecmp(val, "false") == 0)
3386                         *preload = 0;
3387                 else
3388                         *preload = 0;
3389         }
3390         return PMINFO_R_OK;
3391 }
3392
3393 API int pkgmgrinfo_pkginfo_is_system(pkgmgrinfo_pkginfo_h handle, bool *system)
3394 {
3395         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3396         retvm_if(system == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3397
3398         char *val = NULL;
3399         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3400         val = (char *)info->manifest_info->system;
3401         if (val) {
3402                 if (strcasecmp(val, "true") == 0)
3403                         *system = 1;
3404                 else if (strcasecmp(val, "false") == 0)
3405                         *system = 0;
3406                 else
3407                         *system = 0;
3408         }
3409
3410         return PMINFO_R_OK;
3411 }
3412
3413 API int pkgmgrinfo_pkginfo_is_readonly(pkgmgrinfo_pkginfo_h handle, bool *readonly)
3414 {
3415         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3416         retvm_if(readonly == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3417         char *val = NULL;
3418         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3419         val = (char *)info->manifest_info->readonly;
3420         if (val) {
3421                 if (strcasecmp(val, "true") == 0)
3422                         *readonly = 1;
3423                 else if (strcasecmp(val, "false") == 0)
3424                         *readonly = 0;
3425                 else
3426                         *readonly = 0;
3427         }
3428         return PMINFO_R_OK;
3429 }
3430
3431 API int pkgmgrinfo_pkginfo_is_update(pkgmgrinfo_pkginfo_h handle, bool *update)
3432 {
3433         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3434         retvm_if(update == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3435
3436         char *val = NULL;
3437         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3438         val = (char *)info->manifest_info->update;
3439         if (val) {
3440                 if (strcasecmp(val, "true") == 0)
3441                         *update = 1;
3442                 else if (strcasecmp(val, "false") == 0)
3443                         *update = 0;
3444                 else
3445                         *update = 1;
3446         }
3447         return PMINFO_R_OK;
3448 }
3449
3450 API int pkgmgrinfo_pkginfo_destroy_pkginfo(pkgmgrinfo_pkginfo_h handle)
3451 {
3452         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3453         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3454         __cleanup_pkginfo(info);
3455         return PMINFO_R_OK;
3456 }
3457
3458 API int pkgmgrinfo_pkginfo_filter_create(pkgmgrinfo_pkginfo_filter_h *handle)
3459 {
3460         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle output parameter is NULL\n");
3461         *handle = NULL;
3462         pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)calloc(1, sizeof(pkgmgrinfo_filter_x));
3463         if (filter == NULL) {
3464                 _LOGE("Out of Memory!!!");
3465                 return PMINFO_R_ERROR;
3466         }
3467         *handle = filter;
3468         return PMINFO_R_OK;
3469 }
3470
3471 API int pkgmgrinfo_pkginfo_filter_destroy(pkgmgrinfo_pkginfo_filter_h handle)
3472 {
3473         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3474         pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3475         if (filter->list){
3476                 g_slist_foreach(filter->list, __destroy_each_node, NULL);
3477                 g_slist_free(filter->list);
3478         }
3479         free(filter);
3480         filter = NULL;
3481
3482         if (access(PKG_SIZE_INFO_FILE, F_OK) == 0) {
3483                 char info_file[PKG_VALUE_STRING_LEN_MAX] = { 0, };
3484                 snprintf(info_file, PKG_VALUE_STRING_LEN_MAX, "%s", PKG_SIZE_INFO_FILE);
3485                 remove(info_file);
3486         }
3487
3488         return PMINFO_R_OK;
3489 }
3490
3491 API int pkgmgrinfo_pkginfo_filter_add_int(pkgmgrinfo_pkginfo_filter_h handle,
3492                                 const char *property, const int value)
3493 {
3494         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3495         retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3496         char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
3497         char *val = NULL;
3498         GSList *link = NULL;
3499         int prop = -1;
3500         prop = _pminfo_pkginfo_convert_to_prop_int(property);
3501         if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_INT ||
3502                 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_INT) {
3503                 _LOGE("Invalid Integer Property\n");
3504                 return PMINFO_R_EINVAL;
3505         }
3506         pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3507         pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
3508         if (node == NULL) {
3509                 _LOGE("Out of Memory!!!\n");
3510                 return PMINFO_R_ERROR;
3511         }
3512         snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
3513         val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
3514         if (val == NULL) {
3515                 _LOGE("Out of Memory\n");
3516                 free(node);
3517                 node = NULL;
3518                 return PMINFO_R_ERROR;
3519         }
3520         node->prop = prop;
3521         node->value = val;
3522         /*If API is called multiple times for same property, we should override the previous values.
3523         Last value set will be used for filtering.*/
3524         link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
3525         if (link)
3526                 filter->list = g_slist_delete_link(filter->list, link);
3527         filter->list = g_slist_append(filter->list, (gpointer)node);
3528         return PMINFO_R_OK;
3529
3530 }
3531
3532 API int pkgmgrinfo_pkginfo_filter_add_bool(pkgmgrinfo_pkginfo_filter_h handle,
3533                                 const char *property, const bool value)
3534 {
3535         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3536         retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3537         char *val = NULL;
3538         GSList *link = NULL;
3539         int prop = -1;
3540         prop = _pminfo_pkginfo_convert_to_prop_bool(property);
3541         if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_BOOL ||
3542                 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_BOOL) {
3543                 _LOGE("Invalid Boolean Property\n");
3544                 return PMINFO_R_EINVAL;
3545         }
3546         pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3547         pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
3548         if (node == NULL) {
3549                 _LOGE("Out of Memory!!!\n");
3550                 return PMINFO_R_ERROR;
3551         }
3552         if (value)
3553                 val = strndup("('true','True')", 15);
3554         else
3555                 val = strndup("('false','False')", 17);
3556         if (val == NULL) {
3557                 _LOGE("Out of Memory\n");
3558                 free(node);
3559                 node = NULL;
3560                 return PMINFO_R_ERROR;
3561         }
3562         node->prop = prop;
3563         node->value = val;
3564         /*If API is called multiple times for same property, we should override the previous values.
3565         Last value set will be used for filtering.*/
3566         link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
3567         if (link)
3568                 filter->list = g_slist_delete_link(filter->list, link);
3569         filter->list = g_slist_append(filter->list, (gpointer)node);
3570         return PMINFO_R_OK;
3571
3572 }
3573
3574 API int pkgmgrinfo_pkginfo_filter_add_string(pkgmgrinfo_pkginfo_filter_h handle,
3575                                 const char *property, const char *value)
3576 {
3577         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3578         retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3579         retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3580         char *val = NULL;
3581         GSList *link = NULL;
3582         int prop = -1;
3583         prop = _pminfo_pkginfo_convert_to_prop_str(property);
3584         if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_STR ||
3585                 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_STR) {
3586                 _LOGE("Invalid String Property\n");
3587                 return PMINFO_R_EINVAL;
3588         }
3589         pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3590         pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
3591         if (node == NULL) {
3592                 _LOGE("Out of Memory!!!\n");
3593                 return PMINFO_R_ERROR;
3594         }
3595         if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_AUTO) == 0)
3596                 val = strndup("auto", PKG_STRING_LEN_MAX - 1);
3597         else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_INTERNAL) == 0)
3598                 val = strndup("internal-only", PKG_STRING_LEN_MAX - 1);
3599         else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_EXTERNAL) == 0)
3600                 val = strndup("prefer-external", PKG_STRING_LEN_MAX - 1);
3601         else if (strcmp(value, "installed_internal") == 0)
3602                 val = strndup("installed_internal", PKG_STRING_LEN_MAX - 1);
3603         else if (strcmp(value, "installed_external") == 0)
3604                 val = strndup("installed_external", PKG_STRING_LEN_MAX - 1);
3605         else
3606                 val = strndup(value, PKG_STRING_LEN_MAX - 1);
3607         if (val == NULL) {
3608                 _LOGE("Out of Memory\n");
3609                 free(node);
3610                 node = NULL;
3611                 return PMINFO_R_ERROR;
3612         }
3613         node->prop = prop;
3614         node->value = val;
3615         /*If API is called multiple times for same property, we should override the previous values.
3616         Last value set will be used for filtering.*/
3617         link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
3618         if (link)
3619                 filter->list = g_slist_delete_link(filter->list, link);
3620         filter->list = g_slist_append(filter->list, (gpointer)node);
3621         return PMINFO_R_OK;
3622
3623 }
3624
3625 API int pkgmgrinfo_pkginfo_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count)
3626 {
3627         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3628         retvm_if(count == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3629         char *syslocale = NULL;
3630         char *locale = NULL;
3631         char *condition = NULL;
3632         char query[MAX_QUERY_LEN] = {'\0'};
3633         char where[MAX_QUERY_LEN] = {'\0'};
3634         GSList *list;
3635         int ret = 0;
3636         pkgmgr_pkginfo_x *node = NULL;
3637         pkgmgr_pkginfo_x *tmphead = NULL;
3638         pkgmgr_pkginfo_x *pkginfo = NULL;
3639         pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3640         sqlite3 *pkginfo_db = NULL;
3641         int filter_count = 0;
3642
3643         /*open db*/
3644         ret = db_util_open(MANIFEST_DB, &pkginfo_db, 0);
3645         retvm_if(ret != SQLITE_OK, PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
3646
3647         /*get system locale*/
3648         syslocale = vconf_get_str(VCONFKEY_LANGSET);
3649         locale = __convert_system_locale_to_manifest_locale(syslocale);
3650         tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
3651
3652         /*Start constructing query*/
3653         snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_LIST_PACKAGE, locale);
3654
3655         /*Get where clause*/
3656         for (list = filter->list; list; list = g_slist_next(list)) {
3657                 __get_filter_condition(list->data, &condition);
3658                 if (condition) {
3659                         strncat(where, condition, sizeof(where) - strlen(where) -1);
3660                         where[sizeof(where) - 1] = '\0';
3661                         free(condition);
3662                         condition = NULL;
3663                 }
3664                 if (g_slist_next(list)) {
3665                         strncat(where, " and ", sizeof(where) - strlen(where) - 1);
3666                         where[sizeof(where) - 1] = '\0';
3667                 }
3668         }
3669         _LOGE("where = %s\n", where);
3670         if (strlen(where) > 0) {
3671                 strncat(query, where, sizeof(query) - strlen(query) - 1);
3672                 query[sizeof(query) - 1] = '\0';
3673         }
3674         _LOGE("query = %s\n", query);
3675
3676         tmphead = calloc(1, sizeof(pkgmgr_pkginfo_x));
3677         tryvm_if(tmphead == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
3678
3679         ret = __exec_db_query(pkginfo_db, query, __pkg_list_cb, (void *)tmphead);
3680         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
3681
3682         LISTHEAD(tmphead, node);
3683         for(node = node->next ; node ; node = node->next) {
3684                 pkginfo = node;
3685                 pkginfo->locale = strdup(locale);
3686                 pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
3687                 tryvm_if(pkginfo->manifest_info->privileges == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for privileges info\n");
3688
3689                 /*populate manifest_info from DB*/
3690                 snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkginfo->manifest_info->package);
3691                 ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
3692                 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
3693
3694                 memset(query, '\0', MAX_QUERY_LEN);
3695                 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
3696                         " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, locale);
3697                 ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
3698                 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
3699
3700                 /*Also store the values corresponding to default locales*/
3701                 memset(query, '\0', MAX_QUERY_LEN);
3702                 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
3703                         " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, DEFAULT_LOCALE);
3704                 ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
3705                 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
3706         }
3707
3708         LISTHEAD(tmphead, node);
3709
3710         for(node = node->next ; node ; node = node->next) {
3711                 pkginfo = node;
3712                 ret = __pkginfo_check_installed_storage(pkginfo);
3713                 if(ret < 0)
3714                         continue;
3715                 filter_count++;
3716         }
3717
3718         *count = filter_count;
3719         ret = PMINFO_R_OK;
3720
3721 catch:
3722         if (locale) {
3723                 free(locale);
3724                 locale = NULL;
3725         }
3726         if (syslocale) {
3727                 free(syslocale);
3728                 syslocale = NULL;
3729         }
3730         sqlite3_close(pkginfo_db);
3731         __cleanup_pkginfo(tmphead);
3732         return ret;
3733 }
3734
3735 API int pkgmgrinfo_pkginfo_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h handle,
3736                                 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data)
3737 {
3738         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3739         retvm_if(pkg_cb == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3740         char *syslocale = NULL;
3741         char *locale = NULL;
3742         char *condition = NULL;
3743         char query[MAX_QUERY_LEN] = {'\0'};
3744         char where[MAX_QUERY_LEN] = {'\0'};
3745         GSList *list;
3746         int ret = 0;
3747         label_x *tmp1 = NULL;
3748         icon_x *tmp2 = NULL;
3749         description_x *tmp3 = NULL;
3750         author_x *tmp4 = NULL;
3751         privilege_x *tmp5 = NULL;
3752         pkgmgr_pkginfo_x *node = NULL;
3753         pkgmgr_pkginfo_x *tmphead = NULL;
3754         pkgmgr_pkginfo_x *pkginfo = NULL;
3755         pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3756         sqlite3 *pkginfo_db = NULL;
3757         const char* package_size_info = NULL;
3758         bool is_setting = false;
3759
3760         /*open db*/
3761         ret = db_util_open(MANIFEST_DB, &pkginfo_db, 0);
3762         retvm_if(ret != SQLITE_OK, PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
3763
3764         /*get system locale*/
3765         syslocale = vconf_get_str(VCONFKEY_LANGSET);
3766         locale = __convert_system_locale_to_manifest_locale(syslocale);
3767         tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
3768
3769         /*Start constructing query*/
3770         snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_LIST_PACKAGE, locale);
3771
3772         /*Get where clause*/
3773         for (list = filter->list; list; list = g_slist_next(list)) {
3774                 __get_filter_condition(list->data, &condition);
3775                 if (condition) {
3776                         strncat(where, condition, sizeof(where) - strlen(where) -1);
3777                         where[sizeof(where) - 1] = '\0';
3778
3779                         if (strstr(condition, "package_info.package_nodisplay"))
3780                                 is_setting = true;
3781
3782                         free(condition);
3783                         condition = NULL;
3784                 }
3785                 if (g_slist_next(list)) {
3786                         strncat(where, " and ", sizeof(where) - strlen(where) - 1);
3787                         where[sizeof(where) - 1] = '\0';
3788                 }
3789         }
3790         _LOGE("where = %s\n", where);
3791         if (strlen(where) > 0) {
3792                 strncat(query, where, sizeof(query) - strlen(query) - 1);
3793                 query[sizeof(query) - 1] = '\0';
3794         }
3795         _LOGE("query = %s\n", query);
3796
3797         tmphead = calloc(1, sizeof(pkgmgr_pkginfo_x));
3798         tryvm_if(tmphead == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
3799
3800         ret = __exec_db_query(pkginfo_db, query, __pkg_list_cb, (void *)tmphead);
3801         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
3802
3803         if (is_setting) {
3804                 ret = __reqeust_get_size("size_info", PM_GET_SIZE_INFO);
3805                 tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "fail reqeust size info");
3806
3807                 ret = __get_package_size_info(&package_size_info);
3808                 tryvm_if(ret != 0 || package_size_info == NULL, ret = PMINFO_R_ERROR, "__get_package_size_info() failed");
3809                 _LOGD("is_setting is true, get package size info success!! ");
3810         }
3811
3812         LISTHEAD(tmphead, node);
3813         for(node = node->next ; node ; node = node->next) {
3814                 pkginfo = node;
3815                 pkginfo->locale = strdup(locale);
3816                 pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
3817                 tryvm_if(pkginfo->manifest_info->privileges == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for privileges info\n");
3818
3819                 /*populate manifest_info from DB*/
3820                 snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkginfo->manifest_info->package);
3821                 ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
3822                 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
3823
3824                 memset(query, '\0', MAX_QUERY_LEN);
3825                 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
3826                         " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, locale);
3827                 ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
3828                 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
3829
3830                 /*Also store the values corresponding to default locales*/
3831                 memset(query, '\0', MAX_QUERY_LEN);
3832                 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
3833                         " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, DEFAULT_LOCALE);
3834                 ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
3835                 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
3836
3837                 if (pkginfo->manifest_info->label) {
3838                         LISTHEAD(pkginfo->manifest_info->label, tmp1);
3839                         pkginfo->manifest_info->label = tmp1;
3840                 }
3841                 if (pkginfo->manifest_info->icon) {
3842                         LISTHEAD(pkginfo->manifest_info->icon, tmp2);
3843                         pkginfo->manifest_info->icon = tmp2;
3844                 }
3845                 if (pkginfo->manifest_info->description) {
3846                         LISTHEAD(pkginfo->manifest_info->description, tmp3);
3847                         pkginfo->manifest_info->description = tmp3;
3848                 }
3849                 if (pkginfo->manifest_info->author) {
3850                         LISTHEAD(pkginfo->manifest_info->author, tmp4);
3851                         pkginfo->manifest_info->author = tmp4;
3852                 }
3853                 if (pkginfo->manifest_info->privileges->privilege) {
3854                         LISTHEAD(pkginfo->manifest_info->privileges->privilege, tmp5);
3855                         pkginfo->manifest_info->privileges->privilege = tmp5;
3856                 }
3857                 if (is_setting) {
3858                         __set_package_size_info(pkginfo->manifest_info, package_size_info);
3859                 }
3860         }
3861
3862         LISTHEAD(tmphead, node);
3863
3864         for(node = node->next ; node ; node = node->next) {
3865                 pkginfo = node;
3866
3867                 ret = __pkginfo_check_installed_storage(pkginfo);
3868                 if(ret < 0)
3869                         continue;
3870
3871                 ret = pkg_cb( (void *)pkginfo, user_data);
3872                 if(ret < 0)
3873                         break;
3874         }
3875         ret = PMINFO_R_OK;
3876
3877 catch:
3878         if (locale) {
3879                 free(locale);
3880                 locale = NULL;
3881         }
3882         if (syslocale) {
3883                 free(syslocale);
3884                 syslocale = NULL;
3885         }
3886         if (package_size_info) {
3887                 free(package_size_info);
3888         }
3889
3890         sqlite3_close(pkginfo_db);
3891         __cleanup_pkginfo(tmphead);
3892         return ret;
3893 }
3894
3895 API int pkgmgrinfo_pkginfo_foreach_privilege(pkgmgrinfo_pkginfo_h handle,
3896                         pkgmgrinfo_pkg_privilege_list_cb privilege_func, void *user_data)
3897 {
3898         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
3899         retvm_if(privilege_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
3900         int ret = -1;
3901         privilege_x *ptr = NULL;
3902         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3903         ptr = info->manifest_info->privileges->privilege;
3904         for (; ptr; ptr = ptr->next) {
3905                 if (ptr->text){
3906                         ret = privilege_func(ptr->text, user_data);
3907                         if (ret < 0)
3908                                 break;
3909                 }
3910         }
3911         return PMINFO_R_OK;
3912 }
3913
3914 API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_component component,
3915                                                 pkgmgrinfo_app_list_cb app_func, void *user_data)
3916 {
3917         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
3918         retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback pointer is NULL");
3919         retvm_if((component != PMINFO_UI_APP) && (component != PMINFO_SVC_APP) && (component != PMINFO_ALL_APP), PMINFO_R_EINVAL, "Invalid App Component Type");
3920
3921         char *syslocale = NULL;
3922         char *locale = NULL;
3923         int ret = -1;
3924         char query[MAX_QUERY_LEN] = {'\0'};
3925         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3926         pkgmgr_pkginfo_x *allinfo = NULL;
3927         pkgmgr_appinfo_x *appinfo = NULL;
3928         icon_x *ptr1 = NULL;
3929         label_x *ptr2 = NULL;
3930         category_x *ptr3 = NULL;
3931         metadata_x *ptr4 = NULL;
3932         permission_x *ptr5 = NULL;
3933         image_x *ptr6 = NULL;
3934         sqlite3 *appinfo_db = NULL;
3935
3936         /*check installed storage*/
3937         ret = __pkginfo_check_installed_storage(info);
3938         retvm_if(ret < 0, PMINFO_R_EINVAL, "[%s] is installed external, but is not in mmc", info->manifest_info->package);
3939
3940         /*get system locale*/
3941         syslocale = vconf_get_str(VCONFKEY_LANGSET);
3942         locale = __convert_system_locale_to_manifest_locale(syslocale);
3943         tryvm_if(locale == NULL, ret = PMINFO_R_EINVAL, "manifest locale is NULL");
3944
3945         /*calloc allinfo*/
3946         allinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
3947         tryvm_if(allinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
3948
3949         /*calloc manifest_info*/
3950         allinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
3951         tryvm_if(allinfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
3952
3953         /*calloc appinfo*/
3954         appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
3955         tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
3956
3957         /*set component type*/
3958         if (component == PMINFO_UI_APP)
3959                 appinfo->app_component = PMINFO_UI_APP;
3960         if (component == PMINFO_SVC_APP)
3961                 appinfo->app_component = PMINFO_SVC_APP;
3962         if (component == PMINFO_ALL_APP)
3963                 appinfo->app_component = PMINFO_ALL_APP;
3964
3965         /*open db */
3966         ret = db_util_open(MANIFEST_DB, &appinfo_db, 0);
3967         tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
3968
3969         appinfo->package = strdup(info->manifest_info->package);
3970         snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
3971                         "from package_app_info where " \
3972                         "package='%s' and app_component='%s'",
3973                         info->manifest_info->package,
3974                         (appinfo->app_component==PMINFO_UI_APP ? "uiapp" : "svcapp"));
3975
3976         switch(component) {
3977         case PMINFO_UI_APP:
3978                 /*Populate ui app info */
3979                 ret = __exec_db_query(appinfo_db, query, __uiapp_list_cb, (void *)info);
3980                 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
3981
3982                 uiapplication_x *tmp = NULL;
3983                 if (info->manifest_info->uiapplication) {
3984                         LISTHEAD(info->manifest_info->uiapplication, tmp);
3985                         info->manifest_info->uiapplication = tmp;
3986                 }
3987                 /*Populate localized info for default locales and call callback*/
3988                 /*If the callback func return < 0 we break and no more call back is called*/
3989                 while(tmp != NULL)
3990                 {
3991                         appinfo->locale = strdup(locale);
3992                         appinfo->uiapp_info = tmp;
3993                         if (strcmp(appinfo->uiapp_info->type,"c++app") == 0){
3994                                 if (locale) {
3995                                         free(locale);
3996                                 }
3997                                 locale = __get_app_locale_by_fallback(appinfo_db, appinfo->uiapp_info->appid, syslocale);
3998                         }
3999
4000                         memset(query, '\0', MAX_QUERY_LEN);
4001                         snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->uiapp_info->appid, locale);
4002                         ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4003                         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4004
4005                         memset(query, '\0', MAX_QUERY_LEN);
4006                         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);
4007                         ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4008                         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4009
4010                         /*store setting notification icon section*/
4011                         memset(query, '\0', MAX_QUERY_LEN);
4012                         snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appinfo->uiapp_info->appid);
4013                         ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4014                         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
4015                         
4016                         /*store app preview image info*/
4017                         memset(query, '\0', MAX_QUERY_LEN);
4018                         snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", appinfo->uiapp_info->appid);
4019                         ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4020                         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
4021
4022                         if (appinfo->uiapp_info->label) {
4023                                 LISTHEAD(appinfo->uiapp_info->label, ptr2);
4024                                 appinfo->uiapp_info->label = ptr2;
4025                         }
4026                         if (appinfo->uiapp_info->icon) {
4027                                 LISTHEAD(appinfo->uiapp_info->icon, ptr1);
4028                                 appinfo->uiapp_info->icon = ptr1;
4029                         }
4030                         if (appinfo->uiapp_info->category) {
4031                                 LISTHEAD(appinfo->uiapp_info->category, ptr3);
4032                                 appinfo->uiapp_info->category = ptr3;
4033                         }
4034                         if (appinfo->uiapp_info->metadata) {
4035                                 LISTHEAD(appinfo->uiapp_info->metadata, ptr4);
4036                                 appinfo->uiapp_info->metadata = ptr4;
4037                         }
4038                         if (appinfo->uiapp_info->permission) {
4039                                 LISTHEAD(appinfo->uiapp_info->permission, ptr5);
4040                                 appinfo->uiapp_info->permission = ptr5;
4041                         }
4042                         if (appinfo->uiapp_info->image) {
4043                                 LISTHEAD(appinfo->uiapp_info->image, ptr6);
4044                                 appinfo->uiapp_info->image = ptr6;
4045                         }
4046                         ret = app_func((void *)appinfo, user_data);
4047                         if (ret < 0)
4048                                 break;
4049                         tmp = tmp->next;
4050                 }
4051                 break;
4052         case PMINFO_SVC_APP:
4053                 /*Populate svc app info */
4054                 ret = __exec_db_query(appinfo_db, query, __svcapp_list_cb, (void *)info);
4055                 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
4056
4057                 serviceapplication_x *tmp1 = NULL;
4058                 if (info->manifest_info->serviceapplication) {
4059                         LISTHEAD(info->manifest_info->serviceapplication, tmp1);
4060                         info->manifest_info->serviceapplication = tmp1;
4061                 }
4062                 /*Populate localized info for default locales and call callback*/
4063                 /*If the callback func return < 0 we break and no more call back is called*/
4064                 while(tmp1 != NULL)
4065                 {
4066                         appinfo->locale = strdup(locale);
4067                         appinfo->svcapp_info = tmp1;
4068                         memset(query, '\0', MAX_QUERY_LEN);
4069                         snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->svcapp_info->appid, locale);
4070                         ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4071                         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4072
4073                         memset(query, '\0', MAX_QUERY_LEN);
4074                         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);
4075                         ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4076                         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4077
4078                         if (appinfo->svcapp_info->label) {
4079                                 LISTHEAD(appinfo->svcapp_info->label, ptr2);
4080                                 appinfo->svcapp_info->label = ptr2;
4081                         }
4082                         if (appinfo->svcapp_info->icon) {
4083                                 LISTHEAD(appinfo->svcapp_info->icon, ptr1);
4084                                 appinfo->svcapp_info->icon = ptr1;
4085                         }
4086                         if (appinfo->svcapp_info->category) {
4087                                 LISTHEAD(appinfo->svcapp_info->category, ptr3);
4088                                 appinfo->svcapp_info->category = ptr3;
4089                         }
4090                         if (appinfo->svcapp_info->metadata) {
4091                                 LISTHEAD(appinfo->svcapp_info->metadata, ptr4);
4092                                 appinfo->svcapp_info->metadata = ptr4;
4093                         }
4094                         if (appinfo->svcapp_info->permission) {
4095                                 LISTHEAD(appinfo->svcapp_info->permission, ptr5);
4096                                 appinfo->svcapp_info->permission = ptr5;
4097                         }
4098                         ret = app_func((void *)appinfo, user_data);
4099                         if (ret < 0)
4100                                 break;
4101                         tmp1 = tmp1->next;
4102                 }
4103                 break;
4104         case PMINFO_ALL_APP:
4105                 memset(query, '\0', MAX_QUERY_LEN);
4106                 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where package='%s'", info->manifest_info->package);
4107
4108                 /*Populate all app info */
4109                 ret = __exec_db_query(appinfo_db, query, __allapp_list_cb, (void *)allinfo);
4110                 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
4111
4112                 /*UI Apps*/
4113                 appinfo->app_component = PMINFO_UI_APP;
4114                 uiapplication_x *tmp2 = NULL;
4115                 if (allinfo->manifest_info->uiapplication) {
4116                         LISTHEAD(allinfo->manifest_info->uiapplication, tmp2);
4117                         allinfo->manifest_info->uiapplication = tmp2;
4118                 }
4119                 /*Populate localized info for default locales and call callback*/
4120                 /*If the callback func return < 0 we break and no more call back is called*/
4121                 while(tmp2 != NULL)
4122                 {
4123                         appinfo->locale = strdup(locale);
4124                         appinfo->uiapp_info = tmp2;
4125                         memset(query, '\0', MAX_QUERY_LEN);
4126                         snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->uiapp_info->appid, locale);
4127                         ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4128                         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4129
4130                         memset(query, '\0', MAX_QUERY_LEN);
4131                         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);
4132                         ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4133                         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4134
4135                         /*store setting notification icon section*/
4136                         memset(query, '\0', MAX_QUERY_LEN);
4137                         snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appinfo->uiapp_info->appid);
4138                         ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4139                         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
4140                         
4141                         /*store app preview image info*/
4142                         memset(query, '\0', MAX_QUERY_LEN);
4143                         snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", appinfo->uiapp_info->appid);
4144                         ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4145                         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
4146
4147                         if (appinfo->uiapp_info->label) {
4148                                 LISTHEAD(appinfo->uiapp_info->label, ptr2);
4149                                 appinfo->uiapp_info->label = ptr2;
4150                         }
4151                         if (appinfo->uiapp_info->icon) {
4152                                 LISTHEAD(appinfo->uiapp_info->icon, ptr1);
4153                                 appinfo->uiapp_info->icon = ptr1;
4154                         }
4155                         if (appinfo->uiapp_info->category) {
4156                                 LISTHEAD(appinfo->uiapp_info->category, ptr3);
4157                                 appinfo->uiapp_info->category = ptr3;
4158                         }
4159                         if (appinfo->uiapp_info->metadata) {
4160                                 LISTHEAD(appinfo->uiapp_info->metadata, ptr4);
4161                                 appinfo->uiapp_info->metadata = ptr4;
4162                         }
4163                         if (appinfo->uiapp_info->permission) {
4164                                 LISTHEAD(appinfo->uiapp_info->permission, ptr5);
4165                                 appinfo->uiapp_info->permission = ptr5;
4166                         }
4167                         if (appinfo->uiapp_info->image) {
4168                                 LISTHEAD(appinfo->uiapp_info->image, ptr6);
4169                                 appinfo->uiapp_info->image = ptr6;
4170                         }
4171                         ret = app_func((void *)appinfo, user_data);
4172                         if (ret < 0)
4173                                 break;
4174                         tmp2 = tmp2->next;
4175                 }
4176
4177                 /*SVC Apps*/
4178                 appinfo->app_component = PMINFO_SVC_APP;
4179                 serviceapplication_x *tmp3 = NULL;
4180                 if (allinfo->manifest_info->serviceapplication) {
4181                         LISTHEAD(allinfo->manifest_info->serviceapplication, tmp3);
4182                         allinfo->manifest_info->serviceapplication = tmp3;
4183                 }
4184                 /*Populate localized info for default locales and call callback*/
4185                 /*If the callback func return < 0 we break and no more call back is called*/
4186                 while(tmp3 != NULL)
4187                 {
4188                         appinfo->locale = strdup(locale);
4189                         appinfo->svcapp_info = tmp3;
4190                         memset(query, '\0', MAX_QUERY_LEN);
4191                         snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->svcapp_info->appid, locale);
4192                         ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4193                         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4194
4195                         memset(query, '\0', MAX_QUERY_LEN);
4196                         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);
4197                         ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4198                         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4199
4200                         if (appinfo->svcapp_info->label) {
4201                                 LISTHEAD(appinfo->svcapp_info->label, ptr2);
4202                                 appinfo->svcapp_info->label = ptr2;
4203                         }
4204                         if (appinfo->svcapp_info->icon) {
4205                                 LISTHEAD(appinfo->svcapp_info->icon, ptr1);
4206                                 appinfo->svcapp_info->icon = ptr1;
4207                         }
4208                         if (appinfo->svcapp_info->category) {
4209                                 LISTHEAD(appinfo->svcapp_info->category, ptr3);
4210                                 appinfo->svcapp_info->category = ptr3;
4211                         }
4212                         if (appinfo->svcapp_info->metadata) {
4213                                 LISTHEAD(appinfo->svcapp_info->metadata, ptr4);
4214                                 appinfo->svcapp_info->metadata = ptr4;
4215                         }
4216                         if (appinfo->svcapp_info->permission) {
4217                                 LISTHEAD(appinfo->svcapp_info->permission, ptr5);
4218                                 appinfo->svcapp_info->permission = ptr5;
4219                         }
4220                         ret = app_func((void *)appinfo, user_data);
4221                         if (ret < 0)
4222                                 break;
4223                         tmp3 = tmp3->next;
4224                 }
4225                 appinfo->app_component = PMINFO_ALL_APP;
4226                 break;
4227
4228         }
4229
4230         ret = PMINFO_R_OK;
4231 catch:
4232         if (locale) {
4233                 free(locale);
4234                 locale = NULL;
4235         }
4236         if (syslocale) {
4237                 free(syslocale);
4238                 syslocale = NULL;
4239         }
4240         if (appinfo) {
4241                 if (appinfo->package) {
4242                         free((void *)appinfo->package);
4243                         appinfo->package = NULL;
4244                 }
4245                 free(appinfo);
4246                 appinfo = NULL;
4247         }
4248         __cleanup_pkginfo(allinfo);
4249
4250         sqlite3_close(appinfo_db);
4251         return ret;
4252 }
4253
4254 API int pkgmgrinfo_appinfo_get_install_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
4255 {
4256         retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback function is NULL");
4257
4258         int ret = PMINFO_R_OK;
4259         char query[MAX_QUERY_LEN] = {'\0'};
4260         pkgmgr_appinfo_x *appinfo = NULL;
4261         uiapplication_x *ptr1 = NULL;
4262         serviceapplication_x *ptr2 = NULL;
4263         sqlite3 *appinfo_db = NULL;
4264
4265         /*open db*/
4266         ret = db_util_open(MANIFEST_DB, &appinfo_db, 0);
4267         retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
4268
4269         /*calloc pkginfo*/
4270         pkgmgr_pkginfo_x *info = NULL;
4271         info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
4272         tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4273
4274         /*calloc manifest_info*/
4275         info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
4276         tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4277
4278         /*calloc appinfo*/
4279         appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
4280         tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4281
4282         snprintf(query, MAX_QUERY_LEN, "select * from package_app_info");
4283         ret = __exec_db_query(appinfo_db, query, __mini_appinfo_cb, (void *)info);
4284         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4285
4286         if (info->manifest_info->uiapplication) {
4287                 LISTHEAD(info->manifest_info->uiapplication, ptr1);
4288                 info->manifest_info->uiapplication = ptr1;
4289         }
4290         if (info->manifest_info->serviceapplication) {
4291                 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
4292                 info->manifest_info->serviceapplication = ptr2;
4293         }
4294
4295         /*UI Apps*/
4296         for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
4297         {
4298                 appinfo->app_component = PMINFO_UI_APP;
4299                 appinfo->package = strdup(ptr1->package);
4300                 appinfo->uiapp_info = ptr1;
4301
4302                 ret = __appinfo_check_installed_storage(appinfo);
4303                 if(ret < 0)
4304                         continue;
4305
4306                 ret = app_func((void *)appinfo, user_data);
4307                 if (ret < 0)
4308                         break;
4309                 free((void *)appinfo->package);
4310                 appinfo->package = NULL;
4311         }
4312         /*Service Apps*/
4313         for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
4314         {
4315                 appinfo->app_component = PMINFO_SVC_APP;
4316                 appinfo->package = strdup(ptr2->package);
4317                 appinfo->svcapp_info = ptr2;
4318
4319                 ret = app_func((void *)appinfo, user_data);
4320                 if (ret < 0)
4321                         break;
4322                 free((void *)appinfo->package);
4323                 appinfo->package = NULL;
4324         }
4325         ret = PMINFO_R_OK;
4326
4327 catch:
4328         sqlite3_close(appinfo_db);
4329
4330         if (appinfo) {
4331                 free(appinfo);
4332                 appinfo = NULL;
4333         }
4334         __cleanup_pkginfo(info);
4335         return ret;
4336 }
4337
4338 API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
4339 {
4340         retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback function is NULL");
4341
4342         int ret = PMINFO_R_OK;
4343         char query[MAX_QUERY_LEN] = {'\0'};
4344         char *syslocale = NULL;
4345         char *locale = NULL;
4346         pkgmgr_appinfo_x *appinfo = NULL;
4347         uiapplication_x *ptr1 = NULL;
4348         serviceapplication_x *ptr2 = NULL;
4349         label_x *tmp1 = NULL;
4350         icon_x *tmp2 = NULL;
4351         category_x *tmp3 = NULL;
4352         metadata_x *tmp4 = NULL;
4353         permission_x *tmp5 = NULL;
4354         image_x *tmp6 = NULL;
4355         sqlite3 *appinfo_db = NULL;
4356
4357         /*get system locale*/
4358         syslocale = vconf_get_str(VCONFKEY_LANGSET);
4359         locale = __convert_system_locale_to_manifest_locale(syslocale);
4360         tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
4361
4362         /*open db*/
4363         ret = db_util_open(MANIFEST_DB, &appinfo_db, 0);
4364         retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
4365
4366         /*calloc pkginfo*/
4367         pkgmgr_pkginfo_x *info = NULL;
4368         info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
4369         tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4370
4371         /*calloc manifest_info*/
4372         info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
4373         tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4374
4375         /*calloc appinfo*/
4376         appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
4377         tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4378
4379         snprintf(query, MAX_QUERY_LEN, "select * from package_app_info");
4380         ret = __exec_db_query(appinfo_db, query, __app_list_cb, (void *)info);
4381         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4382
4383         if (info->manifest_info->uiapplication) {
4384                 LISTHEAD(info->manifest_info->uiapplication, ptr1);
4385                 info->manifest_info->uiapplication = ptr1;
4386         }
4387         if (info->manifest_info->serviceapplication) {
4388                 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
4389                 info->manifest_info->serviceapplication = ptr2;
4390         }
4391
4392         /*UI Apps*/
4393         for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
4394         {
4395                 appinfo->locale = strdup(locale);
4396                 appinfo->app_component = PMINFO_UI_APP;
4397                 appinfo->package = strdup(ptr1->package);
4398                 appinfo->uiapp_info = ptr1;
4399                 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4400                                 "from package_app_info where " \
4401                                 "app_id='%s'", ptr1->appid);
4402                 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4403                 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4404
4405                 if (strcmp(appinfo->uiapp_info->type,"c++app") == 0){
4406                         if (locale) {
4407                                 free(locale);
4408                         }
4409                         locale = __get_app_locale_by_fallback(appinfo_db, ptr1->appid, syslocale);
4410                 }
4411
4412                 memset(query, '\0', MAX_QUERY_LEN);
4413                 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4414                                 "from package_app_localized_info where " \
4415                                 "app_id='%s' and app_locale='%s'",
4416                                 ptr1->appid, locale);
4417                 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4418                 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4419
4420                 memset(query, '\0', MAX_QUERY_LEN);
4421                 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4422                                 "from package_app_localized_info where " \
4423                                 "app_id='%s' and app_locale='%s'",
4424                                 ptr1->appid, DEFAULT_LOCALE);
4425
4426                 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4427                 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4428
4429                 /*store setting notification icon section*/
4430                 memset(query, '\0', MAX_QUERY_LEN);
4431                 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", ptr1->appid);
4432                 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4433                 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
4434                 
4435                 /*store app preview image info*/
4436                 memset(query, '\0', MAX_QUERY_LEN);
4437                 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", ptr1->appid);
4438                 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4439                 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
4440
4441                 if (appinfo->uiapp_info->label) {
4442                         LISTHEAD(appinfo->uiapp_info->label, tmp1);
4443                         appinfo->uiapp_info->label = tmp1;
4444                 }
4445                 if (appinfo->uiapp_info->icon) {
4446                         LISTHEAD(appinfo->uiapp_info->icon, tmp2);
4447                         appinfo->uiapp_info->icon= tmp2;
4448                 }
4449                 if (appinfo->uiapp_info->category) {
4450                         LISTHEAD(appinfo->uiapp_info->category, tmp3);
4451                         appinfo->uiapp_info->category = tmp3;
4452                 }
4453                 if (appinfo->uiapp_info->metadata) {
4454                         LISTHEAD(appinfo->uiapp_info->metadata, tmp4);
4455                         appinfo->uiapp_info->metadata = tmp4;
4456                 }
4457                 if (appinfo->uiapp_info->permission) {
4458                         LISTHEAD(appinfo->uiapp_info->permission, tmp5);
4459                         appinfo->uiapp_info->permission = tmp5;
4460                 }
4461                 if (appinfo->uiapp_info->image) {
4462                         LISTHEAD(appinfo->uiapp_info->image, tmp6);
4463                         appinfo->uiapp_info->image = tmp6;
4464                 }
4465
4466                 ret = __appinfo_check_installed_storage(appinfo);
4467                 if(ret < 0)
4468                         continue;
4469
4470                 ret = app_func((void *)appinfo, user_data);
4471                 if (ret < 0)
4472                         break;
4473                 free((void *)appinfo->package);
4474                 appinfo->package = NULL;
4475         }
4476         /*Service Apps*/
4477         for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
4478         {
4479                 appinfo->locale = strdup(locale);
4480                 appinfo->app_component = PMINFO_SVC_APP;
4481                 appinfo->package = strdup(ptr2->package);
4482                 appinfo->svcapp_info = ptr2;
4483                 memset(query, '\0', MAX_QUERY_LEN);
4484                 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4485                                 "from package_app_info where " \
4486                                 "app_id='%s'", ptr2->appid);
4487                 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4488                 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4489
4490                 memset(query, '\0', MAX_QUERY_LEN);
4491                 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4492                                 "from package_app_localized_info where " \
4493                                 "app_id='%s' and app_locale='%s'",
4494                                 ptr2->appid, locale);
4495                 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4496                 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4497
4498                 memset(query, '\0', MAX_QUERY_LEN);
4499                 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4500                                 "from package_app_localized_info where " \
4501                                 "app_id='%s' and app_locale='%s'",
4502                                 ptr2->appid, DEFAULT_LOCALE);
4503                 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4504                 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4505
4506                 if (appinfo->svcapp_info->label) {
4507                         LISTHEAD(appinfo->svcapp_info->label, tmp1);
4508                         appinfo->svcapp_info->label = tmp1;
4509                 }
4510                 if (appinfo->svcapp_info->icon) {
4511                         LISTHEAD(appinfo->svcapp_info->icon, tmp2);
4512                         appinfo->svcapp_info->icon= tmp2;
4513                 }
4514                 if (appinfo->svcapp_info->category) {
4515                         LISTHEAD(appinfo->svcapp_info->category, tmp3);
4516                         appinfo->svcapp_info->category = tmp3;
4517                 }
4518                 if (appinfo->svcapp_info->metadata) {
4519                         LISTHEAD(appinfo->svcapp_info->metadata, tmp4);
4520                         appinfo->svcapp_info->metadata = tmp4;
4521                 }
4522                 if (appinfo->svcapp_info->permission) {
4523                         LISTHEAD(appinfo->svcapp_info->permission, tmp5);
4524                         appinfo->svcapp_info->permission = tmp5;
4525                 }
4526                 ret = app_func((void *)appinfo, user_data);
4527                 if (ret < 0)
4528                         break;
4529                 free((void *)appinfo->package);
4530                 appinfo->package = NULL;
4531         }
4532         ret = PMINFO_R_OK;
4533
4534 catch:
4535         if (locale) {
4536                 free(locale);
4537                 locale = NULL;
4538         }
4539         if (syslocale) {
4540                 free(syslocale);
4541                 syslocale = NULL;
4542         }
4543         sqlite3_close(appinfo_db);
4544         if (appinfo) {
4545                 free(appinfo);
4546                 appinfo = NULL;
4547         }
4548         __cleanup_pkginfo(info);
4549         return ret;
4550 }
4551
4552 API int pkgmgrinfo_appinfo_get_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
4553 {
4554         retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL");
4555         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4556
4557         pkgmgr_appinfo_x *appinfo = NULL;
4558         char *syslocale = NULL;
4559         char *locale = NULL;
4560         int ret = -1;
4561         int exist = 0;
4562         label_x *tmp1 = NULL;
4563         icon_x *tmp2 = NULL;
4564         category_x *tmp3 = NULL;
4565         metadata_x *tmp4 = NULL;
4566         permission_x *tmp5 = NULL;
4567         image_x *tmp6 = NULL;
4568         char query[MAX_QUERY_LEN] = {'\0'};
4569         sqlite3 *appinfo_db = NULL;
4570
4571         /*open db*/
4572         ret = db_util_open(MANIFEST_DB, &appinfo_db, 0);
4573         retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
4574
4575         /*check appid exist on db*/
4576         snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", appid);
4577         ret = __exec_db_query(appinfo_db, query, __validate_cb, (void *)&exist);
4578         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "sqlite3_exec fail");
4579         tryvm_if(exist == 0, ret = PMINFO_R_ERROR, "Appid[%s] not found in DB", appid);
4580
4581         /*get system locale*/
4582         syslocale = vconf_get_str(VCONFKEY_LANGSET);
4583         locale = __convert_system_locale_to_manifest_locale(syslocale);
4584         tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
4585
4586         /*calloc appinfo*/
4587         appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
4588         tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
4589
4590         /*check app_component from DB*/
4591         memset(query, '\0', MAX_QUERY_LEN);
4592         snprintf(query, MAX_QUERY_LEN, "select app_component, package from package_app_info where app_id='%s' ", appid);
4593         ret = __exec_db_query(appinfo_db, query, __appcomponent_cb, (void *)appinfo);
4594         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4595
4596         /*calloc app_component*/
4597         if (appinfo->app_component == PMINFO_UI_APP) {
4598                 appinfo->uiapp_info = (uiapplication_x *)calloc(1, sizeof(uiapplication_x));
4599                 tryvm_if(appinfo->uiapp_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for uiapp info");
4600         } else {
4601                 appinfo->svcapp_info = (serviceapplication_x *)calloc(1, sizeof(serviceapplication_x));
4602                 tryvm_if(appinfo->svcapp_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for svcapp info");
4603         }
4604         appinfo->locale = strdup(locale);
4605
4606         /*populate app_info from DB*/
4607         memset(query, '\0', MAX_QUERY_LEN);
4608         snprintf(query, MAX_QUERY_LEN, "select * from package_app_info 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 Info DB Information retrieval failed");
4611
4612         memset(query, '\0', MAX_QUERY_LEN);
4613         snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appid, locale);
4614         ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4615         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4616
4617         /*Also store the values corresponding to default locales*/
4618         memset(query, '\0', MAX_QUERY_LEN);
4619         snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appid, DEFAULT_LOCALE);
4620         ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4621         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4622
4623         /*Populate app category*/
4624         memset(query, '\0', MAX_QUERY_LEN);
4625         snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_category where app_id='%s'", appid);
4626         ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4627         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Category Info DB Information retrieval failed");
4628
4629         /*Populate app metadata*/
4630         memset(query, '\0', MAX_QUERY_LEN);
4631         snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_metadata where app_id='%s'", appid);
4632         ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4633         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Metadata Info DB Information retrieval failed");
4634
4635         /*Populate app permission*/
4636         memset(query, '\0', MAX_QUERY_LEN);
4637         snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_permission where app_id='%s'", appid);
4638         ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4639         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App permission Info DB Information retrieval failed");
4640
4641         /*store setting notification icon section*/
4642         memset(query, '\0', MAX_QUERY_LEN);
4643         snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appid);
4644         ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4645         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
4646
4647         /*store app preview image info*/
4648         memset(query, '\0', MAX_QUERY_LEN);
4649         snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", appid);
4650         ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4651         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
4652
4653         ret = __appinfo_check_installed_storage(appinfo);
4654         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "[%s] is installed external, but is not in mmc", appinfo->package);
4655
4656         switch (appinfo->app_component) {
4657         case PMINFO_UI_APP:
4658                 if (appinfo->uiapp_info->label) {
4659                         LISTHEAD(appinfo->uiapp_info->label, tmp1);
4660                         appinfo->uiapp_info->label = tmp1;
4661                 }
4662                 if (appinfo->uiapp_info->icon) {
4663                         LISTHEAD(appinfo->uiapp_info->icon, tmp2);
4664                         appinfo->uiapp_info->icon = tmp2;
4665                 }
4666                 if (appinfo->uiapp_info->category) {
4667                         LISTHEAD(appinfo->uiapp_info->category, tmp3);
4668                         appinfo->uiapp_info->category = tmp3;
4669                 }
4670                 if (appinfo->uiapp_info->metadata) {
4671                         LISTHEAD(appinfo->uiapp_info->metadata, tmp4);
4672                         appinfo->uiapp_info->metadata = tmp4;
4673                 }
4674                 if (appinfo->uiapp_info->permission) {
4675                         LISTHEAD(appinfo->uiapp_info->permission, tmp5);
4676                         appinfo->uiapp_info->permission = tmp5;
4677                 }
4678                 if (appinfo->uiapp_info->image) {
4679                         LISTHEAD(appinfo->uiapp_info->image, tmp6);
4680                         appinfo->uiapp_info->image = tmp6;
4681                 }
4682                 break;
4683         case PMINFO_SVC_APP:
4684                 if (appinfo->svcapp_info->label) {
4685                         LISTHEAD(appinfo->svcapp_info->label, tmp1);
4686                         appinfo->svcapp_info->label = tmp1;
4687                 }
4688                 if (appinfo->svcapp_info->icon) {
4689                         LISTHEAD(appinfo->svcapp_info->icon, tmp2);
4690                         appinfo->svcapp_info->icon = tmp2;
4691                 }
4692                 if (appinfo->svcapp_info->category) {
4693                         LISTHEAD(appinfo->svcapp_info->category, tmp3);
4694                         appinfo->svcapp_info->category = tmp3;
4695                 }
4696                 if (appinfo->svcapp_info->metadata) {
4697                         LISTHEAD(appinfo->svcapp_info->metadata, tmp4);
4698                         appinfo->svcapp_info->metadata = tmp4;
4699                 }
4700                 if (appinfo->svcapp_info->permission) {
4701                         LISTHEAD(appinfo->svcapp_info->permission, tmp5);
4702                         appinfo->svcapp_info->permission = tmp5;
4703                 }
4704                 break;
4705         default:
4706                 break;
4707         }
4708
4709         ret = PMINFO_R_OK;
4710
4711 catch:
4712         if (ret == PMINFO_R_OK)
4713                 *handle = (void*)appinfo;
4714         else {
4715                 *handle = NULL;
4716                 __cleanup_appinfo(appinfo);
4717         }
4718
4719         sqlite3_close(appinfo_db);
4720         if (syslocale) {
4721                 free(syslocale);
4722                 syslocale = NULL;
4723         }
4724         if (locale) {
4725                 free(locale);
4726                 locale = NULL;
4727         }
4728         return ret;
4729 }
4730
4731
4732 API int pkgmgrinfo_appinfo_get_appid(pkgmgrinfo_appinfo_h  handle, char **appid)
4733 {
4734         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4735         retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4736         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4737
4738         if (info->app_component == PMINFO_UI_APP)
4739                 *appid = (char *)info->uiapp_info->appid;
4740         else if (info->app_component == PMINFO_SVC_APP)
4741                 *appid = (char *)info->svcapp_info->appid;
4742
4743         return PMINFO_R_OK;
4744 }
4745
4746 API int pkgmgrinfo_appinfo_get_pkgname(pkgmgrinfo_appinfo_h  handle, char **pkg_name)
4747 {
4748         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4749         retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4750         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4751
4752         *pkg_name = (char *)info->package;
4753
4754         return PMINFO_R_OK;
4755 }
4756
4757 API int pkgmgrinfo_appinfo_get_pkgid(pkgmgrinfo_appinfo_h  handle, char **pkgid)
4758 {
4759         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4760         retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4761         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4762
4763         *pkgid = (char *)info->package;
4764
4765         return PMINFO_R_OK;
4766 }
4767
4768 API int pkgmgrinfo_appinfo_get_exec(pkgmgrinfo_appinfo_h  handle, char **exec)
4769 {
4770         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4771         retvm_if(exec == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4772         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4773
4774         if (info->app_component == PMINFO_UI_APP)
4775                 *exec = (char *)info->uiapp_info->exec;
4776         if (info->app_component == PMINFO_SVC_APP)
4777                 *exec = (char *)info->svcapp_info->exec;
4778
4779         return PMINFO_R_OK;
4780 }
4781
4782
4783 API int pkgmgrinfo_appinfo_get_icon(pkgmgrinfo_appinfo_h  handle, char **icon)
4784 {
4785         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4786         retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4787         char *locale = NULL;
4788         icon_x *ptr = NULL;
4789         icon_x *start = NULL;
4790         *icon = NULL;
4791
4792         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4793                 locale = info->locale;
4794                 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
4795
4796         if (info->app_component == PMINFO_UI_APP)
4797                 start = info->uiapp_info->icon;
4798         if (info->app_component == PMINFO_SVC_APP)
4799                 start = info->svcapp_info->icon;
4800         for(ptr = start; ptr != NULL; ptr = ptr->next)
4801         {
4802                 if (ptr->lang) {
4803                         if (strcmp(ptr->lang, locale) == 0) {
4804                                 *icon = (char *)ptr->text;
4805                                 if (strcasecmp(*icon, "(null)") == 0) {
4806                                         locale = DEFAULT_LOCALE;
4807                                         continue;
4808                                 } else
4809                                         break;
4810                         } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
4811                                 *icon = (char *)ptr->text;
4812                                 break;
4813                         }
4814                 }
4815         }
4816         return PMINFO_R_OK;
4817 }
4818
4819
4820 API int pkgmgrinfo_appinfo_get_label(pkgmgrinfo_appinfo_h  handle, char **label)
4821 {
4822         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4823         retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4824         char *locale = NULL;
4825         label_x *ptr = NULL;
4826         label_x *start = NULL;
4827         *label = NULL;
4828
4829         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4830         locale = info->locale;
4831         retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
4832
4833         if (info->app_component == PMINFO_UI_APP)
4834                 start = info->uiapp_info->label;
4835         if (info->app_component == PMINFO_SVC_APP)
4836                 start = info->svcapp_info->label;
4837         for(ptr = start; ptr != NULL; ptr = ptr->next)
4838         {
4839                 if (ptr->lang) {
4840                         if (strcmp(ptr->lang, locale) == 0) {
4841                                 *label = (char *)ptr->text;
4842                                 if (strcasecmp(*label, "(null)") == 0) {
4843                                         locale = DEFAULT_LOCALE;
4844                                         continue;
4845                                 } else
4846                                         break;
4847                         } else if (strncasecmp(ptr->lang, locale, 2) == 0) {
4848                                 *label = (char *)ptr->text;
4849                                 if (strcasecmp(*label, "(null)") == 0) {
4850                                                 locale = DEFAULT_LOCALE;
4851                                                 continue;
4852                                 } else
4853                                                 break;
4854                         } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
4855                                 *label = (char *)ptr->text;
4856                                 break;
4857                         }
4858                 }
4859         }
4860         return PMINFO_R_OK;
4861 }
4862
4863
4864 API int pkgmgrinfo_appinfo_get_component(pkgmgrinfo_appinfo_h  handle, pkgmgrinfo_app_component *component)
4865 {
4866         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4867         retvm_if(component == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4868         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4869
4870         if (info->app_component == PMINFO_UI_APP)
4871                 *component = PMINFO_UI_APP;
4872         else if (info->app_component == PMINFO_SVC_APP)
4873                 *component = PMINFO_SVC_APP;
4874         else
4875                 return PMINFO_R_ERROR;
4876
4877         return PMINFO_R_OK;
4878 }
4879
4880 API int pkgmgrinfo_appinfo_get_apptype(pkgmgrinfo_appinfo_h  handle, char **app_type)
4881 {
4882         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4883         retvm_if(app_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4884         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4885
4886         if (info->app_component == PMINFO_UI_APP)
4887                 *app_type = (char *)info->uiapp_info->type;
4888         if (info->app_component == PMINFO_SVC_APP)
4889                 *app_type = (char *)info->svcapp_info->type;
4890
4891         return PMINFO_R_OK;
4892 }
4893
4894 API int pkgmgrinfo_appinfo_get_operation(pkgmgrinfo_appcontrol_h  handle,
4895                                         int *operation_count, char ***operation)
4896 {
4897         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4898         retvm_if(operation == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4899         retvm_if(operation_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4900         pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
4901         *operation_count = data->operation_count;
4902         *operation = data->operation;
4903         return PMINFO_R_OK;
4904 }
4905
4906 API int pkgmgrinfo_appinfo_get_uri(pkgmgrinfo_appcontrol_h  handle,
4907                                         int *uri_count, char ***uri)
4908 {
4909         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4910         retvm_if(uri == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4911         retvm_if(uri_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4912         pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
4913         *uri_count = data->uri_count;
4914         *uri = data->uri;
4915         return PMINFO_R_OK;
4916 }
4917
4918 API int pkgmgrinfo_appinfo_get_mime(pkgmgrinfo_appcontrol_h  handle,
4919                                         int *mime_count, char ***mime)
4920 {
4921         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4922         retvm_if(mime == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4923         retvm_if(mime_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4924         pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
4925         *mime_count = data->mime_count;
4926         *mime = data->mime;
4927         return PMINFO_R_OK;
4928 }
4929
4930 API int pkgmgrinfo_appinfo_get_subapp(pkgmgrinfo_appcontrol_h  handle,
4931                                         int *subapp_count, char ***subapp)
4932 {
4933         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4934         retvm_if(subapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4935         retvm_if(subapp_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4936         pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
4937         *subapp_count = data->subapp_count;
4938         *subapp = data->subapp;
4939         return PMINFO_R_OK;
4940 }
4941
4942 API int pkgmgrinfo_appinfo_get_setting_icon(pkgmgrinfo_appinfo_h  handle, char **icon)
4943 {
4944         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
4945         retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4946
4947         char *val = NULL;
4948         icon_x *ptr = NULL;
4949         icon_x *start = NULL;
4950         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4951
4952         start = info->uiapp_info->icon;
4953
4954         for(ptr = start; ptr != NULL; ptr = ptr->next)
4955         {
4956                 if (ptr->section) {
4957                         val = (char *)ptr->section;
4958                         if (strcmp(val, "setting") == 0){
4959                                 *icon = (char *)ptr->text;
4960                                 break;
4961                         }
4962                 }
4963         }
4964         return PMINFO_R_OK;
4965 }
4966
4967
4968 API int pkgmgrinfo_appinfo_get_notification_icon(pkgmgrinfo_appinfo_h  handle, char **icon)
4969 {
4970         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
4971         retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4972
4973         char *val = NULL;
4974         icon_x *ptr = NULL;
4975         icon_x *start = NULL;
4976         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4977
4978         start = info->uiapp_info->icon;
4979
4980         for(ptr = start; ptr != NULL; ptr = ptr->next)
4981         {
4982                 if (ptr->section) {
4983                         val = (char *)ptr->section;
4984
4985                         if (strcmp(val, "notification") == 0){
4986                                 *icon = (char *)ptr->text;
4987                                 break;
4988                         }
4989                 }
4990         }
4991
4992         return PMINFO_R_OK;
4993 }
4994
4995 API int pkgmgrinfo_appinfo_get_recent_image_type(pkgmgrinfo_appinfo_h  handle, pkgmgrinfo_app_recentimage *type)
4996 {
4997         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4998         retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4999         char *val = NULL;
5000         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5001         val = (char *)info->uiapp_info->recentimage;
5002         if (val) {
5003                 if (strcasecmp(val, "capture") == 0)
5004                         *type = PMINFO_RECENTIMAGE_USE_CAPTURE;
5005                 else if (strcasecmp(val, "icon") == 0)
5006                         *type = PMINFO_RECENTIMAGE_USE_ICON;
5007                 else
5008                         *type = PMINFO_RECENTIMAGE_USE_NOTHING;
5009         }
5010
5011         return PMINFO_R_OK;
5012 }
5013
5014 API int pkgmgrinfo_appinfo_get_preview_image(pkgmgrinfo_appinfo_h  handle, char **preview_img)
5015 {
5016         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
5017         retvm_if(preview_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5018
5019         char *val = NULL;
5020         image_x *ptr = NULL;
5021         image_x *start = NULL;
5022         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5023
5024         start = info->uiapp_info->image;
5025
5026         for(ptr = start; ptr != NULL; ptr = ptr->next)
5027         {
5028                 if (ptr->section) {
5029                         val = (char *)ptr->section;
5030
5031                         if (strcmp(val, "preview") == 0)
5032                                 *preview_img = (char *)ptr->text;
5033
5034                         break;
5035                 }
5036         }
5037         return PMINFO_R_OK;
5038 }
5039
5040 API int pkgmgrinfo_appinfo_get_permission_type(pkgmgrinfo_appinfo_h  handle, pkgmgrinfo_permission_type *permission)
5041 {
5042         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
5043         retvm_if(permission == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5044
5045         char *val = NULL;
5046         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5047
5048         if (info->app_component == PMINFO_UI_APP)
5049                 val = info->uiapp_info->permission_type;
5050         else if (info->app_component == PMINFO_SVC_APP)
5051                 val = info->svcapp_info->permission_type;
5052         else
5053                 return PMINFO_R_ERROR;
5054
5055         if (strcmp(val, "signature") == 0)
5056                 *permission = PMINFO_PERMISSION_SIGNATURE;
5057         else if (strcmp(val, "privilege") == 0)
5058                 *permission = PMINFO_PERMISSION_PRIVILEGE;
5059         else
5060                 *permission = PMINFO_PERMISSION_NORMAL;
5061
5062         return PMINFO_R_OK;
5063 }
5064
5065 API int pkgmgrinfo_appinfo_get_component_type(pkgmgrinfo_appinfo_h  handle, char **component_type)
5066 {
5067         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5068         retvm_if(component_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5069         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5070
5071         *component_type = (char *)info->uiapp_info->component_type;
5072
5073         return PMINFO_R_OK;
5074 }
5075
5076 API int pkgmgrinfo_appinfo_get_hwacceleration(pkgmgrinfo_appinfo_h  handle, pkgmgrinfo_app_hwacceleration *hwacceleration)
5077 {
5078         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5079         retvm_if(hwacceleration == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5080         char *val = NULL;
5081         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5082         val = (char *)info->uiapp_info->hwacceleration;
5083         if (val) {
5084                 if (strcasecmp(val, "not-use-GL") == 0)
5085                         *hwacceleration = PMINFO_HWACCELERATION_NOT_USE_GL;
5086                 else if (strcasecmp(val, "use-GL") == 0)
5087                         *hwacceleration = PMINFO_HWACCELERATION_USE_GL;
5088                 else
5089                         *hwacceleration = PMINFO_HWACCELERATION_USE_SYSTEM_SETTING;
5090         }
5091         return PMINFO_R_OK;
5092 }
5093
5094 API int pkgmgrinfo_appinfo_get_screenreader(pkgmgrinfo_appinfo_h  handle, pkgmgrinfo_app_screenreader *screenreader)
5095 {
5096         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5097         retvm_if(screenreader == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5098         char *val = NULL;
5099         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5100         val = (char *)info->uiapp_info->screenreader;
5101         if (val) {
5102                 if (strcasecmp(val, "screenreader-off") == 0)
5103                         *screenreader = PMINFO_SCREENREADER_OFF;
5104                 else if (strcasecmp(val, "screenreader-on") == 0)
5105                         *screenreader = PMINFO_SCREENREADER_ON;
5106                 else
5107                         *screenreader = PMINFO_SCREENREADER_USE_SYSTEM_SETTING;
5108         }
5109         return PMINFO_R_OK;
5110 }
5111
5112 API int pkgmgrinfo_appinfo_get_effectimage(pkgmgrinfo_appinfo_h  handle, char **portrait_img, char **landscape_img)
5113 {
5114         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5115         retvm_if(portrait_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5116         retvm_if(landscape_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5117         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5118
5119         if (info->app_component == PMINFO_UI_APP){
5120                 *portrait_img = (char *)info->uiapp_info->portraitimg;
5121                 *landscape_img = (char *)info->uiapp_info->landscapeimg;
5122         }
5123
5124         return PMINFO_R_OK;
5125 }
5126
5127 API int pkgmgrinfo_appinfo_get_submode_mainid(pkgmgrinfo_appinfo_h  handle, char **submode_mainid)
5128 {
5129         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5130         retvm_if(submode_mainid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5131         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5132
5133         *submode_mainid = (char *)info->uiapp_info->submode_mainid;
5134
5135         return PMINFO_R_OK;
5136 }
5137
5138 API int pkgmgrinfo_appinfo_foreach_permission(pkgmgrinfo_appinfo_h handle,
5139                         pkgmgrinfo_app_permission_list_cb permission_func, void *user_data)
5140 {
5141         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5142         retvm_if(permission_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
5143         int ret = -1;
5144         permission_x *ptr = NULL;
5145         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5146         if (info->app_component == PMINFO_UI_APP)
5147                 ptr = info->uiapp_info->permission;
5148         else if (info->app_component == PMINFO_SVC_APP)
5149                 ptr = info->svcapp_info->permission;
5150         else
5151                 return PMINFO_R_EINVAL;
5152         for (; ptr; ptr = ptr->next) {
5153                 if (ptr->value) {
5154                         ret = permission_func(ptr->value, user_data);
5155                         if (ret < 0)
5156                                 break;
5157                 }
5158         }
5159         return PMINFO_R_OK;
5160 }
5161
5162 API int pkgmgrinfo_appinfo_foreach_category(pkgmgrinfo_appinfo_h handle,
5163                         pkgmgrinfo_app_category_list_cb category_func, void *user_data)
5164 {
5165         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5166         retvm_if(category_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
5167         int ret = -1;
5168         category_x *ptr = NULL;
5169         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5170         if (info->app_component == PMINFO_UI_APP)
5171                 ptr = info->uiapp_info->category;
5172         else if (info->app_component == PMINFO_SVC_APP)
5173                 ptr = info->svcapp_info->category;
5174         else
5175                 return PMINFO_R_EINVAL;
5176         for (; ptr; ptr = ptr->next) {
5177                 if (ptr->name) {
5178                         ret = category_func(ptr->name, user_data);
5179                         if (ret < 0)
5180                                 break;
5181                 }
5182         }
5183         return PMINFO_R_OK;
5184 }
5185
5186 API int pkgmgrinfo_appinfo_foreach_metadata(pkgmgrinfo_appinfo_h handle,
5187                         pkgmgrinfo_app_metadata_list_cb metadata_func, void *user_data)
5188 {
5189         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5190         retvm_if(metadata_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
5191         int ret = -1;
5192         metadata_x *ptr = NULL;
5193         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5194         if (info->app_component == PMINFO_UI_APP)
5195                 ptr = info->uiapp_info->metadata;
5196         else if (info->app_component == PMINFO_SVC_APP)
5197                 ptr = info->svcapp_info->metadata;
5198         else
5199                 return PMINFO_R_EINVAL;
5200         for (; ptr; ptr = ptr->next) {
5201                 if (ptr->key) {
5202                         ret = metadata_func(ptr->key, ptr->value, user_data);
5203                         if (ret < 0)
5204                                 break;
5205                 }
5206         }
5207         return PMINFO_R_OK;
5208 }
5209
5210 API int pkgmgrinfo_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
5211                         pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data)
5212 {
5213         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5214         retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
5215         int i = 0;
5216         int ret = -1;
5217         int oc = 0;
5218         int mc = 0;
5219         int uc = 0;
5220         int sc = 0;
5221         char *pkgid = NULL;
5222         char *manifest = NULL;
5223         char **operation = NULL;
5224         char **uri = NULL;
5225         char **mime = NULL;
5226         char **subapp = NULL;
5227         appcontrol_x *appcontrol = NULL;
5228         manifest_x *mfx = NULL;
5229         operation_x *op = NULL;
5230         uri_x *ui = NULL;
5231         mime_x *mi = NULL;
5232         subapp_x *sa = NULL;
5233         pkgmgrinfo_app_component component;
5234         pkgmgrinfo_appcontrol_x *ptr = NULL;
5235         ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid);
5236         if (ret < 0) {
5237                 _LOGE("Failed to get package name\n");
5238                 return PMINFO_R_ERROR;
5239         }
5240         ret = pkgmgrinfo_appinfo_get_component(handle, &component);
5241         if (ret < 0) {
5242                 _LOGE("Failed to get app component name\n");
5243                 return PMINFO_R_ERROR;
5244         }
5245         manifest = pkgmgr_parser_get_manifest_file(pkgid);
5246         if (manifest == NULL) {
5247                 _LOGE("Failed to fetch package manifest file\n");
5248                 return PMINFO_R_ERROR;
5249         }
5250         mfx = pkgmgr_parser_process_manifest_xml(manifest);
5251         if (mfx == NULL) {
5252                 _LOGE("Failed to parse package manifest file\n");
5253                 free(manifest);
5254                 manifest = NULL;
5255                 return PMINFO_R_ERROR;
5256         }
5257         free(manifest);
5258         ptr  = calloc(1, sizeof(pkgmgrinfo_appcontrol_x));
5259         if (ptr == NULL) {
5260                 _LOGE("Out of Memory!!!\n");
5261                 pkgmgr_parser_free_manifest_xml(mfx);
5262                 return PMINFO_R_ERROR;
5263         }
5264         /*Get Operation, Uri, Mime*/
5265         switch (component) {
5266         case PMINFO_UI_APP:
5267                 if (mfx->uiapplication) {
5268                         if (mfx->uiapplication->appsvc) {
5269                                 appcontrol = mfx->uiapplication->appsvc;
5270                         }
5271                 }
5272                 break;
5273         case PMINFO_SVC_APP:
5274                 if (mfx->serviceapplication) {
5275                         if (mfx->serviceapplication->appsvc) {
5276                                 appcontrol = mfx->serviceapplication->appsvc;
5277                         }
5278                 }
5279                 break;
5280         default:
5281                 break;
5282         }
5283         for (; appcontrol; appcontrol = appcontrol->next) {
5284                 op = appcontrol->operation;
5285                 for (; op; op = op->next)
5286                         oc = oc + 1;
5287                 op = appcontrol->operation;
5288
5289                 ui = appcontrol->uri;
5290                 for (; ui; ui = ui->next)
5291                         uc = uc + 1;
5292                 ui = appcontrol->uri;
5293
5294                 mi = appcontrol->mime;
5295                 for (; mi; mi = mi->next)
5296                         mc = mc + 1;
5297                 mi = appcontrol->mime;
5298
5299                 sa = appcontrol->subapp;
5300                 for (; sa; sa = sa->next)
5301                         sc = sc + 1;
5302                 sa = appcontrol->subapp;
5303
5304                 operation = (char **)calloc(oc, sizeof(char *));
5305                 for (i = 0; i < oc; i++) {
5306                         operation[i] = strndup(op->name, PKG_STRING_LEN_MAX - 1);
5307                         op = op->next;
5308                 }
5309
5310                 uri = (char **)calloc(uc, sizeof(char *));
5311                 for (i = 0; i < uc; i++) {
5312                         uri[i] = strndup(ui->name, PKG_STRING_LEN_MAX - 1);
5313                         ui = ui->next;
5314                 }
5315
5316                 mime = (char **)calloc(mc, sizeof(char *));
5317                 for (i = 0; i < mc; i++) {
5318                         mime[i] = strndup(mi->name, PKG_STRING_LEN_MAX - 1);
5319                         mi = mi->next;
5320                 }
5321
5322                 subapp = (char **)calloc(sc, sizeof(char *));
5323                 for (i = 0; i < sc; i++) {
5324                         subapp[i] = strndup(sa->name, PKG_STRING_LEN_MAX - 1);
5325                         sa = sa->next;
5326                 }
5327
5328                 /*populate appcontrol handle*/
5329                 ptr->operation_count = oc;
5330                 ptr->uri_count = uc;
5331                 ptr->mime_count = mc;
5332                 ptr->subapp_count = sc;
5333                 ptr->operation = operation;
5334                 ptr->uri = uri;
5335                 ptr->mime = mime;
5336                 ptr->subapp = subapp;
5337
5338                 ret = appcontrol_func((void *)ptr, user_data);
5339                 for (i = 0; i < oc; i++) {
5340                         if (operation[i]) {
5341                                 free(operation[i]);
5342                                 operation[i] = NULL;
5343                         }
5344                 }
5345                 if (operation) {
5346                         free(operation);
5347                         operation = NULL;
5348                 }
5349                 for (i = 0; i < uc; i++) {
5350                         if (uri[i]) {
5351                                 free(uri[i]);
5352                                 uri[i] = NULL;
5353                         }
5354                 }
5355                 if (uri) {
5356                         free(uri);
5357                         uri = NULL;
5358                 }
5359                 for (i = 0; i < mc; i++) {
5360                         if (mime[i]) {
5361                                 free(mime[i]);
5362                                 mime[i] = NULL;
5363                         }
5364                 }
5365                 if (mime) {
5366                         free(mime);
5367                         mime = NULL;
5368                 }
5369                 for (i = 0; i < sc; i++) {
5370                         if (subapp[i]) {
5371                                 free(subapp[i]);
5372                                 subapp[i] = NULL;
5373                         }
5374                 }
5375                 if (subapp) {
5376                         free(subapp);
5377                         subapp = NULL;
5378                 }
5379                 if (ret < 0)
5380                         break;
5381                 uc = 0;
5382                 mc = 0;
5383                 oc = 0;
5384                 sc = 0;
5385         }
5386         pkgmgr_parser_free_manifest_xml(mfx);
5387         if (ptr) {
5388                 free(ptr);
5389                 ptr = NULL;
5390         }
5391         return PMINFO_R_OK;
5392 }
5393
5394 API int pkgmgrinfo_appinfo_is_nodisplay(pkgmgrinfo_appinfo_h  handle, bool *nodisplay)
5395 {
5396         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5397         retvm_if(nodisplay == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5398         char *val = NULL;
5399         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5400         val = (char *)info->uiapp_info->nodisplay;
5401         if (val) {
5402                 if (strcasecmp(val, "true") == 0)
5403                         *nodisplay = 1;
5404                 else if (strcasecmp(val, "false") == 0)
5405                         *nodisplay = 0;
5406                 else
5407                         *nodisplay = 0;
5408         }
5409         return PMINFO_R_OK;
5410 }
5411
5412 API int pkgmgrinfo_appinfo_is_multiple(pkgmgrinfo_appinfo_h  handle, bool *multiple)
5413 {
5414         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5415         retvm_if(multiple == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5416         char *val = NULL;
5417         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5418         val = (char *)info->uiapp_info->multiple;
5419         if (val) {
5420                 if (strcasecmp(val, "true") == 0)
5421                         *multiple = 1;
5422                 else if (strcasecmp(val, "false") == 0)
5423                         *multiple = 0;
5424                 else
5425                         *multiple = 0;
5426         }
5427         return PMINFO_R_OK;
5428 }
5429
5430 API int pkgmgrinfo_appinfo_is_indicator_display_allowed(pkgmgrinfo_appinfo_h handle, bool *indicator_disp)
5431 {
5432         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5433         retvm_if(indicator_disp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5434         char *val = NULL;
5435         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5436         val = (char *)info->uiapp_info->indicatordisplay;
5437         if (val) {
5438                 if (strcasecmp(val, "true") == 0){
5439                         *indicator_disp = 1;
5440                 }else if (strcasecmp(val, "false") == 0){
5441                         *indicator_disp = 0;
5442                 }else{
5443                         *indicator_disp = 0;
5444                 }
5445         }
5446         return PMINFO_R_OK;
5447 }
5448
5449 API int pkgmgrinfo_appinfo_is_taskmanage(pkgmgrinfo_appinfo_h  handle, bool *taskmanage)
5450 {
5451         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5452         retvm_if(taskmanage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5453         char *val = NULL;
5454         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5455         val = (char *)info->uiapp_info->taskmanage;
5456         if (val) {
5457                 if (strcasecmp(val, "true") == 0)
5458                         *taskmanage = 1;
5459                 else if (strcasecmp(val, "false") == 0)
5460                         *taskmanage = 0;
5461                 else
5462                         *taskmanage = 0;
5463         }
5464         return PMINFO_R_OK;
5465 }
5466
5467 API int pkgmgrinfo_appinfo_is_enabled(pkgmgrinfo_appinfo_h  handle, bool *enabled)
5468 {
5469         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5470         retvm_if(enabled == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5471         char *val = NULL;
5472         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5473         if (info->app_component == PMINFO_UI_APP)
5474                 val = (char *)info->uiapp_info->enabled;
5475         else if (info->app_component == PMINFO_SVC_APP)
5476                 val = (char *)info->uiapp_info->enabled;
5477         else {
5478                 _LOGE("invalid component type\n");
5479                 return PMINFO_R_EINVAL;
5480         }
5481
5482         if (val) {
5483                 if (strcasecmp(val, "true") == 0)
5484                         *enabled = 1;
5485                 else if (strcasecmp(val, "false") == 0)
5486                         *enabled = 0;
5487                 else
5488                         *enabled = 1;
5489         }
5490         return PMINFO_R_OK;
5491
5492 }
5493
5494 API int pkgmgrinfo_appinfo_is_onboot(pkgmgrinfo_appinfo_h  handle, bool *onboot)
5495 {
5496         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5497         retvm_if(onboot == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5498         char *val = NULL;
5499         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5500         val = (char *)info->svcapp_info->onboot;
5501         if (val) {
5502                 if (strcasecmp(val, "true") == 0)
5503                         *onboot = 1;
5504                 else if (strcasecmp(val, "false") == 0)
5505                         *onboot = 0;
5506                 else
5507                         *onboot = 0;
5508         }
5509         return PMINFO_R_OK;
5510 }
5511
5512 API int pkgmgrinfo_appinfo_is_autorestart(pkgmgrinfo_appinfo_h  handle, bool *autorestart)
5513 {
5514         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5515         retvm_if(autorestart == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5516         char *val = NULL;
5517         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5518         val = (char *)info->svcapp_info->autorestart;
5519         if (val) {
5520                 if (strcasecmp(val, "true") == 0)
5521                         *autorestart = 1;
5522                 else if (strcasecmp(val, "false") == 0)
5523                         *autorestart = 0;
5524                 else
5525                         *autorestart = 0;
5526         }
5527         return PMINFO_R_OK;
5528 }
5529
5530 API int pkgmgrinfo_appinfo_is_mainapp(pkgmgrinfo_appinfo_h  handle, bool *mainapp)
5531 {
5532         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5533         retvm_if(mainapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5534         char *val = NULL;
5535         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5536         val = (char *)info->uiapp_info->mainapp;
5537         if (val) {
5538                 if (strcasecmp(val, "true") == 0)
5539                         *mainapp = 1;
5540                 else if (strcasecmp(val, "false") == 0)
5541                         *mainapp = 0;
5542                 else
5543                         *mainapp = 0;
5544         }
5545         return PMINFO_R_OK;
5546 }
5547
5548 API int pkgmgrinfo_appinfo_is_preload(pkgmgrinfo_appinfo_h handle, bool *preload)
5549 {
5550         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
5551         retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5552         char *val = NULL;
5553         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5554         val = (char *)info->uiapp_info->preload;
5555         if (val) {
5556                 if (strcasecmp(val, "true") == 0)
5557                         *preload = 1;
5558                 else if (strcasecmp(val, "false") == 0)
5559                         *preload = 0;
5560                 else
5561                         *preload = 0;
5562         }
5563         return PMINFO_R_OK;
5564 }
5565
5566 API int pkgmgrinfo_appinfo_is_submode(pkgmgrinfo_appinfo_h handle, bool *submode)
5567 {
5568         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
5569         retvm_if(submode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5570         char *val = NULL;
5571         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5572         val = (char *)info->uiapp_info->submode;
5573         if (val) {
5574                 if (strcasecmp(val, "true") == 0)
5575                         *submode = 1;
5576                 else if (strcasecmp(val, "false") == 0)
5577                         *submode = 0;
5578                 else
5579                         *submode = 0;
5580         }
5581         return PMINFO_R_OK;
5582 }
5583
5584 API int pkgmgrinfo_appinfo_destroy_appinfo(pkgmgrinfo_appinfo_h  handle)
5585 {
5586         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5587         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5588         __cleanup_appinfo(info);
5589         return PMINFO_R_OK;
5590 }
5591
5592 API int pkgmgrinfo_appinfo_filter_create(pkgmgrinfo_appinfo_filter_h *handle)
5593 {
5594         return (pkgmgrinfo_pkginfo_filter_create(handle));
5595 }
5596
5597 API int pkgmgrinfo_appinfo_filter_destroy(pkgmgrinfo_appinfo_filter_h handle)
5598 {
5599         return (pkgmgrinfo_pkginfo_filter_destroy(handle));
5600 }
5601
5602 API int pkgmgrinfo_appinfo_filter_add_int(pkgmgrinfo_appinfo_filter_h handle,
5603                                 const char *property, const int value)
5604 {
5605         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5606         retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5607         char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
5608         char *val = NULL;
5609         GSList *link = NULL;
5610         int prop = -1;
5611         prop = _pminfo_appinfo_convert_to_prop_int(property);
5612         if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_INT ||
5613                 prop > E_PMINFO_APPINFO_PROP_APP_MAX_INT) {
5614                 _LOGE("Invalid Integer Property\n");
5615                 return PMINFO_R_EINVAL;
5616         }
5617         pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5618         pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
5619         if (node == NULL) {
5620                 _LOGE("Out of Memory!!!\n");
5621                 return PMINFO_R_ERROR;
5622         }
5623         snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
5624         val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
5625         if (val == NULL) {
5626                 _LOGE("Out of Memory\n");
5627                 free(node);
5628                 node = NULL;
5629                 return PMINFO_R_ERROR;
5630         }
5631         node->prop = prop;
5632         node->value = val;
5633         /*If API is called multiple times for same property, we should override the previous values.
5634         Last value set will be used for filtering.*/
5635         link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
5636         if (link)
5637                 filter->list = g_slist_delete_link(filter->list, link);
5638         filter->list = g_slist_append(filter->list, (gpointer)node);
5639         return PMINFO_R_OK;
5640
5641 }
5642
5643 API int pkgmgrinfo_appinfo_filter_add_bool(pkgmgrinfo_appinfo_filter_h handle,
5644                                 const char *property, const bool value)
5645 {
5646         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5647         retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5648         char *val = NULL;
5649         GSList *link = NULL;
5650         int prop = -1;
5651         prop = _pminfo_appinfo_convert_to_prop_bool(property);
5652         if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_BOOL ||
5653                 prop > E_PMINFO_APPINFO_PROP_APP_MAX_BOOL) {
5654                 _LOGE("Invalid Boolean Property\n");
5655                 return PMINFO_R_EINVAL;
5656         }
5657         pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5658         pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
5659         if (node == NULL) {
5660                 _LOGE("Out of Memory!!!\n");
5661                 return PMINFO_R_ERROR;
5662         }
5663         if (value)
5664                 val = strndup("('true','True')", 15);
5665         else
5666                 val = strndup("('false','False')", 17);
5667         if (val == NULL) {
5668                 _LOGE("Out of Memory\n");
5669                 free(node);
5670                 node = NULL;
5671                 return PMINFO_R_ERROR;
5672         }
5673         node->prop = prop;
5674         node->value = val;
5675         /*If API is called multiple times for same property, we should override the previous values.
5676         Last value set will be used for filtering.*/
5677         link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
5678         if (link)
5679                 filter->list = g_slist_delete_link(filter->list, link);
5680         filter->list = g_slist_append(filter->list, (gpointer)node);
5681         return PMINFO_R_OK;
5682
5683 }
5684
5685 API int pkgmgrinfo_appinfo_filter_add_string(pkgmgrinfo_appinfo_filter_h handle,
5686                                 const char *property, const char *value)
5687 {
5688         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5689         retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5690         retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5691         char *val = NULL;
5692         pkgmgrinfo_node_x *ptr = NULL;
5693         char prev[PKG_STRING_LEN_MAX] = {'\0'};
5694         char temp[PKG_STRING_LEN_MAX] = {'\0'};
5695         GSList *link = NULL;
5696         int prop = -1;
5697         prop = _pminfo_appinfo_convert_to_prop_str(property);
5698         if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_STR ||
5699                 prop > E_PMINFO_APPINFO_PROP_APP_MAX_STR) {
5700                 _LOGE("Invalid String Property\n");
5701                 return PMINFO_R_EINVAL;
5702         }
5703         pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5704         pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
5705         if (node == NULL) {
5706                 _LOGE("Out of Memory!!!\n");
5707                 return PMINFO_R_ERROR;
5708         }
5709         node->prop = prop;
5710         switch (prop) {
5711         case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
5712                 if (strcmp(value, PMINFO_APPINFO_UI_APP) == 0)
5713                         val = strndup("uiapp", PKG_STRING_LEN_MAX - 1);
5714                 else
5715                         val = strndup("svcapp", PKG_STRING_LEN_MAX - 1);
5716                 node->value = val;
5717                 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
5718                 if (link)
5719                         filter->list = g_slist_delete_link(filter->list, link);
5720                 filter->list = g_slist_append(filter->list, (gpointer)node);
5721                 break;
5722         case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
5723         case E_PMINFO_APPINFO_PROP_APP_OPERATION:
5724         case E_PMINFO_APPINFO_PROP_APP_URI:
5725         case E_PMINFO_APPINFO_PROP_APP_MIME:
5726                 val = (char *)calloc(1, PKG_STRING_LEN_MAX);
5727                 if (val == NULL) {
5728                         _LOGE("Out of Memory\n");
5729                         free(node);
5730                         node = NULL;
5731                         return PMINFO_R_ERROR;
5732                 }
5733                 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
5734                 if (link) {
5735                         ptr = (pkgmgrinfo_node_x *)link->data;
5736                         strncpy(prev, ptr->value, PKG_STRING_LEN_MAX - 1);
5737                         _LOGE("Previous value is %s\n", prev);
5738                         filter->list = g_slist_delete_link(filter->list, link);
5739                         snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s , '%s'", prev, value);
5740                         strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
5741                         _LOGE("New value is %s\n", val);
5742                         node->value = val;
5743                         filter->list = g_slist_append(filter->list, (gpointer)node);
5744                         memset(temp, '\0', PKG_STRING_LEN_MAX);
5745                 } else {
5746                         snprintf(temp, PKG_STRING_LEN_MAX - 1, "'%s'", value);
5747                         strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
5748                         _LOGE("First value is %s\n", val);
5749                         node->value = val;
5750                         filter->list = g_slist_append(filter->list, (gpointer)node);
5751                         memset(temp, '\0', PKG_STRING_LEN_MAX);
5752                 }
5753                 break;
5754         default:
5755                 node->value = strndup(value, PKG_STRING_LEN_MAX - 1);
5756                 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
5757                 if (link)
5758                         filter->list = g_slist_delete_link(filter->list, link);
5759                 filter->list = g_slist_append(filter->list, (gpointer)node);
5760                 break;
5761         }
5762         return PMINFO_R_OK;
5763 }
5764
5765 API int pkgmgrinfo_appinfo_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count)
5766 {
5767         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5768         retvm_if(count == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5769         char *syslocale = NULL;
5770         char *locale = NULL;
5771         char *condition = NULL;
5772         char query[MAX_QUERY_LEN] = {'\0'};
5773         char where[MAX_QUERY_LEN] = {'\0'};
5774         GSList *list;
5775         int ret = 0;
5776         uiapplication_x *ptr1 = NULL;
5777         serviceapplication_x *ptr2 = NULL;
5778         pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5779         sqlite3 *pkginfo_db = NULL;
5780         int filter_count = 0;
5781
5782         /*open db*/
5783         ret = db_util_open(MANIFEST_DB, &pkginfo_db, 0);
5784         retvm_if(ret != SQLITE_OK, PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
5785
5786         /*get system locale*/
5787         syslocale = vconf_get_str(VCONFKEY_LANGSET);
5788         locale = __convert_system_locale_to_manifest_locale(syslocale);
5789         tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
5790
5791         /*Start constructing query*/
5792         snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_LIST_APP, locale);
5793         /*Get where clause*/
5794         for (list = filter->list; list; list = g_slist_next(list)) {
5795                 __get_filter_condition(list->data, &condition);
5796                 if (condition) {
5797                         strncat(where, condition, sizeof(where) - strlen(where) -1);
5798                         where[sizeof(where) - 1] = '\0';
5799                         free(condition);
5800                         condition = NULL;
5801                 }
5802                 if (g_slist_next(list)) {
5803                         strncat(where, " and ", sizeof(where) - strlen(where) - 1);
5804                         where[sizeof(where) - 1] = '\0';
5805                 }
5806         }
5807         _LOGE("where = %s\n", where);
5808         if (strlen(where) > 0) {
5809                 strncat(query, where, sizeof(query) - strlen(query) - 1);
5810                 query[sizeof(query) - 1] = '\0';
5811         }
5812 //      SECURE_LOGD("query = %s\n", query);
5813         /*To get filtered list*/
5814         pkgmgr_pkginfo_x *info = NULL;
5815         info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
5816         tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5817
5818         info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
5819         tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5820
5821         /*To get detail app info for each member of filtered list*/
5822         pkgmgr_pkginfo_x *filtinfo = NULL;
5823         filtinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
5824         tryvm_if(filtinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5825
5826         filtinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
5827         tryvm_if(filtinfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5828
5829         pkgmgr_appinfo_x *appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
5830         tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5831
5832         ret = __exec_db_query(pkginfo_db, query, __app_list_cb, (void *)info);
5833         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
5834
5835         memset(query, '\0', MAX_QUERY_LEN);
5836         if (info->manifest_info->uiapplication) {
5837                 LISTHEAD(info->manifest_info->uiapplication, ptr1);
5838                 info->manifest_info->uiapplication = ptr1;
5839         }
5840         if (info->manifest_info->serviceapplication) {
5841                 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
5842                 info->manifest_info->serviceapplication = ptr2;
5843         }
5844         /*Filtered UI Apps*/
5845         for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
5846         {
5847                 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
5848                                                         ptr1->appid, "uiapp");
5849                 ret = __exec_db_query(pkginfo_db, query, __uiapp_list_cb, (void *)filtinfo);
5850                 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
5851         }
5852         for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
5853         {
5854                 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
5855                                                         ptr2->appid, "svcapp");
5856                 ret = __exec_db_query(pkginfo_db, query, __svcapp_list_cb, (void *)filtinfo);
5857                 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
5858         }
5859         if (filtinfo->manifest_info->uiapplication) {
5860                 LISTHEAD(filtinfo->manifest_info->uiapplication, ptr1);
5861                 filtinfo->manifest_info->uiapplication = ptr1;
5862         }
5863         /*If the callback func return < 0 we break and no more call back is called*/
5864         while(ptr1 != NULL)
5865         {
5866                 appinfo->locale = strdup(locale);
5867                 appinfo->uiapp_info = ptr1;
5868                 appinfo->app_component = PMINFO_UI_APP;
5869
5870                 ret = __appinfo_check_installed_storage(appinfo);
5871                 if(ret < 0) {
5872                         ptr1 = ptr1->next;
5873                         continue;
5874                 }
5875
5876                 filter_count++;
5877
5878                 ptr1 = ptr1->next;
5879         }
5880         /*Filtered Service Apps*/
5881         if (filtinfo->manifest_info->serviceapplication) {
5882                 LISTHEAD(filtinfo->manifest_info->serviceapplication, ptr2);
5883                 filtinfo->manifest_info->serviceapplication = ptr2;
5884         }
5885         /*If the callback func return < 0 we break and no more call back is called*/
5886         while(ptr2 != NULL)
5887         {
5888                 appinfo->locale = strdup(locale);
5889                 appinfo->svcapp_info = ptr2;
5890                 appinfo->app_component = PMINFO_SVC_APP;
5891                 filter_count++;
5892                 ptr2 = ptr2->next;
5893         }
5894         *count = filter_count;
5895
5896         ret = PMINFO_R_OK;
5897 catch:
5898         if (locale) {
5899                 free(locale);
5900                 locale = NULL;
5901         }
5902         if (syslocale) {
5903                 free(syslocale);
5904                 syslocale = NULL;
5905         }
5906         sqlite3_close(pkginfo_db);
5907         if (appinfo) {
5908                 free(appinfo);
5909                 appinfo = NULL;
5910         }
5911         __cleanup_pkginfo(info);
5912         __cleanup_pkginfo(filtinfo);
5913         return ret;
5914 }
5915
5916 API int pkgmgrinfo_appinfo_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h handle,
5917                                 pkgmgrinfo_app_list_cb app_cb, void * user_data)
5918 {
5919         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5920         retvm_if(app_cb == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5921         char *syslocale = NULL;
5922         char *locale = NULL;
5923         char *condition = NULL;
5924         char query[MAX_QUERY_LEN] = {'\0'};
5925         char where[MAX_QUERY_LEN] = {'\0'};
5926         GSList *list;
5927         int ret = 0;
5928         uiapplication_x *ptr1 = NULL;
5929         serviceapplication_x *ptr2 = NULL;
5930         pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5931         sqlite3 *pkginfo_db = NULL;
5932
5933         /*open db*/
5934         ret = db_util_open(MANIFEST_DB, &pkginfo_db, 0);
5935         retvm_if(ret != SQLITE_OK, PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
5936
5937         /*get system locale*/
5938         syslocale = vconf_get_str(VCONFKEY_LANGSET);
5939         locale = __convert_system_locale_to_manifest_locale(syslocale);
5940         tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
5941
5942         /*Start constructing query*/
5943         snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_LIST_APP, locale);
5944         /*Get where clause*/
5945         for (list = filter->list; list; list = g_slist_next(list)) {
5946                 __get_filter_condition(list->data, &condition);
5947                 if (condition) {
5948                         strncat(where, condition, sizeof(where) - strlen(where) -1);
5949                         where[sizeof(where) - 1] = '\0';
5950                         free(condition);
5951                         condition = NULL;
5952                 }
5953                 if (g_slist_next(list)) {
5954                         strncat(where, " and ", sizeof(where) - strlen(where) - 1);
5955                         where[sizeof(where) - 1] = '\0';
5956                 }
5957         }
5958         _LOGE("where = %s\n", where);
5959         if (strlen(where) > 0) {
5960                 strncat(query, where, sizeof(query) - strlen(query) - 1);
5961                 query[sizeof(query) - 1] = '\0';
5962         }
5963         _LOGE("query = %s\n", query);
5964         /*To get filtered list*/
5965         pkgmgr_pkginfo_x *info = NULL;
5966         info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
5967         tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5968
5969         info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
5970         tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5971
5972         /*To get detail app info for each member of filtered list*/
5973         pkgmgr_pkginfo_x *filtinfo = NULL;
5974         filtinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
5975         tryvm_if(filtinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5976
5977         filtinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
5978         tryvm_if(filtinfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5979
5980         pkgmgr_appinfo_x *appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
5981         tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5982
5983         ret = __exec_db_query(pkginfo_db, query, __app_list_cb, (void *)info);
5984         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
5985
5986         memset(query, '\0', MAX_QUERY_LEN);
5987         if (info->manifest_info->uiapplication) {
5988                 LISTHEAD(info->manifest_info->uiapplication, ptr1);
5989                 info->manifest_info->uiapplication = ptr1;
5990         }
5991         if (info->manifest_info->serviceapplication) {
5992                 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
5993                 info->manifest_info->serviceapplication = ptr2;
5994         }
5995         /*Filtered UI Apps*/
5996         for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
5997         {
5998                 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
5999                                                         ptr1->appid, "uiapp");
6000                 ret = __exec_db_query(pkginfo_db, query, __uiapp_list_cb, (void *)filtinfo);
6001                 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
6002         }
6003         for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
6004         {
6005                 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
6006                                                         ptr2->appid, "svcapp");
6007                 ret = __exec_db_query(pkginfo_db, query, __svcapp_list_cb, (void *)filtinfo);
6008                 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
6009         }
6010         if (filtinfo->manifest_info->uiapplication) {
6011                 LISTHEAD(filtinfo->manifest_info->uiapplication, ptr1);
6012                 filtinfo->manifest_info->uiapplication = ptr1;
6013         }
6014         /*If the callback func return < 0 we break and no more call back is called*/
6015         while(ptr1 != NULL)
6016         {
6017                 appinfo->locale = strdup(locale);
6018                 appinfo->uiapp_info = ptr1;
6019                 appinfo->app_component = PMINFO_UI_APP;
6020
6021                 ret = __appinfo_check_installed_storage(appinfo);
6022                 if(ret < 0) {
6023                         ptr1 = ptr1->next;
6024                         continue;
6025                 }
6026
6027                 ret = app_cb((void *)appinfo, user_data);
6028                 if (ret < 0)
6029                         break;
6030                 ptr1 = ptr1->next;
6031         }
6032         /*Filtered Service Apps*/
6033         if (filtinfo->manifest_info->serviceapplication) {
6034                 LISTHEAD(filtinfo->manifest_info->serviceapplication, ptr2);
6035                 filtinfo->manifest_info->serviceapplication = ptr2;
6036         }
6037         /*If the callback func return < 0 we break and no more call back is called*/
6038         while(ptr2 != NULL)
6039         {
6040                 appinfo->locale = strdup(locale);
6041                 appinfo->svcapp_info = ptr2;
6042                 appinfo->app_component = PMINFO_SVC_APP;
6043                 ret = app_cb((void *)appinfo, user_data);
6044                 if (ret < 0)
6045                         break;
6046                 ptr2 = ptr2->next;
6047         }
6048         ret = PMINFO_R_OK;
6049 catch:
6050         if (locale) {
6051                 free(locale);
6052                 locale = NULL;
6053         }
6054         if (syslocale) {
6055                 free(syslocale);
6056                 syslocale = NULL;
6057         }
6058         sqlite3_close(pkginfo_db);
6059         if (appinfo) {
6060                 free(appinfo);
6061                 appinfo = NULL;
6062         }
6063         __cleanup_pkginfo(info);
6064         __cleanup_pkginfo(filtinfo);
6065         return ret;
6066 }
6067
6068 API int pkgmgrinfo_appinfo_metadata_filter_create(pkgmgrinfo_appinfo_metadata_filter_h *handle)
6069 {
6070         return (pkgmgrinfo_pkginfo_filter_create(handle));
6071 }
6072
6073 API int pkgmgrinfo_appinfo_metadata_filter_destroy(pkgmgrinfo_appinfo_metadata_filter_h handle)
6074 {
6075         return (pkgmgrinfo_pkginfo_filter_destroy(handle));
6076 }
6077
6078 API int pkgmgrinfo_appinfo_metadata_filter_add(pkgmgrinfo_appinfo_metadata_filter_h handle,
6079                 const char *key, const char *value)
6080 {
6081         retvm_if(handle == NULL, PMINFO_R_EINVAL, "filter handle is NULL\n");
6082         retvm_if(key == NULL, PMINFO_R_EINVAL, "metadata key supplied is NULL\n");
6083         /*value can be NULL. In that case all apps with specified key should be displayed*/
6084         int ret = 0;
6085         char *k = NULL;
6086         char *v = NULL;
6087         pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6088         pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
6089         retvm_if(node == NULL, PMINFO_R_ERROR, "Out of Memory!!!\n");
6090         k = strdup(key);
6091         tryvm_if(k == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
6092         node->key = k;
6093         if (value) {
6094                 v = strdup(value);
6095                 tryvm_if(v == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
6096         }
6097         node->value = v;
6098         /*If API is called multiple times, we should OR all conditions.*/
6099         filter->list = g_slist_append(filter->list, (gpointer)node);
6100         /*All memory will be freed in destroy API*/
6101         return PMINFO_R_OK;
6102 catch:
6103         if (node) {
6104                 if (node->key) {
6105                         free(node->key);
6106                         node->key = NULL;
6107                 }
6108                 if (node->value) {
6109                         free(node->value);
6110                         node->value = NULL;
6111                 }
6112                 free(node);
6113                 node = NULL;
6114         }
6115         return ret;
6116 }
6117
6118 API int pkgmgrinfo_appinfo_metadata_filter_foreach(pkgmgrinfo_appinfo_metadata_filter_h handle,
6119                 pkgmgrinfo_app_list_cb app_cb, void *user_data)
6120 {
6121         retvm_if(handle == NULL, PMINFO_R_EINVAL, "filter handle is NULL\n");
6122         retvm_if(app_cb == NULL, PMINFO_R_EINVAL, "Callback function supplied is NULL\n");
6123         char *syslocale = NULL;
6124         char *locale = NULL;
6125         char *condition = NULL;
6126         char *error_message = NULL;
6127         char query[MAX_QUERY_LEN] = {'\0'};
6128         char where[MAX_QUERY_LEN] = {'\0'};
6129         GSList *list;
6130         int ret = 0;
6131         pkgmgr_pkginfo_x *info = NULL;
6132         pkgmgr_pkginfo_x *filtinfo = NULL;
6133         pkgmgr_appinfo_x *appinfo = NULL;
6134         uiapplication_x *ptr1 = NULL;
6135         serviceapplication_x *ptr2 = NULL;
6136         pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6137         sqlite3 *pkginfo_db = NULL;
6138
6139         /*open db*/
6140         ret = db_util_open(MANIFEST_DB, &pkginfo_db, 0);
6141         retvm_if(ret != SQLITE_OK, PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
6142
6143         /*Get current locale*/
6144         syslocale = vconf_get_str(VCONFKEY_LANGSET);
6145         locale = __convert_system_locale_to_manifest_locale(syslocale);
6146         tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL\n");
6147
6148         /*Start constructing query*/
6149         memset(where, '\0', MAX_QUERY_LEN);
6150         memset(query, '\0', MAX_QUERY_LEN);
6151         snprintf(query, MAX_QUERY_LEN - 1, METADATA_FILTER_QUERY_SELECT_CLAUSE);
6152         /*Get where clause*/
6153         for (list = filter->list; list; list = g_slist_next(list)) {
6154                 __get_metadata_filter_condition(list->data, &condition);
6155                 if (condition) {
6156                         strncat(where, condition, sizeof(where) - strlen(where) -1);
6157                         free(condition);
6158                         condition = NULL;
6159                 }
6160                 if (g_slist_next(list)) {
6161                         strncat(where, METADATA_FILTER_QUERY_UNION_CLAUSE, sizeof(where) - strlen(where) - 1);
6162                 }
6163         }
6164         _LOGE("where = %s (%d)\n", where, strlen(where));
6165         if (strlen(where) > 0) {
6166                 strncat(query, where, sizeof(query) - strlen(query) - 1);
6167         }
6168         _LOGE("query = %s (%d)\n", query, strlen(query));
6169         /*To get filtered list*/
6170         info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
6171         tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
6172
6173         info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
6174         tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
6175
6176         /*To get detail app info for each member of filtered list*/
6177         filtinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
6178         tryvm_if(filtinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
6179
6180         filtinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
6181         tryvm_if(filtinfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
6182
6183         appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
6184         tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
6185
6186         ret = sqlite3_exec(pkginfo_db, query, __app_list_cb, (void *)info, &error_message);
6187         tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
6188         memset(query, '\0', MAX_QUERY_LEN);
6189
6190         if (info->manifest_info->uiapplication) {
6191                 LISTHEAD(info->manifest_info->uiapplication, ptr1);
6192                 info->manifest_info->uiapplication = ptr1;
6193         }
6194         if (info->manifest_info->serviceapplication) {
6195                 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
6196                 info->manifest_info->serviceapplication = ptr2;
6197         }
6198
6199         /*UI Apps*/
6200         for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
6201         {
6202                 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
6203                                                         ptr1->appid, "uiapp");
6204                 ret = sqlite3_exec(pkginfo_db, query, __uiapp_list_cb, (void *)filtinfo, &error_message);
6205                 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
6206                 memset(query, '\0', MAX_QUERY_LEN);
6207         }
6208         /*Service Apps*/
6209         for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
6210         {
6211                 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
6212                                                         ptr2->appid, "svcapp");
6213                 ret = sqlite3_exec(pkginfo_db, query, __svcapp_list_cb, (void *)filtinfo, &error_message);
6214                 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
6215                 memset(query, '\0', MAX_QUERY_LEN);
6216         }
6217         /*Filtered UI Apps*/
6218         if (filtinfo->manifest_info->uiapplication) {
6219                 LISTHEAD(filtinfo->manifest_info->uiapplication, ptr1);
6220                 filtinfo->manifest_info->uiapplication = ptr1;
6221         }
6222         /*If the callback func return < 0 we break and no more call back is called*/
6223         while(ptr1 != NULL)
6224         {
6225                 appinfo->locale = strdup(locale);
6226                 appinfo->uiapp_info = ptr1;
6227                 appinfo->app_component = PMINFO_UI_APP;
6228                 ret = app_cb((void *)appinfo, user_data);
6229                 if (ret < 0)
6230                         break;
6231                 ptr1 = ptr1->next;
6232         }
6233         /*Filtered Service Apps*/
6234         if (filtinfo->manifest_info->serviceapplication) {
6235                 LISTHEAD(filtinfo->manifest_info->serviceapplication, ptr2);
6236                 filtinfo->manifest_info->serviceapplication = ptr2;
6237         }
6238         /*If the callback func return < 0 we break and no more call back is called*/
6239         while(ptr2 != NULL)
6240         {
6241                 appinfo->locale = strdup(locale);
6242                 appinfo->svcapp_info = ptr2;
6243                 appinfo->app_component = PMINFO_SVC_APP;
6244                 ret = app_cb((void *)appinfo, user_data);
6245                 if (ret < 0)
6246                         break;
6247                 ptr2 = ptr2->next;
6248         }
6249         ret = PMINFO_R_OK;
6250 catch:
6251         if (locale) {
6252                 free(locale);
6253                 locale = NULL;
6254         }
6255         if (syslocale) {
6256                 free(syslocale);
6257                 syslocale = NULL;
6258         }
6259         sqlite3_free(error_message);
6260         sqlite3_close(pkginfo_db);
6261         if (appinfo) {
6262                 free(appinfo);
6263                 appinfo = NULL;
6264         }
6265         __cleanup_pkginfo(info);
6266         __cleanup_pkginfo(filtinfo);
6267         return ret;
6268 }
6269
6270 API int pkgmgrinfo_pkginfo_create_certinfo(pkgmgrinfo_certinfo_h *handle)
6271 {
6272         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
6273         pkgmgr_certinfo_x *certinfo = NULL;
6274         certinfo = calloc(1, sizeof(pkgmgr_certinfo_x));
6275         retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
6276         *handle = (void *)certinfo;
6277         return PMINFO_R_OK;
6278 }
6279
6280 API int pkgmgrinfo_pkginfo_load_certinfo(const char *pkgid, pkgmgrinfo_certinfo_h handle)
6281 {
6282         retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "package ID is NULL\n");
6283         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Certinfo handle is NULL\n");
6284         pkgmgr_certinfo_x *certinfo = NULL;
6285         char *error_message = NULL;
6286         int ret = PMINFO_R_OK;
6287         char query[MAX_QUERY_LEN] = {'\0'};
6288         int exist = 0;
6289         int i = 0;
6290
6291         /*Open db.*/
6292         ret = db_util_open_with_options(CERT_DB, &cert_db, SQLITE_OPEN_READONLY, NULL);
6293         if (ret != SQLITE_OK) {
6294                 _LOGE("connect db [%s] failed!\n", CERT_DB);
6295                 return PMINFO_R_ERROR;
6296         }
6297         /*validate pkgid*/
6298         snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", pkgid);
6299         if (SQLITE_OK !=
6300             sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
6301                 _LOGE("Don't execute query = %s error message = %s\n", query,
6302                        error_message);
6303                 sqlite3_free(error_message);
6304                 ret = PMINFO_R_ERROR;
6305                 goto err;
6306         }
6307         if (exist == 0) {
6308                 _LOGE("Package not found in DB\n");
6309                 ret = PMINFO_R_ERROR;
6310                 goto err;
6311         }
6312         certinfo = (pkgmgr_certinfo_x *)handle;
6313         /*populate certinfo from DB*/
6314         snprintf(query, MAX_QUERY_LEN, "select * from package_cert_info where package='%s' ", pkgid);
6315         ret = __exec_certinfo_query(query, (void *)certinfo);
6316         if (ret == -1) {
6317                 _LOGE("Package Cert Info DB Information retrieval failed\n");
6318                 ret = PMINFO_R_ERROR;
6319                 goto err;
6320         }
6321         for (i = 0; i < MAX_CERT_TYPE; i++) {
6322                 memset(query, '\0', MAX_QUERY_LEN);
6323                 snprintf(query, MAX_QUERY_LEN, "select cert_info from package_cert_index_info where cert_id=%d ", (certinfo->cert_id)[i]);
6324                 ret = __exec_certinfo_query(query, (void *)certinfo);
6325                 if (ret == -1) {
6326                         _LOGE("Cert Info DB Information retrieval failed\n");
6327                         ret = PMINFO_R_ERROR;
6328                         goto err;
6329                 }
6330                 if (certinfo->cert_value) {
6331                         (certinfo->cert_info)[i] = strdup(certinfo->cert_value);
6332                         free(certinfo->cert_value);
6333                         certinfo->cert_value = NULL;
6334                 }
6335         }
6336 err:
6337         sqlite3_close(cert_db);
6338         return ret;
6339 }
6340
6341 API int pkgmgrinfo_pkginfo_get_cert_value(pkgmgrinfo_certinfo_h handle, pkgmgrinfo_cert_type cert_type, const char **cert_value)
6342 {
6343         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
6344         retvm_if(cert_value == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
6345         retvm_if(cert_type < PMINFO_AUTHOR_ROOT_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
6346         retvm_if(cert_type > PMINFO_DISTRIBUTOR2_SIGNER_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
6347         pkgmgr_certinfo_x *certinfo = NULL;
6348         certinfo = (pkgmgr_certinfo_x *)handle;
6349         if ((certinfo->cert_info)[cert_type])
6350                 *cert_value = (certinfo->cert_info)[cert_type];
6351         else
6352                 *cert_value = NULL;
6353         return PMINFO_R_OK;
6354 }
6355
6356 API int pkgmgrinfo_pkginfo_destroy_certinfo(pkgmgrinfo_certinfo_h handle)
6357 {
6358         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
6359         int i = 0;
6360         pkgmgr_certinfo_x *certinfo = NULL;
6361         certinfo = (pkgmgr_certinfo_x *)handle;
6362         if (certinfo->pkgid) {
6363                 free(certinfo->pkgid);
6364                 certinfo->pkgid = NULL;
6365         }
6366         for (i = 0; i < MAX_CERT_TYPE; i++) {
6367                 if ((certinfo->cert_info)[i]) {
6368                         free((certinfo->cert_info)[i]);
6369                         (certinfo->cert_info)[i] = NULL;
6370                 }
6371         }
6372         free(certinfo);
6373         certinfo = NULL;
6374         return PMINFO_R_OK;
6375 }
6376
6377 API int pkgmgrinfo_create_certinfo_set_handle(pkgmgrinfo_instcertinfo_h *handle)
6378 {
6379         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
6380         pkgmgr_instcertinfo_x *certinfo = NULL;
6381         certinfo = calloc(1, sizeof(pkgmgr_instcertinfo_x));
6382         retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
6383         *handle = (void *)certinfo;
6384         return PMINFO_R_OK;
6385 }
6386
6387 API int pkgmgrinfo_set_cert_value(pkgmgrinfo_instcertinfo_h handle, pkgmgrinfo_instcert_type cert_type, char *cert_value)
6388 {
6389         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
6390         retvm_if(cert_value == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
6391         retvm_if(cert_type < PMINFO_SET_AUTHOR_ROOT_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
6392         retvm_if(cert_type > PMINFO_SET_DISTRIBUTOR2_SIGNER_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
6393         pkgmgr_instcertinfo_x *certinfo = NULL;
6394         certinfo = (pkgmgr_instcertinfo_x *)handle;
6395         (certinfo->cert_info)[cert_type] = strdup(cert_value);
6396         return PMINFO_R_OK;
6397 }
6398
6399 API int pkgmgrinfo_save_certinfo(const char *pkgid, pkgmgrinfo_instcertinfo_h handle)
6400 {
6401         retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "package ID is NULL\n");
6402         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Certinfo handle is NULL\n");
6403         char *error_message = NULL;
6404         char query[MAX_QUERY_LEN] = {'\0'};
6405         char *vquery = NULL;
6406         int len = 0;
6407         int i = 0;
6408         int j = 0;
6409         int c = 0;
6410         int unique_id[MAX_CERT_TYPE] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
6411         int newid = 0;
6412         int is_new = 0;
6413         int exist = -1;
6414         int ret = -1;
6415         int maxid = 0;
6416         int flag = 0;
6417         pkgmgr_instcertinfo_x *info = (pkgmgr_instcertinfo_x *)handle;
6418         pkgmgr_certindexinfo_x *indexinfo = NULL;
6419         indexinfo = calloc(1, sizeof(pkgmgr_certindexinfo_x));
6420         if (indexinfo == NULL) {
6421                 _LOGE("Out of Memory!!!");
6422                 return PMINFO_R_ERROR;
6423         }
6424         info->pkgid = strdup(pkgid);
6425
6426         /*Open db.*/
6427         ret = db_util_open_with_options(CERT_DB, &cert_db, SQLITE_OPEN_READWRITE, NULL);
6428         if (ret != SQLITE_OK) {
6429                 _LOGE("connect db [%s] failed!\n", CERT_DB);
6430                 ret = PMINFO_R_ERROR;
6431                 goto err;
6432         }
6433         /*Begin Transaction*/
6434         ret = sqlite3_exec(cert_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
6435         if (ret != SQLITE_OK) {
6436                 _LOGE("Failed to begin transaction\n");
6437                 ret = PMINFO_R_ERROR;
6438                 goto err;
6439         }
6440         _LOGE("Transaction Begin\n");
6441         /*Check if request is to insert/update*/
6442         snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", pkgid);
6443         if (SQLITE_OK !=
6444             sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
6445                 _LOGE("Don't execute query = %s error message = %s\n", query,
6446                        error_message);
6447                 sqlite3_free(error_message);
6448                 ret = PMINFO_R_ERROR;
6449                 goto err;
6450         }
6451         if (exist) {
6452                 /*Update request.
6453                 We cant just issue update query directly. We need to manage index table also.
6454                 Hence it is better to delete and insert again in case of update*/
6455                 ret = __delete_certinfo(pkgid);
6456                 if (ret < 0)
6457                         _LOGE("Certificate Deletion Failed\n");
6458         }
6459         for (i = 0; i < MAX_CERT_TYPE; i++) {
6460                 if ((info->cert_info)[i]) {
6461                         for (j = 0; j < i; j++) {
6462                                 if ( (info->cert_info)[j]) {
6463                                         if (strcmp((info->cert_info)[i], (info->cert_info)[j]) == 0) {
6464                                                 (info->cert_id)[i] = (info->cert_id)[j];
6465                                                 (info->is_new)[i] = 0;
6466                                                 (info->ref_count)[i] = (info->ref_count)[j];
6467                                                 break;
6468                                         }
6469                                 }
6470                         }
6471                         if (j < i)
6472                                 continue;
6473                         memset(query, '\0', MAX_QUERY_LEN);
6474                         snprintf(query, MAX_QUERY_LEN, "select * from package_cert_index_info " \
6475                                 "where cert_info='%s'",(info->cert_info)[i]);
6476                         ret = __exec_certindexinfo_query(query, (void *)indexinfo);
6477                         if (ret == -1) {
6478                                 _LOGE("Cert Info DB Information retrieval failed\n");
6479                                 ret = PMINFO_R_ERROR;
6480                                 goto err;
6481                         }
6482                         if (indexinfo->cert_id == 0) {
6483                                 /*New certificate. Get newid*/
6484                                 memset(query, '\0', MAX_QUERY_LEN);
6485                                 snprintf(query, MAX_QUERY_LEN, "select MAX(cert_id) from package_cert_index_info ");
6486                                 if (SQLITE_OK !=
6487                                     sqlite3_exec(cert_db, query, __maxid_cb, (void *)&newid, &error_message)) {
6488                                         _LOGE("Don't execute query = %s error message = %s\n", query,
6489                                                error_message);
6490                                         sqlite3_free(error_message);
6491                                         ret = PMINFO_R_ERROR;
6492                                         goto err;
6493                                 }
6494                                 newid = newid + 1;
6495                                 if (flag == 0) {
6496                                         maxid = newid;
6497                                         flag = 1;
6498                                 }
6499                                 indexinfo->cert_id = maxid;
6500                                 indexinfo->cert_ref_count = 1;
6501                                 is_new = 1;
6502                                 maxid = maxid + 1;
6503                         }
6504                         (info->cert_id)[i] = indexinfo->cert_id;
6505                         (info->is_new)[i] = is_new;
6506                         (info->ref_count)[i] = indexinfo->cert_ref_count;
6507                         _LOGE("Id:Count = %d %d\n", indexinfo->cert_id, indexinfo->cert_ref_count);
6508                         indexinfo->cert_id = 0;
6509                         indexinfo->cert_ref_count = 0;
6510                         is_new = 0;
6511                 }
6512         }
6513         len = MAX_QUERY_LEN;
6514         for (i = 0; i < MAX_CERT_TYPE; i++) {
6515                 if ((info->cert_info)[i])
6516                         len+= strlen((info->cert_info)[i]);
6517         }
6518         vquery = (char *)calloc(1, len);
6519         /*insert*/
6520         snprintf(vquery, len,
6521                  "insert into package_cert_info(package, author_root_cert, author_im_cert, author_signer_cert, dist_root_cert, " \
6522                 "dist_im_cert, dist_signer_cert, dist2_root_cert, dist2_im_cert, dist2_signer_cert) " \
6523                 "values('%s', %d, %d, %d, %d, %d, %d, %d, %d, %d)",\
6524                  info->pkgid,(info->cert_id)[PMINFO_SET_AUTHOR_ROOT_CERT],(info->cert_id)[PMINFO_SET_AUTHOR_INTERMEDIATE_CERT],
6525                 (info->cert_id)[PMINFO_SET_AUTHOR_SIGNER_CERT], (info->cert_id)[PMINFO_SET_DISTRIBUTOR_ROOT_CERT],
6526                 (info->cert_id)[PMINFO_SET_DISTRIBUTOR_INTERMEDIATE_CERT], (info->cert_id)[PMINFO_SET_DISTRIBUTOR_SIGNER_CERT],
6527                 (info->cert_id)[PMINFO_SET_DISTRIBUTOR2_ROOT_CERT],(info->cert_id)[PMINFO_SET_DISTRIBUTOR2_INTERMEDIATE_CERT],
6528                 (info->cert_id)[PMINFO_SET_DISTRIBUTOR2_SIGNER_CERT]);
6529         if (SQLITE_OK !=
6530             sqlite3_exec(cert_db, vquery, NULL, NULL, &error_message)) {
6531                 _LOGE("Don't execute query = %s error message = %s\n", vquery,
6532                        error_message);
6533                 sqlite3_free(error_message);
6534                 ret = PMINFO_R_ERROR;
6535                 goto err;
6536         }
6537         /*Update index table info*/
6538         /*If cert_id exists and is repeated for current package, ref count should only be increased once*/
6539         for (i = 0; i < MAX_CERT_TYPE; i++) {
6540                 if ((info->cert_info)[i]) {
6541                         memset(vquery, '\0', len);
6542                         if ((info->is_new)[i]) {
6543                                 snprintf(vquery, len, "insert into package_cert_index_info(cert_info, cert_id, cert_ref_count) " \
6544                                 "values('%s', '%d', '%d') ", (info->cert_info)[i], (info->cert_id)[i], 1);
6545                                 unique_id[c++] = (info->cert_id)[i];
6546                         } else {
6547                                 /*Update*/
6548                                 for (j = 0; j < MAX_CERT_TYPE; j++) {
6549                                         if ((info->cert_id)[i] == unique_id[j]) {
6550                                                 /*Ref count has already been increased. Just continue*/
6551                                                 break;
6552                                         }
6553                                 }
6554                                 if (j == MAX_CERT_TYPE)
6555                                         unique_id[c++] = (info->cert_id)[i];
6556                                 else
6557                                         continue;
6558                                 snprintf(vquery, len, "update package_cert_index_info set cert_ref_count=%d " \
6559                                 "where cert_id=%d",  (info->ref_count)[i] + 1, (info->cert_id)[i]);
6560                         }
6561                         if (SQLITE_OK !=
6562                             sqlite3_exec(cert_db, vquery, NULL, NULL, &error_message)) {
6563                                 _LOGE("Don't execute query = %s error message = %s\n", vquery,
6564                                        error_message);
6565                                 sqlite3_free(error_message);
6566                                 ret = PMINFO_R_ERROR;
6567                                 goto err;
6568                         }
6569                 }
6570         }
6571         /*Commit transaction*/
6572         ret = sqlite3_exec(cert_db, "COMMIT", NULL, NULL, NULL);
6573         if (ret != SQLITE_OK) {
6574                 _LOGE("Failed to commit transaction, Rollback now\n");
6575                 sqlite3_exec(cert_db, "ROLLBACK", NULL, NULL, NULL);
6576                 ret = PMINFO_R_ERROR;
6577                 goto err;
6578         }
6579         _LOGE("Transaction Commit and End\n");
6580         ret =  PMINFO_R_OK;
6581 err:
6582         sqlite3_close(cert_db);
6583         if (vquery) {
6584                 free(vquery);
6585                 vquery = NULL;
6586         }
6587         if (indexinfo) {
6588                 free(indexinfo);
6589                 indexinfo = NULL;
6590         }
6591         return ret;
6592 }
6593
6594 API int pkgmgrinfo_destroy_certinfo_set_handle(pkgmgrinfo_instcertinfo_h handle)
6595 {
6596         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
6597         int i = 0;
6598         pkgmgr_instcertinfo_x *certinfo = NULL;
6599         certinfo = (pkgmgr_instcertinfo_x *)handle;
6600         if (certinfo->pkgid) {
6601                 free(certinfo->pkgid);
6602                 certinfo->pkgid = NULL;
6603         }
6604         for (i = 0; i < MAX_CERT_TYPE; i++) {
6605                 if ((certinfo->cert_info)[i]) {
6606                         free((certinfo->cert_info)[i]);
6607                         (certinfo->cert_info)[i] = NULL;
6608                 }
6609         }
6610         free(certinfo);
6611         certinfo = NULL;
6612         return PMINFO_R_OK;
6613 }
6614
6615 API int pkgmgrinfo_delete_certinfo(const char *pkgid)
6616 {
6617         retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
6618         int ret = -1;
6619         /*Open db.*/
6620         ret = db_util_open_with_options(CERT_DB, &cert_db, SQLITE_OPEN_READWRITE, NULL);
6621         if (ret != SQLITE_OK) {
6622                 _LOGE("connect db [%s] failed!\n", CERT_DB);
6623                 ret = PMINFO_R_ERROR;
6624                 goto err;
6625         }
6626         /*Begin Transaction*/
6627         ret = sqlite3_exec(cert_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
6628         if (ret != SQLITE_OK) {
6629                 _LOGE("Failed to begin transaction\n");
6630                 ret = PMINFO_R_ERROR;
6631                 goto err;
6632         }
6633         _LOGE("Transaction Begin\n");
6634         ret = __delete_certinfo(pkgid);
6635         if (ret < 0) {
6636                 _LOGE("Certificate Deletion Failed\n");
6637         } else {
6638                 _LOGE("Certificate Deletion Success\n");
6639         }
6640         /*Commit transaction*/
6641         ret = sqlite3_exec(cert_db, "COMMIT", NULL, NULL, NULL);
6642         if (ret != SQLITE_OK) {
6643                 _LOGE("Failed to commit transaction, Rollback now\n");
6644                 sqlite3_exec(cert_db, "ROLLBACK", NULL, NULL, NULL);
6645                 ret = PMINFO_R_ERROR;
6646                 goto err;
6647         }
6648         _LOGE("Transaction Commit and End\n");
6649         ret = PMINFO_R_OK;
6650 err:
6651         sqlite3_close(cert_db);
6652         return ret;
6653 }
6654
6655 API int pkgmgrinfo_create_pkgdbinfo(const char *pkgid, pkgmgrinfo_pkgdbinfo_h *handle)
6656 {
6657         retvm_if(!pkgid, PMINFO_R_EINVAL, "pkgid is NULL");
6658         retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6659
6660         char *manifest = NULL;
6661         manifest_x *mfx = NULL;
6662
6663         manifest = pkgmgr_parser_get_manifest_file(pkgid);
6664         retvm_if(manifest == NULL, PMINFO_R_EINVAL, "pkg[%s] dont have manifest file", pkgid);
6665
6666         mfx = pkgmgr_parser_process_manifest_xml(manifest);
6667         if (manifest) {
6668                 free(manifest);
6669                 manifest = NULL;
6670         }
6671         retvm_if(mfx == NULL, PMINFO_R_EINVAL, "pkg[%s] parsing fail", pkgid);
6672
6673         *handle = (void *)mfx;
6674
6675         return PMINFO_R_OK;
6676 }
6677
6678 API int pkgmgrinfo_set_type_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *type)
6679 {
6680         retvm_if(!type, PMINFO_R_EINVAL, "Argument supplied is NULL");
6681         retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6682
6683         int len = strlen(type);
6684         retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
6685
6686         manifest_x *mfx = (manifest_x *)handle;
6687
6688         mfx->type = strndup(type, PKG_TYPE_STRING_LEN_MAX);
6689         return PMINFO_R_OK;
6690 }
6691
6692 API int pkgmgrinfo_set_version_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *version)
6693 {
6694         retvm_if(!version, PMINFO_R_EINVAL, "Argument supplied is NULL");
6695         retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6696
6697         int len = strlen(version);
6698         retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
6699
6700         manifest_x *mfx = (manifest_x *)handle;
6701
6702         mfx->version = strndup(version, PKG_VERSION_STRING_LEN_MAX);
6703         return PMINFO_R_OK;
6704 }
6705
6706 API int pkgmgrinfo_set_install_location_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, INSTALL_LOCATION location)
6707 {
6708         retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6709         retvm_if((location < 0) || (location > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
6710
6711         manifest_x *mfx = (manifest_x *)handle;
6712
6713         if (location == INSTALL_INTERNAL)
6714                 strcpy(mfx->installlocation, "internal-only");
6715         else if (location == INSTALL_EXTERNAL)
6716                 strcpy(mfx->installlocation, "prefer-external");
6717
6718         return PMINFO_R_OK;
6719 }
6720
6721 API int pkgmgrinfo_set_size_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *size)
6722 {
6723         retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6724         retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL");
6725
6726         manifest_x *mfx = (manifest_x *)handle;
6727
6728         mfx->package_size = strdup(size);
6729
6730         return PMINFO_R_OK;
6731 }
6732
6733 API int pkgmgrinfo_set_label_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *label_txt, const char *locale)
6734 {
6735         retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6736         retvm_if(!label_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
6737
6738         int len = strlen(label_txt);
6739         retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
6740
6741         manifest_x *mfx = (manifest_x *)handle;
6742
6743         label_x *label = calloc(1, sizeof(label_x));
6744         retvm_if(label == NULL, PMINFO_R_EINVAL, "Malloc Failed");
6745
6746         LISTADD(mfx->label, label);
6747         if (locale)
6748                 mfx->label->lang = strdup(locale);
6749         else
6750                 mfx->label->lang = strdup(DEFAULT_LOCALE);
6751         mfx->label->text = strdup(label_txt);
6752
6753         return PMINFO_R_OK;
6754 }
6755
6756 API int pkgmgrinfo_set_icon_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *icon_txt, const char *locale)
6757 {
6758         retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6759         retvm_if(!icon_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
6760
6761         int len = strlen(icon_txt);
6762         retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
6763
6764         manifest_x *mfx = (manifest_x *)handle;
6765
6766         icon_x *icon = calloc(1, sizeof(icon_x));
6767         retvm_if(icon == NULL, PMINFO_R_EINVAL, "Malloc Failed");
6768
6769         LISTADD(mfx->icon, icon);
6770         if (locale)
6771                 mfx->icon->lang = strdup(locale);
6772         else
6773                 mfx->icon->lang = strdup(DEFAULT_LOCALE);
6774         mfx->icon->text = strdup(icon_txt);
6775
6776         return PMINFO_R_OK;
6777 }
6778
6779 API int pkgmgrinfo_set_description_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *desc_txt, const char *locale)
6780 {
6781         retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6782         retvm_if(!desc_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
6783
6784         int len = strlen(desc_txt);
6785         retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
6786
6787         manifest_x *mfx = (manifest_x *)handle;
6788
6789         description_x *description = calloc(1, sizeof(description_x));
6790         retvm_if(description == NULL, PMINFO_R_EINVAL, "Malloc Failed");
6791
6792         LISTADD(mfx->description, description);
6793         if (locale)
6794                 mfx->description->lang = strdup(locale);
6795         else
6796                 mfx->description->lang = strdup(DEFAULT_LOCALE);
6797         mfx->description->text = strdup(desc_txt);
6798
6799         return PMINFO_R_OK;
6800 }
6801
6802 API int pkgmgrinfo_set_author_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *author_name,
6803                 const char *author_email, const char *author_href, const char *locale)
6804 {
6805         retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6806         manifest_x *mfx = (manifest_x *)handle;
6807         author_x *author = calloc(1, sizeof(author_x));
6808         retvm_if(author == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL");
6809
6810         LISTADD(mfx->author, author);
6811         if (author_name)
6812                 mfx->author->text = strdup(author_name);
6813         if (author_email)
6814                 mfx->author->email = strdup(author_email);
6815         if (author_href)
6816                 mfx->author->href = strdup(author_href);
6817         if (locale)
6818                 mfx->author->lang = strdup(locale);
6819         else
6820                 mfx->author->lang = strdup(DEFAULT_LOCALE);
6821         return PMINFO_R_OK;
6822 }
6823
6824 API int pkgmgrinfo_set_removable_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, int removable)
6825 {
6826         retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6827         retvm_if((removable < 0) || (removable > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
6828
6829         manifest_x *mfx = (manifest_x *)handle;
6830
6831         if (removable == 0)
6832                 strcpy(mfx->removable, "false");
6833         else if (removable == 1)
6834                 strcpy(mfx->removable, "true");
6835
6836         return PMINFO_R_OK;
6837 }
6838
6839 API int pkgmgrinfo_set_preload_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, int preload)
6840 {
6841         retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6842         retvm_if((preload < 0) || (preload > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
6843
6844         manifest_x *mfx = (manifest_x *)handle;
6845
6846         if (preload == 0)
6847                 strcpy(mfx->preload, "false");
6848         else if (preload == 1)
6849                 strcpy(mfx->preload, "true");
6850
6851         return PMINFO_R_OK;
6852 }
6853
6854 API int pkgmgrinfo_set_installed_storage_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, INSTALL_LOCATION location)
6855 {
6856         retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6857         retvm_if((location < 0) || (location > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
6858
6859         manifest_x *mfx = (manifest_x *)handle;
6860
6861         if (location == INSTALL_INTERNAL)
6862                 strcpy(mfx->installed_storage, "installed_internal");
6863         else if (location == INSTALL_EXTERNAL)
6864                 strcpy(mfx->installed_storage, "installed_external");
6865
6866         return PMINFO_R_OK;
6867 }
6868
6869 API int pkgmgrinfo_save_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle)
6870 {
6871         retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6872
6873         int ret = 0;
6874         manifest_x *mfx = NULL;
6875         mfx = (manifest_x *)handle;
6876
6877         ret = pkgmgr_parser_update_manifest_info_in_db(mfx);
6878         retvm_if(ret != 0, PMINFO_R_ERROR, "Failed to store info in DB\n");
6879         
6880         ret = __update_ail_appinfo(mfx);
6881         retvm_if(ret != 0, PMINFO_R_ERROR, "Failed to store info in DB\n");
6882
6883         _LOGE("Successfully stored info in DB\n");
6884         return PMINFO_R_OK;
6885 }
6886
6887 API int pkgmgrinfo_destroy_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle)
6888 {
6889         retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6890
6891         manifest_x *mfx = NULL;
6892         mfx = (manifest_x *)handle;
6893         pkgmgr_parser_free_manifest_xml(mfx);
6894         return PMINFO_R_OK;
6895 }
6896
6897 API int pkgmgrinfo_pkginfo_set_state_enabled(const char *pkgid, bool enabled)
6898 {
6899         /* Should be implemented later */
6900         return 0;
6901 }
6902
6903 API int pkgmgrinfo_appinfo_set_state_enabled(const char *appid, bool enabled)
6904 {
6905         retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL\n");
6906         int ret = -1;
6907         char query[MAX_QUERY_LEN] = {'\0'};
6908         sqlite3 *pkginfo_db = NULL;
6909
6910         ret = db_util_open(MANIFEST_DB, &pkginfo_db, 0);
6911         retvm_if(ret != SQLITE_OK, PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
6912
6913         /*Begin transaction*/
6914         ret = sqlite3_exec(pkginfo_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
6915         if (ret != SQLITE_OK) {
6916                 _LOGE("Failed to begin transaction\n");
6917                 sqlite3_close(pkginfo_db);
6918                 return PMINFO_R_ERROR;
6919         }
6920         _LOGD("Transaction Begin\n");
6921
6922         memset(query, '\0', MAX_QUERY_LEN);
6923         snprintf(query, MAX_QUERY_LEN,
6924                 "update package_app_info set app_enabled='%s' where app_id='%s'", enabled?"true":"false", appid);
6925
6926         char *error_message = NULL;
6927         if (SQLITE_OK !=
6928             sqlite3_exec(pkginfo_db, query, NULL, NULL, &error_message)) {
6929                 _LOGE("Don't execute query = %s error message = %s\n", query,
6930                        error_message);
6931                 sqlite3_free(error_message);
6932                 return PMINFO_R_ERROR;
6933         }
6934         sqlite3_free(error_message);
6935
6936         /*Commit transaction*/
6937         ret = sqlite3_exec(pkginfo_db, "COMMIT", NULL, NULL, NULL);
6938         if (ret != SQLITE_OK) {
6939                 _LOGE("Failed to commit transaction. Rollback now\n");
6940                 sqlite3_exec(pkginfo_db, "ROLLBACK", NULL, NULL, NULL);
6941                 sqlite3_close(pkginfo_db);
6942                 return PMINFO_R_ERROR;
6943         }
6944         _LOGD("Transaction Commit and End\n");
6945         sqlite3_close(pkginfo_db);
6946
6947         return PMINFO_R_OK;
6948 }
6949
6950
6951 API int pkgmgrinfo_datacontrol_get_info(const char *providerid, const char * type, char **appid, char **access)
6952 {
6953         retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
6954         retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
6955         retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
6956         retvm_if(access == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
6957         int ret = PMINFO_R_OK;
6958         char query[MAX_QUERY_LEN] = {'\0'};
6959         char *error_message = NULL;
6960         pkgmgr_datacontrol_x *data = NULL;
6961
6962         sqlite3 *datacontrol_info_db = NULL;
6963
6964         /*open db*/
6965         ret = db_util_open(DATACONTROL_DB, &datacontrol_info_db, 0);
6966         retvm_if(ret != SQLITE_OK, PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
6967
6968         data = (pkgmgr_datacontrol_x *)calloc(1, sizeof(pkgmgr_datacontrol_x));
6969         if (data == NULL) {
6970                 _LOGE("Failed to allocate memory for pkgmgr_datacontrol_x\n");
6971                 sqlite3_close(datacontrol_info_db);
6972                 return PMINFO_R_ERROR;
6973         }
6974
6975         snprintf(query, MAX_QUERY_LEN, 
6976                 "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",
6977                 providerid, type);
6978
6979         if (SQLITE_OK !=
6980                 sqlite3_exec(datacontrol_info_db, query, __datacontrol_cb, (void *)data, &error_message)) {
6981                 _LOGE("Don't execute query = %s error message = %s\n", query,
6982                            error_message);
6983                 sqlite3_free(error_message);
6984                 sqlite3_close(datacontrol_info_db);
6985                 return PMINFO_R_ERROR;
6986         }
6987
6988         *appid = (char *)data->appid;
6989         *access = (char *)data->access;
6990         free(data);
6991         sqlite3_close(datacontrol_info_db);
6992
6993         return PMINFO_R_OK;
6994 }
6995
6996 API int pkgmgrinfo_appinfo_set_default_label(const char *appid, const char *label)
6997 {
6998         retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL\n");
6999         int ret = -1;
7000         char query[MAX_QUERY_LEN] = {'\0'};
7001         char *error_message = NULL;
7002         sqlite3 *pkginfo_db = NULL;
7003
7004         /*open db*/
7005         ret = db_util_open(MANIFEST_DB, &pkginfo_db, 0);
7006         retvm_if(ret != SQLITE_OK, PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
7007
7008         /*Begin transaction*/
7009         ret = sqlite3_exec(pkginfo_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
7010         if (ret != SQLITE_OK) {
7011                 _LOGE("Failed to begin transaction\n");
7012                 sqlite3_close(pkginfo_db);
7013                 return PMINFO_R_ERROR;
7014         }
7015         _LOGD("Transaction Begin\n");
7016
7017         memset(query, '\0', MAX_QUERY_LEN);
7018         snprintf(query, MAX_QUERY_LEN, "update package_app_localized_info set app_label='%s' where app_id='%s'", label, appid);
7019
7020         ret = sqlite3_exec(pkginfo_db, query, NULL, NULL, &error_message);
7021         if (ret != SQLITE_OK) {
7022                 _LOGE("Don't execute query = %s error message = %s\n", query, error_message);
7023                 sqlite3_free(error_message);
7024                 return PMINFO_R_ERROR;
7025         }
7026
7027         /*Commit transaction*/
7028         ret = sqlite3_exec(pkginfo_db, "COMMIT", NULL, NULL, NULL);
7029         if (ret != SQLITE_OK) {
7030                 _LOGE("Failed to commit transaction. Rollback now\n");
7031                 sqlite3_exec(pkginfo_db, "ROLLBACK", NULL, NULL, NULL);
7032                 sqlite3_close(pkginfo_db);
7033                 return PMINFO_R_ERROR;
7034         }
7035         _LOGD("Transaction Commit and End\n");
7036         sqlite3_close(pkginfo_db);
7037
7038         return PMINFO_R_OK;
7039 }
7040
7041 API int pkgmgrinfo_appinfo_is_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool *status)
7042 {
7043         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
7044         retvm_if(status == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
7045         char *val = NULL;
7046         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
7047         val = (char *)info->uiapp_info->guestmode_visibility;
7048         if (val) {
7049                 if (strcasecmp(val, "true") == 0){
7050                         *status = 1;
7051                 }else if (strcasecmp(val, "false") == 0){
7052                         *status = 0;
7053                 }else{
7054                         *status = 1;
7055                 }
7056         }
7057         return PMINFO_R_OK;
7058 }
7059
7060 API int pkgmgrinfo_appinfo_set_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool status)
7061 {
7062         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
7063         char *val = NULL;
7064         int ret = 0;
7065         char *noti_string = NULL;
7066         int len = 0;
7067         char query[MAX_QUERY_LEN] = {'\0'};
7068         char *errmsg = NULL;
7069         sqlite3 *pkgmgr_parser_db;
7070
7071         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
7072         val = (char *)info->uiapp_info->guestmode_visibility;
7073         if (val ) {
7074                 ret =
7075                     db_util_open_with_options(MANIFEST_DB, &pkgmgr_parser_db, SQLITE_OPEN_READWRITE, NULL);
7076
7077                 if (ret != SQLITE_OK) {
7078                         _LOGE("DB Open Failed\n");
7079                         return PMINFO_R_ERROR;
7080                 }
7081
7082                 /*TODO: Write to DB here*/
7083                 if (status == true)
7084                         snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_guestmodevisibility = 'true' where app_id = '%s'", (char *)info->uiapp_info->appid);
7085                 else
7086                         snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_guestmodevisibility = 'false' where app_id = '%s'", (char *)info->uiapp_info->appid);
7087
7088                 if (SQLITE_OK != sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &errmsg)) {
7089                         _LOGE("DB update [%s] failed, error message = %s\n", query, errmsg);
7090                         free(errmsg);
7091                         sqlite3_close(pkgmgr_parser_db);
7092                         return PMINFO_R_ERROR;
7093                 }else{
7094                         sqlite3_close(pkgmgr_parser_db);
7095                         len = strlen((char *)info->uiapp_info->appid) + 8;
7096                         noti_string = calloc(1, len);
7097                         if (noti_string == NULL){
7098                                 return PMINFO_R_ERROR;
7099                         }
7100                         snprintf(noti_string, len, "update:%s", (char *)info->uiapp_info->appid);
7101                 vconf_set_str(VCONFKEY_AIL_INFO_STATE, noti_string);
7102                         vconf_set_str(VCONFKEY_MENUSCREEN_DESKTOP, noti_string); // duplicate, will be removed
7103                         free(noti_string);
7104                 }
7105         }
7106         return PMINFO_R_OK;
7107 }
7108
7109 /* pkgmgrinfo client start*/
7110 API pkgmgrinfo_client *pkgmgrinfo_client_new(pkgmgrinfo_client_type ctype)
7111 {
7112         int ret = 0;
7113         char *errmsg = NULL;
7114         void *pc = NULL;
7115         void *handle = NULL;
7116         pkgmgrinfo_client *(*__pkgmgr_client_new)(pkgmgrinfo_client_type ctype) = NULL;
7117
7118         handle = dlopen("libpkgmgr-client.so.0", RTLD_LAZY | RTLD_GLOBAL);
7119         retvm_if(!handle, PMINFO_R_ERROR, "dlopen() failed. [%s]", dlerror());
7120
7121         __pkgmgr_client_new = dlsym(handle, "pkgmgr_client_new");
7122         errmsg = dlerror();
7123         tryvm_if((errmsg != NULL) || (__pkgmgr_client_new == NULL), ret = PMINFO_R_ERROR, "dlsym() failed. [%s]", errmsg);
7124
7125         pc = __pkgmgr_client_new(ctype);
7126         tryvm_if(pc == NULL, ret = PMINFO_R_ERROR, "pkgmgr_client_new failed.");
7127
7128 catch:
7129 //      dlclose(handle);
7130         return (pkgmgrinfo_client *) pc;
7131 }
7132
7133 API int pkgmgrinfo_client_set_status_type(pkgmgrinfo_client *pc, int status_type)
7134 {
7135         int ret = 0;
7136         char *errmsg = NULL;
7137         void *handle = NULL;
7138         int (*__pkgmgr_client_set_status_type)(pkgmgrinfo_client *pc, int status_type) = NULL;
7139
7140         handle = dlopen("libpkgmgr-client.so.0", RTLD_LAZY | RTLD_GLOBAL);
7141         retvm_if(!handle, PMINFO_R_ERROR, "dlopen() failed. [%s]", dlerror());
7142
7143         __pkgmgr_client_set_status_type = dlsym(handle, "pkgmgr_client_set_status_type");
7144         errmsg = dlerror();
7145         tryvm_if((errmsg != NULL) || (__pkgmgr_client_set_status_type == NULL), ret = PMINFO_R_ERROR, "dlsym() failed. [%s]", errmsg);
7146
7147         ret = __pkgmgr_client_set_status_type(pc, status_type);
7148         tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgr_client_new failed.");
7149
7150 catch:
7151 //      dlclose(handle);
7152         return ret;
7153 }
7154
7155 API int pkgmgrinfo_client_listen_status(pkgmgrinfo_client *pc, pkgmgrinfo_handler event_cb, void *data)
7156 {
7157         int ret = 0;
7158         char *errmsg = NULL;
7159         void *handle = NULL;
7160         int (*__pkgmgr_client_listen_status)(pkgmgrinfo_client *pc, pkgmgrinfo_handler event_cb, void *data) = NULL;
7161
7162         handle = dlopen("libpkgmgr-client.so.0", RTLD_LAZY | RTLD_GLOBAL);
7163         retvm_if(!handle, PMINFO_R_ERROR, "dlopen() failed. [%s]", dlerror());
7164
7165         __pkgmgr_client_listen_status = dlsym(handle, "pkgmgr_client_listen_status");
7166         errmsg = dlerror();
7167         tryvm_if((errmsg != NULL) || (__pkgmgr_client_listen_status == NULL), ret = PMINFO_R_ERROR, "dlsym() failed. [%s]", errmsg);
7168
7169         ret = __pkgmgr_client_listen_status(pc, event_cb, data);
7170         tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgr_client_new failed.");
7171
7172 catch:
7173 //      dlclose(handle);
7174         return ret;
7175 }
7176
7177 API int pkgmgrinfo_client_free(pkgmgrinfo_client *pc)
7178 {
7179         int ret = 0;
7180         char *errmsg = NULL;
7181         void *handle = NULL;
7182         int (*__pkgmgr_client_free)(pkgmgrinfo_client *pc) = NULL;
7183
7184         handle = dlopen("libpkgmgr-client.so.0", RTLD_LAZY | RTLD_GLOBAL);
7185         retvm_if(!handle, PMINFO_R_ERROR, "dlopen() failed. [%s]", dlerror());
7186
7187         __pkgmgr_client_free = dlsym(handle, "pkgmgr_client_free");
7188         errmsg = dlerror();
7189         tryvm_if((errmsg != NULL) || (__pkgmgr_client_free == NULL), ret = PMINFO_R_ERROR, "dlsym() failed. [%s]", errmsg);
7190
7191         ret = __pkgmgr_client_free(pc);
7192         tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgr_client_new failed.");
7193
7194 catch:
7195 //      dlclose(handle);
7196         return ret;
7197 }
7198
7199 API int pkgmgrinfo_client_request_enable_external_pkg(char *pkgid)
7200 {
7201         int ret = 0;
7202         DBusConnection *bus;
7203         DBusMessage *message;
7204
7205         retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "pkgid is NULL\n");
7206
7207         if(__get_pkg_location(pkgid) != PMINFO_EXTERNAL_STORAGE)
7208                 return PMINFO_R_OK;
7209
7210         bus = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
7211         retvm_if(bus == NULL, PMINFO_R_EINVAL, "dbus_bus_get() failed.");
7212
7213         message = dbus_message_new_method_call (SERVICE_NAME, PATH_NAME, INTERFACE_NAME, METHOD_NAME);
7214         retvm_if(message == NULL, PMINFO_R_EINVAL, "dbus_message_new_method_call() failed.");
7215
7216         dbus_message_append_args(message, DBUS_TYPE_STRING, &pkgid, DBUS_TYPE_INVALID);
7217
7218         ret = dbus_connection_send_with_reply_and_block(bus, message, -1, NULL);
7219         retvm_if(!ret, ret = PMINFO_R_EINVAL, "connection_send dbus fail");
7220
7221         dbus_connection_flush(bus);
7222         dbus_message_unref(message);
7223
7224         return PMINFO_R_OK;
7225 }
7226
7227 /* pkgmgrinfo client end*/
7228