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