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