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