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