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;
42 #define QUERY_CREATE_TABLE_PACKAGE_INFO "create table if not exists package_info " \
43 "(package text primary key not null, " \
44 "package_type text DEFAULT 'rpm', " \
45 "package_version text, " \
46 "install_location text, " \
47 "package_size text, " \
48 "package_removable text DEFAULT 'true', " \
49 "package_preload text DEFAULT 'false', " \
50 "package_readonly text DEFAULT 'false', " \
51 "package_update text DEFAULT 'false', " \
52 "package_appsetting text DEFAULT 'false', " \
53 "package_nodisplay text DEFAULT 'false', " \
54 "package_system text DEFAULT 'false', " \
55 "author_name text, " \
56 "author_email text, " \
58 "installed_time text," \
59 "installed_storage text," \
60 "storeclient_id text," \
66 #define QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO "create table if not exists package_localized_info " \
67 "(package text not null, " \
68 "package_locale text DEFAULT 'No Locale', " \
69 "package_label text, " \
70 "package_icon text, " \
71 "package_description text, " \
72 "package_license text, " \
74 "PRIMARY KEY(package, package_locale), " \
75 "FOREIGN KEY(package) " \
76 "REFERENCES package_info(package) " \
79 #define QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO "create table if not exists package_privilege_info " \
80 "(package text not null, " \
81 "privilege text not null, " \
82 "PRIMARY KEY(package, privilege) " \
83 "FOREIGN KEY(package) " \
84 "REFERENCES package_info(package) " \
87 #define QUERY_CREATE_TABLE_PACKAGE_APP_INFO "create table if not exists package_app_info " \
88 "(app_id text primary key not null, " \
89 "app_component text, " \
91 "app_nodisplay text DEFAULT 'false', " \
93 "app_onboot text DEFAULT 'false', " \
94 "app_multiple text DEFAULT 'false', " \
95 "app_autorestart text DEFAULT 'false', " \
96 "app_taskmanage text DEFAULT 'false', " \
97 "app_enabled text DEFAULT 'true', " \
98 "app_hwacceleration text DEFAULT 'use-system-setting', " \
99 "app_screenreader text DEFAULT 'use-system-setting', " \
100 "app_mainapp text, " \
101 "app_recentimage text, " \
102 "app_launchcondition text, " \
103 "app_indicatordisplay text DEFAULT 'true', " \
104 "app_portraitimg text, " \
105 "app_landscapeimg text, " \
106 "app_guestmodevisibility text DEFAULT 'true', " \
107 "app_permissiontype text DEFAULT 'normal', " \
108 "app_preload text DEFAULT 'false', " \
109 "app_submode text DEFAULT 'false', " \
110 "app_submode_mainid text, " \
111 "component_type text, " \
112 "package text not null, " \
113 "FOREIGN KEY(package) " \
114 "REFERENCES package_info(package) " \
117 #define QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO "create table if not exists package_app_localized_info " \
118 "(app_id text not null, " \
119 "app_locale text DEFAULT 'No Locale', " \
122 "PRIMARY KEY(app_id,app_locale) " \
123 "FOREIGN KEY(app_id) " \
124 "REFERENCES package_app_info(app_id) " \
127 #define QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO "create table if not exists package_app_icon_section_info " \
128 "(app_id text not null, " \
130 "app_icon_section text, " \
131 "app_icon_resolution text, " \
132 "PRIMARY KEY(app_id,app_icon_section,app_icon_resolution) " \
133 "FOREIGN KEY(app_id) " \
134 "REFERENCES package_app_info(app_id) " \
137 #define QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO "create table if not exists package_app_image_info " \
138 "(app_id text not null, " \
139 "app_locale text DEFAULT 'No Locale', " \
140 "app_image_section text, " \
142 "PRIMARY KEY(app_id,app_image_section) " \
143 "FOREIGN KEY(app_id) " \
144 "REFERENCES package_app_info(app_id) " \
147 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL "create table if not exists package_app_app_control " \
148 "(app_id text not null, " \
149 "operation text not null, " \
150 "uri_scheme text, " \
152 "subapp_name text, " \
153 "PRIMARY KEY(app_id,operation,uri_scheme,mime_type,subapp_name) " \
154 "FOREIGN KEY(app_id) " \
155 "REFERENCES package_app_info(app_id) " \
158 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_SVC "create table if not exists package_app_app_svc " \
159 "(app_id text not null, " \
160 "operation text not null, " \
161 "uri_scheme text, " \
163 "subapp_name text, " \
164 "PRIMARY KEY(app_id,operation,uri_scheme,mime_type,subapp_name) " \
165 "FOREIGN KEY(app_id) " \
166 "REFERENCES package_app_info(app_id) " \
169 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY "create table if not exists package_app_app_category " \
170 "(app_id text not null, " \
171 "category text not null, " \
172 "PRIMARY KEY(app_id,category) " \
173 "FOREIGN KEY(app_id) " \
174 "REFERENCES package_app_info(app_id) " \
177 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA "create table if not exists package_app_app_metadata " \
178 "(app_id text not null, " \
179 "md_key text not null, " \
180 "md_value text not null, " \
181 "PRIMARY KEY(app_id, md_key, md_value) " \
182 "FOREIGN KEY(app_id) " \
183 "REFERENCES package_app_info(app_id) " \
186 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION "create table if not exists package_app_app_permission " \
187 "(app_id text not null, " \
188 "pm_type text not null, " \
189 "pm_value text not null, " \
190 "PRIMARY KEY(app_id, pm_type, pm_value) " \
191 "FOREIGN KEY(app_id) " \
192 "REFERENCES package_app_info(app_id) " \
195 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED "create table if not exists package_app_share_allowed " \
196 "(app_id text not null, " \
197 "data_share_path text not null, " \
198 "data_share_allowed text not null, " \
199 "PRIMARY KEY(app_id,data_share_path,data_share_allowed) " \
200 "FOREIGN KEY(app_id) " \
201 "REFERENCES package_app_info(app_id) " \
204 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST "create table if not exists package_app_share_request " \
205 "(app_id text not null, " \
206 "data_share_request text not null, " \
207 "PRIMARY KEY(app_id,data_share_request) " \
208 "FOREIGN KEY(app_id) " \
209 "REFERENCES package_app_info(app_id) " \
212 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO "create table if not exists package_cert_index_info " \
213 "(cert_info text not null, " \
214 "cert_id integer, " \
215 "cert_ref_count integer, " \
216 "PRIMARY KEY(cert_id)) "
218 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INFO "create table if not exists package_cert_info " \
219 "(package text not null, " \
220 "author_root_cert integer, " \
221 "author_im_cert integer, " \
222 "author_signer_cert integer, " \
223 "dist_root_cert integer, " \
224 "dist_im_cert integer, " \
225 "dist_signer_cert integer, " \
226 "dist2_root_cert integer, " \
227 "dist2_im_cert integer, " \
228 "dist2_signer_cert integer, " \
229 "PRIMARY KEY(package)) "
231 static int __insert_uiapplication_info(manifest_x *mfx);
232 static int __insert_serviceapplication_info(manifest_x *mfx);
233 static int __insert_uiapplication_appsvc_info(manifest_x *mfx);
234 static int __insert_serviceapplication_appsvc_info(manifest_x *mfx);
235 static int __insert_uiapplication_appcategory_info(manifest_x *mfx);
236 static int __insert_serviceapplication_appcategory_info(manifest_x *mfx);
237 static int __insert_uiapplication_appcontrol_info(manifest_x *mfx);
238 static int __insert_serviceapplication_appmetadata_info(manifest_x *mfx);
239 static int __insert_uiapplication_appmetadata_info(manifest_x *mfx);
240 static int __insert_serviceapplication_appcontrol_info(manifest_x *mfx);
241 static int __insert_uiapplication_share_allowed_info(manifest_x *mfx);
242 static int __insert_serviceapplication_share_allowed_info(manifest_x *mfx);
243 static int __insert_uiapplication_share_request_info(manifest_x *mfx);
244 static int __insert_serviceapplication_share_request_info(manifest_x *mfx);
245 static void __insert_serviceapplication_locale_info(gpointer data, gpointer userdata);
246 static void __insert_uiapplication_locale_info(gpointer data, gpointer userdata);
247 static void __insert_pkglocale_info(gpointer data, gpointer userdata);
248 static int __insert_manifest_info_in_db(manifest_x *mfx);
249 static int __delete_manifest_info_from_db(manifest_x *mfx);
250 static int __delete_appinfo_from_db(char *db_table, const char *appid);
251 static int __initialize_db(sqlite3 *db_handle, const char *db_query);
252 static int __exec_query(char *query);
253 static void __extract_data(gpointer data, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath,
254 char **label, char **license, char **icon, char **description, char **author);
255 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata);
256 static GList *__create_locale_list(GList *locale, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath);
257 static void __preserve_guestmode_visibility_value(manifest_x *mfx);
258 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname);
259 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path);
261 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path)
265 if (access(db_path, F_OK) == 0) {
267 db_util_open(db_path, &handle,
268 DB_UTIL_REGISTER_HOOK_METHOD);
269 if (ret != SQLITE_OK) {
270 DBG("connect db [%s] failed!\n",
277 DBG("%s DB does not exists. Create one!!\n", db_path);
280 db_util_open(db_path, &handle,
281 DB_UTIL_REGISTER_HOOK_METHOD);
283 if (ret != SQLITE_OK) {
284 DBG("connect db [%s] failed!\n", db_path);
291 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname)
293 manifest_x *mfx = (manifest_x *)data;
297 uiapplication_x *uiapp = NULL;
298 for(i = 0; i < ncols; i++)
300 uiapp = mfx->uiapplication;
301 if (strcmp(colname[i], "app_id") == 0) {
303 appid = strdup(coltxt[i]);
304 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0) {
306 status = strdup(coltxt[i]);
310 DBG("app id is NULL\n");
313 /*update guest mode visibility*/
314 for (; uiapp != NULL; uiapp = uiapp->next) {
315 if (strcmp(uiapp->appid, appid) == 0) {
316 free((void *)uiapp->guestmode_visibility);
317 uiapp->guestmode_visibility = strdup(status);
333 static void __preserve_guestmode_visibility_value(manifest_x *mfx)
335 char *error_message = NULL;
336 char query[MAX_QUERY_LEN] = {'\0'};
337 snprintf(query, MAX_QUERY_LEN - 1, "select app_id, app_guestmodevisibility from package_app_info where package='%s'", mfx->package);
339 sqlite3_exec(pkgmgr_parser_db, query,
340 __guestmode_visibility_cb, (void *)mfx, &error_message)) {
341 DBG("Don't execute query = %s error message = %s\n",
342 query, error_message);
343 sqlite3_free(error_message);
348 static int __initialize_db(sqlite3 *db_handle, const char *db_query)
350 char *error_message = NULL;
352 sqlite3_exec(db_handle, db_query,
353 NULL, NULL, &error_message)) {
354 DBG("Don't execute query = %s error message = %s\n",
355 db_query, error_message);
356 sqlite3_free(error_message);
359 sqlite3_free(error_message);
363 static int __exec_query(char *query)
365 char *error_message = NULL;
367 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
368 DBG("Don't execute query = %s error message = %s\n", query,
370 sqlite3_free(error_message);
373 sqlite3_free(error_message);
377 static int __exec_query_no_msg(char *query)
379 char *error_message = NULL;
381 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
382 sqlite3_free(error_message);
385 sqlite3_free(error_message);
389 static GList *__create_locale_list(GList *locale, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath)
395 locale = g_list_insert_sorted_with_data(locale, (gpointer)lbl->lang, __comparefunc, NULL);
401 locale = g_list_insert_sorted_with_data(locale, (gpointer)lcn->lang, __comparefunc, NULL);
407 locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->lang, __comparefunc, NULL);
413 locale = g_list_insert_sorted_with_data(locale, (gpointer)dcn->lang, __comparefunc, NULL);
419 locale = g_list_insert_sorted_with_data(locale, (gpointer)ath->lang, __comparefunc, NULL);
426 static GList *__create_icon_list(GList *locale, icon_x *icn)
431 locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->section, __comparefunc, NULL);
437 static GList *__create_image_list(GList *locale, image_x *image)
442 locale = g_list_insert_sorted_with_data(locale, (gpointer)image->section, __comparefunc, NULL);
448 static void __printfunc(gpointer data, gpointer userdata)
450 DBG("%s ", (char*)data);
453 static void __trimfunc(GList* trim_list)
455 char *trim_data = NULL;
459 list = g_list_first(trim_list);
462 trim_data = (char *)list->data;
465 if (strcmp(trim_data, prev) == 0) {
466 trim_list = g_list_remove(trim_list, trim_data);
467 list = g_list_first(trim_list);
476 list = g_list_next(list);
480 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata)
482 if (a == NULL || b == NULL)
484 if (strcmp((char*)a, (char*)b) == 0)
486 if (strcmp((char*)a, (char*)b) < 0)
488 if (strcmp((char*)a, (char*)b) > 0)
493 static void __extract_data(gpointer data, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath,
494 char **label, char **license, char **icon, char **description, char **author)
499 if (strcmp(lbl->lang, (char *)data) == 0) {
500 *label = (char*)lbl->text;
509 if (strcmp(lcn->lang, (char *)data) == 0) {
510 *license = (char*)lcn->text;
519 if (strcmp(icn->lang, (char *)data) == 0) {
520 *icon = (char*)icn->text;
529 if (strcmp(dcn->lang, (char *)data) == 0) {
530 *description = (char*)dcn->text;
539 if (strcmp(ath->lang, (char *)data) == 0) {
540 *author = (char*)ath->text;
549 static void __extract_icon_data(gpointer data, icon_x *icn, char **icon, char **resolution)
554 if (strcmp(icn->section, (char *)data) == 0) {
555 *icon = (char*)icn->text;
556 *resolution = (char*)icn->resolution;
564 static void __extract_image_data(gpointer data, image_x*image, char **lang, char **img)
568 if (image->section) {
569 if (strcmp(image->section, (char *)data) == 0) {
570 *lang = (char*)image->lang;
571 *img = (char*)image->text;
579 static void __insert_pkglocale_info(gpointer data, gpointer userdata)
584 char *description = NULL;
585 char *license = NULL;
587 char query[MAX_QUERY_LEN] = {'\0'};
589 manifest_x *mfx = (manifest_x *)userdata;
590 label_x *lbl = mfx->label;
591 license_x *lcn = mfx->license;
592 icon_x *icn = mfx->icon;
593 description_x *dcn = mfx->description;
594 author_x *ath = mfx->author;
596 __extract_data(data, lbl, lcn, icn, dcn, ath, &label, &license, &icon, &description, &author);
597 if (!label && !description && !icon && !license && !author)
599 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_localized_info(package, package_locale, " \
600 "package_label, package_icon, package_description, package_license, package_author) values " \
601 "('%q', '%q', '%q', '%q', '%q', '%q', '%q')", mfx->package, (char*)data,
602 label, icon, description, license, author);
603 ret = __exec_query(query);
605 DBG("Package Localized Info DB Insert failed\n");
608 static void __insert_uiapplication_locale_info(gpointer data, gpointer userdata)
613 char query[MAX_QUERY_LEN] = {'\0'};
615 uiapplication_x *up = (uiapplication_x*)userdata;
616 label_x *lbl = up->label;
617 icon_x *icn = up->icon;
619 __extract_data(data, lbl, NULL, icn, NULL, NULL, &label, NULL, &icon, NULL, NULL);
622 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_localized_info(app_id, app_locale, " \
623 "app_label, app_icon) values " \
624 "('%q', '%q', '%q', '%q')", up->appid, (char*)data,
626 ret = __exec_query(query);
628 DBG("Package UiApp Localized Info DB Insert failed\n");
630 /*insert ui app locale info to pkg locale to get mainapp data */
631 if (strcasecmp(up->mainapp, "true")==0) {
632 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_localized_info(package, package_locale, " \
633 "package_label, package_icon, package_description, package_license, package_author) values " \
634 "('%q', '%q', '%q', '%q', '%q', '%q', '%q')", up->package, (char*)data,
635 label, icon, NULL, NULL, NULL);
636 ret = __exec_query_no_msg(query);
639 sqlite3_snprintf(MAX_QUERY_LEN, query, "update package_localized_info set package_icon='%s' "\
640 "where package='%s' and package_locale='%s'", icon, up->package, (char*)data);
641 ret = __exec_query_no_msg(query);
646 static void __insert_uiapplication_icon_section_info(gpointer data, gpointer userdata)
650 char *resolution = NULL;
651 char query[MAX_QUERY_LEN] = {'\0'};
653 uiapplication_x *up = (uiapplication_x*)userdata;
654 icon_x *icn = up->icon;
656 __extract_icon_data(data, icn, &icon, &resolution);
657 if (!icon && !resolution)
659 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_icon_section_info(app_id, " \
660 "app_icon, app_icon_section, app_icon_resolution) values " \
661 "('%q', '%q', '%q', '%q')", up->appid,
662 icon, (char*)data, resolution);
664 ret = __exec_query(query);
666 DBG("Package UiApp Localized Info DB Insert failed\n");
670 static void __insert_uiapplication_image_info(gpointer data, gpointer userdata)
675 char query[MAX_QUERY_LEN] = {'\0'};
677 uiapplication_x *up = (uiapplication_x*)userdata;
678 image_x *image = up->image;
680 __extract_image_data(data, image, &lang, &img);
683 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_image_info(app_id, app_locale, " \
684 "app_image_section, app_image) values " \
685 "('%q', '%q', '%q', '%q')", up->appid, lang, (char*)data, img);
687 ret = __exec_query(query);
689 DBG("Package UiApp image Info DB Insert failed\n");
694 static void __insert_serviceapplication_locale_info(gpointer data, gpointer userdata)
699 char query[MAX_QUERY_LEN] = {'\0'};
701 serviceapplication_x *sp = (serviceapplication_x*)userdata;
702 label_x *lbl = sp->label;
703 icon_x *icn = sp->icon;
705 __extract_data(data, lbl, NULL, icn, NULL, NULL, &label, NULL, &icon, NULL, NULL);
708 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_localized_info(app_id, app_locale, " \
709 "app_label, app_icon) values " \
710 "('%q', '%q', '%q', '%q')", sp->appid, (char*)data,
712 ret = __exec_query(query);
714 DBG("Package ServiceApp Localized Info DB Insert failed\n");
717 static int __insert_ui_mainapp_info(manifest_x *mfx)
719 uiapplication_x *up = mfx->uiapplication;
721 char query[MAX_QUERY_LEN] = {'\0'};
724 snprintf(query, MAX_QUERY_LEN,
725 "update package_app_info set app_mainapp='%s' where app_id='%s'", up->mainapp, up->appid);
727 ret = __exec_query(query);
729 DBG("Package UiApp Info DB Insert Failed\n");
732 if (strcasecmp(up->mainapp, "True")==0)
733 mfx->mainapp_id = strdup(up->appid);
736 memset(query, '\0', MAX_QUERY_LEN);
739 if (mfx->mainapp_id == NULL){
740 if (mfx->uiapplication && mfx->uiapplication->appid) {
741 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_mainapp='true' where app_id='%s'", mfx->uiapplication->appid);
743 DBG("Not valid appid\n");
747 ret = __exec_query(query);
749 DBG("Package UiApp Info DB Insert Failed\n");
753 free((void *)mfx->uiapplication->mainapp);
754 mfx->uiapplication->mainapp= strdup("true");
755 mfx->mainapp_id = strdup(mfx->uiapplication->appid);
758 memset(query, '\0', MAX_QUERY_LEN);
759 snprintf(query, MAX_QUERY_LEN,
760 "update package_info set mainapp_id='%s' where package='%s'", mfx->mainapp_id, mfx->package);
761 ret = __exec_query(query);
763 DBG("Package Info DB update Failed\n");
769 /* _PRODUCT_LAUNCHING_ENHANCED_
770 * up->indicatordisplay, up->portraitimg, up->landscapeimg, up->guestmode_appstatus
772 static int __insert_uiapplication_info(manifest_x *mfx)
774 uiapplication_x *up = mfx->uiapplication;
776 char query[MAX_QUERY_LEN] = {'\0'};
779 snprintf(query, MAX_QUERY_LEN,
780 "insert into package_app_info(app_id, app_component, app_exec, app_nodisplay, app_type, app_onboot, " \
781 "app_multiple, app_autorestart, app_taskmanage, app_enabled, app_hwacceleration, app_screenreader, app_mainapp , app_recentimage, " \
782 "app_launchcondition, app_indicatordisplay, app_portraitimg, app_landscapeimg, app_guestmodevisibility, app_permissiontype, "\
783 "app_preload, app_submode, app_submode_mainid, component_type, package) " \
784 "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')",\
785 up->appid, "uiapp", up->exec, up->nodisplay, up->type, "\0", up->multiple,
786 "\0", up->taskmanage, up->enabled, up->hwacceleration, up->screenreader, up->mainapp, up->recentimage,
787 up->launchcondition, up->indicatordisplay, up->portraitimg, up->landscapeimg, up->guestmode_visibility, up->permission_type,
788 mfx->preload, up->submode, up->submode_mainid, up->component_type, mfx->package);
789 ret = __exec_query(query);
791 DBG("Package UiApp Info DB Insert Failed\n");
795 memset(query, '\0', MAX_QUERY_LEN);
800 static int __insert_uiapplication_appcategory_info(manifest_x *mfx)
802 uiapplication_x *up = mfx->uiapplication;
803 category_x *ct = NULL;
805 char query[MAX_QUERY_LEN] = {'\0'};
811 snprintf(query, MAX_QUERY_LEN,
812 "insert into package_app_app_category(app_id, category) " \
813 "values('%s','%s')",\
814 up->appid, ct->name);
815 ret = __exec_query(query);
817 DBG("Package UiApp Category Info DB Insert Failed\n");
821 memset(query, '\0', MAX_QUERY_LEN);
828 static int __insert_uiapplication_appmetadata_info(manifest_x *mfx)
830 uiapplication_x *up = mfx->uiapplication;
831 metadata_x *md = NULL;
833 char query[MAX_QUERY_LEN] = {'\0'};
840 snprintf(query, MAX_QUERY_LEN,
841 "insert into package_app_app_metadata(app_id, md_key, md_value) " \
842 "values('%s','%s', '%s')",\
843 up->appid, md->key, md->value);
844 ret = __exec_query(query);
846 DBG("Package UiApp Metadata Info DB Insert Failed\n");
851 memset(query, '\0', MAX_QUERY_LEN);
858 static int __insert_uiapplication_apppermission_info(manifest_x *mfx)
860 uiapplication_x *up = mfx->uiapplication;
861 permission_x *pm = NULL;
863 char query[MAX_QUERY_LEN] = {'\0'};
869 snprintf(query, MAX_QUERY_LEN,
870 "insert into package_app_app_permission(app_id, pm_type, pm_value) " \
871 "values('%s','%s', '%s')",\
872 up->appid, pm->type, pm->value);
873 ret = __exec_query(query);
875 DBG("Package UiApp permission Info DB Insert Failed\n");
879 memset(query, '\0', MAX_QUERY_LEN);
886 static int __insert_uiapplication_appcontrol_info(manifest_x *mfx)
888 uiapplication_x *up = mfx->uiapplication;
889 appcontrol_x *acontrol = NULL;
890 operation_x *op = NULL;
893 subapp_x *sub = NULL;
895 char query[MAX_QUERY_LEN] = {'\0'};
896 const char *operation = NULL;
897 const char *mime = NULL;
898 const char *uri = NULL;
899 const char *subapp = NULL;
902 acontrol = up->appcontrol;
903 while(acontrol != NULL)
905 op = acontrol->operation;
909 operation = op->name;
916 sub = acontrol->subapp;
926 snprintf(query, MAX_QUERY_LEN,
927 "insert into package_app_app_control(app_id, operation, uri_scheme, mime_type, subapp_name) " \
928 "values('%s', '%s', '%s', '%s', '%s')",\
929 up->appid, operation, uri, mime, subapp);
931 ret = __exec_query(query);
933 DBG("Package UiApp AppSvc DB Insert Failed\n");
936 memset(query, '\0', MAX_QUERY_LEN);
953 acontrol = acontrol->next;
960 static int __insert_uiapplication_appsvc_info(manifest_x *mfx)
962 uiapplication_x *up = mfx->uiapplication;
963 appsvc_x *asvc = NULL;
964 operation_x *op = NULL;
967 subapp_x *sub = NULL;
969 char query[MAX_QUERY_LEN] = {'\0'};
970 const char *operation = NULL;
971 const char *mime = NULL;
972 const char *uri = NULL;
973 const char *subapp = NULL;
979 op = asvc->operation;
983 operation = op->name;
1000 snprintf(query, MAX_QUERY_LEN,
1001 "insert into package_app_app_svc(app_id, operation, uri_scheme, mime_type, subapp_name) " \
1002 "values('%s', '%s', '%s', '%s', '%s')",\
1003 up->appid, operation, uri, mime, subapp);
1005 ret = __exec_query(query);
1007 DBG("Package UiApp AppSvc DB Insert Failed\n");
1010 memset(query, '\0', MAX_QUERY_LEN);
1014 } while(ui != NULL);
1018 }while(sub != NULL);
1034 static int __insert_uiapplication_share_request_info(manifest_x *mfx)
1036 uiapplication_x *up = mfx->uiapplication;
1037 datashare_x *ds = NULL;
1038 request_x *rq = NULL;
1040 char query[MAX_QUERY_LEN] = {'\0'};
1049 snprintf(query, MAX_QUERY_LEN,
1050 "insert into package_app_share_request(app_id, data_share_request) " \
1051 "values('%s', '%s')",\
1052 up->appid, rq->text);
1053 ret = __exec_query(query);
1055 DBG("Package UiApp Share Request DB Insert Failed\n");
1058 memset(query, '\0', MAX_QUERY_LEN);
1068 static int __insert_uiapplication_share_allowed_info(manifest_x *mfx)
1070 uiapplication_x *up = mfx->uiapplication;
1071 datashare_x *ds = NULL;
1072 define_x *df = NULL;
1073 allowed_x *al = NULL;
1075 char query[MAX_QUERY_LEN] = {'\0'};
1087 snprintf(query, MAX_QUERY_LEN,
1088 "insert into package_app_share_allowed(app_id, data_share_path, data_share_allowed) " \
1089 "values('%s', '%s', '%s')",\
1090 up->appid, df->path, al->text);
1091 ret = __exec_query(query);
1093 DBG("Package UiApp Share Allowed DB Insert Failed\n");
1096 memset(query, '\0', MAX_QUERY_LEN);
1108 static int __insert_serviceapplication_info(manifest_x *mfx)
1110 serviceapplication_x *sp = mfx->serviceapplication;
1112 char query[MAX_QUERY_LEN] = {'\0'};
1115 snprintf(query, MAX_QUERY_LEN,
1116 "insert into package_app_info(app_id, app_component, app_exec, app_type, app_onboot, " \
1117 "app_multiple, app_autorestart, app_enabled, app_permissiontype, package) " \
1118 "values('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",\
1119 sp->appid, "svcapp", sp->exec, sp->type, sp->onboot, "\0",
1120 sp->autorestart, sp->enabled, sp->permission_type, mfx->package);
1121 ret = __exec_query(query);
1123 DBG("Package ServiceApp Info DB Insert Failed\n");
1127 memset(query, '\0', MAX_QUERY_LEN);
1132 static int __insert_serviceapplication_appcategory_info(manifest_x *mfx)
1134 serviceapplication_x *sp = mfx->serviceapplication;
1135 category_x *ct = NULL;
1137 char query[MAX_QUERY_LEN] = {'\0'};
1143 snprintf(query, MAX_QUERY_LEN,
1144 "insert into package_app_app_category(app_id, category) " \
1145 "values('%s','%s')",\
1146 sp->appid, ct->name);
1147 ret = __exec_query(query);
1149 DBG("Package ServiceApp Category Info DB Insert Failed\n");
1153 memset(query, '\0', MAX_QUERY_LEN);
1160 static int __insert_serviceapplication_appmetadata_info(manifest_x *mfx)
1162 serviceapplication_x *sp = mfx->serviceapplication;
1163 metadata_x *md = NULL;
1165 char query[MAX_QUERY_LEN] = {'\0'};
1172 snprintf(query, MAX_QUERY_LEN,
1173 "insert into package_app_app_metadata(app_id, md_key, md_value) " \
1174 "values('%s','%s', '%s')",\
1175 sp->appid, md->key, md->value);
1176 ret = __exec_query(query);
1178 DBG("Package ServiceApp Metadata Info DB Insert Failed\n");
1183 memset(query, '\0', MAX_QUERY_LEN);
1190 static int __insert_serviceapplication_apppermission_info(manifest_x *mfx)
1192 serviceapplication_x *sp = mfx->serviceapplication;
1193 permission_x *pm = NULL;
1195 char query[MAX_QUERY_LEN] = {'\0'};
1198 pm = sp->permission;
1201 snprintf(query, MAX_QUERY_LEN,
1202 "insert into package_app_app_permission(app_id, pm_type, pm_value) " \
1203 "values('%s','%s', '%s')",\
1204 sp->appid, pm->type, pm->value);
1205 ret = __exec_query(query);
1207 DBG("Package ServiceApp permission Info DB Insert Failed\n");
1211 memset(query, '\0', MAX_QUERY_LEN);
1218 static int __insert_serviceapplication_appcontrol_info(manifest_x *mfx)
1220 serviceapplication_x *sp = mfx->serviceapplication;
1221 appcontrol_x *acontrol = NULL;
1223 char query[MAX_QUERY_LEN] = {'\0'};
1224 operation_x *op = NULL;
1227 subapp_x *sub = NULL;
1228 const char *operation = NULL;
1229 const char *mime = NULL;
1230 const char *uri = NULL;
1231 const char *subapp = NULL;
1234 acontrol = sp->appcontrol;
1235 while(acontrol != NULL)
1237 op = acontrol->operation;
1241 operation = op->name;
1242 mi = acontrol->mime;
1247 sub = acontrol->subapp;
1257 snprintf(query, MAX_QUERY_LEN,
1258 "insert into package_app_app_control(app_id, operation, uri_scheme, mime_type,subapp_name) " \
1259 "values('%s', '%s', '%s', '%s', '%s')",\
1260 sp->appid, operation, uri, mime, subapp);
1261 ret = __exec_query(query);
1263 DBG("Package UiApp AppSvc DB Insert Failed\n");
1266 memset(query, '\0', MAX_QUERY_LEN);
1270 } while(ui != NULL);
1274 }while(sub != NULL);
1283 acontrol = acontrol->next;
1290 static int __insert_serviceapplication_appsvc_info(manifest_x *mfx)
1292 serviceapplication_x *sp = mfx->serviceapplication;
1293 appsvc_x *asvc = NULL;
1295 char query[MAX_QUERY_LEN] = {'\0'};
1296 operation_x *op = NULL;
1299 subapp_x *sub = NULL;
1300 const char *operation = NULL;
1301 const char *mime = NULL;
1302 const char *uri = NULL;
1303 const char *subapp = NULL;
1309 op = asvc->operation;
1313 operation = op->name;
1329 snprintf(query, MAX_QUERY_LEN,
1330 "insert into package_app_app_svc(app_id, operation, uri_scheme, mime_type, subapp_name) " \
1331 "values('%s', '%s', '%s', '%s', '%s')",\
1332 sp->appid, operation, uri, mime, subapp);
1333 ret = __exec_query(query);
1335 DBG("Package UiApp AppSvc DB Insert Failed\n");
1338 memset(query, '\0', MAX_QUERY_LEN);
1342 } while(ui != NULL);
1346 }while(sub != NULL);
1364 static int __insert_serviceapplication_share_request_info(manifest_x *mfx)
1366 serviceapplication_x *sp = mfx->serviceapplication;
1367 datashare_x *ds = NULL;
1368 request_x *rq = NULL;
1370 char query[MAX_QUERY_LEN] = {'\0'};
1379 snprintf(query, MAX_QUERY_LEN,
1380 "insert into package_app_share_request(app_id, data_share_request) " \
1381 "values('%s', '%s')",\
1382 sp->appid, rq->text);
1383 ret = __exec_query(query);
1385 DBG("Package ServiceApp Share Request DB Insert Failed\n");
1388 memset(query, '\0', MAX_QUERY_LEN);
1400 static int __insert_serviceapplication_share_allowed_info(manifest_x *mfx)
1402 serviceapplication_x *sp = mfx->serviceapplication;
1403 datashare_x *ds = NULL;
1404 define_x *df = NULL;
1405 allowed_x *al = NULL;
1407 char query[MAX_QUERY_LEN] = {'\0'};
1419 snprintf(query, MAX_QUERY_LEN,
1420 "insert into package_app_share_allowed(app_id, data_share_path, data_share_allowed) " \
1421 "values('%s', '%s', '%s')",\
1422 sp->appid, df->path, al->text);
1423 ret = __exec_query(query);
1425 DBG("Package App Share Allowed DB Insert Failed\n");
1428 memset(query, '\0', MAX_QUERY_LEN);
1440 static int __insert_manifest_info_in_db(manifest_x *mfx)
1442 label_x *lbl = mfx->label;
1443 license_x *lcn = mfx->license;
1444 icon_x *icn = mfx->icon;
1445 description_x *dcn = mfx->description;
1446 author_x *ath = mfx->author;
1447 uiapplication_x *up = mfx->uiapplication;
1448 uiapplication_x *up_icn = mfx->uiapplication;
1449 uiapplication_x *up_image = mfx->uiapplication;
1450 serviceapplication_x *sp = mfx->serviceapplication;
1451 privileges_x *pvs = NULL;
1452 privilege_x *pv = NULL;
1453 char query[MAX_QUERY_LEN] = { '\0' };
1454 char root[MAX_QUERY_LEN] = { '\0' };
1458 const char *auth_name = NULL;
1459 const char *auth_email = NULL;
1460 const char *auth_href = NULL;
1462 GList *pkglocale = NULL;
1463 GList *applocale = NULL;
1464 GList *appicon = NULL;
1465 GList *appimage = NULL;
1469 auth_name = ath->text;
1471 auth_email = ath->email;
1473 auth_href = ath->href;
1476 /*Insert in the package_info DB*/
1478 type = strdup(mfx->type);
1480 type = strdup("rpm");
1481 /*Insert in the package_info DB*/
1483 path = strdup(mfx->root_path);
1485 if (strcmp(type,"rpm")==0)
1486 snprintf(root, MAX_QUERY_LEN - 1, "/usr/apps/%s", mfx->package);
1488 snprintf(root, MAX_QUERY_LEN - 1, "/opt/usr/apps/%s", mfx->package);
1490 path = strdup(root);
1492 snprintf(query, MAX_QUERY_LEN,
1493 "insert into package_info(package, package_type, package_version, install_location, package_size, " \
1494 "package_removable, package_preload, package_readonly, package_update, package_appsetting, package_nodisplay, package_system," \
1495 "author_name, author_email, author_href, installed_time, installed_storage, storeclient_id, mainapp_id, package_url, root_path, csc_path) " \
1496 "values('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",\
1497 mfx->package, type, mfx->version, mfx->installlocation, mfx->package_size, mfx->removable, mfx->preload,
1498 mfx->readonly, mfx->update, mfx->appsetting, mfx->nodisplay_setting, mfx->system,
1499 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);
1500 ret = __exec_query(query);
1502 DBG("Package Info DB Insert Failed\n");
1522 /*Insert in the package_privilege_info DB*/
1523 pvs = mfx->privileges;
1524 while (pvs != NULL) {
1525 pv = pvs->privilege;
1526 while (pv != NULL) {
1527 memset(query, '\0', MAX_QUERY_LEN);
1528 snprintf(query, MAX_QUERY_LEN,
1529 "insert into package_privilege_info(package, privilege) " \
1530 "values('%s','%s')",\
1531 mfx->package, pv->text);
1532 ret = __exec_query(query);
1534 DBG("Package Privilege Info DB Insert Failed\n");
1542 ret = __insert_ui_mainapp_info(mfx);
1546 /*Insert the package locale*/
1547 pkglocale = __create_locale_list(pkglocale, lbl, lcn, icn, dcn, ath);
1548 /*remove duplicated data in pkglocale*/
1549 __trimfunc(pkglocale);
1551 /*Insert the app locale info */
1554 applocale = __create_locale_list(applocale, up->label, NULL, up->icon, NULL, NULL);
1559 applocale = __create_locale_list(applocale, sp->label, NULL, sp->icon, NULL, NULL);
1562 /*remove duplicated data in applocale*/
1563 __trimfunc(applocale);
1565 /*Insert the app icon info */
1566 while(up_icn != NULL)
1568 appicon = __create_icon_list(appicon, up_icn->icon);
1569 up_icn = up_icn->next;
1571 /*remove duplicated data in appicon*/
1572 __trimfunc(appicon);
1574 /*Insert the image info */
1575 while(up_image != NULL)
1577 appimage = __create_image_list(appimage, up_image->image);
1578 up_image = up_image->next;
1580 /*remove duplicated data in appimage*/
1581 __trimfunc(appimage);
1583 /*g_list_foreach(pkglocale, __printfunc, NULL);*/
1585 /*g_list_foreach(applocale, __printfunc, NULL);*/
1587 /*package locale info*/
1588 g_list_foreach(pkglocale, __insert_pkglocale_info, (gpointer)mfx);
1589 /*native app locale info*/
1590 up = mfx->uiapplication;
1593 g_list_foreach(applocale, __insert_uiapplication_locale_info, (gpointer)up);
1596 /*agent app locale info*/
1597 sp = mfx->serviceapplication;
1600 g_list_foreach(applocale, __insert_serviceapplication_locale_info, (gpointer)sp);
1604 /*app icon locale info*/
1605 up_icn = mfx->uiapplication;
1606 while(up_icn != NULL)
1608 g_list_foreach(appicon, __insert_uiapplication_icon_section_info, (gpointer)up_icn);
1609 up_icn = up_icn->next;
1613 up_image = mfx->uiapplication;
1614 while(up_image != NULL)
1616 g_list_foreach(appimage, __insert_uiapplication_image_info, (gpointer)up_image);
1617 up_image = up_image->next;
1620 g_list_free(pkglocale);
1622 g_list_free(applocale);
1624 g_list_free(appicon);
1626 g_list_free(appimage);
1630 /*Insert in the package_app_info DB*/
1631 ret = __insert_uiapplication_info(mfx);
1634 ret = __insert_serviceapplication_info(mfx);
1638 /*Insert in the package_app_app_control DB*/
1639 ret = __insert_uiapplication_appcontrol_info(mfx);
1642 ret = __insert_serviceapplication_appcontrol_info(mfx);
1646 /*Insert in the package_app_app_category DB*/
1647 ret = __insert_uiapplication_appcategory_info(mfx);
1650 ret = __insert_serviceapplication_appcategory_info(mfx);
1654 /*Insert in the package_app_app_metadata DB*/
1655 ret = __insert_uiapplication_appmetadata_info(mfx);
1658 ret = __insert_serviceapplication_appmetadata_info(mfx);
1662 /*Insert in the package_app_app_permission DB*/
1663 ret = __insert_uiapplication_apppermission_info(mfx);
1666 ret = __insert_serviceapplication_apppermission_info(mfx);
1670 /*Insert in the package_app_app_svc DB*/
1671 ret = __insert_uiapplication_appsvc_info(mfx);
1674 ret = __insert_serviceapplication_appsvc_info(mfx);
1678 /*Insert in the package_app_share_allowed DB*/
1679 ret = __insert_uiapplication_share_allowed_info(mfx);
1682 ret = __insert_serviceapplication_share_allowed_info(mfx);
1686 /*Insert in the package_app_share_request DB*/
1687 ret = __insert_uiapplication_share_request_info(mfx);
1690 ret = __insert_serviceapplication_share_request_info(mfx);
1698 static int __delete_appinfo_from_db(char *db_table, const char *appid)
1700 char query[MAX_QUERY_LEN] = { '\0' };
1702 memset(query, '\0', MAX_QUERY_LEN);
1703 snprintf(query, MAX_QUERY_LEN,
1704 "delete from %s where app_id='%s'", db_table, appid);
1705 ret = __exec_query(query);
1707 DBG("DB Deletion from table (%s) Failed\n", db_table);
1713 static int __delete_manifest_info_from_db(manifest_x *mfx)
1715 char query[MAX_QUERY_LEN] = { '\0' };
1717 uiapplication_x *up = mfx->uiapplication;
1718 serviceapplication_x *sp = mfx->serviceapplication;
1719 /*Delete from cert table*/
1720 ret = pkgmgrinfo_delete_certinfo(mfx->package);
1722 DBG("Cert Info DB Delete Failed\n");
1726 /*Delete from Package Info DB*/
1727 snprintf(query, MAX_QUERY_LEN,
1728 "delete from package_info where package='%s'", mfx->package);
1729 ret = __exec_query(query);
1731 DBG("Package Info DB Delete Failed\n");
1734 memset(query, '\0', MAX_QUERY_LEN);
1736 /*Delete from Package Localized Info*/
1737 snprintf(query, MAX_QUERY_LEN,
1738 "delete from package_localized_info where package='%s'", mfx->package);
1739 ret = __exec_query(query);
1741 DBG("Package Localized Info DB Delete Failed\n");
1745 /*Delete from Package Privilege Info*/
1746 snprintf(query, MAX_QUERY_LEN,
1747 "delete from package_privilege_info where package='%s'", mfx->package);
1748 ret = __exec_query(query);
1750 DBG("Package Privilege Info DB Delete Failed\n");
1754 while (up != NULL) {
1755 ret = __delete_appinfo_from_db("package_app_info", up->appid);
1758 ret = __delete_appinfo_from_db("package_app_localized_info", up->appid);
1761 ret = __delete_appinfo_from_db("package_app_icon_section_info", up->appid);
1764 ret = __delete_appinfo_from_db("package_app_image_info", up->appid);
1767 ret = __delete_appinfo_from_db("package_app_app_svc", up->appid);
1770 ret = __delete_appinfo_from_db("package_app_app_control", up->appid);
1773 ret = __delete_appinfo_from_db("package_app_app_category", up->appid);
1776 ret = __delete_appinfo_from_db("package_app_app_metadata", up->appid);
1779 ret = __delete_appinfo_from_db("package_app_app_permission", up->appid);
1782 ret = __delete_appinfo_from_db("package_app_share_allowed", up->appid);
1785 ret = __delete_appinfo_from_db("package_app_share_request", up->appid);
1791 while (sp != NULL) {
1792 ret = __delete_appinfo_from_db("package_app_info", sp->appid);
1795 ret = __delete_appinfo_from_db("package_app_localized_info", sp->appid);
1798 ret = __delete_appinfo_from_db("package_app_icon_section_info", sp->appid);
1801 ret = __delete_appinfo_from_db("package_app_image_info", sp->appid);
1804 ret = __delete_appinfo_from_db("package_app_app_svc", sp->appid);
1807 ret = __delete_appinfo_from_db("package_app_app_control", sp->appid);
1810 ret = __delete_appinfo_from_db("package_app_app_category", sp->appid);
1813 ret = __delete_appinfo_from_db("package_app_app_metadata", sp->appid);
1816 ret = __delete_appinfo_from_db("package_app_app_permission", sp->appid);
1819 ret = __delete_appinfo_from_db("package_app_share_allowed", sp->appid);
1822 ret = __delete_appinfo_from_db("package_app_share_request", sp->appid);
1830 static int __update_preload_condition_in_db()
1833 char query[MAX_QUERY_LEN] = {'\0'};
1835 snprintf(query, MAX_QUERY_LEN, "update package_info set package_preload='true'");
1837 ret = __exec_query(query);
1839 DBG("Package preload_condition update failed\n");
1844 int pkgmgr_parser_initialize_db()
1848 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_INFO);
1850 DBG("package info DB initialization failed\n");
1853 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO);
1855 DBG("package localized info DB initialization failed\n");
1858 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO);
1860 DBG("package app app privilege DB initialization failed\n");
1863 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_INFO);
1865 DBG("package app info DB initialization failed\n");
1868 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO);
1870 DBG("package app localized info DB initialization failed\n");
1873 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO);
1875 DBG("package app icon localized info DB initialization failed\n");
1878 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO);
1880 DBG("package app image info DB initialization failed\n");
1883 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL);
1885 DBG("package app app control DB initialization failed\n");
1888 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY);
1890 DBG("package app app category DB initialization failed\n");
1893 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA);
1895 DBG("package app app category DB initialization failed\n");
1898 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION);
1900 DBG("package app app permission DB initialization failed\n");
1903 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_SVC);
1905 DBG("package app app svc DB initialization failed\n");
1908 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED);
1910 DBG("package app share allowed DB initialization failed\n");
1913 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST);
1915 DBG("package app share request DB initialization failed\n");
1919 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INFO);
1921 DBG("package cert info DB initialization failed\n");
1924 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO);
1926 DBG("package cert index info DB initialization failed\n");
1932 int pkgmgr_parser_check_and_create_db()
1936 ret = __pkgmgr_parser_create_db(&pkgmgr_parser_db, PKGMGR_PARSER_DB_FILE);
1938 DBG("Manifest DB creation Failed\n");
1942 ret = __pkgmgr_parser_create_db(&pkgmgr_cert_db, PKGMGR_CERT_DB_FILE);
1944 DBG("Cert DB creation Failed\n");
1950 void pkgmgr_parser_close_db()
1952 sqlite3_close(pkgmgr_parser_db);
1953 sqlite3_close(pkgmgr_cert_db);
1956 API int pkgmgr_parser_insert_manifest_info_in_db(manifest_x *mfx)
1959 DBG("manifest pointer is NULL\n");
1963 ret = pkgmgr_parser_check_and_create_db();
1965 DBG("Failed to open DB\n");
1968 ret = pkgmgr_parser_initialize_db();
1971 /*Begin transaction*/
1972 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
1973 if (ret != SQLITE_OK) {
1974 DBG("Failed to begin transaction\n");
1978 DBG("Transaction Begin\n");
1979 ret = __insert_manifest_info_in_db(mfx);
1981 DBG("Insert into DB failed. Rollback now\n");
1982 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
1985 /*Commit transaction*/
1986 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
1987 if (ret != SQLITE_OK) {
1988 DBG("Failed to commit transaction. Rollback now\n");
1989 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
1993 DBG("Transaction Commit and End\n");
1995 pkgmgr_parser_close_db();
1999 API int pkgmgr_parser_update_manifest_info_in_db(manifest_x *mfx)
2002 DBG("manifest pointer is NULL\n");
2006 ret = pkgmgr_parser_check_and_create_db();
2008 DBG("Failed to open DB\n");
2011 ret = pkgmgr_parser_initialize_db();
2014 /*Preserve guest mode visibility*/
2015 __preserve_guestmode_visibility_value( mfx);
2016 /*Begin transaction*/
2017 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2018 if (ret != SQLITE_OK) {
2019 DBG("Failed to begin transaction\n");
2023 DBG("Transaction Begin\n");
2024 ret = __delete_manifest_info_from_db(mfx);
2026 DBG("Delete from DB failed. Rollback now\n");
2027 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2030 ret = __insert_manifest_info_in_db(mfx);
2032 DBG("Insert into DB failed. Rollback now\n");
2033 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2037 /*Commit transaction*/
2038 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2039 if (ret != SQLITE_OK) {
2040 DBG("Failed to commit transaction. Rollback now\n");
2041 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2045 DBG("Transaction Commit and End\n");
2047 pkgmgr_parser_close_db();
2051 API int pkgmgr_parser_delete_manifest_info_from_db(manifest_x *mfx)
2054 DBG("manifest pointer is NULL\n");
2058 ret = pkgmgr_parser_check_and_create_db();
2060 DBG("Failed to open DB\n");
2063 /*Begin transaction*/
2064 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2065 if (ret != SQLITE_OK) {
2066 DBG("Failed to begin transaction\n");
2070 DBG("Transaction Begin\n");
2071 ret = __delete_manifest_info_from_db(mfx);
2073 DBG("Delete from DB failed. Rollback now\n");
2074 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2077 /*Commit transaction*/
2078 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2079 if (ret != SQLITE_OK) {
2080 DBG("Failed to commit transaction, Rollback now\n");
2081 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2085 DBG("Transaction Commit and End\n");
2087 pkgmgr_parser_close_db();
2091 API int pkgmgr_parser_update_preload_info_in_db()
2094 ret = pkgmgr_parser_check_and_create_db();
2096 DBG("Failed to open DB\n");
2099 /*Begin transaction*/
2100 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2101 if (ret != SQLITE_OK) {
2102 DBG("Failed to begin transaction\n");
2106 DBG("Transaction Begin\n");
2107 ret = __update_preload_condition_in_db();
2109 DBG("__update_preload_condition_in_db failed. Rollback now\n");
2110 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2113 /*Commit transaction*/
2114 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2115 if (ret != SQLITE_OK) {
2116 DBG("Failed to commit transaction, Rollback now\n");
2117 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2121 DBG("Transaction Commit and End\n");
2123 pkgmgr_parser_close_db();