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