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>
33 #include "pkgmgr_parser_internal.h"
34 #include "pkgmgr_parser_db.h"
36 #include "pkgmgrinfo_debug.h"
37 #include "pkgmgrinfo_type.h"
42 #define LOG_TAG "PKGMGR_PARSER"
44 #define MAX_QUERY_LEN 4096
45 #define MAX_PACKAGE_STR_SIZE 512
46 #define MAX_ALIAS_INI_ENTRY (2 * MAX_PACKAGE_STR_SIZE) + 1
47 #define USR_APPSVC_ALIAS_INI "/usr/share/appsvc/alias.ini"
48 #define OPT_APPSVC_ALIAS_INI "/opt/usr/share/appsvc/alias.ini"
49 #define MANIFEST_DB "/opt/dbspace/.pkgmgr_parser.db"
50 typedef int (*sqlite_query_callback)(void *data, int ncols, char **coltxt, char **colname);
52 sqlite3 *pkgmgr_parser_db;
53 sqlite3 *pkgmgr_cert_db;
56 #define QUERY_CREATE_TABLE_PACKAGE_INFO "create table if not exists package_info " \
57 "(package text primary key not null, " \
58 "package_type text DEFAULT 'rpm', " \
59 "package_version text, " \
60 "install_location text, " \
61 "package_size text, " \
62 "package_removable text DEFAULT 'true', " \
63 "package_preload text DEFAULT 'false', " \
64 "package_readonly text DEFAULT 'false', " \
65 "package_update text DEFAULT 'false', " \
66 "package_appsetting text DEFAULT 'false', " \
67 "package_nodisplay text DEFAULT 'false', " \
68 "package_system text DEFAULT 'false', " \
69 "author_name text, " \
70 "author_email text, " \
72 "installed_time text," \
73 "installed_storage text," \
74 "storeclient_id text," \
79 "package_support_disable text DEFAULT 'false', " \
80 "package_mother_package text DEFAULT 'false', " \
81 "package_disable text DEFAULT 'false', " \
82 "package_support_mode text, " \
83 "package_hash text, " \
84 "package_reserve1 text," \
85 "package_reserve2 text," \
86 "package_reserve3 text," \
87 "package_reserve4 text," \
88 "package_reserve5 text)"
90 #define QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO "create table if not exists package_localized_info " \
91 "(package text not null, " \
92 "package_locale text DEFAULT 'No Locale', " \
93 "package_label text, " \
94 "package_icon text, " \
95 "package_description text, " \
96 "package_license text, " \
98 "PRIMARY KEY(package, package_locale), " \
99 "FOREIGN KEY(package) " \
100 "REFERENCES package_info(package) " \
103 #define QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO "create table if not exists package_privilege_info " \
104 "(package text not null, " \
105 "privilege text not null, " \
106 "PRIMARY KEY(package, privilege) " \
107 "FOREIGN KEY(package) " \
108 "REFERENCES package_info(package) " \
111 #define QUERY_CREATE_TABLE_PACKAGE_APP_INFO "create table if not exists package_app_info " \
112 "(app_id text primary key not null, " \
113 "app_component text, " \
115 "app_nodisplay text DEFAULT 'false', " \
117 "app_onboot text DEFAULT 'false', " \
118 "app_multiple text DEFAULT 'false', " \
119 "app_autorestart text DEFAULT 'false', " \
120 "app_taskmanage text DEFAULT 'false', " \
121 "app_enabled text DEFAULT 'true', " \
122 "app_hwacceleration text DEFAULT 'use-system-setting', " \
123 "app_screenreader text DEFAULT 'use-system-setting', " \
124 "app_mainapp text, " \
125 "app_recentimage text, " \
126 "app_launchcondition text, " \
127 "app_indicatordisplay text DEFAULT 'true', " \
128 "app_portraitimg text, " \
129 "app_landscapeimg text, " \
130 "app_effectimage_type text, " \
131 "app_guestmodevisibility text DEFAULT 'true', " \
132 "app_permissiontype text DEFAULT 'normal', " \
133 "app_preload text DEFAULT 'false', " \
134 "app_submode text DEFAULT 'false', " \
135 "app_submode_mainid text, " \
136 "app_installed_storage text, " \
137 "app_process_pool text DEFAULT 'false', " \
138 "app_multi_instance text DEFAULT 'false', " \
139 "app_multi_instance_mainid text, " \
140 "app_multi_window text DEFAULT 'false', " \
141 "app_support_disable text DEFAULT 'false', " \
142 "app_disable text DEFAULT 'false', " \
143 "app_ui_gadget text DEFAULT 'false', " \
144 "app_removable text DEFAULT 'false', " \
145 "app_support_mode text, " \
146 "app_support_feature text, " \
147 "component_type text, " \
148 "package text not null, " \
149 "app_package_type text DEFAULT 'rpm', " \
150 "app_package_system text, " \
151 "app_package_installed_time text, " \
152 "app_reserve1 text, " \
153 "app_reserve2 text, " \
154 "app_reserve3 text, " \
155 "app_reserve4 text, " \
156 "app_reserve5 text, " \
157 "FOREIGN KEY(package) " \
158 "REFERENCES package_info(package) " \
161 #define QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO "create table if not exists package_app_localized_info " \
162 "(app_id text not null, " \
163 "app_locale text DEFAULT 'No Locale', " \
166 "PRIMARY KEY(app_id,app_locale) " \
167 "FOREIGN KEY(app_id) " \
168 "REFERENCES package_app_info(app_id) " \
171 #define QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO "create table if not exists package_app_icon_section_info " \
172 "(app_id text not null, " \
174 "app_icon_section text, " \
175 "app_icon_resolution text, " \
176 "PRIMARY KEY(app_id,app_icon_section,app_icon_resolution) " \
177 "FOREIGN KEY(app_id) " \
178 "REFERENCES package_app_info(app_id) " \
181 #define QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO "create table if not exists package_app_image_info " \
182 "(app_id text not null, " \
183 "app_locale text DEFAULT 'No Locale', " \
184 "app_image_section text, " \
186 "PRIMARY KEY(app_id,app_image_section) " \
187 "FOREIGN KEY(app_id) " \
188 "REFERENCES package_app_info(app_id) " \
191 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL "create table if not exists package_app_app_control " \
192 "(app_id text not null, " \
193 "app_control text not null, " \
194 "PRIMARY KEY(app_id,app_control) " \
195 "FOREIGN KEY(app_id) " \
196 "REFERENCES package_app_info(app_id) " \
199 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_SVC "create table if not exists package_app_app_svc " \
200 "(app_id text not null, " \
201 "operation text not null, " \
202 "uri_scheme text, " \
204 "subapp_name text, " \
205 "PRIMARY KEY(app_id,operation,uri_scheme,mime_type,subapp_name) " \
206 "FOREIGN KEY(app_id) " \
207 "REFERENCES package_app_info(app_id) " \
210 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY "create table if not exists package_app_app_category " \
211 "(app_id text not null, " \
212 "category text not null, " \
213 "PRIMARY KEY(app_id,category) " \
214 "FOREIGN KEY(app_id) " \
215 "REFERENCES package_app_info(app_id) " \
218 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA "create table if not exists package_app_app_metadata " \
219 "(app_id text not null, " \
220 "md_key text not null, " \
221 "md_value text not null, " \
222 "PRIMARY KEY(app_id, md_key, md_value) " \
223 "FOREIGN KEY(app_id) " \
224 "REFERENCES package_app_info(app_id) " \
227 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION "create table if not exists package_app_app_permission " \
228 "(app_id text not null, " \
229 "pm_type text not null, " \
230 "pm_value text not null, " \
231 "PRIMARY KEY(app_id, pm_type, pm_value) " \
232 "FOREIGN KEY(app_id) " \
233 "REFERENCES package_app_info(app_id) " \
236 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED "create table if not exists package_app_share_allowed " \
237 "(app_id text not null, " \
238 "data_share_path text not null, " \
239 "data_share_allowed text not null, " \
240 "PRIMARY KEY(app_id,data_share_path,data_share_allowed) " \
241 "FOREIGN KEY(app_id) " \
242 "REFERENCES package_app_info(app_id) " \
245 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST "create table if not exists package_app_share_request " \
246 "(app_id text not null, " \
247 "data_share_request text not null, " \
248 "PRIMARY KEY(app_id,data_share_request) " \
249 "FOREIGN KEY(app_id) " \
250 "REFERENCES package_app_info(app_id) " \
253 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO "create table if not exists package_cert_index_info " \
254 "(cert_info text not null, " \
255 "cert_id integer, " \
256 "cert_ref_count integer, " \
257 "PRIMARY KEY(cert_id)) "
259 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INFO "create table if not exists package_cert_info " \
260 "(package text not null, " \
261 "author_root_cert integer, " \
262 "author_im_cert integer, " \
263 "author_signer_cert integer, " \
264 "dist_root_cert integer, " \
265 "dist_im_cert integer, " \
266 "dist_signer_cert integer, " \
267 "dist2_root_cert integer, " \
268 "dist2_im_cert integer, " \
269 "dist2_signer_cert integer, " \
270 "PRIMARY KEY(package)) "
272 #define QUERY_CREATE_TABLE_PACKAGE_PKG_RESERVE "create table if not exists package_pkg_reserve " \
273 "(pkgid text not null, " \
279 "PRIMARY KEY(pkgid)) "
281 #define QUERY_CREATE_TABLE_PACKAGE_APP_RESERVE "create table if not exists package_app_reserve " \
282 "(app_id text not null, " \
288 "PRIMARY KEY(app_id)) "
290 #define QUERY_CREATE_TABLE_PACKAGE_PLUGIN_INFO "create table if not exists package_plugin_info " \
291 "(pkgid text primary key not null, " \
292 "enabled_plugin INTEGER DEFAULT 0)"
294 #define QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL "create table if not exists package_app_data_control " \
295 "(app_id text not null, " \
296 "providerid text not null, " \
297 "access text not null, " \
298 "type text not null, " \
299 "PRIMARY KEY(app_id, providerid, access, type) " \
300 "FOREIGN KEY(app_id) " \
301 "REFERENCES package_app_info(app_id) " \
304 #define QUERY_CREATE_TABLE_PACKAGE_APP_ALIASID "create table if not exists package_app_aliasid" \
305 "(app_id text primary key not null, "\
306 "alias_id text not null)"
308 static int __insert_uiapplication_info(manifest_x *mfx);
309 static int __insert_uiapplication_appsvc_info(manifest_x *mfx);
310 static int __insert_uiapplication_appcategory_info(manifest_x *mfx);
311 static int __insert_uiapplication_appcontrol_info(manifest_x *mfx);
312 static int __insert_uiapplication_appmetadata_info(manifest_x *mfx);
313 static int __insert_uiapplication_share_allowed_info(manifest_x *mfx);
314 static int __insert_uiapplication_share_request_info(manifest_x *mfx);
315 static void __insert_uiapplication_locale_info(gpointer data, gpointer userdata);
316 static int __insert_uiapplication_datacontrol_info(manifest_x *mfx);
317 static void __insert_pkglocale_info(gpointer data, gpointer userdata);
318 static int __delete_manifest_info_from_pkgid(const char *pkgid);
319 static int __delete_manifest_info_from_appid(const char *appid);
320 static int __insert_manifest_info_in_db(manifest_x *mfx);
321 static int __delete_manifest_info_from_db(manifest_x *mfx);
322 static int __delete_appinfo_from_db(char *db_table, const char *appid);
323 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata);
324 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path);
326 static void __str_trim(char *input)
328 char *trim_str = input;
333 while (*input != 0) {
334 if (!isspace(*input)) {
345 const char *__get_str(const char *str)
349 return PKGMGR_PARSER_EMPTY_STR;
355 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path)
359 if (access(db_path, F_OK) == 0) {
361 db_util_open(db_path, &handle,
362 DB_UTIL_REGISTER_HOOK_METHOD);
363 if (ret != SQLITE_OK) {
364 _LOGD("connect db [%s] failed!\n",
371 _LOGD("%s DB does not exists. Create one!!\n", db_path);
374 db_util_open(db_path, &handle,
375 DB_UTIL_REGISTER_HOOK_METHOD);
377 if (ret != SQLITE_OK) {
378 _LOGD("connect db [%s] failed!\n", db_path);
385 int __evaluate_query(sqlite3 *db_handle, char *query)
387 sqlite3_stmt* p_statement;
389 result = sqlite3_prepare_v2(db_handle, query, strlen(query), &p_statement, NULL);
390 if (result != SQLITE_OK) {
391 _LOGE("Sqlite3 error [%d] : <%s> preparing <%s> querry\n", result, sqlite3_errmsg(db_handle), query);
395 result = sqlite3_step(p_statement);
396 if (result != SQLITE_DONE) {
397 _LOGE("Sqlite3 error [%d] : <%s> executing <%s> statement\n", result, sqlite3_errmsg(db_handle), query);
401 result = sqlite3_finalize(p_statement);
402 if (result != SQLITE_OK) {
403 _LOGE("Sqlite3 error [%d] : <%s> finalizing <%s> statement\n", result, sqlite3_errmsg(db_handle), query);
409 int __initialize_db(sqlite3 *db_handle, char *db_query)
411 return (__evaluate_query(db_handle, db_query));
414 int __exec_query(char *query)
416 return (__evaluate_query(pkgmgr_parser_db, query));
419 int __exec_query_no_msg(char *query)
421 char *error_message = NULL;
423 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
424 sqlite3_free(error_message);
427 sqlite3_free(error_message);
431 static int __exec_db_query(sqlite3 *db, char *query, sqlite_query_callback callback, void *data)
433 char *error_message = NULL;
435 sqlite3_exec(db, query, callback, data, &error_message)) {
436 _LOGE("Don't execute query = %s error message = %s\n", query,
438 sqlite3_free(error_message);
441 sqlite3_free(error_message);
445 GList *__create_locale_list(GList *locale, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath)
451 locale = g_list_insert_sorted_with_data(locale, (gpointer)lbl->lang, __comparefunc, NULL);
457 locale = g_list_insert_sorted_with_data(locale, (gpointer)lcn->lang, __comparefunc, NULL);
463 locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->lang, __comparefunc, NULL);
469 locale = g_list_insert_sorted_with_data(locale, (gpointer)dcn->lang, __comparefunc, NULL);
475 locale = g_list_insert_sorted_with_data(locale, (gpointer)ath->lang, __comparefunc, NULL);
482 static GList *__create_icon_list(GList *locale, icon_x *icn)
487 locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->section, __comparefunc, NULL);
493 static GList *__create_image_list(GList *locale, image_x *image)
498 locale = g_list_insert_sorted_with_data(locale, (gpointer)image->section, __comparefunc, NULL);
504 void __trimfunc(GList* trim_list)
506 char *trim_data = NULL;
510 list = g_list_first(trim_list);
513 trim_data = (char *)list->data;
516 if (strcmp(trim_data, prev) == 0) {
517 trim_list = g_list_remove(trim_list, trim_data);
518 list = g_list_first(trim_list);
527 list = g_list_next(list);
531 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata)
533 if (a == NULL || b == NULL)
535 if (strcmp((char*)a, (char*)b) == 0)
537 if (strcmp((char*)a, (char*)b) < 0)
539 if (strcmp((char*)a, (char*)b) > 0)
544 void __extract_data(gpointer data, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath,
545 char **label, char **license, char **icon, char **description, char **author)
550 if (strcmp(lbl->lang, (char *)data) == 0) {
551 *label = (char*)lbl->text;
560 if (strcmp(lcn->lang, (char *)data) == 0) {
561 *license = (char*)lcn->text;
569 if (icn->section == NULL) {
571 if (strcmp(icn->lang, (char *)data) == 0) {
572 *icon = (char*)icn->text;
582 if (strcmp(dcn->lang, (char *)data) == 0) {
583 *description = (char*)dcn->text;
592 if (strcmp(ath->lang, (char *)data) == 0) {
593 *author = (char*)ath->text;
602 static void __extract_icon_data(gpointer data, icon_x *icn, char **icon, char **resolution)
607 if (strcmp(icn->section, (char *)data) == 0) {
608 *icon = (char*)icn->text;
609 *resolution = (char*)icn->resolution;
617 static void __extract_image_data(gpointer data, image_x*image, char **lang, char **img)
621 if (image->section) {
622 if (strcmp(image->section, (char *)data) == 0) {
623 *lang = (char*)image->lang;
624 *img = (char*)image->text;
632 static void __insert_pkglocale_info(gpointer data, gpointer userdata)
637 char *description = NULL;
638 char *license = NULL;
642 manifest_x *mfx = (manifest_x *)userdata;
643 label_x *lbl = mfx->label;
644 license_x *lcn = mfx->license;
645 icon_x *icn = mfx->icon;
646 description_x *dcn = mfx->description;
647 author_x *ath = mfx->author;
649 __extract_data(data, lbl, lcn, icn, dcn, ath, &label, &license, &icon, &description, &author);
650 if (!label && !description && !icon && !license && !author)
653 query = sqlite3_mprintf("insert into package_localized_info(package, package_locale, " \
654 "package_label, package_icon, package_description, package_license, package_author) values " \
655 "(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
660 __get_str(description),
664 ret = __exec_query(query);
666 _LOGD("Package Localized Info DB Insert failed\n");
671 static int __insert_uiapplication_datacontrol_info(manifest_x *mfx)
673 uiapplication_x *up = mfx->uiapplication;
674 datacontrol_x *dc = NULL;
680 dc = up->datacontrol;
682 query = sqlite3_mprintf("insert into package_app_data_control(app_id, providerid, access, type) " \
683 "values(%Q, %Q, %Q, %Q)", \
689 ret = __exec_query(query);
692 _LOGD("Package UiApp Data Control DB Insert Failed\n");
702 static void __insert_uiapplication_locale_info(gpointer data, gpointer userdata)
709 uiapplication_x *up = (uiapplication_x*)userdata;
710 label_x *lbl = up->label;
711 icon_x *icn = up->icon;
713 __extract_data(data, lbl, NULL, icn, NULL, NULL, &label, NULL, &icon, NULL, NULL);
717 query = sqlite3_mprintf("insert into package_app_localized_info(app_id, app_locale, " \
718 "app_label, app_icon) values " \
719 "(%Q, %Q, %Q, %Q)", up->appid, (char*)data,
720 __get_str(label), __get_str(icon));
721 ret = __exec_query(query);
723 _LOGD("Package UiApp Localized Info DB Insert failed\n");
727 /*insert ui app locale info to pkg locale to get mainapp data */
728 if (strcasecmp(up->mainapp, "true")==0) {
729 char *update_query = NULL;
730 update_query = sqlite3_mprintf("insert into package_localized_info(package, package_locale, " \
731 "package_label, package_icon, package_description, package_license, package_author) values " \
732 "(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
737 PKGMGR_PARSER_EMPTY_STR,
738 PKGMGR_PARSER_EMPTY_STR,
739 PKGMGR_PARSER_EMPTY_STR);
741 ret = __exec_query_no_msg(update_query);
742 sqlite3_free(update_query);
745 update_query = sqlite3_mprintf("update package_localized_info set package_icon=%Q " \
746 "where package=%Q and package_locale=%Q", icon, up->package, (char*)data);
747 ret = __exec_query_no_msg(update_query);
748 sqlite3_free(update_query);
753 static void __insert_uiapplication_icon_section_info(gpointer data, gpointer userdata)
757 char *resolution = NULL;
760 uiapplication_x *up = (uiapplication_x*)userdata;
761 icon_x *icn = up->icon;
763 __extract_icon_data(data, icn, &icon, &resolution);
764 if (!icon && !resolution)
767 query = sqlite3_mprintf("insert into package_app_icon_section_info(app_id, " \
768 "app_icon, app_icon_section, app_icon_resolution) values " \
769 "(%Q, %Q, %Q, %Q)", up->appid,
770 icon, (char*)data, resolution);
772 ret = __exec_query(query);
774 _LOGD("Package UiApp Localized Info DB Insert failed\n");
779 static void __insert_uiapplication_image_info(gpointer data, gpointer userdata)
786 uiapplication_x *up = (uiapplication_x*)userdata;
787 image_x *image = up->image;
789 __extract_image_data(data, image, &lang, &img);
793 query = sqlite3_mprintf("insert into package_app_image_info(app_id, app_locale, " \
794 "app_image_section, app_image) values " \
795 "(%Q, %Q, %Q, %Q)", up->appid, lang, (char*)data, img);
797 ret = __exec_query(query);
799 _LOGD("Package UiApp image Info DB Insert failed\n");
804 static int __insert_ui_mainapp_info(manifest_x *mfx)
806 uiapplication_x *up = mfx->uiapplication;
811 query = sqlite3_mprintf("update package_app_info set app_mainapp=%Q where app_id=%Q", up->mainapp, up->appid);
813 ret = __exec_query(query);
816 _LOGD("Package UiApp Info DB Insert Failed\n");
819 if (strcasecmp(up->mainapp, "True")==0)
820 mfx->mainapp_id = strdup(up->appid);
825 if (mfx->mainapp_id == NULL){
826 if (mfx->uiapplication && mfx->uiapplication->appid) {
827 query = sqlite3_mprintf("update package_app_info set app_mainapp='true' where app_id=%Q", mfx->uiapplication->appid);
829 _LOGD("Not valid appid\n");
833 ret = __exec_query(query);
836 _LOGD("Package UiApp Info DB Insert Failed\n");
840 FREE_AND_NULL(mfx->uiapplication->mainapp);
841 mfx->uiapplication->mainapp= strdup("true");
842 mfx->mainapp_id = strdup(mfx->uiapplication->appid);
845 query = sqlite3_mprintf("update package_info set mainapp_id=%Q where package=%Q", mfx->mainapp_id, mfx->package);
846 ret = __exec_query(query);
849 _LOGD("Package Info DB update Failed\n");
855 /* _PRODUCT_LAUNCHING_ENHANCED_
856 * up->indicatordisplay, up->portraitimg, up->landscapeimg, up->guestmode_appstatus
858 static int __insert_uiapplication_info(manifest_x *mfx)
860 uiapplication_x *up = mfx->uiapplication;
866 type = strdup(mfx->type);
868 type = strdup("rpm");
872 query = sqlite3_mprintf("insert into package_app_info(app_id, app_component, app_exec, app_nodisplay, app_type, app_onboot, " \
873 "app_multiple, app_autorestart, app_taskmanage, app_enabled, app_hwacceleration, app_screenreader, app_mainapp , app_recentimage, " \
874 "app_launchcondition, app_indicatordisplay, app_portraitimg, app_landscapeimg, app_effectimage_type, app_guestmodevisibility, app_permissiontype, "\
875 "app_preload, app_submode, app_submode_mainid, app_installed_storage, app_process_pool, app_multi_instance, app_multi_instance_mainid, app_multi_window, app_support_disable, "\
876 "app_ui_gadget, app_removable, app_support_mode, app_support_feature, component_type, package, "\
877 "app_package_type, app_package_system, app_package_installed_time"\
879 "values(%Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q)",\
893 __get_str(up->recentimage),
895 up->indicatordisplay,
896 __get_str(up->portraitimg),
897 __get_str(up->landscapeimg),
898 __get_str(up->effectimage_type),
899 up->guestmode_visibility,
903 __get_str(up->submode_mainid),
904 mfx->installed_storage,
907 __get_str(up->multi_instance_mainid),
909 mfx->support_disable,
921 ret = __exec_query(query);
924 _LOGD("Package UiApp Info DB Insert Failed\n");
934 static int __insert_uiapplication_appcategory_info(manifest_x *mfx)
936 uiapplication_x *up = mfx->uiapplication;
937 category_x *ct = NULL;
945 query = sqlite3_mprintf("insert into package_app_app_category(app_id, category) " \
947 up->appid, ct->name);
948 ret = __exec_query(query);
951 _LOGD("Package UiApp Category Info DB Insert Failed\n");
961 static int __insert_uiapplication_appmetadata_info(manifest_x *mfx)
963 uiapplication_x *up = mfx->uiapplication;
964 metadata_x *md = NULL;
973 query = sqlite3_mprintf("insert into package_app_app_metadata(app_id, md_key, md_value) " \
974 "values(%Q, %Q, %Q)",\
975 up->appid, md->key, __get_str(md->value));
976 ret = __exec_query(query);
979 _LOGD("Package UiApp Metadata Info DB Insert Failed\n");
990 static int __insert_uiapplication_apppermission_info(manifest_x *mfx)
992 uiapplication_x *up = mfx->uiapplication;
993 permission_x *pm = NULL;
1001 query = sqlite3_mprintf("insert into package_app_app_permission(app_id, pm_type, pm_value) " \
1002 "values(%Q, %Q, %Q)",\
1003 up->appid, pm->type, pm->value);
1004 ret = __exec_query(query);
1005 sqlite3_free(query);
1007 _LOGD("Package UiApp permission Info DB Insert Failed\n");
1017 static int __insert_uiapplication_appcontrol_info(manifest_x *mfx)
1021 char *buftemp = NULL;
1023 uiapplication_x *up = mfx->uiapplication;
1025 buf = (char *)calloc(1, BUFMAX);
1026 retvm_if(!buf, PMINFO_R_ERROR, "Malloc Failed\n");
1028 buftemp = (char *)calloc(1, BUFMAX);
1029 tryvm_if(!buftemp, ret = PMINFO_R_ERROR, "Malloc Failed\n");
1031 for(; up; up=up->next) {
1033 appsvc_x *asvc = NULL;
1034 operation_x *op = NULL;
1037 subapp_x *sub = NULL;
1038 const char *operation = NULL;
1039 const char *mime = NULL;
1040 const char *uri = NULL;
1041 const char *subapp = NULL;
1043 memset(buf, '\0', BUFMAX);
1044 memset(buftemp, '\0', BUFMAX);
1047 while(asvc != NULL) {
1048 op = asvc->operation;
1051 operation = op->name;
1070 strncpy(buftemp, buf, BUFMAX);
1071 snprintf(buf, BUFMAX, "%s;", buftemp);
1074 strncpy(buftemp, buf, BUFMAX);
1075 snprintf(buf, BUFMAX, "%s%s|%s|%s|%s", buftemp, operation?operation:"NULL", uri?uri:"NULL", mime?mime:"NULL", subapp?subapp:"NULL");
1076 // _LOGD("buf[%s]\n", buf);
1081 } while(ui != NULL);
1085 }while(sub != NULL);
1097 query= sqlite3_mprintf("insert into package_app_app_control(app_id, app_control) values(%Q, %Q)", up->appid, buf);
1098 ret = __exec_query(query);
1100 _LOGD("Package UiApp app_control DB Insert Failed\n");
1102 sqlite3_free(query);
1108 FREE_AND_NULL(buftemp);
1113 static int __insert_uiapplication_appsvc_info(manifest_x *mfx)
1115 uiapplication_x *up = mfx->uiapplication;
1116 appsvc_x *asvc = NULL;
1117 operation_x *op = NULL;
1120 subapp_x *sub = NULL;
1123 const char *operation = NULL;
1124 const char *mime = NULL;
1125 const char *uri = NULL;
1126 const char *subapp = NULL;
1132 op = asvc->operation;
1136 operation = op->name;
1153 query = sqlite3_mprintf("insert into package_app_app_svc(app_id, operation, uri_scheme, mime_type, subapp_name) " \
1154 "values(%Q, %Q, %Q, %Q, %Q)",\
1161 ret = __exec_query(query);
1162 sqlite3_free(query);
1164 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1170 } while(ui != NULL);
1174 }while(sub != NULL);
1190 static int __insert_uiapplication_share_request_info(manifest_x *mfx)
1192 uiapplication_x *up = mfx->uiapplication;
1193 datashare_x *ds = NULL;
1194 request_x *rq = NULL;
1205 query = sqlite3_mprintf("insert into package_app_share_request(app_id, data_share_request) " \
1207 up->appid, rq->text);
1208 ret = __exec_query(query);
1209 sqlite3_free(query);
1211 _LOGD("Package UiApp Share Request DB Insert Failed\n");
1223 static int __insert_uiapplication_share_allowed_info(manifest_x *mfx)
1225 uiapplication_x *up = mfx->uiapplication;
1226 datashare_x *ds = NULL;
1227 define_x *df = NULL;
1228 allowed_x *al = NULL;
1242 query = sqlite3_mprintf("insert into package_app_share_allowed(app_id, data_share_path, data_share_allowed) " \
1243 "values(%Q, %Q, %Q)",\
1244 up->appid, df->path, al->text);
1245 ret = __exec_query(query);
1246 sqlite3_free(query);
1248 _LOGD("Package UiApp Share Allowed DB Insert Failed\n");
1262 static int __insert_manifest_info_in_db(manifest_x *mfx)
1264 label_x *lbl = mfx->label;
1265 license_x *lcn = mfx->license;
1266 icon_x *icn = mfx->icon;
1267 description_x *dcn = mfx->description;
1268 author_x *ath = mfx->author;
1269 uiapplication_x *up = mfx->uiapplication;
1270 uiapplication_x *up_icn = mfx->uiapplication;
1271 uiapplication_x *up_image = mfx->uiapplication;
1272 privileges_x *pvs = NULL;
1273 privilege_x *pv = NULL;
1275 char root[MAX_QUERY_LEN] = { '\0' };
1279 const char *auth_name = NULL;
1280 const char *auth_email = NULL;
1281 const char *auth_href = NULL;
1283 GList *pkglocale = NULL;
1284 GList *applocale = NULL;
1285 GList *appicon = NULL;
1286 GList *appimage = NULL;
1290 auth_name = ath->text;
1292 auth_email = ath->email;
1294 auth_href = ath->href;
1297 /*Insert in the package_info DB*/
1299 type = strdup(mfx->type);
1301 type = strdup("rpm");
1302 /*Insert in the package_info DB*/
1303 if (mfx->root_path) {
1304 path = strdup(mfx->root_path);
1306 if (strcmp(type,"rpm")==0) {
1307 snprintf(root, MAX_QUERY_LEN - 1, "/opt/share/packages/%s.xml", mfx->package);
1308 if (access(root, F_OK) == 0) {
1309 memset(root, '\0', MAX_QUERY_LEN);
1310 snprintf(root, MAX_QUERY_LEN - 1, "/opt/usr/apps/%s", mfx->package);
1312 memset(root, '\0', MAX_QUERY_LEN);
1313 snprintf(root, MAX_QUERY_LEN - 1, "/usr/apps/%s", mfx->package);
1316 snprintf(root, MAX_QUERY_LEN - 1, "/opt/usr/apps/%s", mfx->package);
1319 path = strdup(root);
1322 query = sqlite3_mprintf("insert into package_info(package, package_type, package_version, install_location, package_size, " \
1323 "package_removable, package_preload, package_readonly, package_update, package_appsetting, package_nodisplay, package_system," \
1324 "author_name, author_email, author_href, installed_time, installed_storage, storeclient_id, mainapp_id, package_url, root_path, csc_path, package_support_disable, " \
1325 "package_mother_package, package_support_mode, package_reserve1, package_reserve2, package_hash) " \
1326 "values(%Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q)",\
1330 __get_str(mfx->installlocation),
1331 __get_str(mfx->package_size),
1337 mfx->nodisplay_setting,
1339 __get_str(auth_name),
1340 __get_str(auth_email),
1341 __get_str(auth_href),
1342 mfx->installed_time,
1343 mfx->installed_storage,
1344 __get_str(mfx->storeclient_id),
1346 __get_str(mfx->package_url),
1348 __get_str(mfx->csc_path),
1349 mfx->support_disable,
1350 mfx->mother_package,
1352 __get_str(mfx->support_reset),
1357 ret = __exec_query(query);
1358 sqlite3_free(query);
1360 _LOGD("Package Info DB Insert Failed\n");
1361 FREE_AND_NULL(type);
1362 FREE_AND_NULL(path);
1366 FREE_AND_NULL(type);
1367 FREE_AND_NULL(path);
1369 /*Insert in the package_privilege_info DB*/
1370 pvs = mfx->privileges;
1371 while (pvs != NULL) {
1372 pv = pvs->privilege;
1373 while (pv != NULL) {
1374 query = sqlite3_mprintf("insert into package_privilege_info(package, privilege) " \
1376 mfx->package, pv->text);
1377 ret = __exec_query(query);
1378 sqlite3_free(query);
1380 _LOGD("Package Privilege Info DB Insert Failed\n");
1388 ret = __insert_ui_mainapp_info(mfx);
1392 /*Insert the package locale*/
1393 pkglocale = __create_locale_list(pkglocale, lbl, lcn, icn, dcn, ath);
1394 /*remove duplicated data in pkglocale*/
1395 __trimfunc(pkglocale);
1397 /*Insert the app locale info */
1400 applocale = __create_locale_list(applocale, up->label, NULL, up->icon, NULL, NULL);
1403 /*remove duplicated data in applocale*/
1404 __trimfunc(applocale);
1406 /*Insert the app icon info */
1407 while(up_icn != NULL)
1409 appicon = __create_icon_list(appicon, up_icn->icon);
1410 up_icn = up_icn->next;
1412 /*remove duplicated data in appicon*/
1413 __trimfunc(appicon);
1415 /*Insert the image info */
1416 while(up_image != NULL)
1418 appimage = __create_image_list(appimage, up_image->image);
1419 up_image = up_image->next;
1421 /*remove duplicated data in appimage*/
1422 __trimfunc(appimage);
1424 /*g_list_foreach(pkglocale, __printfunc, NULL);*/
1426 /*g_list_foreach(applocale, __printfunc, NULL);*/
1428 g_list_foreach(pkglocale, __insert_pkglocale_info, (gpointer)mfx);
1430 /*native app locale info*/
1431 up = mfx->uiapplication;
1434 g_list_foreach(applocale, __insert_uiapplication_locale_info, (gpointer)up);
1438 /*app icon locale info*/
1439 up_icn = mfx->uiapplication;
1440 while(up_icn != NULL)
1442 g_list_foreach(appicon, __insert_uiapplication_icon_section_info, (gpointer)up_icn);
1443 up_icn = up_icn->next;
1447 up_image = mfx->uiapplication;
1448 while(up_image != NULL)
1450 g_list_foreach(appimage, __insert_uiapplication_image_info, (gpointer)up_image);
1451 up_image = up_image->next;
1454 g_list_free(pkglocale);
1456 g_list_free(applocale);
1458 g_list_free(appicon);
1460 g_list_free(appimage);
1464 /*Insert in the package_app_info DB*/
1465 ret = __insert_uiapplication_info(mfx);
1469 /*Insert in the package_app_app_control DB*/
1470 ret = __insert_uiapplication_appcontrol_info(mfx);
1474 /*Insert in the package_app_app_category DB*/
1475 ret = __insert_uiapplication_appcategory_info(mfx);
1479 /*Insert in the package_app_app_metadata DB*/
1480 ret = __insert_uiapplication_appmetadata_info(mfx);
1484 /*Insert in the package_app_app_permission DB*/
1485 ret = __insert_uiapplication_apppermission_info(mfx);
1489 /*Insert in the package_app_app_svc DB*/
1490 ret = __insert_uiapplication_appsvc_info(mfx);
1494 /*Insert in the package_app_share_allowed DB*/
1495 ret = __insert_uiapplication_share_allowed_info(mfx);
1499 /*Insert in the package_app_share_request DB*/
1500 ret = __insert_uiapplication_share_request_info(mfx);
1504 /*Insert in the package_app_data_control DB*/
1505 ret = __insert_uiapplication_datacontrol_info(mfx);
1513 static int __update_pkg_info_for_disable(const char *pkgid, bool disable)
1518 /*Update from package info*/
1519 query = sqlite3_mprintf("update package_info set package_disable=%Q where package=%Q", disable?"true":"false", pkgid);
1520 ret = __exec_query(query);
1521 sqlite3_free(query);
1522 retvm_if(ret < 0, PMINFO_R_ERROR, "__exec_query() failed.\n");
1524 /*Update from app info*/
1525 query = sqlite3_mprintf("update package_app_info set app_disable=%Q where package=%Q", disable?"true":"false", pkgid);
1526 ret = __exec_query(query);
1527 sqlite3_free(query);
1528 retvm_if(ret < 0, PMINFO_R_ERROR, "__exec_query() failed.\n");
1533 static int __delete_appinfo_from_db(char *db_table, const char *appid)
1536 char *query = sqlite3_mprintf("delete from %Q where app_id=%Q", db_table, appid);
1537 ret = __exec_query(query);
1538 sqlite3_free(query);
1540 _LOGD("DB Deletion from table (%s) Failed\n", db_table);
1547 static int __delete_manifest_info_from_db(manifest_x *mfx)
1550 uiapplication_x *up = mfx->uiapplication;
1552 /* Delete package info DB */
1553 ret = __delete_manifest_info_from_pkgid(mfx->package);
1554 retvm_if(ret < 0, PMINFO_R_ERROR, "Package Info DB Delete Failed\n");
1556 while (up != NULL) {
1557 ret = __delete_manifest_info_from_appid(up->appid);
1558 retvm_if(ret < 0, PMINFO_R_ERROR, "App Info DB Delete Failed\n");
1566 static int __delete_appsvc_db(const char *appid)
1569 void *lib_handle = NULL;
1570 int (*appsvc_operation) (const char *);
1572 if ((lib_handle = dlopen(LIBAPPSVC_PATH, RTLD_LAZY)) == NULL) {
1573 _LOGE("dlopen is failed LIBAIL_PATH[%s]\n", LIBAPPSVC_PATH);
1576 if ((appsvc_operation =
1577 dlsym(lib_handle, "appsvc_unset_defapp")) == NULL || dlerror() != NULL) {
1578 _LOGE("can not find symbol \n");
1582 ret = appsvc_operation(appid);
1586 dlclose(lib_handle);
1591 static int __delete_appsvc_info_from_db(manifest_x *mfx)
1594 uiapplication_x *uiapplication = mfx->uiapplication;
1596 for(; uiapplication; uiapplication=uiapplication->next) {
1597 ret = __delete_appsvc_db(uiapplication->appid);
1599 _LOGE("can not remove_appsvc_db\n");
1605 static int __delete_manifest_info_from_pkgid(const char *pkgid)
1610 /*Delete from cert table*/
1611 ret = pkgmgrinfo_delete_certinfo(pkgid);
1612 retvm_if(ret < 0, PMINFO_R_ERROR, "Cert Info DB Delete Failed\n");
1614 /*Delete from Package Info DB*/
1615 query = sqlite3_mprintf("delete from package_info where package=%Q", pkgid);
1616 ret = __exec_query(query);
1617 tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "Package Info DB Delete Failed\n");
1619 /*Delete from Package Localized Info*/
1620 sqlite3_free(query);
1621 query = sqlite3_mprintf("delete from package_localized_info where package=%Q", pkgid);
1622 ret = __exec_query(query);
1623 tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "Package Localized Info DB Delete Failed\n");
1625 /*Delete from Package Privilege Info*/
1626 sqlite3_free(query);
1627 query = sqlite3_mprintf("delete from package_privilege_info where package=%Q", pkgid);
1628 ret = __exec_query(query);
1629 tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "Package Privilege Info DB Delete Failed\n");
1632 sqlite3_free(query);
1637 static int __delete_manifest_info_from_appid(const char *appid)
1641 ret = __delete_appinfo_from_db("package_app_info", appid);
1642 retvm_if(ret < 0, PMINFO_R_ERROR, "Fail to get handle");
1644 ret = __delete_appinfo_from_db("package_app_localized_info", appid);
1645 retvm_if(ret < 0, PMINFO_R_ERROR, "Fail to get handle");
1647 ret = __delete_appinfo_from_db("package_app_icon_section_info", appid);
1648 retvm_if(ret < 0, PMINFO_R_ERROR, "Fail to get handle");
1650 ret = __delete_appinfo_from_db("package_app_image_info", appid);
1651 retvm_if(ret < 0, PMINFO_R_ERROR, "Fail to get handle");
1653 ret = __delete_appinfo_from_db("package_app_app_svc", appid);
1654 retvm_if(ret < 0, PMINFO_R_ERROR, "Fail to get handle");
1656 ret = __delete_appinfo_from_db("package_app_app_control", appid);
1657 retvm_if(ret < 0, PMINFO_R_ERROR, "Fail to get handle");
1659 ret = __delete_appinfo_from_db("package_app_app_category", appid);
1660 retvm_if(ret < 0, PMINFO_R_ERROR, "Fail to get handle");
1662 ret = __delete_appinfo_from_db("package_app_app_metadata", appid);
1663 retvm_if(ret < 0, PMINFO_R_ERROR, "Fail to get handle");
1665 ret = __delete_appinfo_from_db("package_app_app_permission", appid);
1666 retvm_if(ret < 0, PMINFO_R_ERROR, "Fail to get handle");
1668 ret = __delete_appinfo_from_db("package_app_share_allowed", appid);
1669 retvm_if(ret < 0, PMINFO_R_ERROR, "Fail to get handle");
1671 ret = __delete_appinfo_from_db("package_app_share_request", appid);
1672 retvm_if(ret < 0, PMINFO_R_ERROR, "Fail to get handle");
1674 ret = __delete_appinfo_from_db("package_app_data_control", appid);
1675 retvm_if(ret < 0, PMINFO_R_ERROR, "Fail to get handle");
1681 static int __update_preload_condition_in_db()
1686 query = sqlite3_mprintf("update package_info set package_preload='true'");
1688 ret = __exec_query(query);
1689 sqlite3_free(query);
1691 _LOGD("Package preload_condition update failed\n");
1696 int pkgmgr_parser_initialize_db()
1700 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_INFO);
1702 _LOGD("package info DB initialization failed\n");
1705 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO);
1707 _LOGD("package localized info DB initialization failed\n");
1710 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO);
1712 _LOGD("package app app privilege DB initialization failed\n");
1715 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_INFO);
1717 _LOGD("package app info DB initialization failed\n");
1720 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO);
1722 _LOGD("package app localized info DB initialization failed\n");
1725 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO);
1727 _LOGD("package app icon localized info DB initialization failed\n");
1730 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO);
1732 _LOGD("package app image info DB initialization failed\n");
1735 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL);
1737 _LOGD("package app app control DB initialization failed\n");
1740 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY);
1742 _LOGD("package app app category DB initialization failed\n");
1745 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA);
1747 _LOGD("package app app category DB initialization failed\n");
1750 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION);
1752 _LOGD("package app app permission DB initialization failed\n");
1755 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_SVC);
1757 _LOGD("package app app svc DB initialization failed\n");
1760 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED);
1762 _LOGD("package app share allowed DB initialization failed\n");
1765 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST);
1767 _LOGD("package app share request DB initialization failed\n");
1770 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL);
1772 _LOGD("package app data control DB initialization failed\n");
1776 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INFO);
1778 _LOGD("package cert info DB initialization failed\n");
1781 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO);
1783 _LOGD("package cert index info DB initialization failed\n");
1787 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_PKG_RESERVE);
1789 _LOGD("package pkg reserve info DB initialization failed\n");
1792 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_RESERVE);
1794 _LOGD("package pkg reserve info DB initialization failed\n");
1798 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_PLUGIN_INFO);
1800 _LOGD("package pkg reserve info DB initialization failed\n");
1803 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_ALIASID);
1805 _LOGD("package app aliasId DB initialization failed\n");
1808 #ifdef _APPFW_FEATURE_PROFILE_WEARABLE
1809 ret = __init_tables_for_wearable();
1811 _LOGD("package pkg reserve info DB initialization failed\n");
1819 int pkgmgr_parser_check_and_create_db()
1823 ret = __pkgmgr_parser_create_db(&pkgmgr_parser_db, PKGMGR_PARSER_DB_FILE);
1825 _LOGD("Manifest DB creation Failed\n");
1829 ret = __pkgmgr_parser_create_db(&pkgmgr_cert_db, PKGMGR_CERT_DB_FILE);
1831 _LOGD("Cert DB creation Failed\n");
1837 void pkgmgr_parser_close_db()
1839 sqlite3_close(pkgmgr_parser_db);
1840 sqlite3_close(pkgmgr_cert_db);
1843 API int pkgmgr_parser_insert_manifest_info_in_db(manifest_x *mfx)
1846 _LOGD("manifest pointer is NULL\n");
1850 ret = pkgmgr_parser_check_and_create_db();
1852 _LOGD("Failed to open DB\n");
1855 ret = pkgmgr_parser_initialize_db();
1858 /*Begin transaction*/
1859 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
1860 if (ret != SQLITE_OK) {
1861 _LOGD("Failed to begin transaction[%d]\n", ret);
1865 _LOGD("Transaction Begin\n");
1866 ret = __insert_manifest_info_in_db(mfx);
1868 _LOGD("Insert into DB failed. Rollback now\n");
1869 ret = sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
1870 if (ret != SQLITE_OK)
1871 _LOGD("ROLLBACK is fail after insert_disabled_pkg_info_in_db\n");
1876 /*Commit transaction*/
1877 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
1878 if (ret != SQLITE_OK) {
1879 _LOGD("Failed to commit transaction. Rollback now\n");
1880 ret = sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
1881 if (ret != SQLITE_OK)
1882 _LOGE("Failed to commit transaction. Rollback now\n");
1887 _LOGD("Transaction Commit and End\n");
1889 pkgmgr_parser_close_db();
1893 API int pkgmgr_parser_update_manifest_info_in_db(manifest_x *mfx)
1896 _LOGD("manifest pointer is NULL\n");
1900 ret = pkgmgr_parser_check_and_create_db();
1902 _LOGD("Failed to open DB\n");
1905 ret = pkgmgr_parser_initialize_db();
1909 /*Begin transaction*/
1910 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
1911 if (ret != SQLITE_OK) {
1912 _LOGD("Failed to begin transaction\n");
1916 _LOGD("Transaction Begin\n");
1917 ret = __delete_manifest_info_from_db(mfx);
1919 _LOGD("Delete from DB failed. Rollback now\n");
1920 ret = sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
1921 if (ret != SQLITE_OK)
1922 _LOGD("Failed to commit transaction. Rollback now\n");
1925 ret = __insert_manifest_info_in_db(mfx);
1927 _LOGD("Insert into DB failed. Rollback now\n");
1928 ret = sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
1929 if (ret != SQLITE_OK)
1930 _LOGD("Failed to commit transaction. Rollback now\n");
1934 /*Commit transaction*/
1935 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
1936 if (ret != SQLITE_OK) {
1937 _LOGD("Failed to commit transaction. Rollback now\n");
1938 ret = sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
1939 if (ret != SQLITE_OK)
1940 _LOGD("Failed to commit transaction. Rollback now\n");
1945 _LOGD("Transaction Commit and End\n");
1947 pkgmgr_parser_close_db();
1951 API int pkgmgr_parser_delete_manifest_info_from_db(manifest_x *mfx)
1954 _LOGD("manifest pointer is NULL\n");
1958 ret = pkgmgr_parser_check_and_create_db();
1960 _LOGD("Failed to open DB\n");
1963 /*Begin transaction*/
1964 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
1965 if (ret != SQLITE_OK) {
1966 _LOGD("Failed to begin transaction\n");
1970 _LOGD("Transaction Begin\n");
1971 ret = __delete_manifest_info_from_db(mfx);
1973 _LOGD("Delete from DB failed. Rollback now\n");
1974 ret = sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
1975 if (ret != SQLITE_OK)
1976 _LOGE("Failed to commit transaction, Rollback now\n");
1980 /*Commit transaction*/
1981 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
1982 if (ret != SQLITE_OK) {
1983 _LOGD("Failed to commit transaction, Rollback now\n");
1984 ret = sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
1985 if (ret != SQLITE_OK)
1986 _LOGE("Failed to commit transaction, Rollback now\n");
1992 ret = __delete_appsvc_info_from_db(mfx);
1994 _LOGD("Removing appsvc_db failed\n");
1996 _LOGD("Removing appsvc_db Success\n");
1998 _LOGD("Transaction Commit and End\n");
2000 pkgmgr_parser_close_db();
2004 API int pkgmgr_parser_update_preload_info_in_db()
2007 ret = pkgmgr_parser_check_and_create_db();
2009 _LOGD("Failed to open DB\n");
2012 /*Begin transaction*/
2013 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2014 if (ret != SQLITE_OK) {
2015 _LOGD("Failed to begin transaction\n");
2019 _LOGD("Transaction Begin\n");
2020 ret = __update_preload_condition_in_db();
2022 _LOGD("__update_preload_condition_in_db failed. Rollback now\n");
2023 ret = sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2024 if (ret != SQLITE_OK)
2025 _LOGE("Failed to commit transaction, Rollback now\n");
2029 /*Commit transaction*/
2030 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2031 if (ret != SQLITE_OK) {
2032 _LOGD("Failed to commit transaction, Rollback now\n");
2033 ret = sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2034 if (ret != SQLITE_OK)
2035 _LOGE("Failed to commit transaction, Rollback now\n");
2040 _LOGD("Transaction Commit and End\n");
2042 pkgmgr_parser_close_db();
2046 API int pkgmgr_parser_delete_pkgid_info_from_db(const char *pkgid)
2048 retvm_if(pkgid == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2053 ret = pkgmgr_parser_check_and_create_db();
2054 retvm_if(ret < 0, PMINFO_R_ERROR, "Failed to open DB\n");
2056 /*Begin transaction*/
2057 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2058 if (ret != SQLITE_OK) {
2059 _LOGE("Failed to begin transaction\n");
2064 _LOGD("Start to Delete pkgid[%s] info from db\n", pkgid);
2067 ret = __delete_manifest_info_from_pkgid(pkgid);
2069 _LOGD("Delete from DB failed. Rollback now\n");
2070 ret = sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2071 if (ret != SQLITE_OK)
2072 _LOGE("Failed to begin transaction\n");
2076 /*Commit transaction*/
2077 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2078 if (ret != SQLITE_OK) {
2079 _LOGD("Failed to commit transaction, Rollback now\n");
2080 ret = sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2081 if (ret != SQLITE_OK)
2082 _LOGE("Failed to commit transaction, Rollback now\n");
2089 pkgmgr_parser_close_db();
2093 API int pkgmgr_parser_delete_appid_info_from_db(const char *appid)
2095 retvm_if(appid == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2100 ret = pkgmgr_parser_check_and_create_db();
2101 retvm_if(ret < 0, PMINFO_R_ERROR, "Failed to open DB\n");
2103 /*Begin transaction*/
2104 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2105 if (ret != SQLITE_OK) {
2106 _LOGE("Failed to begin transaction\n");
2111 _LOGD("Start to Delete appid[%s] info from db\n", appid);
2113 /*delete appinfo db*/
2114 ret = __delete_manifest_info_from_appid(appid);
2116 _LOGE("Fail to delete appid[%s] info from pkgmgr db\n", appid);
2118 /*delete appsvc db*/
2119 ret = __delete_appsvc_db(appid);
2121 _LOGE("Fail to delete appid[%s] info from appsvc db\n", appid);
2123 /*Commit transaction*/
2124 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2125 if (ret != SQLITE_OK) {
2126 _LOGD("Failed to commit transaction, Rollback now\n");
2127 ret = sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2128 if (ret != SQLITE_OK)
2129 _LOGE("Failed to commit transaction, Rollback now\n");
2136 pkgmgr_parser_close_db();
2140 API int pkgmgr_parser_update_enabled_pkg_info_in_db(const char *pkgid)
2142 retvm_if(pkgid == NULL, PMINFO_R_ERROR, "pkgid is NULL.");
2146 _LOGD("pkgmgr_parser_update_enabled_pkg_info_in_db(%s)\n", pkgid);
2149 ret = pkgmgr_parser_check_and_create_db();
2150 retvm_if(ret < 0, PMINFO_R_ERROR, "pkgmgr_parser_check_and_create_db(%s) failed.\n", pkgid);
2152 /*Begin transaction*/
2153 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2154 if (ret != SQLITE_OK) {
2155 _LOGE("sqlite3_exec(BEGIN EXCLUSIVE) failed.\n");
2161 ret = __update_pkg_info_for_disable(pkgid, false);
2163 _LOGD("__update_pkg_info_for_disable(%s) failed.\n", pkgid);
2164 ret = sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2165 if (ret != SQLITE_OK)
2166 _LOGE("sqlite3_exec(ROLLBACK) failed.\n");
2170 /*Commit transaction*/
2171 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2172 if (ret != SQLITE_OK) {
2173 _LOGD("sqlite3_exec(COMMIT) failed.\n");
2174 ret = sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2175 if (ret != SQLITE_OK)
2176 _LOGE("sqlite3_exec(ROLLBACK) failed.\n");
2183 pkgmgr_parser_close_db();
2187 API int pkgmgr_parser_update_disabled_pkg_info_in_db(const char *pkgid)
2189 retvm_if(pkgid == NULL, PMINFO_R_ERROR, "pkgid is NULL.");
2193 _LOGD("pkgmgr_parser_update_disabled_pkg_info_in_db(%s)\n", pkgid);
2196 ret = pkgmgr_parser_check_and_create_db();
2197 retvm_if(ret < 0, PMINFO_R_ERROR, "pkgmgr_parser_check_and_create_db(%s) failed.\n", pkgid);
2199 /*Begin transaction*/
2200 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2201 if (ret != SQLITE_OK) {
2202 _LOGE("sqlite3_exec(BEGIN EXCLUSIVE) failed.\n");
2208 ret = __update_pkg_info_for_disable(pkgid, true);
2210 _LOGD("__update_pkg_info_for_disable(%s) failed.\n", pkgid);
2211 ret = sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2212 if (ret != SQLITE_OK)
2213 _LOGE("sqlite3_exec(ROLLBACK) failed.\n");
2217 /*Commit transaction*/
2218 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2219 if (ret != SQLITE_OK) {
2220 _LOGD("sqlite3_exec(COMMIT) failed.\n");
2221 ret = sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2222 if (ret != SQLITE_OK)
2223 _LOGE("sqlite3_exec(ROLLBACK) failed.\n");
2230 pkgmgr_parser_close_db();
2234 int pkgmgr_parser_insert_app_aliasid_info_in_db(void)
2236 FILE *ini_file = NULL;
2238 char *tizen_id = NULL;
2239 char *app_id = NULL;
2241 char buf[ MAX_ALIAS_INI_ENTRY ] = {0};
2242 int ret = PM_PARSER_R_OK;
2243 sqlite3 *pkgmgr_db = NULL;
2246 /*Open the alias.ini file*/
2247 ini_file = fopen(USR_APPSVC_ALIAS_INI,"r");
2249 /*Open the pkgmgr DB*/
2250 ret = db_util_open_with_options(MANIFEST_DB, &pkgmgr_db, SQLITE_OPEN_READWRITE, NULL);
2251 if (ret != SQLITE_OK) {
2252 _LOGE("connect db [%s] failed!\n", MANIFEST_DB);
2254 return PM_PARSER_R_ERROR;
2257 /*Begin Transaction*/
2258 ret = sqlite3_exec(pkgmgr_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2259 tryvm_if(ret != SQLITE_OK, ret = PM_PARSER_R_ERROR, "Failed to begin transaction");
2261 _LOGD("Transaction Begin\n");
2263 /*delete all the previous entries from package_app_aliasid tables*/
2264 query = sqlite3_mprintf("delete from package_app_aliasid");
2265 ret = __exec_db_query(pkgmgr_db, query, NULL, NULL);
2266 sqlite3_free(query);
2267 tryvm_if(ret != SQLITE_OK,ret = PM_PARSER_R_ERROR,"sqlite exec failed to delete entries from package_app_aliasid!!");
2269 while ( fgets ( buf, sizeof(buf), ini_file ) != NULL ) /* read a line */
2271 match = strstr(buf,"=");
2274 /*format of alias.ini entry is 'tizen_app_id=alias_id'*/
2275 /*get the tizen appid id*/
2276 len = strlen(buf)-strlen(match);
2277 tizen_id = malloc(len + 1);
2278 tryvm_if(tizen_id == NULL, ret = PM_PARSER_R_ERROR,"Malloc failed!!");
2279 memset(tizen_id,'\0',len +1);
2280 strncpy(tizen_id,buf,len);
2282 __str_trim(tizen_id);
2284 /*get the corresponding alias id*/
2285 len = strlen(match)-1;
2286 app_id = malloc(len + 1);
2287 tryvm_if(app_id == NULL, ret = PM_PARSER_R_ERROR,"Malloc failed!!");
2288 memset(app_id,'\0',len + 1);
2289 strncpy(app_id, match + 1, len);
2293 /* Insert the data into DB*/
2294 query = sqlite3_mprintf("insert into package_app_aliasid(app_id, alias_id) values(%Q ,%Q)",tizen_id,app_id);
2295 ret = __exec_db_query(pkgmgr_db, query, NULL, NULL);
2296 sqlite3_free(query);
2297 tryvm_if(ret != SQLITE_OK,ret = PM_PARSER_R_ERROR, "sqlite exec failed to insert entries into package_app_aliasid table!!");
2299 FREE_AND_NULL(tizen_id);
2300 FREE_AND_NULL(app_id);
2301 memset(buf,'\0',MAX_ALIAS_INI_ENTRY);
2304 /*Commit transaction*/
2305 ret = sqlite3_exec(pkgmgr_db, "COMMIT", NULL, NULL, NULL);
2306 if (ret != SQLITE_OK) {
2307 _LOGE("Failed to commit transaction, Rollback now\n");
2308 ret = sqlite3_exec(pkgmgr_db, "ROLLBACK", NULL, NULL, NULL);
2309 if (ret != SQLITE_OK)
2310 _LOGE("Failed to Rollback\n");
2312 ret = PM_PARSER_R_ERROR;
2315 _LOGE("Transaction Commit and End\n");
2316 ret = PM_PARSER_R_OK;
2318 perror(USR_APPSVC_ALIAS_INI);
2326 FREE_AND_NULL(tizen_id);
2327 FREE_AND_NULL(app_id);
2328 sqlite3_close(pkgmgr_db);
2334 int pkgmgr_parser_update_app_aliasid_info_in_db(void)
2336 FILE *ini_file = NULL;
2338 char *tizen_id = NULL;
2339 char *app_id = NULL;
2341 char buf[ MAX_ALIAS_INI_ENTRY ] = {0};
2342 int ret = PM_PARSER_R_OK;
2343 sqlite3 *pkgmgr_db = NULL;
2346 /*Open the alias.ini file*/
2347 ini_file = fopen(OPT_APPSVC_ALIAS_INI,"r");
2349 /*Open the pkgmgr DB*/
2350 ret = db_util_open_with_options(MANIFEST_DB, &pkgmgr_db, SQLITE_OPEN_READWRITE, NULL);
2351 if (ret != SQLITE_OK) {
2352 _LOGE("connect db [%s] failed!\n", MANIFEST_DB);
2354 return PM_PARSER_R_ERROR;
2357 /*Begin Transaction*/
2358 ret = sqlite3_exec(pkgmgr_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2359 tryvm_if(ret != SQLITE_OK, ret = PM_PARSER_R_ERROR, "Failed to begin transaction");
2361 _LOGD("Transaction Begin\n");
2363 while ( fgets ( buf, sizeof(buf), ini_file ) != NULL ) /* read a line */
2365 match = strstr(buf,"=");
2368 /*format of alias.ini entry is 'tizen_app_id=alias_id'*/
2369 /*get the tizen appid id*/
2370 len = strlen(buf)-strlen(match);
2371 tizen_id = malloc(len + 1);
2372 tryvm_if(tizen_id == NULL, ret = PM_PARSER_R_ERROR,"Malloc failed!!");
2373 memset(tizen_id,'\0',len +1);
2374 strncpy(tizen_id,buf,len);
2376 __str_trim(tizen_id);
2378 /*get the corresponding alias id*/
2379 len = strlen(match)-1;
2380 app_id = malloc(len + 1);
2381 tryvm_if(app_id == NULL, ret = PM_PARSER_R_ERROR,"Malloc failed!!");
2382 memset(app_id,'\0',len + 1);
2383 strncpy(app_id, match + 1, len);
2387 /* Insert the data into DB*/
2388 query = sqlite3_mprintf("insert or replace into package_app_aliasid(app_id, alias_id) values(%Q ,%Q)",tizen_id,app_id);
2389 ret = __exec_db_query(pkgmgr_db, query, NULL, NULL);
2390 sqlite3_free(query);
2391 tryvm_if(ret != SQLITE_OK,ret = PM_PARSER_R_ERROR, "sqlite exec failed to insert entries into package_app_aliasid table!!");
2393 FREE_AND_NULL(tizen_id);
2394 FREE_AND_NULL(app_id);
2395 memset(buf,'\0',MAX_ALIAS_INI_ENTRY);
2398 /*Commit transaction*/
2399 ret = sqlite3_exec(pkgmgr_db, "COMMIT", NULL, NULL, NULL);
2400 if (ret != SQLITE_OK) {
2401 _LOGE("Failed to commit transaction, Rollback now\n");
2402 ret = sqlite3_exec(pkgmgr_db, "ROLLBACK", NULL, NULL, NULL);
2403 if (ret != SQLITE_OK)
2404 _LOGE("Failed to Rollback\n");
2406 ret = PM_PARSER_R_ERROR;
2409 _LOGE("Transaction Commit and End\n");
2410 ret = PM_PARSER_R_OK;
2412 perror(OPT_APPSVC_ALIAS_INI);
2420 FREE_AND_NULL(tizen_id);
2421 FREE_AND_NULL(app_id);
2422 sqlite3_close(pkgmgr_db);