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_parser_internal.h"
32 #include "pkgmgr_parser_db.h"
34 #define PKGMGR_PARSER_DB_FILE "/opt/dbspace/.pkgmgr_parser.db"
35 #define PKGMGR_CERT_DB_FILE "/opt/dbspace/.pkgmgr_cert.db"
36 #define MAX_QUERY_LEN 4096
37 sqlite3 *pkgmgr_parser_db;
38 sqlite3 *pkgmgr_cert_db;
39 GList *pkglocale = NULL;
40 GList *applocale = NULL;
41 GList *appicon = NULL;
42 GList *appimage = NULL;
45 #define QUERY_CREATE_TABLE_PACKAGE_INFO "create table if not exists package_info " \
46 "(package text primary key not null, " \
47 "package_type text DEFAULT 'rpm', " \
48 "package_version text, " \
49 "install_location text, " \
50 "package_size text, " \
51 "package_removable text DEFAULT 'true', " \
52 "package_preload text DEFAULT 'false', " \
53 "package_readonly text DEFAULT 'false', " \
54 "author_name text, " \
55 "author_email text, " \
57 "installed_time text," \
58 "storeclient_id text," \
63 #define QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO "create table if not exists package_localized_info " \
64 "(package text not null, " \
65 "package_locale text DEFAULT 'No Locale', " \
66 "package_label text, " \
67 "package_icon text, " \
68 "package_description text, " \
69 "package_license text, " \
71 "PRIMARY KEY(package, package_locale), " \
72 "FOREIGN KEY(package) " \
73 "REFERENCES package_info(package) " \
76 #define QUERY_CREATE_TABLE_PACKAGE_APP_INFO "create table if not exists package_app_info " \
77 "(app_id text primary key not null, " \
78 "app_component text, " \
80 "app_nodisplay text DEFAULT 'false', " \
82 "app_onboot text DEFAULT 'false', " \
83 "app_multiple text DEFAULT 'false', " \
84 "app_autorestart text DEFAULT 'false', " \
85 "app_taskmanage text DEFAULT 'false', " \
86 "app_enabled text DEFAULT 'true', " \
87 "app_hwacceleration text DEFAULT 'use-system-setting', " \
88 "app_mainapp text, " \
89 "app_recentimage text, " \
90 "app_indicatordisplay text DEFAULT 'true', " \
91 "app_portraitimg text, " \
92 "app_landscapeimg text, " \
93 "app_guestmodevisibility text DEFAULT 'true', " \
94 "package text not null, " \
95 "FOREIGN KEY(package) " \
96 "REFERENCES package_info(package) " \
99 #define QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO "create table if not exists package_app_localized_info " \
100 "(app_id text not null, " \
101 "app_locale text DEFAULT 'No Locale', " \
104 "PRIMARY KEY(app_id,app_locale) " \
105 "FOREIGN KEY(app_id) " \
106 "REFERENCES package_app_info(app_id) " \
109 #define QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO "create table if not exists package_app_icon_section_info " \
110 "(app_id text not null, " \
112 "app_icon_section text, " \
113 "app_icon_resolution text, " \
114 "PRIMARY KEY(app_id,app_icon_section,app_icon_resolution) " \
115 "FOREIGN KEY(app_id) " \
116 "REFERENCES package_app_info(app_id) " \
119 #define QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO "create table if not exists package_app_image_info " \
120 "(app_id text not null, " \
121 "app_locale text DEFAULT 'No Locale', " \
122 "app_image_section text, " \
124 "PRIMARY KEY(app_id,app_image_section) " \
125 "FOREIGN KEY(app_id) " \
126 "REFERENCES package_app_info(app_id) " \
129 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL "create table if not exists package_app_app_control " \
130 "(app_id text not null, " \
131 "operation text not null, " \
132 "uri_scheme text, " \
134 "subapp_name text, " \
135 "PRIMARY KEY(app_id,operation,uri_scheme,mime_type,subapp_name) " \
136 "FOREIGN KEY(app_id) " \
137 "REFERENCES package_app_info(app_id) " \
140 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_SVC "create table if not exists package_app_app_svc " \
141 "(app_id text not null, " \
142 "operation text not null, " \
143 "uri_scheme text, " \
145 "subapp_name text, " \
146 "PRIMARY KEY(app_id,operation,uri_scheme,mime_type,subapp_name) " \
147 "FOREIGN KEY(app_id) " \
148 "REFERENCES package_app_info(app_id) " \
151 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY "create table if not exists package_app_app_category " \
152 "(app_id text not null, " \
153 "category text not null, " \
154 "PRIMARY KEY(app_id,category) " \
155 "FOREIGN KEY(app_id) " \
156 "REFERENCES package_app_info(app_id) " \
159 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA "create table if not exists package_app_app_metadata " \
160 "(app_id text not null, " \
161 "md_name text not null, " \
162 "md_value text not null, " \
163 "PRIMARY KEY(app_id, md_name) " \
164 "FOREIGN KEY(app_id) " \
165 "REFERENCES package_app_info(app_id) " \
168 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION "create table if not exists package_app_app_permission " \
169 "(app_id text not null, " \
170 "pm_type text not null, " \
171 "pm_value text not null, " \
172 "PRIMARY KEY(app_id) " \
173 "FOREIGN KEY(app_id) " \
174 "REFERENCES package_app_info(app_id) " \
177 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED "create table if not exists package_app_share_allowed " \
178 "(app_id text not null, " \
179 "data_share_path text not null, " \
180 "data_share_allowed text not null, " \
181 "PRIMARY KEY(app_id,data_share_path,data_share_allowed) " \
182 "FOREIGN KEY(app_id) " \
183 "REFERENCES package_app_info(app_id) " \
186 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST "create table if not exists package_app_share_request " \
187 "(app_id text not null, " \
188 "data_share_request text not null, " \
189 "PRIMARY KEY(app_id,data_share_request) " \
190 "FOREIGN KEY(app_id) " \
191 "REFERENCES package_app_info(app_id) " \
194 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INFO "create table if not exists package_cert_info " \
195 "(package text not null, " \
196 "author_root_cert text, " \
197 "author_im_cert text, " \
198 "author_signer_cert text, " \
199 "dist_root_cert text, " \
200 "dist_im_cert text, " \
201 "dist_signer_cert text, " \
202 "dist2_root_cert text, " \
203 "dist2_im_cert text, " \
204 "dist2_signer_cert text, " \
205 "PRIMARY KEY(package), " \
206 "FOREIGN KEY(package) " \
207 "REFERENCES package_info(package) " \
210 static int __insert_uiapplication_info(manifest_x *mfx);
211 static int __insert_serviceapplication_info(manifest_x *mfx);
212 static int __insert_uiapplication_appsvc_info(manifest_x *mfx);
213 static int __insert_serviceapplication_appsvc_info(manifest_x *mfx);
214 static int __insert_uiapplication_appcategory_info(manifest_x *mfx);
215 static int __insert_serviceapplication_appcategory_info(manifest_x *mfx);
216 static int __insert_uiapplication_appcontrol_info(manifest_x *mfx);
217 static int __insert_serviceapplication_appmetadata_info(manifest_x *mfx);
218 static int __insert_uiapplication_appmetadata_info(manifest_x *mfx);
219 static int __insert_serviceapplication_appcontrol_info(manifest_x *mfx);
220 static int __insert_uiapplication_share_allowed_info(manifest_x *mfx);
221 static int __insert_serviceapplication_share_allowed_info(manifest_x *mfx);
222 static int __insert_uiapplication_share_request_info(manifest_x *mfx);
223 static int __insert_serviceapplication_share_request_info(manifest_x *mfx);
224 static void __insert_serviceapplication_locale_info(gpointer data, gpointer userdata);
225 static void __insert_uiapplication_locale_info(gpointer data, gpointer userdata);
226 static void __insert_pkglocale_info(gpointer data, gpointer userdata);
227 static int __insert_manifest_info_in_db(manifest_x *mfx);
228 static int __update_manifest_info_in_db(manifest_x *mfx);
229 static int __delete_cert_info_from_db(manifest_x *mfx);
230 static int __delete_manifest_info_from_db(manifest_x *mfx);
231 static int __initialize_package_info_db();
232 static int __initialize_package_localized_info_db();
233 static int __initialize_package_app_info_db();
234 static int __initialize_package_cert_info_db();
235 static int __initialize_package_app_localized_info_db();
236 static int __initialize_package_app_icon_section_info_db();
237 static int __initialize_package_app_image_info_db();
238 static int __initialize_package_app_app_svc_db();
239 static int __initialize_package_app_app_category_db();
240 static int __initialize_package_app_app_control_db();
241 static int __initialize_package_app_app_metadata_db();
242 static int __initialize_package_app_share_allowed_db();
243 static int __initialize_package_app_share_request_db();
244 static int __exec_query(char *query);
245 static void __extract_data(gpointer data, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath,
246 char **label, char **license, char **icon, char **description, char **author);
248 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata);
249 static void __trimfunc1(gpointer data, gpointer userdata);
250 static void __trimfunc2(gpointer data, gpointer userdata);
251 static GList *__create_locale_list(GList *locale, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath);
252 static void __preserve_guestmode_visibility_value(manifest_x *mfx);
253 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname);
255 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname)
257 manifest_x *mfx = (manifest_x *)data;
261 uiapplication_x *uiapp = NULL;
262 for(i = 0; i < ncols; i++)
264 uiapp = mfx->uiapplication;
265 if (strcmp(colname[i], "app_id") == 0) {
267 appid = strdup(coltxt[i]);
268 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0) {
270 status = strdup(coltxt[i]);
273 /*update guest mode visibility*/
274 for (; uiapp != NULL; uiapp = uiapp->next) {
275 if (strcmp(uiapp->appid, appid) == 0) {
276 free((void *)uiapp->guestmode_visibility);
277 uiapp->guestmode_visibility = strdup(status);
293 static void __preserve_guestmode_visibility_value(manifest_x *mfx)
296 char *error_message = NULL;
297 char query[MAX_QUERY_LEN] = {'\0'};
298 snprintf(query, MAX_QUERY_LEN - 1, "select app_id, app_guestmodevisibility from package_app_info where package='%s'", mfx->package);
300 sqlite3_exec(pkgmgr_parser_db, query,
301 __guestmode_visibility_cb, (void *)mfx, &error_message)) {
302 DBG("Don't execute query = %s error message = %s\n",
303 query, error_message);
304 sqlite3_free(error_message);
309 static int __initialize_package_info_db()
311 char *error_message = NULL;
313 sqlite3_exec(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_INFO,
314 NULL, NULL, &error_message)) {
315 DBG("Don't execute query = %s error message = %s\n",
316 QUERY_CREATE_TABLE_PACKAGE_INFO, error_message);
317 sqlite3_free(error_message);
320 sqlite3_free(error_message);
324 static int __pkgmgr_parser_cert_create_db()
327 if (access(PKGMGR_CERT_DB_FILE, F_OK) == 0) {
329 db_util_open(PKGMGR_CERT_DB_FILE, &pkgmgr_cert_db,
330 DB_UTIL_REGISTER_HOOK_METHOD);
331 if (ret != SQLITE_OK) {
332 DBG("connect db [%s] failed!\n",
333 PKGMGR_CERT_DB_FILE);
338 DBG("Pkgmgr DB does not exists. Create one!!\n");
341 db_util_open(PKGMGR_CERT_DB_FILE, &pkgmgr_cert_db,
342 DB_UTIL_REGISTER_HOOK_METHOD);
344 if (ret != SQLITE_OK) {
345 DBG("connect db [%s] failed!\n", PKGMGR_CERT_DB_FILE);
351 static int __initialize_package_cert_info_db()
353 char *error_message = NULL;
355 ret = __pkgmgr_parser_cert_create_db();
357 DBG("Failed to open DB\n");
362 sqlite3_exec(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INFO,
363 NULL, NULL, &error_message)) {
364 DBG("Don't execute query = %s error message = %s\n",
365 QUERY_CREATE_TABLE_PACKAGE_CERT_INFO, error_message);
366 sqlite3_free(error_message);
367 sqlite3_close(pkgmgr_cert_db);
370 sqlite3_free(error_message);
371 sqlite3_close(pkgmgr_cert_db);
375 static int __initialize_package_localized_info_db()
377 char *error_message = NULL;
379 sqlite3_exec(pkgmgr_parser_db,
380 QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO, NULL, NULL,
382 DBG("Don't execute query = %s error message = %s\n",
383 QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO,
385 sqlite3_free(error_message);
388 sqlite3_free(error_message);
392 static int __initialize_package_app_info_db()
394 char *error_message = NULL;
396 sqlite3_exec(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_INFO,
397 NULL, NULL, &error_message)) {
398 DBG("Don't execute query = %s error message = %s\n",
399 QUERY_CREATE_TABLE_PACKAGE_APP_INFO, error_message);
400 sqlite3_free(error_message);
403 sqlite3_free(error_message);
407 static int __initialize_package_app_localized_info_db()
409 char *error_message = NULL;
411 sqlite3_exec(pkgmgr_parser_db,
412 QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO, NULL,
413 NULL, &error_message)) {
414 DBG("Don't execute query = %s error message = %s\n",
415 QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO,
417 sqlite3_free(error_message);
420 sqlite3_free(error_message);
424 static int __initialize_package_app_icon_section_info_db()
426 char *error_message = NULL;
428 sqlite3_exec(pkgmgr_parser_db,
429 QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO, NULL,
430 NULL, &error_message)) {
431 DBG("Don't execute query = %s error message = %s\n",
432 QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO,
434 sqlite3_free(error_message);
437 sqlite3_free(error_message);
441 static int __initialize_package_app_image_info_db()
443 char *error_message = NULL;
445 sqlite3_exec(pkgmgr_parser_db,
446 QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO, NULL,
447 NULL, &error_message)) {
448 DBG("Don't execute query = %s error message = %s\n",
449 QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO,
451 sqlite3_free(error_message);
454 sqlite3_free(error_message);
458 static int __initialize_package_app_app_control_db()
460 char *error_message = NULL;
462 sqlite3_exec(pkgmgr_parser_db,
463 QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL, NULL, NULL,
465 DBG("Don't execute query = %s error message = %s\n",
466 QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL, error_message);
467 sqlite3_free(error_message);
470 sqlite3_free(error_message);
474 static int __initialize_package_app_app_category_db()
476 char *error_message = NULL;
478 sqlite3_exec(pkgmgr_parser_db,
479 QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY, NULL, NULL,
481 DBG("Don't execute query = %s error message = %s\n",
482 QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY, error_message);
483 sqlite3_free(error_message);
486 sqlite3_free(error_message);
490 static int __initialize_package_app_app_metadata_db()
492 char *error_message = NULL;
494 sqlite3_exec(pkgmgr_parser_db,
495 QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA, NULL, NULL,
497 DBG("Don't execute query = %s error message = %s\n",
498 QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA, error_message);
499 sqlite3_free(error_message);
502 sqlite3_free(error_message);
506 static int __initialize_package_app_app_permission_db()
508 char *error_message = NULL;
510 sqlite3_exec(pkgmgr_parser_db,
511 QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION, NULL, NULL,
513 DBG("Don't execute query = %s error message = %s\n",
514 QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION, error_message);
515 sqlite3_free(error_message);
518 sqlite3_free(error_message);
522 static int __initialize_package_app_app_svc_db()
524 char *error_message = NULL;
526 sqlite3_exec(pkgmgr_parser_db,
527 QUERY_CREATE_TABLE_PACKAGE_APP_APP_SVC, NULL, NULL,
529 DBG("Don't execute query = %s error message = %s\n",
530 QUERY_CREATE_TABLE_PACKAGE_APP_APP_SVC, error_message);
531 sqlite3_free(error_message);
534 sqlite3_free(error_message);
538 static int __initialize_package_app_share_allowed_db()
540 char *error_message = NULL;
542 sqlite3_exec(pkgmgr_parser_db,
543 QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED, NULL,
544 NULL, &error_message)) {
545 DBG("Don't execute query = %s error message = %s\n",
546 QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED,
548 sqlite3_free(error_message);
551 sqlite3_free(error_message);
555 static int __initialize_package_app_share_request_db()
557 char *error_message = NULL;
559 sqlite3_exec(pkgmgr_parser_db,
560 QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST, NULL,
561 NULL, &error_message)) {
562 DBG("Don't execute query = %s error message = %s\n",
563 QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST,
565 sqlite3_free(error_message);
568 sqlite3_free(error_message);
572 static int __exec_query(char *query)
574 char *error_message = NULL;
576 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
577 DBG("Don't execute query = %s error message = %s\n", query,
579 sqlite3_free(error_message);
582 sqlite3_free(error_message);
585 static GList *__create_locale_list(GList *locale, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath)
591 locale = g_list_insert_sorted_with_data(locale, (gpointer)lbl->lang, __comparefunc, NULL);
597 locale = g_list_insert_sorted_with_data(locale, (gpointer)lcn->lang, __comparefunc, NULL);
603 locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->lang, __comparefunc, NULL);
609 locale = g_list_insert_sorted_with_data(locale, (gpointer)dcn->lang, __comparefunc, NULL);
615 locale = g_list_insert_sorted_with_data(locale, (gpointer)ath->lang, __comparefunc, NULL);
622 static GList *__create_icon_list(GList *locale, icon_x *icn)
627 locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->section, __comparefunc, NULL);
633 static GList *__create_image_list(GList *locale, image_x *image)
638 locale = g_list_insert_sorted_with_data(locale, (gpointer)image->section, __comparefunc, NULL);
644 static void __printfunc(gpointer data, gpointer userdata)
646 DBG("%s ", (char*)data);
649 static void __trimfunc1(gpointer data, gpointer userdata)
652 if (strcmp((char *)data, prev) == 0) {
653 pkglocale = g_list_remove(pkglocale, data);
661 static void __trimfunc2(gpointer data, gpointer userdata)
664 if (strcmp((char *)data, prev) == 0) {
665 applocale = g_list_remove(applocale, data);
673 static void __trimfunc3(gpointer data, gpointer userdata)
676 if (strcmp((char *)data, prev) == 0) {
677 appicon = g_list_remove(appicon, data);
685 static void __trimfunc4(gpointer data, gpointer userdata)
688 if (strcmp((char *)data, prev) == 0) {
689 appimage = g_list_remove(appimage, data);
697 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata)
699 if (a == NULL || b == NULL)
701 if (strcmp((char*)a, (char*)b) == 0)
703 if (strcmp((char*)a, (char*)b) < 0)
705 if (strcmp((char*)a, (char*)b) > 0)
709 static void __extract_data(gpointer data, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath,
710 char **label, char **license, char **icon, char **description, char **author)
715 if (strcmp(lbl->lang, (char *)data) == 0) {
716 *label = (char*)lbl->text;
725 if (strcmp(lcn->lang, (char *)data) == 0) {
726 *license = (char*)lcn->text;
735 if (strcmp(icn->lang, (char *)data) == 0) {
736 *icon = (char*)icn->text;
745 if (strcmp(dcn->lang, (char *)data) == 0) {
746 *description = (char*)dcn->text;
755 if (strcmp(ath->lang, (char *)data) == 0) {
756 *author = (char*)ath->text;
765 static void __extract_icon_data(gpointer data, icon_x *icn, char **icon, char **resolution)
770 if (strcmp(icn->section, (char *)data) == 0) {
771 *icon = (char*)icn->text;
772 *resolution = (char*)icn->resolution;
780 static void __extract_image_data(gpointer data, icon_x *image, char **lang, char **img)
784 if (image->section) {
785 if (strcmp(image->section, (char *)data) == 0) {
786 *lang = (char*)image->lang;
787 *img = (char*)image->text;
795 static void __insert_pkglocale_info(gpointer data, gpointer userdata)
800 char *description = NULL;
801 char *license = NULL;
803 char query[MAX_QUERY_LEN] = {'\0'};
805 manifest_x *mfx = (manifest_x *)userdata;
806 label_x *lbl = mfx->label;
807 license_x *lcn = mfx->license;
808 icon_x *icn = mfx->icon;
809 description_x *dcn = mfx->description;
810 author_x *ath = mfx->author;
812 __extract_data(data, lbl, lcn, icn, dcn, ath, &label, &license, &icon, &description, &author);
813 if (!label && !description && !icon && !license && !author)
815 snprintf(query, MAX_QUERY_LEN, "insert into package_localized_info(package, package_locale, " \
816 "package_label, package_icon, package_description, package_license, package_author) values " \
817 "('%s', '%s', '%s', '%s', '%s', '%s', '%s')", mfx->package, (char*)data,
818 label, icon, description, license, author);
819 ret = __exec_query(query);
821 DBG("Package Localized Info DB Insert failed\n");
824 static void __insert_uiapplication_locale_info(gpointer data, gpointer userdata)
829 char query[MAX_QUERY_LEN] = {'\0'};
831 uiapplication_x *up = (uiapplication_x*)userdata;
832 label_x *lbl = up->label;
833 icon_x *icn = up->icon;
835 __extract_data(data, lbl, NULL, icn, NULL, NULL, &label, NULL, &icon, NULL, NULL);
838 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_localized_info(app_id, app_locale, " \
839 "app_label, app_icon) values " \
840 "('%q', '%q', '%q', '%q')", up->appid, (char*)data,
842 ret = __exec_query(query);
844 DBG("Package UiApp Localized Info DB Insert failed\n");
848 static void __insert_uiapplication_icon_section_info(gpointer data, gpointer userdata)
852 char *resolution = NULL;
853 char query[MAX_QUERY_LEN] = {'\0'};
855 uiapplication_x *up = (uiapplication_x*)userdata;
856 icon_x *icn = up->icon;
858 __extract_icon_data(data, icn, &icon, &resolution);
859 if (!icon && !resolution)
861 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_icon_section_info(app_id, " \
862 "app_icon, app_icon_section, app_icon_resolution) values " \
863 "('%q', '%q', '%q', '%q')", up->appid,
864 icon, (char*)data, resolution);
866 ret = __exec_query(query);
868 DBG("Package UiApp Localized Info DB Insert failed\n");
872 static void __insert_uiapplication_image_info(gpointer data, gpointer userdata)
877 char query[MAX_QUERY_LEN] = {'\0'};
879 uiapplication_x *up = (uiapplication_x*)userdata;
880 image_x *image = up->image;
882 __extract_image_data(data, image, &lang, &img);
885 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_image_info(app_id, app_locale, " \
886 "app_image_section, app_image) values " \
887 "('%q', '%q', '%q', '%q')", up->appid, lang, (char*)data, img);
889 ret = __exec_query(query);
891 DBG("Package UiApp image Info DB Insert failed\n");
896 static void __insert_serviceapplication_locale_info(gpointer data, gpointer userdata)
901 char query[MAX_QUERY_LEN] = {'\0'};
903 serviceapplication_x *sp = (serviceapplication_x*)userdata;
904 label_x *lbl = sp->label;
905 icon_x *icn = sp->icon;
907 __extract_data(data, lbl, NULL, icn, NULL, NULL, &label, NULL, &icon, NULL, NULL);
910 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_localized_info(app_id, app_locale, " \
911 "app_label, app_icon) values " \
912 "('%q', '%q', '%q', '%q')", sp->appid, (char*)data,
914 ret = __exec_query(query);
916 DBG("Package ServiceApp Localized Info DB Insert failed\n");
919 static int __insert_ui_mainapp_info(manifest_x *mfx)
921 uiapplication_x *up = mfx->uiapplication;
923 char query[MAX_QUERY_LEN] = {'\0'};
926 snprintf(query, MAX_QUERY_LEN,
927 "update package_app_info set app_mainapp='%s' where app_id='%s'", up->mainapp, up->appid);
929 ret = __exec_query(query);
931 DBG("Package UiApp Info DB Insert Failed\n");
934 if (strcasecmp(up->mainapp, "True")==0)
935 mfx->mainapp_id = strdup(up->appid);
938 memset(query, '\0', MAX_QUERY_LEN);
941 if (mfx->mainapp_id == NULL){
942 if (mfx->uiapplication
943 && mfx->uiapplication->appid) {
944 snprintf(query, MAX_QUERY_LEN,
945 "update package_app_info set app_mainapp='true' where app_id='%s'", mfx->uiapplication->appid);
946 } else if (mfx->serviceapplication
947 && mfx->serviceapplication->appid) {
948 snprintf(query, MAX_QUERY_LEN,
949 "update package_app_info set app_mainapp='true' where app_id='%s'", mfx->serviceapplication->appid);
951 DBG("Not valid appid\n");
955 ret = __exec_query(query);
957 DBG("Package UiApp Info DB Insert Failed\n");
960 if (mfx->uiapplication && mfx->uiapplication->appid)
961 mfx->mainapp_id = strdup(mfx->uiapplication->appid);
962 else if (mfx->serviceapplication && mfx->serviceapplication->appid)
963 mfx->mainapp_id = strdup(mfx->serviceapplication->appid);
967 memset(query, '\0', MAX_QUERY_LEN);
968 snprintf(query, MAX_QUERY_LEN,
969 "update package_info set mainapp_id='%s' where package='%s'", mfx->mainapp_id, mfx->package);
970 ret = __exec_query(query);
972 DBG("Package Info DB update Failed\n");
978 /* _PRODUCT_LAUNCHING_ENHANCED_
979 * up->indicatordisplay, up->portraitimg, up->landscapeimg, up->guestmode_appstatus
981 static int __insert_uiapplication_info(manifest_x *mfx)
983 uiapplication_x *up = mfx->uiapplication;
985 char query[MAX_QUERY_LEN] = {'\0'};
988 snprintf(query, MAX_QUERY_LEN,
989 "insert into package_app_info(app_id, app_component, app_exec, app_nodisplay, app_type, app_onboot, " \
990 "app_multiple, app_autorestart, app_taskmanage, app_enabled, app_hwacceleration, app_mainapp , app_recentimage, app_indicatordisplay, app_portraitimg, app_landscapeimg, app_guestmodevisibility, package) " \
991 "values('%s', '%s', '%s', '%s', '%s', '%s','%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",\
992 up->appid, "uiapp", up->exec, up->nodisplay, up->type, "\0", up->multiple,
993 "\0", up->taskmanage, up->enabled, up->hwacceleration,up->mainapp, up->recentimage, up->indicatordisplay, up->portraitimg, up->landscapeimg, up->guestmode_visibility, mfx->package);
994 ret = __exec_query(query);
996 DBG("Package UiApp Info DB Insert Failed\n");
1000 memset(query, '\0', MAX_QUERY_LEN);
1005 static int __insert_uiapplication_appcategory_info(manifest_x *mfx)
1007 uiapplication_x *up = mfx->uiapplication;
1008 category_x *ct = NULL;
1010 char query[MAX_QUERY_LEN] = {'\0'};
1016 snprintf(query, MAX_QUERY_LEN,
1017 "insert into package_app_app_category(app_id, category) " \
1018 "values('%s','%s')",\
1019 up->appid, ct->name);
1020 ret = __exec_query(query);
1022 DBG("Package UiApp Category Info DB Insert Failed\n");
1026 memset(query, '\0', MAX_QUERY_LEN);
1033 static int __insert_uiapplication_appmetadata_info(manifest_x *mfx)
1035 uiapplication_x *up = mfx->uiapplication;
1036 metadata_x *md = NULL;
1038 char query[MAX_QUERY_LEN] = {'\0'};
1044 if (md->name && md->value) {
1045 snprintf(query, MAX_QUERY_LEN,
1046 "insert into package_app_app_metadata(app_id, md_name, md_value) " \
1047 "values('%s','%s', '%s')",\
1048 up->appid, md->name, md->value);
1049 ret = __exec_query(query);
1051 DBG("Package UiApp Metadata Info DB Insert Failed\n");
1056 memset(query, '\0', MAX_QUERY_LEN);
1063 static int __insert_uiapplication_apppermission_info(manifest_x *mfx)
1065 uiapplication_x *up = mfx->uiapplication;
1066 permission_x *pm = NULL;
1068 char query[MAX_QUERY_LEN] = {'\0'};
1071 pm = up->permission;
1074 snprintf(query, MAX_QUERY_LEN,
1075 "insert into package_app_app_permission(app_id, pm_type, pm_value) " \
1076 "values('%s','%s', '%s')",\
1077 up->appid, pm->type, pm->value);
1078 ret = __exec_query(query);
1080 DBG("Package UiApp permission Info DB Insert Failed\n");
1084 memset(query, '\0', MAX_QUERY_LEN);
1091 static int __insert_uiapplication_appcontrol_info(manifest_x *mfx)
1093 uiapplication_x *up = mfx->uiapplication;
1094 appcontrol_x *acontrol = NULL;
1095 operation_x *op = NULL;
1098 subapp_x *sub = NULL;
1100 char query[MAX_QUERY_LEN] = {'\0'};
1101 char *operation = NULL;
1104 char *subapp = NULL;
1107 acontrol = up->appcontrol;
1108 while(acontrol != NULL)
1110 op = acontrol->operation;
1114 operation = op->name;
1115 mi = acontrol->mime;
1121 sub = acontrol->subapp;
1131 snprintf(query, MAX_QUERY_LEN,
1132 "insert into package_app_app_control(app_id, operation, uri_scheme, mime_type, subapp_name) " \
1133 "values('%s', '%s', '%s', '%s', '%s')",\
1134 up->appid, operation, uri, mime, subapp);
1136 ret = __exec_query(query);
1138 DBG("Package UiApp AppSvc DB Insert Failed\n");
1141 memset(query, '\0', MAX_QUERY_LEN);
1145 } while(ui != NULL);
1149 }while(sub != NULL);
1158 acontrol = acontrol->next;
1165 static int __insert_uiapplication_appsvc_info(manifest_x *mfx)
1167 uiapplication_x *up = mfx->uiapplication;
1168 appsvc_x *asvc = NULL;
1169 operation_x *op = NULL;
1172 subapp_x *sub = NULL;
1174 char query[MAX_QUERY_LEN] = {'\0'};
1175 char *operation = NULL;
1178 char *subapp = NULL;
1184 op = asvc->operation;
1188 operation = op->name;
1205 snprintf(query, MAX_QUERY_LEN,
1206 "insert into package_app_app_svc(app_id, operation, uri_scheme, mime_type, subapp_name) " \
1207 "values('%s', '%s', '%s', '%s', '%s')",\
1208 up->appid, operation, uri, mime, subapp);
1210 ret = __exec_query(query);
1212 DBG("Package UiApp AppSvc DB Insert Failed\n");
1215 memset(query, '\0', MAX_QUERY_LEN);
1219 } while(ui != NULL);
1223 }while(sub != NULL);
1239 static int __insert_uiapplication_share_request_info(manifest_x *mfx)
1241 uiapplication_x *up = mfx->uiapplication;
1242 datashare_x *ds = NULL;
1243 request_x *rq = NULL;
1245 char query[MAX_QUERY_LEN] = {'\0'};
1254 snprintf(query, MAX_QUERY_LEN,
1255 "insert into package_app_share_request(app_id, data_share_request) " \
1256 "values('%s', '%s')",\
1257 up->appid, rq->text);
1258 ret = __exec_query(query);
1260 DBG("Package UiApp Share Request DB Insert Failed\n");
1263 memset(query, '\0', MAX_QUERY_LEN);
1273 static int __insert_uiapplication_share_allowed_info(manifest_x *mfx)
1275 uiapplication_x *up = mfx->uiapplication;
1276 datashare_x *ds = NULL;
1277 define_x *df = NULL;
1278 allowed_x *al = NULL;
1280 char query[MAX_QUERY_LEN] = {'\0'};
1292 snprintf(query, MAX_QUERY_LEN,
1293 "insert into package_app_share_allowed(app_id, data_share_path, data_share_allowed) " \
1294 "values('%s', '%s', '%s')",\
1295 up->appid, df->path, al->text);
1296 ret = __exec_query(query);
1298 DBG("Package UiApp Share Allowed DB Insert Failed\n");
1301 memset(query, '\0', MAX_QUERY_LEN);
1313 static int __insert_serviceapplication_info(manifest_x *mfx)
1315 serviceapplication_x *sp = mfx->serviceapplication;
1317 char query[MAX_QUERY_LEN] = {'\0'};
1320 snprintf(query, MAX_QUERY_LEN,
1321 "insert into package_app_info(app_id, app_component, app_exec, app_type, app_onboot, " \
1322 "app_multiple, app_autorestart, app_enabled, package) " \
1323 "values('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",\
1324 sp->appid, "svcapp", sp->exec, sp->type, sp->onboot, "\0",
1325 sp->autorestart, sp->enabled, mfx->package);
1326 ret = __exec_query(query);
1328 DBG("Package ServiceApp Info DB Insert Failed\n");
1332 memset(query, '\0', MAX_QUERY_LEN);
1337 static int __insert_serviceapplication_appcategory_info(manifest_x *mfx)
1339 serviceapplication_x *sp = mfx->serviceapplication;
1340 category_x *ct = NULL;
1342 char query[MAX_QUERY_LEN] = {'\0'};
1348 snprintf(query, MAX_QUERY_LEN,
1349 "insert into package_app_app_category(app_id, category) " \
1350 "values('%s','%s')",\
1351 sp->appid, ct->name);
1352 ret = __exec_query(query);
1354 DBG("Package ServiceApp Category Info DB Insert Failed\n");
1358 memset(query, '\0', MAX_QUERY_LEN);
1365 static int __insert_serviceapplication_appmetadata_info(manifest_x *mfx)
1367 serviceapplication_x *sp = mfx->serviceapplication;
1368 metadata_x *md = NULL;
1370 char query[MAX_QUERY_LEN] = {'\0'};
1376 if (md->name && md->value) {
1377 snprintf(query, MAX_QUERY_LEN,
1378 "insert into package_app_app_metadata(app_id, md_name, md_value) " \
1379 "values('%s','%s', '%s')",\
1380 sp->appid, md->name, md->value);
1381 ret = __exec_query(query);
1383 DBG("Package ServiceApp Metadata Info DB Insert Failed\n");
1388 memset(query, '\0', MAX_QUERY_LEN);
1395 static int __insert_serviceapplication_apppermission_info(manifest_x *mfx)
1397 serviceapplication_x *sp = mfx->serviceapplication;
1398 permission_x *pm = NULL;
1400 char query[MAX_QUERY_LEN] = {'\0'};
1403 pm = sp->permission;
1406 snprintf(query, MAX_QUERY_LEN,
1407 "insert into package_app_app_permission(app_id, pm_type, pm_value) " \
1408 "values('%s','%s', '%s')",\
1409 sp->appid, pm->type, pm->value);
1410 ret = __exec_query(query);
1412 DBG("Package ServiceApp permission Info DB Insert Failed\n");
1416 memset(query, '\0', MAX_QUERY_LEN);
1423 static int __insert_serviceapplication_appcontrol_info(manifest_x *mfx)
1425 serviceapplication_x *sp = mfx->serviceapplication;
1426 appcontrol_x *acontrol = NULL;
1428 char query[MAX_QUERY_LEN] = {'\0'};
1429 operation_x *op = NULL;
1432 subapp_x *sub = NULL;
1433 char *operation = NULL;
1436 char *subapp = NULL;
1439 acontrol = sp->appcontrol;
1440 while(acontrol != NULL)
1442 op = acontrol->operation;
1446 operation = op->name;
1447 mi = acontrol->mime;
1452 sub = acontrol->subapp;
1462 snprintf(query, MAX_QUERY_LEN,
1463 "insert into package_app_app_control(app_id, operation, uri_scheme, mime_type,subapp_name) " \
1464 "values('%s', '%s', '%s', '%s', '%s')",\
1465 sp->appid, operation, uri, mime, subapp);
1466 ret = __exec_query(query);
1468 DBG("Package UiApp AppSvc DB Insert Failed\n");
1471 memset(query, '\0', MAX_QUERY_LEN);
1475 } while(ui != NULL);
1479 }while(sub != NULL);
1488 acontrol = acontrol->next;
1495 static int __insert_serviceapplication_appsvc_info(manifest_x *mfx)
1497 serviceapplication_x *sp = mfx->serviceapplication;
1498 appsvc_x *asvc = NULL;
1500 char query[MAX_QUERY_LEN] = {'\0'};
1501 operation_x *op = NULL;
1504 subapp_x *sub = NULL;
1505 char *operation = NULL;
1508 char *subapp = NULL;
1514 op = asvc->operation;
1518 operation = op->name;
1534 snprintf(query, MAX_QUERY_LEN,
1535 "insert into package_app_app_svc(app_id, operation, uri_scheme, mime_type, subapp_name) " \
1536 "values('%s', '%s', '%s', '%s', '%s')",\
1537 sp->appid, operation, uri, mime, subapp);
1538 ret = __exec_query(query);
1540 DBG("Package UiApp AppSvc DB Insert Failed\n");
1543 memset(query, '\0', MAX_QUERY_LEN);
1547 } while(ui != NULL);
1551 }while(sub != NULL);
1569 static int __insert_serviceapplication_share_request_info(manifest_x *mfx)
1571 serviceapplication_x *sp = mfx->serviceapplication;
1572 datashare_x *ds = NULL;
1573 request_x *rq = NULL;
1575 char query[MAX_QUERY_LEN] = {'\0'};
1584 snprintf(query, MAX_QUERY_LEN,
1585 "insert into package_app_share_request(app_id, data_share_request) " \
1586 "values('%s', '%s')",\
1587 sp->appid, rq->text);
1588 ret = __exec_query(query);
1590 DBG("Package ServiceApp Share Request DB Insert Failed\n");
1593 memset(query, '\0', MAX_QUERY_LEN);
1605 static int __insert_serviceapplication_share_allowed_info(manifest_x *mfx)
1607 serviceapplication_x *sp = mfx->serviceapplication;
1608 datashare_x *ds = NULL;
1609 define_x *df = NULL;
1610 allowed_x *al = NULL;
1612 char query[MAX_QUERY_LEN] = {'\0'};
1624 snprintf(query, MAX_QUERY_LEN,
1625 "insert into package_app_share_allowed(app_id, data_share_path, data_share_allowed) " \
1626 "values('%s', '%s', '%s')",\
1627 sp->appid, df->path, al->text);
1628 ret = __exec_query(query);
1630 DBG("Package App Share Allowed DB Insert Failed\n");
1633 memset(query, '\0', MAX_QUERY_LEN);
1645 static int __insert_manifest_info_in_db(manifest_x *mfx)
1647 label_x *lbl = mfx->label;
1648 license_x *lcn = mfx->license;
1649 icon_x *icn = mfx->icon;
1650 description_x *dcn = mfx->description;
1651 author_x *ath = mfx->author;
1652 uiapplication_x *up = mfx->uiapplication;
1653 uiapplication_x *up_icn = mfx->uiapplication;
1654 uiapplication_x *up_image = mfx->uiapplication;
1655 serviceapplication_x *sp = mfx->serviceapplication;
1656 char query[MAX_QUERY_LEN] = { '\0' };
1660 char *auth_name = NULL;
1661 char *auth_email = NULL;
1662 char *auth_href = NULL;
1665 auth_name = ath->text;
1667 auth_email = ath->email;
1669 auth_href = ath->href;
1672 /*Insert in the package_info DB*/
1674 type = strdup(mfx->type);
1676 type = strdup("rpm");
1677 /*Insert in the package_info DB*/
1679 path = strdup(mfx->root_path);
1681 if (strcmp(type,"rpm")==0)
1682 path = strdup("/usr/apps");
1684 path = strdup("/opt/usr/apps");
1686 snprintf(query, MAX_QUERY_LEN,
1687 "insert into package_info(package, package_type, package_version, install_location, package_size, " \
1688 "package_removable, package_preload, package_readonly, author_name, author_email, author_href, installed_time, storeclient_id, mainapp_id, package_url, root_path) " \
1689 "values('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",\
1690 mfx->package, type, mfx->version, mfx->installlocation, mfx->package_size, mfx->removable, mfx->preload,
1691 mfx->readonly, auth_name, auth_email, auth_href, mfx->installed_time, mfx->storeclient_id, mfx->mainapp_id, mfx->package_url, path);
1692 ret = __exec_query(query);
1694 DBG("Package Info DB Insert Failed\n");
1713 /*Insert the package locale and app locale info */
1714 pkglocale = __create_locale_list(pkglocale, lbl, lcn, icn, dcn, ath);
1715 g_list_foreach(pkglocale, __trimfunc1, NULL);
1720 applocale = __create_locale_list(applocale, up->label, NULL, up->icon, NULL, NULL);
1725 applocale = __create_locale_list(applocale, sp->label, NULL, sp->icon, NULL, NULL);
1728 g_list_foreach(applocale, __trimfunc2, NULL);
1731 /*Insert the app icon info */
1732 while(up_icn != NULL)
1734 appicon = __create_icon_list(appicon, up_icn->icon);
1735 up_icn = up_icn->next;
1737 g_list_foreach(appicon, __trimfunc3, NULL);
1740 /*Insert the image info */
1741 while(up_image != NULL)
1743 appimage = __create_image_list(appimage, up_image->image);
1744 up_image = up_image->next;
1746 g_list_foreach(appimage, __trimfunc4, NULL);
1749 /*g_list_foreach(pkglocale, __printfunc, NULL);*/
1751 /*g_list_foreach(applocale, __printfunc, NULL);*/
1753 /*package locale info*/
1754 g_list_foreach(pkglocale, __insert_pkglocale_info, (gpointer)mfx);
1755 /*native app locale info*/
1756 up = mfx->uiapplication;
1759 g_list_foreach(applocale, __insert_uiapplication_locale_info, (gpointer)up);
1762 /*agent app locale info*/
1763 sp = mfx->serviceapplication;
1766 g_list_foreach(applocale, __insert_serviceapplication_locale_info, (gpointer)sp);
1770 /*app icon locale info*/
1771 up_icn = mfx->uiapplication;
1772 while(up_icn != NULL)
1774 g_list_foreach(appicon, __insert_uiapplication_icon_section_info, (gpointer)up_icn);
1775 up_icn = up_icn->next;
1779 up_image = mfx->uiapplication;
1780 while(up_image != NULL)
1782 g_list_foreach(appimage, __insert_uiapplication_image_info, (gpointer)up_image);
1783 up_image = up_image->next;
1786 g_list_free(pkglocale);
1788 g_list_free(applocale);
1790 g_list_free(appicon);
1792 g_list_free(appimage);
1796 /*Insert in the package_app_info DB*/
1797 ret = __insert_uiapplication_info(mfx);
1800 ret = __insert_ui_mainapp_info(mfx);
1803 ret = __insert_serviceapplication_info(mfx);
1807 /*Insert in the package_app_app_control DB*/
1808 ret = __insert_uiapplication_appcontrol_info(mfx);
1811 ret = __insert_serviceapplication_appcontrol_info(mfx);
1815 /*Insert in the package_app_app_category DB*/
1816 ret = __insert_uiapplication_appcategory_info(mfx);
1819 ret = __insert_serviceapplication_appcategory_info(mfx);
1823 /*Insert in the package_app_app_metadata DB*/
1824 ret = __insert_uiapplication_appmetadata_info(mfx);
1827 ret = __insert_serviceapplication_appmetadata_info(mfx);
1831 /*Insert in the package_app_app_permission DB*/
1832 ret = __insert_uiapplication_apppermission_info(mfx);
1835 ret = __insert_serviceapplication_apppermission_info(mfx);
1839 /*Insert in the package_app_app_svc DB*/
1840 ret = __insert_uiapplication_appsvc_info(mfx);
1843 ret = __insert_serviceapplication_appsvc_info(mfx);
1847 /*Insert in the package_app_share_allowed DB*/
1848 ret = __insert_uiapplication_share_allowed_info(mfx);
1851 ret = __insert_serviceapplication_share_allowed_info(mfx);
1855 /*Insert in the package_app_share_request DB*/
1856 ret = __insert_uiapplication_share_request_info(mfx);
1859 ret = __insert_serviceapplication_share_request_info(mfx);
1867 static int __delete_cert_info_from_db(manifest_x *mfx)
1869 char query[MAX_QUERY_LEN] = { '\0' };
1871 char *error_message = NULL;
1873 ret = __pkgmgr_parser_cert_create_db();
1875 DBG("Failed to open DB\n");
1879 /*Begin transaction*/
1880 ret = sqlite3_exec(pkgmgr_cert_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
1881 if (ret != SQLITE_OK) {
1882 DBG("Failed to begin transaction\n");
1883 sqlite3_close(pkgmgr_cert_db);
1886 DBG("Transaction Begin\n");
1887 snprintf(query, MAX_QUERY_LEN,
1888 "delete from package_cert_info where package='%s'", mfx->package);
1891 sqlite3_exec(pkgmgr_cert_db, query, NULL, NULL, &error_message)) {
1892 DBG("Don't execute query = %s error message = %s\n", query,
1896 sqlite3_free(error_message);
1899 DBG("Delete from DB failed. Rollback now\n");
1900 sqlite3_exec(pkgmgr_cert_db, "ROLLBACK", NULL, NULL, NULL);
1901 sqlite3_close(pkgmgr_cert_db);
1904 /*Commit transaction*/
1905 ret = sqlite3_exec(pkgmgr_cert_db, "COMMIT", NULL, NULL, NULL);
1906 if (ret != SQLITE_OK) {
1907 DBG("Failed to commit transaction, Rollback now\n");
1908 sqlite3_exec(pkgmgr_cert_db, "ROLLBACK", NULL, NULL, NULL);
1909 sqlite3_close(pkgmgr_cert_db);
1912 DBG("Transaction Commit and End\n");
1913 sqlite3_free(error_message);
1914 sqlite3_close(pkgmgr_cert_db);
1919 static int __delete_manifest_info_from_db(manifest_x *mfx)
1921 char query[MAX_QUERY_LEN] = { '\0' };
1923 uiapplication_x *up = mfx->uiapplication;
1924 serviceapplication_x *sp = mfx->serviceapplication;
1926 ret = __delete_cert_info_from_db(mfx);
1928 DBG("Package cert DB Delete Failed\n");
1932 /*Delete from Package Info DB*/
1933 snprintf(query, MAX_QUERY_LEN,
1934 "delete from package_info where package='%s'", mfx->package);
1935 ret = __exec_query(query);
1937 DBG("Package Info DB Delete Failed\n");
1940 memset(query, '\0', MAX_QUERY_LEN);
1942 /*Delete from Package Localized Info*/
1943 snprintf(query, MAX_QUERY_LEN,
1944 "delete from package_localized_info where package='%s'", mfx->package);
1945 ret = __exec_query(query);
1947 DBG("Package Localized Info DB Delete Failed\n");
1950 memset(query, '\0', MAX_QUERY_LEN);
1952 /*Delete from Package App Info*/
1955 snprintf(query, MAX_QUERY_LEN,
1956 "delete from package_app_info where app_id='%s'", up->appid);
1957 ret = __exec_query(query);
1959 DBG("Package App Info DB Delete Failed\n");
1962 memset(query, '\0', MAX_QUERY_LEN);
1967 snprintf(query, MAX_QUERY_LEN,
1968 "delete from package_app_info where app_id='%s'", sp->appid);
1969 ret = __exec_query(query);
1971 DBG("Package App Info DB Delete Failed\n");
1974 memset(query, '\0', MAX_QUERY_LEN);
1978 /*Delete from Package App Localized Info*/
1979 up = mfx->uiapplication;
1980 sp = mfx->serviceapplication;
1983 snprintf(query, MAX_QUERY_LEN,
1984 "delete from package_app_localized_info where app_id='%s'", up->appid);
1985 ret = __exec_query(query);
1987 DBG("Package App Localized Info DB Delete Failed\n");
1990 memset(query, '\0', MAX_QUERY_LEN);
1995 snprintf(query, MAX_QUERY_LEN,
1996 "delete from package_app_localized_info where app_id='%s'", sp->appid);
1997 ret = __exec_query(query);
1999 DBG("Package App Localized Info DB Delete Failed\n");
2002 memset(query, '\0', MAX_QUERY_LEN);
2006 /*Delete from App icon localized Info*/
2007 up = mfx->uiapplication;
2010 snprintf(query, MAX_QUERY_LEN,
2011 "delete from package_app_icon_section_info where app_id='%s'", up->appid);
2012 ret = __exec_query(query);
2014 DBG("Package App image Info DB Delete Failed\n");
2017 memset(query, '\0', MAX_QUERY_LEN);
2021 /*Delete from App image Info*/
2022 up = mfx->uiapplication;
2025 snprintf(query, MAX_QUERY_LEN,
2026 "delete from package_app_image_info where app_id='%s'", up->appid);
2027 ret = __exec_query(query);
2029 DBG("Package App image Info DB Delete Failed\n");
2032 memset(query, '\0', MAX_QUERY_LEN);
2036 /*Delete from Package App App-Svc*/
2037 up = mfx->uiapplication;
2038 sp = mfx->serviceapplication;
2041 snprintf(query, MAX_QUERY_LEN,
2042 "delete from package_app_app_svc where app_id='%s'", up->appid);
2043 ret = __exec_query(query);
2045 DBG("Package App App-Svc DB Delete Failed\n");
2048 memset(query, '\0', MAX_QUERY_LEN);
2053 snprintf(query, MAX_QUERY_LEN,
2054 "delete from package_app_app_svc where app_id='%s'", sp->appid);
2055 ret = __exec_query(query);
2057 DBG("Package App App-Svc DB Delete Failed\n");
2060 memset(query, '\0', MAX_QUERY_LEN);
2064 /*Delete from Package App App-Control*/
2065 up = mfx->uiapplication;
2066 sp = mfx->serviceapplication;
2069 snprintf(query, MAX_QUERY_LEN,
2070 "delete from package_app_app_control where app_id='%s'", up->appid);
2071 ret = __exec_query(query);
2073 DBG("Package App App-Control DB Delete Failed\n");
2076 memset(query, '\0', MAX_QUERY_LEN);
2081 snprintf(query, MAX_QUERY_LEN,
2082 "delete from package_app_app_control where app_id='%s'", sp->appid);
2083 ret = __exec_query(query);
2085 DBG("Package App App-Control DB Delete Failed\n");
2088 memset(query, '\0', MAX_QUERY_LEN);
2092 /*Delete from Package App App-Category*/
2093 up = mfx->uiapplication;
2094 sp = mfx->serviceapplication;
2097 snprintf(query, MAX_QUERY_LEN,
2098 "delete from package_app_app_category where app_id='%s'", up->appid);
2099 ret = __exec_query(query);
2101 DBG("Package App App-Category DB Delete Failed\n");
2104 memset(query, '\0', MAX_QUERY_LEN);
2109 snprintf(query, MAX_QUERY_LEN,
2110 "delete from package_app_app_category where app_id='%s'", sp->appid);
2111 ret = __exec_query(query);
2113 DBG("Package App App-Category DB Delete Failed\n");
2116 memset(query, '\0', MAX_QUERY_LEN);
2120 /*Delete from Package App App-Metadata*/
2121 up = mfx->uiapplication;
2122 sp = mfx->serviceapplication;
2125 snprintf(query, MAX_QUERY_LEN,
2126 "delete from package_app_app_metadata where app_id='%s'", up->appid);
2127 ret = __exec_query(query);
2129 DBG("Package App App-Metadata DB Delete Failed\n");
2132 memset(query, '\0', MAX_QUERY_LEN);
2137 snprintf(query, MAX_QUERY_LEN,
2138 "delete from package_app_app_metadata where app_id='%s'", sp->appid);
2139 ret = __exec_query(query);
2141 DBG("Package App App-Metadata DB Delete Failed\n");
2144 memset(query, '\0', MAX_QUERY_LEN);
2148 /*Delete from Package App App-permission*/
2149 up = mfx->uiapplication;
2150 sp = mfx->serviceapplication;
2153 snprintf(query, MAX_QUERY_LEN,
2154 "delete from package_app_app_permission where app_id='%s'", up->appid);
2155 ret = __exec_query(query);
2157 DBG("Package App App-permission DB Delete Failed\n");
2160 memset(query, '\0', MAX_QUERY_LEN);
2165 snprintf(query, MAX_QUERY_LEN,
2166 "delete from package_app_app_permission where app_id='%s'", sp->appid);
2167 ret = __exec_query(query);
2169 DBG("Package App App-permission DB Delete Failed\n");
2172 memset(query, '\0', MAX_QUERY_LEN);
2176 /*Delete from Package App Share Allowed*/
2177 up = mfx->uiapplication;
2178 sp = mfx->serviceapplication;
2181 snprintf(query, MAX_QUERY_LEN,
2182 "delete from package_app_share_allowed where app_id='%s'", up->appid);
2183 ret = __exec_query(query);
2185 DBG("Package App Share Allowed DB Delete Failed\n");
2188 memset(query, '\0', MAX_QUERY_LEN);
2193 snprintf(query, MAX_QUERY_LEN,
2194 "delete from package_app_share_allowed where app_id='%s'", sp->appid);
2195 ret = __exec_query(query);
2197 DBG("Package App Share Allowed DB Delete Failed\n");
2200 memset(query, '\0', MAX_QUERY_LEN);
2204 /*Delete from Package App Share Request*/
2205 up = mfx->uiapplication;
2206 sp = mfx->serviceapplication;
2209 snprintf(query, MAX_QUERY_LEN,
2210 "delete from package_app_share_request where app_id='%s'", up->appid);
2211 ret = __exec_query(query);
2213 DBG("Package App Share Request DB Delete Failed\n");
2216 memset(query, '\0', MAX_QUERY_LEN);
2221 snprintf(query, MAX_QUERY_LEN,
2222 "delete from package_app_share_request where app_id='%s'", sp->appid);
2223 ret = __exec_query(query);
2225 DBG("Package App Share Request DB Delete Failed\n");
2228 memset(query, '\0', MAX_QUERY_LEN);
2235 int pkgmgr_parser_initialize_db()
2238 ret = __initialize_package_info_db();
2240 DBG("package info DB initialization failed\n");
2243 ret = __initialize_package_localized_info_db();
2245 DBG("package localized info DB initialization failed\n");
2248 ret = __initialize_package_cert_info_db();
2250 DBG("package cert info DB initialization failed\n");
2253 ret = __initialize_package_app_info_db();
2255 DBG("package app info DB initialization failed\n");
2258 ret = __initialize_package_app_localized_info_db();
2260 DBG("package app localized info DB initialization failed\n");
2263 ret = __initialize_package_app_icon_section_info_db();
2265 DBG("package app icon localized info DB initialization failed\n");
2268 ret = __initialize_package_app_image_info_db();
2270 DBG("package app image info DB initialization failed\n");
2273 ret = __initialize_package_app_app_control_db();
2275 DBG("package app app control DB initialization failed\n");
2278 ret = __initialize_package_app_app_category_db();
2280 DBG("package app app category DB initialization failed\n");
2283 ret = __initialize_package_app_app_metadata_db();
2285 DBG("package app app category DB initialization failed\n");
2288 ret = __initialize_package_app_app_permission_db();
2290 DBG("package app app permission DB initialization failed\n");
2293 ret = __initialize_package_app_app_svc_db();
2295 DBG("package app app svc DB initialization failed\n");
2298 ret = __initialize_package_app_share_allowed_db();
2300 DBG("package app share allowed DB initialization failed\n");
2303 ret = __initialize_package_app_share_request_db();
2305 DBG("package app share request DB initialization failed\n");
2311 int pkgmgr_parser_check_and_create_db()
2314 if (access(PKGMGR_PARSER_DB_FILE, F_OK) == 0) {
2316 db_util_open(PKGMGR_PARSER_DB_FILE, &pkgmgr_parser_db,
2317 DB_UTIL_REGISTER_HOOK_METHOD);
2318 if (ret != SQLITE_OK) {
2319 DBG("connect db [%s] failed!\n",
2320 PKGMGR_PARSER_DB_FILE);
2323 ret = chmod(PKGMGR_PARSER_DB_FILE, 0664);
2325 DBG("Failed to change mode of manifest DB\n");
2328 DBG("Pkgmgr DB does not exists. Create one!!\n");
2331 db_util_open(PKGMGR_PARSER_DB_FILE, &pkgmgr_parser_db,
2332 DB_UTIL_REGISTER_HOOK_METHOD);
2334 if (ret != SQLITE_OK) {
2335 DBG("connect db [%s] failed!\n", PKGMGR_PARSER_DB_FILE);
2338 ret = chmod(PKGMGR_PARSER_DB_FILE, 0664);
2340 DBG("Failed to change mode of manifest DB\n");
2344 API int pkgmgr_parser_insert_manifest_info_in_db(manifest_x *mfx)
2347 DBG("manifest pointer is NULL\n");
2351 ret = pkgmgr_parser_check_and_create_db();
2353 DBG("Failed to open DB\n");
2356 ret = pkgmgr_parser_initialize_db();
2359 /*Begin transaction*/
2360 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2361 if (ret != SQLITE_OK) {
2362 DBG("Failed to begin transaction\n");
2363 sqlite3_close(pkgmgr_parser_db);
2366 DBG("Transaction Begin\n");
2367 ret = __insert_manifest_info_in_db(mfx);
2369 DBG("Insert into DB failed. Rollback now\n");
2370 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2371 sqlite3_close(pkgmgr_parser_db);
2374 /*Commit transaction*/
2375 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2376 if (ret != SQLITE_OK) {
2377 DBG("Failed to commit transaction. Rollback now\n");
2378 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2379 sqlite3_close(pkgmgr_parser_db);
2382 DBG("Transaction Commit and End\n");
2383 sqlite3_close(pkgmgr_parser_db);
2387 API int pkgmgr_parser_update_manifest_info_in_db(manifest_x *mfx)
2390 DBG("manifest pointer is NULL\n");
2394 ret = pkgmgr_parser_check_and_create_db();
2396 DBG("Failed to open DB\n");
2399 ret = pkgmgr_parser_initialize_db();
2402 /*Preserve guest mode visibility*/
2403 __preserve_guestmode_visibility_value( mfx);
2404 /*Begin transaction*/
2405 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2406 if (ret != SQLITE_OK) {
2407 DBG("Failed to begin transaction\n");
2408 sqlite3_close(pkgmgr_parser_db);
2411 DBG("Transaction Begin\n");
2412 ret = __delete_manifest_info_from_db(mfx);
2414 DBG("Delete from DB failed. Rollback now\n");
2415 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2416 sqlite3_close(pkgmgr_parser_db);
2419 ret = __insert_manifest_info_in_db(mfx);
2421 DBG("Insert into DB failed. Rollback now\n");
2422 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2423 sqlite3_close(pkgmgr_parser_db);
2427 /*Commit transaction*/
2428 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2429 if (ret != SQLITE_OK) {
2430 DBG("Failed to commit transaction. Rollback now\n");
2431 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2432 sqlite3_close(pkgmgr_parser_db);
2435 DBG("Transaction Commit and End\n");
2436 sqlite3_close(pkgmgr_parser_db);
2440 API int pkgmgr_parser_delete_manifest_info_from_db(manifest_x *mfx)
2443 DBG("manifest pointer is NULL\n");
2447 ret = pkgmgr_parser_check_and_create_db();
2449 DBG("Failed to open DB\n");
2452 /*Begin transaction*/
2453 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2454 if (ret != SQLITE_OK) {
2455 DBG("Failed to begin transaction\n");
2456 sqlite3_close(pkgmgr_parser_db);
2459 DBG("Transaction Begin\n");
2460 ret = __delete_manifest_info_from_db(mfx);
2462 DBG("Delete from DB failed. Rollback now\n");
2463 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2464 sqlite3_close(pkgmgr_parser_db);
2467 /*Commit transaction*/
2468 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2469 if (ret != SQLITE_OK) {
2470 DBG("Failed to commit transaction, Rollback now\n");
2471 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2472 sqlite3_close(pkgmgr_parser_db);
2475 DBG("Transaction Commit and End\n");
2476 sqlite3_close(pkgmgr_parser_db);