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