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 "package_update text DEFAULT 'false', " \
55 "package_appsetting text DEFAULT 'false', " \
56 "author_name text, " \
57 "author_email text, " \
59 "installed_time text," \
60 "installed_storage text," \
61 "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_APP_INFO "create table if not exists package_app_info " \
80 "(app_id text primary key not null, " \
81 "app_component text, " \
83 "app_nodisplay text DEFAULT 'false', " \
85 "app_onboot text DEFAULT 'false', " \
86 "app_multiple text DEFAULT 'false', " \
87 "app_autorestart text DEFAULT 'false', " \
88 "app_taskmanage text DEFAULT 'false', " \
89 "app_enabled text DEFAULT 'true', " \
90 "app_hwacceleration text DEFAULT 'use-system-setting', " \
91 "app_mainapp text, " \
92 "app_recentimage text, " \
93 "app_indicatordisplay text DEFAULT 'true', " \
94 "app_portraitimg text, " \
95 "app_landscapeimg text, " \
96 "app_guestmodevisibility text DEFAULT 'true', " \
97 "package text not null, " \
98 "FOREIGN KEY(package) " \
99 "REFERENCES package_info(package) " \
102 #define QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO "create table if not exists package_app_localized_info " \
103 "(app_id text not null, " \
104 "app_locale text DEFAULT 'No Locale', " \
107 "PRIMARY KEY(app_id,app_locale) " \
108 "FOREIGN KEY(app_id) " \
109 "REFERENCES package_app_info(app_id) " \
112 #define QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO "create table if not exists package_app_icon_section_info " \
113 "(app_id text not null, " \
115 "app_icon_section text, " \
116 "app_icon_resolution text, " \
117 "PRIMARY KEY(app_id,app_icon_section,app_icon_resolution) " \
118 "FOREIGN KEY(app_id) " \
119 "REFERENCES package_app_info(app_id) " \
122 #define QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO "create table if not exists package_app_image_info " \
123 "(app_id text not null, " \
124 "app_locale text DEFAULT 'No Locale', " \
125 "app_image_section text, " \
127 "PRIMARY KEY(app_id,app_image_section) " \
128 "FOREIGN KEY(app_id) " \
129 "REFERENCES package_app_info(app_id) " \
132 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL "create table if not exists package_app_app_control " \
133 "(app_id text not null, " \
134 "operation text not null, " \
135 "uri_scheme text, " \
137 "subapp_name text, " \
138 "PRIMARY KEY(app_id,operation,uri_scheme,mime_type,subapp_name) " \
139 "FOREIGN KEY(app_id) " \
140 "REFERENCES package_app_info(app_id) " \
143 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_SVC "create table if not exists package_app_app_svc " \
144 "(app_id text not null, " \
145 "operation text not null, " \
146 "uri_scheme text, " \
148 "subapp_name text, " \
149 "PRIMARY KEY(app_id,operation,uri_scheme,mime_type,subapp_name) " \
150 "FOREIGN KEY(app_id) " \
151 "REFERENCES package_app_info(app_id) " \
154 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY "create table if not exists package_app_app_category " \
155 "(app_id text not null, " \
156 "category text not null, " \
157 "PRIMARY KEY(app_id,category) " \
158 "FOREIGN KEY(app_id) " \
159 "REFERENCES package_app_info(app_id) " \
162 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA "create table if not exists package_app_app_metadata " \
163 "(app_id text not null, " \
164 "md_name text not null, " \
165 "md_value text not null, " \
166 "PRIMARY KEY(app_id, md_name) " \
167 "FOREIGN KEY(app_id) " \
168 "REFERENCES package_app_info(app_id) " \
171 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION "create table if not exists package_app_app_permission " \
172 "(app_id text not null, " \
173 "pm_type text not null, " \
174 "pm_value text not null, " \
175 "PRIMARY KEY(app_id) " \
176 "FOREIGN KEY(app_id) " \
177 "REFERENCES package_app_info(app_id) " \
180 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED "create table if not exists package_app_share_allowed " \
181 "(app_id text not null, " \
182 "data_share_path text not null, " \
183 "data_share_allowed text not null, " \
184 "PRIMARY KEY(app_id,data_share_path,data_share_allowed) " \
185 "FOREIGN KEY(app_id) " \
186 "REFERENCES package_app_info(app_id) " \
189 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST "create table if not exists package_app_share_request " \
190 "(app_id text not null, " \
191 "data_share_request text not null, " \
192 "PRIMARY KEY(app_id,data_share_request) " \
193 "FOREIGN KEY(app_id) " \
194 "REFERENCES package_app_info(app_id) " \
197 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INFO "create table if not exists package_cert_info " \
198 "(package text not null, " \
199 "author_root_cert text, " \
200 "author_im_cert text, " \
201 "author_signer_cert text, " \
202 "dist_root_cert text, " \
203 "dist_im_cert text, " \
204 "dist_signer_cert text, " \
205 "dist2_root_cert text, " \
206 "dist2_im_cert text, " \
207 "dist2_signer_cert text, " \
208 "PRIMARY KEY(package), " \
209 "FOREIGN KEY(package) " \
210 "REFERENCES package_info(package) " \
213 static int __insert_uiapplication_info(manifest_x *mfx);
214 static int __insert_serviceapplication_info(manifest_x *mfx);
215 static int __insert_uiapplication_appsvc_info(manifest_x *mfx);
216 static int __insert_serviceapplication_appsvc_info(manifest_x *mfx);
217 static int __insert_uiapplication_appcategory_info(manifest_x *mfx);
218 static int __insert_serviceapplication_appcategory_info(manifest_x *mfx);
219 static int __insert_uiapplication_appcontrol_info(manifest_x *mfx);
220 static int __insert_serviceapplication_appmetadata_info(manifest_x *mfx);
221 static int __insert_uiapplication_appmetadata_info(manifest_x *mfx);
222 static int __insert_serviceapplication_appcontrol_info(manifest_x *mfx);
223 static int __insert_uiapplication_share_allowed_info(manifest_x *mfx);
224 static int __insert_serviceapplication_share_allowed_info(manifest_x *mfx);
225 static int __insert_uiapplication_share_request_info(manifest_x *mfx);
226 static int __insert_serviceapplication_share_request_info(manifest_x *mfx);
227 static void __insert_serviceapplication_locale_info(gpointer data, gpointer userdata);
228 static void __insert_uiapplication_locale_info(gpointer data, gpointer userdata);
229 static void __insert_pkglocale_info(gpointer data, gpointer userdata);
230 static int __insert_manifest_info_in_db(manifest_x *mfx);
231 static int __update_manifest_info_in_db(manifest_x *mfx);
232 static int __delete_cert_info_from_db(manifest_x *mfx);
233 static int __delete_manifest_info_from_db(manifest_x *mfx);
234 static int __initialize_package_info_db();
235 static int __initialize_package_localized_info_db();
236 static int __initialize_package_app_info_db();
237 static int __initialize_package_cert_info_db();
238 static int __initialize_package_app_localized_info_db();
239 static int __initialize_package_app_icon_section_info_db();
240 static int __initialize_package_app_image_info_db();
241 static int __initialize_package_app_app_svc_db();
242 static int __initialize_package_app_app_category_db();
243 static int __initialize_package_app_app_control_db();
244 static int __initialize_package_app_app_metadata_db();
245 static int __initialize_package_app_share_allowed_db();
246 static int __initialize_package_app_share_request_db();
247 static int __exec_query(char *query);
248 static void __extract_data(gpointer data, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath,
249 char **label, char **license, char **icon, char **description, char **author);
251 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata);
252 static void __trimfunc1(gpointer data, gpointer userdata);
253 static void __trimfunc2(gpointer data, gpointer userdata);
254 static GList *__create_locale_list(GList *locale, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath);
255 static void __preserve_guestmode_visibility_value(manifest_x *mfx);
256 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname);
258 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname)
260 manifest_x *mfx = (manifest_x *)data;
264 uiapplication_x *uiapp = NULL;
265 for(i = 0; i < ncols; i++)
267 uiapp = mfx->uiapplication;
268 if (strcmp(colname[i], "app_id") == 0) {
270 appid = strdup(coltxt[i]);
271 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0) {
273 status = strdup(coltxt[i]);
276 /*update guest mode visibility*/
277 for (; uiapp != NULL; uiapp = uiapp->next) {
278 if (strcmp(uiapp->appid, appid) == 0) {
279 free((void *)uiapp->guestmode_visibility);
280 uiapp->guestmode_visibility = strdup(status);
296 static void __preserve_guestmode_visibility_value(manifest_x *mfx)
298 char *error_message = NULL;
299 char query[MAX_QUERY_LEN] = {'\0'};
300 snprintf(query, MAX_QUERY_LEN - 1, "select app_id, app_guestmodevisibility from package_app_info where package='%s'", mfx->package);
302 sqlite3_exec(pkgmgr_parser_db, query,
303 __guestmode_visibility_cb, (void *)mfx, &error_message)) {
304 DBG("Don't execute query = %s error message = %s\n",
305 query, error_message);
306 sqlite3_free(error_message);
311 static int __initialize_package_info_db()
313 char *error_message = NULL;
315 sqlite3_exec(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_INFO,
316 NULL, NULL, &error_message)) {
317 DBG("Don't execute query = %s error message = %s\n",
318 QUERY_CREATE_TABLE_PACKAGE_INFO, error_message);
319 sqlite3_free(error_message);
322 sqlite3_free(error_message);
326 static int __pkgmgr_parser_cert_create_db()
329 if (access(PKGMGR_CERT_DB_FILE, F_OK) == 0) {
331 db_util_open(PKGMGR_CERT_DB_FILE, &pkgmgr_cert_db,
332 DB_UTIL_REGISTER_HOOK_METHOD);
333 if (ret != SQLITE_OK) {
334 DBG("connect db [%s] failed!\n",
335 PKGMGR_CERT_DB_FILE);
340 DBG("Pkgmgr DB does not exists. Create one!!\n");
343 db_util_open(PKGMGR_CERT_DB_FILE, &pkgmgr_cert_db,
344 DB_UTIL_REGISTER_HOOK_METHOD);
346 if (ret != SQLITE_OK) {
347 DBG("connect db [%s] failed!\n", PKGMGR_CERT_DB_FILE);
353 static int __initialize_package_cert_info_db()
355 char *error_message = NULL;
357 ret = __pkgmgr_parser_cert_create_db();
359 DBG("Failed to open DB\n");
364 sqlite3_exec(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INFO,
365 NULL, NULL, &error_message)) {
366 DBG("Don't execute query = %s error message = %s\n",
367 QUERY_CREATE_TABLE_PACKAGE_CERT_INFO, error_message);
368 sqlite3_free(error_message);
369 sqlite3_close(pkgmgr_cert_db);
372 sqlite3_free(error_message);
373 sqlite3_close(pkgmgr_cert_db);
377 static int __initialize_package_localized_info_db()
379 char *error_message = NULL;
381 sqlite3_exec(pkgmgr_parser_db,
382 QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO, NULL, NULL,
384 DBG("Don't execute query = %s error message = %s\n",
385 QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO,
387 sqlite3_free(error_message);
390 sqlite3_free(error_message);
394 static int __initialize_package_app_info_db()
396 char *error_message = NULL;
398 sqlite3_exec(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_INFO,
399 NULL, NULL, &error_message)) {
400 DBG("Don't execute query = %s error message = %s\n",
401 QUERY_CREATE_TABLE_PACKAGE_APP_INFO, error_message);
402 sqlite3_free(error_message);
405 sqlite3_free(error_message);
409 static int __initialize_package_app_localized_info_db()
411 char *error_message = NULL;
413 sqlite3_exec(pkgmgr_parser_db,
414 QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO, NULL,
415 NULL, &error_message)) {
416 DBG("Don't execute query = %s error message = %s\n",
417 QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO,
419 sqlite3_free(error_message);
422 sqlite3_free(error_message);
426 static int __initialize_package_app_icon_section_info_db()
428 char *error_message = NULL;
430 sqlite3_exec(pkgmgr_parser_db,
431 QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO, NULL,
432 NULL, &error_message)) {
433 DBG("Don't execute query = %s error message = %s\n",
434 QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO,
436 sqlite3_free(error_message);
439 sqlite3_free(error_message);
443 static int __initialize_package_app_image_info_db()
445 char *error_message = NULL;
447 sqlite3_exec(pkgmgr_parser_db,
448 QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO, NULL,
449 NULL, &error_message)) {
450 DBG("Don't execute query = %s error message = %s\n",
451 QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO,
453 sqlite3_free(error_message);
456 sqlite3_free(error_message);
460 static int __initialize_package_app_app_control_db()
462 char *error_message = NULL;
464 sqlite3_exec(pkgmgr_parser_db,
465 QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL, NULL, NULL,
467 DBG("Don't execute query = %s error message = %s\n",
468 QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL, error_message);
469 sqlite3_free(error_message);
472 sqlite3_free(error_message);
476 static int __initialize_package_app_app_category_db()
478 char *error_message = NULL;
480 sqlite3_exec(pkgmgr_parser_db,
481 QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY, NULL, NULL,
483 DBG("Don't execute query = %s error message = %s\n",
484 QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY, error_message);
485 sqlite3_free(error_message);
488 sqlite3_free(error_message);
492 static int __initialize_package_app_app_metadata_db()
494 char *error_message = NULL;
496 sqlite3_exec(pkgmgr_parser_db,
497 QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA, NULL, NULL,
499 DBG("Don't execute query = %s error message = %s\n",
500 QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA, error_message);
501 sqlite3_free(error_message);
504 sqlite3_free(error_message);
508 static int __initialize_package_app_app_permission_db()
510 char *error_message = NULL;
512 sqlite3_exec(pkgmgr_parser_db,
513 QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION, NULL, NULL,
515 DBG("Don't execute query = %s error message = %s\n",
516 QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION, error_message);
517 sqlite3_free(error_message);
520 sqlite3_free(error_message);
524 static int __initialize_package_app_app_svc_db()
526 char *error_message = NULL;
528 sqlite3_exec(pkgmgr_parser_db,
529 QUERY_CREATE_TABLE_PACKAGE_APP_APP_SVC, NULL, NULL,
531 DBG("Don't execute query = %s error message = %s\n",
532 QUERY_CREATE_TABLE_PACKAGE_APP_APP_SVC, error_message);
533 sqlite3_free(error_message);
536 sqlite3_free(error_message);
540 static int __initialize_package_app_share_allowed_db()
542 char *error_message = NULL;
544 sqlite3_exec(pkgmgr_parser_db,
545 QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED, NULL,
546 NULL, &error_message)) {
547 DBG("Don't execute query = %s error message = %s\n",
548 QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED,
550 sqlite3_free(error_message);
553 sqlite3_free(error_message);
557 static int __initialize_package_app_share_request_db()
559 char *error_message = NULL;
561 sqlite3_exec(pkgmgr_parser_db,
562 QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST, NULL,
563 NULL, &error_message)) {
564 DBG("Don't execute query = %s error message = %s\n",
565 QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST,
567 sqlite3_free(error_message);
570 sqlite3_free(error_message);
574 static int __exec_query(char *query)
576 char *error_message = NULL;
578 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
579 DBG("Don't execute query = %s error message = %s\n", query,
581 sqlite3_free(error_message);
584 sqlite3_free(error_message);
587 static GList *__create_locale_list(GList *locale, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath)
593 locale = g_list_insert_sorted_with_data(locale, (gpointer)lbl->lang, __comparefunc, NULL);
599 locale = g_list_insert_sorted_with_data(locale, (gpointer)lcn->lang, __comparefunc, NULL);
605 locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->lang, __comparefunc, NULL);
611 locale = g_list_insert_sorted_with_data(locale, (gpointer)dcn->lang, __comparefunc, NULL);
617 locale = g_list_insert_sorted_with_data(locale, (gpointer)ath->lang, __comparefunc, NULL);
624 static GList *__create_icon_list(GList *locale, icon_x *icn)
629 locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->section, __comparefunc, NULL);
635 static GList *__create_image_list(GList *locale, image_x *image)
640 locale = g_list_insert_sorted_with_data(locale, (gpointer)image->section, __comparefunc, NULL);
646 static void __printfunc(gpointer data, gpointer userdata)
648 DBG("%s ", (char*)data);
651 static void __trimfunc1(gpointer data, gpointer userdata)
654 if (strcmp((char *)data, prev) == 0) {
655 pkglocale = g_list_remove(pkglocale, data);
663 static void __trimfunc2(gpointer data, gpointer userdata)
666 if (strcmp((char *)data, prev) == 0) {
667 applocale = g_list_remove(applocale, data);
675 static void __trimfunc3(gpointer data, gpointer userdata)
678 if (strcmp((char *)data, prev) == 0) {
679 appicon = g_list_remove(appicon, data);
687 static void __trimfunc4(gpointer data, gpointer userdata)
690 if (strcmp((char *)data, prev) == 0) {
691 appimage = g_list_remove(appimage, data);
699 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata)
701 if (a == NULL || b == NULL)
703 if (strcmp((char*)a, (char*)b) == 0)
705 if (strcmp((char*)a, (char*)b) < 0)
707 if (strcmp((char*)a, (char*)b) > 0)
711 static void __extract_data(gpointer data, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath,
712 char **label, char **license, char **icon, char **description, char **author)
717 if (strcmp(lbl->lang, (char *)data) == 0) {
718 *label = (char*)lbl->text;
727 if (strcmp(lcn->lang, (char *)data) == 0) {
728 *license = (char*)lcn->text;
737 if (strcmp(icn->lang, (char *)data) == 0) {
738 *icon = (char*)icn->text;
747 if (strcmp(dcn->lang, (char *)data) == 0) {
748 *description = (char*)dcn->text;
757 if (strcmp(ath->lang, (char *)data) == 0) {
758 *author = (char*)ath->text;
767 static void __extract_icon_data(gpointer data, icon_x *icn, char **icon, char **resolution)
772 if (strcmp(icn->section, (char *)data) == 0) {
773 *icon = (char*)icn->text;
774 *resolution = (char*)icn->resolution;
782 static void __extract_image_data(gpointer data, icon_x *image, char **lang, char **img)
786 if (image->section) {
787 if (strcmp(image->section, (char *)data) == 0) {
788 *lang = (char*)image->lang;
789 *img = (char*)image->text;
797 static void __insert_pkglocale_info(gpointer data, gpointer userdata)
802 char *description = NULL;
803 char *license = NULL;
805 char query[MAX_QUERY_LEN] = {'\0'};
807 manifest_x *mfx = (manifest_x *)userdata;
808 label_x *lbl = mfx->label;
809 license_x *lcn = mfx->license;
810 icon_x *icn = mfx->icon;
811 description_x *dcn = mfx->description;
812 author_x *ath = mfx->author;
814 __extract_data(data, lbl, lcn, icn, dcn, ath, &label, &license, &icon, &description, &author);
815 if (!label && !description && !icon && !license && !author)
817 snprintf(query, MAX_QUERY_LEN, "insert into package_localized_info(package, package_locale, " \
818 "package_label, package_icon, package_description, package_license, package_author) values " \
819 "('%s', '%s', '%s', '%s', '%s', '%s', '%s')", mfx->package, (char*)data,
820 label, icon, description, license, author);
821 ret = __exec_query(query);
823 DBG("Package Localized Info DB Insert failed\n");
826 static void __insert_uiapplication_locale_info(gpointer data, gpointer userdata)
831 char query[MAX_QUERY_LEN] = {'\0'};
833 uiapplication_x *up = (uiapplication_x*)userdata;
834 label_x *lbl = up->label;
835 icon_x *icn = up->icon;
837 __extract_data(data, lbl, NULL, icn, NULL, NULL, &label, NULL, &icon, NULL, NULL);
840 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_localized_info(app_id, app_locale, " \
841 "app_label, app_icon) values " \
842 "('%q', '%q', '%q', '%q')", up->appid, (char*)data,
844 ret = __exec_query(query);
846 DBG("Package UiApp Localized Info DB Insert failed\n");
850 static void __insert_uiapplication_icon_section_info(gpointer data, gpointer userdata)
854 char *resolution = NULL;
855 char query[MAX_QUERY_LEN] = {'\0'};
857 uiapplication_x *up = (uiapplication_x*)userdata;
858 icon_x *icn = up->icon;
860 __extract_icon_data(data, icn, &icon, &resolution);
861 if (!icon && !resolution)
863 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_icon_section_info(app_id, " \
864 "app_icon, app_icon_section, app_icon_resolution) values " \
865 "('%q', '%q', '%q', '%q')", up->appid,
866 icon, (char*)data, resolution);
868 ret = __exec_query(query);
870 DBG("Package UiApp Localized Info DB Insert failed\n");
874 static void __insert_uiapplication_image_info(gpointer data, gpointer userdata)
879 char query[MAX_QUERY_LEN] = {'\0'};
881 uiapplication_x *up = (uiapplication_x*)userdata;
882 image_x *image = up->image;
884 __extract_image_data(data, image, &lang, &img);
887 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_image_info(app_id, app_locale, " \
888 "app_image_section, app_image) values " \
889 "('%q', '%q', '%q', '%q')", up->appid, lang, (char*)data, img);
891 ret = __exec_query(query);
893 DBG("Package UiApp image Info DB Insert failed\n");
898 static void __insert_serviceapplication_locale_info(gpointer data, gpointer userdata)
903 char query[MAX_QUERY_LEN] = {'\0'};
905 serviceapplication_x *sp = (serviceapplication_x*)userdata;
906 label_x *lbl = sp->label;
907 icon_x *icn = sp->icon;
909 __extract_data(data, lbl, NULL, icn, NULL, NULL, &label, NULL, &icon, NULL, NULL);
912 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_localized_info(app_id, app_locale, " \
913 "app_label, app_icon) values " \
914 "('%q', '%q', '%q', '%q')", sp->appid, (char*)data,
916 ret = __exec_query(query);
918 DBG("Package ServiceApp Localized Info DB Insert failed\n");
921 static int __insert_ui_mainapp_info(manifest_x *mfx)
923 uiapplication_x *up = mfx->uiapplication;
925 char query[MAX_QUERY_LEN] = {'\0'};
928 snprintf(query, MAX_QUERY_LEN,
929 "update package_app_info set app_mainapp='%s' where app_id='%s'", up->mainapp, up->appid);
931 ret = __exec_query(query);
933 DBG("Package UiApp Info DB Insert Failed\n");
936 if (strcasecmp(up->mainapp, "True")==0)
937 mfx->mainapp_id = strdup(up->appid);
940 memset(query, '\0', MAX_QUERY_LEN);
943 if (mfx->mainapp_id == NULL){
944 if (mfx->uiapplication
945 && mfx->uiapplication->appid) {
946 snprintf(query, MAX_QUERY_LEN,
947 "update package_app_info set app_mainapp='true' where app_id='%s'", mfx->uiapplication->appid);
948 } else if (mfx->serviceapplication
949 && mfx->serviceapplication->appid) {
950 snprintf(query, MAX_QUERY_LEN,
951 "update package_app_info set app_mainapp='true' where app_id='%s'", mfx->serviceapplication->appid);
953 DBG("Not valid appid\n");
957 ret = __exec_query(query);
959 DBG("Package UiApp Info DB Insert Failed\n");
962 if (mfx->uiapplication && mfx->uiapplication->appid)
963 mfx->mainapp_id = strdup(mfx->uiapplication->appid);
964 else if (mfx->serviceapplication && mfx->serviceapplication->appid)
965 mfx->mainapp_id = strdup(mfx->serviceapplication->appid);
969 memset(query, '\0', MAX_QUERY_LEN);
970 snprintf(query, MAX_QUERY_LEN,
971 "update package_info set mainapp_id='%s' where package='%s'", mfx->mainapp_id, mfx->package);
972 ret = __exec_query(query);
974 DBG("Package Info DB update Failed\n");
980 /* _PRODUCT_LAUNCHING_ENHANCED_
981 * up->indicatordisplay, up->portraitimg, up->landscapeimg, up->guestmode_appstatus
983 static int __insert_uiapplication_info(manifest_x *mfx)
985 uiapplication_x *up = mfx->uiapplication;
987 char query[MAX_QUERY_LEN] = {'\0'};
990 snprintf(query, MAX_QUERY_LEN,
991 "insert into package_app_info(app_id, app_component, app_exec, app_nodisplay, app_type, app_onboot, " \
992 "app_multiple, app_autorestart, app_taskmanage, app_enabled, app_hwacceleration, app_mainapp , app_recentimage, app_indicatordisplay, app_portraitimg, app_landscapeimg, app_guestmodevisibility, package) " \
993 "values('%s', '%s', '%s', '%s', '%s', '%s','%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",\
994 up->appid, "uiapp", up->exec, up->nodisplay, up->type, "\0", up->multiple,
995 "\0", up->taskmanage, up->enabled, up->hwacceleration,up->mainapp, up->recentimage, up->indicatordisplay, up->portraitimg, up->landscapeimg, up->guestmode_visibility, mfx->package);
996 ret = __exec_query(query);
998 DBG("Package UiApp Info DB Insert Failed\n");
1002 memset(query, '\0', MAX_QUERY_LEN);
1007 static int __insert_uiapplication_appcategory_info(manifest_x *mfx)
1009 uiapplication_x *up = mfx->uiapplication;
1010 category_x *ct = NULL;
1012 char query[MAX_QUERY_LEN] = {'\0'};
1018 snprintf(query, MAX_QUERY_LEN,
1019 "insert into package_app_app_category(app_id, category) " \
1020 "values('%s','%s')",\
1021 up->appid, ct->name);
1022 ret = __exec_query(query);
1024 DBG("Package UiApp Category Info DB Insert Failed\n");
1028 memset(query, '\0', MAX_QUERY_LEN);
1035 static int __insert_uiapplication_appmetadata_info(manifest_x *mfx)
1037 uiapplication_x *up = mfx->uiapplication;
1038 metadata_x *md = NULL;
1040 char query[MAX_QUERY_LEN] = {'\0'};
1046 if (md->name && md->value) {
1047 snprintf(query, MAX_QUERY_LEN,
1048 "insert into package_app_app_metadata(app_id, md_name, md_value) " \
1049 "values('%s','%s', '%s')",\
1050 up->appid, md->name, md->value);
1051 ret = __exec_query(query);
1053 DBG("Package UiApp Metadata Info DB Insert Failed\n");
1058 memset(query, '\0', MAX_QUERY_LEN);
1065 static int __insert_uiapplication_apppermission_info(manifest_x *mfx)
1067 uiapplication_x *up = mfx->uiapplication;
1068 permission_x *pm = NULL;
1070 char query[MAX_QUERY_LEN] = {'\0'};
1073 pm = up->permission;
1076 snprintf(query, MAX_QUERY_LEN,
1077 "insert into package_app_app_permission(app_id, pm_type, pm_value) " \
1078 "values('%s','%s', '%s')",\
1079 up->appid, pm->type, pm->value);
1080 ret = __exec_query(query);
1082 DBG("Package UiApp permission Info DB Insert Failed\n");
1086 memset(query, '\0', MAX_QUERY_LEN);
1093 static int __insert_uiapplication_appcontrol_info(manifest_x *mfx)
1095 uiapplication_x *up = mfx->uiapplication;
1096 appcontrol_x *acontrol = NULL;
1097 operation_x *op = NULL;
1100 subapp_x *sub = NULL;
1102 char query[MAX_QUERY_LEN] = {'\0'};
1103 char *operation = NULL;
1106 char *subapp = NULL;
1109 acontrol = up->appcontrol;
1110 while(acontrol != NULL)
1112 op = acontrol->operation;
1116 operation = op->name;
1117 mi = acontrol->mime;
1123 sub = acontrol->subapp;
1133 snprintf(query, MAX_QUERY_LEN,
1134 "insert into package_app_app_control(app_id, operation, uri_scheme, mime_type, subapp_name) " \
1135 "values('%s', '%s', '%s', '%s', '%s')",\
1136 up->appid, operation, uri, mime, subapp);
1138 ret = __exec_query(query);
1140 DBG("Package UiApp AppSvc DB Insert Failed\n");
1143 memset(query, '\0', MAX_QUERY_LEN);
1147 } while(ui != NULL);
1151 }while(sub != NULL);
1160 acontrol = acontrol->next;
1167 static int __insert_uiapplication_appsvc_info(manifest_x *mfx)
1169 uiapplication_x *up = mfx->uiapplication;
1170 appsvc_x *asvc = NULL;
1171 operation_x *op = NULL;
1174 subapp_x *sub = NULL;
1176 char query[MAX_QUERY_LEN] = {'\0'};
1177 char *operation = NULL;
1180 char *subapp = NULL;
1186 op = asvc->operation;
1190 operation = op->name;
1207 snprintf(query, MAX_QUERY_LEN,
1208 "insert into package_app_app_svc(app_id, operation, uri_scheme, mime_type, subapp_name) " \
1209 "values('%s', '%s', '%s', '%s', '%s')",\
1210 up->appid, operation, uri, mime, subapp);
1212 ret = __exec_query(query);
1214 DBG("Package UiApp AppSvc DB Insert Failed\n");
1217 memset(query, '\0', MAX_QUERY_LEN);
1221 } while(ui != NULL);
1225 }while(sub != NULL);
1241 static int __insert_uiapplication_share_request_info(manifest_x *mfx)
1243 uiapplication_x *up = mfx->uiapplication;
1244 datashare_x *ds = NULL;
1245 request_x *rq = NULL;
1247 char query[MAX_QUERY_LEN] = {'\0'};
1256 snprintf(query, MAX_QUERY_LEN,
1257 "insert into package_app_share_request(app_id, data_share_request) " \
1258 "values('%s', '%s')",\
1259 up->appid, rq->text);
1260 ret = __exec_query(query);
1262 DBG("Package UiApp Share Request DB Insert Failed\n");
1265 memset(query, '\0', MAX_QUERY_LEN);
1275 static int __insert_uiapplication_share_allowed_info(manifest_x *mfx)
1277 uiapplication_x *up = mfx->uiapplication;
1278 datashare_x *ds = NULL;
1279 define_x *df = NULL;
1280 allowed_x *al = NULL;
1282 char query[MAX_QUERY_LEN] = {'\0'};
1294 snprintf(query, MAX_QUERY_LEN,
1295 "insert into package_app_share_allowed(app_id, data_share_path, data_share_allowed) " \
1296 "values('%s', '%s', '%s')",\
1297 up->appid, df->path, al->text);
1298 ret = __exec_query(query);
1300 DBG("Package UiApp Share Allowed DB Insert Failed\n");
1303 memset(query, '\0', MAX_QUERY_LEN);
1315 static int __insert_serviceapplication_info(manifest_x *mfx)
1317 serviceapplication_x *sp = mfx->serviceapplication;
1319 char query[MAX_QUERY_LEN] = {'\0'};
1322 snprintf(query, MAX_QUERY_LEN,
1323 "insert into package_app_info(app_id, app_component, app_exec, app_type, app_onboot, " \
1324 "app_multiple, app_autorestart, app_enabled, package) " \
1325 "values('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",\
1326 sp->appid, "svcapp", sp->exec, sp->type, sp->onboot, "\0",
1327 sp->autorestart, sp->enabled, mfx->package);
1328 ret = __exec_query(query);
1330 DBG("Package ServiceApp Info DB Insert Failed\n");
1334 memset(query, '\0', MAX_QUERY_LEN);
1339 static int __insert_serviceapplication_appcategory_info(manifest_x *mfx)
1341 serviceapplication_x *sp = mfx->serviceapplication;
1342 category_x *ct = NULL;
1344 char query[MAX_QUERY_LEN] = {'\0'};
1350 snprintf(query, MAX_QUERY_LEN,
1351 "insert into package_app_app_category(app_id, category) " \
1352 "values('%s','%s')",\
1353 sp->appid, ct->name);
1354 ret = __exec_query(query);
1356 DBG("Package ServiceApp Category Info DB Insert Failed\n");
1360 memset(query, '\0', MAX_QUERY_LEN);
1367 static int __insert_serviceapplication_appmetadata_info(manifest_x *mfx)
1369 serviceapplication_x *sp = mfx->serviceapplication;
1370 metadata_x *md = NULL;
1372 char query[MAX_QUERY_LEN] = {'\0'};
1378 if (md->name && md->value) {
1379 snprintf(query, MAX_QUERY_LEN,
1380 "insert into package_app_app_metadata(app_id, md_name, md_value) " \
1381 "values('%s','%s', '%s')",\
1382 sp->appid, md->name, md->value);
1383 ret = __exec_query(query);
1385 DBG("Package ServiceApp Metadata Info DB Insert Failed\n");
1390 memset(query, '\0', MAX_QUERY_LEN);
1397 static int __insert_serviceapplication_apppermission_info(manifest_x *mfx)
1399 serviceapplication_x *sp = mfx->serviceapplication;
1400 permission_x *pm = NULL;
1402 char query[MAX_QUERY_LEN] = {'\0'};
1405 pm = sp->permission;
1408 snprintf(query, MAX_QUERY_LEN,
1409 "insert into package_app_app_permission(app_id, pm_type, pm_value) " \
1410 "values('%s','%s', '%s')",\
1411 sp->appid, pm->type, pm->value);
1412 ret = __exec_query(query);
1414 DBG("Package ServiceApp permission Info DB Insert Failed\n");
1418 memset(query, '\0', MAX_QUERY_LEN);
1425 static int __insert_serviceapplication_appcontrol_info(manifest_x *mfx)
1427 serviceapplication_x *sp = mfx->serviceapplication;
1428 appcontrol_x *acontrol = NULL;
1430 char query[MAX_QUERY_LEN] = {'\0'};
1431 operation_x *op = NULL;
1434 subapp_x *sub = NULL;
1435 char *operation = NULL;
1438 char *subapp = NULL;
1441 acontrol = sp->appcontrol;
1442 while(acontrol != NULL)
1444 op = acontrol->operation;
1448 operation = op->name;
1449 mi = acontrol->mime;
1454 sub = acontrol->subapp;
1464 snprintf(query, MAX_QUERY_LEN,
1465 "insert into package_app_app_control(app_id, operation, uri_scheme, mime_type,subapp_name) " \
1466 "values('%s', '%s', '%s', '%s', '%s')",\
1467 sp->appid, operation, uri, mime, subapp);
1468 ret = __exec_query(query);
1470 DBG("Package UiApp AppSvc DB Insert Failed\n");
1473 memset(query, '\0', MAX_QUERY_LEN);
1477 } while(ui != NULL);
1481 }while(sub != NULL);
1490 acontrol = acontrol->next;
1497 static int __insert_serviceapplication_appsvc_info(manifest_x *mfx)
1499 serviceapplication_x *sp = mfx->serviceapplication;
1500 appsvc_x *asvc = NULL;
1502 char query[MAX_QUERY_LEN] = {'\0'};
1503 operation_x *op = NULL;
1506 subapp_x *sub = NULL;
1507 char *operation = NULL;
1510 char *subapp = NULL;
1516 op = asvc->operation;
1520 operation = op->name;
1536 snprintf(query, MAX_QUERY_LEN,
1537 "insert into package_app_app_svc(app_id, operation, uri_scheme, mime_type, subapp_name) " \
1538 "values('%s', '%s', '%s', '%s', '%s')",\
1539 sp->appid, operation, uri, mime, subapp);
1540 ret = __exec_query(query);
1542 DBG("Package UiApp AppSvc DB Insert Failed\n");
1545 memset(query, '\0', MAX_QUERY_LEN);
1549 } while(ui != NULL);
1553 }while(sub != NULL);
1571 static int __insert_serviceapplication_share_request_info(manifest_x *mfx)
1573 serviceapplication_x *sp = mfx->serviceapplication;
1574 datashare_x *ds = NULL;
1575 request_x *rq = NULL;
1577 char query[MAX_QUERY_LEN] = {'\0'};
1586 snprintf(query, MAX_QUERY_LEN,
1587 "insert into package_app_share_request(app_id, data_share_request) " \
1588 "values('%s', '%s')",\
1589 sp->appid, rq->text);
1590 ret = __exec_query(query);
1592 DBG("Package ServiceApp Share Request DB Insert Failed\n");
1595 memset(query, '\0', MAX_QUERY_LEN);
1607 static int __insert_serviceapplication_share_allowed_info(manifest_x *mfx)
1609 serviceapplication_x *sp = mfx->serviceapplication;
1610 datashare_x *ds = NULL;
1611 define_x *df = NULL;
1612 allowed_x *al = NULL;
1614 char query[MAX_QUERY_LEN] = {'\0'};
1626 snprintf(query, MAX_QUERY_LEN,
1627 "insert into package_app_share_allowed(app_id, data_share_path, data_share_allowed) " \
1628 "values('%s', '%s', '%s')",\
1629 sp->appid, df->path, al->text);
1630 ret = __exec_query(query);
1632 DBG("Package App Share Allowed DB Insert Failed\n");
1635 memset(query, '\0', MAX_QUERY_LEN);
1647 static int __insert_manifest_info_in_db(manifest_x *mfx)
1649 label_x *lbl = mfx->label;
1650 license_x *lcn = mfx->license;
1651 icon_x *icn = mfx->icon;
1652 description_x *dcn = mfx->description;
1653 author_x *ath = mfx->author;
1654 uiapplication_x *up = mfx->uiapplication;
1655 uiapplication_x *up_icn = mfx->uiapplication;
1656 uiapplication_x *up_image = mfx->uiapplication;
1657 serviceapplication_x *sp = mfx->serviceapplication;
1658 char query[MAX_QUERY_LEN] = { '\0' };
1662 char *auth_name = NULL;
1663 char *auth_email = NULL;
1664 char *auth_href = NULL;
1667 auth_name = ath->text;
1669 auth_email = ath->email;
1671 auth_href = ath->href;
1674 /*Insert in the package_info DB*/
1676 type = strdup(mfx->type);
1678 type = strdup("rpm");
1679 /*Insert in the package_info DB*/
1681 path = strdup(mfx->root_path);
1683 if (strcmp(type,"rpm")==0)
1684 path = strdup("/usr/apps");
1686 path = strdup("/opt/usr/apps");
1688 snprintf(query, MAX_QUERY_LEN,
1689 "insert into package_info(package, package_type, package_version, install_location, package_size, " \
1690 "package_removable, package_preload, package_readonly, package_update, package_appsetting, author_name, author_email, author_href, installed_time, installed_storage, storeclient_id, mainapp_id, package_url, root_path) " \
1691 "values('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",\
1692 mfx->package, type, mfx->version, mfx->installlocation, mfx->package_size, mfx->removable, mfx->preload,
1693 mfx->readonly, mfx->update, mfx->appsetting, auth_name, auth_email, auth_href, mfx->installed_time, mfx->installed_storage, mfx->storeclient_id, mfx->mainapp_id, mfx->package_url, path);
1694 ret = __exec_query(query);
1696 DBG("Package Info DB Insert Failed\n");
1715 /*Insert the package locale and app locale info */
1716 pkglocale = __create_locale_list(pkglocale, lbl, lcn, icn, dcn, ath);
1717 g_list_foreach(pkglocale, __trimfunc1, NULL);
1722 applocale = __create_locale_list(applocale, up->label, NULL, up->icon, NULL, NULL);
1727 applocale = __create_locale_list(applocale, sp->label, NULL, sp->icon, NULL, NULL);
1730 g_list_foreach(applocale, __trimfunc2, NULL);
1733 /*Insert the app icon info */
1734 while(up_icn != NULL)
1736 appicon = __create_icon_list(appicon, up_icn->icon);
1737 up_icn = up_icn->next;
1739 g_list_foreach(appicon, __trimfunc3, NULL);
1742 /*Insert the image info */
1743 while(up_image != NULL)
1745 appimage = __create_image_list(appimage, up_image->image);
1746 up_image = up_image->next;
1748 g_list_foreach(appimage, __trimfunc4, NULL);
1751 /*g_list_foreach(pkglocale, __printfunc, NULL);*/
1753 /*g_list_foreach(applocale, __printfunc, NULL);*/
1755 /*package locale info*/
1756 g_list_foreach(pkglocale, __insert_pkglocale_info, (gpointer)mfx);
1757 /*native app locale info*/
1758 up = mfx->uiapplication;
1761 g_list_foreach(applocale, __insert_uiapplication_locale_info, (gpointer)up);
1764 /*agent app locale info*/
1765 sp = mfx->serviceapplication;
1768 g_list_foreach(applocale, __insert_serviceapplication_locale_info, (gpointer)sp);
1772 /*app icon locale info*/
1773 up_icn = mfx->uiapplication;
1774 while(up_icn != NULL)
1776 g_list_foreach(appicon, __insert_uiapplication_icon_section_info, (gpointer)up_icn);
1777 up_icn = up_icn->next;
1781 up_image = mfx->uiapplication;
1782 while(up_image != NULL)
1784 g_list_foreach(appimage, __insert_uiapplication_image_info, (gpointer)up_image);
1785 up_image = up_image->next;
1788 g_list_free(pkglocale);
1790 g_list_free(applocale);
1792 g_list_free(appicon);
1794 g_list_free(appimage);
1798 /*Insert in the package_app_info DB*/
1799 ret = __insert_uiapplication_info(mfx);
1802 ret = __insert_ui_mainapp_info(mfx);
1805 ret = __insert_serviceapplication_info(mfx);
1809 /*Insert in the package_app_app_control DB*/
1810 ret = __insert_uiapplication_appcontrol_info(mfx);
1813 ret = __insert_serviceapplication_appcontrol_info(mfx);
1817 /*Insert in the package_app_app_category DB*/
1818 ret = __insert_uiapplication_appcategory_info(mfx);
1821 ret = __insert_serviceapplication_appcategory_info(mfx);
1825 /*Insert in the package_app_app_metadata DB*/
1826 ret = __insert_uiapplication_appmetadata_info(mfx);
1829 ret = __insert_serviceapplication_appmetadata_info(mfx);
1833 /*Insert in the package_app_app_permission DB*/
1834 ret = __insert_uiapplication_apppermission_info(mfx);
1837 ret = __insert_serviceapplication_apppermission_info(mfx);
1841 /*Insert in the package_app_app_svc DB*/
1842 ret = __insert_uiapplication_appsvc_info(mfx);
1845 ret = __insert_serviceapplication_appsvc_info(mfx);
1849 /*Insert in the package_app_share_allowed DB*/
1850 ret = __insert_uiapplication_share_allowed_info(mfx);
1853 ret = __insert_serviceapplication_share_allowed_info(mfx);
1857 /*Insert in the package_app_share_request DB*/
1858 ret = __insert_uiapplication_share_request_info(mfx);
1861 ret = __insert_serviceapplication_share_request_info(mfx);
1869 static int __delete_cert_info_from_db(manifest_x *mfx)
1871 char query[MAX_QUERY_LEN] = { '\0' };
1873 char *error_message = NULL;
1875 ret = __pkgmgr_parser_cert_create_db();
1877 DBG("Failed to open DB\n");
1881 /*Begin transaction*/
1882 ret = sqlite3_exec(pkgmgr_cert_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
1883 if (ret != SQLITE_OK) {
1884 DBG("Failed to begin transaction\n");
1885 sqlite3_close(pkgmgr_cert_db);
1888 DBG("Transaction Begin\n");
1889 snprintf(query, MAX_QUERY_LEN,
1890 "delete from package_cert_info where package='%s'", mfx->package);
1893 sqlite3_exec(pkgmgr_cert_db, query, NULL, NULL, &error_message)) {
1894 DBG("Don't execute query = %s error message = %s\n", query,
1898 sqlite3_free(error_message);
1901 DBG("Delete from DB failed. Rollback now\n");
1902 sqlite3_exec(pkgmgr_cert_db, "ROLLBACK", NULL, NULL, NULL);
1903 sqlite3_close(pkgmgr_cert_db);
1906 /*Commit transaction*/
1907 ret = sqlite3_exec(pkgmgr_cert_db, "COMMIT", NULL, NULL, NULL);
1908 if (ret != SQLITE_OK) {
1909 DBG("Failed to commit transaction, Rollback now\n");
1910 sqlite3_exec(pkgmgr_cert_db, "ROLLBACK", NULL, NULL, NULL);
1911 sqlite3_close(pkgmgr_cert_db);
1914 DBG("Transaction Commit and End\n");
1915 sqlite3_free(error_message);
1916 sqlite3_close(pkgmgr_cert_db);
1921 static int __delete_manifest_info_from_db(manifest_x *mfx)
1923 char query[MAX_QUERY_LEN] = { '\0' };
1925 uiapplication_x *up = mfx->uiapplication;
1926 serviceapplication_x *sp = mfx->serviceapplication;
1928 ret = __delete_cert_info_from_db(mfx);
1930 DBG("Package cert DB Delete Failed\n");
1934 /*Delete from Package Info DB*/
1935 snprintf(query, MAX_QUERY_LEN,
1936 "delete from package_info where package='%s'", mfx->package);
1937 ret = __exec_query(query);
1939 DBG("Package Info DB Delete Failed\n");
1942 memset(query, '\0', MAX_QUERY_LEN);
1944 /*Delete from Package Localized Info*/
1945 snprintf(query, MAX_QUERY_LEN,
1946 "delete from package_localized_info where package='%s'", mfx->package);
1947 ret = __exec_query(query);
1949 DBG("Package Localized Info DB Delete Failed\n");
1952 memset(query, '\0', MAX_QUERY_LEN);
1954 /*Delete from Package App Info*/
1957 snprintf(query, MAX_QUERY_LEN,
1958 "delete from package_app_info where app_id='%s'", up->appid);
1959 ret = __exec_query(query);
1961 DBG("Package App Info DB Delete Failed\n");
1964 memset(query, '\0', MAX_QUERY_LEN);
1969 snprintf(query, MAX_QUERY_LEN,
1970 "delete from package_app_info where app_id='%s'", sp->appid);
1971 ret = __exec_query(query);
1973 DBG("Package App Info DB Delete Failed\n");
1976 memset(query, '\0', MAX_QUERY_LEN);
1980 /*Delete from Package App Localized Info*/
1981 up = mfx->uiapplication;
1982 sp = mfx->serviceapplication;
1985 snprintf(query, MAX_QUERY_LEN,
1986 "delete from package_app_localized_info where app_id='%s'", up->appid);
1987 ret = __exec_query(query);
1989 DBG("Package App Localized Info DB Delete Failed\n");
1992 memset(query, '\0', MAX_QUERY_LEN);
1997 snprintf(query, MAX_QUERY_LEN,
1998 "delete from package_app_localized_info where app_id='%s'", sp->appid);
1999 ret = __exec_query(query);
2001 DBG("Package App Localized Info DB Delete Failed\n");
2004 memset(query, '\0', MAX_QUERY_LEN);
2008 /*Delete from App icon localized Info*/
2009 up = mfx->uiapplication;
2012 snprintf(query, MAX_QUERY_LEN,
2013 "delete from package_app_icon_section_info where app_id='%s'", up->appid);
2014 ret = __exec_query(query);
2016 DBG("Package App image Info DB Delete Failed\n");
2019 memset(query, '\0', MAX_QUERY_LEN);
2023 /*Delete from App image Info*/
2024 up = mfx->uiapplication;
2027 snprintf(query, MAX_QUERY_LEN,
2028 "delete from package_app_image_info where app_id='%s'", up->appid);
2029 ret = __exec_query(query);
2031 DBG("Package App image Info DB Delete Failed\n");
2034 memset(query, '\0', MAX_QUERY_LEN);
2038 /*Delete from Package App App-Svc*/
2039 up = mfx->uiapplication;
2040 sp = mfx->serviceapplication;
2043 snprintf(query, MAX_QUERY_LEN,
2044 "delete from package_app_app_svc where app_id='%s'", up->appid);
2045 ret = __exec_query(query);
2047 DBG("Package App App-Svc DB Delete Failed\n");
2050 memset(query, '\0', MAX_QUERY_LEN);
2055 snprintf(query, MAX_QUERY_LEN,
2056 "delete from package_app_app_svc where app_id='%s'", sp->appid);
2057 ret = __exec_query(query);
2059 DBG("Package App App-Svc DB Delete Failed\n");
2062 memset(query, '\0', MAX_QUERY_LEN);
2066 /*Delete from Package App App-Control*/
2067 up = mfx->uiapplication;
2068 sp = mfx->serviceapplication;
2071 snprintf(query, MAX_QUERY_LEN,
2072 "delete from package_app_app_control where app_id='%s'", up->appid);
2073 ret = __exec_query(query);
2075 DBG("Package App App-Control DB Delete Failed\n");
2078 memset(query, '\0', MAX_QUERY_LEN);
2083 snprintf(query, MAX_QUERY_LEN,
2084 "delete from package_app_app_control where app_id='%s'", sp->appid);
2085 ret = __exec_query(query);
2087 DBG("Package App App-Control DB Delete Failed\n");
2090 memset(query, '\0', MAX_QUERY_LEN);
2094 /*Delete from Package App App-Category*/
2095 up = mfx->uiapplication;
2096 sp = mfx->serviceapplication;
2099 snprintf(query, MAX_QUERY_LEN,
2100 "delete from package_app_app_category where app_id='%s'", up->appid);
2101 ret = __exec_query(query);
2103 DBG("Package App App-Category DB Delete Failed\n");
2106 memset(query, '\0', MAX_QUERY_LEN);
2111 snprintf(query, MAX_QUERY_LEN,
2112 "delete from package_app_app_category where app_id='%s'", sp->appid);
2113 ret = __exec_query(query);
2115 DBG("Package App App-Category DB Delete Failed\n");
2118 memset(query, '\0', MAX_QUERY_LEN);
2122 /*Delete from Package App App-Metadata*/
2123 up = mfx->uiapplication;
2124 sp = mfx->serviceapplication;
2127 snprintf(query, MAX_QUERY_LEN,
2128 "delete from package_app_app_metadata where app_id='%s'", up->appid);
2129 ret = __exec_query(query);
2131 DBG("Package App App-Metadata DB Delete Failed\n");
2134 memset(query, '\0', MAX_QUERY_LEN);
2139 snprintf(query, MAX_QUERY_LEN,
2140 "delete from package_app_app_metadata where app_id='%s'", sp->appid);
2141 ret = __exec_query(query);
2143 DBG("Package App App-Metadata DB Delete Failed\n");
2146 memset(query, '\0', MAX_QUERY_LEN);
2150 /*Delete from Package App App-permission*/
2151 up = mfx->uiapplication;
2152 sp = mfx->serviceapplication;
2155 snprintf(query, MAX_QUERY_LEN,
2156 "delete from package_app_app_permission where app_id='%s'", up->appid);
2157 ret = __exec_query(query);
2159 DBG("Package App App-permission DB Delete Failed\n");
2162 memset(query, '\0', MAX_QUERY_LEN);
2167 snprintf(query, MAX_QUERY_LEN,
2168 "delete from package_app_app_permission where app_id='%s'", sp->appid);
2169 ret = __exec_query(query);
2171 DBG("Package App App-permission DB Delete Failed\n");
2174 memset(query, '\0', MAX_QUERY_LEN);
2178 /*Delete from Package App Share Allowed*/
2179 up = mfx->uiapplication;
2180 sp = mfx->serviceapplication;
2183 snprintf(query, MAX_QUERY_LEN,
2184 "delete from package_app_share_allowed where app_id='%s'", up->appid);
2185 ret = __exec_query(query);
2187 DBG("Package App Share Allowed DB Delete Failed\n");
2190 memset(query, '\0', MAX_QUERY_LEN);
2195 snprintf(query, MAX_QUERY_LEN,
2196 "delete from package_app_share_allowed where app_id='%s'", sp->appid);
2197 ret = __exec_query(query);
2199 DBG("Package App Share Allowed DB Delete Failed\n");
2202 memset(query, '\0', MAX_QUERY_LEN);
2206 /*Delete from Package App Share Request*/
2207 up = mfx->uiapplication;
2208 sp = mfx->serviceapplication;
2211 snprintf(query, MAX_QUERY_LEN,
2212 "delete from package_app_share_request where app_id='%s'", up->appid);
2213 ret = __exec_query(query);
2215 DBG("Package App Share Request DB Delete Failed\n");
2218 memset(query, '\0', MAX_QUERY_LEN);
2223 snprintf(query, MAX_QUERY_LEN,
2224 "delete from package_app_share_request where app_id='%s'", sp->appid);
2225 ret = __exec_query(query);
2227 DBG("Package App Share Request DB Delete Failed\n");
2230 memset(query, '\0', MAX_QUERY_LEN);
2237 int pkgmgr_parser_initialize_db()
2240 ret = __initialize_package_info_db();
2242 DBG("package info DB initialization failed\n");
2245 ret = __initialize_package_localized_info_db();
2247 DBG("package localized info DB initialization failed\n");
2250 ret = __initialize_package_cert_info_db();
2252 DBG("package cert info DB initialization failed\n");
2255 ret = __initialize_package_app_info_db();
2257 DBG("package app info DB initialization failed\n");
2260 ret = __initialize_package_app_localized_info_db();
2262 DBG("package app localized info DB initialization failed\n");
2265 ret = __initialize_package_app_icon_section_info_db();
2267 DBG("package app icon localized info DB initialization failed\n");
2270 ret = __initialize_package_app_image_info_db();
2272 DBG("package app image info DB initialization failed\n");
2275 ret = __initialize_package_app_app_control_db();
2277 DBG("package app app control DB initialization failed\n");
2280 ret = __initialize_package_app_app_category_db();
2282 DBG("package app app category DB initialization failed\n");
2285 ret = __initialize_package_app_app_metadata_db();
2287 DBG("package app app category DB initialization failed\n");
2290 ret = __initialize_package_app_app_permission_db();
2292 DBG("package app app permission DB initialization failed\n");
2295 ret = __initialize_package_app_app_svc_db();
2297 DBG("package app app svc DB initialization failed\n");
2300 ret = __initialize_package_app_share_allowed_db();
2302 DBG("package app share allowed DB initialization failed\n");
2305 ret = __initialize_package_app_share_request_db();
2307 DBG("package app share request DB initialization failed\n");
2313 int pkgmgr_parser_check_and_create_db()
2316 if (access(PKGMGR_PARSER_DB_FILE, F_OK) == 0) {
2318 db_util_open(PKGMGR_PARSER_DB_FILE, &pkgmgr_parser_db,
2319 DB_UTIL_REGISTER_HOOK_METHOD);
2320 if (ret != SQLITE_OK) {
2321 DBG("connect db [%s] failed!\n",
2322 PKGMGR_PARSER_DB_FILE);
2325 ret = chmod(PKGMGR_PARSER_DB_FILE, 0664);
2327 DBG("Failed to change mode of manifest DB\n");
2330 DBG("Pkgmgr DB does not exists. Create one!!\n");
2333 db_util_open(PKGMGR_PARSER_DB_FILE, &pkgmgr_parser_db,
2334 DB_UTIL_REGISTER_HOOK_METHOD);
2336 if (ret != SQLITE_OK) {
2337 DBG("connect db [%s] failed!\n", PKGMGR_PARSER_DB_FILE);
2340 ret = chmod(PKGMGR_PARSER_DB_FILE, 0664);
2342 DBG("Failed to change mode of manifest DB\n");
2346 API int pkgmgr_parser_insert_manifest_info_in_db(manifest_x *mfx)
2349 DBG("manifest pointer is NULL\n");
2353 ret = pkgmgr_parser_check_and_create_db();
2355 DBG("Failed to open DB\n");
2358 ret = pkgmgr_parser_initialize_db();
2361 /*Begin transaction*/
2362 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2363 if (ret != SQLITE_OK) {
2364 DBG("Failed to begin transaction\n");
2365 sqlite3_close(pkgmgr_parser_db);
2368 DBG("Transaction Begin\n");
2369 ret = __insert_manifest_info_in_db(mfx);
2371 DBG("Insert into DB failed. Rollback now\n");
2372 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2373 sqlite3_close(pkgmgr_parser_db);
2376 /*Commit transaction*/
2377 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2378 if (ret != SQLITE_OK) {
2379 DBG("Failed to commit transaction. Rollback now\n");
2380 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2381 sqlite3_close(pkgmgr_parser_db);
2384 DBG("Transaction Commit and End\n");
2385 sqlite3_close(pkgmgr_parser_db);
2389 API int pkgmgr_parser_update_manifest_info_in_db(manifest_x *mfx)
2392 DBG("manifest pointer is NULL\n");
2396 ret = pkgmgr_parser_check_and_create_db();
2398 DBG("Failed to open DB\n");
2401 ret = pkgmgr_parser_initialize_db();
2404 /*Preserve guest mode visibility*/
2405 __preserve_guestmode_visibility_value( mfx);
2406 /*Begin transaction*/
2407 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2408 if (ret != SQLITE_OK) {
2409 DBG("Failed to begin transaction\n");
2410 sqlite3_close(pkgmgr_parser_db);
2413 DBG("Transaction Begin\n");
2414 ret = __delete_manifest_info_from_db(mfx);
2416 DBG("Delete from DB failed. Rollback now\n");
2417 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2418 sqlite3_close(pkgmgr_parser_db);
2421 ret = __insert_manifest_info_in_db(mfx);
2423 DBG("Insert into DB failed. Rollback now\n");
2424 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2425 sqlite3_close(pkgmgr_parser_db);
2429 /*Commit transaction*/
2430 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2431 if (ret != SQLITE_OK) {
2432 DBG("Failed to commit transaction. Rollback now\n");
2433 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2434 sqlite3_close(pkgmgr_parser_db);
2437 DBG("Transaction Commit and End\n");
2438 sqlite3_close(pkgmgr_parser_db);
2442 API int pkgmgr_parser_delete_manifest_info_from_db(manifest_x *mfx)
2445 DBG("manifest pointer is NULL\n");
2449 ret = pkgmgr_parser_check_and_create_db();
2451 DBG("Failed to open DB\n");
2454 /*Begin transaction*/
2455 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2456 if (ret != SQLITE_OK) {
2457 DBG("Failed to begin transaction\n");
2458 sqlite3_close(pkgmgr_parser_db);
2461 DBG("Transaction Begin\n");
2462 ret = __delete_manifest_info_from_db(mfx);
2464 DBG("Delete from DB failed. Rollback now\n");
2465 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2466 sqlite3_close(pkgmgr_parser_db);
2469 /*Commit transaction*/
2470 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2471 if (ret != SQLITE_OK) {
2472 DBG("Failed to commit transaction, Rollback now\n");
2473 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2474 sqlite3_close(pkgmgr_parser_db);
2477 DBG("Transaction Commit and End\n");
2478 sqlite3_close(pkgmgr_parser_db);