4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
7 * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
26 #include <sys/types.h>
31 #include "pkgmgr-info.h"
32 #include "pkgmgr_parser_internal.h"
33 #include "pkgmgr_parser_db.h"
35 #define PKGMGR_PARSER_DB_FILE "/opt/dbspace/.pkgmgr_parser.db"
36 #define PKGMGR_CERT_DB_FILE "/opt/dbspace/.pkgmgr_cert.db"
37 #define MAX_QUERY_LEN 4096
38 sqlite3 *pkgmgr_parser_db;
39 sqlite3 *pkgmgr_cert_db;
40 GList *pkglocale = NULL;
41 GList *applocale = NULL;
42 GList *appicon = NULL;
43 GList *appimage = NULL;
46 #define QUERY_CREATE_TABLE_PACKAGE_INFO "create table if not exists package_info " \
47 "(package text primary key not null, " \
48 "package_type text DEFAULT 'rpm', " \
49 "package_version text, " \
50 "install_location text, " \
51 "package_size text, " \
52 "package_removable text DEFAULT 'true', " \
53 "package_preload text DEFAULT 'false', " \
54 "package_readonly text DEFAULT 'false', " \
55 "package_update text DEFAULT 'false', " \
56 "package_appsetting text DEFAULT 'false', " \
57 "author_name text, " \
58 "author_email text, " \
60 "installed_time text," \
61 "installed_storage text," \
62 "storeclient_id text," \
67 #define QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO "create table if not exists package_localized_info " \
68 "(package text not null, " \
69 "package_locale text DEFAULT 'No Locale', " \
70 "package_label text, " \
71 "package_icon text, " \
72 "package_description text, " \
73 "package_license text, " \
75 "PRIMARY KEY(package, package_locale), " \
76 "FOREIGN KEY(package) " \
77 "REFERENCES package_info(package) " \
80 #define QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO "create table if not exists package_privilege_info " \
81 "(package text not null, " \
82 "privilege text not null, " \
83 "PRIMARY KEY(package, privilege) " \
84 "FOREIGN KEY(package) " \
85 "REFERENCES package_info(package) " \
88 #define QUERY_CREATE_TABLE_PACKAGE_APP_INFO "create table if not exists package_app_info " \
89 "(app_id text primary key not null, " \
90 "app_component text, " \
92 "app_nodisplay text DEFAULT 'false', " \
94 "app_onboot text DEFAULT 'false', " \
95 "app_multiple text DEFAULT 'false', " \
96 "app_autorestart text DEFAULT 'false', " \
97 "app_taskmanage text DEFAULT 'false', " \
98 "app_enabled text DEFAULT 'true', " \
99 "app_hwacceleration text DEFAULT 'use-system-setting', " \
100 "app_mainapp text, " \
101 "app_recentimage text, " \
102 "app_indicatordisplay text DEFAULT 'true', " \
103 "app_portraitimg text, " \
104 "app_landscapeimg text, " \
105 "app_guestmodevisibility text DEFAULT 'true', " \
106 "package text not null, " \
107 "FOREIGN KEY(package) " \
108 "REFERENCES package_info(package) " \
111 #define QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO "create table if not exists package_app_localized_info " \
112 "(app_id text not null, " \
113 "app_locale text DEFAULT 'No Locale', " \
116 "PRIMARY KEY(app_id,app_locale) " \
117 "FOREIGN KEY(app_id) " \
118 "REFERENCES package_app_info(app_id) " \
121 #define QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO "create table if not exists package_app_icon_section_info " \
122 "(app_id text not null, " \
124 "app_icon_section text, " \
125 "app_icon_resolution text, " \
126 "PRIMARY KEY(app_id,app_icon_section,app_icon_resolution) " \
127 "FOREIGN KEY(app_id) " \
128 "REFERENCES package_app_info(app_id) " \
131 #define QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO "create table if not exists package_app_image_info " \
132 "(app_id text not null, " \
133 "app_locale text DEFAULT 'No Locale', " \
134 "app_image_section text, " \
136 "PRIMARY KEY(app_id,app_image_section) " \
137 "FOREIGN KEY(app_id) " \
138 "REFERENCES package_app_info(app_id) " \
141 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL "create table if not exists package_app_app_control " \
142 "(app_id text not null, " \
143 "operation text not null, " \
144 "uri_scheme text, " \
146 "subapp_name text, " \
147 "PRIMARY KEY(app_id,operation,uri_scheme,mime_type,subapp_name) " \
148 "FOREIGN KEY(app_id) " \
149 "REFERENCES package_app_info(app_id) " \
152 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_SVC "create table if not exists package_app_app_svc " \
153 "(app_id text not null, " \
154 "operation text not null, " \
155 "uri_scheme text, " \
157 "subapp_name text, " \
158 "PRIMARY KEY(app_id,operation,uri_scheme,mime_type,subapp_name) " \
159 "FOREIGN KEY(app_id) " \
160 "REFERENCES package_app_info(app_id) " \
163 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY "create table if not exists package_app_app_category " \
164 "(app_id text not null, " \
165 "category text not null, " \
166 "PRIMARY KEY(app_id,category) " \
167 "FOREIGN KEY(app_id) " \
168 "REFERENCES package_app_info(app_id) " \
171 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA "create table if not exists package_app_app_metadata " \
172 "(app_id text not null, " \
173 "md_key text not null, " \
174 "md_value text not null, " \
175 "PRIMARY KEY(app_id, md_key, md_value) " \
176 "FOREIGN KEY(app_id) " \
177 "REFERENCES package_app_info(app_id) " \
180 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION "create table if not exists package_app_app_permission " \
181 "(app_id text not null, " \
182 "pm_type text not null, " \
183 "pm_value text not null, " \
184 "PRIMARY KEY(app_id) " \
185 "FOREIGN KEY(app_id) " \
186 "REFERENCES package_app_info(app_id) " \
189 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED "create table if not exists package_app_share_allowed " \
190 "(app_id text not null, " \
191 "data_share_path text not null, " \
192 "data_share_allowed text not null, " \
193 "PRIMARY KEY(app_id,data_share_path,data_share_allowed) " \
194 "FOREIGN KEY(app_id) " \
195 "REFERENCES package_app_info(app_id) " \
198 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST "create table if not exists package_app_share_request " \
199 "(app_id text not null, " \
200 "data_share_request text not null, " \
201 "PRIMARY KEY(app_id,data_share_request) " \
202 "FOREIGN KEY(app_id) " \
203 "REFERENCES package_app_info(app_id) " \
206 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO "create table if not exists package_cert_index_info " \
207 "(cert_info text not null, " \
208 "cert_id integer, " \
209 "cert_ref_count integer, " \
210 "PRIMARY KEY(cert_id)) "
212 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INFO "create table if not exists package_cert_info " \
213 "(package text not null, " \
214 "author_root_cert integer, " \
215 "author_im_cert integer, " \
216 "author_signer_cert integer, " \
217 "dist_root_cert integer, " \
218 "dist_im_cert integer, " \
219 "dist_signer_cert integer, " \
220 "dist2_root_cert integer, " \
221 "dist2_im_cert integer, " \
222 "dist2_signer_cert integer, " \
223 "PRIMARY KEY(package)) "
225 static int __insert_uiapplication_info(manifest_x *mfx);
226 static int __insert_serviceapplication_info(manifest_x *mfx);
227 static int __insert_uiapplication_appsvc_info(manifest_x *mfx);
228 static int __insert_serviceapplication_appsvc_info(manifest_x *mfx);
229 static int __insert_uiapplication_appcategory_info(manifest_x *mfx);
230 static int __insert_serviceapplication_appcategory_info(manifest_x *mfx);
231 static int __insert_uiapplication_appcontrol_info(manifest_x *mfx);
232 static int __insert_serviceapplication_appmetadata_info(manifest_x *mfx);
233 static int __insert_uiapplication_appmetadata_info(manifest_x *mfx);
234 static int __insert_serviceapplication_appcontrol_info(manifest_x *mfx);
235 static int __insert_uiapplication_share_allowed_info(manifest_x *mfx);
236 static int __insert_serviceapplication_share_allowed_info(manifest_x *mfx);
237 static int __insert_uiapplication_share_request_info(manifest_x *mfx);
238 static int __insert_serviceapplication_share_request_info(manifest_x *mfx);
239 static void __insert_serviceapplication_locale_info(gpointer data, gpointer userdata);
240 static void __insert_uiapplication_locale_info(gpointer data, gpointer userdata);
241 static void __insert_pkglocale_info(gpointer data, gpointer userdata);
242 static int __insert_manifest_info_in_db(manifest_x *mfx);
243 static int __delete_manifest_info_from_db(manifest_x *mfx);
244 static int __delete_appinfo_from_db(char *db_table, const char *appid);
245 static int __initialize_db(sqlite3 *db_handle, const char *db_query);
246 static int __exec_query(char *query);
247 static void __extract_data(gpointer data, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath,
248 char **label, char **license, char **icon, char **description, char **author);
249 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata);
250 static void __trimfunc1(gpointer data, gpointer userdata);
251 static void __trimfunc2(gpointer data, gpointer userdata);
252 static GList *__create_locale_list(GList *locale, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath);
253 static void __preserve_guestmode_visibility_value(manifest_x *mfx);
254 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname);
255 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path);
257 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path)
261 if (access(db_path, F_OK) == 0) {
263 db_util_open(db_path, &handle,
264 DB_UTIL_REGISTER_HOOK_METHOD);
265 if (ret != SQLITE_OK) {
266 DBG("connect db [%s] failed!\n",
273 DBG("%s DB does not exists. Create one!!\n", db_path);
276 db_util_open(db_path, &handle,
277 DB_UTIL_REGISTER_HOOK_METHOD);
279 if (ret != SQLITE_OK) {
280 DBG("connect db [%s] failed!\n", db_path);
287 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname)
289 manifest_x *mfx = (manifest_x *)data;
293 uiapplication_x *uiapp = NULL;
294 for(i = 0; i < ncols; i++)
296 uiapp = mfx->uiapplication;
297 if (strcmp(colname[i], "app_id") == 0) {
299 appid = strdup(coltxt[i]);
300 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0) {
302 status = strdup(coltxt[i]);
305 /*update guest mode visibility*/
306 for (; uiapp != NULL; uiapp = uiapp->next) {
307 if (strcmp(uiapp->appid, appid) == 0) {
308 free((void *)uiapp->guestmode_visibility);
309 uiapp->guestmode_visibility = strdup(status);
325 static void __preserve_guestmode_visibility_value(manifest_x *mfx)
327 char *error_message = NULL;
328 char query[MAX_QUERY_LEN] = {'\0'};
329 snprintf(query, MAX_QUERY_LEN - 1, "select app_id, app_guestmodevisibility from package_app_info where package='%s'", mfx->package);
331 sqlite3_exec(pkgmgr_parser_db, query,
332 __guestmode_visibility_cb, (void *)mfx, &error_message)) {
333 DBG("Don't execute query = %s error message = %s\n",
334 query, error_message);
335 sqlite3_free(error_message);
340 static int __initialize_db(sqlite3 *db_handle, const char *db_query)
342 char *error_message = NULL;
344 sqlite3_exec(db_handle, db_query,
345 NULL, NULL, &error_message)) {
346 DBG("Don't execute query = %s error message = %s\n",
347 db_query, error_message);
348 sqlite3_free(error_message);
351 sqlite3_free(error_message);
355 static int __exec_query(char *query)
357 char *error_message = NULL;
359 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
360 DBG("Don't execute query = %s error message = %s\n", query,
362 sqlite3_free(error_message);
365 sqlite3_free(error_message);
368 static GList *__create_locale_list(GList *locale, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath)
374 locale = g_list_insert_sorted_with_data(locale, (gpointer)lbl->lang, __comparefunc, NULL);
380 locale = g_list_insert_sorted_with_data(locale, (gpointer)lcn->lang, __comparefunc, NULL);
386 locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->lang, __comparefunc, NULL);
392 locale = g_list_insert_sorted_with_data(locale, (gpointer)dcn->lang, __comparefunc, NULL);
398 locale = g_list_insert_sorted_with_data(locale, (gpointer)ath->lang, __comparefunc, NULL);
405 static GList *__create_icon_list(GList *locale, icon_x *icn)
410 locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->section, __comparefunc, NULL);
416 static GList *__create_image_list(GList *locale, image_x *image)
421 locale = g_list_insert_sorted_with_data(locale, (gpointer)image->section, __comparefunc, NULL);
427 static void __printfunc(gpointer data, gpointer userdata)
429 DBG("%s ", (char*)data);
432 static void __trimfunc1(gpointer data, gpointer userdata)
435 if (strcmp((char *)data, prev) == 0) {
436 pkglocale = g_list_remove(pkglocale, data);
444 static void __trimfunc2(gpointer data, gpointer userdata)
447 if (strcmp((char *)data, prev) == 0) {
448 applocale = g_list_remove(applocale, data);
456 static void __trimfunc3(gpointer data, gpointer userdata)
459 if (strcmp((char *)data, prev) == 0) {
460 appicon = g_list_remove(appicon, data);
468 static void __trimfunc4(gpointer data, gpointer userdata)
471 if (strcmp((char *)data, prev) == 0) {
472 appimage = g_list_remove(appimage, data);
480 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata)
482 if (a == NULL || b == NULL)
484 if (strcmp((char*)a, (char*)b) == 0)
486 if (strcmp((char*)a, (char*)b) < 0)
488 if (strcmp((char*)a, (char*)b) > 0)
493 static void __extract_data(gpointer data, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath,
494 char **label, char **license, char **icon, char **description, char **author)
499 if (strcmp(lbl->lang, (char *)data) == 0) {
500 *label = (char*)lbl->text;
509 if (strcmp(lcn->lang, (char *)data) == 0) {
510 *license = (char*)lcn->text;
519 if (strcmp(icn->lang, (char *)data) == 0) {
520 *icon = (char*)icn->text;
529 if (strcmp(dcn->lang, (char *)data) == 0) {
530 *description = (char*)dcn->text;
539 if (strcmp(ath->lang, (char *)data) == 0) {
540 *author = (char*)ath->text;
549 static void __extract_icon_data(gpointer data, icon_x *icn, char **icon, char **resolution)
554 if (strcmp(icn->section, (char *)data) == 0) {
555 *icon = (char*)icn->text;
556 *resolution = (char*)icn->resolution;
564 static void __extract_image_data(gpointer data, image_x*image, char **lang, char **img)
568 if (image->section) {
569 if (strcmp(image->section, (char *)data) == 0) {
570 *lang = (char*)image->lang;
571 *img = (char*)image->text;
579 static void __insert_pkglocale_info(gpointer data, gpointer userdata)
584 char *description = NULL;
585 char *license = NULL;
587 char query[MAX_QUERY_LEN] = {'\0'};
589 manifest_x *mfx = (manifest_x *)userdata;
590 label_x *lbl = mfx->label;
591 license_x *lcn = mfx->license;
592 icon_x *icn = mfx->icon;
593 description_x *dcn = mfx->description;
594 author_x *ath = mfx->author;
596 __extract_data(data, lbl, lcn, icn, dcn, ath, &label, &license, &icon, &description, &author);
597 if (!label && !description && !icon && !license && !author)
599 snprintf(query, MAX_QUERY_LEN, "insert into package_localized_info(package, package_locale, " \
600 "package_label, package_icon, package_description, package_license, package_author) values " \
601 "('%s', '%s', '%s', '%s', '%s', '%s', '%s')", mfx->package, (char*)data,
602 label, icon, description, license, author);
603 ret = __exec_query(query);
605 DBG("Package Localized Info DB Insert failed\n");
608 static void __insert_uiapplication_locale_info(gpointer data, gpointer userdata)
613 char query[MAX_QUERY_LEN] = {'\0'};
615 uiapplication_x *up = (uiapplication_x*)userdata;
616 label_x *lbl = up->label;
617 icon_x *icn = up->icon;
619 __extract_data(data, lbl, NULL, icn, NULL, NULL, &label, NULL, &icon, NULL, NULL);
622 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_localized_info(app_id, app_locale, " \
623 "app_label, app_icon) values " \
624 "('%q', '%q', '%q', '%q')", up->appid, (char*)data,
626 ret = __exec_query(query);
628 DBG("Package UiApp Localized Info DB Insert failed\n");
632 static void __insert_uiapplication_icon_section_info(gpointer data, gpointer userdata)
636 char *resolution = NULL;
637 char query[MAX_QUERY_LEN] = {'\0'};
639 uiapplication_x *up = (uiapplication_x*)userdata;
640 icon_x *icn = up->icon;
642 __extract_icon_data(data, icn, &icon, &resolution);
643 if (!icon && !resolution)
645 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_icon_section_info(app_id, " \
646 "app_icon, app_icon_section, app_icon_resolution) values " \
647 "('%q', '%q', '%q', '%q')", up->appid,
648 icon, (char*)data, resolution);
650 ret = __exec_query(query);
652 DBG("Package UiApp Localized Info DB Insert failed\n");
656 static void __insert_uiapplication_image_info(gpointer data, gpointer userdata)
661 char query[MAX_QUERY_LEN] = {'\0'};
663 uiapplication_x *up = (uiapplication_x*)userdata;
664 image_x *image = up->image;
666 __extract_image_data(data, image, &lang, &img);
669 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_image_info(app_id, app_locale, " \
670 "app_image_section, app_image) values " \
671 "('%q', '%q', '%q', '%q')", up->appid, lang, (char*)data, img);
673 ret = __exec_query(query);
675 DBG("Package UiApp image Info DB Insert failed\n");
680 static void __insert_serviceapplication_locale_info(gpointer data, gpointer userdata)
685 char query[MAX_QUERY_LEN] = {'\0'};
687 serviceapplication_x *sp = (serviceapplication_x*)userdata;
688 label_x *lbl = sp->label;
689 icon_x *icn = sp->icon;
691 __extract_data(data, lbl, NULL, icn, NULL, NULL, &label, NULL, &icon, NULL, NULL);
694 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_localized_info(app_id, app_locale, " \
695 "app_label, app_icon) values " \
696 "('%q', '%q', '%q', '%q')", sp->appid, (char*)data,
698 ret = __exec_query(query);
700 DBG("Package ServiceApp Localized Info DB Insert failed\n");
703 static int __insert_ui_mainapp_info(manifest_x *mfx)
705 uiapplication_x *up = mfx->uiapplication;
707 char query[MAX_QUERY_LEN] = {'\0'};
710 snprintf(query, MAX_QUERY_LEN,
711 "update package_app_info set app_mainapp='%s' where app_id='%s'", up->mainapp, up->appid);
713 ret = __exec_query(query);
715 DBG("Package UiApp Info DB Insert Failed\n");
718 if (strcasecmp(up->mainapp, "True")==0)
719 mfx->mainapp_id = strdup(up->appid);
722 memset(query, '\0', MAX_QUERY_LEN);
725 if (mfx->mainapp_id == NULL){
726 if (mfx->uiapplication
727 && mfx->uiapplication->appid) {
728 snprintf(query, MAX_QUERY_LEN,
729 "update package_app_info set app_mainapp='true' where app_id='%s'", mfx->uiapplication->appid);
730 } else if (mfx->serviceapplication
731 && mfx->serviceapplication->appid) {
732 snprintf(query, MAX_QUERY_LEN,
733 "update package_app_info set app_mainapp='true' where app_id='%s'", mfx->serviceapplication->appid);
735 DBG("Not valid appid\n");
739 ret = __exec_query(query);
741 DBG("Package UiApp Info DB Insert Failed\n");
744 if (mfx->uiapplication && mfx->uiapplication->appid)
745 mfx->mainapp_id = strdup(mfx->uiapplication->appid);
746 else if (mfx->serviceapplication && mfx->serviceapplication->appid)
747 mfx->mainapp_id = strdup(mfx->serviceapplication->appid);
751 memset(query, '\0', MAX_QUERY_LEN);
752 snprintf(query, MAX_QUERY_LEN,
753 "update package_info set mainapp_id='%s' where package='%s'", mfx->mainapp_id, mfx->package);
754 ret = __exec_query(query);
756 DBG("Package Info DB update Failed\n");
762 /* _PRODUCT_LAUNCHING_ENHANCED_
763 * up->indicatordisplay, up->portraitimg, up->landscapeimg, up->guestmode_appstatus
765 static int __insert_uiapplication_info(manifest_x *mfx)
767 uiapplication_x *up = mfx->uiapplication;
769 char query[MAX_QUERY_LEN] = {'\0'};
772 snprintf(query, MAX_QUERY_LEN,
773 "insert into package_app_info(app_id, app_component, app_exec, app_nodisplay, app_type, app_onboot, " \
774 "app_multiple, app_autorestart, app_taskmanage, app_enabled, app_hwacceleration, app_mainapp , app_recentimage, app_indicatordisplay, app_portraitimg, app_landscapeimg, app_guestmodevisibility, package) " \
775 "values('%s', '%s', '%s', '%s', '%s', '%s','%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",\
776 up->appid, "uiapp", up->exec, up->nodisplay, up->type, "\0", up->multiple,
777 "\0", up->taskmanage, up->enabled, up->hwacceleration,up->mainapp, up->recentimage, up->indicatordisplay, up->portraitimg, up->landscapeimg, up->guestmode_visibility, mfx->package);
778 ret = __exec_query(query);
780 DBG("Package UiApp Info DB Insert Failed\n");
784 memset(query, '\0', MAX_QUERY_LEN);
789 static int __insert_uiapplication_appcategory_info(manifest_x *mfx)
791 uiapplication_x *up = mfx->uiapplication;
792 category_x *ct = NULL;
794 char query[MAX_QUERY_LEN] = {'\0'};
800 snprintf(query, MAX_QUERY_LEN,
801 "insert into package_app_app_category(app_id, category) " \
802 "values('%s','%s')",\
803 up->appid, ct->name);
804 ret = __exec_query(query);
806 DBG("Package UiApp Category Info DB Insert Failed\n");
810 memset(query, '\0', MAX_QUERY_LEN);
817 static int __insert_uiapplication_appmetadata_info(manifest_x *mfx)
819 uiapplication_x *up = mfx->uiapplication;
820 metadata_x *md = NULL;
822 char query[MAX_QUERY_LEN] = {'\0'};
829 snprintf(query, MAX_QUERY_LEN,
830 "insert into package_app_app_metadata(app_id, md_key, md_value) " \
831 "values('%s','%s', '%s')",\
832 up->appid, md->key, md->value);
833 ret = __exec_query(query);
835 DBG("Package UiApp Metadata Info DB Insert Failed\n");
840 memset(query, '\0', MAX_QUERY_LEN);
847 static int __insert_uiapplication_apppermission_info(manifest_x *mfx)
849 uiapplication_x *up = mfx->uiapplication;
850 permission_x *pm = NULL;
852 char query[MAX_QUERY_LEN] = {'\0'};
858 snprintf(query, MAX_QUERY_LEN,
859 "insert into package_app_app_permission(app_id, pm_type, pm_value) " \
860 "values('%s','%s', '%s')",\
861 up->appid, pm->type, pm->value);
862 ret = __exec_query(query);
864 DBG("Package UiApp permission Info DB Insert Failed\n");
868 memset(query, '\0', MAX_QUERY_LEN);
875 static int __insert_uiapplication_appcontrol_info(manifest_x *mfx)
877 uiapplication_x *up = mfx->uiapplication;
878 appcontrol_x *acontrol = NULL;
879 operation_x *op = NULL;
882 subapp_x *sub = NULL;
884 char query[MAX_QUERY_LEN] = {'\0'};
885 const char *operation = NULL;
886 const char *mime = NULL;
887 const char *uri = NULL;
888 const char *subapp = NULL;
891 acontrol = up->appcontrol;
892 while(acontrol != NULL)
894 op = acontrol->operation;
898 operation = op->name;
905 sub = acontrol->subapp;
915 snprintf(query, MAX_QUERY_LEN,
916 "insert into package_app_app_control(app_id, operation, uri_scheme, mime_type, subapp_name) " \
917 "values('%s', '%s', '%s', '%s', '%s')",\
918 up->appid, operation, uri, mime, subapp);
920 ret = __exec_query(query);
922 DBG("Package UiApp AppSvc DB Insert Failed\n");
925 memset(query, '\0', MAX_QUERY_LEN);
942 acontrol = acontrol->next;
949 static int __insert_uiapplication_appsvc_info(manifest_x *mfx)
951 uiapplication_x *up = mfx->uiapplication;
952 appsvc_x *asvc = NULL;
953 operation_x *op = NULL;
956 subapp_x *sub = NULL;
958 char query[MAX_QUERY_LEN] = {'\0'};
959 const char *operation = NULL;
960 const char *mime = NULL;
961 const char *uri = NULL;
962 const char *subapp = NULL;
968 op = asvc->operation;
972 operation = op->name;
989 snprintf(query, MAX_QUERY_LEN,
990 "insert into package_app_app_svc(app_id, operation, uri_scheme, mime_type, subapp_name) " \
991 "values('%s', '%s', '%s', '%s', '%s')",\
992 up->appid, operation, uri, mime, subapp);
994 ret = __exec_query(query);
996 DBG("Package UiApp AppSvc DB Insert Failed\n");
999 memset(query, '\0', MAX_QUERY_LEN);
1003 } while(ui != NULL);
1007 }while(sub != NULL);
1023 static int __insert_uiapplication_share_request_info(manifest_x *mfx)
1025 uiapplication_x *up = mfx->uiapplication;
1026 datashare_x *ds = NULL;
1027 request_x *rq = NULL;
1029 char query[MAX_QUERY_LEN] = {'\0'};
1038 snprintf(query, MAX_QUERY_LEN,
1039 "insert into package_app_share_request(app_id, data_share_request) " \
1040 "values('%s', '%s')",\
1041 up->appid, rq->text);
1042 ret = __exec_query(query);
1044 DBG("Package UiApp Share Request DB Insert Failed\n");
1047 memset(query, '\0', MAX_QUERY_LEN);
1057 static int __insert_uiapplication_share_allowed_info(manifest_x *mfx)
1059 uiapplication_x *up = mfx->uiapplication;
1060 datashare_x *ds = NULL;
1061 define_x *df = NULL;
1062 allowed_x *al = NULL;
1064 char query[MAX_QUERY_LEN] = {'\0'};
1076 snprintf(query, MAX_QUERY_LEN,
1077 "insert into package_app_share_allowed(app_id, data_share_path, data_share_allowed) " \
1078 "values('%s', '%s', '%s')",\
1079 up->appid, df->path, al->text);
1080 ret = __exec_query(query);
1082 DBG("Package UiApp Share Allowed DB Insert Failed\n");
1085 memset(query, '\0', MAX_QUERY_LEN);
1097 static int __insert_serviceapplication_info(manifest_x *mfx)
1099 serviceapplication_x *sp = mfx->serviceapplication;
1101 char query[MAX_QUERY_LEN] = {'\0'};
1104 snprintf(query, MAX_QUERY_LEN,
1105 "insert into package_app_info(app_id, app_component, app_exec, app_type, app_onboot, " \
1106 "app_multiple, app_autorestart, app_enabled, package) " \
1107 "values('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",\
1108 sp->appid, "svcapp", sp->exec, sp->type, sp->onboot, "\0",
1109 sp->autorestart, sp->enabled, mfx->package);
1110 ret = __exec_query(query);
1112 DBG("Package ServiceApp Info DB Insert Failed\n");
1116 memset(query, '\0', MAX_QUERY_LEN);
1121 static int __insert_serviceapplication_appcategory_info(manifest_x *mfx)
1123 serviceapplication_x *sp = mfx->serviceapplication;
1124 category_x *ct = NULL;
1126 char query[MAX_QUERY_LEN] = {'\0'};
1132 snprintf(query, MAX_QUERY_LEN,
1133 "insert into package_app_app_category(app_id, category) " \
1134 "values('%s','%s')",\
1135 sp->appid, ct->name);
1136 ret = __exec_query(query);
1138 DBG("Package ServiceApp Category Info DB Insert Failed\n");
1142 memset(query, '\0', MAX_QUERY_LEN);
1149 static int __insert_serviceapplication_appmetadata_info(manifest_x *mfx)
1151 serviceapplication_x *sp = mfx->serviceapplication;
1152 metadata_x *md = NULL;
1154 char query[MAX_QUERY_LEN] = {'\0'};
1161 snprintf(query, MAX_QUERY_LEN,
1162 "insert into package_app_app_metadata(app_id, md_key, md_value) " \
1163 "values('%s','%s', '%s')",\
1164 sp->appid, md->key, md->value);
1165 ret = __exec_query(query);
1167 DBG("Package ServiceApp Metadata Info DB Insert Failed\n");
1172 memset(query, '\0', MAX_QUERY_LEN);
1179 static int __insert_serviceapplication_apppermission_info(manifest_x *mfx)
1181 serviceapplication_x *sp = mfx->serviceapplication;
1182 permission_x *pm = NULL;
1184 char query[MAX_QUERY_LEN] = {'\0'};
1187 pm = sp->permission;
1190 snprintf(query, MAX_QUERY_LEN,
1191 "insert into package_app_app_permission(app_id, pm_type, pm_value) " \
1192 "values('%s','%s', '%s')",\
1193 sp->appid, pm->type, pm->value);
1194 ret = __exec_query(query);
1196 DBG("Package ServiceApp permission Info DB Insert Failed\n");
1200 memset(query, '\0', MAX_QUERY_LEN);
1207 static int __insert_serviceapplication_appcontrol_info(manifest_x *mfx)
1209 serviceapplication_x *sp = mfx->serviceapplication;
1210 appcontrol_x *acontrol = NULL;
1212 char query[MAX_QUERY_LEN] = {'\0'};
1213 operation_x *op = NULL;
1216 subapp_x *sub = NULL;
1217 const char *operation = NULL;
1218 const char *mime = NULL;
1219 const char *uri = NULL;
1220 const char *subapp = NULL;
1223 acontrol = sp->appcontrol;
1224 while(acontrol != NULL)
1226 op = acontrol->operation;
1230 operation = op->name;
1231 mi = acontrol->mime;
1236 sub = acontrol->subapp;
1246 snprintf(query, MAX_QUERY_LEN,
1247 "insert into package_app_app_control(app_id, operation, uri_scheme, mime_type,subapp_name) " \
1248 "values('%s', '%s', '%s', '%s', '%s')",\
1249 sp->appid, operation, uri, mime, subapp);
1250 ret = __exec_query(query);
1252 DBG("Package UiApp AppSvc DB Insert Failed\n");
1255 memset(query, '\0', MAX_QUERY_LEN);
1259 } while(ui != NULL);
1263 }while(sub != NULL);
1272 acontrol = acontrol->next;
1279 static int __insert_serviceapplication_appsvc_info(manifest_x *mfx)
1281 serviceapplication_x *sp = mfx->serviceapplication;
1282 appsvc_x *asvc = NULL;
1284 char query[MAX_QUERY_LEN] = {'\0'};
1285 operation_x *op = NULL;
1288 subapp_x *sub = NULL;
1289 const char *operation = NULL;
1290 const char *mime = NULL;
1291 const char *uri = NULL;
1292 const char *subapp = NULL;
1298 op = asvc->operation;
1302 operation = op->name;
1318 snprintf(query, MAX_QUERY_LEN,
1319 "insert into package_app_app_svc(app_id, operation, uri_scheme, mime_type, subapp_name) " \
1320 "values('%s', '%s', '%s', '%s', '%s')",\
1321 sp->appid, operation, uri, mime, subapp);
1322 ret = __exec_query(query);
1324 DBG("Package UiApp AppSvc DB Insert Failed\n");
1327 memset(query, '\0', MAX_QUERY_LEN);
1331 } while(ui != NULL);
1335 }while(sub != NULL);
1353 static int __insert_serviceapplication_share_request_info(manifest_x *mfx)
1355 serviceapplication_x *sp = mfx->serviceapplication;
1356 datashare_x *ds = NULL;
1357 request_x *rq = NULL;
1359 char query[MAX_QUERY_LEN] = {'\0'};
1368 snprintf(query, MAX_QUERY_LEN,
1369 "insert into package_app_share_request(app_id, data_share_request) " \
1370 "values('%s', '%s')",\
1371 sp->appid, rq->text);
1372 ret = __exec_query(query);
1374 DBG("Package ServiceApp Share Request DB Insert Failed\n");
1377 memset(query, '\0', MAX_QUERY_LEN);
1389 static int __insert_serviceapplication_share_allowed_info(manifest_x *mfx)
1391 serviceapplication_x *sp = mfx->serviceapplication;
1392 datashare_x *ds = NULL;
1393 define_x *df = NULL;
1394 allowed_x *al = NULL;
1396 char query[MAX_QUERY_LEN] = {'\0'};
1408 snprintf(query, MAX_QUERY_LEN,
1409 "insert into package_app_share_allowed(app_id, data_share_path, data_share_allowed) " \
1410 "values('%s', '%s', '%s')",\
1411 sp->appid, df->path, al->text);
1412 ret = __exec_query(query);
1414 DBG("Package App Share Allowed DB Insert Failed\n");
1417 memset(query, '\0', MAX_QUERY_LEN);
1429 static int __insert_manifest_info_in_db(manifest_x *mfx)
1431 label_x *lbl = mfx->label;
1432 license_x *lcn = mfx->license;
1433 icon_x *icn = mfx->icon;
1434 description_x *dcn = mfx->description;
1435 author_x *ath = mfx->author;
1436 uiapplication_x *up = mfx->uiapplication;
1437 uiapplication_x *up_icn = mfx->uiapplication;
1438 uiapplication_x *up_image = mfx->uiapplication;
1439 serviceapplication_x *sp = mfx->serviceapplication;
1440 privileges_x *pvs = NULL;
1441 privilege_x *pv = NULL;
1442 char query[MAX_QUERY_LEN] = { '\0' };
1446 const char *auth_name = NULL;
1447 const char *auth_email = NULL;
1448 const char *auth_href = NULL;
1451 auth_name = ath->text;
1453 auth_email = ath->email;
1455 auth_href = ath->href;
1458 /*Insert in the package_info DB*/
1460 type = strdup(mfx->type);
1462 type = strdup("rpm");
1463 /*Insert in the package_info DB*/
1465 path = strdup(mfx->root_path);
1467 if (strcmp(type,"rpm")==0)
1468 path = strdup("/usr/apps");
1470 path = strdup("/opt/usr/apps");
1472 snprintf(query, MAX_QUERY_LEN,
1473 "insert into package_info(package, package_type, package_version, install_location, package_size, " \
1474 "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) " \
1475 "values('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",\
1476 mfx->package, type, mfx->version, mfx->installlocation, mfx->package_size, mfx->removable, mfx->preload,
1477 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);
1478 ret = __exec_query(query);
1480 DBG("Package Info DB Insert Failed\n");
1500 /*Insert in the package_privilege_info DB*/
1501 pvs = mfx->privileges;
1502 while (pvs != NULL) {
1503 pv = pvs->privilege;
1504 while (pv != NULL) {
1505 memset(query, '\0', MAX_QUERY_LEN);
1506 snprintf(query, MAX_QUERY_LEN,
1507 "insert into package_privilege_info(package, privilege) " \
1508 "values('%s','%s')",\
1509 mfx->package, pv->text);
1510 ret = __exec_query(query);
1512 DBG("Package Privilege Info DB Insert Failed\n");
1520 /*Insert the package locale and app locale info */
1521 pkglocale = __create_locale_list(pkglocale, lbl, lcn, icn, dcn, ath);
1522 g_list_foreach(pkglocale, __trimfunc1, NULL);
1527 applocale = __create_locale_list(applocale, up->label, NULL, up->icon, NULL, NULL);
1532 applocale = __create_locale_list(applocale, sp->label, NULL, sp->icon, NULL, NULL);
1535 g_list_foreach(applocale, __trimfunc2, NULL);
1538 /*Insert the app icon info */
1539 while(up_icn != NULL)
1541 appicon = __create_icon_list(appicon, up_icn->icon);
1542 up_icn = up_icn->next;
1544 g_list_foreach(appicon, __trimfunc3, NULL);
1547 /*Insert the image info */
1548 while(up_image != NULL)
1550 appimage = __create_image_list(appimage, up_image->image);
1551 up_image = up_image->next;
1553 g_list_foreach(appimage, __trimfunc4, NULL);
1556 /*g_list_foreach(pkglocale, __printfunc, NULL);*/
1558 /*g_list_foreach(applocale, __printfunc, NULL);*/
1560 /*package locale info*/
1561 g_list_foreach(pkglocale, __insert_pkglocale_info, (gpointer)mfx);
1562 /*native app locale info*/
1563 up = mfx->uiapplication;
1566 g_list_foreach(applocale, __insert_uiapplication_locale_info, (gpointer)up);
1569 /*agent app locale info*/
1570 sp = mfx->serviceapplication;
1573 g_list_foreach(applocale, __insert_serviceapplication_locale_info, (gpointer)sp);
1577 /*app icon locale info*/
1578 up_icn = mfx->uiapplication;
1579 while(up_icn != NULL)
1581 g_list_foreach(appicon, __insert_uiapplication_icon_section_info, (gpointer)up_icn);
1582 up_icn = up_icn->next;
1586 up_image = mfx->uiapplication;
1587 while(up_image != NULL)
1589 g_list_foreach(appimage, __insert_uiapplication_image_info, (gpointer)up_image);
1590 up_image = up_image->next;
1593 g_list_free(pkglocale);
1595 g_list_free(applocale);
1597 g_list_free(appicon);
1599 g_list_free(appimage);
1603 /*Insert in the package_app_info DB*/
1604 ret = __insert_uiapplication_info(mfx);
1607 ret = __insert_ui_mainapp_info(mfx);
1610 ret = __insert_serviceapplication_info(mfx);
1614 /*Insert in the package_app_app_control DB*/
1615 ret = __insert_uiapplication_appcontrol_info(mfx);
1618 ret = __insert_serviceapplication_appcontrol_info(mfx);
1622 /*Insert in the package_app_app_category DB*/
1623 ret = __insert_uiapplication_appcategory_info(mfx);
1626 ret = __insert_serviceapplication_appcategory_info(mfx);
1630 /*Insert in the package_app_app_metadata DB*/
1631 ret = __insert_uiapplication_appmetadata_info(mfx);
1634 ret = __insert_serviceapplication_appmetadata_info(mfx);
1638 /*Insert in the package_app_app_permission DB*/
1639 ret = __insert_uiapplication_apppermission_info(mfx);
1642 ret = __insert_serviceapplication_apppermission_info(mfx);
1646 /*Insert in the package_app_app_svc DB*/
1647 ret = __insert_uiapplication_appsvc_info(mfx);
1650 ret = __insert_serviceapplication_appsvc_info(mfx);
1654 /*Insert in the package_app_share_allowed DB*/
1655 ret = __insert_uiapplication_share_allowed_info(mfx);
1658 ret = __insert_serviceapplication_share_allowed_info(mfx);
1662 /*Insert in the package_app_share_request DB*/
1663 ret = __insert_uiapplication_share_request_info(mfx);
1666 ret = __insert_serviceapplication_share_request_info(mfx);
1674 static int __delete_appinfo_from_db(char *db_table, const char *appid)
1676 char query[MAX_QUERY_LEN] = { '\0' };
1678 memset(query, '\0', MAX_QUERY_LEN);
1679 snprintf(query, MAX_QUERY_LEN,
1680 "delete from %s where app_id='%s'", db_table, appid);
1681 ret = __exec_query(query);
1683 DBG("DB Deletion from table (%s) Failed\n", db_table);
1689 static int __delete_manifest_info_from_db(manifest_x *mfx)
1691 char query[MAX_QUERY_LEN] = { '\0' };
1693 uiapplication_x *up = mfx->uiapplication;
1694 serviceapplication_x *sp = mfx->serviceapplication;
1695 /*Delete from cert table*/
1696 ret = pkgmgrinfo_delete_certinfo(mfx->package);
1698 DBG("Cert Info DB Delete Failed\n");
1702 /*Delete from Package Info DB*/
1703 snprintf(query, MAX_QUERY_LEN,
1704 "delete from package_info where package='%s'", mfx->package);
1705 ret = __exec_query(query);
1707 DBG("Package Info DB Delete Failed\n");
1710 memset(query, '\0', MAX_QUERY_LEN);
1712 /*Delete from Package Localized Info*/
1713 snprintf(query, MAX_QUERY_LEN,
1714 "delete from package_localized_info where package='%s'", mfx->package);
1715 ret = __exec_query(query);
1717 DBG("Package Localized Info DB Delete Failed\n");
1721 /*Delete from Package Privilege Info*/
1722 snprintf(query, MAX_QUERY_LEN,
1723 "delete from package_privilege_info where package='%s'", mfx->package);
1724 ret = __exec_query(query);
1726 DBG("Package Privilege Info DB Delete Failed\n");
1730 while (up != NULL) {
1731 ret = __delete_appinfo_from_db("package_app_info", up->appid);
1734 ret = __delete_appinfo_from_db("package_app_localized_info", up->appid);
1737 ret = __delete_appinfo_from_db("package_app_icon_section_info", up->appid);
1740 ret = __delete_appinfo_from_db("package_app_image_info", up->appid);
1743 ret = __delete_appinfo_from_db("package_app_app_svc", up->appid);
1746 ret = __delete_appinfo_from_db("package_app_app_control", up->appid);
1749 ret = __delete_appinfo_from_db("package_app_app_category", up->appid);
1752 ret = __delete_appinfo_from_db("package_app_app_metadata", up->appid);
1755 ret = __delete_appinfo_from_db("package_app_app_permission", up->appid);
1758 ret = __delete_appinfo_from_db("package_app_share_allowed", up->appid);
1761 ret = __delete_appinfo_from_db("package_app_share_request", up->appid);
1767 while (sp != NULL) {
1768 ret = __delete_appinfo_from_db("package_app_info", sp->appid);
1771 ret = __delete_appinfo_from_db("package_app_localized_info", sp->appid);
1774 ret = __delete_appinfo_from_db("package_app_icon_section_info", sp->appid);
1777 ret = __delete_appinfo_from_db("package_app_image_info", sp->appid);
1780 ret = __delete_appinfo_from_db("package_app_app_svc", sp->appid);
1783 ret = __delete_appinfo_from_db("package_app_app_control", sp->appid);
1786 ret = __delete_appinfo_from_db("package_app_app_category", sp->appid);
1789 ret = __delete_appinfo_from_db("package_app_app_metadata", sp->appid);
1792 ret = __delete_appinfo_from_db("package_app_app_permission", sp->appid);
1795 ret = __delete_appinfo_from_db("package_app_share_allowed", sp->appid);
1798 ret = __delete_appinfo_from_db("package_app_share_request", sp->appid);
1807 int pkgmgr_parser_initialize_db()
1811 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_INFO);
1813 DBG("package info DB initialization failed\n");
1816 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO);
1818 DBG("package localized info DB initialization failed\n");
1821 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO);
1823 DBG("package app app privilege DB initialization failed\n");
1826 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_INFO);
1828 DBG("package app info DB initialization failed\n");
1831 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO);
1833 DBG("package app localized info DB initialization failed\n");
1836 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO);
1838 DBG("package app icon localized info DB initialization failed\n");
1841 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO);
1843 DBG("package app image info DB initialization failed\n");
1846 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL);
1848 DBG("package app app control DB initialization failed\n");
1851 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY);
1853 DBG("package app app category DB initialization failed\n");
1856 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA);
1858 DBG("package app app category DB initialization failed\n");
1861 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION);
1863 DBG("package app app permission DB initialization failed\n");
1866 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_SVC);
1868 DBG("package app app svc DB initialization failed\n");
1871 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED);
1873 DBG("package app share allowed DB initialization failed\n");
1876 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST);
1878 DBG("package app share request DB initialization failed\n");
1882 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INFO);
1884 DBG("package cert info DB initialization failed\n");
1887 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO);
1889 DBG("package cert index info DB initialization failed\n");
1895 int pkgmgr_parser_check_and_create_db()
1899 ret = __pkgmgr_parser_create_db(&pkgmgr_parser_db, PKGMGR_PARSER_DB_FILE);
1901 DBG("Manifest DB creation Failed\n");
1905 ret = __pkgmgr_parser_create_db(&pkgmgr_cert_db, PKGMGR_CERT_DB_FILE);
1907 DBG("Cert DB creation Failed\n");
1913 API int pkgmgr_parser_insert_manifest_info_in_db(manifest_x *mfx)
1916 DBG("manifest pointer is NULL\n");
1920 ret = pkgmgr_parser_check_and_create_db();
1922 DBG("Failed to open DB\n");
1925 ret = pkgmgr_parser_initialize_db();
1928 /*Begin transaction*/
1929 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
1930 if (ret != SQLITE_OK) {
1931 DBG("Failed to begin transaction\n");
1935 DBG("Transaction Begin\n");
1936 ret = __insert_manifest_info_in_db(mfx);
1938 DBG("Insert into DB failed. Rollback now\n");
1939 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
1942 /*Commit transaction*/
1943 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
1944 if (ret != SQLITE_OK) {
1945 DBG("Failed to commit transaction. Rollback now\n");
1946 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
1950 DBG("Transaction Commit and End\n");
1952 sqlite3_close(pkgmgr_parser_db);
1953 sqlite3_close(pkgmgr_cert_db);
1957 API int pkgmgr_parser_update_manifest_info_in_db(manifest_x *mfx)
1960 DBG("manifest pointer is NULL\n");
1964 ret = pkgmgr_parser_check_and_create_db();
1966 DBG("Failed to open DB\n");
1969 ret = pkgmgr_parser_initialize_db();
1972 /*Preserve guest mode visibility*/
1973 __preserve_guestmode_visibility_value( mfx);
1974 /*Begin transaction*/
1975 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
1976 if (ret != SQLITE_OK) {
1977 DBG("Failed to begin transaction\n");
1981 DBG("Transaction Begin\n");
1982 ret = __delete_manifest_info_from_db(mfx);
1984 DBG("Delete from DB failed. Rollback now\n");
1985 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
1988 ret = __insert_manifest_info_in_db(mfx);
1990 DBG("Insert into DB failed. Rollback now\n");
1991 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
1995 /*Commit transaction*/
1996 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
1997 if (ret != SQLITE_OK) {
1998 DBG("Failed to commit transaction. Rollback now\n");
1999 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2003 DBG("Transaction Commit and End\n");
2005 sqlite3_close(pkgmgr_parser_db);
2006 sqlite3_close(pkgmgr_cert_db);
2010 API int pkgmgr_parser_delete_manifest_info_from_db(manifest_x *mfx)
2013 DBG("manifest pointer is NULL\n");
2017 ret = pkgmgr_parser_check_and_create_db();
2019 DBG("Failed to open DB\n");
2022 /*Begin transaction*/
2023 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2024 if (ret != SQLITE_OK) {
2025 DBG("Failed to begin transaction\n");
2029 DBG("Transaction Begin\n");
2030 ret = __delete_manifest_info_from_db(mfx);
2032 DBG("Delete from DB failed. Rollback now\n");
2033 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2036 /*Commit transaction*/
2037 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2038 if (ret != SQLITE_OK) {
2039 DBG("Failed to commit transaction, Rollback now\n");
2040 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2044 DBG("Transaction Commit and End\n");
2045 sqlite3_close(pkgmgr_parser_db);
2047 sqlite3_close(pkgmgr_parser_db);
2048 sqlite3_close(pkgmgr_cert_db);