Save empty string when metadata value isn't set
[platform/core/appfw/pkgmgr-info.git] / parser / pkgmgr_parser_db.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 <sys/types.h>
27 #include <sys/smack.h>
28 #include <sys/stat.h>
29 #include <unistd.h>
30 #include <grp.h>
31 #include <pwd.h>
32
33 #include <db-util.h>
34 #include <glib.h>
35 /* For multi-user support */
36 #include <tzplatform_config.h>
37
38 #include "pkgmgr-info.h"
39 #include "pkgmgrinfo_basic.h"
40 #include "pkgmgrinfo_debug.h"
41 #include "pkgmgr_parser_internal.h"
42 #include "pkgmgr_parser_db.h"
43
44 #ifdef LOG_TAG
45 #undef LOG_TAG
46 #endif
47 #define LOG_TAG "PKGMGR_PARSER"
48
49 #define PKGMGR_PARSER_DB_FILE tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_parser.db")
50 #define PKGMGR_CERT_DB_FILE tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_cert.db")
51 #define MAX_QUERY_LEN           4096
52 #define BUFSIZE 4096
53 #define OWNER_ROOT 0
54
55 #define SET_SMACK_LABEL(x) \
56 do { \
57         if (smack_setlabel((x), "System::Shared", SMACK_LABEL_ACCESS)) \
58                 _LOGE("failed chsmack -a \"System::Shared\" %s", x); \
59         else \
60                 _LOGD("chsmack -a \"System::Shared\" %s", x); \
61 } while (0)
62
63 sqlite3 *pkgmgr_parser_db;
64 sqlite3 *pkgmgr_cert_db;
65
66
67 #define QUERY_CREATE_TABLE_PACKAGE_INFO "create table if not exists package_info " \
68                                                 "(package text primary key not null, " \
69                                                 "package_type text DEFAULT 'rpm', " \
70                                                 "package_version text, " \
71                                                 "package_api_version text, " \
72                                                 "install_location text, " \
73                                                 "package_size text, " \
74                                                 "package_removable text DEFAULT 'true', " \
75                                                 "package_preload text DEFAULT 'false', " \
76                                                 "package_readonly text DEFAULT 'false', " \
77                                                 "package_update text DEFAULT 'false', " \
78                                                 "package_appsetting text DEFAULT 'false', " \
79                                                 "package_nodisplay text DEFAULT 'false', " \
80                                                 "package_system text DEFAULT 'false', " \
81                                                 "author_name text, " \
82                                                 "author_email text, " \
83                                                 "author_href text," \
84                                                 "installed_time text," \
85                                                 "installed_storage text," \
86                                                 "storeclient_id text," \
87                                                 "mainapp_id text," \
88                                                 "package_url text," \
89                                                 "root_path text," \
90                                                 "csc_path text," \
91                                                 "package_support_disable text DEFAULT 'false')"
92
93 #define QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO "create table if not exists package_localized_info " \
94                                                 "(package text not null, " \
95                                                 "package_locale text DEFAULT 'No Locale', " \
96                                                 "package_label text, " \
97                                                 "package_icon text, " \
98                                                 "package_description text, " \
99                                                 "package_license text, " \
100                                                 "package_author, " \
101                                                 "PRIMARY KEY(package, package_locale), " \
102                                                 "FOREIGN KEY(package) " \
103                                                 "REFERENCES package_info(package) " \
104                                                 "ON DELETE CASCADE)"
105
106 #define QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO "create table if not exists package_privilege_info " \
107                                                 "(package text not null, " \
108                                                 "privilege text not null, " \
109                                                 "PRIMARY KEY(package, privilege) " \
110                                                 "FOREIGN KEY(package) " \
111                                                 "REFERENCES package_info(package) " \
112                                                 "ON DELETE CASCADE)"
113
114 #define QUERY_CREATE_TABLE_PACKAGE_APP_INFO "create table if not exists package_app_info " \
115                                                 "(app_id text primary key not null, " \
116                                                 "app_component text, " \
117                                                 "app_exec text, " \
118                                                 "app_nodisplay text DEFAULT 'false', " \
119                                                 "app_type text, " \
120                                                 "app_onboot text DEFAULT 'false', " \
121                                                 "app_multiple text DEFAULT 'false', " \
122                                                 "app_autorestart text DEFAULT 'false', " \
123                                                 "app_taskmanage text DEFAULT 'false', " \
124                                                 "app_enabled text DEFAULT 'true', " \
125                                                 "app_hwacceleration text DEFAULT 'use-system-setting', " \
126                                                 "app_screenreader text DEFAULT 'use-system-setting', " \
127                                                 "app_mainapp text, " \
128                                                 "app_recentimage text, " \
129                                                 "app_launchcondition text, " \
130                                                 "app_indicatordisplay text DEFAULT 'true', " \
131                                                 "app_portraitimg text, " \
132                                                 "app_landscapeimg text, " \
133                                                 "app_guestmodevisibility text DEFAULT 'true', " \
134                                                 "app_permissiontype text DEFAULT 'normal', " \
135                                                 "app_preload text DEFAULT 'false', " \
136                                                 "app_submode text DEFAULT 'false', " \
137                                                 "app_submode_mainid text, " \
138                                                 "app_launch_mode text NOT NULL DEFAULT 'caller', " \
139                                                 "app_ui_gadget text DEFAULT 'false', " \
140                                                 "app_support_disable text DEFAULT 'false', " \
141                                                 "component_type text, " \
142                                                 "package text not null, " \
143                                                 "FOREIGN KEY(package) " \
144                                                 "REFERENCES package_info(package) " \
145                                                 "ON DELETE CASCADE)"
146
147 #define QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO "create table if not exists package_app_localized_info " \
148                                                 "(app_id text not null, " \
149                                                 "app_locale text DEFAULT 'No Locale', " \
150                                                 "app_label text, " \
151                                                 "app_icon text, " \
152                                                 "PRIMARY KEY(app_id,app_locale) " \
153                                                 "FOREIGN KEY(app_id) " \
154                                                 "REFERENCES package_app_info(app_id) " \
155                                                 "ON DELETE CASCADE)"
156
157 #define QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO "create table if not exists package_app_icon_section_info " \
158                                                 "(app_id text not null, " \
159                                                 "app_icon text, " \
160                                                 "app_icon_section text, " \
161                                                 "app_icon_resolution text, " \
162                                                 "PRIMARY KEY(app_id,app_icon_section,app_icon_resolution) " \
163                                                 "FOREIGN KEY(app_id) " \
164                                                 "REFERENCES package_app_info(app_id) " \
165                                                 "ON DELETE CASCADE)"
166
167 #define QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO "create table if not exists package_app_image_info " \
168                                                 "(app_id text not null, " \
169                                                 "app_locale text DEFAULT 'No Locale', " \
170                                                 "app_image_section text, " \
171                                                 "app_image text, " \
172                                                 "PRIMARY KEY(app_id,app_image_section) " \
173                                                 "FOREIGN KEY(app_id) " \
174                                                 "REFERENCES package_app_info(app_id) " \
175                                                 "ON DELETE CASCADE)"
176
177 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL "create table if not exists package_app_app_control " \
178                                                 "(app_id text not null, " \
179                                                 "app_control text not null, " \
180                                                 "PRIMARY KEY(app_id,app_control) " \
181                                                 "FOREIGN KEY(app_id) " \
182                                                 "REFERENCES package_app_info(app_id) " \
183                                                 "ON DELETE CASCADE)"
184
185 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_SVC "create table if not exists package_app_app_svc " \
186                                                 "(app_id text not null, " \
187                                                 "operation text not null, " \
188                                                 "uri_scheme text, " \
189                                                 "mime_type text, " \
190                                                 "subapp_name text, " \
191                                                 "PRIMARY KEY(app_id,operation,uri_scheme,mime_type,subapp_name) " \
192                                                 "FOREIGN KEY(app_id) " \
193                                                 "REFERENCES package_app_info(app_id) " \
194                                                 "ON DELETE CASCADE)"
195
196 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY "create table if not exists package_app_app_category " \
197                                                 "(app_id text not null, " \
198                                                 "category text not null, " \
199                                                 "PRIMARY KEY(app_id,category) " \
200                                                 "FOREIGN KEY(app_id) " \
201                                                 "REFERENCES package_app_info(app_id) " \
202                                                 "ON DELETE CASCADE)"
203
204 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA "create table if not exists package_app_app_metadata " \
205                                                 "(app_id text not null, " \
206                                                 "md_key text not null, " \
207                                                 "md_value text not null, " \
208                                                 "PRIMARY KEY(app_id, md_key, md_value) " \
209                                                 "FOREIGN KEY(app_id) " \
210                                                 "REFERENCES package_app_info(app_id) " \
211                                                 "ON DELETE CASCADE)"
212
213 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION "create table if not exists package_app_app_permission " \
214                                                 "(app_id text not null, " \
215                                                 "pm_type text not null, " \
216                                                 "pm_value text not null, " \
217                                                 "PRIMARY KEY(app_id, pm_type, pm_value) " \
218                                                 "FOREIGN KEY(app_id) " \
219                                                 "REFERENCES package_app_info(app_id) " \
220                                                 "ON DELETE CASCADE)"
221
222 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED "create table if not exists package_app_share_allowed " \
223                                                 "(app_id text not null, " \
224                                                 "data_share_path text not null, " \
225                                                 "data_share_allowed text not null, " \
226                                                 "PRIMARY KEY(app_id,data_share_path,data_share_allowed) " \
227                                                 "FOREIGN KEY(app_id) " \
228                                                 "REFERENCES package_app_info(app_id) " \
229                                                 "ON DELETE CASCADE)"
230
231 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST "create table if not exists package_app_share_request " \
232                                                 "(app_id text not null, " \
233                                                 "data_share_request text not null, " \
234                                                 "PRIMARY KEY(app_id,data_share_request) " \
235                                                 "FOREIGN KEY(app_id) " \
236                                                 "REFERENCES package_app_info(app_id) " \
237                                                 "ON DELETE CASCADE)"
238
239 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO "create table if not exists package_cert_index_info " \
240                                                 "(cert_info text not null, " \
241                                                 "cert_id integer, " \
242                                                 "cert_ref_count integer, " \
243                                                 "PRIMARY KEY(cert_id)) "
244
245 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INFO "create table if not exists package_cert_info " \
246                                                 "(package text not null, " \
247                                                 "author_root_cert integer, " \
248                                                 "author_im_cert integer, " \
249                                                 "author_signer_cert integer, " \
250                                                 "dist_root_cert integer, " \
251                                                 "dist_im_cert integer, " \
252                                                 "dist_signer_cert integer, " \
253                                                 "dist2_root_cert integer, " \
254                                                 "dist2_im_cert integer, " \
255                                                 "dist2_signer_cert integer, " \
256                                                 "PRIMARY KEY(package)) "
257
258 #define QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL "create table if not exists package_app_data_control " \
259                                                 "(app_id text not null, " \
260                                                 "providerid text not null, " \
261                                                 "access text not null, " \
262                                                 "type text not null, " \
263                                                 "PRIMARY KEY(app_id, providerid, access, type) " \
264                                                 "FOREIGN KEY(app_id) " \
265                                                 "REFERENCES package_app_info(app_id) " \
266                                                 "ON DELETE CASCADE)"
267
268 static int __insert_uiapplication_info(manifest_x *mfx);
269 static int __insert_serviceapplication_info(manifest_x *mfx);
270 static int __insert_uiapplication_appsvc_info(manifest_x *mfx);
271 static int __insert_serviceapplication_appsvc_info(manifest_x *mfx);
272 static int __insert_uiapplication_appcategory_info(manifest_x *mfx);
273 static int __insert_serviceapplication_appcategory_info(manifest_x *mfx);
274 static int __insert_uiapplication_appcontrol_info(manifest_x *mfx);
275 static int __insert_serviceapplication_appmetadata_info(manifest_x *mfx);
276 static int __insert_uiapplication_appmetadata_info(manifest_x *mfx);
277 static int __insert_serviceapplication_appcontrol_info(manifest_x *mfx);
278 static int __insert_uiapplication_share_allowed_info(manifest_x *mfx);
279 static int __insert_serviceapplication_share_allowed_info(manifest_x *mfx);
280 static int __insert_uiapplication_share_request_info(manifest_x *mfx);
281 static int __insert_serviceapplication_share_request_info(manifest_x *mfx);
282 static int __insert_uiapplication_datacontrol_info(manifest_x *mfx);
283 static int __insert_serviceapplication_datacontrol_info(manifest_x *mfx);
284 static void __insert_serviceapplication_locale_info(gpointer data, gpointer userdata);
285 static void __insert_uiapplication_locale_info(gpointer data, gpointer userdata);
286 static void __insert_pkglocale_info(gpointer data, gpointer userdata);
287 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid);
288 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid);
289 static int __delete_subpkg_info_from_db(char *appid);
290 static int __delete_appinfo_from_db(char *db_table, const char *appid);
291 static int __initialize_db(sqlite3 *db_handle, const char *db_query);
292 static int __exec_query(char *query);
293 static void __extract_data(gpointer data, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath,
294                 char **label, char **license, char **icon, char **description, char **author);
295 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata);
296 static GList *__create_locale_list(GList *locale, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath);
297 static void __preserve_guestmode_visibility_value(manifest_x *mfx);
298 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname);
299 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path);
300 static int __parserdb_change_perm(const char *db_file, uid_t uid);
301
302 static int __delete_subpkg_list_cb(void *data, int ncols, char **coltxt, char **colname)
303 {
304         if (coltxt[0])
305                 __delete_subpkg_info_from_db(coltxt[0]);
306
307         return 0;
308 }
309
310 static const char *__get_str(const char *str)
311 {
312         if (str == NULL)
313         {
314                 return PKGMGR_PARSER_EMPTY_STR;
315         }
316
317         return str;
318 }
319
320 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path)
321 {
322         int ret = -1;
323         sqlite3 *handle;
324
325         ret = db_util_open(db_path, &handle,  DB_UTIL_REGISTER_HOOK_METHOD);
326         if (ret != SQLITE_OK) {
327                 _LOGD("connect db [%s] failed!\n", db_path);
328                 return -1;
329         }
330         *db_handle = handle;
331
332         return 0;
333 }
334
335 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname)
336 {
337         manifest_x *mfx = (manifest_x *)data;
338         int i = 0;
339         char *appid = NULL;
340         char *status = NULL;
341         uiapplication_x *uiapp = NULL;
342         for(i = 0; i < ncols; i++)
343         {
344                 uiapp = mfx->uiapplication;
345                 if (strcmp(colname[i], "app_id") == 0) {
346                         if (coltxt[i])
347                                 appid = strdup(coltxt[i]);
348                 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0) {
349                         if (coltxt[i])
350                                 status = strdup(coltxt[i]);
351                 }
352         }
353         if (appid == NULL) {
354                 _LOGD("app id is NULL\n");
355                 return -1;
356         }
357         /*update guest mode visibility*/
358         for (; uiapp != NULL; uiapp = uiapp->next) {
359                 if (strcmp(uiapp->appid, appid) == 0) {
360                         free((void *)uiapp->guestmode_visibility);
361                         uiapp->guestmode_visibility = strdup(status);
362                         break;
363                 }
364         }
365         if (appid) {
366                 free(appid);
367                 appid = NULL;
368         }
369         if (status) {
370                 free(status);
371                 status = NULL;
372         }
373
374         return 0;
375 }
376
377 static void __preserve_guestmode_visibility_value(manifest_x *mfx)
378 {
379         char *error_message = NULL;
380         char query[MAX_QUERY_LEN] = {'\0'};
381         snprintf(query, MAX_QUERY_LEN - 1, "select app_id, app_guestmodevisibility from package_app_info where package='%s'", mfx->package);
382         if (SQLITE_OK !=
383             sqlite3_exec(pkgmgr_parser_db, query,
384                          __guestmode_visibility_cb, (void *)mfx, &error_message)) {
385                 _LOGD("Don't execute query = %s error message = %s\n",
386                        query, error_message);
387                 sqlite3_free(error_message);
388         }
389         return;
390 }
391
392 static int __initialize_db(sqlite3 *db_handle, const char *db_query)
393 {
394         char *error_message = NULL;
395         if (SQLITE_OK !=
396             sqlite3_exec(db_handle, db_query,
397                          NULL, NULL, &error_message)) {
398                 _LOGD("Don't execute query = %s error message = %s\n",
399                        db_query, error_message);
400                 sqlite3_free(error_message);
401                 return -1;
402         }
403         sqlite3_free(error_message);
404         return 0;
405 }
406
407 static int __exec_query(char *query)
408 {
409         char *error_message = NULL;
410         if (SQLITE_OK !=
411             sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
412                 _LOGD("Don't execute query = %s error message = %s\n", query,
413                        error_message);
414                 sqlite3_free(error_message);
415                 return -1;
416         }
417         sqlite3_free(error_message);
418         return 0;
419 }
420
421 static int __exec_query_no_msg(char *query)
422 {
423         char *error_message = NULL;
424         if (SQLITE_OK !=
425             sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
426                 sqlite3_free(error_message);
427                 return -1;
428         }
429         sqlite3_free(error_message);
430         return 0;
431 }
432
433 static GList *__create_locale_list(GList *locale, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath)
434 {
435
436         while(lbl != NULL)
437         {
438                 if (lbl->lang)
439                         locale = g_list_insert_sorted_with_data(locale, (gpointer)lbl->lang, __comparefunc, NULL);
440                 lbl = lbl->next;
441         }
442         while(lcn != NULL)
443         {
444                 if (lcn->lang)
445                         locale = g_list_insert_sorted_with_data(locale, (gpointer)lcn->lang, __comparefunc, NULL);
446                 lcn = lcn->next;
447         }
448         while(icn != NULL)
449         {
450                 if (icn->lang)
451                         locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->lang, __comparefunc, NULL);
452                 icn = icn->next;
453         }
454         while(dcn != NULL)
455         {
456                 if (dcn->lang)
457                         locale = g_list_insert_sorted_with_data(locale, (gpointer)dcn->lang, __comparefunc, NULL);
458                 dcn = dcn->next;
459         }
460         while(ath != NULL)
461         {
462                 if (ath->lang)
463                         locale = g_list_insert_sorted_with_data(locale, (gpointer)ath->lang, __comparefunc, NULL);
464                 ath = ath->next;
465         }
466         return locale;
467
468 }
469
470 static GList *__create_icon_list(GList *locale, icon_x *icn)
471 {
472         while(icn != NULL)
473         {
474                 if (icn->section)
475                         locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->section, __comparefunc, NULL);
476                 icn = icn->next;
477         }
478         return locale;
479 }
480
481 static GList *__create_image_list(GList *locale, image_x *image)
482 {
483         while(image != NULL)
484         {
485                 if (image->section)
486                         locale = g_list_insert_sorted_with_data(locale, (gpointer)image->section, __comparefunc, NULL);
487                 image = image->next;
488         }
489         return locale;
490 }
491
492 static void __trimfunc(GList* trim_list)
493 {
494         char *trim_data = NULL;
495         char *prev = NULL;
496
497         GList *list = NULL;
498         list = g_list_first(trim_list);
499
500         while (list) {
501                 trim_data = (char *)list->data;
502                 if (trim_data) {
503                         if (prev) {
504                                 if (strcmp(trim_data, prev) == 0) {
505                                         trim_list = g_list_remove(trim_list, trim_data);
506                                         list = g_list_first(trim_list);
507                                         prev = NULL;
508                                         continue;
509                                 } else
510                                         prev = trim_data;
511                         }
512                         else
513                                 prev = trim_data;
514                 }
515                 list = g_list_next(list);
516         }
517 }
518
519 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata)
520 {
521         if (a == NULL || b == NULL)
522                 return 0;
523         if (strcmp((char*)a, (char*)b) == 0)
524                 return 0;
525         if (strcmp((char*)a, (char*)b) < 0)
526                 return -1;
527         if (strcmp((char*)a, (char*)b) > 0)
528                 return 1;
529         return 0;
530 }
531
532 static void __extract_data(gpointer data, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath,
533                 char **label, char **license, char **icon, char **description, char **author)
534 {
535         while(lbl != NULL)
536         {
537                 if (lbl->lang) {
538                         if (strcmp(lbl->lang, (char *)data) == 0) {
539                                 *label = (char*)lbl->text;
540                                 break;
541                         }
542                 }
543                 lbl = lbl->next;
544         }
545         while(lcn != NULL)
546         {
547                 if (lcn->lang) {
548                         if (strcmp(lcn->lang, (char *)data) == 0) {
549                                 *license = (char*)lcn->text;
550                                 break;
551                         }
552                 }
553                 lcn = lcn->next;
554         }
555         while(icn != NULL)
556         {
557                 if (icn->lang) {
558                         if (strcmp(icn->lang, (char *)data) == 0) {
559                                 *icon = (char*)icn->text;
560                                 break;
561                         }
562                 }
563                 icn = icn->next;
564         }
565         while(dcn != NULL)
566         {
567                 if (dcn->lang) {
568                         if (strcmp(dcn->lang, (char *)data) == 0) {
569                                 *description = (char*)dcn->text;
570                                 break;
571                         }
572                 }
573                 dcn = dcn->next;
574         }
575         while(ath != NULL)
576         {
577                 if (ath->lang) {
578                         if (strcmp(ath->lang, (char *)data) == 0) {
579                                 *author = (char*)ath->text;
580                                 break;
581                         }
582                 }
583                 ath = ath->next;
584         }
585
586 }
587
588 static void __extract_icon_data(gpointer data, icon_x *icn, char **icon, char **resolution)
589 {
590         while(icn != NULL)
591         {
592                 if (icn->section) {
593                         if (strcmp(icn->section, (char *)data) == 0) {
594                                 *icon = (char*)icn->text;
595                                 *resolution = (char*)icn->resolution;
596                                 break;
597                         }
598                 }
599                 icn = icn->next;
600         }
601 }
602
603 static void __extract_image_data(gpointer data, image_x*image, char **lang, char **img)
604 {
605         while(image != NULL)
606         {
607                 if (image->section) {
608                         if (strcmp(image->section, (char *)data) == 0) {
609                                 *lang = (char*)image->lang;
610                                 *img = (char*)image->text;
611                                 break;
612                         }
613                 }
614                 image = image->next;
615         }
616 }
617
618 static void __insert_pkglocale_info(gpointer data, gpointer userdata)
619 {
620         int ret = -1;
621         char *label = NULL;
622         char *icon = NULL;
623         char *description = NULL;
624         char *license = NULL;
625         char *author = NULL;
626         char query[MAX_QUERY_LEN] = {'\0'};
627
628         manifest_x *mfx = (manifest_x *)userdata;
629         label_x *lbl = mfx->label;
630         license_x *lcn = mfx->license;
631         icon_x *icn = mfx->icon;
632         description_x *dcn = mfx->description;
633         author_x *ath = mfx->author;
634
635         __extract_data(data, lbl, lcn, icn, dcn, ath, &label, &license, &icon, &description, &author);
636         if (!label && !description && !icon && !license && !author)
637                 return;
638
639         sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_localized_info(package, package_locale, " \
640                 "package_label, package_icon, package_description, package_license, package_author) values " \
641                 "('%q', '%q', '%q', '%q', '%s', '%s', '%s')",
642                 mfx->package,
643                 (char*)data,
644                 label,
645                 icon,
646                 __get_str(description),
647                 __get_str(license),
648                 __get_str(author));
649
650         ret = __exec_query(query);
651         if (ret == -1)
652                 _LOGD("Package Localized Info DB Insert failed\n");
653 }
654
655 static void __insert_uiapplication_locale_info(gpointer data, gpointer userdata)
656 {
657         int ret = -1;
658         char *label = NULL;
659         char *icon = NULL;
660         char query[MAX_QUERY_LEN] = {'\0'};
661
662         uiapplication_x *up = (uiapplication_x*)userdata;
663         label_x *lbl = up->label;
664         icon_x *icn = up->icon;
665
666         __extract_data(data, lbl, NULL, icn, NULL, NULL, &label, NULL, &icon, NULL, NULL);
667         if (!label && !icon)
668                 return;
669         sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_localized_info(app_id, app_locale, " \
670                 "app_label, app_icon) values " \
671                 "('%q', '%q', '%q', '%q')", up->appid, (char*)data,
672                 label, icon);
673         ret = __exec_query(query);
674         if (ret == -1)
675                 _LOGD("Package UiApp Localized Info DB Insert failed\n");
676
677         /*insert ui app locale info to pkg locale to get mainapp data */
678         if (strcasecmp(up->mainapp, "true")==0) {
679                 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_localized_info(package, package_locale, " \
680                         "package_label, package_icon, package_description, package_license, package_author) values " \
681                         "('%q', '%q', '%q', '%q', '%q', '%q', '%q')",
682                         up->package,
683                         (char*)data,
684                         label,
685                         icon,
686                         PKGMGR_PARSER_EMPTY_STR,
687                         PKGMGR_PARSER_EMPTY_STR,
688                         PKGMGR_PARSER_EMPTY_STR);
689
690                 ret = __exec_query_no_msg(query);
691
692                 if (icon != NULL) {
693                         sqlite3_snprintf(MAX_QUERY_LEN, query, "update package_localized_info set package_icon='%s' "\
694                                 "where package='%s' and package_locale='%s'", icon, up->package, (char*)data);
695                         ret = __exec_query_no_msg(query);
696                 }
697         }
698 }
699
700 static void __insert_uiapplication_icon_section_info(gpointer data, gpointer userdata)
701 {
702         int ret = -1;
703         char *icon = NULL;
704         char *resolution = NULL;
705         char query[MAX_QUERY_LEN] = {'\0'};
706
707         uiapplication_x *up = (uiapplication_x*)userdata;
708         icon_x *icn = up->icon;
709
710         __extract_icon_data(data, icn, &icon, &resolution);
711         if (!icon && !resolution)
712                 return;
713         sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_icon_section_info(app_id, " \
714                 "app_icon, app_icon_section, app_icon_resolution) values " \
715                 "('%q', '%q', '%q', '%q')", up->appid,
716                 icon, (char*)data, resolution);
717
718         ret = __exec_query(query);
719         if (ret == -1)
720                 _LOGD("Package UiApp Localized Info DB Insert failed\n");
721
722 }
723
724 static void __insert_uiapplication_image_info(gpointer data, gpointer userdata)
725 {
726         int ret = -1;
727         char *lang = NULL;
728         char *img = NULL;
729         char query[MAX_QUERY_LEN] = {'\0'};
730
731         uiapplication_x *up = (uiapplication_x*)userdata;
732         image_x *image = up->image;
733
734         __extract_image_data(data, image, &lang, &img);
735         if (!lang && !img)
736                 return;
737         sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_image_info(app_id, app_locale, " \
738                 "app_image_section, app_image) values " \
739                 "('%q', '%q', '%q', '%q')", up->appid, lang, (char*)data, img);
740
741         ret = __exec_query(query);
742         if (ret == -1)
743                 _LOGD("Package UiApp image Info DB Insert failed\n");
744
745 }
746
747
748 static void __insert_serviceapplication_locale_info(gpointer data, gpointer userdata)
749 {
750         int ret = -1;
751         char *icon = NULL;
752         char *label = NULL;
753         char query[MAX_QUERY_LEN] = {'\0'};
754
755         serviceapplication_x *sp = (serviceapplication_x*)userdata;
756         label_x *lbl = sp->label;
757         icon_x *icn = sp->icon;
758
759         __extract_data(data, lbl, NULL, icn, NULL, NULL, &label, NULL, &icon, NULL, NULL);
760         if (!icon && !label)
761                 return;
762         sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_localized_info(app_id, app_locale, " \
763                 "app_label, app_icon) values " \
764                 "('%q', '%q', '%q', '%q')", sp->appid, (char*)data,
765                 label, icon);
766         ret = __exec_query(query);
767         if (ret == -1)
768                 _LOGD("Package ServiceApp Localized Info DB Insert failed\n");
769 }
770
771 static int __insert_ui_mainapp_info(manifest_x *mfx)
772 {
773         uiapplication_x *up = mfx->uiapplication;
774         int ret = -1;
775         char query[MAX_QUERY_LEN] = {'\0'};
776         while(up != NULL)
777         {
778                 snprintf(query, MAX_QUERY_LEN,
779                         "update package_app_info set app_mainapp='%s' where app_id='%s'", up->mainapp, up->appid);
780
781                 ret = __exec_query(query);
782                 if (ret == -1) {
783                         _LOGD("Package UiApp Info DB Insert Failed\n");
784                         return -1;
785                 }
786                 if (strcasecmp(up->mainapp, "True")==0)
787                         mfx->mainapp_id = strdup(up->appid);
788
789                 up = up->next;
790                 memset(query, '\0', MAX_QUERY_LEN);
791         }
792
793         if (mfx->mainapp_id == NULL){
794                 if (mfx->uiapplication && mfx->uiapplication->appid) {
795                         snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_mainapp='true' where app_id='%s'", mfx->uiapplication->appid);
796                 } else {
797                         _LOGD("Not valid appid\n");
798                         return -1;
799                 }
800
801                 ret = __exec_query(query);
802                 if (ret == -1) {
803                         _LOGD("Package UiApp Info DB Insert Failed\n");
804                         return -1;
805                 }
806
807                 free((void *)mfx->uiapplication->mainapp);
808                 mfx->uiapplication->mainapp= strdup("true");
809                 mfx->mainapp_id = strdup(mfx->uiapplication->appid);
810         }
811
812         memset(query, '\0', MAX_QUERY_LEN);
813         snprintf(query, MAX_QUERY_LEN,
814                 "update package_info set mainapp_id='%s' where package='%s'", mfx->mainapp_id, mfx->package);
815         ret = __exec_query(query);
816         if (ret == -1) {
817                 _LOGD("Package Info DB update Failed\n");
818                 return -1;
819         }
820
821         return 0;
822 }
823 /* _PRODUCT_LAUNCHING_ENHANCED_
824 *  up->indicatordisplay, up->portraitimg, up->landscapeimg, up->guestmode_appstatus
825 */
826 static int __insert_uiapplication_info(manifest_x *mfx)
827 {
828         uiapplication_x *up = mfx->uiapplication;
829         int ret = -1;
830         char query[MAX_QUERY_LEN] = {'\0'};
831         while(up != NULL)
832         {
833                 snprintf(query, MAX_QUERY_LEN,
834                          "insert into package_app_info(app_id, app_component, app_exec, app_nodisplay, app_type, app_onboot, " \
835                         "app_multiple, app_autorestart, app_taskmanage, app_enabled, app_hwacceleration, app_screenreader, app_mainapp , app_recentimage, " \
836                         "app_launchcondition, app_indicatordisplay, app_portraitimg, app_landscapeimg, app_guestmodevisibility, app_permissiontype, "\
837                         "app_preload, app_submode, app_submode_mainid, app_launch_mode, app_ui_gadget, app_support_disable, component_type, package) " \
838                         "values('%s', '%s', '%s', '%s', '%s', '%s', '%s','%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",\
839                          up->appid,
840                          "uiapp",
841                          up->exec,
842                          up->nodisplay,
843                          up->type,
844                          PKGMGR_PARSER_EMPTY_STR,
845                          up->multiple,
846                          PKGMGR_PARSER_EMPTY_STR,
847                          up->taskmanage,
848                          up->enabled,
849                          up->hwacceleration,
850                          up->screenreader,
851                          up->mainapp,
852                          __get_str(up->recentimage),
853                          up->launchcondition,
854                          up->indicatordisplay,
855                          __get_str(up->portraitimg),
856                          __get_str(up->landscapeimg),
857                          up->guestmode_visibility,
858                          up->permission_type,
859                          mfx->preload,
860                          up->submode,
861                          __get_str(up->submode_mainid),
862                          up->launch_mode,
863                          up->ui_gadget,
864                          mfx->support_disable,
865                          up->component_type,
866                          mfx->package);
867
868                 ret = __exec_query(query);
869                 if (ret == -1) {
870                         _LOGD("Package UiApp Info DB Insert Failed\n");
871                         return -1;
872                 }
873                 up = up->next;
874                 memset(query, '\0', MAX_QUERY_LEN);
875         }
876         return 0;
877 }
878
879 static int __insert_uiapplication_appcategory_info(manifest_x *mfx)
880 {
881         uiapplication_x *up = mfx->uiapplication;
882         category_x *ct = NULL;
883         int ret = -1;
884         char query[MAX_QUERY_LEN] = {'\0'};
885         while(up != NULL)
886         {
887                 ct = up->category;
888                 while (ct != NULL)
889                 {
890                         snprintf(query, MAX_QUERY_LEN,
891                                 "insert into package_app_app_category(app_id, category) " \
892                                 "values('%s','%s')",\
893                                  up->appid, ct->name);
894                         ret = __exec_query(query);
895                         if (ret == -1) {
896                                 _LOGD("Package UiApp Category Info DB Insert Failed\n");
897                                 return -1;
898                         }
899                         ct = ct->next;
900                         memset(query, '\0', MAX_QUERY_LEN);
901                 }
902                 up = up->next;
903         }
904         return 0;
905 }
906
907 static int __insert_uiapplication_appmetadata_info(manifest_x *mfx)
908 {
909         uiapplication_x *up = mfx->uiapplication;
910         metadata_x *md = NULL;
911         int ret = -1;
912         char query[MAX_QUERY_LEN] = {'\0'};
913         while(up != NULL)
914         {
915                 md = up->metadata;
916                 while (md != NULL)
917                 {
918                         if (md->key) {
919                                 snprintf(query, MAX_QUERY_LEN,
920                                         "insert into package_app_app_metadata(app_id, md_key, md_value) " \
921                                         "values('%s','%s', '%s')",\
922                                          up->appid, md->key, md->value ? md->value : "");
923                                 ret = __exec_query(query);
924                                 if (ret == -1) {
925                                         _LOGD("Package UiApp Metadata Info DB Insert Failed\n");
926                                         return -1;
927                                 }
928                         }
929                         md = md->next;
930                         memset(query, '\0', MAX_QUERY_LEN);
931                 }
932                 up = up->next;
933         }
934         return 0;
935 }
936
937 static int __insert_uiapplication_apppermission_info(manifest_x *mfx)
938 {
939         uiapplication_x *up = mfx->uiapplication;
940         permission_x *pm = NULL;
941         int ret = -1;
942         char query[MAX_QUERY_LEN] = {'\0'};
943         while(up != NULL)
944         {
945                 pm = up->permission;
946                 while (pm != NULL)
947                 {
948                         snprintf(query, MAX_QUERY_LEN,
949                                 "insert into package_app_app_permission(app_id, pm_type, pm_value) " \
950                                 "values('%s','%s', '%s')",\
951                                  up->appid, pm->type, pm->value);
952                         ret = __exec_query(query);
953                         if (ret == -1) {
954                                 _LOGD("Package UiApp permission Info DB Insert Failed\n");
955                                 return -1;
956                         }
957                         pm = pm->next;
958                         memset(query, '\0', MAX_QUERY_LEN);
959                 }
960                 up = up->next;
961         }
962         return 0;
963 }
964
965 static int __insert_uiapplication_appcontrol_info(manifest_x *mfx)
966 {
967         uiapplication_x *up = mfx->uiapplication;
968         appcontrol_x *acontrol = NULL;
969         int ret = -1;
970         char query[MAX_QUERY_LEN] = {'\0'};
971         char buf[BUFSIZE] = {'\0'};
972         while (up != NULL) {
973                 acontrol = up->appcontrol;
974                 while (acontrol != NULL) {
975                         snprintf(buf, BUFSIZE, "%s|%s|%s",\
976                                         acontrol->operation ? (strlen(acontrol->operation) > 0 ? acontrol->operation : "NULL") : "NULL",
977                                         acontrol->uri ? (strlen(acontrol->uri) > 0 ? acontrol->uri : "NULL") : "NULL",
978                                         acontrol->mime ? (strlen(acontrol->mime) > 0 ? acontrol->mime : "NULL") : "NULL");
979                         snprintf(query, MAX_QUERY_LEN,
980                                         "insert into package_app_app_control(app_id, app_control) " \
981                                         "values('%s', '%s')",\
982                                         up->appid, buf);
983                         ret = __exec_query(query);
984                         if (ret == -1) {
985                                 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
986                                 return -1;
987                         }
988                         memset(query, '\0', MAX_QUERY_LEN);
989                         acontrol = acontrol->next;
990                 }
991                 up = up->next;
992         }
993         return 0;
994 }
995
996 static int __insert_uiapplication_appsvc_info(manifest_x *mfx)
997 {
998         uiapplication_x *up = mfx->uiapplication;
999         appsvc_x *asvc = NULL;
1000         operation_x *op = NULL;
1001         mime_x *mi = NULL;
1002         uri_x *ui = NULL;
1003         subapp_x *sub = NULL;
1004         int ret = -1;
1005         char query[MAX_QUERY_LEN] = {'\0'};
1006         const char *operation = NULL;
1007         const char *mime = NULL;
1008         const char *uri = NULL;
1009         const char *subapp = NULL;
1010         while(up != NULL)
1011         {
1012                 asvc = up->appsvc;
1013                 while(asvc != NULL)
1014                 {
1015                         op = asvc->operation;
1016                         while(op != NULL)
1017                         {
1018                                 if (op)
1019                                         operation = op->name;
1020                                 mi = asvc->mime;
1021
1022                                 do
1023                                 {
1024                                         if (mi)
1025                                                 mime = mi->name;
1026                                         sub = asvc->subapp;
1027                                         do
1028                                         {
1029                                                 if (sub)
1030                                                         subapp = sub->name;
1031                                                 ui = asvc->uri;
1032                                                 do
1033                                                 {
1034                                                         if (ui)
1035                                                                 uri = ui->name;
1036                                                         snprintf(query, MAX_QUERY_LEN,
1037                                                                  "insert into package_app_app_svc(app_id, operation, uri_scheme, mime_type, subapp_name) " \
1038                                                                 "values('%s', '%s', '%s', '%s', '%s')",\
1039                                                                  up->appid,
1040                                                                  operation,
1041                                                                  __get_str(uri),
1042                                                                  __get_str(mime),
1043                                                                  __get_str(subapp));
1044
1045                                                         ret = __exec_query(query);
1046                                                         if (ret == -1) {
1047                                                                 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1048                                                                 return -1;
1049                                                         }
1050                                                         memset(query, '\0', MAX_QUERY_LEN);
1051                                                         if (ui)
1052                                                                 ui = ui->next;
1053                                                         uri = NULL;
1054                                                 } while(ui != NULL);
1055                                                 if (sub)
1056                                                         sub = sub->next;
1057                                                 subapp = NULL;
1058                                         }while(sub != NULL);
1059                                         if (mi)
1060                                                 mi = mi->next;
1061                                         mime = NULL;
1062                                 }while(mi != NULL);
1063                                 if (op)
1064                                         op = op->next;
1065                                 operation = NULL;
1066                         }
1067                         asvc = asvc->next;
1068                 }
1069                 up = up->next;
1070         }
1071         return 0;
1072 }
1073
1074 static int __insert_uiapplication_datacontrol_info(manifest_x *mfx)
1075 {
1076         uiapplication_x *up = mfx->uiapplication;
1077         datacontrol_x *dc = NULL;
1078         int ret = -1;
1079         char query[MAX_QUERY_LEN] = {'\0'};
1080
1081         while(up != NULL)
1082         {
1083                 dc = up->datacontrol;
1084                 while(dc != NULL)
1085                 {
1086                         snprintf(query, MAX_QUERY_LEN,
1087                                         "insert into package_app_data_control(app_id, providerid, access, type) " \
1088                                         "values('%s', '%s', '%s', '%s')",\
1089                                         mfx->uiapplication->appid,
1090                                         dc->providerid,
1091                                         dc->access,
1092                                         dc->type);
1093
1094                         ret = __exec_query(query);
1095                         if (ret == -1) {
1096                                 _LOGD("Package UiApp Data Control DB Insert Failed\n");
1097                                 return -1;
1098                         }
1099                         memset(query, '\0', MAX_QUERY_LEN);
1100                         dc = dc->next;
1101                 }
1102                 up = up->next;
1103         }
1104         return 0;
1105 }
1106
1107 static int __insert_uiapplication_share_request_info(manifest_x *mfx)
1108 {
1109         uiapplication_x *up = mfx->uiapplication;
1110         datashare_x *ds = NULL;
1111         request_x *rq = NULL;
1112         int ret = -1;
1113         char query[MAX_QUERY_LEN] = {'\0'};
1114         while(up != NULL)
1115         {
1116                 ds = up->datashare;
1117                 while(ds != NULL)
1118                 {
1119                         rq = ds->request;
1120                         while(rq != NULL)
1121                         {
1122                                 snprintf(query, MAX_QUERY_LEN,
1123                                          "insert into package_app_share_request(app_id, data_share_request) " \
1124                                         "values('%s', '%s')",\
1125                                          up->appid, rq->text);
1126                                 ret = __exec_query(query);
1127                                 if (ret == -1) {
1128                                         _LOGD("Package UiApp Share Request DB Insert Failed\n");
1129                                         return -1;
1130                                 }
1131                                 memset(query, '\0', MAX_QUERY_LEN);
1132                                 rq = rq->next;
1133                         }
1134                         ds = ds->next;
1135                 }
1136                 up = up->next;
1137         }
1138         return 0;
1139 }
1140
1141 static int __insert_uiapplication_share_allowed_info(manifest_x *mfx)
1142 {
1143         uiapplication_x *up = mfx->uiapplication;
1144         datashare_x *ds = NULL;
1145         define_x *df = NULL;
1146         allowed_x *al = NULL;
1147         int ret = -1;
1148         char query[MAX_QUERY_LEN] = {'\0'};
1149         while(up != NULL)
1150         {
1151                 ds = up->datashare;
1152                 while(ds != NULL)
1153                 {
1154                         df = ds->define;
1155                         while(df != NULL)
1156                         {
1157                                 al = df->allowed;
1158                                 while(al != NULL)
1159                                 {
1160                                         snprintf(query, MAX_QUERY_LEN,
1161                                                  "insert into package_app_share_allowed(app_id, data_share_path, data_share_allowed) " \
1162                                                 "values('%s', '%s', '%s')",\
1163                                                  up->appid, df->path, al->text);
1164                                         ret = __exec_query(query);
1165                                         if (ret == -1) {
1166                                                 _LOGD("Package UiApp Share Allowed DB Insert Failed\n");
1167                                                 return -1;
1168                                         }
1169                                         memset(query, '\0', MAX_QUERY_LEN);
1170                                         al = al->next;
1171                                 }
1172                                 df = df->next;
1173                         }
1174                         ds = ds->next;
1175                 }
1176                 up = up->next;
1177         }
1178         return 0;
1179 }
1180
1181 static int __insert_serviceapplication_info(manifest_x *mfx)
1182 {
1183         serviceapplication_x *sp = mfx->serviceapplication;
1184         int ret = -1;
1185         char query[MAX_QUERY_LEN] = {'\0'};
1186         while(sp != NULL)
1187         {
1188                 snprintf(query, MAX_QUERY_LEN,
1189                          "insert into package_app_info(app_id, app_component, app_exec, app_type, app_onboot, " \
1190                         "app_multiple, app_autorestart, app_enabled, app_permissiontype, package) " \
1191                         "values('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",\
1192                          sp->appid, "svcapp", sp->exec, sp->type, sp->onboot, "\0",
1193                          sp->autorestart, sp->enabled, sp->permission_type, mfx->package);
1194                 ret = __exec_query(query);
1195                 if (ret == -1) {
1196                         _LOGD("Package ServiceApp Info DB Insert Failed\n");
1197                         return -1;
1198                 }
1199                 sp = sp->next;
1200                 memset(query, '\0', MAX_QUERY_LEN);
1201         }
1202         return 0;
1203 }
1204
1205 static int __insert_serviceapplication_appcategory_info(manifest_x *mfx)
1206 {
1207         serviceapplication_x *sp = mfx->serviceapplication;
1208         category_x *ct = NULL;
1209         int ret = -1;
1210         char query[MAX_QUERY_LEN] = {'\0'};
1211         while(sp != NULL)
1212         {
1213                 ct = sp->category;
1214                 while (ct != NULL)
1215                 {
1216                         snprintf(query, MAX_QUERY_LEN,
1217                                 "insert into package_app_app_category(app_id, category) " \
1218                                 "values('%s','%s')",\
1219                                  sp->appid, ct->name);
1220                         ret = __exec_query(query);
1221                         if (ret == -1) {
1222                                 _LOGD("Package ServiceApp Category Info DB Insert Failed\n");
1223                                 return -1;
1224                         }
1225                         ct = ct->next;
1226                         memset(query, '\0', MAX_QUERY_LEN);
1227                 }
1228                 sp = sp->next;
1229         }
1230         return 0;
1231 }
1232
1233 static int __insert_serviceapplication_appmetadata_info(manifest_x *mfx)
1234 {
1235         serviceapplication_x *sp = mfx->serviceapplication;
1236         metadata_x *md = NULL;
1237         int ret = -1;
1238         char query[MAX_QUERY_LEN] = {'\0'};
1239         while(sp != NULL)
1240         {
1241                 md = sp->metadata;
1242                 while (md != NULL)
1243                 {
1244                         if (md->key) {
1245                                 snprintf(query, MAX_QUERY_LEN,
1246                                         "insert into package_app_app_metadata(app_id, md_key, md_value) " \
1247                                         "values('%s','%s', '%s')",\
1248                                          sp->appid, md->key, md->value ? md->value : "");
1249                                 ret = __exec_query(query);
1250                                 if (ret == -1) {
1251                                         _LOGD("Package ServiceApp Metadata Info DB Insert Failed\n");
1252                                         return -1;
1253                                 }
1254                         }
1255                         md = md->next;
1256                         memset(query, '\0', MAX_QUERY_LEN);
1257                 }
1258                 sp = sp->next;
1259         }
1260         return 0;
1261 }
1262
1263 static int __insert_serviceapplication_apppermission_info(manifest_x *mfx)
1264 {
1265         serviceapplication_x *sp = mfx->serviceapplication;
1266         permission_x *pm = NULL;
1267         int ret = -1;
1268         char query[MAX_QUERY_LEN] = {'\0'};
1269         while(sp != NULL)
1270         {
1271                 pm = sp->permission;
1272                 while (pm != NULL)
1273                 {
1274                         snprintf(query, MAX_QUERY_LEN,
1275                                 "insert into package_app_app_permission(app_id, pm_type, pm_value) " \
1276                                 "values('%s','%s', '%s')",\
1277                                  sp->appid, pm->type, pm->value);
1278                         ret = __exec_query(query);
1279                         if (ret == -1) {
1280                                 _LOGD("Package ServiceApp permission Info DB Insert Failed\n");
1281                                 return -1;
1282                         }
1283                         pm = pm->next;
1284                         memset(query, '\0', MAX_QUERY_LEN);
1285                 }
1286                 sp = sp->next;
1287         }
1288         return 0;
1289 }
1290
1291 static int __insert_serviceapplication_appcontrol_info(manifest_x *mfx)
1292 {
1293         serviceapplication_x *sp = mfx->serviceapplication;
1294         appcontrol_x *acontrol = NULL;
1295         int ret = -1;
1296         char query[MAX_QUERY_LEN] = {'\0'};
1297         char buf[BUFSIZE] = {'\0'};
1298         while (sp != NULL) {
1299                 acontrol = sp->appcontrol;
1300                 while (acontrol != NULL) {
1301                         snprintf(buf, BUFSIZE, "%s|%s|%s",
1302                                         acontrol->operation ? (strlen(acontrol->operation) > 0 ? acontrol->operation : "NULL") : "NULL",
1303                                         acontrol->uri ? (strlen(acontrol->uri) > 0 ? acontrol->uri : "NULL") : "NULL",
1304                                         acontrol->mime ? (strlen(acontrol->mime) > 0 ? acontrol->mime : "NULL") : "NULL");
1305                         snprintf(query, MAX_QUERY_LEN,
1306                                         "insert into package_app_app_control(app_id, app_control) " \
1307                                         "values('%s', '%s')",\
1308                                         sp->appid, buf);
1309                         ret = __exec_query(query);
1310                         if (ret == -1) {
1311                                 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1312                                 return -1;
1313                         }
1314                         memset(query, '\0', MAX_QUERY_LEN);
1315                         acontrol = acontrol->next;
1316                 }
1317                 sp = sp->next;
1318         }
1319         return 0;
1320 }
1321
1322 static int __insert_serviceapplication_appsvc_info(manifest_x *mfx)
1323 {
1324         serviceapplication_x *sp = mfx->serviceapplication;
1325         appsvc_x *asvc = NULL;
1326         int ret = -1;
1327         char query[MAX_QUERY_LEN] = {'\0'};
1328         operation_x *op = NULL;
1329         mime_x *mi = NULL;
1330         uri_x *ui = NULL;
1331         subapp_x *sub = NULL;
1332         const char *operation = NULL;
1333         const char *mime = NULL;
1334         const char *uri = NULL;
1335         const char *subapp = NULL;
1336         while(sp != NULL)
1337         {
1338                 asvc = sp->appsvc;
1339                 while(asvc != NULL)
1340                 {
1341                         op = asvc->operation;
1342                         while(op != NULL)
1343                         {
1344                         if (op)
1345                                 operation = op->name;
1346                         mi = asvc->mime;
1347                                 do
1348                                 {
1349                                 if (mi)
1350                                         mime = mi->name;
1351                                 sub = asvc->subapp;
1352                                         do
1353                                         {
1354                                         if (sub)
1355                                                 subapp = sub->name;
1356                                         ui = asvc->uri;
1357                                                         do
1358                                                         {
1359                                                                 if (ui)
1360                                                                         uri = ui->name;
1361                                                                 snprintf(query, MAX_QUERY_LEN,
1362                                                                          "insert into package_app_app_svc(app_id, operation, uri_scheme, mime_type, subapp_name) " \
1363                                                                         "values('%s', '%s', '%s', '%s', '%s')",\
1364                                                                          sp->appid,
1365                                                                          operation,
1366                                                                         __get_str(uri),
1367                                                                         __get_str(mime),
1368                                                                         __get_str(subapp));
1369                                                                 ret = __exec_query(query);
1370                                                                 if (ret == -1) {
1371                                                                         _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1372                                                                         return -1;
1373                                                                 }
1374                                                                 memset(query, '\0', MAX_QUERY_LEN);
1375                                                                 if (ui)
1376                                                                         ui = ui->next;
1377                                                                 uri = NULL;
1378                                                         } while(ui != NULL);
1379                                                 if (sub)
1380                                                         sub     = sub->next;
1381                                                 subapp = NULL;
1382                                         }while(sub != NULL);
1383                                         if (mi)
1384                                                 mi = mi->next;
1385                                         mime = NULL;
1386                                 }while(mi != NULL);
1387                                 if (op)
1388                                         op = op->next;
1389                                 operation = NULL;
1390                         }
1391                         asvc = asvc->next;
1392                 }
1393                 sp = sp->next;
1394         }
1395         return 0;
1396 }
1397
1398 static int __insert_serviceapplication_datacontrol_info(manifest_x *mfx)
1399 {
1400         serviceapplication_x *sp = mfx->serviceapplication;
1401         datacontrol_x *dc = NULL;
1402         int ret = -1;
1403         char query[MAX_QUERY_LEN] = {'\0'};
1404
1405         while(sp != NULL)
1406         {
1407                 dc = sp->datacontrol;
1408                 while(dc != NULL)
1409                 {
1410                         snprintf(query, MAX_QUERY_LEN,
1411                                         "insert into package_app_data_control(app_id, providerid, access, type) " \
1412                                         "values('%s', '%s', '%s', '%s')",\
1413                                         mfx->serviceapplication->appid,
1414                                         dc->providerid,
1415                                         dc->access,
1416                                         dc->type);
1417
1418                         ret = __exec_query(query);
1419                         if (ret == -1) {
1420                                 _LOGD("Package ServiceApp Data Control DB Insert Failed\n");
1421                                 return -1;
1422                         }
1423                         memset(query, '\0', MAX_QUERY_LEN);
1424                         dc = dc->next;
1425                 }
1426                 sp = sp->next;
1427         }
1428         return 0;
1429 }
1430
1431 static int __insert_serviceapplication_share_request_info(manifest_x *mfx)
1432 {
1433         serviceapplication_x *sp = mfx->serviceapplication;
1434         datashare_x *ds = NULL;
1435         request_x *rq = NULL;
1436         int ret = -1;
1437         char query[MAX_QUERY_LEN] = {'\0'};
1438         while(sp != NULL)
1439         {
1440                 ds = sp->datashare;
1441                 while(ds != NULL)
1442                 {
1443                         rq = ds->request;
1444                         while(rq != NULL)
1445                         {
1446                                 snprintf(query, MAX_QUERY_LEN,
1447                                          "insert into package_app_share_request(app_id, data_share_request) " \
1448                                         "values('%s', '%s')",\
1449                                          sp->appid, rq->text);
1450                                 ret = __exec_query(query);
1451                                 if (ret == -1) {
1452                                         _LOGD("Package ServiceApp Share Request DB Insert Failed\n");
1453                                         return -1;
1454                                 }
1455                                 memset(query, '\0', MAX_QUERY_LEN);
1456                                 rq = rq->next;
1457                         }
1458                         ds = ds->next;
1459                 }
1460                 sp = sp->next;
1461         }
1462         return 0;
1463 }
1464
1465
1466
1467 static int __insert_serviceapplication_share_allowed_info(manifest_x *mfx)
1468 {
1469         serviceapplication_x *sp = mfx->serviceapplication;
1470         datashare_x *ds = NULL;
1471         define_x *df = NULL;
1472         allowed_x *al = NULL;
1473         int ret = -1;
1474         char query[MAX_QUERY_LEN] = {'\0'};
1475         while(sp != NULL)
1476         {
1477                 ds = sp->datashare;
1478                 while(ds != NULL)
1479                 {
1480                         df = ds->define;
1481                         while(df != NULL)
1482                         {
1483                                 al = df->allowed;
1484                                 while(al != NULL)
1485                                 {
1486                                         snprintf(query, MAX_QUERY_LEN,
1487                                                  "insert into package_app_share_allowed(app_id, data_share_path, data_share_allowed) " \
1488                                                 "values('%s', '%s', '%s')",\
1489                                                  sp->appid, df->path, al->text);
1490                                         ret = __exec_query(query);
1491                                         if (ret == -1) {
1492                                                 _LOGD("Package App Share Allowed DB Insert Failed\n");
1493                                                 return -1;
1494                                         }
1495                                         memset(query, '\0', MAX_QUERY_LEN);
1496                                         al = al->next;
1497                                 }
1498                                 df = df->next;
1499                         }
1500                         ds = ds->next;
1501                 }
1502                 sp = sp->next;
1503         }
1504         return 0;
1505 }
1506
1507 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid)
1508 {
1509         label_x *lbl = mfx->label;
1510         license_x *lcn = mfx->license;
1511         icon_x *icn = mfx->icon;
1512         description_x *dcn = mfx->description;
1513         author_x *ath = mfx->author;
1514         uiapplication_x *up = mfx->uiapplication;
1515         uiapplication_x *up_icn = mfx->uiapplication;
1516         uiapplication_x *up_image = mfx->uiapplication;
1517         serviceapplication_x *sp = mfx->serviceapplication;
1518         privileges_x *pvs = NULL;
1519         privilege_x *pv = NULL;
1520         char query[MAX_QUERY_LEN] = { '\0' };
1521         int ret = -1;
1522         const char *auth_name = NULL;
1523         const char *auth_email = NULL;
1524         const char *auth_href = NULL;
1525
1526         GList *pkglocale = NULL;
1527         GList *applocale = NULL;
1528         GList *appicon = NULL;
1529         GList *appimage = NULL;
1530
1531         if (ath) {
1532                 if (ath->text)
1533                         auth_name = ath->text;
1534                 if (ath->email)
1535                         auth_email = ath->email;
1536                 if (ath->href)
1537                         auth_href = ath->href;
1538         }
1539         /*Insert in the package_cert_info CERT_DB*/
1540         pkgmgrinfo_instcertinfo_h cert_handle = NULL;
1541         ret = pkgmgrinfo_set_cert_value(&cert_handle, PMINFO_SET_AUTHOR_ROOT_CERT, "author root certificate");
1542         if (ret != PMINFO_R_OK) {
1543                 pkgmgrinfo_destroy_certinfo_set_handle(cert_handle);
1544                 _LOGE("Cert Info DB create handle failed\n");
1545                 return -1;
1546         }
1547         ret = pkgmgrinfo_save_certinfo(mfx->package, &cert_handle, uid);
1548         if (ret != PMINFO_R_OK) {
1549                 pkgmgrinfo_destroy_certinfo_set_handle(cert_handle);
1550                 _LOGE("Cert Info DB Insert Failed\n");
1551                 return -1;
1552         }
1553
1554         /*Insert in the package_info DB*/
1555         snprintf(query, MAX_QUERY_LEN,
1556                  "insert into package_info(package, package_type, package_version, package_api_version, install_location, package_size, " \
1557                 "package_removable, package_preload, package_readonly, package_update, package_appsetting, package_nodisplay, package_system," \
1558                 "author_name, author_email, author_href, installed_time, installed_storage, storeclient_id, mainapp_id, package_url, root_path, csc_path, package_support_disable) " \
1559                 "values('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",\
1560                  mfx->package,
1561                  mfx->type,
1562                  mfx->version,
1563                  __get_str(mfx->api_version),
1564                  __get_str(mfx->installlocation),
1565                  __get_str(mfx->package_size),
1566                  mfx->removable,
1567                  mfx->preload,
1568                  mfx->readonly,
1569                  mfx->update,
1570                  mfx->appsetting,
1571                  mfx->nodisplay_setting,
1572                  mfx->system,
1573                  __get_str(auth_name),
1574                  __get_str(auth_email),
1575                  __get_str(auth_href),
1576                  mfx->installed_time,
1577                  mfx->installed_storage,
1578                  __get_str(mfx->storeclient_id),
1579                  mfx->mainapp_id,
1580                  __get_str(mfx->package_url),
1581                  mfx->root_path,
1582                  __get_str(mfx->csc_path),
1583                  mfx->support_disable);
1584
1585         ret = __exec_query(query);
1586         if (ret == -1) {
1587                 _LOGD("Package Info DB Insert Failed\n");
1588                 return -1;
1589         }
1590
1591         /*Insert in the package_privilege_info DB*/
1592         pvs = mfx->privileges;
1593         while (pvs != NULL) {
1594                 pv = pvs->privilege;
1595                 while (pv != NULL) {
1596                         memset(query, '\0', MAX_QUERY_LEN);
1597                         snprintf(query, MAX_QUERY_LEN,
1598                                 "insert into package_privilege_info(package, privilege) " \
1599                                 "values('%s','%s')",\
1600                                  mfx->package, pv->text);
1601                         ret = __exec_query(query);
1602                         if (ret == -1) {
1603                                 _LOGD("Package Privilege Info DB Insert Failed\n");
1604                                 return -1;
1605                         }
1606                         pv = pv->next;
1607                 }
1608                 pvs = pvs->next;
1609         }
1610
1611         if (up != NULL) {
1612                 ret = __insert_ui_mainapp_info(mfx);
1613                 if (ret == -1)
1614                         return -1;
1615         }
1616
1617         /*Insert the package locale*/
1618         pkglocale = __create_locale_list(pkglocale, lbl, lcn, icn, dcn, ath);
1619         /*remove duplicated data in pkglocale*/
1620         __trimfunc(pkglocale);
1621
1622         /*Insert the app locale info */
1623         while(up != NULL)
1624         {
1625                 applocale = __create_locale_list(applocale, up->label, NULL, up->icon, NULL, NULL);
1626                 up = up->next;
1627         }
1628         while(sp != NULL)
1629         {
1630                 applocale = __create_locale_list(applocale, sp->label, NULL, sp->icon, NULL, NULL);
1631                 sp = sp->next;
1632         }
1633         /*remove duplicated data in applocale*/
1634         __trimfunc(applocale);
1635
1636         /*Insert the app icon info */
1637         while(up_icn != NULL)
1638         {
1639                 appicon = __create_icon_list(appicon, up_icn->icon);
1640                 up_icn = up_icn->next;
1641         }
1642         /*remove duplicated data in appicon*/
1643         __trimfunc(appicon);
1644
1645         /*Insert the image info */
1646         while(up_image != NULL)
1647         {
1648                 appimage = __create_image_list(appimage, up_image->image);
1649                 up_image = up_image->next;
1650         }
1651         /*remove duplicated data in appimage*/
1652         __trimfunc(appimage);
1653
1654         g_list_foreach(pkglocale, __insert_pkglocale_info, (gpointer)mfx);
1655
1656         /*native app locale info*/
1657         up = mfx->uiapplication;
1658         while(up != NULL)
1659         {
1660                 g_list_foreach(applocale, __insert_uiapplication_locale_info, (gpointer)up);
1661                 up = up->next;
1662         }
1663         /*agent app locale info*/
1664         sp = mfx->serviceapplication;
1665         while(sp != NULL)
1666         {
1667                 g_list_foreach(applocale, __insert_serviceapplication_locale_info, (gpointer)sp);
1668                 sp = sp->next;
1669         }
1670
1671         /*app icon locale info*/
1672         up_icn = mfx->uiapplication;
1673         while(up_icn != NULL)
1674         {
1675                 g_list_foreach(appicon, __insert_uiapplication_icon_section_info, (gpointer)up_icn);
1676                 up_icn = up_icn->next;
1677         }
1678
1679         /*app image info*/
1680         up_image = mfx->uiapplication;
1681         while(up_image != NULL)
1682         {
1683                 g_list_foreach(appimage, __insert_uiapplication_image_info, (gpointer)up_image);
1684                 up_image = up_image->next;
1685         }
1686
1687         g_list_free(pkglocale);
1688         pkglocale = NULL;
1689         g_list_free(applocale);
1690         applocale = NULL;
1691         g_list_free(appicon);
1692         appicon = NULL;
1693         g_list_free(appimage);
1694         appimage = NULL;
1695
1696         /*Insert in the package_app_info DB*/
1697         ret = __insert_uiapplication_info(mfx);
1698         if (ret == -1)
1699                 return -1;
1700         ret = __insert_serviceapplication_info(mfx);
1701         if (ret == -1)
1702                 return -1;
1703         /*Insert in the package_app_app_control DB*/
1704         ret = __insert_uiapplication_appcontrol_info(mfx);
1705         if (ret == -1)
1706                 return -1;
1707         ret = __insert_serviceapplication_appcontrol_info(mfx);
1708         if (ret == -1)
1709                 return -1;
1710
1711         /*Insert in the package_app_app_category DB*/
1712         ret = __insert_uiapplication_appcategory_info(mfx);
1713         if (ret == -1)
1714                 return -1;
1715         ret = __insert_serviceapplication_appcategory_info(mfx);
1716         if (ret == -1)
1717                 return -1;
1718
1719         /*Insert in the package_app_app_metadata DB*/
1720         ret = __insert_uiapplication_appmetadata_info(mfx);
1721         if (ret == -1)
1722                 return -1;
1723         ret = __insert_serviceapplication_appmetadata_info(mfx);
1724         if (ret == -1)
1725                 return -1;
1726
1727         /*Insert in the package_app_app_permission DB*/
1728         ret = __insert_uiapplication_apppermission_info(mfx);
1729         if (ret == -1)
1730                 return -1;
1731         ret = __insert_serviceapplication_apppermission_info(mfx);
1732         if (ret == -1)
1733                 return -1;
1734
1735         /*Insert in the package_app_app_svc DB*/
1736         ret = __insert_uiapplication_appsvc_info(mfx);
1737         if (ret == -1)
1738                 return -1;
1739         ret = __insert_serviceapplication_appsvc_info(mfx);
1740         if (ret == -1)
1741                 return -1;
1742
1743         /*Insert in the package_app_share_allowed DB*/
1744         ret = __insert_uiapplication_share_allowed_info(mfx);
1745         if (ret == -1)
1746                 return -1;
1747         ret = __insert_serviceapplication_share_allowed_info(mfx);
1748         if (ret == -1)
1749                 return -1;
1750
1751         /*Insert in the package_app_share_request DB*/
1752         ret = __insert_uiapplication_share_request_info(mfx);
1753         if (ret == -1)
1754                 return -1;
1755         ret = __insert_serviceapplication_share_request_info(mfx);
1756         if (ret == -1)
1757                 return -1;
1758
1759         /*Insert in the package_app_data_control DB*/
1760         ret = __insert_uiapplication_datacontrol_info(mfx);
1761         if (ret == -1)
1762                 return -1;
1763         ret = __insert_serviceapplication_datacontrol_info(mfx);
1764         if (ret == -1)
1765                 return -1;
1766
1767         return 0;
1768
1769 }
1770
1771 static int __delete_appinfo_from_db(char *db_table, const char *appid)
1772 {
1773         char query[MAX_QUERY_LEN] = { '\0' };
1774         int ret = -1;
1775         memset(query, '\0', MAX_QUERY_LEN);
1776         snprintf(query, MAX_QUERY_LEN,
1777                  "delete from %s where app_id='%s'", db_table, appid);
1778         ret = __exec_query(query);
1779         if (ret == -1) {
1780                 _LOGD("DB Deletion from table (%s) Failed\n", db_table);
1781                 return -1;
1782         }
1783         return 0;
1784 }
1785
1786 static int __delete_subpkg_info_from_db(char *appid)
1787 {
1788         int ret = -1;
1789
1790         ret = __delete_appinfo_from_db("package_app_info", appid);
1791         if (ret < 0)
1792                 return ret;
1793         ret = __delete_appinfo_from_db("package_app_localized_info", appid);
1794         if (ret < 0)
1795                 return ret;
1796         ret = __delete_appinfo_from_db("package_app_icon_section_info", appid);
1797         if (ret < 0)
1798                 return ret;
1799         ret = __delete_appinfo_from_db("package_app_image_info", appid);
1800         if (ret < 0)
1801                 return ret;
1802         ret = __delete_appinfo_from_db("package_app_app_svc", appid);
1803         if (ret < 0)
1804                 return ret;
1805         ret = __delete_appinfo_from_db("package_app_app_control", appid);
1806         if (ret < 0)
1807                 return ret;
1808         ret = __delete_appinfo_from_db("package_app_app_category", appid);
1809         if (ret < 0)
1810                 return ret;
1811         ret = __delete_appinfo_from_db("package_app_app_metadata", appid);
1812         if (ret < 0)
1813                 return ret;
1814         ret = __delete_appinfo_from_db("package_app_app_permission", appid);
1815         if (ret < 0)
1816                 return ret;
1817         ret = __delete_appinfo_from_db("package_app_share_allowed", appid);
1818         if (ret < 0)
1819                 return ret;
1820         ret = __delete_appinfo_from_db("package_app_share_request", appid);
1821         if (ret < 0)
1822                 return ret;
1823         ret = __delete_appinfo_from_db("package_app_data_control", appid);
1824         if (ret < 0)
1825                 return ret;
1826
1827         return 0;
1828 }
1829
1830 static int __delete_subpkg_from_db(manifest_x *mfx)
1831 {
1832         char query[MAX_QUERY_LEN] = { '\0' };
1833         char *error_message = NULL;
1834
1835         snprintf(query, MAX_QUERY_LEN, "select app_id from package_app_info where package='%s'", mfx->package);
1836         if (SQLITE_OK !=
1837             sqlite3_exec(pkgmgr_parser_db, query, __delete_subpkg_list_cb, NULL, &error_message)) {
1838                 _LOGE("Don't execute query = %s error message = %s\n", query,
1839                        error_message);
1840                 sqlite3_free(error_message);
1841                 return -1;
1842         }
1843         sqlite3_free(error_message);
1844
1845         return 0;
1846 }
1847
1848 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid)
1849 {
1850         char query[MAX_QUERY_LEN] = { '\0' };
1851         int ret = -1;
1852         uiapplication_x *up = mfx->uiapplication;
1853         serviceapplication_x *sp = mfx->serviceapplication;
1854         /*Delete from cert table*/
1855         if (uid != GLOBAL_USER)
1856                 ret = pkgmgrinfo_delete_usr_certinfo(mfx->package, uid);
1857         else
1858                 ret = pkgmgrinfo_delete_certinfo(mfx->package);
1859         if (ret) {
1860                 _LOGD("Cert Info  DB Delete Failed\n");
1861                 return -1;
1862         }
1863
1864         /*Delete from Package Info DB*/
1865         snprintf(query, MAX_QUERY_LEN,
1866                  "delete from package_info where package='%s'", mfx->package);
1867         ret = __exec_query(query);
1868         if (ret == -1) {
1869                 _LOGD("Package Info DB Delete Failed\n");
1870                 return -1;
1871         }
1872         memset(query, '\0', MAX_QUERY_LEN);
1873
1874         /*Delete from Package Localized Info*/
1875         snprintf(query, MAX_QUERY_LEN,
1876                  "delete from package_localized_info where package='%s'", mfx->package);
1877         ret = __exec_query(query);
1878         if (ret == -1) {
1879                 _LOGD("Package Localized Info DB Delete Failed\n");
1880                 return -1;
1881         }
1882
1883         /*Delete from Package Privilege Info*/
1884         snprintf(query, MAX_QUERY_LEN,
1885                  "delete from package_privilege_info where package='%s'", mfx->package);
1886         ret = __exec_query(query);
1887         if (ret == -1) {
1888                 _LOGD("Package Privilege Info DB Delete Failed\n");
1889                 return -1;
1890         }
1891
1892         while (up != NULL) {
1893                 ret = __delete_appinfo_from_db("package_app_info", up->appid);
1894                 if (ret < 0)
1895                         return ret;
1896                 ret = __delete_appinfo_from_db("package_app_localized_info", up->appid);
1897                 if (ret < 0)
1898                         return ret;
1899                 ret = __delete_appinfo_from_db("package_app_icon_section_info", up->appid);
1900                 if (ret < 0)
1901                         return ret;
1902                 ret = __delete_appinfo_from_db("package_app_image_info", up->appid);
1903                 if (ret < 0)
1904                         return ret;
1905                 ret = __delete_appinfo_from_db("package_app_app_svc", up->appid);
1906                 if (ret < 0)
1907                         return ret;
1908                 ret = __delete_appinfo_from_db("package_app_app_control", up->appid);
1909                 if (ret < 0)
1910                         return ret;
1911                 ret = __delete_appinfo_from_db("package_app_app_category", up->appid);
1912                 if (ret < 0)
1913                         return ret;
1914                 ret = __delete_appinfo_from_db("package_app_app_metadata", up->appid);
1915                 if (ret < 0)
1916                         return ret;
1917                 ret = __delete_appinfo_from_db("package_app_app_permission", up->appid);
1918                 if (ret < 0)
1919                         return ret;
1920                 ret = __delete_appinfo_from_db("package_app_share_allowed", up->appid);
1921                 if (ret < 0)
1922                         return ret;
1923                 ret = __delete_appinfo_from_db("package_app_share_request", up->appid);
1924                 if (ret < 0)
1925                         return ret;
1926                 ret = __delete_appinfo_from_db("package_app_data_control", up->appid);
1927                 if (ret < 0)
1928                         return ret;
1929                 up = up->next;
1930         }
1931
1932         while (sp != NULL) {
1933                 ret = __delete_appinfo_from_db("package_app_info", sp->appid);
1934                 if (ret < 0)
1935                         return ret;
1936                 ret = __delete_appinfo_from_db("package_app_localized_info", sp->appid);
1937                 if (ret < 0)
1938                         return ret;
1939                 ret = __delete_appinfo_from_db("package_app_icon_section_info", sp->appid);
1940                 if (ret < 0)
1941                         return ret;
1942                 ret = __delete_appinfo_from_db("package_app_image_info", sp->appid);
1943                 if (ret < 0)
1944                         return ret;
1945                 ret = __delete_appinfo_from_db("package_app_app_svc", sp->appid);
1946                 if (ret < 0)
1947                         return ret;
1948                 ret = __delete_appinfo_from_db("package_app_app_control", sp->appid);
1949                 if (ret < 0)
1950                         return ret;
1951                 ret = __delete_appinfo_from_db("package_app_app_category", sp->appid);
1952                 if (ret < 0)
1953                         return ret;
1954                 ret = __delete_appinfo_from_db("package_app_app_metadata", sp->appid);
1955                 if (ret < 0)
1956                         return ret;
1957                 ret = __delete_appinfo_from_db("package_app_app_permission", sp->appid);
1958                 if (ret < 0)
1959                         return ret;
1960                 ret = __delete_appinfo_from_db("package_app_share_allowed", sp->appid);
1961                 if (ret < 0)
1962                         return ret;
1963                 ret = __delete_appinfo_from_db("package_app_share_request", sp->appid);
1964                 if (ret < 0)
1965                         return ret;
1966                 ret = __delete_appinfo_from_db("package_app_data_control", sp->appid);
1967                 if (ret < 0)
1968                         return ret;
1969                 sp = sp->next;
1970         }
1971
1972         /* if main package has sub pkg, delete sub pkg data*/
1973         __delete_subpkg_from_db(mfx);
1974
1975         return 0;
1976 }
1977
1978 static int __update_preload_condition_in_db()
1979 {
1980         int ret = -1;
1981         char query[MAX_QUERY_LEN] = {'\0'};
1982
1983         snprintf(query, MAX_QUERY_LEN, "update package_info set package_preload='true'");
1984
1985         ret = __exec_query(query);
1986         if (ret == -1)
1987                 _LOGD("Package preload_condition update failed\n");
1988
1989         return ret;
1990 }
1991
1992 API int pkgmgr_parser_initialize_db(uid_t uid)
1993 {
1994         int ret = -1;
1995         /*Manifest DB*/
1996         ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_INFO);
1997         if (ret == -1) {
1998                 _LOGD("package info DB initialization failed\n");
1999                 return ret;
2000         }
2001         ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO);
2002         if (ret == -1) {
2003                 _LOGD("package localized info DB initialization failed\n");
2004                 return ret;
2005         }
2006         ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO);
2007         if (ret == -1) {
2008                 _LOGD("package app app privilege DB initialization failed\n");
2009                 return ret;
2010         }
2011         ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_INFO);
2012         if (ret == -1) {
2013                 _LOGD("package app info DB initialization failed\n");
2014                 return ret;
2015         }
2016         ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO);
2017         if (ret == -1) {
2018                 _LOGD("package app localized info DB initialization failed\n");
2019                 return ret;
2020         }
2021         ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO);
2022         if (ret == -1) {
2023                 _LOGD("package app icon localized info DB initialization failed\n");
2024                 return ret;
2025         }
2026         ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO);
2027         if (ret == -1) {
2028                 _LOGD("package app image info DB initialization failed\n");
2029                 return ret;
2030         }
2031         ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL);
2032         if (ret == -1) {
2033                 _LOGD("package app app control DB initialization failed\n");
2034                 return ret;
2035         }
2036         ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY);
2037         if (ret == -1) {
2038                 _LOGD("package app app category DB initialization failed\n");
2039                 return ret;
2040         }
2041         ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA);
2042         if (ret == -1) {
2043                 _LOGD("package app app category DB initialization failed\n");
2044                 return ret;
2045         }
2046         ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION);
2047         if (ret == -1) {
2048                 _LOGD("package app app permission DB initialization failed\n");
2049                 return ret;
2050         }
2051         ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_SVC);
2052         if (ret == -1) {
2053                 _LOGD("package app app svc DB initialization failed\n");
2054                 return ret;
2055         }
2056         ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED);
2057         if (ret == -1) {
2058                 _LOGD("package app share allowed DB initialization failed\n");
2059                 return ret;
2060         }
2061         ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST);
2062         if (ret == -1) {
2063                 _LOGD("package app share request DB initialization failed\n");
2064                 return ret;
2065         }
2066         ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL);
2067         if (ret == -1) {
2068                 _LOGD("package app data control DB initialization failed\n");
2069                 return ret;
2070         }
2071         /*Cert DB*/
2072         ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INFO);
2073         if (ret == -1) {
2074                 _LOGD("package cert info DB initialization failed\n");
2075                 return ret;
2076         }
2077         ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO);
2078         if (ret == -1) {
2079                 _LOGD("package cert index info DB initialization failed\n");
2080                 return ret;
2081         }
2082         
2083         if( 0 != __parserdb_change_perm(getUserPkgCertDBPathUID(uid), uid)) {
2084                 _LOGD("Failed to change cert db permission\n");
2085         }
2086         if( 0 != __parserdb_change_perm(getUserPkgParserDBPathUID(uid), uid)) {
2087                 _LOGD("Failed to change parser db permission\n");
2088         }
2089
2090         return 0;
2091 }
2092
2093 static int __parserdb_change_perm(const char *db_file, uid_t uid)
2094 {
2095         char buf[BUFSIZE];
2096         char journal_file[BUFSIZE];
2097         char *files[3];
2098         int ret, i;
2099         struct passwd *userinfo = NULL;
2100         files[0] = (char *)db_file;
2101         files[1] = journal_file;
2102         files[2] = NULL;
2103
2104         if (db_file == NULL)
2105                 return -1;
2106
2107         if (getuid() != OWNER_ROOT) //At this time we should be root to apply this
2108                 return 0;
2109         snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
2110         if (uid == OWNER_ROOT)
2111                 uid = GLOBAL_USER;
2112         userinfo = getpwuid(uid);
2113         if (!userinfo) {
2114                 _LOGE("FAIL: user %d doesn't exist", uid);
2115                 return -1;
2116         }
2117         snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
2118
2119         for (i = 0; files[i]; i++) {
2120                 ret = chown(files[i], uid, userinfo->pw_gid);
2121                 if (ret == -1) {
2122                         if (strerror_r(errno, buf, sizeof(buf)))
2123                                 strcpy(buf, "");
2124                         _LOGD("FAIL : chown %s %d.%d : %s", files[i], uid,
2125                                         userinfo->pw_gid, buf);
2126                         return -1;
2127                 }
2128
2129                 ret = chmod(files[i], S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
2130                 if (ret == -1) {
2131                         if (strerror_r(errno, buf, sizeof(buf)))
2132                                 strcpy(buf, "");
2133                         _LOGD("FAIL : chmod %s 0664 : %s", files[i], buf);
2134                         return -1;
2135                 }
2136                 SET_SMACK_LABEL(files[i]);
2137         }
2138         return 0;
2139 }
2140
2141 API int pkgmgr_parser_create_and_initialize_db(uid_t uid)
2142 {
2143         int ret;
2144
2145         if (getuid() != OWNER_ROOT) {
2146                 _LOGE("Only root user is allowed");
2147                 return -1;
2148         }
2149
2150         if (access(getUserPkgParserDBPathUID(uid), F_OK) != -1) {
2151                 _LOGE("Manifest db for user %d is already exists", uid);
2152                 return -1;
2153         }
2154
2155         if (access(getUserPkgCertDBPathUID(uid), F_OK) != -1) {
2156                 _LOGE("Cert db for user %d is already exists", uid);
2157                 return -1;
2158         }
2159
2160         ret = pkgmgr_parser_check_and_create_db(uid);
2161         if (ret < 0)
2162                 return -1;
2163         ret = pkgmgr_parser_initialize_db(uid);
2164         if (ret < 0) {
2165                 pkgmgr_parser_close_db();
2166                 return -1;
2167         }
2168         pkgmgr_parser_close_db();
2169
2170         return 0;
2171 }
2172
2173 API int pkgmgr_parser_check_and_create_db(uid_t uid)
2174 {
2175         int ret = -1;
2176         /*Manifest DB*/
2177         ret = __pkgmgr_parser_create_db(&pkgmgr_parser_db, getUserPkgParserDBPathUID(uid));
2178         if (ret) {
2179                 _LOGD("Manifest DB creation Failed\n");
2180                 return -1;
2181         }
2182
2183         /*Cert DB*/
2184         ret = __pkgmgr_parser_create_db(&pkgmgr_cert_db, getUserPkgCertDBPathUID(uid));
2185         if (ret) {
2186                 _LOGD("Cert DB creation Failed\n");
2187                 return -1;
2188         }
2189         return 0;
2190 }
2191
2192 void pkgmgr_parser_close_db(void)
2193 {
2194         sqlite3_close(pkgmgr_parser_db);
2195         sqlite3_close(pkgmgr_cert_db);
2196 }
2197
2198
2199 API int pkgmgr_parser_insert_manifest_info_in_db(manifest_x *mfx)
2200 {
2201         _LOGD("pkgmgr_parser_insert_manifest_info_in_db\n");
2202         if (mfx == NULL) {
2203                 _LOGD("manifest pointer is NULL\n");
2204                 return -1;
2205         }
2206         int ret = 0;
2207         ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2208         if (ret == -1) {
2209                 _LOGD("Failed to open DB\n");
2210                 return ret;
2211         }
2212         ret = pkgmgr_parser_initialize_db(GLOBAL_USER);
2213         if (ret == -1)
2214                 goto err;
2215         /*Begin transaction*/
2216         ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2217         if (ret != SQLITE_OK) {
2218                 _LOGD("Failed to begin transaction\n");
2219                 ret = -1;
2220                 goto err;
2221         }
2222         _LOGD("Transaction Begin\n");
2223         ret = __insert_manifest_info_in_db(mfx, GLOBAL_USER);
2224         if (ret == -1) {
2225                 _LOGD("Insert into DB failed. Rollback now\n");
2226                 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2227                 goto err;
2228         }
2229         /*Commit transaction*/
2230         ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2231         if (ret != SQLITE_OK) {
2232                 _LOGD("Failed to commit transaction. Rollback now\n");
2233                 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2234                 ret = -1;
2235                 goto err;
2236         }
2237         _LOGD("Transaction Commit and End\n");
2238 err:
2239         pkgmgr_parser_close_db();
2240         return ret;
2241 }
2242
2243 API int pkgmgr_parser_insert_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2244 {
2245         _LOGD("pkgmgr_parser_insert_manifest_info_in_usr_db\n");
2246         if (mfx == NULL) {
2247                 _LOGD("manifest pointer is NULL\n");
2248                 return -1;
2249         }
2250         int ret = 0;
2251         ret = pkgmgr_parser_check_and_create_db(uid);
2252         if (ret == -1) {
2253                 _LOGD("Failed to open DB\n");
2254                 return ret;
2255         }
2256         ret = pkgmgr_parser_initialize_db(uid);
2257         if (ret == -1)
2258                 goto err;
2259         /*Begin transaction*/
2260         ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2261         if (ret != SQLITE_OK) {
2262                 _LOGD("Failed to begin transaction\n");
2263                 ret = -1;
2264                 goto err;
2265         }
2266         _LOGD("Transaction Begin\n");
2267         ret = __insert_manifest_info_in_db(mfx, uid);
2268         if (ret == -1) {
2269                 _LOGD("Insert into DB failed. Rollback now\n");
2270                 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2271                 goto err;
2272         }
2273         /*Commit transaction*/
2274         ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2275         if (ret != SQLITE_OK) {
2276                 _LOGD("Failed to commit transaction. Rollback now\n");
2277                 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2278                 ret = -1;
2279                 goto err;
2280         }
2281         _LOGD("Transaction Commit and End\n");
2282 err:
2283         pkgmgr_parser_close_db();
2284         return ret;
2285 }
2286
2287 API int pkgmgr_parser_update_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2288 {
2289         if (mfx == NULL) {
2290                 _LOGD("manifest pointer is NULL\n");
2291                 return -1;
2292         }
2293         int ret = 0;
2294         ret = pkgmgr_parser_check_and_create_db(uid);
2295         if (ret == -1) {
2296                 _LOGD("Failed to open DB\n");
2297                 return ret;
2298         }
2299         ret = pkgmgr_parser_initialize_db(uid);
2300         if (ret == -1)
2301                 goto err;
2302         /*Preserve guest mode visibility*/
2303         __preserve_guestmode_visibility_value( mfx);
2304         /*Begin transaction*/
2305         ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2306         if (ret != SQLITE_OK) {
2307                 _LOGD("Failed to begin transaction\n");
2308                 ret = -1;
2309                 goto err;
2310         }
2311         _LOGD("Transaction Begin\n");
2312         ret = __delete_manifest_info_from_db(mfx, uid);
2313         if (ret == -1) {
2314                 _LOGD("Delete from DB failed. Rollback now\n");
2315                 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2316                 goto err;
2317         }
2318         ret = __insert_manifest_info_in_db(mfx, uid);
2319         if (ret == -1) {
2320                 _LOGD("Insert into DB failed. Rollback now\n");
2321                 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2322                 goto err;
2323         }
2324
2325         /*Commit transaction*/
2326         ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2327         if (ret != SQLITE_OK) {
2328                 _LOGD("Failed to commit transaction. Rollback now\n");
2329                 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2330                 ret = -1;
2331                 goto err;
2332         }
2333         _LOGD("Transaction Commit and End\n");
2334 err:
2335         pkgmgr_parser_close_db();
2336         return ret;
2337 }
2338
2339 API int pkgmgr_parser_update_manifest_info_in_db(manifest_x *mfx)
2340 {
2341         return pkgmgr_parser_update_manifest_info_in_usr_db(mfx, GLOBAL_USER);
2342 }
2343
2344 API int pkgmgr_parser_delete_manifest_info_from_usr_db(manifest_x *mfx, uid_t uid)
2345 {
2346         if (mfx == NULL) {
2347                 _LOGD("manifest pointer is NULL\n");
2348                 return -1;
2349         }
2350         int ret = 0;
2351         ret = pkgmgr_parser_check_and_create_db(uid);
2352         if (ret == -1) {
2353                 _LOGD("Failed to open DB\n");
2354                 return ret;
2355         }
2356         /*Begin transaction*/
2357         ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2358         if (ret != SQLITE_OK) {
2359                 _LOGD("Failed to begin transaction\n");
2360                 ret = -1;
2361                 goto err;
2362         }
2363         _LOGD("Transaction Begin\n");
2364         ret = __delete_manifest_info_from_db(mfx, uid);
2365         if (ret == -1) {
2366                 _LOGD("Delete from DB failed. Rollback now\n");
2367                 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2368                 goto err;
2369         }
2370         /*Commit transaction*/
2371         ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2372         if (ret != SQLITE_OK) {
2373                 _LOGD("Failed to commit transaction, Rollback now\n");
2374                 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2375                 ret = -1;
2376                 goto err;
2377         }
2378         _LOGD("Transaction Commit and End\n");
2379 err:
2380         pkgmgr_parser_close_db();
2381         return ret;
2382 }
2383
2384 API int pkgmgr_parser_delete_manifest_info_from_db(manifest_x *mfx)
2385 {
2386         return pkgmgr_parser_delete_manifest_info_from_usr_db(mfx, GLOBAL_USER);
2387 }
2388
2389 API int pkgmgr_parser_update_preload_info_in_db()
2390 {
2391         int ret = 0;
2392         ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2393         if (ret == -1) {
2394                 _LOGD("Failed to open DB\n");
2395                 return ret;
2396         }
2397         /*Begin transaction*/
2398         ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2399         if (ret != SQLITE_OK) {
2400                 _LOGD("Failed to begin transaction\n");
2401                 ret = -1;
2402                 goto err;
2403         }
2404         _LOGD("Transaction Begin\n");
2405         ret = __update_preload_condition_in_db();
2406         if (ret == -1) {
2407                 _LOGD("__update_preload_condition_in_db failed. Rollback now\n");
2408                 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2409                 goto err;
2410         }
2411         /*Commit transaction*/
2412         ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2413         if (ret != SQLITE_OK) {
2414                 _LOGD("Failed to commit transaction, Rollback now\n");
2415                 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2416                 ret = -1;
2417                 goto err;
2418         }
2419         _LOGD("Transaction Commit and End\n");
2420 err:
2421         pkgmgr_parser_close_db();
2422         return ret;
2423 }
2424
2425 API int pkgmgr_parser_update_preload_info_in_usr_db(uid_t uid)
2426 {
2427         int ret = 0;
2428         ret = pkgmgr_parser_check_and_create_db(uid);
2429         if (ret == -1) {
2430                 _LOGD("Failed to open DB\n");
2431                 return ret;
2432         }
2433         /*Begin transaction*/
2434         ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2435         if (ret != SQLITE_OK) {
2436                 _LOGD("Failed to begin transaction\n");
2437                 ret = -1;
2438                 goto err;
2439         }
2440         _LOGD("Transaction Begin\n");
2441         ret = __update_preload_condition_in_db();
2442         if (ret == -1) {
2443                 _LOGD("__update_preload_condition_in_db failed. Rollback now\n");
2444                 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2445                 goto err;
2446         }
2447         /*Commit transaction*/
2448         ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2449         if (ret != SQLITE_OK) {
2450                 _LOGD("Failed to commit transaction, Rollback now\n");
2451                 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2452                 ret = -1;
2453                 goto err;
2454         }
2455         _LOGD("Transaction Commit and End\n");
2456 err:
2457         pkgmgr_parser_close_db();
2458         return ret;
2459 }