4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
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>
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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.
26 #include <sys/types.h>
31 #include "pkgmgr-info.h"
32 #include "pkgmgr_parser_internal.h"
33 #include "pkgmgr_parser_db.h"
35 #define PKGMGR_PARSER_DB_FILE "/opt/dbspace/.pkgmgr_parser.db"
36 #define PKGMGR_CERT_DB_FILE "/opt/dbspace/.pkgmgr_cert.db"
37 #define MAX_QUERY_LEN 4096
38 sqlite3 *pkgmgr_parser_db;
39 sqlite3 *pkgmgr_cert_db;
40 GList *pkglocale = NULL;
41 GList *applocale = NULL;
42 GList *appicon = NULL;
43 GList *appimage = NULL;
46 #define QUERY_CREATE_TABLE_PACKAGE_INFO "create table if not exists package_info " \
47 "(package text primary key not null, " \
48 "package_type text DEFAULT 'rpm', " \
49 "package_version text, " \
50 "install_location text, " \
51 "package_size text, " \
52 "package_removable text DEFAULT 'true', " \
53 "package_preload text DEFAULT 'false', " \
54 "package_readonly text DEFAULT 'false', " \
55 "package_update text DEFAULT 'false', " \
56 "package_appsetting text DEFAULT 'false', " \
57 "package_nodisplay text DEFAULT 'false', " \
58 "author_name text, " \
59 "author_email text, " \
61 "installed_time text," \
62 "installed_storage text," \
63 "storeclient_id text," \
69 #define QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO "create table if not exists package_localized_info " \
70 "(package text not null, " \
71 "package_locale text DEFAULT 'No Locale', " \
72 "package_label text, " \
73 "package_icon text, " \
74 "package_description text, " \
75 "package_license text, " \
77 "PRIMARY KEY(package, package_locale), " \
78 "FOREIGN KEY(package) " \
79 "REFERENCES package_info(package) " \
82 #define QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO "create table if not exists package_privilege_info " \
83 "(package text not null, " \
84 "privilege text not null, " \
85 "PRIMARY KEY(package, privilege) " \
86 "FOREIGN KEY(package) " \
87 "REFERENCES package_info(package) " \
90 #define QUERY_CREATE_TABLE_PACKAGE_APP_INFO "create table if not exists package_app_info " \
91 "(app_id text primary key not null, " \
92 "app_component text, " \
94 "app_nodisplay text DEFAULT 'false', " \
96 "app_onboot text DEFAULT 'false', " \
97 "app_multiple text DEFAULT 'false', " \
98 "app_autorestart text DEFAULT 'false', " \
99 "app_taskmanage text DEFAULT 'false', " \
100 "app_enabled text DEFAULT 'true', " \
101 "app_hwacceleration text DEFAULT 'use-system-setting', " \
102 "app_screenreader text DEFAULT 'use-system-setting', " \
103 "app_mainapp text, " \
104 "app_recentimage text, " \
105 "app_launchcondition text, " \
106 "app_indicatordisplay text DEFAULT 'true', " \
107 "app_portraitimg text, " \
108 "app_landscapeimg text, " \
109 "app_guestmodevisibility text DEFAULT 'true', " \
110 "app_permissiontype text DEFAULT 'normal', " \
111 "app_preload text DEFAULT 'false', " \
112 "app_submode text DEFAULT 'false', " \
113 "app_submode_mainid text, " \
114 "component_type text, " \
115 "package text not null, " \
116 "FOREIGN KEY(package) " \
117 "REFERENCES package_info(package) " \
120 #define QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO "create table if not exists package_app_localized_info " \
121 "(app_id text not null, " \
122 "app_locale text DEFAULT 'No Locale', " \
125 "PRIMARY KEY(app_id,app_locale) " \
126 "FOREIGN KEY(app_id) " \
127 "REFERENCES package_app_info(app_id) " \
130 #define QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO "create table if not exists package_app_icon_section_info " \
131 "(app_id text not null, " \
133 "app_icon_section text, " \
134 "app_icon_resolution text, " \
135 "PRIMARY KEY(app_id,app_icon_section,app_icon_resolution) " \
136 "FOREIGN KEY(app_id) " \
137 "REFERENCES package_app_info(app_id) " \
140 #define QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO "create table if not exists package_app_image_info " \
141 "(app_id text not null, " \
142 "app_locale text DEFAULT 'No Locale', " \
143 "app_image_section text, " \
145 "PRIMARY KEY(app_id,app_image_section) " \
146 "FOREIGN KEY(app_id) " \
147 "REFERENCES package_app_info(app_id) " \
150 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL "create table if not exists package_app_app_control " \
151 "(app_id text not null, " \
152 "operation text not null, " \
153 "uri_scheme text, " \
155 "subapp_name text, " \
156 "PRIMARY KEY(app_id,operation,uri_scheme,mime_type,subapp_name) " \
157 "FOREIGN KEY(app_id) " \
158 "REFERENCES package_app_info(app_id) " \
161 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_SVC "create table if not exists package_app_app_svc " \
162 "(app_id text not null, " \
163 "operation text not null, " \
164 "uri_scheme text, " \
166 "subapp_name text, " \
167 "PRIMARY KEY(app_id,operation,uri_scheme,mime_type,subapp_name) " \
168 "FOREIGN KEY(app_id) " \
169 "REFERENCES package_app_info(app_id) " \
172 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY "create table if not exists package_app_app_category " \
173 "(app_id text not null, " \
174 "category text not null, " \
175 "PRIMARY KEY(app_id,category) " \
176 "FOREIGN KEY(app_id) " \
177 "REFERENCES package_app_info(app_id) " \
180 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA "create table if not exists package_app_app_metadata " \
181 "(app_id text not null, " \
182 "md_key text not null, " \
183 "md_value text not null, " \
184 "PRIMARY KEY(app_id, md_key, md_value) " \
185 "FOREIGN KEY(app_id) " \
186 "REFERENCES package_app_info(app_id) " \
189 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION "create table if not exists package_app_app_permission " \
190 "(app_id text not null, " \
191 "pm_type text not null, " \
192 "pm_value text not null, " \
193 "PRIMARY KEY(app_id, pm_type, pm_value) " \
194 "FOREIGN KEY(app_id) " \
195 "REFERENCES package_app_info(app_id) " \
198 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED "create table if not exists package_app_share_allowed " \
199 "(app_id text not null, " \
200 "data_share_path text not null, " \
201 "data_share_allowed text not null, " \
202 "PRIMARY KEY(app_id,data_share_path,data_share_allowed) " \
203 "FOREIGN KEY(app_id) " \
204 "REFERENCES package_app_info(app_id) " \
207 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST "create table if not exists package_app_share_request " \
208 "(app_id text not null, " \
209 "data_share_request text not null, " \
210 "PRIMARY KEY(app_id,data_share_request) " \
211 "FOREIGN KEY(app_id) " \
212 "REFERENCES package_app_info(app_id) " \
215 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO "create table if not exists package_cert_index_info " \
216 "(cert_info text not null, " \
217 "cert_id integer, " \
218 "cert_ref_count integer, " \
219 "PRIMARY KEY(cert_id)) "
221 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INFO "create table if not exists package_cert_info " \
222 "(package text not null, " \
223 "author_root_cert integer, " \
224 "author_im_cert integer, " \
225 "author_signer_cert integer, " \
226 "dist_root_cert integer, " \
227 "dist_im_cert integer, " \
228 "dist_signer_cert integer, " \
229 "dist2_root_cert integer, " \
230 "dist2_im_cert integer, " \
231 "dist2_signer_cert integer, " \
232 "PRIMARY KEY(package)) "
234 static int __insert_uiapplication_info(manifest_x *mfx);
235 static int __insert_serviceapplication_info(manifest_x *mfx);
236 static int __insert_uiapplication_appsvc_info(manifest_x *mfx);
237 static int __insert_serviceapplication_appsvc_info(manifest_x *mfx);
238 static int __insert_uiapplication_appcategory_info(manifest_x *mfx);
239 static int __insert_serviceapplication_appcategory_info(manifest_x *mfx);
240 static int __insert_uiapplication_appcontrol_info(manifest_x *mfx);
241 static int __insert_serviceapplication_appmetadata_info(manifest_x *mfx);
242 static int __insert_uiapplication_appmetadata_info(manifest_x *mfx);
243 static int __insert_serviceapplication_appcontrol_info(manifest_x *mfx);
244 static int __insert_uiapplication_share_allowed_info(manifest_x *mfx);
245 static int __insert_serviceapplication_share_allowed_info(manifest_x *mfx);
246 static int __insert_uiapplication_share_request_info(manifest_x *mfx);
247 static int __insert_serviceapplication_share_request_info(manifest_x *mfx);
248 static void __insert_serviceapplication_locale_info(gpointer data, gpointer userdata);
249 static void __insert_uiapplication_locale_info(gpointer data, gpointer userdata);
250 static void __insert_pkglocale_info(gpointer data, gpointer userdata);
251 static int __insert_manifest_info_in_db(manifest_x *mfx);
252 static int __delete_manifest_info_from_db(manifest_x *mfx);
253 static int __delete_appinfo_from_db(char *db_table, const char *appid);
254 static int __initialize_db(sqlite3 *db_handle, const char *db_query);
255 static int __exec_query(char *query);
256 static void __extract_data(gpointer data, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath,
257 char **label, char **license, char **icon, char **description, char **author);
258 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata);
259 static void __trimfunc1(gpointer data, gpointer userdata);
260 static void __trimfunc2(gpointer data, gpointer userdata);
261 static GList *__create_locale_list(GList *locale, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath);
262 static void __preserve_guestmode_visibility_value(manifest_x *mfx);
263 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname);
264 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path);
266 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path)
270 if (access(db_path, F_OK) == 0) {
272 db_util_open(db_path, &handle,
273 DB_UTIL_REGISTER_HOOK_METHOD);
274 if (ret != SQLITE_OK) {
275 DBG("connect db [%s] failed!\n",
282 DBG("%s DB does not exists. Create one!!\n", db_path);
285 db_util_open(db_path, &handle,
286 DB_UTIL_REGISTER_HOOK_METHOD);
288 if (ret != SQLITE_OK) {
289 DBG("connect db [%s] failed!\n", db_path);
296 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname)
298 manifest_x *mfx = (manifest_x *)data;
302 uiapplication_x *uiapp = NULL;
303 for(i = 0; i < ncols; i++)
305 uiapp = mfx->uiapplication;
306 if (strcmp(colname[i], "app_id") == 0) {
308 appid = strdup(coltxt[i]);
309 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0) {
311 status = strdup(coltxt[i]);
315 DBG("app id is NULL\n");
318 /*update guest mode visibility*/
319 for (; uiapp != NULL; uiapp = uiapp->next) {
320 if (strcmp(uiapp->appid, appid) == 0) {
321 free((void *)uiapp->guestmode_visibility);
322 uiapp->guestmode_visibility = strdup(status);
338 static void __preserve_guestmode_visibility_value(manifest_x *mfx)
340 char *error_message = NULL;
341 char query[MAX_QUERY_LEN] = {'\0'};
342 snprintf(query, MAX_QUERY_LEN - 1, "select app_id, app_guestmodevisibility from package_app_info where package='%s'", mfx->package);
344 sqlite3_exec(pkgmgr_parser_db, query,
345 __guestmode_visibility_cb, (void *)mfx, &error_message)) {
346 DBG("Don't execute query = %s error message = %s\n",
347 query, error_message);
348 sqlite3_free(error_message);
353 static int __initialize_db(sqlite3 *db_handle, const char *db_query)
355 char *error_message = NULL;
357 sqlite3_exec(db_handle, db_query,
358 NULL, NULL, &error_message)) {
359 DBG("Don't execute query = %s error message = %s\n",
360 db_query, error_message);
361 sqlite3_free(error_message);
364 sqlite3_free(error_message);
368 static int __exec_query(char *query)
370 char *error_message = NULL;
372 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
373 DBG("Don't execute query = %s error message = %s\n", query,
375 sqlite3_free(error_message);
378 sqlite3_free(error_message);
382 static int __exec_query_no_msg(char *query)
384 char *error_message = NULL;
386 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
387 sqlite3_free(error_message);
390 sqlite3_free(error_message);
394 static GList *__create_locale_list(GList *locale, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath)
400 locale = g_list_insert_sorted_with_data(locale, (gpointer)lbl->lang, __comparefunc, NULL);
406 locale = g_list_insert_sorted_with_data(locale, (gpointer)lcn->lang, __comparefunc, NULL);
412 locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->lang, __comparefunc, NULL);
418 locale = g_list_insert_sorted_with_data(locale, (gpointer)dcn->lang, __comparefunc, NULL);
424 locale = g_list_insert_sorted_with_data(locale, (gpointer)ath->lang, __comparefunc, NULL);
431 static GList *__create_icon_list(GList *locale, icon_x *icn)
436 locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->section, __comparefunc, NULL);
442 static GList *__create_image_list(GList *locale, image_x *image)
447 locale = g_list_insert_sorted_with_data(locale, (gpointer)image->section, __comparefunc, NULL);
453 static void __printfunc(gpointer data, gpointer userdata)
455 DBG("%s ", (char*)data);
458 static void __trimfunc1(gpointer data, gpointer userdata)
461 if (strcmp((char *)data, prev) == 0) {
462 pkglocale = g_list_remove(pkglocale, data);
470 static void __trimfunc2(gpointer data, gpointer userdata)
473 if (strcmp((char *)data, prev) == 0) {
474 applocale = g_list_remove(applocale, data);
482 static void __trimfunc3(gpointer data, gpointer userdata)
485 if (strcmp((char *)data, prev) == 0) {
486 appicon = g_list_remove(appicon, data);
494 static void __trimfunc4(gpointer data, gpointer userdata)
497 if (strcmp((char *)data, prev) == 0) {
498 appimage = g_list_remove(appimage, data);
506 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata)
508 if (a == NULL || b == NULL)
510 if (strcmp((char*)a, (char*)b) == 0)
512 if (strcmp((char*)a, (char*)b) < 0)
514 if (strcmp((char*)a, (char*)b) > 0)
519 static void __extract_data(gpointer data, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath,
520 char **label, char **license, char **icon, char **description, char **author)
525 if (strcmp(lbl->lang, (char *)data) == 0) {
526 *label = (char*)lbl->text;
535 if (strcmp(lcn->lang, (char *)data) == 0) {
536 *license = (char*)lcn->text;
545 if (strcmp(icn->lang, (char *)data) == 0) {
546 *icon = (char*)icn->text;
555 if (strcmp(dcn->lang, (char *)data) == 0) {
556 *description = (char*)dcn->text;
565 if (strcmp(ath->lang, (char *)data) == 0) {
566 *author = (char*)ath->text;
575 static void __extract_icon_data(gpointer data, icon_x *icn, char **icon, char **resolution)
580 if (strcmp(icn->section, (char *)data) == 0) {
581 *icon = (char*)icn->text;
582 *resolution = (char*)icn->resolution;
590 static void __extract_image_data(gpointer data, image_x*image, char **lang, char **img)
594 if (image->section) {
595 if (strcmp(image->section, (char *)data) == 0) {
596 *lang = (char*)image->lang;
597 *img = (char*)image->text;
605 static void __insert_pkglocale_info(gpointer data, gpointer userdata)
610 char *description = NULL;
611 char *license = NULL;
613 char query[MAX_QUERY_LEN] = {'\0'};
615 manifest_x *mfx = (manifest_x *)userdata;
616 label_x *lbl = mfx->label;
617 license_x *lcn = mfx->license;
618 icon_x *icn = mfx->icon;
619 description_x *dcn = mfx->description;
620 author_x *ath = mfx->author;
622 __extract_data(data, lbl, lcn, icn, dcn, ath, &label, &license, &icon, &description, &author);
623 if (!label && !description && !icon && !license && !author)
625 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_localized_info(package, package_locale, " \
626 "package_label, package_icon, package_description, package_license, package_author) values " \
627 "('%q', '%q', '%q', '%q', '%q', '%q', '%q')", mfx->package, (char*)data,
628 label, icon, description, license, author);
629 ret = __exec_query(query);
631 DBG("Package Localized Info DB Insert failed\n");
634 static void __insert_uiapplication_locale_info(gpointer data, gpointer userdata)
639 char query[MAX_QUERY_LEN] = {'\0'};
641 uiapplication_x *up = (uiapplication_x*)userdata;
642 label_x *lbl = up->label;
643 icon_x *icn = up->icon;
645 __extract_data(data, lbl, NULL, icn, NULL, NULL, &label, NULL, &icon, NULL, NULL);
648 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_localized_info(app_id, app_locale, " \
649 "app_label, app_icon) values " \
650 "('%q', '%q', '%q', '%q')", up->appid, (char*)data,
652 ret = __exec_query(query);
654 DBG("Package UiApp Localized Info DB Insert failed\n");
656 /*insert ui app locale info to pkg locale to get mainapp data */
657 if (strcasecmp(up->mainapp, "true")==0) {
658 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_localized_info(package, package_locale, " \
659 "package_label, package_icon, package_description, package_license, package_author) values " \
660 "('%q', '%q', '%q', '%q', '%q', '%q', '%q')", up->package, (char*)data,
661 label, icon, NULL, NULL, NULL);
662 ret = __exec_query_no_msg(query);
666 static void __insert_uiapplication_icon_section_info(gpointer data, gpointer userdata)
670 char *resolution = NULL;
671 char query[MAX_QUERY_LEN] = {'\0'};
673 uiapplication_x *up = (uiapplication_x*)userdata;
674 icon_x *icn = up->icon;
676 __extract_icon_data(data, icn, &icon, &resolution);
677 if (!icon && !resolution)
679 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_icon_section_info(app_id, " \
680 "app_icon, app_icon_section, app_icon_resolution) values " \
681 "('%q', '%q', '%q', '%q')", up->appid,
682 icon, (char*)data, resolution);
684 ret = __exec_query(query);
686 DBG("Package UiApp Localized Info DB Insert failed\n");
690 static void __insert_uiapplication_image_info(gpointer data, gpointer userdata)
695 char query[MAX_QUERY_LEN] = {'\0'};
697 uiapplication_x *up = (uiapplication_x*)userdata;
698 image_x *image = up->image;
700 __extract_image_data(data, image, &lang, &img);
703 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_image_info(app_id, app_locale, " \
704 "app_image_section, app_image) values " \
705 "('%q', '%q', '%q', '%q')", up->appid, lang, (char*)data, img);
707 ret = __exec_query(query);
709 DBG("Package UiApp image Info DB Insert failed\n");
714 static void __insert_serviceapplication_locale_info(gpointer data, gpointer userdata)
719 char query[MAX_QUERY_LEN] = {'\0'};
721 serviceapplication_x *sp = (serviceapplication_x*)userdata;
722 label_x *lbl = sp->label;
723 icon_x *icn = sp->icon;
725 __extract_data(data, lbl, NULL, icn, NULL, NULL, &label, NULL, &icon, NULL, NULL);
728 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_localized_info(app_id, app_locale, " \
729 "app_label, app_icon) values " \
730 "('%q', '%q', '%q', '%q')", sp->appid, (char*)data,
732 ret = __exec_query(query);
734 DBG("Package ServiceApp Localized Info DB Insert failed\n");
737 static int __insert_ui_mainapp_info(manifest_x *mfx)
739 uiapplication_x *up = mfx->uiapplication;
741 char query[MAX_QUERY_LEN] = {'\0'};
744 snprintf(query, MAX_QUERY_LEN,
745 "update package_app_info set app_mainapp='%s' where app_id='%s'", up->mainapp, up->appid);
747 ret = __exec_query(query);
749 DBG("Package UiApp Info DB Insert Failed\n");
752 if (strcasecmp(up->mainapp, "True")==0)
753 mfx->mainapp_id = strdup(up->appid);
756 memset(query, '\0', MAX_QUERY_LEN);
759 if (mfx->mainapp_id == NULL){
760 if (mfx->uiapplication && mfx->uiapplication->appid) {
761 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_mainapp='true' where app_id='%s'", mfx->uiapplication->appid);
763 DBG("Not valid appid\n");
767 ret = __exec_query(query);
769 DBG("Package UiApp Info DB Insert Failed\n");
773 free((void *)mfx->uiapplication->mainapp);
774 mfx->uiapplication->mainapp= strdup("true");
775 mfx->mainapp_id = strdup(mfx->uiapplication->appid);
778 memset(query, '\0', MAX_QUERY_LEN);
779 snprintf(query, MAX_QUERY_LEN,
780 "update package_info set mainapp_id='%s' where package='%s'", mfx->mainapp_id, mfx->package);
781 ret = __exec_query(query);
783 DBG("Package Info DB update Failed\n");
789 /* _PRODUCT_LAUNCHING_ENHANCED_
790 * up->indicatordisplay, up->portraitimg, up->landscapeimg, up->guestmode_appstatus
792 static int __insert_uiapplication_info(manifest_x *mfx)
794 uiapplication_x *up = mfx->uiapplication;
796 char query[MAX_QUERY_LEN] = {'\0'};
799 snprintf(query, MAX_QUERY_LEN,
800 "insert into package_app_info(app_id, app_component, app_exec, app_nodisplay, app_type, app_onboot, " \
801 "app_multiple, app_autorestart, app_taskmanage, app_enabled, app_hwacceleration, app_screenreader, app_mainapp , app_recentimage, " \
802 "app_launchcondition, app_indicatordisplay, app_portraitimg, app_landscapeimg, app_guestmodevisibility, app_permissiontype, "\
803 "app_preload, app_submode, app_submode_mainid, component_type, package) " \
804 "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')",\
805 up->appid, "uiapp", up->exec, up->nodisplay, up->type, "\0", up->multiple,
806 "\0", up->taskmanage, up->enabled, up->hwacceleration, up->screenreader, up->mainapp, up->recentimage,
807 up->launchcondition, up->indicatordisplay, up->portraitimg, up->landscapeimg, up->guestmode_visibility, up->permission_type,
808 mfx->preload, up->submode, up->submode_mainid, up->component_type, mfx->package);
809 ret = __exec_query(query);
811 DBG("Package UiApp Info DB Insert Failed\n");
815 memset(query, '\0', MAX_QUERY_LEN);
820 static int __insert_uiapplication_appcategory_info(manifest_x *mfx)
822 uiapplication_x *up = mfx->uiapplication;
823 category_x *ct = NULL;
825 char query[MAX_QUERY_LEN] = {'\0'};
831 snprintf(query, MAX_QUERY_LEN,
832 "insert into package_app_app_category(app_id, category) " \
833 "values('%s','%s')",\
834 up->appid, ct->name);
835 ret = __exec_query(query);
837 DBG("Package UiApp Category Info DB Insert Failed\n");
841 memset(query, '\0', MAX_QUERY_LEN);
848 static int __insert_uiapplication_appmetadata_info(manifest_x *mfx)
850 uiapplication_x *up = mfx->uiapplication;
851 metadata_x *md = NULL;
853 char query[MAX_QUERY_LEN] = {'\0'};
860 snprintf(query, MAX_QUERY_LEN,
861 "insert into package_app_app_metadata(app_id, md_key, md_value) " \
862 "values('%s','%s', '%s')",\
863 up->appid, md->key, md->value);
864 ret = __exec_query(query);
866 DBG("Package UiApp Metadata Info DB Insert Failed\n");
871 memset(query, '\0', MAX_QUERY_LEN);
878 static int __insert_uiapplication_apppermission_info(manifest_x *mfx)
880 uiapplication_x *up = mfx->uiapplication;
881 permission_x *pm = NULL;
883 char query[MAX_QUERY_LEN] = {'\0'};
889 snprintf(query, MAX_QUERY_LEN,
890 "insert into package_app_app_permission(app_id, pm_type, pm_value) " \
891 "values('%s','%s', '%s')",\
892 up->appid, pm->type, pm->value);
893 ret = __exec_query(query);
895 DBG("Package UiApp permission Info DB Insert Failed\n");
899 memset(query, '\0', MAX_QUERY_LEN);
906 static int __insert_uiapplication_appcontrol_info(manifest_x *mfx)
908 uiapplication_x *up = mfx->uiapplication;
909 appcontrol_x *acontrol = NULL;
910 operation_x *op = NULL;
913 subapp_x *sub = NULL;
915 char query[MAX_QUERY_LEN] = {'\0'};
916 const char *operation = NULL;
917 const char *mime = NULL;
918 const char *uri = NULL;
919 const char *subapp = NULL;
922 acontrol = up->appcontrol;
923 while(acontrol != NULL)
925 op = acontrol->operation;
929 operation = op->name;
936 sub = acontrol->subapp;
946 snprintf(query, MAX_QUERY_LEN,
947 "insert into package_app_app_control(app_id, operation, uri_scheme, mime_type, subapp_name) " \
948 "values('%s', '%s', '%s', '%s', '%s')",\
949 up->appid, operation, uri, mime, subapp);
951 ret = __exec_query(query);
953 DBG("Package UiApp AppSvc DB Insert Failed\n");
956 memset(query, '\0', MAX_QUERY_LEN);
973 acontrol = acontrol->next;
980 static int __insert_uiapplication_appsvc_info(manifest_x *mfx)
982 uiapplication_x *up = mfx->uiapplication;
983 appsvc_x *asvc = NULL;
984 operation_x *op = NULL;
987 subapp_x *sub = NULL;
989 char query[MAX_QUERY_LEN] = {'\0'};
990 const char *operation = NULL;
991 const char *mime = NULL;
992 const char *uri = NULL;
993 const char *subapp = NULL;
999 op = asvc->operation;
1003 operation = op->name;
1020 snprintf(query, MAX_QUERY_LEN,
1021 "insert into package_app_app_svc(app_id, operation, uri_scheme, mime_type, subapp_name) " \
1022 "values('%s', '%s', '%s', '%s', '%s')",\
1023 up->appid, operation, uri, mime, subapp);
1025 ret = __exec_query(query);
1027 DBG("Package UiApp AppSvc DB Insert Failed\n");
1030 memset(query, '\0', MAX_QUERY_LEN);
1034 } while(ui != NULL);
1038 }while(sub != NULL);
1054 static int __insert_uiapplication_share_request_info(manifest_x *mfx)
1056 uiapplication_x *up = mfx->uiapplication;
1057 datashare_x *ds = NULL;
1058 request_x *rq = NULL;
1060 char query[MAX_QUERY_LEN] = {'\0'};
1069 snprintf(query, MAX_QUERY_LEN,
1070 "insert into package_app_share_request(app_id, data_share_request) " \
1071 "values('%s', '%s')",\
1072 up->appid, rq->text);
1073 ret = __exec_query(query);
1075 DBG("Package UiApp Share Request DB Insert Failed\n");
1078 memset(query, '\0', MAX_QUERY_LEN);
1088 static int __insert_uiapplication_share_allowed_info(manifest_x *mfx)
1090 uiapplication_x *up = mfx->uiapplication;
1091 datashare_x *ds = NULL;
1092 define_x *df = NULL;
1093 allowed_x *al = NULL;
1095 char query[MAX_QUERY_LEN] = {'\0'};
1107 snprintf(query, MAX_QUERY_LEN,
1108 "insert into package_app_share_allowed(app_id, data_share_path, data_share_allowed) " \
1109 "values('%s', '%s', '%s')",\
1110 up->appid, df->path, al->text);
1111 ret = __exec_query(query);
1113 DBG("Package UiApp Share Allowed DB Insert Failed\n");
1116 memset(query, '\0', MAX_QUERY_LEN);
1128 static int __insert_serviceapplication_info(manifest_x *mfx)
1130 serviceapplication_x *sp = mfx->serviceapplication;
1132 char query[MAX_QUERY_LEN] = {'\0'};
1135 snprintf(query, MAX_QUERY_LEN,
1136 "insert into package_app_info(app_id, app_component, app_exec, app_type, app_onboot, " \
1137 "app_multiple, app_autorestart, app_enabled, app_permissiontype, package) " \
1138 "values('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",\
1139 sp->appid, "svcapp", sp->exec, sp->type, sp->onboot, "\0",
1140 sp->autorestart, sp->enabled, sp->permission_type, mfx->package);
1141 ret = __exec_query(query);
1143 DBG("Package ServiceApp Info DB Insert Failed\n");
1147 memset(query, '\0', MAX_QUERY_LEN);
1152 static int __insert_serviceapplication_appcategory_info(manifest_x *mfx)
1154 serviceapplication_x *sp = mfx->serviceapplication;
1155 category_x *ct = NULL;
1157 char query[MAX_QUERY_LEN] = {'\0'};
1163 snprintf(query, MAX_QUERY_LEN,
1164 "insert into package_app_app_category(app_id, category) " \
1165 "values('%s','%s')",\
1166 sp->appid, ct->name);
1167 ret = __exec_query(query);
1169 DBG("Package ServiceApp Category Info DB Insert Failed\n");
1173 memset(query, '\0', MAX_QUERY_LEN);
1180 static int __insert_serviceapplication_appmetadata_info(manifest_x *mfx)
1182 serviceapplication_x *sp = mfx->serviceapplication;
1183 metadata_x *md = NULL;
1185 char query[MAX_QUERY_LEN] = {'\0'};
1192 snprintf(query, MAX_QUERY_LEN,
1193 "insert into package_app_app_metadata(app_id, md_key, md_value) " \
1194 "values('%s','%s', '%s')",\
1195 sp->appid, md->key, md->value);
1196 ret = __exec_query(query);
1198 DBG("Package ServiceApp Metadata Info DB Insert Failed\n");
1203 memset(query, '\0', MAX_QUERY_LEN);
1210 static int __insert_serviceapplication_apppermission_info(manifest_x *mfx)
1212 serviceapplication_x *sp = mfx->serviceapplication;
1213 permission_x *pm = NULL;
1215 char query[MAX_QUERY_LEN] = {'\0'};
1218 pm = sp->permission;
1221 snprintf(query, MAX_QUERY_LEN,
1222 "insert into package_app_app_permission(app_id, pm_type, pm_value) " \
1223 "values('%s','%s', '%s')",\
1224 sp->appid, pm->type, pm->value);
1225 ret = __exec_query(query);
1227 DBG("Package ServiceApp permission Info DB Insert Failed\n");
1231 memset(query, '\0', MAX_QUERY_LEN);
1238 static int __insert_serviceapplication_appcontrol_info(manifest_x *mfx)
1240 serviceapplication_x *sp = mfx->serviceapplication;
1241 appcontrol_x *acontrol = NULL;
1243 char query[MAX_QUERY_LEN] = {'\0'};
1244 operation_x *op = NULL;
1247 subapp_x *sub = NULL;
1248 const char *operation = NULL;
1249 const char *mime = NULL;
1250 const char *uri = NULL;
1251 const char *subapp = NULL;
1254 acontrol = sp->appcontrol;
1255 while(acontrol != NULL)
1257 op = acontrol->operation;
1261 operation = op->name;
1262 mi = acontrol->mime;
1267 sub = acontrol->subapp;
1277 snprintf(query, MAX_QUERY_LEN,
1278 "insert into package_app_app_control(app_id, operation, uri_scheme, mime_type,subapp_name) " \
1279 "values('%s', '%s', '%s', '%s', '%s')",\
1280 sp->appid, operation, uri, mime, subapp);
1281 ret = __exec_query(query);
1283 DBG("Package UiApp AppSvc DB Insert Failed\n");
1286 memset(query, '\0', MAX_QUERY_LEN);
1290 } while(ui != NULL);
1294 }while(sub != NULL);
1303 acontrol = acontrol->next;
1310 static int __insert_serviceapplication_appsvc_info(manifest_x *mfx)
1312 serviceapplication_x *sp = mfx->serviceapplication;
1313 appsvc_x *asvc = NULL;
1315 char query[MAX_QUERY_LEN] = {'\0'};
1316 operation_x *op = NULL;
1319 subapp_x *sub = NULL;
1320 const char *operation = NULL;
1321 const char *mime = NULL;
1322 const char *uri = NULL;
1323 const char *subapp = NULL;
1329 op = asvc->operation;
1333 operation = op->name;
1349 snprintf(query, MAX_QUERY_LEN,
1350 "insert into package_app_app_svc(app_id, operation, uri_scheme, mime_type, subapp_name) " \
1351 "values('%s', '%s', '%s', '%s', '%s')",\
1352 sp->appid, operation, uri, mime, subapp);
1353 ret = __exec_query(query);
1355 DBG("Package UiApp AppSvc DB Insert Failed\n");
1358 memset(query, '\0', MAX_QUERY_LEN);
1362 } while(ui != NULL);
1366 }while(sub != NULL);
1384 static int __insert_serviceapplication_share_request_info(manifest_x *mfx)
1386 serviceapplication_x *sp = mfx->serviceapplication;
1387 datashare_x *ds = NULL;
1388 request_x *rq = NULL;
1390 char query[MAX_QUERY_LEN] = {'\0'};
1399 snprintf(query, MAX_QUERY_LEN,
1400 "insert into package_app_share_request(app_id, data_share_request) " \
1401 "values('%s', '%s')",\
1402 sp->appid, rq->text);
1403 ret = __exec_query(query);
1405 DBG("Package ServiceApp Share Request DB Insert Failed\n");
1408 memset(query, '\0', MAX_QUERY_LEN);
1420 static int __insert_serviceapplication_share_allowed_info(manifest_x *mfx)
1422 serviceapplication_x *sp = mfx->serviceapplication;
1423 datashare_x *ds = NULL;
1424 define_x *df = NULL;
1425 allowed_x *al = NULL;
1427 char query[MAX_QUERY_LEN] = {'\0'};
1439 snprintf(query, MAX_QUERY_LEN,
1440 "insert into package_app_share_allowed(app_id, data_share_path, data_share_allowed) " \
1441 "values('%s', '%s', '%s')",\
1442 sp->appid, df->path, al->text);
1443 ret = __exec_query(query);
1445 DBG("Package App Share Allowed DB Insert Failed\n");
1448 memset(query, '\0', MAX_QUERY_LEN);
1460 static int __insert_manifest_info_in_db(manifest_x *mfx)
1462 label_x *lbl = mfx->label;
1463 license_x *lcn = mfx->license;
1464 icon_x *icn = mfx->icon;
1465 description_x *dcn = mfx->description;
1466 author_x *ath = mfx->author;
1467 uiapplication_x *up = mfx->uiapplication;
1468 uiapplication_x *up_icn = mfx->uiapplication;
1469 uiapplication_x *up_image = mfx->uiapplication;
1470 serviceapplication_x *sp = mfx->serviceapplication;
1471 privileges_x *pvs = NULL;
1472 privilege_x *pv = NULL;
1473 char query[MAX_QUERY_LEN] = { '\0' };
1474 char root[MAX_QUERY_LEN] = { '\0' };
1478 const char *auth_name = NULL;
1479 const char *auth_email = NULL;
1480 const char *auth_href = NULL;
1483 auth_name = ath->text;
1485 auth_email = ath->email;
1487 auth_href = ath->href;
1490 /*Insert in the package_info DB*/
1492 type = strdup(mfx->type);
1494 type = strdup("rpm");
1495 /*Insert in the package_info DB*/
1497 path = strdup(mfx->root_path);
1499 if (strcmp(type,"rpm")==0)
1500 snprintf(root, MAX_QUERY_LEN - 1, "/usr/apps/%s", mfx->package);
1502 snprintf(root, MAX_QUERY_LEN - 1, "/opt/usr/apps/%s", mfx->package);
1504 path = strdup(root);
1506 snprintf(query, MAX_QUERY_LEN,
1507 "insert into package_info(package, package_type, package_version, install_location, package_size, " \
1508 "package_removable, package_preload, package_readonly, package_update, package_appsetting, package_nodisplay, " \
1509 "author_name, author_email, author_href, installed_time, installed_storage, storeclient_id, mainapp_id, package_url, root_path, csc_path) " \
1510 "values('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",\
1511 mfx->package, type, mfx->version, mfx->installlocation, mfx->package_size, mfx->removable, mfx->preload,
1512 mfx->readonly, mfx->update, mfx->appsetting, mfx->nodisplay_setting,
1513 auth_name, auth_email, auth_href, mfx->installed_time, mfx->installed_storage, mfx->storeclient_id, mfx->mainapp_id, mfx->package_url, path, mfx->csc_path);
1514 ret = __exec_query(query);
1516 DBG("Package Info DB Insert Failed\n");
1536 /*Insert in the package_privilege_info DB*/
1537 pvs = mfx->privileges;
1538 while (pvs != NULL) {
1539 pv = pvs->privilege;
1540 while (pv != NULL) {
1541 memset(query, '\0', MAX_QUERY_LEN);
1542 snprintf(query, MAX_QUERY_LEN,
1543 "insert into package_privilege_info(package, privilege) " \
1544 "values('%s','%s')",\
1545 mfx->package, pv->text);
1546 ret = __exec_query(query);
1548 DBG("Package Privilege Info DB Insert Failed\n");
1556 ret = __insert_ui_mainapp_info(mfx);
1560 /*Insert the package locale and app locale info */
1561 pkglocale = __create_locale_list(pkglocale, lbl, lcn, icn, dcn, ath);
1562 g_list_foreach(pkglocale, __trimfunc1, NULL);
1567 applocale = __create_locale_list(applocale, up->label, NULL, up->icon, NULL, NULL);
1572 applocale = __create_locale_list(applocale, sp->label, NULL, sp->icon, NULL, NULL);
1575 g_list_foreach(applocale, __trimfunc2, NULL);
1578 /*Insert the app icon info */
1579 while(up_icn != NULL)
1581 appicon = __create_icon_list(appicon, up_icn->icon);
1582 up_icn = up_icn->next;
1584 g_list_foreach(appicon, __trimfunc3, NULL);
1587 /*Insert the image info */
1588 while(up_image != NULL)
1590 appimage = __create_image_list(appimage, up_image->image);
1591 up_image = up_image->next;
1593 g_list_foreach(appimage, __trimfunc4, NULL);
1596 /*g_list_foreach(pkglocale, __printfunc, NULL);*/
1598 /*g_list_foreach(applocale, __printfunc, NULL);*/
1600 /*package locale info*/
1601 g_list_foreach(pkglocale, __insert_pkglocale_info, (gpointer)mfx);
1602 /*native app locale info*/
1603 up = mfx->uiapplication;
1606 g_list_foreach(applocale, __insert_uiapplication_locale_info, (gpointer)up);
1609 /*agent app locale info*/
1610 sp = mfx->serviceapplication;
1613 g_list_foreach(applocale, __insert_serviceapplication_locale_info, (gpointer)sp);
1617 /*app icon locale info*/
1618 up_icn = mfx->uiapplication;
1619 while(up_icn != NULL)
1621 g_list_foreach(appicon, __insert_uiapplication_icon_section_info, (gpointer)up_icn);
1622 up_icn = up_icn->next;
1626 up_image = mfx->uiapplication;
1627 while(up_image != NULL)
1629 g_list_foreach(appimage, __insert_uiapplication_image_info, (gpointer)up_image);
1630 up_image = up_image->next;
1633 g_list_free(pkglocale);
1635 g_list_free(applocale);
1637 g_list_free(appicon);
1639 g_list_free(appimage);
1643 /*Insert in the package_app_info DB*/
1644 ret = __insert_uiapplication_info(mfx);
1647 ret = __insert_serviceapplication_info(mfx);
1651 /*Insert in the package_app_app_control DB*/
1652 ret = __insert_uiapplication_appcontrol_info(mfx);
1655 ret = __insert_serviceapplication_appcontrol_info(mfx);
1659 /*Insert in the package_app_app_category DB*/
1660 ret = __insert_uiapplication_appcategory_info(mfx);
1663 ret = __insert_serviceapplication_appcategory_info(mfx);
1667 /*Insert in the package_app_app_metadata DB*/
1668 ret = __insert_uiapplication_appmetadata_info(mfx);
1671 ret = __insert_serviceapplication_appmetadata_info(mfx);
1675 /*Insert in the package_app_app_permission DB*/
1676 ret = __insert_uiapplication_apppermission_info(mfx);
1679 ret = __insert_serviceapplication_apppermission_info(mfx);
1683 /*Insert in the package_app_app_svc DB*/
1684 ret = __insert_uiapplication_appsvc_info(mfx);
1687 ret = __insert_serviceapplication_appsvc_info(mfx);
1691 /*Insert in the package_app_share_allowed DB*/
1692 ret = __insert_uiapplication_share_allowed_info(mfx);
1695 ret = __insert_serviceapplication_share_allowed_info(mfx);
1699 /*Insert in the package_app_share_request DB*/
1700 ret = __insert_uiapplication_share_request_info(mfx);
1703 ret = __insert_serviceapplication_share_request_info(mfx);
1711 static int __delete_appinfo_from_db(char *db_table, const char *appid)
1713 char query[MAX_QUERY_LEN] = { '\0' };
1715 memset(query, '\0', MAX_QUERY_LEN);
1716 snprintf(query, MAX_QUERY_LEN,
1717 "delete from %s where app_id='%s'", db_table, appid);
1718 ret = __exec_query(query);
1720 DBG("DB Deletion from table (%s) Failed\n", db_table);
1726 static int __delete_manifest_info_from_db(manifest_x *mfx)
1728 char query[MAX_QUERY_LEN] = { '\0' };
1730 uiapplication_x *up = mfx->uiapplication;
1731 serviceapplication_x *sp = mfx->serviceapplication;
1732 /*Delete from cert table*/
1733 ret = pkgmgrinfo_delete_certinfo(mfx->package);
1735 DBG("Cert Info DB Delete Failed\n");
1739 /*Delete from Package Info DB*/
1740 snprintf(query, MAX_QUERY_LEN,
1741 "delete from package_info where package='%s'", mfx->package);
1742 ret = __exec_query(query);
1744 DBG("Package Info DB Delete Failed\n");
1747 memset(query, '\0', MAX_QUERY_LEN);
1749 /*Delete from Package Localized Info*/
1750 snprintf(query, MAX_QUERY_LEN,
1751 "delete from package_localized_info where package='%s'", mfx->package);
1752 ret = __exec_query(query);
1754 DBG("Package Localized Info DB Delete Failed\n");
1758 /*Delete from Package Privilege Info*/
1759 snprintf(query, MAX_QUERY_LEN,
1760 "delete from package_privilege_info where package='%s'", mfx->package);
1761 ret = __exec_query(query);
1763 DBG("Package Privilege Info DB Delete Failed\n");
1767 while (up != NULL) {
1768 ret = __delete_appinfo_from_db("package_app_info", up->appid);
1771 ret = __delete_appinfo_from_db("package_app_localized_info", up->appid);
1774 ret = __delete_appinfo_from_db("package_app_icon_section_info", up->appid);
1777 ret = __delete_appinfo_from_db("package_app_image_info", up->appid);
1780 ret = __delete_appinfo_from_db("package_app_app_svc", up->appid);
1783 ret = __delete_appinfo_from_db("package_app_app_control", up->appid);
1786 ret = __delete_appinfo_from_db("package_app_app_category", up->appid);
1789 ret = __delete_appinfo_from_db("package_app_app_metadata", up->appid);
1792 ret = __delete_appinfo_from_db("package_app_app_permission", up->appid);
1795 ret = __delete_appinfo_from_db("package_app_share_allowed", up->appid);
1798 ret = __delete_appinfo_from_db("package_app_share_request", up->appid);
1804 while (sp != NULL) {
1805 ret = __delete_appinfo_from_db("package_app_info", sp->appid);
1808 ret = __delete_appinfo_from_db("package_app_localized_info", sp->appid);
1811 ret = __delete_appinfo_from_db("package_app_icon_section_info", sp->appid);
1814 ret = __delete_appinfo_from_db("package_app_image_info", sp->appid);
1817 ret = __delete_appinfo_from_db("package_app_app_svc", sp->appid);
1820 ret = __delete_appinfo_from_db("package_app_app_control", sp->appid);
1823 ret = __delete_appinfo_from_db("package_app_app_category", sp->appid);
1826 ret = __delete_appinfo_from_db("package_app_app_metadata", sp->appid);
1829 ret = __delete_appinfo_from_db("package_app_app_permission", sp->appid);
1832 ret = __delete_appinfo_from_db("package_app_share_allowed", sp->appid);
1835 ret = __delete_appinfo_from_db("package_app_share_request", sp->appid);
1843 static int __update_preload_condition_in_db()
1846 char query[MAX_QUERY_LEN] = {'\0'};
1848 snprintf(query, MAX_QUERY_LEN, "update package_info set package_preload='true'");
1850 ret = __exec_query(query);
1852 DBG("Package preload_condition update failed\n");
1857 int pkgmgr_parser_initialize_db()
1861 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_INFO);
1863 DBG("package info DB initialization failed\n");
1866 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO);
1868 DBG("package localized info DB initialization failed\n");
1871 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO);
1873 DBG("package app app privilege DB initialization failed\n");
1876 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_INFO);
1878 DBG("package app info DB initialization failed\n");
1881 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO);
1883 DBG("package app localized info DB initialization failed\n");
1886 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO);
1888 DBG("package app icon localized info DB initialization failed\n");
1891 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO);
1893 DBG("package app image info DB initialization failed\n");
1896 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL);
1898 DBG("package app app control DB initialization failed\n");
1901 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY);
1903 DBG("package app app category DB initialization failed\n");
1906 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA);
1908 DBG("package app app category DB initialization failed\n");
1911 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION);
1913 DBG("package app app permission DB initialization failed\n");
1916 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_SVC);
1918 DBG("package app app svc DB initialization failed\n");
1921 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED);
1923 DBG("package app share allowed DB initialization failed\n");
1926 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST);
1928 DBG("package app share request DB initialization failed\n");
1932 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INFO);
1934 DBG("package cert info DB initialization failed\n");
1937 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO);
1939 DBG("package cert index info DB initialization failed\n");
1945 int pkgmgr_parser_check_and_create_db()
1949 ret = __pkgmgr_parser_create_db(&pkgmgr_parser_db, PKGMGR_PARSER_DB_FILE);
1951 DBG("Manifest DB creation Failed\n");
1955 ret = __pkgmgr_parser_create_db(&pkgmgr_cert_db, PKGMGR_CERT_DB_FILE);
1957 DBG("Cert DB creation Failed\n");
1963 int pkgmgr_parser_close_db()
1965 sqlite3_close(pkgmgr_parser_db);
1966 sqlite3_close(pkgmgr_cert_db);
1969 API int pkgmgr_parser_insert_manifest_info_in_db(manifest_x *mfx)
1972 DBG("manifest pointer is NULL\n");
1976 ret = pkgmgr_parser_check_and_create_db();
1978 DBG("Failed to open DB\n");
1981 ret = pkgmgr_parser_initialize_db();
1984 /*Begin transaction*/
1985 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
1986 if (ret != SQLITE_OK) {
1987 DBG("Failed to begin transaction\n");
1991 DBG("Transaction Begin\n");
1992 ret = __insert_manifest_info_in_db(mfx);
1994 DBG("Insert into DB failed. Rollback now\n");
1995 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
1998 /*Commit transaction*/
1999 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2000 if (ret != SQLITE_OK) {
2001 DBG("Failed to commit transaction. Rollback now\n");
2002 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2006 DBG("Transaction Commit and End\n");
2008 pkgmgr_parser_close_db();
2012 API int pkgmgr_parser_update_manifest_info_in_db(manifest_x *mfx)
2015 DBG("manifest pointer is NULL\n");
2019 ret = pkgmgr_parser_check_and_create_db();
2021 DBG("Failed to open DB\n");
2024 ret = pkgmgr_parser_initialize_db();
2027 /*Preserve guest mode visibility*/
2028 __preserve_guestmode_visibility_value( mfx);
2029 /*Begin transaction*/
2030 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2031 if (ret != SQLITE_OK) {
2032 DBG("Failed to begin transaction\n");
2036 DBG("Transaction Begin\n");
2037 ret = __delete_manifest_info_from_db(mfx);
2039 DBG("Delete from DB failed. Rollback now\n");
2040 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2043 ret = __insert_manifest_info_in_db(mfx);
2045 DBG("Insert into DB failed. Rollback now\n");
2046 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2050 /*Commit transaction*/
2051 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2052 if (ret != SQLITE_OK) {
2053 DBG("Failed to commit transaction. Rollback now\n");
2054 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2058 DBG("Transaction Commit and End\n");
2060 pkgmgr_parser_close_db();
2064 API int pkgmgr_parser_delete_manifest_info_from_db(manifest_x *mfx)
2067 DBG("manifest pointer is NULL\n");
2071 ret = pkgmgr_parser_check_and_create_db();
2073 DBG("Failed to open DB\n");
2076 /*Begin transaction*/
2077 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2078 if (ret != SQLITE_OK) {
2079 DBG("Failed to begin transaction\n");
2083 DBG("Transaction Begin\n");
2084 ret = __delete_manifest_info_from_db(mfx);
2086 DBG("Delete from DB failed. Rollback now\n");
2087 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2090 /*Commit transaction*/
2091 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2092 if (ret != SQLITE_OK) {
2093 DBG("Failed to commit transaction, Rollback now\n");
2094 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2098 DBG("Transaction Commit and End\n");
2100 pkgmgr_parser_close_db();
2104 API int pkgmgr_parser_update_preload_info_in_db()
2107 ret = pkgmgr_parser_check_and_create_db();
2109 DBG("Failed to open DB\n");
2112 /*Begin transaction*/
2113 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2114 if (ret != SQLITE_OK) {
2115 DBG("Failed to begin transaction\n");
2119 DBG("Transaction Begin\n");
2120 ret = __update_preload_condition_in_db();
2122 DBG("__update_preload_condition_in_db failed. Rollback now\n");
2123 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2126 /*Commit transaction*/
2127 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2128 if (ret != SQLITE_OK) {
2129 DBG("Failed to commit transaction, Rollback now\n");
2130 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2134 DBG("Transaction Commit and End\n");
2136 pkgmgr_parser_close_db();