implement csc path, is_update status
[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                 _LOGE(" app path in external memory not accesible\n");
2699         } else {
2700                 fclose(fp);
2701                 fp = NULL;
2702                 *storage = PMINFO_EXTERNAL_STORAGE;
2703                 return PMINFO_R_OK;
2704         }
2705
2706         /*check whether application is in internal or not */
2707         fp = fopen(app_dir_path, "r");
2708         if (fp == NULL) {
2709                 _LOGE(" app path in internal memory not accesible\n");
2710                 *storage = -1;
2711                 return PMINFO_R_ERROR;
2712         } else {
2713                 fclose(fp);
2714                 /*check whether the application is installed in SD card
2715                         but SD card is not present*/
2716                 fp = fopen(app_mmc_internal_path, "r");
2717                 if (fp == NULL) {
2718                         *storage = PMINFO_INTERNAL_STORAGE;
2719                         return PMINFO_R_OK;
2720                 } else {
2721                         fclose(fp);
2722                         *storage = PMINFO_EXTERNAL_STORAGE;
2723                         return PMINFO_R_OK;
2724                 }
2725         }
2726 }
2727
2728 API int pkgmgrinfo_pkginfo_get_installed_time(pkgmgrinfo_pkginfo_h handle, int *installed_time)
2729 {
2730         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2731         retvm_if(installed_time == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2732         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2733         if (info->manifest_info->installed_time)
2734                 *installed_time = atoi(info->manifest_info->installed_time);
2735         else
2736                 return PMINFO_R_ERROR;
2737
2738         return PMINFO_R_OK;
2739 }
2740
2741 API int pkgmgrinfo_pkginfo_get_storeclientid(pkgmgrinfo_pkginfo_h handle, char **storeclientid)
2742 {
2743         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2744         retvm_if(storeclientid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2745         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2746         *storeclientid = (char *)info->manifest_info->storeclient_id;
2747         return PMINFO_R_OK;
2748 }
2749
2750 API int pkgmgrinfo_pkginfo_get_mainappid(pkgmgrinfo_pkginfo_h handle, char **mainappid)
2751 {
2752         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2753         retvm_if(mainappid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2754         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2755         *mainappid = (char *)info->manifest_info->mainapp_id;
2756         return PMINFO_R_OK;
2757 }
2758
2759 API int pkgmgrinfo_pkginfo_get_url(pkgmgrinfo_pkginfo_h handle, char **url)
2760 {
2761         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2762         retvm_if(url == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2763         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2764         *url = (char *)info->manifest_info->package_url;
2765         return PMINFO_R_OK;
2766 }
2767
2768 API int pkgmgrinfo_pkginfo_get_size_from_xml(const char *manifest, int *size)
2769 {
2770         const char *val = NULL;
2771         const xmlChar *node;
2772         xmlTextReaderPtr reader;
2773         retvm_if(manifest == NULL, PMINFO_R_EINVAL, "Input argument is NULL\n");
2774         retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2775
2776         xmlInitParser();
2777         reader = xmlReaderForFile(manifest, NULL, 0);
2778
2779         if (reader){
2780                 if (__child_element(reader, -1)) {
2781                         node = xmlTextReaderConstName(reader);
2782                         if (!node) {
2783                                 _LOGE("xmlTextReaderConstName value is NULL\n");
2784                                 xmlFreeTextReader(reader);
2785                                 xmlCleanupParser();
2786                                 return PMINFO_R_ERROR;
2787                         }
2788
2789                         if (!strcmp(ASC_CHAR(node), "manifest")) {
2790                                 if (xmlTextReaderGetAttribute(reader, XML_CHAR("size")))
2791                                         val = ASC_CHAR(xmlTextReaderGetAttribute(reader, XML_CHAR("size")));
2792
2793                                 if (val) {
2794                                         *size = atoi(val);
2795                                 } else {
2796                                         *size = 0;
2797                                         _LOGE("package size is not specified\n");
2798                                         xmlFreeTextReader(reader);
2799                                         xmlCleanupParser();
2800                                         return PMINFO_R_ERROR;
2801                                 }
2802                         } else {
2803                                 _LOGE("Unable to create xml reader\n");
2804                                 xmlFreeTextReader(reader);
2805                                 xmlCleanupParser();
2806                                 return PMINFO_R_ERROR;
2807                         }
2808                 }
2809         } else {
2810                 _LOGE("xmlReaderForFile value is NULL\n");
2811                 xmlCleanupParser();
2812                 return PMINFO_R_ERROR;
2813         }
2814
2815         xmlFreeTextReader(reader);
2816         xmlCleanupParser();
2817
2818         return PMINFO_R_OK;
2819 }
2820
2821 API int pkgmgrinfo_pkginfo_get_location_from_xml(const char *manifest, pkgmgrinfo_install_location *location)
2822 {
2823         const char *val = NULL;
2824         const xmlChar *node;
2825         xmlTextReaderPtr reader;
2826         retvm_if(manifest == NULL, PMINFO_R_EINVAL, "Input argument is NULL\n");
2827         retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2828
2829         xmlInitParser();
2830         reader = xmlReaderForFile(manifest, NULL, 0);
2831
2832         if (reader){
2833                 if ( __child_element(reader, -1)) {
2834                         node = xmlTextReaderConstName(reader);
2835                         if (!node) {
2836                                 _LOGE("xmlTextReaderConstName value is NULL\n");
2837                                 xmlFreeTextReader(reader);
2838                                 xmlCleanupParser();
2839                                 return PMINFO_R_ERROR;
2840                         }
2841
2842                         if (!strcmp(ASC_CHAR(node), "manifest")) {
2843                                 if (xmlTextReaderGetAttribute(reader, XML_CHAR("install-location")))
2844                                         val = ASC_CHAR(xmlTextReaderGetAttribute(reader, XML_CHAR("install-location")));
2845
2846                                 if (val) {
2847                                         if (strcmp(val, "internal-only") == 0)
2848                                                 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
2849                                         else if (strcmp(val, "prefer-external") == 0)
2850                                                 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
2851                                         else
2852                                                 *location = PMINFO_INSTALL_LOCATION_AUTO;
2853                                 }
2854                         } else {
2855                                 _LOGE("Unable to create xml reader\n");
2856                                 xmlFreeTextReader(reader);
2857                                 xmlCleanupParser();
2858                                 return PMINFO_R_ERROR;
2859                         }
2860                 }
2861         } else {
2862                 _LOGE("xmlReaderForFile value is NULL\n");
2863                 xmlCleanupParser();
2864                 return PMINFO_R_ERROR;
2865         }
2866
2867         xmlFreeTextReader(reader);
2868         xmlCleanupParser();
2869
2870         return PMINFO_R_OK;
2871 }
2872
2873
2874 API int pkgmgrinfo_pkginfo_get_root_path(pkgmgrinfo_pkginfo_h handle, char **path)
2875 {
2876         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2877         retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2878
2879         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2880         if (info->manifest_info->root_path)
2881                 *path = (char *)info->manifest_info->root_path;
2882         else
2883                 return PMINFO_R_ERROR;
2884
2885         return PMINFO_R_OK;
2886 }
2887
2888 API int pkgmgrinfo_pkginfo_get_csc_path(pkgmgrinfo_pkginfo_h handle, char **path)
2889 {
2890         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2891         retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2892
2893         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2894         if (info->manifest_info->csc_path)
2895                 *path = (char *)info->manifest_info->csc_path;
2896         else
2897                 *path = (char *)info->manifest_info->csc_path;
2898
2899         return PMINFO_R_OK;
2900 }
2901
2902 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)
2903 {
2904         retvm_if(lhs_package_id == NULL, PMINFO_R_EINVAL, "lhs package ID is NULL");
2905         retvm_if(rhs_package_id == NULL, PMINFO_R_EINVAL, "rhs package ID is NULL");
2906         retvm_if(compare_result == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2907
2908         int ret = PMINFO_R_OK;
2909         char query[MAX_QUERY_LEN] = {'\0'};
2910         char *error_message = NULL;
2911         pkgmgr_cert_x *info= NULL;
2912         int lcert = 0;
2913         int rcert = 0;
2914         int exist = -1;
2915         *compare_result = PMINFO_CERT_COMPARE_ERROR;
2916         info = (pkgmgr_cert_x *)calloc(1, sizeof(pkgmgr_cert_x));
2917         retvm_if(info == NULL, PMINFO_R_ERROR, "Out of Memory!!!");
2918
2919         ret = db_util_open_with_options(CERT_DB, &cert_db,
2920                                         SQLITE_OPEN_READONLY, NULL);
2921         if (ret != SQLITE_OK) {
2922                 _LOGE("connect db [%s] failed!\n", CERT_DB);
2923                 ret = PMINFO_R_ERROR;
2924                 goto err;
2925         }
2926
2927         snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", lhs_package_id);
2928         if (SQLITE_OK !=
2929             sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
2930                 _LOGE("Don't execute query = %s error message = %s\n", query,
2931                        error_message);
2932                 ret = PMINFO_R_ERROR;
2933                 goto err;
2934         }
2935
2936         if (exist == 0) {
2937                 lcert = 0;
2938         } else {
2939                 snprintf(query, MAX_QUERY_LEN, "select author_signer_cert from package_cert_info where package='%s'", lhs_package_id);
2940                 if (SQLITE_OK !=
2941                         sqlite3_exec(cert_db, query, __cert_cb, (void *)info, &error_message)) {
2942                         _LOGE("Don't execute query = %s error message = %s\n", query,
2943                                    error_message);
2944                         ret = PMINFO_R_ERROR;
2945                         goto err;
2946                 }
2947                 lcert = info->cert_id;
2948         }
2949
2950         snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", rhs_package_id);
2951         if (SQLITE_OK !=
2952                 sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
2953                 _LOGE("Don't execute query = %s error message = %s\n", query,
2954                            error_message);
2955                 ret = PMINFO_R_ERROR;
2956                 goto err;
2957         }
2958
2959         if (exist == 0) {
2960                 rcert = 0;
2961         } else {
2962                 snprintf(query, MAX_QUERY_LEN, "select author_signer_cert from package_cert_info where package='%s'", rhs_package_id);
2963                 if (SQLITE_OK !=
2964                         sqlite3_exec(cert_db, query, __cert_cb, (void *)info, &error_message)) {
2965                         _LOGE("Don't execute query = %s error message = %s\n", query,
2966                                    error_message);
2967                         ret = PMINFO_R_ERROR;
2968                         goto err;
2969                 }
2970                 rcert = info->cert_id;
2971         }
2972
2973         if ((lcert == 0) || (rcert == 0))
2974         {
2975                 if ((lcert == 0) && (rcert == 0))
2976                         *compare_result = PMINFO_CERT_COMPARE_BOTH_NO_CERT;
2977                 else if (lcert == 0)
2978                         *compare_result = PMINFO_CERT_COMPARE_LHS_NO_CERT;
2979                 else if (rcert == 0)
2980                         *compare_result = PMINFO_CERT_COMPARE_RHS_NO_CERT;
2981         } else {
2982                 if (lcert == rcert)
2983                         *compare_result = PMINFO_CERT_COMPARE_MATCH;
2984                 else
2985                         *compare_result = PMINFO_CERT_COMPARE_MISMATCH;
2986         }
2987
2988 err:
2989         sqlite3_free(error_message);
2990         sqlite3_close(cert_db);
2991         if (info) {
2992                 if (info->pkgid) {
2993                         free(info->pkgid);
2994                         info->pkgid = NULL;
2995                 }
2996                 free(info);
2997                 info = NULL;
2998         }
2999         return ret;
3000 }
3001
3002
3003 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)
3004 {
3005         retvm_if(lhs_app_id == NULL, PMINFO_R_EINVAL, "lhs app ID is NULL");
3006         retvm_if(rhs_app_id == NULL, PMINFO_R_EINVAL, "rhs app ID is NULL");
3007         retvm_if(compare_result == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3008
3009         int ret = PMINFO_R_OK;
3010         char query[MAX_QUERY_LEN] = {'\0'};
3011         char *error_message = NULL;
3012         pkgmgr_cert_x *info= NULL;
3013         int exist = -1;
3014         char *lpkgid = NULL;
3015         char *rpkgid = NULL;
3016
3017         info = (pkgmgr_cert_x *)calloc(1, sizeof(pkgmgr_cert_x));
3018         retvm_if(info == NULL, PMINFO_R_ERROR, "Out of Memory!!!");
3019
3020         ret = db_util_open_with_options(MANIFEST_DB, &manifest_db,
3021                                         SQLITE_OPEN_READONLY, NULL);
3022         if (ret != SQLITE_OK) {
3023                 _LOGE("connect db [%s] failed!\n", MANIFEST_DB);
3024                 ret = PMINFO_R_ERROR;
3025                 goto err;
3026         }
3027
3028         snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", lhs_app_id);
3029         if (SQLITE_OK !=
3030             sqlite3_exec(manifest_db, query, __validate_cb, (void *)&exist, &error_message)) {
3031                 _LOGE("Don't execute query = %s error message = %s\n", query,
3032                        error_message);
3033                 ret = PMINFO_R_ERROR;
3034                 goto err;
3035         }
3036
3037         if (exist == 0) {
3038                 lpkgid = NULL;
3039         } else {
3040                 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", lhs_app_id);
3041                 if (SQLITE_OK !=
3042                         sqlite3_exec(manifest_db, query, __cert_cb, (void *)info, &error_message)) {
3043                         _LOGE("Don't execute query = %s error message = %s\n", query,
3044                                    error_message);
3045                         ret = PMINFO_R_ERROR;
3046                         goto err;
3047                 }
3048                 lpkgid = strdup(info->pkgid);
3049                 if (lpkgid == NULL) {
3050                         _LOGE("Out of Memory\n");
3051                         ret = PMINFO_R_ERROR;
3052                         goto err;
3053                 }
3054                 free(info->pkgid);
3055                 info->pkgid = NULL;
3056         }
3057
3058         snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", rhs_app_id);
3059         if (SQLITE_OK !=
3060             sqlite3_exec(manifest_db, query, __validate_cb, (void *)&exist, &error_message)) {
3061                 _LOGE("Don't execute query = %s error message = %s\n", query,
3062                        error_message);
3063                 ret = PMINFO_R_ERROR;
3064                 goto err;
3065         }
3066
3067         if (exist == 0) {
3068                 rpkgid = NULL;
3069         } else {
3070                 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", rhs_app_id);
3071                 if (SQLITE_OK !=
3072                         sqlite3_exec(manifest_db, query, __cert_cb, (void *)info, &error_message)) {
3073                         _LOGE("Don't execute query = %s error message = %s\n", query,
3074                                    error_message);
3075                         ret = PMINFO_R_ERROR;
3076                         goto err;
3077                 }
3078                 rpkgid = strdup(info->pkgid);
3079                 if (rpkgid == NULL) {
3080                         _LOGE("Out of Memory\n");
3081                         ret = PMINFO_R_ERROR;
3082                         goto err;
3083                 }
3084                 free(info->pkgid);
3085                 info->pkgid = NULL;
3086         }
3087         ret = pkgmgrinfo_pkginfo_compare_pkg_cert_info(lpkgid, rpkgid, compare_result);
3088  err:
3089         sqlite3_free(error_message);
3090         sqlite3_close(manifest_db);
3091         if (info) {
3092                 if (info->pkgid) {
3093                         free(info->pkgid);
3094                         info->pkgid = NULL;
3095                 }
3096                 free(info);
3097                 info = NULL;
3098         }
3099         if (lpkgid) {
3100                 free(lpkgid);
3101                 lpkgid = NULL;
3102         }
3103         if (rpkgid) {
3104                 free(rpkgid);
3105                 rpkgid = NULL;
3106         }
3107         return ret;
3108 }
3109
3110 API int pkgmgrinfo_pkginfo_is_accessible(pkgmgrinfo_pkginfo_h handle, bool *accessible)
3111 {
3112         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3113         retvm_if(accessible == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3114         char *pkgid = NULL;
3115         pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
3116         if (pkgid == NULL){
3117                  _LOGD("invalid func parameters\n");
3118                  return PMINFO_R_ERROR;
3119         }
3120          _LOGD("pkgmgr_get_pkg_external_validation() called\n");
3121
3122         FILE *fp = NULL;
3123         char app_mmc_path[FILENAME_MAX] = { 0, };
3124         char app_dir_path[FILENAME_MAX] = { 0, };
3125         char app_mmc_internal_path[FILENAME_MAX] = { 0, };
3126         snprintf(app_dir_path, FILENAME_MAX,"%s%s", PKG_INSTALLATION_PATH, pkgid);
3127         snprintf(app_mmc_path, FILENAME_MAX,"%s%s", PKG_SD_PATH, pkgid);
3128         snprintf(app_mmc_internal_path, FILENAME_MAX,"%s%s/.mmc", PKG_INSTALLATION_PATH, pkgid);
3129
3130         /*check whether application is in external memory or not */
3131         fp = fopen(app_mmc_path, "r");
3132         if (fp == NULL){
3133                 _LOGD(" app path in external memory not accesible\n");
3134         } else {
3135                 fclose(fp);
3136                 fp = NULL;
3137                 *accessible = 1;
3138                 _LOGD("pkgmgr_get_pkg_external_validation() : SD_CARD \n");
3139                 return PMINFO_R_OK;
3140         }
3141
3142         /*check whether application is in internal or not */
3143         fp = fopen(app_dir_path, "r");
3144         if (fp == NULL) {
3145                 _LOGD(" app path in internal memory not accesible\n");
3146                 *accessible = 0;
3147                 return PMINFO_R_ERROR;
3148         } else {
3149                 fclose(fp);
3150                 /*check whether the application is installed in SD card
3151                 but SD card is not present*/
3152                 fp = fopen(app_mmc_internal_path, "r");
3153                 if (fp == NULL){
3154                         *accessible = 1;
3155                         _LOGD("pkgmgr_get_pkg_external_validation() : INTERNAL_MEM \n");
3156                         return PMINFO_R_OK;
3157                 }
3158                 else{
3159                         *accessible = 0;
3160                         _LOGD("pkgmgr_get_pkg_external_validation() : ERROR_MMC_STATUS \n");
3161                 }
3162                 fclose(fp);
3163         }
3164
3165         _LOGD("pkgmgr_get_pkg_external_validation() end\n");
3166         return PMINFO_R_OK;
3167 }
3168
3169 API int pkgmgrinfo_pkginfo_is_removable(pkgmgrinfo_pkginfo_h handle, bool *removable)
3170 {
3171         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3172         retvm_if(removable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3173         char *val = NULL;
3174         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3175         val = (char *)info->manifest_info->removable;
3176         if (val) {
3177                 if (strcasecmp(val, "true") == 0)
3178                         *removable = 1;
3179                 else if (strcasecmp(val, "false") == 0)
3180                         *removable = 0;
3181                 else
3182                         *removable = 1;
3183         }
3184         return PMINFO_R_OK;
3185 }
3186
3187 API int pkgmgrinfo_pkginfo_is_movable(pkgmgrinfo_pkginfo_h handle, bool *movable)
3188 {
3189         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3190         retvm_if(movable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3191
3192         char *val = NULL;
3193         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3194
3195         val = (char *)info->manifest_info->installlocation;
3196         if (val) {
3197                 if (strcmp(val, "internal-only") == 0)
3198                         *movable = 0;
3199                 else if (strcmp(val, "prefer-external") == 0)
3200                         *movable = 1;
3201                 else
3202                         *movable = 1;
3203         }
3204
3205         return PMINFO_R_OK;
3206 }
3207
3208 API int pkgmgrinfo_pkginfo_is_preload(pkgmgrinfo_pkginfo_h handle, bool *preload)
3209 {
3210         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3211         retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3212         char *val = NULL;
3213         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3214         val = (char *)info->manifest_info->preload;
3215         if (val) {
3216                 if (strcasecmp(val, "true") == 0)
3217                         *preload = 1;
3218                 else if (strcasecmp(val, "false") == 0)
3219                         *preload = 0;
3220                 else
3221                         *preload = 0;
3222         }
3223         return PMINFO_R_OK;
3224 }
3225
3226 API int pkgmgrinfo_pkginfo_is_readonly(pkgmgrinfo_pkginfo_h handle, bool *readonly)
3227 {
3228         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3229         retvm_if(readonly == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3230         char *val = NULL;
3231         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3232         val = (char *)info->manifest_info->readonly;
3233         if (val) {
3234                 if (strcasecmp(val, "true") == 0)
3235                         *readonly = 1;
3236                 else if (strcasecmp(val, "false") == 0)
3237                         *readonly = 0;
3238                 else
3239                         *readonly = 0;
3240         }
3241         return PMINFO_R_OK;
3242 }
3243
3244 API int pkgmgrinfo_pkginfo_is_update(pkgmgrinfo_pkginfo_h handle, bool *update)
3245 {
3246         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3247         retvm_if(update == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3248
3249         char *val = NULL;
3250         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3251         val = (char *)info->manifest_info->update;
3252         if (val) {
3253                 if (strcasecmp(val, "true") == 0)
3254                         *update = 1;
3255                 else if (strcasecmp(val, "false") == 0)
3256                         *update = 0;
3257                 else
3258                         *update = 1;
3259         }
3260         return PMINFO_R_OK;
3261 }
3262
3263 API int pkgmgrinfo_pkginfo_destroy_pkginfo(pkgmgrinfo_pkginfo_h handle)
3264 {
3265         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3266         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3267         __cleanup_pkginfo(info);
3268         return PMINFO_R_OK;
3269 }
3270
3271 API int pkgmgrinfo_pkginfo_filter_create(pkgmgrinfo_pkginfo_filter_h *handle)
3272 {
3273         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle output parameter is NULL\n");
3274         *handle = NULL;
3275         pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)calloc(1, sizeof(pkgmgrinfo_filter_x));
3276         if (filter == NULL) {
3277                 _LOGE("Out of Memory!!!");
3278                 return PMINFO_R_ERROR;
3279         }
3280         *handle = filter;
3281         return PMINFO_R_OK;
3282 }
3283
3284 API int pkgmgrinfo_pkginfo_filter_destroy(pkgmgrinfo_pkginfo_filter_h handle)
3285 {
3286         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3287         pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3288         if (filter->list){
3289                 g_slist_foreach(filter->list, __destroy_each_node, NULL);
3290                 g_slist_free(filter->list);
3291         }
3292         free(filter);
3293         filter = NULL;
3294         return PMINFO_R_OK;
3295 }
3296
3297 API int pkgmgrinfo_pkginfo_filter_add_int(pkgmgrinfo_pkginfo_filter_h handle,
3298                                 const char *property, const int value)
3299 {
3300         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3301         retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3302         char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
3303         char *val = NULL;
3304         GSList *link = NULL;
3305         int prop = -1;
3306         prop = _pminfo_pkginfo_convert_to_prop_int(property);
3307         if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_INT ||
3308                 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_INT) {
3309                 _LOGE("Invalid Integer Property\n");
3310                 return PMINFO_R_EINVAL;
3311         }
3312         pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3313         pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
3314         if (node == NULL) {
3315                 _LOGE("Out of Memory!!!\n");
3316                 return PMINFO_R_ERROR;
3317         }
3318         snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
3319         val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
3320         if (val == NULL) {
3321                 _LOGE("Out of Memory\n");
3322                 free(node);
3323                 node = NULL;
3324                 return PMINFO_R_ERROR;
3325         }
3326         node->prop = prop;
3327         node->value = val;
3328         /*If API is called multiple times for same property, we should override the previous values.
3329         Last value set will be used for filtering.*/
3330         link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
3331         if (link)
3332                 filter->list = g_slist_delete_link(filter->list, link);
3333         filter->list = g_slist_append(filter->list, (gpointer)node);
3334         return PMINFO_R_OK;
3335
3336 }
3337
3338 API int pkgmgrinfo_pkginfo_filter_add_bool(pkgmgrinfo_pkginfo_filter_h handle,
3339                                 const char *property, const bool value)
3340 {
3341         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3342         retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3343         char *val = NULL;
3344         GSList *link = NULL;
3345         int prop = -1;
3346         prop = _pminfo_pkginfo_convert_to_prop_bool(property);
3347         if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_BOOL ||
3348                 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_BOOL) {
3349                 _LOGE("Invalid Boolean Property\n");
3350                 return PMINFO_R_EINVAL;
3351         }
3352         pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3353         pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
3354         if (node == NULL) {
3355                 _LOGE("Out of Memory!!!\n");
3356                 return PMINFO_R_ERROR;
3357         }
3358         if (value)
3359                 val = strndup("('true','True')", 15);
3360         else
3361                 val = strndup("('false','False')", 17);
3362         if (val == NULL) {
3363                 _LOGE("Out of Memory\n");
3364                 free(node);
3365                 node = NULL;
3366                 return PMINFO_R_ERROR;
3367         }
3368         node->prop = prop;
3369         node->value = val;
3370         /*If API is called multiple times for same property, we should override the previous values.
3371         Last value set will be used for filtering.*/
3372         link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
3373         if (link)
3374                 filter->list = g_slist_delete_link(filter->list, link);
3375         filter->list = g_slist_append(filter->list, (gpointer)node);
3376         return PMINFO_R_OK;
3377
3378 }
3379
3380 API int pkgmgrinfo_pkginfo_filter_add_string(pkgmgrinfo_pkginfo_filter_h handle,
3381                                 const char *property, const char *value)
3382 {
3383         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3384         retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3385         retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3386         char *val = NULL;
3387         GSList *link = NULL;
3388         int prop = -1;
3389         prop = _pminfo_pkginfo_convert_to_prop_str(property);
3390         if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_STR ||
3391                 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_STR) {
3392                 _LOGE("Invalid String Property\n");
3393                 return PMINFO_R_EINVAL;
3394         }
3395         pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3396         pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
3397         if (node == NULL) {
3398                 _LOGE("Out of Memory!!!\n");
3399                 return PMINFO_R_ERROR;
3400         }
3401         if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_AUTO) == 0)
3402                 val = strndup("auto", PKG_STRING_LEN_MAX - 1);
3403         else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_INTERNAL) == 0)
3404                 val = strndup("internal-only", PKG_STRING_LEN_MAX - 1);
3405         else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_EXTERNAL) == 0)
3406                 val = strndup("prefer-external", PKG_STRING_LEN_MAX - 1);
3407         else if (strcmp(value, "installed_internal") == 0)
3408                 val = strndup("installed_internal", PKG_STRING_LEN_MAX - 1);
3409         else if (strcmp(value, "installed_external") == 0)
3410                 val = strndup("installed_external", PKG_STRING_LEN_MAX - 1);
3411         else
3412                 val = strndup(value, PKG_STRING_LEN_MAX - 1);
3413         if (val == NULL) {
3414                 _LOGE("Out of Memory\n");
3415                 free(node);
3416                 node = NULL;
3417                 return PMINFO_R_ERROR;
3418         }
3419         node->prop = prop;
3420         node->value = val;
3421         /*If API is called multiple times for same property, we should override the previous values.
3422         Last value set will be used for filtering.*/
3423         link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
3424         if (link)
3425                 filter->list = g_slist_delete_link(filter->list, link);
3426         filter->list = g_slist_append(filter->list, (gpointer)node);
3427         return PMINFO_R_OK;
3428
3429 }
3430
3431 API int pkgmgrinfo_pkginfo_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count)
3432 {
3433         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3434         retvm_if(count == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3435         char *syslocale = NULL;
3436         char *locale = NULL;
3437         char *condition = NULL;
3438         char *error_message = NULL;
3439         char query[MAX_QUERY_LEN] = {'\0'};
3440         char where[MAX_QUERY_LEN] = {'\0'};
3441         GSList *list;
3442         int ret = 0;
3443
3444         pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3445         /*Get current locale*/
3446         syslocale = vconf_get_str(VCONFKEY_LANGSET);
3447         if (syslocale == NULL) {
3448                 _LOGE("current locale is NULL\n");
3449                 return PMINFO_R_ERROR;
3450         }
3451         locale = __convert_system_locale_to_manifest_locale(syslocale);
3452         if (locale == NULL) {
3453                 _LOGE("manifest locale is NULL\n");
3454                 free(syslocale);
3455                 return PMINFO_R_ERROR;
3456         }
3457
3458         ret = __open_manifest_db();
3459         if (ret == -1) {
3460                 _LOGE("Fail to open manifest DB\n");
3461                 ret = PMINFO_R_ERROR;
3462                 goto err;
3463         }
3464
3465         /*Start constructing query*/
3466         snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_COUNT_PACKAGE, locale);
3467
3468         /*Get where clause*/
3469         for (list = filter->list; list; list = g_slist_next(list)) {
3470                 __get_filter_condition(list->data, &condition);
3471                 if (condition) {
3472                         strncat(where, condition, sizeof(where) - strlen(where) -1);
3473                         where[sizeof(where) - 1] = '\0';
3474                         free(condition);
3475                         condition = NULL;
3476                 }
3477                 if (g_slist_next(list)) {
3478                         strncat(where, " and ", sizeof(where) - strlen(where) - 1);
3479                         where[sizeof(where) - 1] = '\0';
3480                 }
3481         }
3482         _LOGE("where = %s\n", where);
3483         if (strlen(where) > 0) {
3484                 strncat(query, where, sizeof(query) - strlen(query) - 1);
3485                 query[sizeof(query) - 1] = '\0';
3486         }
3487         _LOGE("query = %s\n", query);
3488
3489         /*Execute Query*/
3490         if (SQLITE_OK !=
3491             sqlite3_exec(manifest_db, query, __count_cb, (void *)count, &error_message)) {
3492                 _LOGE("Don't execute query = %s error message = %s\n", query,
3493                        error_message);
3494                 sqlite3_free(error_message);
3495                 sqlite3_close(manifest_db);
3496                 ret = PMINFO_R_ERROR;
3497                 *count = 0;
3498                 goto err;
3499         }
3500         ret = PMINFO_R_OK;
3501 err:
3502         if (locale) {
3503                 free(locale);
3504                 locale = NULL;
3505         }
3506         if (syslocale) {
3507                 free(syslocale);
3508                 syslocale = NULL;
3509         }
3510         sqlite3_close(manifest_db);
3511         return ret;
3512 }
3513
3514 API int pkgmgrinfo_pkginfo_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h handle,
3515                                 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data)
3516 {
3517         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3518         retvm_if(pkg_cb == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3519         char *syslocale = NULL;
3520         char *locale = NULL;
3521         char *condition = NULL;
3522         char *error_message = NULL;
3523         char query[MAX_QUERY_LEN] = {'\0'};
3524         char where[MAX_QUERY_LEN] = {'\0'};
3525         GSList *list;
3526         int ret = 0;
3527         label_x *tmp1 = NULL;
3528         icon_x *tmp2 = NULL;
3529         description_x *tmp3 = NULL;
3530         author_x *tmp4 = NULL;
3531         privilege_x *tmp5 = NULL;
3532         pkgmgr_pkginfo_x *node = NULL;
3533         pkgmgr_pkginfo_x *tmphead = NULL;
3534         pkgmgr_pkginfo_x *pkginfo = NULL;
3535
3536         pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3537         /*Get current locale*/
3538         syslocale = vconf_get_str(VCONFKEY_LANGSET);
3539         if (syslocale == NULL) {
3540                 _LOGE("current locale is NULL\n");
3541                 return PMINFO_R_ERROR;
3542         }
3543         locale = __convert_system_locale_to_manifest_locale(syslocale);
3544         if (locale == NULL) {
3545                 _LOGE("manifest locale is NULL\n");
3546                 free(syslocale);
3547                 return PMINFO_R_ERROR;
3548         }
3549
3550         ret = __open_manifest_db();
3551         if (ret == -1) {
3552                 _LOGE("Fail to open manifest DB\n");
3553                 ret = PMINFO_R_ERROR;
3554                 goto err;
3555         }
3556         /*Start constructing query*/
3557         snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_LIST_PACKAGE, locale);
3558
3559         /*Get where clause*/
3560         for (list = filter->list; list; list = g_slist_next(list)) {
3561                 __get_filter_condition(list->data, &condition);
3562                 if (condition) {
3563                         strncat(where, condition, sizeof(where) - strlen(where) -1);
3564                         where[sizeof(where) - 1] = '\0';
3565                         free(condition);
3566                         condition = NULL;
3567                 }
3568                 if (g_slist_next(list)) {
3569                         strncat(where, " and ", sizeof(where) - strlen(where) - 1);
3570                         where[sizeof(where) - 1] = '\0';
3571                 }
3572         }
3573         _LOGE("where = %s\n", where);
3574         if (strlen(where) > 0) {
3575                 strncat(query, where, sizeof(query) - strlen(query) - 1);
3576                 query[sizeof(query) - 1] = '\0';
3577         }
3578         _LOGE("query = %s\n", query);
3579         tmphead = calloc(1, sizeof(pkgmgr_pkginfo_x));
3580         if (tmphead == NULL) {
3581                 _LOGE("Out of Memory!!!\n");
3582                 ret = PMINFO_R_ERROR;
3583                 goto err;
3584         }
3585
3586         if (SQLITE_OK !=
3587             sqlite3_exec(manifest_db, query, __pkg_list_cb, (void *)tmphead, &error_message)) {
3588                 _LOGE("Don't execute query = %s error message = %s\n", query,
3589                        error_message);
3590                 sqlite3_free(error_message);
3591                 sqlite3_close(manifest_db);
3592                 ret = PMINFO_R_ERROR;
3593                 goto err;
3594         }
3595
3596         LISTHEAD(tmphead, node);
3597         for(node = node->next ; node ; node = node->next) {
3598                 pkginfo = node;
3599                 pkginfo->locale = strdup(locale);
3600                 pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
3601                 if (pkginfo->manifest_info->privileges == NULL) {
3602                         _LOGE("Failed to allocate memory for privileges info\n");
3603                         ret = PMINFO_R_ERROR;
3604                         goto err;
3605                 }
3606
3607                 /*populate manifest_info from DB*/
3608                 snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkginfo->manifest_info->package);
3609                 ret = __exec_pkginfo_query(query, (void *)pkginfo);
3610                 if (ret == -1) {
3611                         _LOGE("Package Info DB Information retrieval failed\n");
3612                         ret = PMINFO_R_ERROR;
3613                         goto err;
3614                 }
3615                 memset(query, '\0', MAX_QUERY_LEN);
3616                 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
3617                         " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, locale);
3618                 ret = __exec_pkginfo_query(query, (void *)pkginfo);
3619                 if (ret == -1) {
3620                         _LOGE("Package Info DB Information retrieval failed\n");
3621                         ret = PMINFO_R_ERROR;
3622                         goto err;
3623                 }
3624                 /*Also store the values corresponding to default locales*/
3625                 memset(query, '\0', MAX_QUERY_LEN);
3626                 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
3627                         " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, DEFAULT_LOCALE);
3628                 ret = __exec_pkginfo_query(query, (void *)pkginfo);
3629                 if (ret == -1) {
3630                         _LOGE("Package Info DB Information retrieval failed\n");
3631                         ret = PMINFO_R_ERROR;
3632                         goto err;
3633                 }
3634                 if (pkginfo->manifest_info->label) {
3635                         LISTHEAD(pkginfo->manifest_info->label, tmp1);
3636                         pkginfo->manifest_info->label = tmp1;
3637                 }
3638                 if (pkginfo->manifest_info->icon) {
3639                         LISTHEAD(pkginfo->manifest_info->icon, tmp2);
3640                         pkginfo->manifest_info->icon = tmp2;
3641                 }
3642                 if (pkginfo->manifest_info->description) {
3643                         LISTHEAD(pkginfo->manifest_info->description, tmp3);
3644                         pkginfo->manifest_info->description = tmp3;
3645                 }
3646                 if (pkginfo->manifest_info->author) {
3647                         LISTHEAD(pkginfo->manifest_info->author, tmp4);
3648                         pkginfo->manifest_info->author = tmp4;
3649                 }
3650                 if (pkginfo->manifest_info->privileges->privilege) {
3651                         LISTHEAD(pkginfo->manifest_info->privileges->privilege, tmp5);
3652                         pkginfo->manifest_info->privileges->privilege = tmp5;
3653                 }
3654         }
3655
3656         LISTHEAD(tmphead, node);
3657
3658         for(node = node->next ; node ; node = node->next) {
3659                 pkginfo = node;
3660                 ret = pkg_cb( (void *)pkginfo, user_data);
3661                 if(ret < 0)
3662                         break;
3663         }
3664         ret = PMINFO_R_OK;
3665
3666 err:
3667         if (locale) {
3668                 free(locale);
3669                 locale = NULL;
3670         }
3671         if (syslocale) {
3672                 free(syslocale);
3673                 syslocale = NULL;
3674         }
3675         sqlite3_close(manifest_db);
3676         __cleanup_pkginfo(tmphead);
3677         return ret;
3678 }
3679
3680 API int pkgmgrinfo_pkginfo_foreach_privilege(pkgmgrinfo_pkginfo_h handle,
3681                         pkgmgrinfo_pkg_privilege_list_cb privilege_func, void *user_data)
3682 {
3683         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
3684         retvm_if(privilege_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
3685         int ret = -1;
3686         privilege_x *ptr = NULL;
3687         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3688         ptr = info->manifest_info->privileges->privilege;
3689         for (; ptr; ptr = ptr->next) {
3690                 if (ptr->text){
3691                         ret = privilege_func(ptr->text, user_data);
3692                         if (ret < 0)
3693                                 break;
3694                 }
3695         }
3696         return PMINFO_R_OK;
3697 }
3698
3699 API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_component component,
3700                                                 pkgmgrinfo_app_list_cb app_func, void *user_data)
3701 {
3702         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
3703         retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback pointer is NULL");
3704         retvm_if((component != PMINFO_UI_APP) && (component != PMINFO_SVC_APP) && (component != PMINFO_ALL_APP), PMINFO_R_EINVAL, "Invalid App Component Type");
3705
3706         char *syslocale = NULL;
3707         char *locale = NULL;
3708         int ret = -1;
3709         char query[MAX_QUERY_LEN] = {'\0'};
3710         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3711         pkgmgr_pkginfo_x *allinfo = NULL;
3712         pkgmgr_appinfo_x *appinfo = NULL;
3713         icon_x *ptr1 = NULL;
3714         label_x *ptr2 = NULL;
3715         category_x *ptr3 = NULL;
3716         metadata_x *ptr4 = NULL;
3717         permission_x *ptr5 = NULL;
3718         image_x *ptr6 = NULL;
3719         sqlite3 *appinfo_db = NULL;
3720
3721         /*get system locale*/
3722         syslocale = vconf_get_str(VCONFKEY_LANGSET);
3723         tryvm_if(syslocale == NULL, ret = PMINFO_R_EINVAL, "current locale is NULL");
3724
3725         /*get locale on db*/
3726         locale = __convert_system_locale_to_manifest_locale(syslocale);
3727         tryvm_if(locale == NULL, ret = PMINFO_R_EINVAL, "manifest locale is NULL");
3728
3729         /*calloc allinfo*/
3730         allinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
3731         tryvm_if(allinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
3732
3733         /*calloc manifest_info*/
3734         allinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
3735         tryvm_if(allinfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
3736
3737         /*calloc appinfo*/
3738         appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
3739         tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
3740
3741         /*set component type*/
3742         if (component == PMINFO_UI_APP)
3743                 appinfo->app_component = PMINFO_UI_APP;
3744         if (component == PMINFO_SVC_APP)
3745                 appinfo->app_component = PMINFO_SVC_APP;
3746         if (component == PMINFO_ALL_APP)
3747                 appinfo->app_component = PMINFO_ALL_APP;
3748
3749         /*open db */
3750         ret = db_util_open_with_options(MANIFEST_DB, &appinfo_db, SQLITE_OPEN_READONLY, NULL);
3751         retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
3752
3753         appinfo->package = strdup(info->manifest_info->package);
3754         snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
3755                         "from package_app_info where " \
3756                         "package='%s' and app_component='%s'",
3757                         info->manifest_info->package,
3758                         (appinfo->app_component==PMINFO_UI_APP ? "uiapp" : "svcapp"));
3759
3760         switch(component) {
3761         case PMINFO_UI_APP:
3762                 /*Populate ui app info */
3763                 ret = __exec_db_query(appinfo_db, query, __uiapp_list_cb, (void *)info);
3764                 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
3765
3766                 uiapplication_x *tmp = NULL;
3767                 if (info->manifest_info->uiapplication) {
3768                         LISTHEAD(info->manifest_info->uiapplication, tmp);
3769                         info->manifest_info->uiapplication = tmp;
3770                 }
3771                 /*Populate localized info for default locales and call callback*/
3772                 /*If the callback func return < 0 we break and no more call back is called*/
3773                 while(tmp != NULL)
3774                 {
3775                         appinfo->locale = strdup(locale);
3776                         appinfo->uiapp_info = tmp;
3777                         if (strcmp(appinfo->uiapp_info->type,"c++app") == 0){
3778                                 if (locale) {
3779                                         free(locale);
3780                                 }
3781                                 locale = __get_app_locale_by_fallback(appinfo_db, appinfo->uiapp_info->appid, syslocale);
3782                         }
3783
3784                         memset(query, '\0', MAX_QUERY_LEN);
3785                         snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->uiapp_info->appid, locale);
3786                         ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3787                         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
3788
3789                         memset(query, '\0', MAX_QUERY_LEN);
3790                         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);
3791                         ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3792                         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
3793
3794                         /*store setting notification icon section*/
3795                         memset(query, '\0', MAX_QUERY_LEN);
3796                         snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appinfo->uiapp_info->appid);
3797                         ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3798                         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
3799                         
3800                         /*store app preview image info*/
3801                         memset(query, '\0', MAX_QUERY_LEN);
3802                         snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", appinfo->uiapp_info->appid);
3803                         ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3804                         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
3805
3806                         if (appinfo->uiapp_info->label) {
3807                                 LISTHEAD(appinfo->uiapp_info->label, ptr2);
3808                                 appinfo->uiapp_info->label = ptr2;
3809                         }
3810                         if (appinfo->uiapp_info->icon) {
3811                                 LISTHEAD(appinfo->uiapp_info->icon, ptr1);
3812                                 appinfo->uiapp_info->icon = ptr1;
3813                         }
3814                         if (appinfo->uiapp_info->category) {
3815                                 LISTHEAD(appinfo->uiapp_info->category, ptr3);
3816                                 appinfo->uiapp_info->category = ptr3;
3817                         }
3818                         if (appinfo->uiapp_info->metadata) {
3819                                 LISTHEAD(appinfo->uiapp_info->metadata, ptr4);
3820                                 appinfo->uiapp_info->metadata = ptr4;
3821                         }
3822                         if (appinfo->uiapp_info->permission) {
3823                                 LISTHEAD(appinfo->uiapp_info->permission, ptr5);
3824                                 appinfo->uiapp_info->permission = ptr5;
3825                         }
3826                         if (appinfo->uiapp_info->image) {
3827                                 LISTHEAD(appinfo->uiapp_info->image, ptr6);
3828                                 appinfo->uiapp_info->image = ptr6;
3829                         }
3830                         ret = app_func((void *)appinfo, user_data);
3831                         if (ret < 0)
3832                                 break;
3833                         tmp = tmp->next;
3834                 }
3835                 break;
3836         case PMINFO_SVC_APP:
3837                 /*Populate svc app info */
3838                 ret = __exec_db_query(appinfo_db, query, __svcapp_list_cb, (void *)info);
3839                 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
3840
3841                 serviceapplication_x *tmp1 = NULL;
3842                 if (info->manifest_info->serviceapplication) {
3843                         LISTHEAD(info->manifest_info->serviceapplication, tmp1);
3844                         info->manifest_info->serviceapplication = tmp1;
3845                 }
3846                 /*Populate localized info for default locales and call callback*/
3847                 /*If the callback func return < 0 we break and no more call back is called*/
3848                 while(tmp1 != NULL)
3849                 {
3850                         appinfo->locale = strdup(locale);
3851                         appinfo->svcapp_info = tmp1;
3852                         memset(query, '\0', MAX_QUERY_LEN);
3853                         snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->svcapp_info->appid, locale);
3854                         ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3855                         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
3856
3857                         memset(query, '\0', MAX_QUERY_LEN);
3858                         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);
3859                         ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3860                         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
3861
3862                         if (appinfo->svcapp_info->label) {
3863                                 LISTHEAD(appinfo->svcapp_info->label, ptr2);
3864                                 appinfo->svcapp_info->label = ptr2;
3865                         }
3866                         if (appinfo->svcapp_info->icon) {
3867                                 LISTHEAD(appinfo->svcapp_info->icon, ptr1);
3868                                 appinfo->svcapp_info->icon = ptr1;
3869                         }
3870                         if (appinfo->svcapp_info->category) {
3871                                 LISTHEAD(appinfo->svcapp_info->category, ptr3);
3872                                 appinfo->svcapp_info->category = ptr3;
3873                         }
3874                         if (appinfo->svcapp_info->metadata) {
3875                                 LISTHEAD(appinfo->svcapp_info->metadata, ptr4);
3876                                 appinfo->svcapp_info->metadata = ptr4;
3877                         }
3878                         if (appinfo->svcapp_info->permission) {
3879                                 LISTHEAD(appinfo->svcapp_info->permission, ptr5);
3880                                 appinfo->svcapp_info->permission = ptr5;
3881                         }
3882                         ret = app_func((void *)appinfo, user_data);
3883                         if (ret < 0)
3884                                 break;
3885                         tmp1 = tmp1->next;
3886                 }
3887                 break;
3888         case PMINFO_ALL_APP:
3889                 memset(query, '\0', MAX_QUERY_LEN);
3890                 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where package='%s'", info->manifest_info->package);
3891
3892                 /*Populate all app info */
3893                 ret = __exec_db_query(appinfo_db, query, __allapp_list_cb, (void *)allinfo);
3894                 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
3895
3896                 /*UI Apps*/
3897                 appinfo->app_component = PMINFO_UI_APP;
3898                 uiapplication_x *tmp2 = NULL;
3899                 if (allinfo->manifest_info->uiapplication) {
3900                         LISTHEAD(allinfo->manifest_info->uiapplication, tmp2);
3901                         allinfo->manifest_info->uiapplication = tmp2;
3902                 }
3903                 /*Populate localized info for default locales and call callback*/
3904                 /*If the callback func return < 0 we break and no more call back is called*/
3905                 while(tmp2 != NULL)
3906                 {
3907                         appinfo->locale = strdup(locale);
3908                         appinfo->uiapp_info = tmp2;
3909                         memset(query, '\0', MAX_QUERY_LEN);
3910                         snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->uiapp_info->appid, locale);
3911                         ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3912                         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
3913
3914                         memset(query, '\0', MAX_QUERY_LEN);
3915                         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);
3916                         ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3917                         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
3918
3919                         /*store setting notification icon section*/
3920                         memset(query, '\0', MAX_QUERY_LEN);
3921                         snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appinfo->uiapp_info->appid);
3922                         ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3923                         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
3924                         
3925                         /*store app preview image info*/
3926                         memset(query, '\0', MAX_QUERY_LEN);
3927                         snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", appinfo->uiapp_info->appid);
3928                         ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3929                         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
3930
3931                         if (appinfo->uiapp_info->label) {
3932                                 LISTHEAD(appinfo->uiapp_info->label, ptr2);
3933                                 appinfo->uiapp_info->label = ptr2;
3934                         }
3935                         if (appinfo->uiapp_info->icon) {
3936                                 LISTHEAD(appinfo->uiapp_info->icon, ptr1);
3937                                 appinfo->uiapp_info->icon = ptr1;
3938                         }
3939                         if (appinfo->uiapp_info->category) {
3940                                 LISTHEAD(appinfo->uiapp_info->category, ptr3);
3941                                 appinfo->uiapp_info->category = ptr3;
3942                         }
3943                         if (appinfo->uiapp_info->metadata) {
3944                                 LISTHEAD(appinfo->uiapp_info->metadata, ptr4);
3945                                 appinfo->uiapp_info->metadata = ptr4;
3946                         }
3947                         if (appinfo->uiapp_info->permission) {
3948                                 LISTHEAD(appinfo->uiapp_info->permission, ptr5);
3949                                 appinfo->uiapp_info->permission = ptr5;
3950                         }
3951                         if (appinfo->uiapp_info->image) {
3952                                 LISTHEAD(appinfo->uiapp_info->image, ptr6);
3953                                 appinfo->uiapp_info->image = ptr6;
3954                         }
3955                         ret = app_func((void *)appinfo, user_data);
3956                         if (ret < 0)
3957                                 break;
3958                         tmp2 = tmp2->next;
3959                 }
3960
3961                 /*SVC Apps*/
3962                 appinfo->app_component = PMINFO_SVC_APP;
3963                 serviceapplication_x *tmp3 = NULL;
3964                 if (allinfo->manifest_info->serviceapplication) {
3965                         LISTHEAD(allinfo->manifest_info->serviceapplication, tmp3);
3966                         allinfo->manifest_info->serviceapplication = tmp3;
3967                 }
3968                 /*Populate localized info for default locales and call callback*/
3969                 /*If the callback func return < 0 we break and no more call back is called*/
3970                 while(tmp3 != NULL)
3971                 {
3972                         appinfo->locale = strdup(locale);
3973                         appinfo->svcapp_info = tmp3;
3974                         memset(query, '\0', MAX_QUERY_LEN);
3975                         snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->svcapp_info->appid, locale);
3976                         ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3977                         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
3978
3979                         memset(query, '\0', MAX_QUERY_LEN);
3980                         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);
3981                         ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3982                         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
3983
3984                         if (appinfo->svcapp_info->label) {
3985                                 LISTHEAD(appinfo->svcapp_info->label, ptr2);
3986                                 appinfo->svcapp_info->label = ptr2;
3987                         }
3988                         if (appinfo->svcapp_info->icon) {
3989                                 LISTHEAD(appinfo->svcapp_info->icon, ptr1);
3990                                 appinfo->svcapp_info->icon = ptr1;
3991                         }
3992                         if (appinfo->svcapp_info->category) {
3993                                 LISTHEAD(appinfo->svcapp_info->category, ptr3);
3994                                 appinfo->svcapp_info->category = ptr3;
3995                         }
3996                         if (appinfo->svcapp_info->metadata) {
3997                                 LISTHEAD(appinfo->svcapp_info->metadata, ptr4);
3998                                 appinfo->svcapp_info->metadata = ptr4;
3999                         }
4000                         if (appinfo->svcapp_info->permission) {
4001                                 LISTHEAD(appinfo->svcapp_info->permission, ptr5);
4002                                 appinfo->svcapp_info->permission = ptr5;
4003                         }
4004                         ret = app_func((void *)appinfo, user_data);
4005                         if (ret < 0)
4006                                 break;
4007                         tmp3 = tmp3->next;
4008                 }
4009                 appinfo->app_component = PMINFO_ALL_APP;
4010                 break;
4011
4012         }
4013
4014         ret = PMINFO_R_OK;
4015 catch:
4016         if (locale) {
4017                 free(locale);
4018                 locale = NULL;
4019         }
4020         if (syslocale) {
4021                 free(syslocale);
4022                 syslocale = NULL;
4023         }
4024         if (appinfo) {
4025                 if (appinfo->package) {
4026                         free((void *)appinfo->package);
4027                         appinfo->package = NULL;
4028                 }
4029                 free(appinfo);
4030                 appinfo = NULL;
4031         }
4032         __cleanup_pkginfo(allinfo);
4033
4034         sqlite3_close(appinfo_db);
4035         return ret;
4036 }
4037
4038 API int pkgmgrinfo_appinfo_get_install_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
4039 {
4040         retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback function is NULL");
4041
4042         int ret = PMINFO_R_OK;
4043         char query[MAX_QUERY_LEN] = {'\0'};
4044         pkgmgr_appinfo_x *info = NULL;
4045         pkgmgr_appinfo_x *appinfo = NULL;
4046         uiapplication_x *ptr1 = NULL;
4047         sqlite3 *appinfo_db = NULL;
4048
4049         /*open db*/
4050         ret = db_util_open_with_options(MANIFEST_DB, &appinfo_db, SQLITE_OPEN_READONLY, NULL);
4051         retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
4052
4053         /*calloc appinfo*/
4054         info = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
4055         tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4056
4057         /*calloc uiapplication_x*/
4058         info->uiapp_info= (uiapplication_x *)calloc(1, sizeof(uiapplication_x));
4059         tryvm_if(info->uiapp_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4060
4061         /*calloc appinfo*/
4062         appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
4063         tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4064
4065         /*query package_app_info*/
4066         snprintf(query, MAX_QUERY_LEN, "select * from package_app_info");
4067         ret = __exec_db_query(appinfo_db, query, __mini_appinfo_cb, (void *)info);
4068         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4069
4070         LISTHEAD(info->uiapp_info, ptr1);
4071
4072         /*call back*/
4073         for(ptr1 = ptr1->next ; ptr1 ; ptr1 = ptr1->next)
4074         {
4075                 appinfo->uiapp_info= ptr1;
4076                 appinfo->package = strdup(ptr1->package);
4077                 appinfo->app_component = PMINFO_UI_APP;
4078
4079                 ret = app_func((void *)appinfo, user_data);
4080                 if (ret < 0)
4081                         break;
4082                 free((void *)appinfo->package);
4083                 appinfo->package = NULL;
4084         }
4085
4086 catch:
4087         sqlite3_close(appinfo_db);
4088
4089         if (appinfo) {
4090                 free(appinfo);
4091                 appinfo = NULL;
4092         }
4093         __cleanup_appinfo(info);
4094         return ret;
4095 }
4096
4097 API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
4098 {
4099         retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback function is NULL");
4100
4101         int ret = PMINFO_R_OK;
4102         char query[MAX_QUERY_LEN] = {'\0'};
4103         char *syslocale = NULL;
4104         char *locale = NULL;
4105         pkgmgr_appinfo_x *appinfo = NULL;
4106         uiapplication_x *ptr1 = NULL;
4107         serviceapplication_x *ptr2 = NULL;
4108         label_x *tmp1 = NULL;
4109         icon_x *tmp2 = NULL;
4110         category_x *tmp3 = NULL;
4111         metadata_x *tmp4 = NULL;
4112         permission_x *tmp5 = NULL;
4113         image_x *tmp6 = NULL;
4114         sqlite3 *appinfo_db = NULL;
4115
4116         /*get system locale*/
4117         syslocale = vconf_get_str(VCONFKEY_LANGSET);
4118         tryvm_if(syslocale == NULL, ret = PMINFO_R_ERROR, "current locale is NULL");
4119
4120         /*get locale on db*/
4121         locale = __convert_system_locale_to_manifest_locale(syslocale);
4122         tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
4123
4124         /*open db*/
4125         ret = db_util_open_with_options(MANIFEST_DB, &appinfo_db, SQLITE_OPEN_READONLY, NULL);
4126         retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
4127
4128         /*calloc pkginfo*/
4129         pkgmgr_pkginfo_x *info = NULL;
4130         info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
4131         tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4132
4133         /*calloc manifest_info*/
4134         info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
4135         tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4136
4137         /*calloc appinfo*/
4138         appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
4139         tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4140
4141         snprintf(query, MAX_QUERY_LEN, "select * from package_app_info");
4142         ret = __exec_db_query(appinfo_db, query, __app_list_cb, (void *)info);
4143         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4144
4145         if (info->manifest_info->uiapplication) {
4146                 LISTHEAD(info->manifest_info->uiapplication, ptr1);
4147                 info->manifest_info->uiapplication = ptr1;
4148         }
4149         if (info->manifest_info->serviceapplication) {
4150                 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
4151                 info->manifest_info->serviceapplication = ptr2;
4152         }
4153
4154         /*UI Apps*/
4155         for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
4156         {
4157                 appinfo->locale = strdup(locale);
4158                 appinfo->app_component = PMINFO_UI_APP;
4159                 appinfo->package = strdup(ptr1->package);
4160                 appinfo->uiapp_info = ptr1;
4161                 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4162                                 "from package_app_info where " \
4163                                 "app_id='%s'", ptr1->appid);
4164                 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4165                 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4166
4167                 if (strcmp(appinfo->uiapp_info->type,"c++app") == 0){
4168                         if (locale) {
4169                                 free(locale);
4170                         }
4171                         locale = __get_app_locale_by_fallback(appinfo_db, ptr1->appid, syslocale);
4172                 }
4173
4174                 memset(query, '\0', MAX_QUERY_LEN);
4175                 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4176                                 "from package_app_localized_info where " \
4177                                 "app_id='%s' and app_locale='%s'",
4178                                 ptr1->appid, locale);
4179                 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4180                 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4181
4182                 memset(query, '\0', MAX_QUERY_LEN);
4183                 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4184                                 "from package_app_localized_info where " \
4185                                 "app_id='%s' and app_locale='%s'",
4186                                 ptr1->appid, DEFAULT_LOCALE);
4187
4188                 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4189                 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4190
4191                 /*store setting notification icon section*/
4192                 memset(query, '\0', MAX_QUERY_LEN);
4193                 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", ptr1->appid);
4194                 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4195                 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
4196                 
4197                 /*store app preview image info*/
4198                 memset(query, '\0', MAX_QUERY_LEN);
4199                 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", ptr1->appid);
4200                 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4201                 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
4202
4203                 if (appinfo->uiapp_info->label) {
4204                         LISTHEAD(appinfo->uiapp_info->label, tmp1);
4205                         appinfo->uiapp_info->label = tmp1;
4206                 }
4207                 if (appinfo->uiapp_info->icon) {
4208                         LISTHEAD(appinfo->uiapp_info->icon, tmp2);
4209                         appinfo->uiapp_info->icon= tmp2;
4210                 }
4211                 if (appinfo->uiapp_info->category) {
4212                         LISTHEAD(appinfo->uiapp_info->category, tmp3);
4213                         appinfo->uiapp_info->category = tmp3;
4214                 }
4215                 if (appinfo->uiapp_info->metadata) {
4216                         LISTHEAD(appinfo->uiapp_info->metadata, tmp4);
4217                         appinfo->uiapp_info->metadata = tmp4;
4218                 }
4219                 if (appinfo->uiapp_info->permission) {
4220                         LISTHEAD(appinfo->uiapp_info->permission, tmp5);
4221                         appinfo->uiapp_info->permission = tmp5;
4222                 }
4223                 if (appinfo->uiapp_info->image) {
4224                         LISTHEAD(appinfo->uiapp_info->image, tmp6);
4225                         appinfo->uiapp_info->image = tmp6;
4226                 }
4227                 ret = app_func((void *)appinfo, user_data);
4228                 if (ret < 0)
4229                         break;
4230                 free((void *)appinfo->package);
4231                 appinfo->package = NULL;
4232         }
4233         /*Service Apps*/
4234         for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
4235         {
4236                 appinfo->locale = strdup(locale);
4237                 appinfo->app_component = PMINFO_SVC_APP;
4238                 appinfo->package = strdup(ptr2->package);
4239                 appinfo->svcapp_info = ptr2;
4240                 memset(query, '\0', MAX_QUERY_LEN);
4241                 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4242                                 "from package_app_info where " \
4243                                 "app_id='%s'", ptr2->appid);
4244                 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4245                 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4246
4247                 memset(query, '\0', MAX_QUERY_LEN);
4248                 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4249                                 "from package_app_localized_info where " \
4250                                 "app_id='%s' and app_locale='%s'",
4251                                 ptr2->appid, locale);
4252                 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4253                 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4254
4255                 memset(query, '\0', MAX_QUERY_LEN);
4256                 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4257                                 "from package_app_localized_info where " \
4258                                 "app_id='%s' and app_locale='%s'",
4259                                 ptr2->appid, DEFAULT_LOCALE);
4260                 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4261                 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4262
4263                 if (appinfo->svcapp_info->label) {
4264                         LISTHEAD(appinfo->svcapp_info->label, tmp1);
4265                         appinfo->svcapp_info->label = tmp1;
4266                 }
4267                 if (appinfo->svcapp_info->icon) {
4268                         LISTHEAD(appinfo->svcapp_info->icon, tmp2);
4269                         appinfo->svcapp_info->icon= tmp2;
4270                 }
4271                 if (appinfo->svcapp_info->category) {
4272                         LISTHEAD(appinfo->svcapp_info->category, tmp3);
4273                         appinfo->svcapp_info->category = tmp3;
4274                 }
4275                 if (appinfo->svcapp_info->metadata) {
4276                         LISTHEAD(appinfo->svcapp_info->metadata, tmp4);
4277                         appinfo->svcapp_info->metadata = tmp4;
4278                 }
4279                 if (appinfo->svcapp_info->permission) {
4280                         LISTHEAD(appinfo->svcapp_info->permission, tmp5);
4281                         appinfo->svcapp_info->permission = tmp5;
4282                 }
4283                 ret = app_func((void *)appinfo, user_data);
4284                 if (ret < 0)
4285                         break;
4286                 free((void *)appinfo->package);
4287                 appinfo->package = NULL;
4288         }
4289         ret = PMINFO_R_OK;
4290
4291 catch:
4292         if (locale) {
4293                 free(locale);
4294                 locale = NULL;
4295         }
4296         if (syslocale) {
4297                 free(syslocale);
4298                 syslocale = NULL;
4299         }
4300         sqlite3_close(appinfo_db);
4301         if (appinfo) {
4302                 free(appinfo);
4303                 appinfo = NULL;
4304         }
4305         __cleanup_pkginfo(info);
4306         return ret;
4307 }
4308
4309 API int pkgmgrinfo_appinfo_get_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
4310 {
4311         retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL");
4312         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4313
4314         pkgmgr_appinfo_x *appinfo = NULL;
4315         char *syslocale = NULL;
4316         char *locale = NULL;
4317         int ret = -1;
4318         int exist = 0;
4319         label_x *tmp1 = NULL;
4320         icon_x *tmp2 = NULL;
4321         category_x *tmp3 = NULL;
4322         metadata_x *tmp4 = NULL;
4323         permission_x *tmp5 = NULL;
4324         image_x *tmp6 = NULL;
4325         char query[MAX_QUERY_LEN] = {'\0'};
4326         sqlite3 *appinfo_db = NULL;
4327
4328         /*open db*/
4329         ret = db_util_open_with_options(MANIFEST_DB, &appinfo_db, SQLITE_OPEN_READONLY, NULL);
4330         retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
4331
4332         /*check appid exist on db*/
4333         snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", appid);
4334         ret = __exec_db_query(appinfo_db, query, __validate_cb, (void *)&exist);
4335         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "sqlite3_exec fail");
4336         tryvm_if(exist == 0, ret = PMINFO_R_ERROR, "Appid[%s] not found in DB", appid);
4337
4338         /*get system locale*/
4339         syslocale = vconf_get_str(VCONFKEY_LANGSET);
4340         tryvm_if(syslocale == NULL, ret = PMINFO_R_ERROR, "current locale is NULL");
4341
4342         /*get locale on db*/
4343         locale = __convert_system_locale_to_manifest_locale(syslocale);
4344         tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
4345
4346         /*calloc appinfo*/
4347         appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
4348         tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
4349
4350         /*check app_component from DB*/
4351         memset(query, '\0', MAX_QUERY_LEN);
4352         snprintf(query, MAX_QUERY_LEN, "select app_component, package from package_app_info where app_id='%s' ", appid);
4353         ret = __exec_db_query(appinfo_db, query, __appcomponent_cb, (void *)appinfo);
4354         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4355
4356         /*calloc app_component*/
4357         if (appinfo->app_component == PMINFO_UI_APP) {
4358                 appinfo->uiapp_info = (uiapplication_x *)calloc(1, sizeof(uiapplication_x));
4359                 tryvm_if(appinfo->uiapp_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for uiapp info");
4360         } else {
4361                 appinfo->svcapp_info = (serviceapplication_x *)calloc(1, sizeof(serviceapplication_x));
4362                 tryvm_if(appinfo->svcapp_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for svcapp info");
4363         }
4364         appinfo->locale = strdup(locale);
4365
4366         /*populate app_info from DB*/
4367         memset(query, '\0', MAX_QUERY_LEN);
4368         snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' ", appid);
4369         ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4370         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4371
4372         memset(query, '\0', MAX_QUERY_LEN);
4373         snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appid, locale);
4374         ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4375         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4376
4377         /*Also store the values corresponding to default locales*/
4378         memset(query, '\0', MAX_QUERY_LEN);
4379         snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appid, DEFAULT_LOCALE);
4380         ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4381         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4382
4383         /*Populate app category*/
4384         memset(query, '\0', MAX_QUERY_LEN);
4385         snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_category where app_id='%s'", appid);
4386         ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4387         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Category Info DB Information retrieval failed");
4388
4389         /*Populate app metadata*/
4390         memset(query, '\0', MAX_QUERY_LEN);
4391         snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_metadata where app_id='%s'", appid);
4392         ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4393         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Metadata Info DB Information retrieval failed");
4394
4395         /*Populate app permission*/
4396         memset(query, '\0', MAX_QUERY_LEN);
4397         snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_permission where app_id='%s'", appid);
4398         ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4399         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App permission Info DB Information retrieval failed");
4400
4401         /*store setting notification icon section*/
4402         memset(query, '\0', MAX_QUERY_LEN);
4403         snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appid);
4404         ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4405         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
4406
4407         /*store app preview image info*/
4408         memset(query, '\0', MAX_QUERY_LEN);
4409         snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", appid);
4410         ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4411         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
4412
4413         switch (appinfo->app_component) {
4414         case PMINFO_UI_APP:
4415                 if (appinfo->uiapp_info->label) {
4416                         LISTHEAD(appinfo->uiapp_info->label, tmp1);
4417                         appinfo->uiapp_info->label = tmp1;
4418                 }
4419                 if (appinfo->uiapp_info->icon) {
4420                         LISTHEAD(appinfo->uiapp_info->icon, tmp2);
4421                         appinfo->uiapp_info->icon = tmp2;
4422                 }
4423                 if (appinfo->uiapp_info->category) {
4424                         LISTHEAD(appinfo->uiapp_info->category, tmp3);
4425                         appinfo->uiapp_info->category = tmp3;
4426                 }
4427                 if (appinfo->uiapp_info->metadata) {
4428                         LISTHEAD(appinfo->uiapp_info->metadata, tmp4);
4429                         appinfo->uiapp_info->metadata = tmp4;
4430                 }
4431                 if (appinfo->uiapp_info->permission) {
4432                         LISTHEAD(appinfo->uiapp_info->permission, tmp5);
4433                         appinfo->uiapp_info->permission = tmp5;
4434                 }
4435                 if (appinfo->uiapp_info->image) {
4436                         LISTHEAD(appinfo->uiapp_info->image, tmp6);
4437                         appinfo->uiapp_info->image = tmp6;
4438                 }
4439                 break;
4440         case PMINFO_SVC_APP:
4441                 if (appinfo->svcapp_info->label) {
4442                         LISTHEAD(appinfo->svcapp_info->label, tmp1);
4443                         appinfo->svcapp_info->label = tmp1;
4444                 }
4445                 if (appinfo->svcapp_info->icon) {
4446                         LISTHEAD(appinfo->svcapp_info->icon, tmp2);
4447                         appinfo->svcapp_info->icon = tmp2;
4448                 }
4449                 if (appinfo->svcapp_info->category) {
4450                         LISTHEAD(appinfo->svcapp_info->category, tmp3);
4451                         appinfo->svcapp_info->category = tmp3;
4452                 }
4453                 if (appinfo->svcapp_info->metadata) {
4454                         LISTHEAD(appinfo->svcapp_info->metadata, tmp4);
4455                         appinfo->svcapp_info->metadata = tmp4;
4456                 }
4457                 if (appinfo->svcapp_info->permission) {
4458                         LISTHEAD(appinfo->svcapp_info->permission, tmp5);
4459                         appinfo->svcapp_info->permission = tmp5;
4460                 }
4461                 break;
4462         default:
4463                 break;
4464         }
4465
4466         ret = PMINFO_R_OK;
4467
4468 catch:
4469         if (ret == PMINFO_R_OK)
4470                 *handle = (void*)appinfo;
4471         else {
4472                 *handle = NULL;
4473                 __cleanup_appinfo(appinfo);
4474         }
4475
4476         sqlite3_close(appinfo_db);
4477         if (syslocale) {
4478                 free(syslocale);
4479                 syslocale = NULL;
4480         }
4481         if (locale) {
4482                 free(locale);
4483                 locale = NULL;
4484         }
4485         return ret;
4486 }
4487
4488
4489 API int pkgmgrinfo_appinfo_get_appid(pkgmgrinfo_appinfo_h  handle, char **appid)
4490 {
4491         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4492         retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4493         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4494
4495         if (info->app_component == PMINFO_UI_APP)
4496                 *appid = (char *)info->uiapp_info->appid;
4497         else if (info->app_component == PMINFO_SVC_APP)
4498                 *appid = (char *)info->svcapp_info->appid;
4499
4500         return PMINFO_R_OK;
4501 }
4502
4503 API int pkgmgrinfo_appinfo_get_pkgname(pkgmgrinfo_appinfo_h  handle, char **pkg_name)
4504 {
4505         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4506         retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4507         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4508
4509         *pkg_name = (char *)info->package;
4510
4511         return PMINFO_R_OK;
4512 }
4513
4514 API int pkgmgrinfo_appinfo_get_pkgid(pkgmgrinfo_appinfo_h  handle, char **pkgid)
4515 {
4516         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4517         retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4518         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4519
4520         *pkgid = (char *)info->package;
4521
4522         return PMINFO_R_OK;
4523 }
4524
4525 API int pkgmgrinfo_appinfo_get_exec(pkgmgrinfo_appinfo_h  handle, char **exec)
4526 {
4527         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4528         retvm_if(exec == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4529         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4530
4531         if (info->app_component == PMINFO_UI_APP)
4532                 *exec = (char *)info->uiapp_info->exec;
4533         if (info->app_component == PMINFO_SVC_APP)
4534                 *exec = (char *)info->svcapp_info->exec;
4535
4536         return PMINFO_R_OK;
4537 }
4538
4539
4540 API int pkgmgrinfo_appinfo_get_icon(pkgmgrinfo_appinfo_h  handle, char **icon)
4541 {
4542         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4543         retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4544         char *locale = NULL;
4545         icon_x *ptr = NULL;
4546         icon_x *start = NULL;
4547         *icon = NULL;
4548
4549         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4550                 locale = info->locale;
4551                 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
4552
4553         if (info->app_component == PMINFO_UI_APP)
4554                 start = info->uiapp_info->icon;
4555         if (info->app_component == PMINFO_SVC_APP)
4556                 start = info->svcapp_info->icon;
4557         for(ptr = start; ptr != NULL; ptr = ptr->next)
4558         {
4559                 if (ptr->lang) {
4560                         if (strcmp(ptr->lang, locale) == 0) {
4561                                 *icon = (char *)ptr->text;
4562                                 if (strcasecmp(*icon, "(null)") == 0) {
4563                                         locale = DEFAULT_LOCALE;
4564                                         continue;
4565                                 } else
4566                                         break;
4567                         } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
4568                                 *icon = (char *)ptr->text;
4569                                 break;
4570                         }
4571                 }
4572         }
4573         return PMINFO_R_OK;
4574 }
4575
4576
4577 API int pkgmgrinfo_appinfo_get_label(pkgmgrinfo_appinfo_h  handle, char **label)
4578 {
4579         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4580         retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4581         char *locale = NULL;
4582         label_x *ptr = NULL;
4583         label_x *start = NULL;
4584         *label = NULL;
4585
4586         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4587         locale = info->locale;
4588         retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
4589
4590         if (info->app_component == PMINFO_UI_APP)
4591                 start = info->uiapp_info->label;
4592         if (info->app_component == PMINFO_SVC_APP)
4593                 start = info->svcapp_info->label;
4594         for(ptr = start; ptr != NULL; ptr = ptr->next)
4595         {
4596                 if (ptr->lang) {
4597                         if (strcmp(ptr->lang, locale) == 0) {
4598                                 *label = (char *)ptr->text;
4599                                 if (strcasecmp(*label, "(null)") == 0) {
4600                                         locale = DEFAULT_LOCALE;
4601                                         continue;
4602                                 } else
4603                                         break;
4604                         } else if (strncasecmp(ptr->lang, locale, 2) == 0) {
4605                                 *label = (char *)ptr->text;
4606                                 if (strcasecmp(*label, "(null)") == 0) {
4607                                                 locale = DEFAULT_LOCALE;
4608                                                 continue;
4609                                 } else
4610                                                 break;
4611                         } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
4612                                 *label = (char *)ptr->text;
4613                                 break;
4614                         }
4615                 }
4616         }
4617         return PMINFO_R_OK;
4618 }
4619
4620
4621 API int pkgmgrinfo_appinfo_get_component(pkgmgrinfo_appinfo_h  handle, pkgmgrinfo_app_component *component)
4622 {
4623         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4624         retvm_if(component == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4625         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4626
4627         if (info->app_component == PMINFO_UI_APP)
4628                 *component = PMINFO_UI_APP;
4629         else if (info->app_component == PMINFO_SVC_APP)
4630                 *component = PMINFO_SVC_APP;
4631         else
4632                 return PMINFO_R_ERROR;
4633
4634         return PMINFO_R_OK;
4635 }
4636
4637 API int pkgmgrinfo_appinfo_get_apptype(pkgmgrinfo_appinfo_h  handle, char **app_type)
4638 {
4639         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4640         retvm_if(app_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4641         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4642
4643         if (info->app_component == PMINFO_UI_APP)
4644                 *app_type = (char *)info->uiapp_info->type;
4645         if (info->app_component == PMINFO_SVC_APP)
4646                 *app_type = (char *)info->svcapp_info->type;
4647
4648         return PMINFO_R_OK;
4649 }
4650
4651 API int pkgmgrinfo_appinfo_get_operation(pkgmgrinfo_appcontrol_h  handle,
4652                                         int *operation_count, char ***operation)
4653 {
4654         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4655         retvm_if(operation == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4656         retvm_if(operation_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4657         pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
4658         *operation_count = data->operation_count;
4659         *operation = data->operation;
4660         return PMINFO_R_OK;
4661 }
4662
4663 API int pkgmgrinfo_appinfo_get_uri(pkgmgrinfo_appcontrol_h  handle,
4664                                         int *uri_count, char ***uri)
4665 {
4666         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4667         retvm_if(uri == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4668         retvm_if(uri_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4669         pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
4670         *uri_count = data->uri_count;
4671         *uri = data->uri;
4672         return PMINFO_R_OK;
4673 }
4674
4675 API int pkgmgrinfo_appinfo_get_mime(pkgmgrinfo_appcontrol_h  handle,
4676                                         int *mime_count, char ***mime)
4677 {
4678         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4679         retvm_if(mime == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4680         retvm_if(mime_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4681         pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
4682         *mime_count = data->mime_count;
4683         *mime = data->mime;
4684         return PMINFO_R_OK;
4685 }
4686
4687 API int pkgmgrinfo_appinfo_get_setting_icon(pkgmgrinfo_appinfo_h  handle, char **icon)
4688 {
4689         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
4690         retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4691
4692         char *val = NULL;
4693         icon_x *ptr = NULL;
4694         icon_x *start = NULL;
4695         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4696
4697         start = info->uiapp_info->icon;
4698
4699         for(ptr = start; ptr != NULL; ptr = ptr->next)
4700         {
4701                 if (ptr->section) {
4702                         val = (char *)ptr->section;
4703                         if (strcmp(val, "setting") == 0){
4704                                 *icon = (char *)ptr->text;
4705                                 break;
4706                         }
4707                 }
4708         }
4709         return PMINFO_R_OK;
4710 }
4711
4712
4713 API int pkgmgrinfo_appinfo_get_notification_icon(pkgmgrinfo_appinfo_h  handle, char **icon)
4714 {
4715         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
4716         retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4717
4718         char *val = NULL;
4719         icon_x *ptr = NULL;
4720         icon_x *start = NULL;
4721         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4722
4723         start = info->uiapp_info->icon;
4724
4725         for(ptr = start; ptr != NULL; ptr = ptr->next)
4726         {
4727                 if (ptr->section) {
4728                         val = (char *)ptr->section;
4729
4730                         if (strcmp(val, "notification") == 0){
4731                                 *icon = (char *)ptr->text;
4732                                 break;
4733                         }
4734                 }
4735         }
4736
4737         return PMINFO_R_OK;
4738 }
4739
4740 API int pkgmgrinfo_appinfo_get_recent_image_type(pkgmgrinfo_appinfo_h  handle, pkgmgrinfo_app_recentimage *type)
4741 {
4742         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4743         retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4744         char *val = NULL;
4745         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4746         val = (char *)info->uiapp_info->recentimage;
4747         if (val) {
4748                 if (strcasecmp(val, "capture") == 0)
4749                         *type = PMINFO_RECENTIMAGE_USE_CAPTURE;
4750                 else if (strcasecmp(val, "icon") == 0)
4751                         *type = PMINFO_RECENTIMAGE_USE_ICON;
4752                 else
4753                         *type = PMINFO_RECENTIMAGE_USE_NOTHING;
4754         }
4755
4756         return PMINFO_R_OK;
4757 }
4758
4759 API int pkgmgrinfo_appinfo_get_preview_image(pkgmgrinfo_appinfo_h  handle, char **preview_img)
4760 {
4761         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
4762         retvm_if(preview_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4763
4764         char *val = NULL;
4765         image_x *ptr = NULL;
4766         image_x *start = NULL;
4767         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4768
4769         start = info->uiapp_info->image;
4770
4771         for(ptr = start; ptr != NULL; ptr = ptr->next)
4772         {
4773                 if (ptr->section) {
4774                         val = (char *)ptr->section;
4775
4776                         if (strcmp(val, "preview") == 0)
4777                                 *preview_img = (char *)ptr->text;
4778
4779                         break;
4780                 }
4781         }
4782         return PMINFO_R_OK;
4783 }
4784
4785 API int pkgmgrinfo_appinfo_get_permission_type(pkgmgrinfo_appinfo_h  handle, pkgmgrinfo_permission_type *permission)
4786 {
4787         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
4788         retvm_if(permission == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4789
4790         char *val = NULL;
4791         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4792
4793         val = info->uiapp_info->permission_type;
4794
4795         if (strcmp(val, "signature") == 0)
4796                 *permission = PMINFO_PERMISSION_SIGNATURE;
4797         else if (strcmp(val, "privilege") == 0)
4798                 *permission = PMINFO_PERMISSION_PRIVILEGE;
4799         else
4800                 *permission = PMINFO_PERMISSION_NORMAL;
4801
4802         return PMINFO_R_OK;
4803 }
4804
4805 API int pkgmgrinfo_appinfo_foreach_permission(pkgmgrinfo_appinfo_h handle,
4806                         pkgmgrinfo_app_permission_list_cb permission_func, void *user_data)
4807 {
4808         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4809         retvm_if(permission_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
4810         int ret = -1;
4811         permission_x *ptr = NULL;
4812         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4813         if (info->app_component == PMINFO_UI_APP)
4814                 ptr = info->uiapp_info->permission;
4815         else if (info->app_component == PMINFO_SVC_APP)
4816                 ptr = info->svcapp_info->permission;
4817         else
4818                 return PMINFO_R_EINVAL;
4819         for (; ptr; ptr = ptr->next) {
4820                 ret = permission_func(ptr->value, user_data);
4821                 if (ret < 0)
4822                         break;
4823         }
4824         return PMINFO_R_OK;
4825 }
4826
4827 API int pkgmgrinfo_appinfo_foreach_category(pkgmgrinfo_appinfo_h handle,
4828                         pkgmgrinfo_app_category_list_cb category_func, void *user_data)
4829 {
4830         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4831         retvm_if(category_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
4832         int ret = -1;
4833         category_x *ptr = NULL;
4834         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4835         if (info->app_component == PMINFO_UI_APP)
4836                 ptr = info->uiapp_info->category;
4837         else if (info->app_component == PMINFO_SVC_APP)
4838                 ptr = info->svcapp_info->category;
4839         else
4840                 return PMINFO_R_EINVAL;
4841         for (; ptr; ptr = ptr->next) {
4842                 ret = category_func(ptr->name, user_data);
4843                 if (ret < 0)
4844                         break;
4845         }
4846         return PMINFO_R_OK;
4847 }
4848
4849 API int pkgmgrinfo_appinfo_foreach_metadata(pkgmgrinfo_appinfo_h handle,
4850                         pkgmgrinfo_app_metadata_list_cb metadata_func, void *user_data)
4851 {
4852         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4853         retvm_if(metadata_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
4854         int ret = -1;
4855         metadata_x *ptr = NULL;
4856         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4857         if (info->app_component == PMINFO_UI_APP)
4858                 ptr = info->uiapp_info->metadata;
4859         else if (info->app_component == PMINFO_SVC_APP)
4860                 ptr = info->svcapp_info->metadata;
4861         else
4862                 return PMINFO_R_EINVAL;
4863         for (; ptr; ptr = ptr->next) {
4864                 ret = metadata_func(ptr->key, ptr->value, user_data);
4865                 if (ret < 0)
4866                         break;
4867         }
4868         return PMINFO_R_OK;
4869 }
4870
4871 API int pkgmgrinfo_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
4872                         pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data)
4873 {
4874         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4875         retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
4876         int i = 0;
4877         int ret = -1;
4878         int oc = 0;
4879         int mc = 0;
4880         int uc = 0;
4881         char *pkgid = NULL;
4882         char *manifest = NULL;
4883         char **operation = NULL;
4884         char **uri = NULL;
4885         char **mime = NULL;
4886         appcontrol_x *appcontrol = NULL;
4887         manifest_x *mfx = NULL;
4888         operation_x *op = NULL;
4889         uri_x *ui = NULL;
4890         mime_x *mi = NULL;
4891         pkgmgrinfo_app_component component;
4892         pkgmgrinfo_appcontrol_x *ptr = NULL;
4893         ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid);
4894         if (ret < 0) {
4895                 _LOGE("Failed to get package name\n");
4896                 return PMINFO_R_ERROR;
4897         }
4898         ret = pkgmgrinfo_appinfo_get_component(handle, &component);
4899         if (ret < 0) {
4900                 _LOGE("Failed to get app component name\n");
4901                 return PMINFO_R_ERROR;
4902         }
4903         manifest = pkgmgr_parser_get_manifest_file(pkgid);
4904         if (manifest == NULL) {
4905                 _LOGE("Failed to fetch package manifest file\n");
4906                 return PMINFO_R_ERROR;
4907         }
4908         mfx = pkgmgr_parser_process_manifest_xml(manifest);
4909         if (mfx == NULL) {
4910                 _LOGE("Failed to parse package manifest file\n");
4911                 free(manifest);
4912                 manifest = NULL;
4913                 return PMINFO_R_ERROR;
4914         }
4915         free(manifest);
4916         ptr  = calloc(1, sizeof(pkgmgrinfo_appcontrol_x));
4917         if (ptr == NULL) {
4918                 _LOGE("Out of Memory!!!\n");
4919                 pkgmgr_parser_free_manifest_xml(mfx);
4920                 return PMINFO_R_ERROR;
4921         }
4922         /*Get Operation, Uri, Mime*/
4923         switch (component) {
4924         case PMINFO_UI_APP:
4925                 if (mfx->uiapplication) {
4926                         if (mfx->uiapplication->appcontrol) {
4927                                 appcontrol = mfx->uiapplication->appcontrol;
4928                         }
4929                 }
4930                 break;
4931         case PMINFO_SVC_APP:
4932                 if (mfx->serviceapplication) {
4933                         if (mfx->serviceapplication->appcontrol) {
4934                                 appcontrol = mfx->serviceapplication->appcontrol;
4935                         }
4936                 }
4937                 break;
4938         default:
4939                 break;
4940         }
4941         for (; appcontrol; appcontrol = appcontrol->next) {
4942                 op = appcontrol->operation;
4943                 for (; op; op = op->next)
4944                         oc = oc + 1;
4945                 op = appcontrol->operation;
4946
4947                 ui = appcontrol->uri;
4948                 for (; ui; ui = ui->next)
4949                         uc = uc + 1;
4950                 ui = appcontrol->uri;
4951
4952                 mi = appcontrol->mime;
4953                 for (; mi; mi = mi->next)
4954                         mc = mc + 1;
4955                 mi = appcontrol->mime;
4956
4957                 operation = (char **)calloc(oc, sizeof(char *));
4958                 for (i = 0; i < oc; i++) {
4959                         operation[i] = strndup(op->name, PKG_STRING_LEN_MAX - 1);
4960                         op = op->next;
4961                 }
4962
4963                 uri = (char **)calloc(uc, sizeof(char *));
4964                 for (i = 0; i < uc; i++) {
4965                         uri[i] = strndup(ui->name, PKG_STRING_LEN_MAX - 1);
4966                         ui = ui->next;
4967                 }
4968
4969                 mime = (char **)calloc(mc, sizeof(char *));
4970                 for (i = 0; i < mc; i++) {
4971                         mime[i] = strndup(mi->name, PKG_STRING_LEN_MAX - 1);
4972                         mi = mi->next;
4973                 }
4974                 /*populate appcontrol handle*/
4975                 ptr->operation_count = oc;
4976                 ptr->uri_count = uc;
4977                 ptr->mime_count = mc;
4978                 ptr->operation = operation;
4979                 ptr->uri = uri;
4980                 ptr->mime = mime;
4981                 ret = appcontrol_func((void *)ptr, user_data);
4982                 for (i = 0; i < oc; i++) {
4983                         if (operation[i]) {
4984                                 free(operation[i]);
4985                                 operation[i] = NULL;
4986                         }
4987                 }
4988                 if (operation) {
4989                         free(operation);
4990                         operation = NULL;
4991                 }
4992                 for (i = 0; i < uc; i++) {
4993                         if (uri[i]) {
4994                                 free(uri[i]);
4995                                 uri[i] = NULL;
4996                         }
4997                 }
4998                 if (uri) {
4999                         free(uri);
5000                         uri = NULL;
5001                 }
5002                 for (i = 0; i < mc; i++) {
5003                         if (mime[i]) {
5004                                 free(mime[i]);
5005                                 mime[i] = NULL;
5006                         }
5007                 }
5008                 if (mime) {
5009                         free(mime);
5010                         mime = NULL;
5011                 }
5012                 if (ret < 0)
5013                         break;
5014                 uc = 0;
5015                 mc = 0;
5016                 oc = 0;
5017         }
5018         pkgmgr_parser_free_manifest_xml(mfx);
5019         if (ptr) {
5020                 free(ptr);
5021                 ptr = NULL;
5022         }
5023         return PMINFO_R_OK;
5024 }
5025
5026 API int pkgmgrinfo_appinfo_is_nodisplay(pkgmgrinfo_appinfo_h  handle, bool *nodisplay)
5027 {
5028         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5029         retvm_if(nodisplay == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5030         char *val = NULL;
5031         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5032         val = (char *)info->uiapp_info->nodisplay;
5033         if (val) {
5034                 if (strcasecmp(val, "true") == 0)
5035                         *nodisplay = 1;
5036                 else if (strcasecmp(val, "false") == 0)
5037                         *nodisplay = 0;
5038                 else
5039                         *nodisplay = 0;
5040         }
5041         return PMINFO_R_OK;
5042 }
5043
5044 API int pkgmgrinfo_appinfo_is_multiple(pkgmgrinfo_appinfo_h  handle, bool *multiple)
5045 {
5046         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5047         retvm_if(multiple == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5048         char *val = NULL;
5049         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5050         val = (char *)info->uiapp_info->multiple;
5051         if (val) {
5052                 if (strcasecmp(val, "true") == 0)
5053                         *multiple = 1;
5054                 else if (strcasecmp(val, "false") == 0)
5055                         *multiple = 0;
5056                 else
5057                         *multiple = 0;
5058         }
5059         return PMINFO_R_OK;
5060 }
5061
5062 API int pkgmgrinfo_appinfo_is_indicator_display_allowed(pkgmgrinfo_appinfo_h handle, bool *indicator_disp)
5063 {
5064         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5065         retvm_if(indicator_disp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5066         char *val = NULL;
5067         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5068         val = (char *)info->uiapp_info->indicatordisplay;
5069         if (val) {
5070                 if (strcasecmp(val, "true") == 0){
5071                         *indicator_disp = 1;
5072                 }else if (strcasecmp(val, "false") == 0){
5073                         *indicator_disp = 0;
5074                 }else{
5075                         *indicator_disp = 0;
5076                 }
5077         }
5078         return PMINFO_R_OK;
5079 }
5080
5081
5082 API int pkgmgrinfo_appinfo_get_effectimage(pkgmgrinfo_appinfo_h  handle, char **portrait_img, char **landscape_img)
5083 {
5084         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5085         retvm_if(portrait_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5086         retvm_if(landscape_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5087         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5088
5089         if (info->app_component == PMINFO_UI_APP){
5090                 *portrait_img = (char *)info->uiapp_info->portraitimg;
5091                 *landscape_img = (char *)info->uiapp_info->landscapeimg;
5092         }
5093
5094         return PMINFO_R_OK;
5095 }
5096
5097 API int pkgmgrinfo_appinfo_is_taskmanage(pkgmgrinfo_appinfo_h  handle, bool *taskmanage)
5098 {
5099         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5100         retvm_if(taskmanage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5101         char *val = NULL;
5102         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5103         val = (char *)info->uiapp_info->taskmanage;
5104         if (val) {
5105                 if (strcasecmp(val, "true") == 0)
5106                         *taskmanage = 1;
5107                 else if (strcasecmp(val, "false") == 0)
5108                         *taskmanage = 0;
5109                 else
5110                         *taskmanage = 0;
5111         }
5112         return PMINFO_R_OK;
5113 }
5114
5115 API int pkgmgrinfo_appinfo_is_enabled(pkgmgrinfo_appinfo_h  handle, bool *enabled)
5116 {
5117         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5118         retvm_if(enabled == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5119         char *val = NULL;
5120         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5121         if (info->app_component == PMINFO_UI_APP)
5122                 val = (char *)info->uiapp_info->enabled;
5123         else if (info->app_component == PMINFO_SVC_APP)
5124                 val = (char *)info->uiapp_info->enabled;
5125         else {
5126                 _LOGE("invalid component type\n");
5127                 return PMINFO_R_EINVAL;
5128         }
5129
5130         if (val) {
5131                 if (strcasecmp(val, "true") == 0)
5132                         *enabled = 1;
5133                 else if (strcasecmp(val, "false") == 0)
5134                         *enabled = 0;
5135                 else
5136                         *enabled = 1;
5137         }
5138         return PMINFO_R_OK;
5139
5140 }
5141
5142 API int pkgmgrinfo_appinfo_get_hwacceleration(pkgmgrinfo_appinfo_h  handle, pkgmgrinfo_app_hwacceleration *hwacceleration)
5143 {
5144         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5145         retvm_if(hwacceleration == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5146         char *val = NULL;
5147         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5148         val = (char *)info->uiapp_info->hwacceleration;
5149         if (val) {
5150                 if (strcasecmp(val, "not-use-GL") == 0)
5151                         *hwacceleration = PMINFO_HWACCELERATION_NOT_USE_GL;
5152                 else if (strcasecmp(val, "use-GL") == 0)
5153                         *hwacceleration = PMINFO_HWACCELERATION_USE_GL;
5154                 else
5155                         *hwacceleration = PMINFO_HWACCELERATION_USE_SYSTEM_SETTING;
5156         }
5157         return PMINFO_R_OK;
5158 }
5159
5160 API int pkgmgrinfo_appinfo_is_onboot(pkgmgrinfo_appinfo_h  handle, bool *onboot)
5161 {
5162         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5163         retvm_if(onboot == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5164         char *val = NULL;
5165         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5166         val = (char *)info->svcapp_info->onboot;
5167         if (val) {
5168                 if (strcasecmp(val, "true") == 0)
5169                         *onboot = 1;
5170                 else if (strcasecmp(val, "false") == 0)
5171                         *onboot = 0;
5172                 else
5173                         *onboot = 0;
5174         }
5175         return PMINFO_R_OK;
5176 }
5177
5178 API int pkgmgrinfo_appinfo_is_autorestart(pkgmgrinfo_appinfo_h  handle, bool *autorestart)
5179 {
5180         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5181         retvm_if(autorestart == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5182         char *val = NULL;
5183         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5184         val = (char *)info->svcapp_info->autorestart;
5185         if (val) {
5186                 if (strcasecmp(val, "true") == 0)
5187                         *autorestart = 1;
5188                 else if (strcasecmp(val, "false") == 0)
5189                         *autorestart = 0;
5190                 else
5191                         *autorestart = 0;
5192         }
5193         return PMINFO_R_OK;
5194 }
5195
5196 API int pkgmgrinfo_appinfo_is_mainapp(pkgmgrinfo_appinfo_h  handle, bool *mainapp)
5197 {
5198         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5199         retvm_if(mainapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5200         char *val = NULL;
5201         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5202         val = (char *)info->uiapp_info->mainapp;
5203         if (val) {
5204                 if (strcasecmp(val, "true") == 0)
5205                         *mainapp = 1;
5206                 else if (strcasecmp(val, "false") == 0)
5207                         *mainapp = 0;
5208                 else
5209                         *mainapp = 0;
5210         }
5211         return PMINFO_R_OK;
5212 }
5213
5214 API int pkgmgrinfo_appinfo_destroy_appinfo(pkgmgrinfo_appinfo_h  handle)
5215 {
5216         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5217         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5218         __cleanup_appinfo(info);
5219         return PMINFO_R_OK;
5220 }
5221
5222 API int pkgmgrinfo_appinfo_filter_create(pkgmgrinfo_appinfo_filter_h *handle)
5223 {
5224         return (pkgmgrinfo_pkginfo_filter_create(handle));
5225 }
5226
5227 API int pkgmgrinfo_appinfo_filter_destroy(pkgmgrinfo_appinfo_filter_h handle)
5228 {
5229         return (pkgmgrinfo_pkginfo_filter_destroy(handle));
5230 }
5231
5232 API int pkgmgrinfo_appinfo_filter_add_int(pkgmgrinfo_appinfo_filter_h handle,
5233                                 const char *property, const int value)
5234 {
5235         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5236         retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5237         char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
5238         char *val = NULL;
5239         GSList *link = NULL;
5240         int prop = -1;
5241         prop = _pminfo_appinfo_convert_to_prop_int(property);
5242         if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_INT ||
5243                 prop > E_PMINFO_APPINFO_PROP_APP_MAX_INT) {
5244                 _LOGE("Invalid Integer Property\n");
5245                 return PMINFO_R_EINVAL;
5246         }
5247         pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5248         pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
5249         if (node == NULL) {
5250                 _LOGE("Out of Memory!!!\n");
5251                 return PMINFO_R_ERROR;
5252         }
5253         snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
5254         val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
5255         if (val == NULL) {
5256                 _LOGE("Out of Memory\n");
5257                 free(node);
5258                 node = NULL;
5259                 return PMINFO_R_ERROR;
5260         }
5261         node->prop = prop;
5262         node->value = val;
5263         /*If API is called multiple times for same property, we should override the previous values.
5264         Last value set will be used for filtering.*/
5265         link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
5266         if (link)
5267                 filter->list = g_slist_delete_link(filter->list, link);
5268         filter->list = g_slist_append(filter->list, (gpointer)node);
5269         return PMINFO_R_OK;
5270
5271 }
5272
5273 API int pkgmgrinfo_appinfo_filter_add_bool(pkgmgrinfo_appinfo_filter_h handle,
5274                                 const char *property, const bool value)
5275 {
5276         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5277         retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5278         char *val = NULL;
5279         GSList *link = NULL;
5280         int prop = -1;
5281         prop = _pminfo_appinfo_convert_to_prop_bool(property);
5282         if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_BOOL ||
5283                 prop > E_PMINFO_APPINFO_PROP_APP_MAX_BOOL) {
5284                 _LOGE("Invalid Boolean Property\n");
5285                 return PMINFO_R_EINVAL;
5286         }
5287         pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5288         pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
5289         if (node == NULL) {
5290                 _LOGE("Out of Memory!!!\n");
5291                 return PMINFO_R_ERROR;
5292         }
5293         if (value)
5294                 val = strndup("('true','True')", 15);
5295         else
5296                 val = strndup("('false','False')", 17);
5297         if (val == NULL) {
5298                 _LOGE("Out of Memory\n");
5299                 free(node);
5300                 node = NULL;
5301                 return PMINFO_R_ERROR;
5302         }
5303         node->prop = prop;
5304         node->value = val;
5305         /*If API is called multiple times for same property, we should override the previous values.
5306         Last value set will be used for filtering.*/
5307         link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
5308         if (link)
5309                 filter->list = g_slist_delete_link(filter->list, link);
5310         filter->list = g_slist_append(filter->list, (gpointer)node);
5311         return PMINFO_R_OK;
5312
5313 }
5314
5315 API int pkgmgrinfo_appinfo_filter_add_string(pkgmgrinfo_appinfo_filter_h handle,
5316                                 const char *property, const char *value)
5317 {
5318         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5319         retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5320         retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5321         char *val = NULL;
5322         pkgmgrinfo_node_x *ptr = NULL;
5323         char prev[PKG_STRING_LEN_MAX] = {'\0'};
5324         char temp[PKG_STRING_LEN_MAX] = {'\0'};
5325         GSList *link = NULL;
5326         int prop = -1;
5327         prop = _pminfo_appinfo_convert_to_prop_str(property);
5328         if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_STR ||
5329                 prop > E_PMINFO_APPINFO_PROP_APP_MAX_STR) {
5330                 _LOGE("Invalid String Property\n");
5331                 return PMINFO_R_EINVAL;
5332         }
5333         pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5334         pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
5335         if (node == NULL) {
5336                 _LOGE("Out of Memory!!!\n");
5337                 return PMINFO_R_ERROR;
5338         }
5339         node->prop = prop;
5340         switch (prop) {
5341         case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
5342                 if (strcmp(value, PMINFO_APPINFO_UI_APP) == 0)
5343                         val = strndup("uiapp", PKG_STRING_LEN_MAX - 1);
5344                 else
5345                         val = strndup("svcapp", PKG_STRING_LEN_MAX - 1);
5346                 node->value = val;
5347                 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
5348                 if (link)
5349                         filter->list = g_slist_delete_link(filter->list, link);
5350                 filter->list = g_slist_append(filter->list, (gpointer)node);
5351                 break;
5352         case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
5353         case E_PMINFO_APPINFO_PROP_APP_OPERATION:
5354         case E_PMINFO_APPINFO_PROP_APP_URI:
5355         case E_PMINFO_APPINFO_PROP_APP_MIME:
5356                 val = (char *)calloc(1, PKG_STRING_LEN_MAX);
5357                 if (val == NULL) {
5358                         _LOGE("Out of Memory\n");
5359                         free(node);
5360                         node = NULL;
5361                         return PMINFO_R_ERROR;
5362                 }
5363                 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
5364                 if (link) {
5365                         ptr = (pkgmgrinfo_node_x *)link->data;
5366                         strncpy(prev, ptr->value, PKG_STRING_LEN_MAX - 1);
5367                         _LOGE("Previous value is %s\n", prev);
5368                         filter->list = g_slist_delete_link(filter->list, link);
5369                         snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s , '%s'", prev, value);
5370                         strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
5371                         _LOGE("New value is %s\n", val);
5372                         node->value = val;
5373                         filter->list = g_slist_append(filter->list, (gpointer)node);
5374                         memset(temp, '\0', PKG_STRING_LEN_MAX);
5375                 } else {
5376                         snprintf(temp, PKG_STRING_LEN_MAX - 1, "'%s'", value);
5377                         strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
5378                         _LOGE("First value is %s\n", val);
5379                         node->value = val;
5380                         filter->list = g_slist_append(filter->list, (gpointer)node);
5381                         memset(temp, '\0', PKG_STRING_LEN_MAX);
5382                 }
5383                 break;
5384         default:
5385                 node->value = strndup(value, PKG_STRING_LEN_MAX - 1);
5386                 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
5387                 if (link)
5388                         filter->list = g_slist_delete_link(filter->list, link);
5389                 filter->list = g_slist_append(filter->list, (gpointer)node);
5390                 break;
5391         }
5392         return PMINFO_R_OK;
5393 }
5394
5395 API int pkgmgrinfo_appinfo_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count)
5396 {
5397         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5398         retvm_if(count == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5399         char *syslocale = NULL;
5400         char *locale = NULL;
5401         char *condition = NULL;
5402         char *error_message = NULL;
5403         char query[MAX_QUERY_LEN] = {'\0'};
5404         char where[MAX_QUERY_LEN] = {'\0'};
5405         GSList *list;
5406         int ret = 0;
5407
5408         pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5409         /*Get current locale*/
5410         syslocale = vconf_get_str(VCONFKEY_LANGSET);
5411         if (syslocale == NULL) {
5412                 _LOGE("current locale is NULL\n");
5413                 return PMINFO_R_ERROR;
5414         }
5415         locale = __convert_system_locale_to_manifest_locale(syslocale);
5416         if (locale == NULL) {
5417                 _LOGE("manifest locale is NULL\n");
5418                 free(syslocale);
5419                 return PMINFO_R_ERROR;
5420         }
5421
5422         ret = __open_manifest_db();
5423         if (ret == -1) {
5424                 _LOGE("Fail to open manifest DB\n");
5425                 ret = PMINFO_R_ERROR;
5426                 goto err;
5427         }
5428
5429         /*Start constructing query*/
5430         snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_COUNT_APP, locale);
5431
5432         /*Get where clause*/
5433         for (list = filter->list; list; list = g_slist_next(list)) {
5434                 __get_filter_condition(list->data, &condition);
5435                 if (condition) {
5436                         strncat(where, condition, sizeof(where) - strlen(where) -1);
5437                         where[sizeof(where) - 1] = '\0';
5438                         free(condition);
5439                         condition = NULL;
5440                 }
5441                 if (g_slist_next(list)) {
5442                         strncat(where, " and ", sizeof(where) - strlen(where) - 1);
5443                         where[sizeof(where) - 1] = '\0';
5444                 }
5445         }
5446         _LOGE("where = %s\n", where);
5447         if (strlen(where) > 0) {
5448                 strncat(query, where, sizeof(query) - strlen(query) - 1);
5449                 query[sizeof(query) - 1] = '\0';
5450         }
5451         _LOGE("query = %s\n", query);
5452
5453         /*Execute Query*/
5454         if (SQLITE_OK !=
5455             sqlite3_exec(manifest_db, query, __count_cb, (void *)count, &error_message)) {
5456                 _LOGE("Don't execute query = %s error message = %s\n", query,
5457                        error_message);
5458                 sqlite3_free(error_message);
5459                 sqlite3_close(manifest_db);
5460                 ret = PMINFO_R_ERROR;
5461                 *count = 0;
5462                 goto err;
5463         }
5464         ret = PMINFO_R_OK;
5465 err:
5466         if (locale) {
5467                 free(locale);
5468                 locale = NULL;
5469         }
5470         if (syslocale) {
5471                 free(syslocale);
5472                 syslocale = NULL;
5473         }
5474         sqlite3_close(manifest_db);
5475         return ret;
5476 }
5477
5478 API int pkgmgrinfo_appinfo_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h handle,
5479                                 pkgmgrinfo_app_list_cb app_cb, void * user_data)
5480 {
5481         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5482         retvm_if(app_cb == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5483         char *syslocale = NULL;
5484         char *locale = NULL;
5485         char *condition = NULL;
5486         char *error_message = NULL;
5487         char query[MAX_QUERY_LEN] = {'\0'};
5488         char where[MAX_QUERY_LEN] = {'\0'};
5489         GSList *list;
5490         int ret = 0;
5491         uiapplication_x *ptr1 = NULL;
5492         serviceapplication_x *ptr2 = NULL;
5493         pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5494         /*Get current locale*/
5495         syslocale = vconf_get_str(VCONFKEY_LANGSET);
5496         if (syslocale == NULL) {
5497                 _LOGE("current locale is NULL\n");
5498                 return PMINFO_R_ERROR;
5499         }
5500         locale = __convert_system_locale_to_manifest_locale(syslocale);
5501         if (locale == NULL) {
5502                 _LOGE("manifest locale is NULL\n");
5503                 free(syslocale);
5504                 return PMINFO_R_ERROR;
5505         }
5506
5507         ret = __open_manifest_db();
5508         if (ret == -1) {
5509                 _LOGE("Fail to open manifest DB\n");
5510                 ret = PMINFO_R_ERROR;
5511                 goto err;
5512         }
5513         /*Start constructing query*/
5514         snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_LIST_APP, locale);
5515         /*Get where clause*/
5516         for (list = filter->list; list; list = g_slist_next(list)) {
5517                 __get_filter_condition(list->data, &condition);
5518                 if (condition) {
5519                         strncat(where, condition, sizeof(where) - strlen(where) -1);
5520                         where[sizeof(where) - 1] = '\0';
5521                         free(condition);
5522                         condition = NULL;
5523                 }
5524                 if (g_slist_next(list)) {
5525                         strncat(where, " and ", sizeof(where) - strlen(where) - 1);
5526                         where[sizeof(where) - 1] = '\0';
5527                 }
5528         }
5529         _LOGE("where = %s\n", where);
5530         if (strlen(where) > 0) {
5531                 strncat(query, where, sizeof(query) - strlen(query) - 1);
5532                 query[sizeof(query) - 1] = '\0';
5533         }
5534         _LOGE("query = %s\n", query);
5535         /*To get filtered list*/
5536         pkgmgr_pkginfo_x *info = NULL;
5537         info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
5538         if (info == NULL) {
5539                 _LOGE("Out of Memory!!!\n");
5540                 ret = PMINFO_R_ERROR;
5541                 goto err;
5542         }
5543         info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
5544         if (info->manifest_info == NULL) {
5545                 _LOGE("Out of Memory!!!\n");
5546                 ret = PMINFO_R_ERROR;
5547                 goto err;
5548         }
5549         /*To get detail app info for each member of filtered list*/
5550         pkgmgr_pkginfo_x *filtinfo = NULL;
5551         filtinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
5552         if (filtinfo == NULL) {
5553                 _LOGE("Out of Memory!!!\n");
5554                 ret = PMINFO_R_ERROR;
5555                 goto err;
5556         }
5557         filtinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
5558         if (filtinfo->manifest_info == NULL) {
5559                 _LOGE("Out of Memory!!!\n");
5560                 ret = PMINFO_R_ERROR;
5561                 goto err;
5562         }
5563         pkgmgr_appinfo_x *appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
5564         if (appinfo == NULL) {
5565                 _LOGE("Out of Memory!!!\n");
5566                 ret = PMINFO_R_ERROR;
5567                 goto err;
5568         }
5569         if (SQLITE_OK !=
5570             sqlite3_exec(manifest_db, query, __app_list_cb, (void *)info, &error_message)) {
5571                 _LOGE("Don't execute query = %s error message = %s\n", query,
5572                        error_message);
5573                 sqlite3_free(error_message);
5574                 sqlite3_close(manifest_db);
5575                 ret = PMINFO_R_ERROR;
5576                 goto err;
5577         }
5578         memset(query, '\0', MAX_QUERY_LEN);
5579         if (info->manifest_info->uiapplication) {
5580                 LISTHEAD(info->manifest_info->uiapplication, ptr1);
5581                 info->manifest_info->uiapplication = ptr1;
5582         }
5583         if (info->manifest_info->serviceapplication) {
5584                 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
5585                 info->manifest_info->serviceapplication = ptr2;
5586         }
5587         /*Filtered UI Apps*/
5588         for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
5589         {
5590                 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
5591                                                         ptr1->appid, "uiapp");
5592                 if (SQLITE_OK !=
5593                 sqlite3_exec(manifest_db, query, __uiapp_list_cb, (void *)filtinfo, &error_message)) {
5594                         _LOGE("Don't execute query = %s error message = %s\n", query,
5595                                error_message);
5596                         sqlite3_free(error_message);
5597                         sqlite3_close(manifest_db);
5598                         ret = PMINFO_R_ERROR;
5599                         goto err;
5600                 }
5601         }
5602         for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
5603         {
5604                 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
5605                                                         ptr2->appid, "svcapp");
5606                 if (SQLITE_OK !=
5607                 sqlite3_exec(manifest_db, query, __svcapp_list_cb, (void *)filtinfo, &error_message)) {
5608                         _LOGE("Don't execute query = %s error message = %s\n", query,
5609                                error_message);
5610                         sqlite3_free(error_message);
5611                         sqlite3_close(manifest_db);
5612                         ret = PMINFO_R_ERROR;
5613                         goto err;
5614                 }
5615         }
5616         if (filtinfo->manifest_info->uiapplication) {
5617                 LISTHEAD(filtinfo->manifest_info->uiapplication, ptr1);
5618                 filtinfo->manifest_info->uiapplication = ptr1;
5619         }
5620         /*If the callback func return < 0 we break and no more call back is called*/
5621         while(ptr1 != NULL)
5622         {
5623                 appinfo->locale = strdup(locale);
5624                 appinfo->uiapp_info = ptr1;
5625                 appinfo->app_component = PMINFO_UI_APP;
5626                 ret = app_cb((void *)appinfo, user_data);
5627                 if (ret < 0)
5628                         break;
5629                 ptr1 = ptr1->next;
5630         }
5631         /*Filtered Service Apps*/
5632         if (filtinfo->manifest_info->serviceapplication) {
5633                 LISTHEAD(filtinfo->manifest_info->serviceapplication, ptr2);
5634                 filtinfo->manifest_info->serviceapplication = ptr2;
5635         }
5636         /*If the callback func return < 0 we break and no more call back is called*/
5637         while(ptr2 != NULL)
5638         {
5639                 appinfo->locale = strdup(locale);
5640                 appinfo->svcapp_info = ptr2;
5641                 appinfo->app_component = PMINFO_SVC_APP;
5642                 ret = app_cb((void *)appinfo, user_data);
5643                 if (ret < 0)
5644                         break;
5645                 ptr2 = ptr2->next;
5646         }
5647         ret = PMINFO_R_OK;
5648 err:
5649         if (locale) {
5650                 free(locale);
5651                 locale = NULL;
5652         }
5653         if (syslocale) {
5654                 free(syslocale);
5655                 syslocale = NULL;
5656         }
5657         sqlite3_close(manifest_db);
5658         if (appinfo) {
5659                 free(appinfo);
5660                 appinfo = NULL;
5661         }
5662         __cleanup_pkginfo(info);
5663         __cleanup_pkginfo(filtinfo);
5664         return ret;
5665 }
5666
5667 API int pkgmgrinfo_appinfo_metadata_filter_create(pkgmgrinfo_appinfo_metadata_filter_h *handle)
5668 {
5669         return (pkgmgrinfo_pkginfo_filter_create(handle));
5670 }
5671
5672 API int pkgmgrinfo_appinfo_metadata_filter_destroy(pkgmgrinfo_appinfo_metadata_filter_h handle)
5673 {
5674         return (pkgmgrinfo_pkginfo_filter_destroy(handle));
5675 }
5676
5677 API int pkgmgrinfo_appinfo_metadata_filter_add(pkgmgrinfo_appinfo_metadata_filter_h handle,
5678                 const char *key, const char *value)
5679 {
5680         retvm_if(handle == NULL, PMINFO_R_EINVAL, "filter handle is NULL\n");
5681         retvm_if(key == NULL, PMINFO_R_EINVAL, "metadata key supplied is NULL\n");
5682         /*value can be NULL. In that case all apps with specified key should be displayed*/
5683         int ret = 0;
5684         char *k = NULL;
5685         char *v = NULL;
5686         pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5687         pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
5688         retvm_if(node == NULL, PMINFO_R_ERROR, "Out of Memory!!!\n");
5689         k = strdup(key);
5690         tryvm_if(k == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5691         node->key = k;
5692         if (value) {
5693                 v = strdup(value);
5694                 tryvm_if(v == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5695         }
5696         node->value = v;
5697         /*If API is called multiple times, we should OR all conditions.*/
5698         filter->list = g_slist_append(filter->list, (gpointer)node);
5699         /*All memory will be freed in destroy API*/
5700         return PMINFO_R_OK;
5701 catch:
5702         if (node) {
5703                 if (node->key) {
5704                         free(node->key);
5705                         node->key = NULL;
5706                 }
5707                 if (node->value) {
5708                         free(node->value);
5709                         node->value = NULL;
5710                 }
5711                 free(node);
5712                 node = NULL;
5713         }
5714         return ret;
5715 }
5716
5717 API int pkgmgrinfo_appinfo_metadata_filter_foreach(pkgmgrinfo_appinfo_metadata_filter_h handle,
5718                 pkgmgrinfo_app_list_cb app_cb, void *user_data)
5719 {
5720         retvm_if(handle == NULL, PMINFO_R_EINVAL, "filter handle is NULL\n");
5721         retvm_if(app_cb == NULL, PMINFO_R_EINVAL, "Callback function supplied is NULL\n");
5722         char *syslocale = NULL;
5723         char *locale = NULL;
5724         char *condition = NULL;
5725         char *error_message = NULL;
5726         char query[MAX_QUERY_LEN] = {'\0'};
5727         char where[MAX_QUERY_LEN] = {'\0'};
5728         GSList *list;
5729         int ret = 0;
5730         pkgmgr_pkginfo_x *info = NULL;
5731         pkgmgr_pkginfo_x *filtinfo = NULL;
5732         pkgmgr_appinfo_x *appinfo = NULL;
5733         uiapplication_x *ptr1 = NULL;
5734         serviceapplication_x *ptr2 = NULL;
5735         pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5736
5737         /*Get current locale*/
5738         syslocale = vconf_get_str(VCONFKEY_LANGSET);
5739         retvm_if(syslocale == NULL, PMINFO_R_ERROR, "current locale is NULL\n");
5740         locale = __convert_system_locale_to_manifest_locale(syslocale);
5741         tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL\n");
5742
5743         ret = __open_manifest_db();
5744         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Fail to open manifest DB\n");
5745
5746         /*Start constructing query*/
5747         memset(where, '\0', MAX_QUERY_LEN);
5748         memset(query, '\0', MAX_QUERY_LEN);
5749         snprintf(query, MAX_QUERY_LEN - 1, METADATA_FILTER_QUERY_SELECT_CLAUSE);
5750         /*Get where clause*/
5751         for (list = filter->list; list; list = g_slist_next(list)) {
5752                 __get_metadata_filter_condition(list->data, &condition);
5753                 if (condition) {
5754                         strncat(where, condition, sizeof(where) - strlen(where) -1);
5755                         free(condition);
5756                         condition = NULL;
5757                 }
5758                 if (g_slist_next(list)) {
5759                         strncat(where, METADATA_FILTER_QUERY_UNION_CLAUSE, sizeof(where) - strlen(where) - 1);
5760                 }
5761         }
5762         _LOGE("where = %s (%d)\n", where, strlen(where));
5763         if (strlen(where) > 0) {
5764                 strncat(query, where, sizeof(query) - strlen(query) - 1);
5765         }
5766         _LOGE("query = %s (%d)\n", query, strlen(query));
5767         /*To get filtered list*/
5768         info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
5769         tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5770
5771         info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
5772         tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5773
5774         /*To get detail app info for each member of filtered list*/
5775         filtinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
5776         tryvm_if(filtinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5777
5778         filtinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
5779         tryvm_if(filtinfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5780
5781         appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
5782         tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5783
5784         ret = sqlite3_exec(manifest_db, query, __app_list_cb, (void *)info, &error_message);
5785         tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
5786         memset(query, '\0', MAX_QUERY_LEN);
5787
5788         if (info->manifest_info->uiapplication) {
5789                 LISTHEAD(info->manifest_info->uiapplication, ptr1);
5790                 info->manifest_info->uiapplication = ptr1;
5791         }
5792         if (info->manifest_info->serviceapplication) {
5793                 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
5794                 info->manifest_info->serviceapplication = ptr2;
5795         }
5796
5797         /*UI Apps*/
5798         for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
5799         {
5800                 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
5801                                                         ptr1->appid, "uiapp");
5802                 ret = sqlite3_exec(manifest_db, query, __uiapp_list_cb, (void *)filtinfo, &error_message);
5803                 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
5804                 memset(query, '\0', MAX_QUERY_LEN);
5805         }
5806         /*Service Apps*/
5807         for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
5808         {
5809                 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
5810                                                         ptr2->appid, "svcapp");
5811                 ret = sqlite3_exec(manifest_db, query, __svcapp_list_cb, (void *)filtinfo, &error_message);
5812                 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
5813                 memset(query, '\0', MAX_QUERY_LEN);
5814         }
5815         /*Filtered UI Apps*/
5816         if (filtinfo->manifest_info->uiapplication) {
5817                 LISTHEAD(filtinfo->manifest_info->uiapplication, ptr1);
5818                 filtinfo->manifest_info->uiapplication = ptr1;
5819         }
5820         /*If the callback func return < 0 we break and no more call back is called*/
5821         while(ptr1 != NULL)
5822         {
5823                 appinfo->locale = strdup(locale);
5824                 appinfo->uiapp_info = ptr1;
5825                 appinfo->app_component = PMINFO_UI_APP;
5826                 ret = app_cb((void *)appinfo, user_data);
5827                 if (ret < 0)
5828                         break;
5829                 ptr1 = ptr1->next;
5830         }
5831         /*Filtered Service Apps*/
5832         if (filtinfo->manifest_info->serviceapplication) {
5833                 LISTHEAD(filtinfo->manifest_info->serviceapplication, ptr2);
5834                 filtinfo->manifest_info->serviceapplication = ptr2;
5835         }
5836         /*If the callback func return < 0 we break and no more call back is called*/
5837         while(ptr2 != NULL)
5838         {
5839                 appinfo->locale = strdup(locale);
5840                 appinfo->svcapp_info = ptr2;
5841                 appinfo->app_component = PMINFO_SVC_APP;
5842                 ret = app_cb((void *)appinfo, user_data);
5843                 if (ret < 0)
5844                         break;
5845                 ptr2 = ptr2->next;
5846         }
5847         ret = PMINFO_R_OK;
5848 catch:
5849         if (locale) {
5850                 free(locale);
5851                 locale = NULL;
5852         }
5853         if (syslocale) {
5854                 free(syslocale);
5855                 syslocale = NULL;
5856         }
5857         sqlite3_free(error_message);
5858         sqlite3_close(manifest_db);
5859         if (appinfo) {
5860                 free(appinfo);
5861                 appinfo = NULL;
5862         }
5863         __cleanup_pkginfo(info);
5864         __cleanup_pkginfo(filtinfo);
5865         return ret;
5866 }
5867
5868 API int pkgmgrinfo_pkginfo_create_certinfo(pkgmgrinfo_certinfo_h *handle)
5869 {
5870         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5871         pkgmgr_certinfo_x *certinfo = NULL;
5872         certinfo = calloc(1, sizeof(pkgmgr_certinfo_x));
5873         retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
5874         *handle = (void *)certinfo;
5875         return PMINFO_R_OK;
5876 }
5877
5878 API int pkgmgrinfo_pkginfo_load_certinfo(const char *pkgid, pkgmgrinfo_certinfo_h handle)
5879 {
5880         retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "package ID is NULL\n");
5881         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Certinfo handle is NULL\n");
5882         pkgmgr_certinfo_x *certinfo = NULL;
5883         char *error_message = NULL;
5884         int ret = PMINFO_R_OK;
5885         char query[MAX_QUERY_LEN] = {'\0'};
5886         int exist = 0;
5887         int i = 0;
5888
5889         /*Open db.*/
5890         ret = db_util_open_with_options(CERT_DB, &cert_db,
5891                                         SQLITE_OPEN_READONLY, NULL);
5892         if (ret != SQLITE_OK) {
5893                 _LOGE("connect db [%s] failed!\n", CERT_DB);
5894                 return PMINFO_R_ERROR;
5895         }
5896         /*validate pkgid*/
5897         snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", pkgid);
5898         if (SQLITE_OK !=
5899             sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
5900                 _LOGE("Don't execute query = %s error message = %s\n", query,
5901                        error_message);
5902                 sqlite3_free(error_message);
5903                 ret = PMINFO_R_ERROR;
5904                 goto err;
5905         }
5906         if (exist == 0) {
5907                 _LOGE("Package not found in DB\n");
5908                 ret = PMINFO_R_ERROR;
5909                 goto err;
5910         }
5911         certinfo = (pkgmgr_certinfo_x *)handle;
5912         /*populate certinfo from DB*/
5913         snprintf(query, MAX_QUERY_LEN, "select * from package_cert_info where package='%s' ", pkgid);
5914         ret = __exec_certinfo_query(query, (void *)certinfo);
5915         if (ret == -1) {
5916                 _LOGE("Package Cert Info DB Information retrieval failed\n");
5917                 ret = PMINFO_R_ERROR;
5918                 goto err;
5919         }
5920         for (i = 0; i < MAX_CERT_TYPE; i++) {
5921                 memset(query, '\0', MAX_QUERY_LEN);
5922                 snprintf(query, MAX_QUERY_LEN, "select cert_info from package_cert_index_info where cert_id=%d ", (certinfo->cert_id)[i]);
5923                 ret = __exec_certinfo_query(query, (void *)certinfo);
5924                 if (ret == -1) {
5925                         _LOGE("Cert Info DB Information retrieval failed\n");
5926                         ret = PMINFO_R_ERROR;
5927                         goto err;
5928                 }
5929                 if (certinfo->cert_value) {
5930                         (certinfo->cert_info)[i] = strdup(certinfo->cert_value);
5931                         free(certinfo->cert_value);
5932                         certinfo->cert_value = NULL;
5933                 }
5934         }
5935 err:
5936         sqlite3_close(cert_db);
5937         return ret;
5938 }
5939
5940 API int pkgmgrinfo_pkginfo_get_cert_value(pkgmgrinfo_certinfo_h handle, pkgmgrinfo_cert_type cert_type, const char **cert_value)
5941 {
5942         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
5943         retvm_if(cert_value == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
5944         retvm_if(cert_type < PMINFO_AUTHOR_ROOT_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
5945         retvm_if(cert_type > PMINFO_DISTRIBUTOR2_SIGNER_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
5946         pkgmgr_certinfo_x *certinfo = NULL;
5947         certinfo = (pkgmgr_certinfo_x *)handle;
5948         if ((certinfo->cert_info)[cert_type])
5949                 *cert_value = (certinfo->cert_info)[cert_type];
5950         else
5951                 *cert_value = NULL;
5952         return PMINFO_R_OK;
5953 }
5954
5955 API int pkgmgrinfo_pkginfo_destroy_certinfo(pkgmgrinfo_certinfo_h handle)
5956 {
5957         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
5958         int i = 0;
5959         pkgmgr_certinfo_x *certinfo = NULL;
5960         certinfo = (pkgmgr_certinfo_x *)handle;
5961         if (certinfo->pkgid) {
5962                 free(certinfo->pkgid);
5963                 certinfo->pkgid = NULL;
5964         }
5965         for (i = 0; i < MAX_CERT_TYPE; i++) {
5966                 if ((certinfo->cert_info)[i]) {
5967                         free((certinfo->cert_info)[i]);
5968                         (certinfo->cert_info)[i] = NULL;
5969                 }
5970         }
5971         free(certinfo);
5972         certinfo = NULL;
5973         return PMINFO_R_OK;
5974 }
5975
5976 API int pkgmgrinfo_create_certinfo_set_handle(pkgmgrinfo_instcertinfo_h *handle)
5977 {
5978         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5979         pkgmgr_instcertinfo_x *certinfo = NULL;
5980         certinfo = calloc(1, sizeof(pkgmgr_instcertinfo_x));
5981         retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
5982         *handle = (void *)certinfo;
5983         return PMINFO_R_OK;
5984 }
5985
5986 API int pkgmgrinfo_set_cert_value(pkgmgrinfo_instcertinfo_h handle, pkgmgrinfo_instcert_type cert_type, char *cert_value)
5987 {
5988         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
5989         retvm_if(cert_value == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
5990         retvm_if(cert_type < PMINFO_SET_AUTHOR_ROOT_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
5991         retvm_if(cert_type > PMINFO_SET_DISTRIBUTOR2_SIGNER_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
5992         pkgmgr_instcertinfo_x *certinfo = NULL;
5993         certinfo = (pkgmgr_instcertinfo_x *)handle;
5994         (certinfo->cert_info)[cert_type] = strdup(cert_value);
5995         return PMINFO_R_OK;
5996 }
5997
5998 API int pkgmgrinfo_save_certinfo(const char *pkgid, pkgmgrinfo_instcertinfo_h handle)
5999 {
6000         retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "package ID is NULL\n");
6001         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Certinfo handle is NULL\n");
6002         char *error_message = NULL;
6003         char query[MAX_QUERY_LEN] = {'\0'};
6004         char *vquery = NULL;
6005         int len = 0;
6006         int i = 0;
6007         int j = 0;
6008         int c = 0;
6009         int unique_id[MAX_CERT_TYPE] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
6010         int newid = 0;
6011         int is_new = 0;
6012         int exist = -1;
6013         int ret = -1;
6014         int maxid = 0;
6015         int flag = 0;
6016         pkgmgr_instcertinfo_x *info = (pkgmgr_instcertinfo_x *)handle;
6017         pkgmgr_certindexinfo_x *indexinfo = NULL;
6018         indexinfo = calloc(1, sizeof(pkgmgr_certindexinfo_x));
6019         if (indexinfo == NULL) {
6020                 _LOGE("Out of Memory!!!");
6021                 return PMINFO_R_ERROR;
6022         }
6023         info->pkgid = strdup(pkgid);
6024
6025         /*Open db.*/
6026         ret = db_util_open_with_options(CERT_DB, &cert_db,
6027                                         SQLITE_OPEN_READWRITE, NULL);
6028         if (ret != SQLITE_OK) {
6029                 _LOGE("connect db [%s] failed!\n", CERT_DB);
6030                 ret = PMINFO_R_ERROR;
6031                 goto err;
6032         }
6033         /*Begin Transaction*/
6034         ret = sqlite3_exec(cert_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
6035         if (ret != SQLITE_OK) {
6036                 _LOGE("Failed to begin transaction\n");
6037                 ret = PMINFO_R_ERROR;
6038                 goto err;
6039         }
6040         _LOGE("Transaction Begin\n");
6041         /*Check if request is to insert/update*/
6042         snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", pkgid);
6043         if (SQLITE_OK !=
6044             sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
6045                 _LOGE("Don't execute query = %s error message = %s\n", query,
6046                        error_message);
6047                 sqlite3_free(error_message);
6048                 ret = PMINFO_R_ERROR;
6049                 goto err;
6050         }
6051         if (exist) {
6052                 /*Update request.
6053                 We cant just issue update query directly. We need to manage index table also.
6054                 Hence it is better to delete and insert again in case of update*/
6055                 ret = __delete_certinfo(pkgid);
6056                 if (ret < 0)
6057                         _LOGE("Certificate Deletion Failed\n");
6058         }
6059         for (i = 0; i < MAX_CERT_TYPE; i++) {
6060                 if ((info->cert_info)[i]) {
6061                         for (j = 0; j < i; j++) {
6062                                 if ( (info->cert_info)[j]) {
6063                                         if (strcmp((info->cert_info)[i], (info->cert_info)[j]) == 0) {
6064                                                 (info->cert_id)[i] = (info->cert_id)[j];
6065                                                 (info->is_new)[i] = 0;
6066                                                 (info->ref_count)[i] = (info->ref_count)[j];
6067                                                 break;
6068                                         }
6069                                 }
6070                         }
6071                         if (j < i)
6072                                 continue;
6073                         memset(query, '\0', MAX_QUERY_LEN);
6074                         snprintf(query, MAX_QUERY_LEN, "select * from package_cert_index_info " \
6075                                 "where cert_info='%s'",(info->cert_info)[i]);
6076                         ret = __exec_certindexinfo_query(query, (void *)indexinfo);
6077                         if (ret == -1) {
6078                                 _LOGE("Cert Info DB Information retrieval failed\n");
6079                                 ret = PMINFO_R_ERROR;
6080                                 goto err;
6081                         }
6082                         if (indexinfo->cert_id == 0) {
6083                                 /*New certificate. Get newid*/
6084                                 memset(query, '\0', MAX_QUERY_LEN);
6085                                 snprintf(query, MAX_QUERY_LEN, "select MAX(cert_id) from package_cert_index_info ");
6086                                 if (SQLITE_OK !=
6087                                     sqlite3_exec(cert_db, query, __maxid_cb, (void *)&newid, &error_message)) {
6088                                         _LOGE("Don't execute query = %s error message = %s\n", query,
6089                                                error_message);
6090                                         sqlite3_free(error_message);
6091                                         ret = PMINFO_R_ERROR;
6092                                         goto err;
6093                                 }
6094                                 newid = newid + 1;
6095                                 if (flag == 0) {
6096                                         maxid = newid;
6097                                         flag = 1;
6098                                 }
6099                                 indexinfo->cert_id = maxid;
6100                                 indexinfo->cert_ref_count = 1;
6101                                 is_new = 1;
6102                                 maxid = maxid + 1;
6103                         }
6104                         (info->cert_id)[i] = indexinfo->cert_id;
6105                         (info->is_new)[i] = is_new;
6106                         (info->ref_count)[i] = indexinfo->cert_ref_count;
6107                         _LOGE("Id:Count = %d %d\n", indexinfo->cert_id, indexinfo->cert_ref_count);
6108                         indexinfo->cert_id = 0;
6109                         indexinfo->cert_ref_count = 0;
6110                         is_new = 0;
6111                 }
6112         }
6113         len = MAX_QUERY_LEN;
6114         for (i = 0; i < MAX_CERT_TYPE; i++) {
6115                 if ((info->cert_info)[i])
6116                         len+= strlen((info->cert_info)[i]);
6117         }
6118         vquery = (char *)calloc(1, len);
6119         /*insert*/
6120         snprintf(vquery, len,
6121                  "insert into package_cert_info(package, author_root_cert, author_im_cert, author_signer_cert, dist_root_cert, " \
6122                 "dist_im_cert, dist_signer_cert, dist2_root_cert, dist2_im_cert, dist2_signer_cert) " \
6123                 "values('%s', %d, %d, %d, %d, %d, %d, %d, %d, %d)",\
6124                  info->pkgid,(info->cert_id)[PMINFO_SET_AUTHOR_ROOT_CERT],(info->cert_id)[PMINFO_SET_AUTHOR_INTERMEDIATE_CERT],
6125                 (info->cert_id)[PMINFO_SET_AUTHOR_SIGNER_CERT], (info->cert_id)[PMINFO_SET_DISTRIBUTOR_ROOT_CERT],
6126                 (info->cert_id)[PMINFO_SET_DISTRIBUTOR_INTERMEDIATE_CERT], (info->cert_id)[PMINFO_SET_DISTRIBUTOR_SIGNER_CERT],
6127                 (info->cert_id)[PMINFO_SET_DISTRIBUTOR2_ROOT_CERT],(info->cert_id)[PMINFO_SET_DISTRIBUTOR2_INTERMEDIATE_CERT],
6128                 (info->cert_id)[PMINFO_SET_DISTRIBUTOR2_SIGNER_CERT]);
6129         if (SQLITE_OK !=
6130             sqlite3_exec(cert_db, vquery, NULL, NULL, &error_message)) {
6131                 _LOGE("Don't execute query = %s error message = %s\n", vquery,
6132                        error_message);
6133                 sqlite3_free(error_message);
6134                 ret = PMINFO_R_ERROR;
6135                 goto err;
6136         }
6137         /*Update index table info*/
6138         /*If cert_id exists and is repeated for current package, ref count should only be increased once*/
6139         for (i = 0; i < MAX_CERT_TYPE; i++) {
6140                 if ((info->cert_info)[i]) {
6141                         memset(vquery, '\0', len);
6142                         if ((info->is_new)[i]) {
6143                                 snprintf(vquery, len, "insert into package_cert_index_info(cert_info, cert_id, cert_ref_count) " \
6144                                 "values('%s', '%d', '%d') ", (info->cert_info)[i], (info->cert_id)[i], 1);
6145                                 unique_id[c++] = (info->cert_id)[i];
6146                         } else {
6147                                 /*Update*/
6148                                 for (j = 0; j < MAX_CERT_TYPE; j++) {
6149                                         if ((info->cert_id)[i] == unique_id[j]) {
6150                                                 /*Ref count has already been increased. Just continue*/
6151                                                 break;
6152                                         }
6153                                 }
6154                                 if (j == MAX_CERT_TYPE)
6155                                         unique_id[c++] = (info->cert_id)[i];
6156                                 else
6157                                         continue;
6158                                 snprintf(vquery, len, "update package_cert_index_info set cert_ref_count=%d " \
6159                                 "where cert_id=%d",  (info->ref_count)[i] + 1, (info->cert_id)[i]);
6160                         }
6161                         if (SQLITE_OK !=
6162                             sqlite3_exec(cert_db, vquery, NULL, NULL, &error_message)) {
6163                                 _LOGE("Don't execute query = %s error message = %s\n", vquery,
6164                                        error_message);
6165                                 sqlite3_free(error_message);
6166                                 ret = PMINFO_R_ERROR;
6167                                 goto err;
6168                         }
6169                 }
6170         }
6171         /*Commit transaction*/
6172         ret = sqlite3_exec(cert_db, "COMMIT", NULL, NULL, NULL);
6173         if (ret != SQLITE_OK) {
6174                 _LOGE("Failed to commit transaction, Rollback now\n");
6175                 sqlite3_exec(cert_db, "ROLLBACK", NULL, NULL, NULL);
6176                 ret = PMINFO_R_ERROR;
6177                 goto err;
6178         }
6179         _LOGE("Transaction Commit and End\n");
6180         ret =  PMINFO_R_OK;
6181 err:
6182         sqlite3_close(cert_db);
6183         if (vquery) {
6184                 free(vquery);
6185                 vquery = NULL;
6186         }
6187         if (indexinfo) {
6188                 free(indexinfo);
6189                 indexinfo = NULL;
6190         }
6191         return ret;
6192 }
6193
6194 API int pkgmgrinfo_destroy_certinfo_set_handle(pkgmgrinfo_instcertinfo_h handle)
6195 {
6196         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
6197         int i = 0;
6198         pkgmgr_instcertinfo_x *certinfo = NULL;
6199         certinfo = (pkgmgr_instcertinfo_x *)handle;
6200         if (certinfo->pkgid) {
6201                 free(certinfo->pkgid);
6202                 certinfo->pkgid = NULL;
6203         }
6204         for (i = 0; i < MAX_CERT_TYPE; i++) {
6205                 if ((certinfo->cert_info)[i]) {
6206                         free((certinfo->cert_info)[i]);
6207                         (certinfo->cert_info)[i] = NULL;
6208                 }
6209         }
6210         free(certinfo);
6211         certinfo = NULL;
6212         return PMINFO_R_OK;
6213 }
6214
6215 API int pkgmgrinfo_delete_certinfo(const char *pkgid)
6216 {
6217         retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
6218         int ret = -1;
6219         /*Open db.*/
6220         ret = db_util_open_with_options(CERT_DB, &cert_db,
6221                                         SQLITE_OPEN_READWRITE, NULL);
6222         if (ret != SQLITE_OK) {
6223                 _LOGE("connect db [%s] failed!\n", CERT_DB);
6224                 ret = PMINFO_R_ERROR;
6225                 goto err;
6226         }
6227         /*Begin Transaction*/
6228         ret = sqlite3_exec(cert_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
6229         if (ret != SQLITE_OK) {
6230                 _LOGE("Failed to begin transaction\n");
6231                 ret = PMINFO_R_ERROR;
6232                 goto err;
6233         }
6234         _LOGE("Transaction Begin\n");
6235         ret = __delete_certinfo(pkgid);
6236         if (ret < 0) {
6237                 _LOGE("Certificate Deletion Failed\n");
6238         } else {
6239                 _LOGE("Certificate Deletion Success\n");
6240         }
6241         /*Commit transaction*/
6242         ret = sqlite3_exec(cert_db, "COMMIT", NULL, NULL, NULL);
6243         if (ret != SQLITE_OK) {
6244                 _LOGE("Failed to commit transaction, Rollback now\n");
6245                 sqlite3_exec(cert_db, "ROLLBACK", NULL, NULL, NULL);
6246                 ret = PMINFO_R_ERROR;
6247                 goto err;
6248         }
6249         _LOGE("Transaction Commit and End\n");
6250         ret = PMINFO_R_OK;
6251 err:
6252         sqlite3_close(cert_db);
6253         return ret;
6254 }
6255
6256 API int pkgmgrinfo_create_pkgdbinfo(const char *pkgid, pkgmgrinfo_pkgdbinfo_h *handle)
6257 {
6258         retvm_if(!pkgid, PMINFO_R_EINVAL, "pkgid is NULL");
6259         retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6260
6261         char *manifest = NULL;
6262         manifest_x *mfx = NULL;
6263
6264         manifest = pkgmgr_parser_get_manifest_file(pkgid);
6265         retvm_if(manifest == NULL, PMINFO_R_EINVAL, "pkg[%s] dont have manifest file", pkgid);
6266
6267         mfx = pkgmgr_parser_process_manifest_xml(manifest);
6268         if (manifest) {
6269                 free(manifest);
6270                 manifest = NULL;
6271         }
6272         retvm_if(mfx == NULL, PMINFO_R_EINVAL, "pkg[%s] parsing fail", pkgid);
6273
6274         *handle = (void *)mfx;
6275
6276         return PMINFO_R_OK;
6277 }
6278
6279 API int pkgmgrinfo_set_type_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *type)
6280 {
6281         retvm_if(!type, PMINFO_R_EINVAL, "Argument supplied is NULL");
6282         retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6283
6284         int len = strlen(type);
6285         retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
6286
6287         manifest_x *mfx = (manifest_x *)handle;
6288
6289         mfx->type = strndup(type, PKG_TYPE_STRING_LEN_MAX);
6290         return PMINFO_R_OK;
6291 }
6292
6293 API int pkgmgrinfo_set_version_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *version)
6294 {
6295         retvm_if(!version, PMINFO_R_EINVAL, "Argument supplied is NULL");
6296         retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6297
6298         int len = strlen(version);
6299         retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
6300
6301         manifest_x *mfx = (manifest_x *)handle;
6302
6303         mfx->version = strndup(version, PKG_VERSION_STRING_LEN_MAX);
6304         return PMINFO_R_OK;
6305 }
6306
6307 API int pkgmgrinfo_set_install_location_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, INSTALL_LOCATION location)
6308 {
6309         retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6310         retvm_if((location < 0) || (location > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
6311
6312         manifest_x *mfx = (manifest_x *)handle;
6313
6314         if (location == INSTALL_INTERNAL)
6315                 strcpy(mfx->installlocation, "internal-only");
6316         else if (location == INSTALL_EXTERNAL)
6317                 strcpy(mfx->installlocation, "prefer-external");
6318
6319         return PMINFO_R_OK;
6320 }
6321
6322 API int pkgmgrinfo_set_size_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *size)
6323 {
6324         retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6325         retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL");
6326
6327         manifest_x *mfx = (manifest_x *)handle;
6328
6329         mfx->package_size = strdup(size);
6330
6331         return PMINFO_R_OK;
6332 }
6333
6334 API int pkgmgrinfo_set_label_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *label_txt, const char *locale)
6335 {
6336         retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6337         retvm_if(!label_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
6338
6339         int len = strlen(label_txt);
6340         retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
6341
6342         manifest_x *mfx = (manifest_x *)handle;
6343
6344         label_x *label = calloc(1, sizeof(label_x));
6345         retvm_if(label == NULL, PMINFO_R_EINVAL, "Malloc Failed");
6346
6347         LISTADD(mfx->label, label);
6348         if (locale)
6349                 mfx->label->lang = strdup(locale);
6350         else
6351                 mfx->label->lang = strdup(DEFAULT_LOCALE);
6352         mfx->label->text = strdup(label_txt);
6353
6354         return PMINFO_R_OK;
6355 }
6356
6357 API int pkgmgrinfo_set_icon_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *icon_txt, const char *locale)
6358 {
6359         retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6360         retvm_if(!icon_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
6361
6362         int len = strlen(icon_txt);
6363         retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
6364
6365         manifest_x *mfx = (manifest_x *)handle;
6366
6367         icon_x *icon = calloc(1, sizeof(icon_x));
6368         retvm_if(icon == NULL, PMINFO_R_EINVAL, "Malloc Failed");
6369
6370         LISTADD(mfx->icon, icon);
6371         if (locale)
6372                 mfx->icon->lang = strdup(locale);
6373         else
6374                 mfx->icon->lang = strdup(DEFAULT_LOCALE);
6375         mfx->icon->text = strdup(icon_txt);
6376
6377         return PMINFO_R_OK;
6378 }
6379
6380 API int pkgmgrinfo_set_description_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *desc_txt, const char *locale)
6381 {
6382         retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6383         retvm_if(!desc_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
6384
6385         int len = strlen(desc_txt);
6386         retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
6387
6388         manifest_x *mfx = (manifest_x *)handle;
6389
6390         description_x *description = calloc(1, sizeof(description_x));
6391         retvm_if(description == NULL, PMINFO_R_EINVAL, "Malloc Failed");
6392
6393         LISTADD(mfx->description, description);
6394         if (locale)
6395                 mfx->description->lang = strdup(locale);
6396         else
6397                 mfx->description->lang = strdup(DEFAULT_LOCALE);
6398         mfx->description->text = strdup(desc_txt);
6399
6400         return PMINFO_R_OK;
6401 }
6402
6403 API int pkgmgrinfo_set_author_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *author_name,
6404                 const char *author_email, const char *author_href, const char *locale)
6405 {
6406         retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6407         manifest_x *mfx = (manifest_x *)handle;
6408         author_x *author = calloc(1, sizeof(author_x));
6409         retvm_if(author == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL");
6410
6411         LISTADD(mfx->author, author);
6412         if (author_name)
6413                 mfx->author->text = strdup(author_name);
6414         if (author_email)
6415                 mfx->author->email = strdup(author_email);
6416         if (author_href)
6417                 mfx->author->href = strdup(author_href);
6418         if (locale)
6419                 mfx->author->lang = strdup(locale);
6420         else
6421                 mfx->author->lang = strdup(DEFAULT_LOCALE);
6422         return PMINFO_R_OK;
6423 }
6424
6425 API int pkgmgrinfo_set_removable_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, int removable)
6426 {
6427         retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6428         retvm_if((removable < 0) || (removable > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
6429
6430         manifest_x *mfx = (manifest_x *)handle;
6431
6432         if (removable == 0)
6433                 strcpy(mfx->removable, "false");
6434         else if (removable == 1)
6435                 strcpy(mfx->removable, "true");
6436
6437         return PMINFO_R_OK;
6438 }
6439
6440 API int pkgmgrinfo_set_preload_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, int preload)
6441 {
6442         retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6443         retvm_if((preload < 0) || (preload > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
6444
6445         manifest_x *mfx = (manifest_x *)handle;
6446
6447         if (preload == 0)
6448                 strcpy(mfx->preload, "false");
6449         else if (preload == 1)
6450                 strcpy(mfx->preload, "true");
6451
6452         return PMINFO_R_OK;
6453 }
6454
6455 API int pkgmgrinfo_set_installed_storage_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, INSTALL_LOCATION location)
6456 {
6457         retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6458         retvm_if((location < 0) || (location > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
6459
6460         manifest_x *mfx = (manifest_x *)handle;
6461
6462         if (location == INSTALL_INTERNAL)
6463                 strcpy(mfx->installed_storage, "installed_internal");
6464         else if (location == INSTALL_EXTERNAL)
6465                 strcpy(mfx->installed_storage, "installed_external");
6466
6467         return PMINFO_R_OK;
6468 }
6469
6470 API int pkgmgrinfo_save_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle)
6471 {
6472         retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6473
6474         int ret = 0;
6475         manifest_x *mfx = NULL;
6476         mfx = (manifest_x *)handle;
6477
6478         ret = pkgmgr_parser_update_manifest_info_in_db(mfx);
6479         if (ret == 0) {
6480                 _LOGE("Successfully stored info in DB\n");
6481                 return PMINFO_R_OK;
6482         } else {
6483                 _LOGE("Failed to store info in DB\n");
6484                 return PMINFO_R_ERROR;
6485         }
6486 }
6487
6488 API int pkgmgrinfo_destroy_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle)
6489 {
6490         retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6491
6492         manifest_x *mfx = NULL;
6493         mfx = (manifest_x *)handle;
6494         pkgmgr_parser_free_manifest_xml(mfx);
6495         return PMINFO_R_OK;
6496 }
6497
6498 API int pkgmgrinfo_pkginfo_set_state_enabled(const char *pkgid, bool enabled)
6499 {
6500         /* Should be implemented later */
6501         return 0;
6502 }
6503
6504 API int pkgmgrinfo_appinfo_set_state_enabled(const char *appid, bool enabled)
6505 {
6506         retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL\n");
6507         int ret = -1;
6508         char query[MAX_QUERY_LEN] = {'\0'};
6509         ret = __open_manifest_db();
6510
6511         if (access(MANIFEST_DB, F_OK) == 0) {
6512                 ret = db_util_open(MANIFEST_DB, &manifest_db,
6513                          DB_UTIL_REGISTER_HOOK_METHOD);
6514                 if (ret != SQLITE_OK) {
6515                         _LOGE("connect db [%s] failed! Manifest DB does not exists!!\n", MANIFEST_DB);
6516                         return PMINFO_R_ERROR;
6517                 }
6518         }
6519
6520         /*Begin transaction*/
6521         ret = sqlite3_exec(manifest_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
6522         if (ret != SQLITE_OK) {
6523                 _LOGE("Failed to begin transaction\n");
6524                 sqlite3_close(manifest_db);
6525                 return PMINFO_R_ERROR;
6526         }
6527         _LOGD("Transaction Begin\n");
6528
6529         memset(query, '\0', MAX_QUERY_LEN);
6530         snprintf(query, MAX_QUERY_LEN,
6531                 "update package_app_info set app_enabled='%s' where app_id='%s'", enabled?"true":"false", appid);
6532
6533         char *error_message = NULL;
6534         if (SQLITE_OK !=
6535             sqlite3_exec(manifest_db, query, NULL, NULL, &error_message)) {
6536                 _LOGE("Don't execute query = %s error message = %s\n", query,
6537                        error_message);
6538                 sqlite3_free(error_message);
6539                 return PMINFO_R_ERROR;
6540         }
6541         sqlite3_free(error_message);
6542
6543         /*Commit transaction*/
6544         ret = sqlite3_exec(manifest_db, "COMMIT", NULL, NULL, NULL);
6545         if (ret != SQLITE_OK) {
6546                 _LOGE("Failed to commit transaction. Rollback now\n");
6547                 sqlite3_exec(manifest_db, "ROLLBACK", NULL, NULL, NULL);
6548                 sqlite3_close(manifest_db);
6549                 return PMINFO_R_ERROR;
6550         }
6551         _LOGD("Transaction Commit and End\n");
6552         sqlite3_close(manifest_db);
6553
6554         return PMINFO_R_OK;
6555 }
6556
6557
6558 API int pkgmgrinfo_datacontrol_get_info(const char *providerid, const char * type, char **appid, char **access)
6559 {
6560         retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
6561         retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
6562         retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
6563         retvm_if(access == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
6564         int ret = PMINFO_R_OK;
6565         char query[MAX_QUERY_LEN] = {'\0'};
6566         char *error_message = NULL;
6567         pkgmgr_datacontrol_x *data = NULL;
6568
6569         ret = __open_datacontrol_db();
6570         if (ret == -1) {
6571                 _LOGE("Fail to open datacontrol DB\n");
6572                 return PMINFO_R_ERROR;
6573         }
6574
6575         data = (pkgmgr_datacontrol_x *)calloc(1, sizeof(pkgmgr_datacontrol_x));
6576         if (data == NULL) {
6577                 _LOGE("Failed to allocate memory for pkgmgr_datacontrol_x\n");
6578                 sqlite3_close(datacontrol_db);
6579                 return PMINFO_R_ERROR;
6580         }
6581
6582         snprintf(query, MAX_QUERY_LEN, 
6583                 "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",
6584                 providerid, type);
6585
6586         if (SQLITE_OK !=
6587                 sqlite3_exec(datacontrol_db, query, __datacontrol_cb, (void *)data, &error_message)) {
6588                 _LOGE("Don't execute query = %s error message = %s\n", query,
6589                            error_message);
6590                 sqlite3_free(error_message);
6591                 sqlite3_close(datacontrol_db);
6592                 return PMINFO_R_ERROR;
6593         }
6594
6595         *appid = (char *)data->appid;
6596         *access = (char *)data->access;
6597         free(data);
6598         sqlite3_close(datacontrol_db);
6599
6600         return PMINFO_R_OK;
6601 }
6602
6603 API int pkgmgrinfo_appinfo_set_default_label(const char *appid, const char *label)
6604 {
6605         retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL\n");
6606         int ret = -1;
6607         char query[MAX_QUERY_LEN] = {'\0'};
6608         char *error_message = NULL;
6609         ret = __open_manifest_db();
6610
6611         if (access(MANIFEST_DB, F_OK) == 0) {
6612                 ret = db_util_open(MANIFEST_DB, &manifest_db,
6613                          DB_UTIL_REGISTER_HOOK_METHOD);
6614                 if (ret != SQLITE_OK) {
6615                         _LOGE("connect db [%s] failed! Manifest DB does not exists!!\n", MANIFEST_DB);
6616                         return PMINFO_R_ERROR;
6617                 }
6618         }
6619
6620         /*Begin transaction*/
6621         ret = sqlite3_exec(manifest_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
6622         if (ret != SQLITE_OK) {
6623                 _LOGE("Failed to begin transaction\n");
6624                 sqlite3_close(manifest_db);
6625                 return PMINFO_R_ERROR;
6626         }
6627         _LOGD("Transaction Begin\n");
6628
6629         memset(query, '\0', MAX_QUERY_LEN);
6630         snprintf(query, MAX_QUERY_LEN,
6631                 "update package_app_localized_info set app_label='%s' where app_id='%s' and app_locale='No Locale'", label, appid);
6632
6633         if (SQLITE_OK !=
6634             sqlite3_exec(manifest_db, query, NULL, NULL, &error_message)) {
6635                 _LOGE("Don't execute query = %s error message = %s\n", query,
6636                        error_message);
6637                 sqlite3_free(error_message);
6638                 return PMINFO_R_ERROR;
6639         }
6640
6641         /*Commit transaction*/
6642         ret = sqlite3_exec(manifest_db, "COMMIT", NULL, NULL, NULL);
6643         if (ret != SQLITE_OK) {
6644                 _LOGE("Failed to commit transaction. Rollback now\n");
6645                 sqlite3_exec(manifest_db, "ROLLBACK", NULL, NULL, NULL);
6646                 sqlite3_close(manifest_db);
6647                 return PMINFO_R_ERROR;
6648         }
6649         _LOGD("Transaction Commit and End\n");
6650         sqlite3_close(manifest_db);
6651
6652         return PMINFO_R_OK;
6653 }
6654
6655 API int pkgmgrinfo_appinfo_is_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool *status)
6656 {
6657         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
6658         retvm_if(status == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
6659         char *val = NULL;
6660         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6661         val = (char *)info->uiapp_info->guestmode_visibility;
6662         if (val) {
6663                 if (strcasecmp(val, "true") == 0){
6664                         *status = 1;
6665                 }else if (strcasecmp(val, "false") == 0){
6666                         *status = 0;
6667                 }else{
6668                         *status = 1;
6669                 }
6670         }
6671         return PMINFO_R_OK;
6672 }
6673
6674 API int pkgmgrinfo_appinfo_set_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool status)
6675 {
6676         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
6677         char *val = NULL;
6678         int ret = 0;
6679         char *noti_string = NULL;
6680         int len = 0;
6681         char query[MAX_QUERY_LEN] = {'\0'};
6682         char *errmsg = NULL;
6683         sqlite3 *pkgmgr_parser_db;
6684
6685         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6686         val = (char *)info->uiapp_info->guestmode_visibility;
6687         if (val ) {
6688                 ret =
6689                     db_util_open_with_options(MANIFEST_DB, &pkgmgr_parser_db,
6690                                  SQLITE_OPEN_READWRITE, NULL);
6691
6692                 if (ret != SQLITE_OK) {
6693                         _LOGE("DB Open Failed\n");
6694                         return PMINFO_R_ERROR;
6695                 }
6696
6697                 /*TODO: Write to DB here*/
6698                 if (status == true)
6699                         snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_guestmodevisibility = 'true' where app_id = '%s'", (char *)info->uiapp_info->appid);
6700                 else
6701                         snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_guestmodevisibility = 'false' where app_id = '%s'", (char *)info->uiapp_info->appid);
6702
6703                 if (SQLITE_OK != sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &errmsg)) {
6704                         _LOGE("DB update [%s] failed, error message = %s\n", query, errmsg);
6705                         free(errmsg);
6706                         sqlite3_close(pkgmgr_parser_db);
6707                         return PMINFO_R_ERROR;
6708                 }else{
6709                         sqlite3_close(pkgmgr_parser_db);
6710                         len = strlen((char *)info->uiapp_info->appid) + 8;
6711                         noti_string = calloc(1, len);
6712                         if (noti_string == NULL){
6713                                 return PMINFO_R_ERROR;
6714                         }
6715                         snprintf(noti_string, len, "update:%s", (char *)info->uiapp_info->appid);
6716                 vconf_set_str(VCONFKEY_AIL_INFO_STATE, noti_string);
6717                         vconf_set_str(VCONFKEY_MENUSCREEN_DESKTOP, noti_string); // duplicate, will be removed
6718                         free(noti_string);
6719                 }
6720         }
6721         return PMINFO_R_OK;
6722 }