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