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_key text not null, " \
165 "md_value text not null, " \
166 "PRIMARY KEY(app_id, md_key, md_value) " \
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_INDEX_INFO "create table if not exists package_cert_index_info " \
198 "(cert_info text not null, " \
199 "cert_id integer, " \
200 "cert_ref_count integer, " \
201 "PRIMARY KEY(cert_id)) "
203 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INFO "create table if not exists package_cert_info " \
204 "(package text not null, " \
205 "author_root_cert integer, " \
206 "author_im_cert integer, " \
207 "author_signer_cert integer, " \
208 "dist_root_cert integer, " \
209 "dist_im_cert integer, " \
210 "dist_signer_cert integer, " \
211 "dist2_root_cert integer, " \
212 "dist2_im_cert integer, " \
213 "dist2_signer_cert integer, " \
214 "PRIMARY KEY(package)) "
216 static int __insert_uiapplication_info(manifest_x *mfx);
217 static int __insert_serviceapplication_info(manifest_x *mfx);
218 static int __insert_uiapplication_appsvc_info(manifest_x *mfx);
219 static int __insert_serviceapplication_appsvc_info(manifest_x *mfx);
220 static int __insert_uiapplication_appcategory_info(manifest_x *mfx);
221 static int __insert_serviceapplication_appcategory_info(manifest_x *mfx);
222 static int __insert_uiapplication_appcontrol_info(manifest_x *mfx);
223 static int __insert_serviceapplication_appmetadata_info(manifest_x *mfx);
224 static int __insert_uiapplication_appmetadata_info(manifest_x *mfx);
225 static int __insert_serviceapplication_appcontrol_info(manifest_x *mfx);
226 static int __insert_uiapplication_share_allowed_info(manifest_x *mfx);
227 static int __insert_serviceapplication_share_allowed_info(manifest_x *mfx);
228 static int __insert_uiapplication_share_request_info(manifest_x *mfx);
229 static int __insert_serviceapplication_share_request_info(manifest_x *mfx);
230 static void __insert_serviceapplication_locale_info(gpointer data, gpointer userdata);
231 static void __insert_uiapplication_locale_info(gpointer data, gpointer userdata);
232 static void __insert_pkglocale_info(gpointer data, gpointer userdata);
233 static int __insert_manifest_info_in_db(manifest_x *mfx);
234 static int __update_manifest_info_in_db(manifest_x *mfx);
235 static int __delete_manifest_info_from_db(manifest_x *mfx);
236 static int __initialize_package_info_db();
237 static int __initialize_package_localized_info_db();
238 static int __initialize_package_app_info_db();
239 static int __initialize_package_cert_info_db();
240 static int __initialize_package_cert_index_info_db();
241 static int __initialize_package_app_localized_info_db();
242 static int __initialize_package_app_icon_section_info_db();
243 static int __initialize_package_app_image_info_db();
244 static int __initialize_package_app_app_svc_db();
245 static int __initialize_package_app_app_category_db();
246 static int __initialize_package_app_app_control_db();
247 static int __initialize_package_app_app_metadata_db();
248 static int __initialize_package_app_share_allowed_db();
249 static int __initialize_package_app_share_request_db();
250 static int __exec_query(char *query);
251 static void __extract_data(gpointer data, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath,
252 char **label, char **license, char **icon, char **description, char **author);
254 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata);
255 static void __trimfunc1(gpointer data, gpointer userdata);
256 static void __trimfunc2(gpointer data, gpointer userdata);
257 static GList *__create_locale_list(GList *locale, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath);
258 static void __preserve_guestmode_visibility_value(manifest_x *mfx);
259 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname);
261 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname)
263 manifest_x *mfx = (manifest_x *)data;
267 uiapplication_x *uiapp = NULL;
268 for(i = 0; i < ncols; i++)
270 uiapp = mfx->uiapplication;
271 if (strcmp(colname[i], "app_id") == 0) {
273 appid = strdup(coltxt[i]);
274 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0) {
276 status = strdup(coltxt[i]);
279 /*update guest mode visibility*/
280 for (; uiapp != NULL; uiapp = uiapp->next) {
281 if (strcmp(uiapp->appid, appid) == 0) {
282 free((void *)uiapp->guestmode_visibility);
283 uiapp->guestmode_visibility = strdup(status);
299 static void __preserve_guestmode_visibility_value(manifest_x *mfx)
301 char *error_message = NULL;
302 char query[MAX_QUERY_LEN] = {'\0'};
303 snprintf(query, MAX_QUERY_LEN - 1, "select app_id, app_guestmodevisibility from package_app_info where package='%s'", mfx->package);
305 sqlite3_exec(pkgmgr_parser_db, query,
306 __guestmode_visibility_cb, (void *)mfx, &error_message)) {
307 DBG("Don't execute query = %s error message = %s\n",
308 query, error_message);
309 sqlite3_free(error_message);
314 static int __initialize_package_info_db()
316 char *error_message = NULL;
318 sqlite3_exec(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_INFO,
319 NULL, NULL, &error_message)) {
320 DBG("Don't execute query = %s error message = %s\n",
321 QUERY_CREATE_TABLE_PACKAGE_INFO, error_message);
322 sqlite3_free(error_message);
325 sqlite3_free(error_message);
329 static int __pkgmgr_parser_cert_create_db()
332 if (access(PKGMGR_CERT_DB_FILE, F_OK) == 0) {
334 db_util_open(PKGMGR_CERT_DB_FILE, &pkgmgr_cert_db,
335 DB_UTIL_REGISTER_HOOK_METHOD);
336 if (ret != SQLITE_OK) {
337 DBG("connect db [%s] failed!\n",
338 PKGMGR_CERT_DB_FILE);
343 DBG("Pkgmgr DB does not exists. Create one!!\n");
346 db_util_open(PKGMGR_CERT_DB_FILE, &pkgmgr_cert_db,
347 DB_UTIL_REGISTER_HOOK_METHOD);
349 if (ret != SQLITE_OK) {
350 DBG("connect db [%s] failed!\n", PKGMGR_CERT_DB_FILE);
356 static int __initialize_package_cert_info_db()
358 char *error_message = NULL;
360 ret = __pkgmgr_parser_cert_create_db();
362 DBG("Failed to open DB\n");
367 sqlite3_exec(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INFO,
368 NULL, NULL, &error_message)) {
369 DBG("Don't execute query = %s error message = %s\n",
370 QUERY_CREATE_TABLE_PACKAGE_CERT_INFO, error_message);
371 sqlite3_free(error_message);
372 sqlite3_close(pkgmgr_cert_db);
375 sqlite3_free(error_message);
379 static int __initialize_package_cert_index_info_db()
381 char *error_message = NULL;
383 sqlite3_exec(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO,
384 NULL, NULL, &error_message)) {
385 DBG("Don't execute query = %s error message = %s\n",
386 QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO, error_message);
387 sqlite3_free(error_message);
388 sqlite3_close(pkgmgr_cert_db);
391 sqlite3_free(error_message);
392 sqlite3_close(pkgmgr_cert_db);
396 static int __initialize_package_localized_info_db()
398 char *error_message = NULL;
400 sqlite3_exec(pkgmgr_parser_db,
401 QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO, NULL, NULL,
403 DBG("Don't execute query = %s error message = %s\n",
404 QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO,
406 sqlite3_free(error_message);
409 sqlite3_free(error_message);
413 static int __initialize_package_app_info_db()
415 char *error_message = NULL;
417 sqlite3_exec(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_INFO,
418 NULL, NULL, &error_message)) {
419 DBG("Don't execute query = %s error message = %s\n",
420 QUERY_CREATE_TABLE_PACKAGE_APP_INFO, error_message);
421 sqlite3_free(error_message);
424 sqlite3_free(error_message);
428 static int __initialize_package_app_localized_info_db()
430 char *error_message = NULL;
432 sqlite3_exec(pkgmgr_parser_db,
433 QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO, NULL,
434 NULL, &error_message)) {
435 DBG("Don't execute query = %s error message = %s\n",
436 QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO,
438 sqlite3_free(error_message);
441 sqlite3_free(error_message);
445 static int __initialize_package_app_icon_section_info_db()
447 char *error_message = NULL;
449 sqlite3_exec(pkgmgr_parser_db,
450 QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO, NULL,
451 NULL, &error_message)) {
452 DBG("Don't execute query = %s error message = %s\n",
453 QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO,
455 sqlite3_free(error_message);
458 sqlite3_free(error_message);
462 static int __initialize_package_app_image_info_db()
464 char *error_message = NULL;
466 sqlite3_exec(pkgmgr_parser_db,
467 QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO, NULL,
468 NULL, &error_message)) {
469 DBG("Don't execute query = %s error message = %s\n",
470 QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO,
472 sqlite3_free(error_message);
475 sqlite3_free(error_message);
479 static int __initialize_package_app_app_control_db()
481 char *error_message = NULL;
483 sqlite3_exec(pkgmgr_parser_db,
484 QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL, NULL, NULL,
486 DBG("Don't execute query = %s error message = %s\n",
487 QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL, error_message);
488 sqlite3_free(error_message);
491 sqlite3_free(error_message);
495 static int __initialize_package_app_app_category_db()
497 char *error_message = NULL;
499 sqlite3_exec(pkgmgr_parser_db,
500 QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY, NULL, NULL,
502 DBG("Don't execute query = %s error message = %s\n",
503 QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY, error_message);
504 sqlite3_free(error_message);
507 sqlite3_free(error_message);
511 static int __initialize_package_app_app_metadata_db()
513 char *error_message = NULL;
515 sqlite3_exec(pkgmgr_parser_db,
516 QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA, NULL, NULL,
518 DBG("Don't execute query = %s error message = %s\n",
519 QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA, error_message);
520 sqlite3_free(error_message);
523 sqlite3_free(error_message);
527 static int __initialize_package_app_app_permission_db()
529 char *error_message = NULL;
531 sqlite3_exec(pkgmgr_parser_db,
532 QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION, NULL, NULL,
534 DBG("Don't execute query = %s error message = %s\n",
535 QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION, error_message);
536 sqlite3_free(error_message);
539 sqlite3_free(error_message);
543 static int __initialize_package_app_app_svc_db()
545 char *error_message = NULL;
547 sqlite3_exec(pkgmgr_parser_db,
548 QUERY_CREATE_TABLE_PACKAGE_APP_APP_SVC, NULL, NULL,
550 DBG("Don't execute query = %s error message = %s\n",
551 QUERY_CREATE_TABLE_PACKAGE_APP_APP_SVC, error_message);
552 sqlite3_free(error_message);
555 sqlite3_free(error_message);
559 static int __initialize_package_app_share_allowed_db()
561 char *error_message = NULL;
563 sqlite3_exec(pkgmgr_parser_db,
564 QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED, NULL,
565 NULL, &error_message)) {
566 DBG("Don't execute query = %s error message = %s\n",
567 QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED,
569 sqlite3_free(error_message);
572 sqlite3_free(error_message);
576 static int __initialize_package_app_share_request_db()
578 char *error_message = NULL;
580 sqlite3_exec(pkgmgr_parser_db,
581 QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST, NULL,
582 NULL, &error_message)) {
583 DBG("Don't execute query = %s error message = %s\n",
584 QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST,
586 sqlite3_free(error_message);
589 sqlite3_free(error_message);
593 static int __exec_query(char *query)
595 char *error_message = NULL;
597 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
598 DBG("Don't execute query = %s error message = %s\n", query,
600 sqlite3_free(error_message);
603 sqlite3_free(error_message);
606 static GList *__create_locale_list(GList *locale, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath)
612 locale = g_list_insert_sorted_with_data(locale, (gpointer)lbl->lang, __comparefunc, NULL);
618 locale = g_list_insert_sorted_with_data(locale, (gpointer)lcn->lang, __comparefunc, NULL);
624 locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->lang, __comparefunc, NULL);
630 locale = g_list_insert_sorted_with_data(locale, (gpointer)dcn->lang, __comparefunc, NULL);
636 locale = g_list_insert_sorted_with_data(locale, (gpointer)ath->lang, __comparefunc, NULL);
643 static GList *__create_icon_list(GList *locale, icon_x *icn)
648 locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->section, __comparefunc, NULL);
654 static GList *__create_image_list(GList *locale, image_x *image)
659 locale = g_list_insert_sorted_with_data(locale, (gpointer)image->section, __comparefunc, NULL);
665 static void __printfunc(gpointer data, gpointer userdata)
667 DBG("%s ", (char*)data);
670 static void __trimfunc1(gpointer data, gpointer userdata)
673 if (strcmp((char *)data, prev) == 0) {
674 pkglocale = g_list_remove(pkglocale, data);
682 static void __trimfunc2(gpointer data, gpointer userdata)
685 if (strcmp((char *)data, prev) == 0) {
686 applocale = g_list_remove(applocale, data);
694 static void __trimfunc3(gpointer data, gpointer userdata)
697 if (strcmp((char *)data, prev) == 0) {
698 appicon = g_list_remove(appicon, data);
706 static void __trimfunc4(gpointer data, gpointer userdata)
709 if (strcmp((char *)data, prev) == 0) {
710 appimage = g_list_remove(appimage, data);
718 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata)
720 if (a == NULL || b == NULL)
722 if (strcmp((char*)a, (char*)b) == 0)
724 if (strcmp((char*)a, (char*)b) < 0)
726 if (strcmp((char*)a, (char*)b) > 0)
730 static void __extract_data(gpointer data, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath,
731 char **label, char **license, char **icon, char **description, char **author)
736 if (strcmp(lbl->lang, (char *)data) == 0) {
737 *label = (char*)lbl->text;
746 if (strcmp(lcn->lang, (char *)data) == 0) {
747 *license = (char*)lcn->text;
756 if (strcmp(icn->lang, (char *)data) == 0) {
757 *icon = (char*)icn->text;
766 if (strcmp(dcn->lang, (char *)data) == 0) {
767 *description = (char*)dcn->text;
776 if (strcmp(ath->lang, (char *)data) == 0) {
777 *author = (char*)ath->text;
786 static void __extract_icon_data(gpointer data, icon_x *icn, char **icon, char **resolution)
791 if (strcmp(icn->section, (char *)data) == 0) {
792 *icon = (char*)icn->text;
793 *resolution = (char*)icn->resolution;
801 static void __extract_image_data(gpointer data, icon_x *image, char **lang, char **img)
805 if (image->section) {
806 if (strcmp(image->section, (char *)data) == 0) {
807 *lang = (char*)image->lang;
808 *img = (char*)image->text;
816 static void __insert_pkglocale_info(gpointer data, gpointer userdata)
821 char *description = NULL;
822 char *license = NULL;
824 char query[MAX_QUERY_LEN] = {'\0'};
826 manifest_x *mfx = (manifest_x *)userdata;
827 label_x *lbl = mfx->label;
828 license_x *lcn = mfx->license;
829 icon_x *icn = mfx->icon;
830 description_x *dcn = mfx->description;
831 author_x *ath = mfx->author;
833 __extract_data(data, lbl, lcn, icn, dcn, ath, &label, &license, &icon, &description, &author);
834 if (!label && !description && !icon && !license && !author)
836 snprintf(query, MAX_QUERY_LEN, "insert into package_localized_info(package, package_locale, " \
837 "package_label, package_icon, package_description, package_license, package_author) values " \
838 "('%s', '%s', '%s', '%s', '%s', '%s', '%s')", mfx->package, (char*)data,
839 label, icon, description, license, author);
840 ret = __exec_query(query);
842 DBG("Package Localized Info DB Insert failed\n");
845 static void __insert_uiapplication_locale_info(gpointer data, gpointer userdata)
850 char query[MAX_QUERY_LEN] = {'\0'};
852 uiapplication_x *up = (uiapplication_x*)userdata;
853 label_x *lbl = up->label;
854 icon_x *icn = up->icon;
856 __extract_data(data, lbl, NULL, icn, NULL, NULL, &label, NULL, &icon, NULL, NULL);
859 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_localized_info(app_id, app_locale, " \
860 "app_label, app_icon) values " \
861 "('%q', '%q', '%q', '%q')", up->appid, (char*)data,
863 ret = __exec_query(query);
865 DBG("Package UiApp Localized Info DB Insert failed\n");
869 static void __insert_uiapplication_icon_section_info(gpointer data, gpointer userdata)
873 char *resolution = NULL;
874 char query[MAX_QUERY_LEN] = {'\0'};
876 uiapplication_x *up = (uiapplication_x*)userdata;
877 icon_x *icn = up->icon;
879 __extract_icon_data(data, icn, &icon, &resolution);
880 if (!icon && !resolution)
882 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_icon_section_info(app_id, " \
883 "app_icon, app_icon_section, app_icon_resolution) values " \
884 "('%q', '%q', '%q', '%q')", up->appid,
885 icon, (char*)data, resolution);
887 ret = __exec_query(query);
889 DBG("Package UiApp Localized Info DB Insert failed\n");
893 static void __insert_uiapplication_image_info(gpointer data, gpointer userdata)
898 char query[MAX_QUERY_LEN] = {'\0'};
900 uiapplication_x *up = (uiapplication_x*)userdata;
901 image_x *image = up->image;
903 __extract_image_data(data, image, &lang, &img);
906 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_image_info(app_id, app_locale, " \
907 "app_image_section, app_image) values " \
908 "('%q', '%q', '%q', '%q')", up->appid, lang, (char*)data, img);
910 ret = __exec_query(query);
912 DBG("Package UiApp image Info DB Insert failed\n");
917 static void __insert_serviceapplication_locale_info(gpointer data, gpointer userdata)
922 char query[MAX_QUERY_LEN] = {'\0'};
924 serviceapplication_x *sp = (serviceapplication_x*)userdata;
925 label_x *lbl = sp->label;
926 icon_x *icn = sp->icon;
928 __extract_data(data, lbl, NULL, icn, NULL, NULL, &label, NULL, &icon, NULL, NULL);
931 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_localized_info(app_id, app_locale, " \
932 "app_label, app_icon) values " \
933 "('%q', '%q', '%q', '%q')", sp->appid, (char*)data,
935 ret = __exec_query(query);
937 DBG("Package ServiceApp Localized Info DB Insert failed\n");
940 static int __insert_ui_mainapp_info(manifest_x *mfx)
942 uiapplication_x *up = mfx->uiapplication;
944 char query[MAX_QUERY_LEN] = {'\0'};
947 snprintf(query, MAX_QUERY_LEN,
948 "update package_app_info set app_mainapp='%s' where app_id='%s'", up->mainapp, up->appid);
950 ret = __exec_query(query);
952 DBG("Package UiApp Info DB Insert Failed\n");
955 if (strcasecmp(up->mainapp, "True")==0)
956 mfx->mainapp_id = strdup(up->appid);
959 memset(query, '\0', MAX_QUERY_LEN);
962 if (mfx->mainapp_id == NULL){
963 if (mfx->uiapplication
964 && mfx->uiapplication->appid) {
965 snprintf(query, MAX_QUERY_LEN,
966 "update package_app_info set app_mainapp='true' where app_id='%s'", mfx->uiapplication->appid);
967 } else if (mfx->serviceapplication
968 && mfx->serviceapplication->appid) {
969 snprintf(query, MAX_QUERY_LEN,
970 "update package_app_info set app_mainapp='true' where app_id='%s'", mfx->serviceapplication->appid);
972 DBG("Not valid appid\n");
976 ret = __exec_query(query);
978 DBG("Package UiApp Info DB Insert Failed\n");
981 if (mfx->uiapplication && mfx->uiapplication->appid)
982 mfx->mainapp_id = strdup(mfx->uiapplication->appid);
983 else if (mfx->serviceapplication && mfx->serviceapplication->appid)
984 mfx->mainapp_id = strdup(mfx->serviceapplication->appid);
988 memset(query, '\0', MAX_QUERY_LEN);
989 snprintf(query, MAX_QUERY_LEN,
990 "update package_info set mainapp_id='%s' where package='%s'", mfx->mainapp_id, mfx->package);
991 ret = __exec_query(query);
993 DBG("Package Info DB update Failed\n");
999 /* _PRODUCT_LAUNCHING_ENHANCED_
1000 * up->indicatordisplay, up->portraitimg, up->landscapeimg, up->guestmode_appstatus
1002 static int __insert_uiapplication_info(manifest_x *mfx)
1004 uiapplication_x *up = mfx->uiapplication;
1006 char query[MAX_QUERY_LEN] = {'\0'};
1009 snprintf(query, MAX_QUERY_LEN,
1010 "insert into package_app_info(app_id, app_component, app_exec, app_nodisplay, app_type, app_onboot, " \
1011 "app_multiple, app_autorestart, app_taskmanage, app_enabled, app_hwacceleration, app_mainapp , app_recentimage, app_indicatordisplay, app_portraitimg, app_landscapeimg, app_guestmodevisibility, package) " \
1012 "values('%s', '%s', '%s', '%s', '%s', '%s','%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",\
1013 up->appid, "uiapp", up->exec, up->nodisplay, up->type, "\0", up->multiple,
1014 "\0", up->taskmanage, up->enabled, up->hwacceleration,up->mainapp, up->recentimage, up->indicatordisplay, up->portraitimg, up->landscapeimg, up->guestmode_visibility, mfx->package);
1015 ret = __exec_query(query);
1017 DBG("Package UiApp Info DB Insert Failed\n");
1021 memset(query, '\0', MAX_QUERY_LEN);
1026 static int __insert_uiapplication_appcategory_info(manifest_x *mfx)
1028 uiapplication_x *up = mfx->uiapplication;
1029 category_x *ct = NULL;
1031 char query[MAX_QUERY_LEN] = {'\0'};
1037 snprintf(query, MAX_QUERY_LEN,
1038 "insert into package_app_app_category(app_id, category) " \
1039 "values('%s','%s')",\
1040 up->appid, ct->name);
1041 ret = __exec_query(query);
1043 DBG("Package UiApp Category Info DB Insert Failed\n");
1047 memset(query, '\0', MAX_QUERY_LEN);
1054 static int __insert_uiapplication_appmetadata_info(manifest_x *mfx)
1056 uiapplication_x *up = mfx->uiapplication;
1057 metadata_x *md = NULL;
1059 char query[MAX_QUERY_LEN] = {'\0'};
1065 if (md->key && md->value) {
1066 snprintf(query, MAX_QUERY_LEN,
1067 "insert into package_app_app_metadata(app_id, md_key, md_value) " \
1068 "values('%s','%s', '%s')",\
1069 up->appid, md->key, md->value);
1070 ret = __exec_query(query);
1072 DBG("Package UiApp Metadata Info DB Insert Failed\n");
1077 memset(query, '\0', MAX_QUERY_LEN);
1084 static int __insert_uiapplication_apppermission_info(manifest_x *mfx)
1086 uiapplication_x *up = mfx->uiapplication;
1087 permission_x *pm = NULL;
1089 char query[MAX_QUERY_LEN] = {'\0'};
1092 pm = up->permission;
1095 snprintf(query, MAX_QUERY_LEN,
1096 "insert into package_app_app_permission(app_id, pm_type, pm_value) " \
1097 "values('%s','%s', '%s')",\
1098 up->appid, pm->type, pm->value);
1099 ret = __exec_query(query);
1101 DBG("Package UiApp permission Info DB Insert Failed\n");
1105 memset(query, '\0', MAX_QUERY_LEN);
1112 static int __insert_uiapplication_appcontrol_info(manifest_x *mfx)
1114 uiapplication_x *up = mfx->uiapplication;
1115 appcontrol_x *acontrol = NULL;
1116 operation_x *op = NULL;
1119 subapp_x *sub = NULL;
1121 char query[MAX_QUERY_LEN] = {'\0'};
1122 char *operation = NULL;
1125 char *subapp = NULL;
1128 acontrol = up->appcontrol;
1129 while(acontrol != NULL)
1131 op = acontrol->operation;
1135 operation = op->name;
1136 mi = acontrol->mime;
1142 sub = acontrol->subapp;
1152 snprintf(query, MAX_QUERY_LEN,
1153 "insert into package_app_app_control(app_id, operation, uri_scheme, mime_type, subapp_name) " \
1154 "values('%s', '%s', '%s', '%s', '%s')",\
1155 up->appid, operation, uri, mime, subapp);
1157 ret = __exec_query(query);
1159 DBG("Package UiApp AppSvc DB Insert Failed\n");
1162 memset(query, '\0', MAX_QUERY_LEN);
1166 } while(ui != NULL);
1170 }while(sub != NULL);
1179 acontrol = acontrol->next;
1186 static int __insert_uiapplication_appsvc_info(manifest_x *mfx)
1188 uiapplication_x *up = mfx->uiapplication;
1189 appsvc_x *asvc = NULL;
1190 operation_x *op = NULL;
1193 subapp_x *sub = NULL;
1195 char query[MAX_QUERY_LEN] = {'\0'};
1196 char *operation = NULL;
1199 char *subapp = NULL;
1205 op = asvc->operation;
1209 operation = op->name;
1226 snprintf(query, MAX_QUERY_LEN,
1227 "insert into package_app_app_svc(app_id, operation, uri_scheme, mime_type, subapp_name) " \
1228 "values('%s', '%s', '%s', '%s', '%s')",\
1229 up->appid, operation, uri, mime, subapp);
1231 ret = __exec_query(query);
1233 DBG("Package UiApp AppSvc DB Insert Failed\n");
1236 memset(query, '\0', MAX_QUERY_LEN);
1240 } while(ui != NULL);
1244 }while(sub != NULL);
1260 static int __insert_uiapplication_share_request_info(manifest_x *mfx)
1262 uiapplication_x *up = mfx->uiapplication;
1263 datashare_x *ds = NULL;
1264 request_x *rq = NULL;
1266 char query[MAX_QUERY_LEN] = {'\0'};
1275 snprintf(query, MAX_QUERY_LEN,
1276 "insert into package_app_share_request(app_id, data_share_request) " \
1277 "values('%s', '%s')",\
1278 up->appid, rq->text);
1279 ret = __exec_query(query);
1281 DBG("Package UiApp Share Request DB Insert Failed\n");
1284 memset(query, '\0', MAX_QUERY_LEN);
1294 static int __insert_uiapplication_share_allowed_info(manifest_x *mfx)
1296 uiapplication_x *up = mfx->uiapplication;
1297 datashare_x *ds = NULL;
1298 define_x *df = NULL;
1299 allowed_x *al = NULL;
1301 char query[MAX_QUERY_LEN] = {'\0'};
1313 snprintf(query, MAX_QUERY_LEN,
1314 "insert into package_app_share_allowed(app_id, data_share_path, data_share_allowed) " \
1315 "values('%s', '%s', '%s')",\
1316 up->appid, df->path, al->text);
1317 ret = __exec_query(query);
1319 DBG("Package UiApp Share Allowed DB Insert Failed\n");
1322 memset(query, '\0', MAX_QUERY_LEN);
1334 static int __insert_serviceapplication_info(manifest_x *mfx)
1336 serviceapplication_x *sp = mfx->serviceapplication;
1338 char query[MAX_QUERY_LEN] = {'\0'};
1341 snprintf(query, MAX_QUERY_LEN,
1342 "insert into package_app_info(app_id, app_component, app_exec, app_type, app_onboot, " \
1343 "app_multiple, app_autorestart, app_enabled, package) " \
1344 "values('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",\
1345 sp->appid, "svcapp", sp->exec, sp->type, sp->onboot, "\0",
1346 sp->autorestart, sp->enabled, mfx->package);
1347 ret = __exec_query(query);
1349 DBG("Package ServiceApp Info DB Insert Failed\n");
1353 memset(query, '\0', MAX_QUERY_LEN);
1358 static int __insert_serviceapplication_appcategory_info(manifest_x *mfx)
1360 serviceapplication_x *sp = mfx->serviceapplication;
1361 category_x *ct = NULL;
1363 char query[MAX_QUERY_LEN] = {'\0'};
1369 snprintf(query, MAX_QUERY_LEN,
1370 "insert into package_app_app_category(app_id, category) " \
1371 "values('%s','%s')",\
1372 sp->appid, ct->name);
1373 ret = __exec_query(query);
1375 DBG("Package ServiceApp Category Info DB Insert Failed\n");
1379 memset(query, '\0', MAX_QUERY_LEN);
1386 static int __insert_serviceapplication_appmetadata_info(manifest_x *mfx)
1388 serviceapplication_x *sp = mfx->serviceapplication;
1389 metadata_x *md = NULL;
1391 char query[MAX_QUERY_LEN] = {'\0'};
1397 if (md->key && md->value) {
1398 snprintf(query, MAX_QUERY_LEN,
1399 "insert into package_app_app_metadata(app_id, md_key, md_value) " \
1400 "values('%s','%s', '%s')",\
1401 sp->appid, md->key, md->value);
1402 ret = __exec_query(query);
1404 DBG("Package ServiceApp Metadata Info DB Insert Failed\n");
1409 memset(query, '\0', MAX_QUERY_LEN);
1416 static int __insert_serviceapplication_apppermission_info(manifest_x *mfx)
1418 serviceapplication_x *sp = mfx->serviceapplication;
1419 permission_x *pm = NULL;
1421 char query[MAX_QUERY_LEN] = {'\0'};
1424 pm = sp->permission;
1427 snprintf(query, MAX_QUERY_LEN,
1428 "insert into package_app_app_permission(app_id, pm_type, pm_value) " \
1429 "values('%s','%s', '%s')",\
1430 sp->appid, pm->type, pm->value);
1431 ret = __exec_query(query);
1433 DBG("Package ServiceApp permission Info DB Insert Failed\n");
1437 memset(query, '\0', MAX_QUERY_LEN);
1444 static int __insert_serviceapplication_appcontrol_info(manifest_x *mfx)
1446 serviceapplication_x *sp = mfx->serviceapplication;
1447 appcontrol_x *acontrol = NULL;
1449 char query[MAX_QUERY_LEN] = {'\0'};
1450 operation_x *op = NULL;
1453 subapp_x *sub = NULL;
1454 char *operation = NULL;
1457 char *subapp = NULL;
1460 acontrol = sp->appcontrol;
1461 while(acontrol != NULL)
1463 op = acontrol->operation;
1467 operation = op->name;
1468 mi = acontrol->mime;
1473 sub = acontrol->subapp;
1483 snprintf(query, MAX_QUERY_LEN,
1484 "insert into package_app_app_control(app_id, operation, uri_scheme, mime_type,subapp_name) " \
1485 "values('%s', '%s', '%s', '%s', '%s')",\
1486 sp->appid, operation, uri, mime, subapp);
1487 ret = __exec_query(query);
1489 DBG("Package UiApp AppSvc DB Insert Failed\n");
1492 memset(query, '\0', MAX_QUERY_LEN);
1496 } while(ui != NULL);
1500 }while(sub != NULL);
1509 acontrol = acontrol->next;
1516 static int __insert_serviceapplication_appsvc_info(manifest_x *mfx)
1518 serviceapplication_x *sp = mfx->serviceapplication;
1519 appsvc_x *asvc = NULL;
1521 char query[MAX_QUERY_LEN] = {'\0'};
1522 operation_x *op = NULL;
1525 subapp_x *sub = NULL;
1526 char *operation = NULL;
1529 char *subapp = NULL;
1535 op = asvc->operation;
1539 operation = op->name;
1555 snprintf(query, MAX_QUERY_LEN,
1556 "insert into package_app_app_svc(app_id, operation, uri_scheme, mime_type, subapp_name) " \
1557 "values('%s', '%s', '%s', '%s', '%s')",\
1558 sp->appid, operation, uri, mime, subapp);
1559 ret = __exec_query(query);
1561 DBG("Package UiApp AppSvc DB Insert Failed\n");
1564 memset(query, '\0', MAX_QUERY_LEN);
1568 } while(ui != NULL);
1572 }while(sub != NULL);
1590 static int __insert_serviceapplication_share_request_info(manifest_x *mfx)
1592 serviceapplication_x *sp = mfx->serviceapplication;
1593 datashare_x *ds = NULL;
1594 request_x *rq = NULL;
1596 char query[MAX_QUERY_LEN] = {'\0'};
1605 snprintf(query, MAX_QUERY_LEN,
1606 "insert into package_app_share_request(app_id, data_share_request) " \
1607 "values('%s', '%s')",\
1608 sp->appid, rq->text);
1609 ret = __exec_query(query);
1611 DBG("Package ServiceApp Share Request DB Insert Failed\n");
1614 memset(query, '\0', MAX_QUERY_LEN);
1626 static int __insert_serviceapplication_share_allowed_info(manifest_x *mfx)
1628 serviceapplication_x *sp = mfx->serviceapplication;
1629 datashare_x *ds = NULL;
1630 define_x *df = NULL;
1631 allowed_x *al = NULL;
1633 char query[MAX_QUERY_LEN] = {'\0'};
1645 snprintf(query, MAX_QUERY_LEN,
1646 "insert into package_app_share_allowed(app_id, data_share_path, data_share_allowed) " \
1647 "values('%s', '%s', '%s')",\
1648 sp->appid, df->path, al->text);
1649 ret = __exec_query(query);
1651 DBG("Package App Share Allowed DB Insert Failed\n");
1654 memset(query, '\0', MAX_QUERY_LEN);
1666 static int __insert_manifest_info_in_db(manifest_x *mfx)
1668 label_x *lbl = mfx->label;
1669 license_x *lcn = mfx->license;
1670 icon_x *icn = mfx->icon;
1671 description_x *dcn = mfx->description;
1672 author_x *ath = mfx->author;
1673 uiapplication_x *up = mfx->uiapplication;
1674 uiapplication_x *up_icn = mfx->uiapplication;
1675 uiapplication_x *up_image = mfx->uiapplication;
1676 serviceapplication_x *sp = mfx->serviceapplication;
1677 char query[MAX_QUERY_LEN] = { '\0' };
1681 char *auth_name = NULL;
1682 char *auth_email = NULL;
1683 char *auth_href = NULL;
1686 auth_name = ath->text;
1688 auth_email = ath->email;
1690 auth_href = ath->href;
1693 /*Insert in the package_info DB*/
1695 type = strdup(mfx->type);
1697 type = strdup("rpm");
1698 /*Insert in the package_info DB*/
1700 path = strdup(mfx->root_path);
1702 if (strcmp(type,"rpm")==0)
1703 path = strdup("/usr/apps");
1705 path = strdup("/opt/usr/apps");
1707 snprintf(query, MAX_QUERY_LEN,
1708 "insert into package_info(package, package_type, package_version, install_location, package_size, " \
1709 "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) " \
1710 "values('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",\
1711 mfx->package, type, mfx->version, mfx->installlocation, mfx->package_size, mfx->removable, mfx->preload,
1712 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);
1713 ret = __exec_query(query);
1715 DBG("Package Info DB Insert Failed\n");
1734 /*Insert the package locale and app locale info */
1735 pkglocale = __create_locale_list(pkglocale, lbl, lcn, icn, dcn, ath);
1736 g_list_foreach(pkglocale, __trimfunc1, NULL);
1741 applocale = __create_locale_list(applocale, up->label, NULL, up->icon, NULL, NULL);
1746 applocale = __create_locale_list(applocale, sp->label, NULL, sp->icon, NULL, NULL);
1749 g_list_foreach(applocale, __trimfunc2, NULL);
1752 /*Insert the app icon info */
1753 while(up_icn != NULL)
1755 appicon = __create_icon_list(appicon, up_icn->icon);
1756 up_icn = up_icn->next;
1758 g_list_foreach(appicon, __trimfunc3, NULL);
1761 /*Insert the image info */
1762 while(up_image != NULL)
1764 appimage = __create_image_list(appimage, up_image->image);
1765 up_image = up_image->next;
1767 g_list_foreach(appimage, __trimfunc4, NULL);
1770 /*g_list_foreach(pkglocale, __printfunc, NULL);*/
1772 /*g_list_foreach(applocale, __printfunc, NULL);*/
1774 /*package locale info*/
1775 g_list_foreach(pkglocale, __insert_pkglocale_info, (gpointer)mfx);
1776 /*native app locale info*/
1777 up = mfx->uiapplication;
1780 g_list_foreach(applocale, __insert_uiapplication_locale_info, (gpointer)up);
1783 /*agent app locale info*/
1784 sp = mfx->serviceapplication;
1787 g_list_foreach(applocale, __insert_serviceapplication_locale_info, (gpointer)sp);
1791 /*app icon locale info*/
1792 up_icn = mfx->uiapplication;
1793 while(up_icn != NULL)
1795 g_list_foreach(appicon, __insert_uiapplication_icon_section_info, (gpointer)up_icn);
1796 up_icn = up_icn->next;
1800 up_image = mfx->uiapplication;
1801 while(up_image != NULL)
1803 g_list_foreach(appimage, __insert_uiapplication_image_info, (gpointer)up_image);
1804 up_image = up_image->next;
1807 g_list_free(pkglocale);
1809 g_list_free(applocale);
1811 g_list_free(appicon);
1813 g_list_free(appimage);
1817 /*Insert in the package_app_info DB*/
1818 ret = __insert_uiapplication_info(mfx);
1821 ret = __insert_ui_mainapp_info(mfx);
1824 ret = __insert_serviceapplication_info(mfx);
1828 /*Insert in the package_app_app_control DB*/
1829 ret = __insert_uiapplication_appcontrol_info(mfx);
1832 ret = __insert_serviceapplication_appcontrol_info(mfx);
1836 /*Insert in the package_app_app_category DB*/
1837 ret = __insert_uiapplication_appcategory_info(mfx);
1840 ret = __insert_serviceapplication_appcategory_info(mfx);
1844 /*Insert in the package_app_app_metadata DB*/
1845 ret = __insert_uiapplication_appmetadata_info(mfx);
1848 ret = __insert_serviceapplication_appmetadata_info(mfx);
1852 /*Insert in the package_app_app_permission DB*/
1853 ret = __insert_uiapplication_apppermission_info(mfx);
1856 ret = __insert_serviceapplication_apppermission_info(mfx);
1860 /*Insert in the package_app_app_svc DB*/
1861 ret = __insert_uiapplication_appsvc_info(mfx);
1864 ret = __insert_serviceapplication_appsvc_info(mfx);
1868 /*Insert in the package_app_share_allowed DB*/
1869 ret = __insert_uiapplication_share_allowed_info(mfx);
1872 ret = __insert_serviceapplication_share_allowed_info(mfx);
1876 /*Insert in the package_app_share_request DB*/
1877 ret = __insert_uiapplication_share_request_info(mfx);
1880 ret = __insert_serviceapplication_share_request_info(mfx);
1888 static int __delete_manifest_info_from_db(manifest_x *mfx)
1890 char query[MAX_QUERY_LEN] = { '\0' };
1892 uiapplication_x *up = mfx->uiapplication;
1893 serviceapplication_x *sp = mfx->serviceapplication;
1895 /*Delete from cert table*/
1896 ret = pkgmgrinfo_delete_certinfo(mfx->package);
1898 DBG("Cert Info DB Delete Failed\n");
1902 /*Delete from Package Info DB*/
1903 snprintf(query, MAX_QUERY_LEN,
1904 "delete from package_info where package='%s'", mfx->package);
1905 ret = __exec_query(query);
1907 DBG("Package Info DB Delete Failed\n");
1910 memset(query, '\0', MAX_QUERY_LEN);
1912 /*Delete from Package Localized Info*/
1913 snprintf(query, MAX_QUERY_LEN,
1914 "delete from package_localized_info where package='%s'", mfx->package);
1915 ret = __exec_query(query);
1917 DBG("Package Localized Info DB Delete Failed\n");
1920 memset(query, '\0', MAX_QUERY_LEN);
1922 /*Delete from Package App Info*/
1925 snprintf(query, MAX_QUERY_LEN,
1926 "delete from package_app_info where app_id='%s'", up->appid);
1927 ret = __exec_query(query);
1929 DBG("Package App Info DB Delete Failed\n");
1932 memset(query, '\0', MAX_QUERY_LEN);
1937 snprintf(query, MAX_QUERY_LEN,
1938 "delete from package_app_info where app_id='%s'", sp->appid);
1939 ret = __exec_query(query);
1941 DBG("Package App Info DB Delete Failed\n");
1944 memset(query, '\0', MAX_QUERY_LEN);
1948 /*Delete from Package App Localized Info*/
1949 up = mfx->uiapplication;
1950 sp = mfx->serviceapplication;
1953 snprintf(query, MAX_QUERY_LEN,
1954 "delete from package_app_localized_info where app_id='%s'", up->appid);
1955 ret = __exec_query(query);
1957 DBG("Package App Localized Info DB Delete Failed\n");
1960 memset(query, '\0', MAX_QUERY_LEN);
1965 snprintf(query, MAX_QUERY_LEN,
1966 "delete from package_app_localized_info where app_id='%s'", sp->appid);
1967 ret = __exec_query(query);
1969 DBG("Package App Localized Info DB Delete Failed\n");
1972 memset(query, '\0', MAX_QUERY_LEN);
1976 /*Delete from App icon localized Info*/
1977 up = mfx->uiapplication;
1980 snprintf(query, MAX_QUERY_LEN,
1981 "delete from package_app_icon_section_info where app_id='%s'", up->appid);
1982 ret = __exec_query(query);
1984 DBG("Package App image Info DB Delete Failed\n");
1987 memset(query, '\0', MAX_QUERY_LEN);
1991 /*Delete from App image Info*/
1992 up = mfx->uiapplication;
1995 snprintf(query, MAX_QUERY_LEN,
1996 "delete from package_app_image_info where app_id='%s'", up->appid);
1997 ret = __exec_query(query);
1999 DBG("Package App image Info DB Delete Failed\n");
2002 memset(query, '\0', MAX_QUERY_LEN);
2006 /*Delete from Package App App-Svc*/
2007 up = mfx->uiapplication;
2008 sp = mfx->serviceapplication;
2011 snprintf(query, MAX_QUERY_LEN,
2012 "delete from package_app_app_svc where app_id='%s'", up->appid);
2013 ret = __exec_query(query);
2015 DBG("Package App App-Svc DB Delete Failed\n");
2018 memset(query, '\0', MAX_QUERY_LEN);
2023 snprintf(query, MAX_QUERY_LEN,
2024 "delete from package_app_app_svc where app_id='%s'", sp->appid);
2025 ret = __exec_query(query);
2027 DBG("Package App App-Svc DB Delete Failed\n");
2030 memset(query, '\0', MAX_QUERY_LEN);
2034 /*Delete from Package App App-Control*/
2035 up = mfx->uiapplication;
2036 sp = mfx->serviceapplication;
2039 snprintf(query, MAX_QUERY_LEN,
2040 "delete from package_app_app_control where app_id='%s'", up->appid);
2041 ret = __exec_query(query);
2043 DBG("Package App App-Control DB Delete Failed\n");
2046 memset(query, '\0', MAX_QUERY_LEN);
2051 snprintf(query, MAX_QUERY_LEN,
2052 "delete from package_app_app_control where app_id='%s'", sp->appid);
2053 ret = __exec_query(query);
2055 DBG("Package App App-Control DB Delete Failed\n");
2058 memset(query, '\0', MAX_QUERY_LEN);
2062 /*Delete from Package App App-Category*/
2063 up = mfx->uiapplication;
2064 sp = mfx->serviceapplication;
2067 snprintf(query, MAX_QUERY_LEN,
2068 "delete from package_app_app_category where app_id='%s'", up->appid);
2069 ret = __exec_query(query);
2071 DBG("Package App App-Category DB Delete Failed\n");
2074 memset(query, '\0', MAX_QUERY_LEN);
2079 snprintf(query, MAX_QUERY_LEN,
2080 "delete from package_app_app_category where app_id='%s'", sp->appid);
2081 ret = __exec_query(query);
2083 DBG("Package App App-Category DB Delete Failed\n");
2086 memset(query, '\0', MAX_QUERY_LEN);
2090 /*Delete from Package App App-Metadata*/
2091 up = mfx->uiapplication;
2092 sp = mfx->serviceapplication;
2095 snprintf(query, MAX_QUERY_LEN,
2096 "delete from package_app_app_metadata where app_id='%s'", up->appid);
2097 ret = __exec_query(query);
2099 DBG("Package App App-Metadata DB Delete Failed\n");
2102 memset(query, '\0', MAX_QUERY_LEN);
2107 snprintf(query, MAX_QUERY_LEN,
2108 "delete from package_app_app_metadata where app_id='%s'", sp->appid);
2109 ret = __exec_query(query);
2111 DBG("Package App App-Metadata DB Delete Failed\n");
2114 memset(query, '\0', MAX_QUERY_LEN);
2118 /*Delete from Package App App-permission*/
2119 up = mfx->uiapplication;
2120 sp = mfx->serviceapplication;
2123 snprintf(query, MAX_QUERY_LEN,
2124 "delete from package_app_app_permission where app_id='%s'", up->appid);
2125 ret = __exec_query(query);
2127 DBG("Package App App-permission DB Delete Failed\n");
2130 memset(query, '\0', MAX_QUERY_LEN);
2135 snprintf(query, MAX_QUERY_LEN,
2136 "delete from package_app_app_permission where app_id='%s'", sp->appid);
2137 ret = __exec_query(query);
2139 DBG("Package App App-permission DB Delete Failed\n");
2142 memset(query, '\0', MAX_QUERY_LEN);
2146 /*Delete from Package App Share Allowed*/
2147 up = mfx->uiapplication;
2148 sp = mfx->serviceapplication;
2151 snprintf(query, MAX_QUERY_LEN,
2152 "delete from package_app_share_allowed where app_id='%s'", up->appid);
2153 ret = __exec_query(query);
2155 DBG("Package App Share Allowed DB Delete Failed\n");
2158 memset(query, '\0', MAX_QUERY_LEN);
2163 snprintf(query, MAX_QUERY_LEN,
2164 "delete from package_app_share_allowed where app_id='%s'", sp->appid);
2165 ret = __exec_query(query);
2167 DBG("Package App Share Allowed DB Delete Failed\n");
2170 memset(query, '\0', MAX_QUERY_LEN);
2174 /*Delete from Package App Share Request*/
2175 up = mfx->uiapplication;
2176 sp = mfx->serviceapplication;
2179 snprintf(query, MAX_QUERY_LEN,
2180 "delete from package_app_share_request where app_id='%s'", up->appid);
2181 ret = __exec_query(query);
2183 DBG("Package App Share Request DB Delete Failed\n");
2186 memset(query, '\0', MAX_QUERY_LEN);
2191 snprintf(query, MAX_QUERY_LEN,
2192 "delete from package_app_share_request where app_id='%s'", sp->appid);
2193 ret = __exec_query(query);
2195 DBG("Package App Share Request DB Delete Failed\n");
2198 memset(query, '\0', MAX_QUERY_LEN);
2205 int pkgmgr_parser_initialize_db()
2208 ret = __initialize_package_info_db();
2210 DBG("package info DB initialization failed\n");
2213 ret = __initialize_package_localized_info_db();
2215 DBG("package localized info DB initialization failed\n");
2218 ret = __initialize_package_cert_info_db();
2220 DBG("package cert info DB initialization failed\n");
2223 ret = __initialize_package_cert_index_info_db();
2225 DBG("package cert index info DB initialization failed\n");
2228 ret = __initialize_package_app_info_db();
2230 DBG("package app info DB initialization failed\n");
2233 ret = __initialize_package_app_localized_info_db();
2235 DBG("package app localized info DB initialization failed\n");
2238 ret = __initialize_package_app_icon_section_info_db();
2240 DBG("package app icon localized info DB initialization failed\n");
2243 ret = __initialize_package_app_image_info_db();
2245 DBG("package app image info DB initialization failed\n");
2248 ret = __initialize_package_app_app_control_db();
2250 DBG("package app app control DB initialization failed\n");
2253 ret = __initialize_package_app_app_category_db();
2255 DBG("package app app category DB initialization failed\n");
2258 ret = __initialize_package_app_app_metadata_db();
2260 DBG("package app app category DB initialization failed\n");
2263 ret = __initialize_package_app_app_permission_db();
2265 DBG("package app app permission DB initialization failed\n");
2268 ret = __initialize_package_app_app_svc_db();
2270 DBG("package app app svc DB initialization failed\n");
2273 ret = __initialize_package_app_share_allowed_db();
2275 DBG("package app share allowed DB initialization failed\n");
2278 ret = __initialize_package_app_share_request_db();
2280 DBG("package app share request DB initialization failed\n");
2286 int pkgmgr_parser_check_and_create_db()
2289 if (access(PKGMGR_PARSER_DB_FILE, F_OK) == 0) {
2291 db_util_open(PKGMGR_PARSER_DB_FILE, &pkgmgr_parser_db,
2292 DB_UTIL_REGISTER_HOOK_METHOD);
2293 if (ret != SQLITE_OK) {
2294 DBG("connect db [%s] failed!\n",
2295 PKGMGR_PARSER_DB_FILE);
2298 ret = chmod(PKGMGR_PARSER_DB_FILE, 0664);
2300 DBG("Failed to change mode of manifest DB\n");
2303 DBG("Pkgmgr DB does not exists. Create one!!\n");
2306 db_util_open(PKGMGR_PARSER_DB_FILE, &pkgmgr_parser_db,
2307 DB_UTIL_REGISTER_HOOK_METHOD);
2309 if (ret != SQLITE_OK) {
2310 DBG("connect db [%s] failed!\n", PKGMGR_PARSER_DB_FILE);
2313 ret = chmod(PKGMGR_PARSER_DB_FILE, 0664);
2315 DBG("Failed to change mode of manifest DB\n");
2319 API int pkgmgr_parser_insert_manifest_info_in_db(manifest_x *mfx)
2322 DBG("manifest pointer is NULL\n");
2326 ret = pkgmgr_parser_check_and_create_db();
2328 DBG("Failed to open DB\n");
2331 ret = pkgmgr_parser_initialize_db();
2334 /*Begin transaction*/
2335 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2336 if (ret != SQLITE_OK) {
2337 DBG("Failed to begin transaction\n");
2338 sqlite3_close(pkgmgr_parser_db);
2341 DBG("Transaction Begin\n");
2342 ret = __insert_manifest_info_in_db(mfx);
2344 DBG("Insert into DB failed. Rollback now\n");
2345 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2346 sqlite3_close(pkgmgr_parser_db);
2349 /*Commit transaction*/
2350 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2351 if (ret != SQLITE_OK) {
2352 DBG("Failed to commit transaction. Rollback now\n");
2353 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2354 sqlite3_close(pkgmgr_parser_db);
2357 DBG("Transaction Commit and End\n");
2358 sqlite3_close(pkgmgr_parser_db);
2362 API int pkgmgr_parser_update_manifest_info_in_db(manifest_x *mfx)
2365 DBG("manifest pointer is NULL\n");
2369 ret = pkgmgr_parser_check_and_create_db();
2371 DBG("Failed to open DB\n");
2374 ret = pkgmgr_parser_initialize_db();
2377 /*Preserve guest mode visibility*/
2378 __preserve_guestmode_visibility_value( mfx);
2379 /*Begin transaction*/
2380 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2381 if (ret != SQLITE_OK) {
2382 DBG("Failed to begin transaction\n");
2383 sqlite3_close(pkgmgr_parser_db);
2386 DBG("Transaction Begin\n");
2387 ret = __delete_manifest_info_from_db(mfx);
2389 DBG("Delete from DB failed. Rollback now\n");
2390 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2391 sqlite3_close(pkgmgr_parser_db);
2394 ret = __insert_manifest_info_in_db(mfx);
2396 DBG("Insert into DB failed. Rollback now\n");
2397 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2398 sqlite3_close(pkgmgr_parser_db);
2402 /*Commit transaction*/
2403 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2404 if (ret != SQLITE_OK) {
2405 DBG("Failed to commit transaction. Rollback now\n");
2406 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2407 sqlite3_close(pkgmgr_parser_db);
2410 DBG("Transaction Commit and End\n");
2411 sqlite3_close(pkgmgr_parser_db);
2415 API int pkgmgr_parser_delete_manifest_info_from_db(manifest_x *mfx)
2418 DBG("manifest pointer is NULL\n");
2422 ret = pkgmgr_parser_check_and_create_db();
2424 DBG("Failed to open DB\n");
2427 /*Begin transaction*/
2428 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2429 if (ret != SQLITE_OK) {
2430 DBG("Failed to begin transaction\n");
2431 sqlite3_close(pkgmgr_parser_db);
2434 DBG("Transaction Begin\n");
2435 ret = __delete_manifest_info_from_db(mfx);
2437 DBG("Delete from DB failed. Rollback now\n");
2438 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2439 sqlite3_close(pkgmgr_parser_db);
2442 /*Commit transaction*/
2443 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2444 if (ret != SQLITE_OK) {
2445 DBG("Failed to commit transaction, Rollback now\n");
2446 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2447 sqlite3_close(pkgmgr_parser_db);
2450 DBG("Transaction Commit and End\n");
2451 sqlite3_close(pkgmgr_parser_db);