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