From: Junghyun Yeon Date: Mon, 8 Mar 2021 09:00:13 +0000 (+0900) Subject: Move some internal APIs into internal files X-Git-Tag: submit/tizen/20210317.082331~57 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3d34cb0c0cf6511eb6e645c24616d5827da07da9;p=platform%2Fcore%2Fappfw%2Fpkgmgr-info.git Move some internal APIs into internal files Signed-off-by: Junghyun Yeon --- diff --git a/parser/include/pkgmgr_parser_db.h b/parser/include/pkgmgr_parser_db.h index 4c4b56b0..5e13b869 100644 --- a/parser/include/pkgmgr_parser_db.h +++ b/parser/include/pkgmgr_parser_db.h @@ -52,9 +52,11 @@ extern "C" { #include "pkgmgrinfo_type.h" // TODO: add descriptions +/* int pkgmgr_parser_insert_pkg_info(sqlite3 *db, manifest_x *mfx, uid_t uid); int pkgmgr_parser_update_pkg_info(sqlite3 *db, manifest_x *mfx, uid_t uid); int pkgmgr_parser_delete_pkg_info(sqlite3 *db, const char *package, uid_t uid); +*/ /** * @fn int pkgmgr_parser_insert_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid) diff --git a/parser/src/pkgmgr_parser_db.c b/parser/src/pkgmgr_parser_db.c index f3530996..781906d3 100644 --- a/parser/src/pkgmgr_parser_db.c +++ b/parser/src/pkgmgr_parser_db.c @@ -103,17 +103,6 @@ static inline uid_t __getuid(void) return uid; } -static const char *__get_bool(char *value, bool is_true) -{ - if (value != NULL) { - if (!strcmp(value, "")) - return (is_true) ? "true" : "false"; - return value; - } - - return (is_true) ? "true" : "false"; -} - #define __BEGIN_TRANSACTION(db) \ do { \ if (sqlite3_exec(db, "BEGIN DEFERRED", NULL, NULL, NULL) != \ @@ -148,24 +137,6 @@ do { \ } \ } while (0) \ -#define __BIND_TEXT(db, stmt, i, text) \ -do { \ - if (sqlite3_bind_text(stmt, i, text, -1, SQLITE_STATIC) != SQLITE_OK) {\ - _LOGE("bind error(index %d): %s", i, sqlite3_errmsg(db)); \ - sqlite3_finalize(stmt); \ - return -1; \ - } \ -} while (0) - -#define __BIND_INT(db, stmt, i, int) \ -do { \ - if (sqlite3_bind_int(stmt, i, int) != SQLITE_OK) { \ - _LOGE("bind error(index %d): %s", i, sqlite3_errmsg(db)); \ - sqlite3_finalize(stmt); \ - return -1; \ - } \ -} while (0) - static const char *__get_parser_db_path(uid_t uid) { char buf[PATH_MAX]; @@ -578,1680 +549,100 @@ API int pkgmgr_parser_create_and_initialize_db(uid_t uid) return PM_PARSER_R_OK; } -static int __convert_background_category(GList *category_list) -{ - int ret = 0; - GList *tmp; - char *category_data; - - if (category_list == NULL) - return 0; - - for (tmp = category_list; tmp; tmp = tmp->next) { - category_data = (char *)tmp->data; - if (category_data == NULL) - continue; - if (!strcmp(category_data, APP_BG_CATEGORY_MEDIA_STR)) - ret |= APP_BG_CATEGORY_MEDIA_VAL; - else if (!strcmp(category_data, APP_BG_CATEGORY_DOWNLOAD_STR)) - ret |= APP_BG_CATEGORY_DOWNLOAD_VAL; - else if (!strcmp(category_data, APP_BG_CATEGORY_BGNETWORK_STR)) - ret |= APP_BG_CATEGORY_BGNETWORK_VAL; - else if (!strcmp(category_data, APP_BG_CATEGORY_LOCATION_STR)) - ret |= APP_BG_CATEGORY_LOCATION_VAL; - else if (!strcmp(category_data, APP_BG_CATEGORY_SENSOR_STR)) - ret |= APP_BG_CATEGORY_SENSOR_VAL; - else if (!strcmp(category_data, APP_BG_CATEGORY_IOTCOMM_STR)) - ret |= APP_BG_CATEGORY_IOTCOMM_VAL; - else if (!strcmp(category_data, APP_BG_CATEGORY_SYSTEM)) - ret |= APP_BG_CATEGORY_SYSTEM_VAL; - else - _LOGE("Unidentified category [%s]", category_data); - } - - return ret; -} - -#define EFFECTIVE_APPID_KEY "http://tizen.org/metadata/effective-appid" -static const char *__find_effective_appid(GList *metadata_list) -{ - GList *tmp; - metadata_x *md; - - for (tmp = metadata_list; tmp; tmp = tmp->next) { - md = (metadata_x *)tmp->data; - if (md == NULL || md->key == NULL) - continue; - - if (strcmp(md->key, EFFECTIVE_APPID_KEY) == 0) { - if (md->value) - return md->value; - } - } - - return NULL; -} - -static int __insert_appcontrol_privilege_info(sqlite3 *db, const char *appid, - appcontrol_x *ac) -{ - static const char query[] = - "INSERT INTO package_app_app_control_privilege (app_id," - " app_control, privilege) VALUES (?, ?, ?)"; - int ret; - sqlite3_stmt *stmt; - int idx; - char app_control[BUFSIZE]; - GList *tmp; - char *privilege; - - if (ac == NULL) - return 0; - - ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL); - if (ret != SQLITE_OK) { - _LOGE("prepare failed: %s", sqlite3_errmsg(db)); - return -1; - } - - for (tmp = ac->privileges; tmp; tmp = tmp->next) { - privilege = (char *)tmp->data; - if (privilege == NULL || !strlen(privilege)) - continue; - - idx = 1; - snprintf(app_control, sizeof(app_control), "%s|%s|%s", - ac->operation ? (strlen(ac->operation) > 0 ? - ac->operation : "NULL") : "NULL", - ac->uri ? (strlen(ac->uri) > 0 ? - ac->uri : "NULL") : "NULL", - ac->mime ? (strlen(ac->mime) > 0 ? - ac->mime : "NULL") : "NULL"); - __BIND_TEXT(db, stmt, idx++, appid); - __BIND_TEXT(db, stmt, idx++, app_control); - __BIND_TEXT(db, stmt, idx++, privilege); - - ret = sqlite3_step(stmt); - if (ret != SQLITE_DONE) { - _LOGE("step failed: %s", sqlite3_errmsg(db)); - sqlite3_finalize(stmt); - return -1; - } - - sqlite3_reset(stmt); - } - - sqlite3_finalize(stmt); - - return 0; -} - -static int __insert_appcontrol_info(sqlite3 *db, application_x *app) -{ - static const char query[] = - "INSERT INTO package_app_app_control (app_id, app_control," - " visibility, app_control_id) " - "VALUES (?, ?, ?, ?)"; - int ret; - sqlite3_stmt *stmt; - int idx; - char app_control[BUFSIZE]; - GList *tmp; - appcontrol_x *ac; - - if (app->appcontrol == NULL) - return 0; - - ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL); - if (ret != SQLITE_OK) { - _LOGE("prepare failed: %s", sqlite3_errmsg(db)); - return -1; - } - - for (tmp = app->appcontrol; tmp; tmp = tmp->next) { - ac = (appcontrol_x *)tmp->data; - if (ac == NULL) - continue; - idx = 1; - snprintf(app_control, sizeof(app_control), "%s|%s|%s", - ac->operation ? (strlen(ac->operation) > 0 ? - ac->operation : "NULL") : "NULL", - ac->uri ? (strlen(ac->uri) > 0 ? - ac->uri : "NULL") : "NULL", - ac->mime ? (strlen(ac->mime) > 0 ? - ac->mime : "NULL") : "NULL"); - __BIND_TEXT(db, stmt, idx++, app->appid); - __BIND_TEXT(db, stmt, idx++, app_control); - __BIND_TEXT(db, stmt, idx++, ac->visibility); - __BIND_TEXT(db, stmt, idx++, ac->id); - - ret = sqlite3_step(stmt); - if (ret != SQLITE_DONE) { - _LOGE("step failed: %s", sqlite3_errmsg(db)); - sqlite3_finalize(stmt); - return -1; - } - - if (__insert_appcontrol_privilege_info(db, app->appid, ac)) { - sqlite3_finalize(stmt); - return -1; - } - - sqlite3_reset(stmt); - } - - sqlite3_finalize(stmt); +/* TODO: move to installer */ - return 0; -} +/* TODO: refactor inserting localized info */ -static int __insert_category_info(sqlite3 *db, application_x *app) +static int __insert_package_plugin_execution_info( + manifest_x *mfx, uid_t uid) { - static const char query[] = - "INSERT INTO package_app_app_category (app_id, category) " - "VALUES (?, ?)"; - int ret; - sqlite3_stmt *stmt; - int idx; GList *tmp; - const char *category; + plugin_x *plugin; + char **queries = NULL; + int idx = 0; + int i = 0; - if (app->category == NULL) - return 0; + if (!mfx->plugin) + return PM_PARSER_R_OK; - ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL); - if (ret != SQLITE_OK) { - _LOGE("prepare failed: %s", sqlite3_errmsg(db)); - return -1; + queries = calloc(g_list_length(mfx->plugin), sizeof (char *)); + if (queries == NULL) { + _LOGE("Out of memory"); + return PM_PARSER_R_ERROR; } - for (tmp = app->category; tmp; tmp = tmp->next) { - category = (const char *)tmp->data; - if (category == NULL) + for (tmp = mfx->plugin; tmp; tmp = tmp->next) { + plugin = (plugin_x *)tmp->data; + if (plugin == NULL) continue; - idx = 1; - __BIND_TEXT(db, stmt, idx++, app->appid); - __BIND_TEXT(db, stmt, idx++, category); - - ret = sqlite3_step(stmt); - if (ret != SQLITE_DONE) { - _LOGE("step failed: %s", sqlite3_errmsg(db)); - sqlite3_finalize(stmt); - return -1; - } - - sqlite3_reset(stmt); - } - - sqlite3_finalize(stmt); - - return 0; -} - -static int __insert_metadata_info(sqlite3 *db, application_x *app) -{ - static const char query[] = - "INSERT INTO package_app_app_metadata (app_id," - " md_key, md_value) VALUES (?, ?, ?)"; - int ret; - sqlite3_stmt *stmt; - int idx; - GList *tmp; - metadata_x *md; - - if (app->metadata == NULL) - return 0; - - ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL); - if (ret != SQLITE_OK) { - _LOGE("prepare failed: %s", sqlite3_errmsg(db)); - return -1; - } - for (tmp = app->metadata; tmp; tmp = tmp->next) { - md = (metadata_x *)tmp->data; - if (md == NULL) - continue; - idx = 1; - __BIND_TEXT(db, stmt, idx++, app->appid); - __BIND_TEXT(db, stmt, idx++, md->key); - __BIND_TEXT(db, stmt, idx++, md->value); - - ret = sqlite3_step(stmt); - if (ret != SQLITE_DONE) { - _LOGE("step failed: %s", sqlite3_errmsg(db)); - sqlite3_finalize(stmt); - return -1; + queries[idx] = sqlite3_mprintf("INSERT INTO package_plugin_info " + "(pkgid, appid, plugin_type, plugin_name) " + "VALUES (%Q, %Q, %Q, %Q)", + plugin->pkgid, plugin->appid, + plugin->plugin_type, plugin->plugin_name); + if (queries[idx] == NULL) { + _LOGE("Out of memory"); + for (i = 0; i < idx; ++i) + sqlite3_free(queries[i]); + free(queries); + return PM_PARSER_R_ERROR; } - sqlite3_reset(stmt); + idx++; } - sqlite3_finalize(stmt); - - return 0; -} - -static int __insert_app_data_control_privilege_info(sqlite3 *db, - datacontrol_x *datacontrol) -{ - static const char query[] = - "INSERT INTO package_app_data_control_privilege (providerid," - " privilege, type) VALUES (?, ?, ?)"; - - int ret; - sqlite3_stmt *stmt; - int idx; - GList *privileges; - char *priv; - - if (datacontrol == NULL) - return 0; - - ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL); - if (ret != SQLITE_OK) { - _LOGE("prepare failed: %s", sqlite3_errmsg(db)); - return -1; + if (_parser_execute_write_queries((const char **)queries, idx, uid) < 0) { + _LOGE("Fail to write to db"); + for (i = 0; i < idx; ++i) + sqlite3_free(queries[i]); + free(queries); + return PM_PARSER_R_ERROR; } - for (privileges = datacontrol->privileges; privileges; - privileges = privileges->next) { - priv = (char *)privileges->data; - if (priv == NULL) - continue; - - idx = 1; - __BIND_TEXT(db, stmt, idx++, datacontrol->providerid); - __BIND_TEXT(db, stmt, idx++, priv); - __BIND_TEXT(db, stmt, idx++, datacontrol->type); - - ret = sqlite3_step(stmt); - if (ret != SQLITE_DONE) { - _LOGE("step failed: %s", sqlite3_errmsg(db)); - sqlite3_finalize(stmt); - return -1; - } - - sqlite3_reset(stmt); - } + for (i = 0; i < idx; ++i) + sqlite3_free(queries[i]); + free(queries); - sqlite3_finalize(stmt); - return 0; + return PM_PARSER_R_OK; } -static int __insert_datacontrol_info(sqlite3 *db, application_x *app) +static int __delete_package_plugin_execution_info(const char *pkgid, uid_t uid) { - static const char query[] = - "INSERT INTO package_app_data_control (app_id, providerid," - " access, type, trusted) VALUES (?, ?, ?, ?, ?)"; - int ret; - sqlite3_stmt *stmt; - int idx; - GList *tmp; - datacontrol_x *dc; - - if (app->datacontrol == NULL) - return 0; + char *query = NULL; - ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL); - if (ret != SQLITE_OK) { - _LOGE("prepare failed: %s", sqlite3_errmsg(db)); - return -1; + query = sqlite3_mprintf( + "DELETE FROM package_plugin_info WHERE pkgid=%Q", pkgid); + if (query == NULL) { + _LOGE("Out of memory"); + return PM_PARSER_R_ERROR; } - for (tmp = app->datacontrol; tmp; tmp = tmp->next) { - dc = (datacontrol_x *)tmp->data; - if (dc == NULL) - continue; - idx = 1; - __BIND_TEXT(db, stmt, idx++, app->appid); - __BIND_TEXT(db, stmt, idx++, dc->providerid); - __BIND_TEXT(db, stmt, idx++, dc->access); - __BIND_TEXT(db, stmt, idx++, dc->type); - __BIND_TEXT(db, stmt, idx++, dc->trusted); - - ret = sqlite3_step(stmt); - if (ret != SQLITE_DONE) { - _LOGE("step failed: %s", sqlite3_errmsg(db)); - sqlite3_finalize(stmt); - return -1; - } - - if (dc->privileges && - __insert_app_data_control_privilege_info(db, dc)) { - sqlite3_finalize(stmt); - return -1; - } - - sqlite3_reset(stmt); + if (_parser_execute_write_query(query, uid) < 0) { + _LOGE("Fail to write to db"); + sqlite3_free(query); + return PM_PARSER_R_ERROR; } + sqlite3_free(query); - sqlite3_finalize(stmt); - - return 0; -} - -/* TODO: move to installer */ -static int __check_dpi(const char *dpi_char, int dpi_int) -{ - if (dpi_char == NULL) - return -1; - - if (strcasecmp(dpi_char, LDPI) == 0) { - if (dpi_int >= LDPI_MIN && dpi_int <= LDPI_MAX) - return 0; - else - return -1; - } else if (strcasecmp(dpi_char, MDPI) == 0) { - if (dpi_int >= MDPI_MIN && dpi_int <= MDPI_MAX) - return 0; - else - return -1; - } else if (strcasecmp(dpi_char, HDPI) == 0) { - if (dpi_int >= HDPI_MIN && dpi_int <= HDPI_MAX) - return 0; - else - return -1; - } else if (strcasecmp(dpi_char, XHDPI) == 0) { - if (dpi_int >= XHDPI_MIN && dpi_int <= XHDPI_MAX) - return 0; - else - return -1; - } else if (strcasecmp(dpi_char, XXHDPI) == 0) { - if (dpi_int >= XXHDPI_MIN && dpi_int <= XXHDPI_MAX) - return 0; - else - return -1; - } else - return -1; -} - -static gint __compare_splashscreen_with_orientation_dpi(gconstpointer a, - gconstpointer b) -{ - splashscreen_x *ss = (splashscreen_x *)a; - const char *orientation = (const char *)b; - int dpi = -1; - int ret; - - if (ss->operation || ss->dpi == NULL) - return -1; - - ret = system_info_get_platform_int( - "http://tizen.org/feature/screen.dpi", &dpi); - if (ret != SYSTEM_INFO_ERROR_NONE) - return -1; - - if (strcasecmp(ss->orientation, orientation) == 0 && - __check_dpi(ss->dpi, dpi) == 0) - return 0; - - return -1; -} - -static gint __compare_splashscreen_with_orientation(gconstpointer a, - gconstpointer b) -{ - splashscreen_x *ss = (splashscreen_x *)a; - const char *orientation = (const char *)b; - - if (ss->operation || ss->dpi) - return -1; - - if (strcasecmp(ss->orientation, orientation) == 0) - return 0; - - return -1; -} - -static splashscreen_x *__find_default_splashscreen(GList *splashscreens, - const char *orientation) -{ - GList *tmp; - - tmp = g_list_find_custom(splashscreens, orientation, - (GCompareFunc) - __compare_splashscreen_with_orientation_dpi); - if (tmp) - return (splashscreen_x *)tmp->data; - - tmp = g_list_find_custom(splashscreens, orientation, - (GCompareFunc)__compare_splashscreen_with_orientation); - if (tmp) - return (splashscreen_x *)tmp->data; - - return NULL; -} - -static void __find_appcontrol_splashscreen_with_dpi(gpointer data, - gpointer user_data) -{ - splashscreen_x *ss = (splashscreen_x *)data; - GList **list = (GList **)user_data; - int dpi = -1; - int ret; - - if (ss->operation == NULL || ss->dpi == NULL) - return; - - ret = system_info_get_platform_int( - "http://tizen.org/feature/screen.dpi", &dpi); - if (ret != SYSTEM_INFO_ERROR_NONE) - return; - - if (__check_dpi(ss->dpi, dpi) != 0) - return; - - *list = g_list_prepend(*list, ss); + return PM_PARSER_R_OK; } -static void __find_appcontrol_splashscreen(gpointer data, gpointer user_data) +API int pkgmgr_parser_insert_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid) { - splashscreen_x *ss = (splashscreen_x *)data; - GList **list = (GList **)user_data; - splashscreen_x *ss_tmp; - GList *tmp; - - if (ss->operation == NULL || ss->dpi) - return; - - for (tmp = *list; tmp; tmp = tmp->next) { - ss_tmp = (splashscreen_x *)tmp->data; - if (ss_tmp->operation - && strcmp(ss_tmp->operation, ss->operation) == 0 - && strcmp(ss_tmp->orientation, ss->orientation) == 0) - return; + if (_parser_insert_manifest_info(mfx, uid) < 0) { + _LOGE("Fail to insert manifest uid[%d]", uid); + return PM_PARSER_R_ERROR; } - *list = g_list_prepend(*list, ss); + return PM_PARSER_R_OK; } -static GList *__find_splashscreens(GList *splashscreens) -{ - GList *list = NULL; - splashscreen_x *ss; - - if (splashscreens == NULL) - return NULL; - - g_list_foreach(splashscreens, - __find_appcontrol_splashscreen_with_dpi, &list); - g_list_foreach(splashscreens, - __find_appcontrol_splashscreen, &list); - - ss = __find_default_splashscreen(splashscreens, "portrait"); - if (ss) - list = g_list_prepend(list, ss); - ss = __find_default_splashscreen(splashscreens, "landscape"); - if (ss) - list = g_list_prepend(list, ss); - - return list; -} - -static int __insert_splashscreen_info(sqlite3 *db, application_x *app, - GList *ss_list) -{ - static const char query[] = - "INSERT INTO package_app_splash_screen (app_id, src, type," - " orientation, indicatordisplay, operation, color_depth) " - "VALUES (?, ?, ?, ?, ?, ?, ?)"; - int ret; - sqlite3_stmt *stmt; - int idx; - GList *tmp; - splashscreen_x *ss; - - if (app->splashscreens == NULL) - return 0; - - if (ss_list == NULL) - return 0; - - ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL); - if (ret != SQLITE_OK) { - _LOGE("prepare failed: %s", sqlite3_errmsg(db)); - return -1; - } - - for (tmp = ss_list; tmp; tmp = tmp->next) { - ss = (splashscreen_x *)tmp->data; - if (ss == NULL) - continue; - idx = 1; - __BIND_TEXT(db, stmt, idx++, app->appid); - __BIND_TEXT(db, stmt, idx++, ss->src); - __BIND_TEXT(db, stmt, idx++, ss->type); - __BIND_TEXT(db, stmt, idx++, ss->orientation); - __BIND_TEXT(db, stmt, idx++, ss->indicatordisplay); - __BIND_TEXT(db, stmt, idx++, ss->operation); - __BIND_TEXT(db, stmt, idx++, ss->color_depth); - - ret = sqlite3_step(stmt); - if (ret != SQLITE_DONE) { - _LOGE("step failed: %s", sqlite3_errmsg(db)); - sqlite3_finalize(stmt); - return -1; - } - - sqlite3_reset(stmt); - } - - sqlite3_finalize(stmt); - - return 0; -} - -static void __trimfunc(GList *trim_list) -{ - char *trim_data; - char *prev = NULL; - GList *list = g_list_first(trim_list); - - while (list) { - trim_data = (char *)list->data; - if (trim_data) { - if (prev) { - if (strcmp(trim_data, prev) == 0) { - trim_list = g_list_remove(trim_list, - trim_data); - list = g_list_first(trim_list); - prev = NULL; - continue; - } else - prev = trim_data; - } else { - prev = trim_data; - } - } - list = g_list_next(list); - } -} - -static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata) -{ - if (a == NULL || b == NULL) - return 0; - if (strcmp((char *)a, (char *)b) == 0) - return 0; - if (strcmp((char *)a, (char *)b) < 0) - return -1; - if (strcmp((char *)a, (char *)b) > 0) - return 1; - return 0; -} - -/* TODO: refactor inserting localized info */ -static GList *__create_locale_list(GList *lbls, GList *lcns, GList *icns, - GList *dcns, GList *aths) -{ - GList *locale = NULL; - GList *tmp; - label_x *lbl; - license_x *lcn; - icon_x *icn; - description_x *dcn; - author_x *ath; - - for (tmp = lbls; tmp; tmp = tmp->next) { - lbl = (label_x *)tmp->data; - if (lbl == NULL) - continue; - if (lbl->lang) - locale = g_list_insert_sorted_with_data( - locale, (gpointer)lbl->lang, - __comparefunc, NULL); - } - for (tmp = lcns; tmp; tmp = tmp->next) { - lcn = (license_x *)tmp->data; - if (lcn == NULL) - continue; - if (lcn->lang) - locale = g_list_insert_sorted_with_data( - locale, (gpointer)lcn->lang, - __comparefunc, NULL); - } - for (tmp = icns; tmp; tmp = tmp->next) { - icn = (icon_x *)tmp->data; - if (icn == NULL) - continue; - if (icn->lang) - locale = g_list_insert_sorted_with_data( - locale, (gpointer)icn->lang, - __comparefunc, NULL); - } - for (tmp = dcns; tmp; tmp = tmp->next) { - dcn = (description_x *)tmp->data; - if (dcn == NULL) - continue; - if (dcn->lang) - locale = g_list_insert_sorted_with_data( - locale, (gpointer)dcn->lang, - __comparefunc, NULL); - } - for (tmp = aths; tmp; tmp = tmp->next) { - ath = (author_x *)tmp->data; - if (ath == NULL) - continue; - if (ath->lang) - locale = g_list_insert_sorted_with_data( - locale, (gpointer)ath->lang, - __comparefunc, NULL); - } - __trimfunc(locale); - return locale; -} - -static gint __check_icon_resolution(const char *orig_icon_path, - char **new_icon_path) -{ - int ret; - char *dpi_path[2]; - char *icon_filename; - char modified_iconpath[BUFSIZE]; - char icon_path[BUFSIZE]; - int i; - int dpi = -1; - - if (orig_icon_path == NULL) - return -1; - - ret = system_info_get_platform_int( - "http://tizen.org/feature/screen.dpi", &dpi); - if (ret != SYSTEM_INFO_ERROR_NONE) - return -1; - - if (dpi >= LDPI_MIN && dpi <= LDPI_MAX) { - dpi_path[0] = "LDPI"; - dpi_path[1] = "ldpi"; - } else if (dpi >= MDPI_MIN && dpi <= MDPI_MAX) { - dpi_path[0] = "MDPI"; - dpi_path[1] = "mdpi"; - } else if (dpi >= HDPI_MIN && dpi <= HDPI_MAX) { - dpi_path[0] = "HDPI"; - dpi_path[1] = "hdpi"; - } else if (dpi >= XHDPI_MIN && dpi <= XHDPI_MAX) { - dpi_path[0] = "XHDPI"; - dpi_path[1] = "xhdpi"; - } else if (dpi >= XXHDPI_MIN && dpi <= XXHDPI_MAX) { - dpi_path[0] = "XXHDPI"; - dpi_path[1] = "xxhdpi"; - } else { - _LOGE("Unidentified dpi[%d]", dpi); - return -1; - } - - icon_filename = strrchr(orig_icon_path, '/'); - if (icon_filename == NULL) - return -1; - - snprintf(icon_path, - strlen(orig_icon_path) - (strlen(icon_filename) - 1), - "%s", orig_icon_path); - for (i = 0; i < 2; i++) { - ret = snprintf(modified_iconpath, BUFSIZE - 1, "%s/%s%s", - icon_path, dpi_path[i], icon_filename); - if (ret < 0 || ret > BUFSIZE -1) { - _LOGE("snprintf fail"); - return -1; - } - if (access(modified_iconpath, F_OK) != -1) { - /* if exists, return modified icon path */ - *new_icon_path = strdup(modified_iconpath); - return 0; - } - } - - return -1; -} - -static gint __compare_icon(gconstpointer a, gconstpointer b) -{ - icon_x *icon = (icon_x *)a; - char *icon_path; - - if (icon->lang != NULL && strcasecmp(icon->lang, DEFAULT_LOCALE) != 0) - return -1; - - if (icon->dpi != NULL) - return -1; - - if (__check_icon_resolution(icon->text, &icon_path) == 0) { - free(icon->text); - icon->text = icon_path; - } - - return 0; -} - -static gint __compare_icon_with_dpi(gconstpointer a, gconstpointer b) -{ - icon_x *icon = (icon_x *)a; - int dpi = GPOINTER_TO_INT(b); - - if (icon->lang != NULL && strcasecmp(icon->lang, DEFAULT_LOCALE) != 0) - return -1; - - if (icon->dpi == NULL) - return -1; - - if (__check_dpi(icon->dpi, dpi) == 0) - return 0; - - return -1; -} - -static gint __compare_icon_with_lang(gconstpointer a, gconstpointer b) -{ - icon_x *icon = (icon_x *)a; - char *lang = (char *)b; - char *icon_path; - - if (icon->dpi != NULL) - return -1; - - if (strcasecmp(icon->lang, lang) == 0) { - if (strcasecmp(icon->lang, DEFAULT_LOCALE) == 0) { - /* icon for no locale. check existance of - * folder-hierachied default icons - */ - if (__check_icon_resolution(icon->text, - &icon_path) == 0) { - free(icon->text); - icon->text = icon_path; - } - } - return 0; - } - - return -1; -} - -static gint __compare_icon_with_lang_dpi(gconstpointer a, gconstpointer b) -{ - int ret; - icon_x *icon = (icon_x *)a; - char *lang = (char *)b; - int dpi = -1; - - ret = system_info_get_platform_int( - "http://tizen.org/feature/screen.dpi", &dpi); - if (ret != SYSTEM_INFO_ERROR_NONE) - return -1; - - if (strcasecmp(icon->lang, lang) == 0 && - __check_dpi(icon->dpi, dpi) == 0) - return 0; - - return -1; -} - -static char *__find_icon(GList *icons, const char *lang) -{ - GList *tmp; - icon_x *icon; - int dpi = 0; - int ret; - - /* first, find icon whose locale and dpi with given lang and - * system's dpi has matched - */ - tmp = g_list_find_custom(icons, lang, - (GCompareFunc)__compare_icon_with_lang_dpi); - if (tmp != NULL) { - icon = (icon_x *)tmp->data; - return (char *)icon->text; - } - - /* if first has failed, find icon whose locale has matched */ - tmp = g_list_find_custom(icons, lang, - (GCompareFunc)__compare_icon_with_lang); - if (tmp != NULL) { - icon = (icon_x *)tmp->data; - return (char *)icon->text; - } - - /* if second has failed, find icon whose dpi has matched with - * system's dpi - */ - ret = system_info_get_platform_int( - "http://tizen.org/feature/screen.dpi", &dpi); - if (ret == SYSTEM_INFO_ERROR_NONE) { - tmp = g_list_find_custom(icons, GINT_TO_POINTER(dpi), - (GCompareFunc)__compare_icon_with_dpi); - if (tmp != NULL) { - icon = (icon_x *)tmp->data; - return (char *)icon->text; - } - } - - /* last, find default icon marked as "No Locale" */ - tmp = g_list_find_custom(icons, NULL, (GCompareFunc)__compare_icon); - if (tmp != NULL) { - icon = (icon_x *)tmp->data; - return (char *)icon->text; - } - - return NULL; -} - -static void __extract_data(const char *locale, GList *lbls, GList *lcns, - GList *icns, GList *dcns, GList *aths, char **label, - char **license, char **icon, char **description, char **author) -{ - GList *tmp; - label_x *lbl; - license_x *lcn; - description_x *dcn; - author_x *ath; - - for (tmp = lbls; tmp; tmp = tmp->next) { - lbl = (label_x *)tmp->data; - if (lbl == NULL) - continue; - if (lbl->lang) { - if (strcmp(lbl->lang, locale) == 0) { - *label = (char *)lbl->text; - break; - } - } - } - for (tmp = lcns; tmp; tmp = tmp->next) { - lcn = (license_x *)tmp->data; - if (lcn == NULL) - continue; - if (lcn->lang) { - if (strcmp(lcn->lang, locale) == 0) { - *license = (char *)lcn->text; - break; - } - } - } - - *icon = __find_icon(icns, locale); - - for (tmp = dcns; tmp; tmp = tmp->next) { - dcn = (description_x *)tmp->data; - if (dcn == NULL) - continue; - if (dcn->lang) { - if (strcmp(dcn->lang, locale) == 0) { - *description = (char *)dcn->text; - break; - } - } - } - for (tmp = aths; tmp; tmp = tmp->next) { - ath = (author_x *)tmp->data; - if (ath == NULL) - continue; - if (ath->lang) { - if (strcmp(ath->lang, locale) == 0) { - *author = (char *)ath->text; - break; - } - } - } -} - -static int __insert_mainapp_localized_info(sqlite3 *db, application_x *app, - const char *locale, const char *label, const char *icon) -{ - static const char query[] = - "INSERT OR REPLACE INTO package_localized_info (" - " package, package_locale, package_label, package_icon," - " package_description, package_license, package_author) " - "VALUES (?, ?," - " COALESCE((SELECT package_label FROM package_localized_info" - " WHERE package=? AND package_locale=?), ?)," - " COALESCE((SELECT package_icon FROM package_localized_info" - " WHERE package=? AND package_icon=?), ?)," - " (SELECT package_description FROM package_localized_info" - " WHERE package=? AND package_locale=?)," - " (SELECT package_description FROM package_localized_info" - " WHERE package=? AND package_locale=?)," - " (SELECT package_description FROM package_localized_info" - " WHERE package=? AND package_locale=?))"; - int ret; - sqlite3_stmt *stmt; - int idx = 1; - - ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL); - if (ret != SQLITE_OK) { - _LOGE("prepare failed: %s", sqlite3_errmsg(db)); - return -1; - } - - __BIND_TEXT(db, stmt, idx++, app->package); - __BIND_TEXT(db, stmt, idx++, locale); - __BIND_TEXT(db, stmt, idx++, app->package); - __BIND_TEXT(db, stmt, idx++, locale); - __BIND_TEXT(db, stmt, idx++, label); - __BIND_TEXT(db, stmt, idx++, app->package); - __BIND_TEXT(db, stmt, idx++, locale); - __BIND_TEXT(db, stmt, idx++, icon); - __BIND_TEXT(db, stmt, idx++, app->package); - __BIND_TEXT(db, stmt, idx++, locale); - __BIND_TEXT(db, stmt, idx++, app->package); - __BIND_TEXT(db, stmt, idx++, locale); - __BIND_TEXT(db, stmt, idx++, app->package); - __BIND_TEXT(db, stmt, idx++, locale); - - ret = sqlite3_step(stmt); - if (ret != SQLITE_DONE) { - _LOGE("step failed: %s", sqlite3_errmsg(db)); - sqlite3_finalize(stmt); - return -1; - } - - sqlite3_finalize(stmt); - - return 0; -} - -static int __insert_app_localized_info(sqlite3 *db, application_x *app) -{ - static const char query[] = - "INSERT INTO package_app_localized_info (app_id, app_locale," - " app_label, app_icon) " - "VALUES (?, ?, ?, ?)"; - int ret; - sqlite3_stmt *stmt; - int idx; - GList *tmp; - GList *locales; - const char *locale; - char *label; - char *icon; - - ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL); - if (ret != SQLITE_OK) { - _LOGE("prepare failed: %s", sqlite3_errmsg(db)); - return -1; - } - - locales = __create_locale_list(app->label, NULL, app->icon, NULL, NULL); - for (tmp = locales; tmp; tmp = tmp->next) { - locale = (const char *)tmp->data; - label = NULL; - icon = NULL; - __extract_data(locale, app->label, NULL, app->icon, NULL, NULL, - &label, NULL, &icon, NULL, NULL); - if (!label && !icon) - continue; - - idx = 1; - __BIND_TEXT(db, stmt, idx++, app->appid); - __BIND_TEXT(db, stmt, idx++, locale); - __BIND_TEXT(db, stmt, idx++, label); - __BIND_TEXT(db, stmt, idx++, icon); - - ret = sqlite3_step(stmt); - if (ret != SQLITE_DONE) { - _LOGE("step failed: %s", sqlite3_errmsg(db)); - g_list_free(locales); - sqlite3_finalize(stmt); - return -1; - } - - sqlite3_reset(stmt); - - if (strcasecmp(app->mainapp, "true") == 0) { - if (__insert_mainapp_localized_info(db, app, locale, - label, icon)) - _LOGE("insert mainapp localized info failed"); - } - } - - g_list_free(locales); - sqlite3_finalize(stmt); - - return 0; -} - -static int __insert_package_privilege_info(sqlite3 *db, manifest_x *mfx) -{ - static const char query[] = - "INSERT INTO package_privilege_info (package, privilege, type) " - "VALUES (?, ?, ?)"; - int ret; - sqlite3_stmt *stmt; - int idx; - GList *tmp; - privilege_x *priv; - - ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL); - if (ret != SQLITE_OK) { - _LOGE("prepare failed: %s", sqlite3_errmsg(db)); - return -1; - } - - for (tmp = mfx->privileges; tmp; tmp = tmp->next) { - priv = (privilege_x *)tmp->data; - if (priv == NULL) - continue; - - idx = 1; - __BIND_TEXT(db, stmt, idx++, mfx->package); - __BIND_TEXT(db, stmt, idx++, priv->value); - __BIND_TEXT(db, stmt, idx++, priv->type); - - ret = sqlite3_step(stmt); - if (ret != SQLITE_DONE) { - _LOGE("step failed: %s", sqlite3_errmsg(db)); - sqlite3_finalize(stmt); - return -1; - } - sqlite3_reset(stmt); - } - - sqlite3_finalize(stmt); - - return 0; -} - -static int __insert_package_plugin_execution_info( - manifest_x *mfx, uid_t uid) -{ - GList *tmp; - plugin_x *plugin; - char **queries = NULL; - int idx = 0; - int i = 0; - - if (!mfx->plugin) - return PM_PARSER_R_OK; - - queries = calloc(g_list_length(mfx->plugin), sizeof (char *)); - if (queries == NULL) { - _LOGE("Out of memory"); - return PM_PARSER_R_ERROR; - } - - for (tmp = mfx->plugin; tmp; tmp = tmp->next) { - plugin = (plugin_x *)tmp->data; - if (plugin == NULL) - continue; - - queries[idx] = sqlite3_mprintf("INSERT INTO package_plugin_info " - "(pkgid, appid, plugin_type, plugin_name) " - "VALUES (%Q, %Q, %Q, %Q)", - plugin->pkgid, plugin->appid, - plugin->plugin_type, plugin->plugin_name); - if (queries[idx] == NULL) { - _LOGE("Out of memory"); - for (i = 0; i < idx; ++i) - sqlite3_free(queries[i]); - free(queries); - return PM_PARSER_R_ERROR; - } - - idx++; - } - - if (_parser_execute_write_queries((const char **)queries, idx, uid) < 0) { - _LOGE("Fail to write to db"); - for (i = 0; i < idx; ++i) - sqlite3_free(queries[i]); - free(queries); - return PM_PARSER_R_ERROR; - } - - for (i = 0; i < idx; ++i) - sqlite3_free(queries[i]); - free(queries); - - return PM_PARSER_R_OK; -} - -static int __delete_package_plugin_execution_info(const char *pkgid, uid_t uid) -{ - char *query = NULL; - - query = sqlite3_mprintf( - "DELETE FROM package_plugin_info WHERE pkgid=%Q", pkgid); - if (query == NULL) { - _LOGE("Out of memory"); - return PM_PARSER_R_ERROR; - } - - if (_parser_execute_write_query(query, uid) < 0) { - _LOGE("Fail to write to db"); - sqlite3_free(query); - return PM_PARSER_R_ERROR; - } - sqlite3_free(query); - - return PM_PARSER_R_OK; -} - -static int __insert_package_appdefined_privilege_info(sqlite3 *db, - manifest_x *mfx) -{ - static const char query[] = - "INSERT INTO package_appdefined_privilege_info " - "(package, privilege, license, type) " - "VALUES (?, ?, ?, ?)"; - int ret; - sqlite3_stmt *stmt; - int idx; - GList *tmp; - appdefined_privilege_x *priv; - - ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL); - if (ret != SQLITE_OK) { - _LOGE("prepare failed: %s", sqlite3_errmsg(db)); - return -1; - } - - for (tmp = mfx->appdefined_privileges; tmp; tmp = tmp->next) { - priv = (appdefined_privilege_x *)tmp->data; - if (priv == NULL) - continue; - - idx = 1; - __BIND_TEXT(db, stmt, idx++, mfx->package); - __BIND_TEXT(db, stmt, idx++, priv->value); - __BIND_TEXT(db, stmt, idx++, priv->license); - __BIND_TEXT(db, stmt, idx++, priv->type); - - ret = sqlite3_step(stmt); - if (ret != SQLITE_DONE) { - _LOGE("step failed: %s", sqlite3_errmsg(db)); - sqlite3_finalize(stmt); - return -1; - } - sqlite3_reset(stmt); - } - - sqlite3_finalize(stmt); - - return 0; -} - -static int __insert_package_dependency_info(sqlite3 *db, manifest_x *mfx) -{ - static const char query[] = - "INSERT INTO package_dependency_info" - " (package, depends_on, type, required_version) " - "VALUES (?, ?, ?, ?)"; - int ret; - sqlite3_stmt *stmt; - int idx; - GList *tmp; - dependency_x *dep; - - ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL); - if (ret != SQLITE_OK) { - _LOGE("prepare failed: %s", sqlite3_errmsg(db)); - return -1; - } - - for (tmp = mfx->dependencies; tmp; tmp = tmp->next) { - dep = (dependency_x *)tmp->data; - if (dep == NULL) - continue; - - idx = 1; - __BIND_TEXT(db, stmt, idx++, mfx->package); - __BIND_TEXT(db, stmt, idx++, dep->depends_on); - __BIND_TEXT(db, stmt, idx++, dep->type); - __BIND_TEXT(db, stmt, idx++, dep->required_version); - - ret = sqlite3_step(stmt); - if (ret != SQLITE_DONE) { - _LOGE("step failed: %s", sqlite3_errmsg(db)); - sqlite3_finalize(stmt); - return -1; - } - sqlite3_reset(stmt); - } - - sqlite3_finalize(stmt); - - return 0; -} - -/* _PRODUCT_LAUNCHING_ENHANCED_ - * app->indicatordisplay, app->portraitimg, app->landscapeimg, - * app->guestmode_appstatus - */ -static int __insert_application_info(sqlite3 *db, manifest_x *mfx) -{ - static const char query[] = - "INSERT INTO package_app_info (app_id, app_component," - " app_exec, app_nodisplay, app_type, app_onboot, app_multiple," - " app_autorestart, app_taskmanage, app_hwacceleration," - " app_screenreader, app_mainapp, app_recentimage," - " app_launchcondition, app_indicatordisplay, app_portraitimg," - " app_landscapeimg, app_guestmodevisibility," - " app_permissiontype, app_preload, app_submode," - " app_submode_mainid, app_installed_storage, app_process_pool," - " app_launch_mode, app_ui_gadget, app_support_mode," - " app_support_disable, component_type, package, app_tep_name," - " app_zip_mount_file, app_background_category," - " app_package_type, app_root_path, app_api_version," - " app_effective_appid, app_splash_screen_display," - " app_package_system, app_removable," - " app_package_installed_time, app_support_ambient," - " app_external_path, app_setup_appid) " - "VALUES (?, ?, " - " ?, LOWER(?), ?, LOWER(?), LOWER(?)," - " LOWER(?), LOWER(?), ?," - " ?, LOWER(?), ?," - " ?, LOWER(?), ?," - " ?, LOWER(?)," - " ?, LOWER(?), LOWER(?)," - " ?, ?, LOWER(?)," - " COALESCE(?, 'single'), LOWER(?), ?," - " LOWER(?), ?, ?, ?," - " ?, ?," - " ?, ?, ?," - " ?, LOWER(?)," - " LOWER(?), LOWER(?)," - " ?, LOWER(?)," - " ?, ?)"; - int ret; - sqlite3_stmt *stmt; - int idx; - GList *tmp; - application_x *app; - int bg_category; - const char *effective_appid; - GList *ss_list; - - ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL); - if (ret != SQLITE_OK) { - _LOGE("prepare failed: %s", sqlite3_errmsg(db)); - return -1; - } - - for (tmp = mfx->application; tmp; tmp = tmp->next) { - app = (application_x *)tmp->data; - if (app == NULL) - continue; - - bg_category = __convert_background_category( - app->background_category); - effective_appid = __find_effective_appid(app->metadata); - - idx = 1; - __BIND_TEXT(db, stmt, idx++, app->appid); - __BIND_TEXT(db, stmt, idx++, app->component_type); - __BIND_TEXT(db, stmt, idx++, app->exec); - __BIND_TEXT(db, stmt, idx++, __get_bool(app->nodisplay, false)); - __BIND_TEXT(db, stmt, idx++, app->type); - __BIND_TEXT(db, stmt, idx++, __get_bool(app->onboot, false)); - __BIND_TEXT(db, stmt, idx++, __get_bool(app->multiple, false)); - __BIND_TEXT(db, stmt, idx++, - __get_bool(app->autorestart, false)); - __BIND_TEXT(db, stmt, idx++, - __get_bool(app->taskmanage, false)); - __BIND_TEXT(db, stmt, idx++, app->hwacceleration); - __BIND_TEXT(db, stmt, idx++, app->screenreader); - __BIND_TEXT(db, stmt, idx++, __get_bool(app->mainapp, false)); - __BIND_TEXT(db, stmt, idx++, app->recentimage); - __BIND_TEXT(db, stmt, idx++, app->launchcondition); - __BIND_TEXT(db, stmt, idx++, - __get_bool(app->indicatordisplay, true)); - __BIND_TEXT(db, stmt, idx++, app->portraitimg); - __BIND_TEXT(db, stmt, idx++, app->landscapeimg); - __BIND_TEXT(db, stmt, idx++, - __get_bool(app->guestmode_visibility, true)); - __BIND_TEXT(db, stmt, idx++, app->permission_type); - __BIND_TEXT(db, stmt, idx++, __get_bool(mfx->preload, false)); - __BIND_TEXT(db, stmt, idx++, __get_bool(app->submode, false)); - __BIND_TEXT(db, stmt, idx++, app->submode_mainid); - __BIND_TEXT(db, stmt, idx++, mfx->installed_storage); - __BIND_TEXT(db, stmt, idx++, - __get_bool(app->process_pool, false)); - __BIND_TEXT(db, stmt, idx++, app->launch_mode); - __BIND_TEXT(db, stmt, idx++, __get_bool(app->ui_gadget, false)); - __BIND_TEXT(db, stmt, idx++, - app->support_mode ? app->support_mode : "0"); - __BIND_TEXT(db, stmt, idx++, - __get_bool(mfx->support_disable, false)); - __BIND_TEXT(db, stmt, idx++, app->component_type); - __BIND_TEXT(db, stmt, idx++, mfx->package); - __BIND_TEXT(db, stmt, idx++, mfx->tep_name); - __BIND_TEXT(db, stmt, idx++, mfx->zip_mount_file); - __BIND_INT(db, stmt, idx++, bg_category); - __BIND_TEXT(db, stmt, idx++, mfx->type ? mfx->type : "tpk"); - __BIND_TEXT(db, stmt, idx++, mfx->root_path); - __BIND_TEXT(db, stmt, idx++, app->api_version); - __BIND_TEXT(db, stmt, idx++, effective_appid); - __BIND_TEXT(db, stmt, idx++, - __get_bool(app->splash_screen_display, true)); - __BIND_TEXT(db, stmt, idx++, __get_bool(mfx->system, false)); - __BIND_TEXT(db, stmt, idx++, __get_bool(mfx->removable, false)); - __BIND_TEXT(db, stmt, idx++, mfx->installed_time); - __BIND_TEXT(db, stmt, idx++, - __get_bool(app->support_ambient, false)); - __BIND_TEXT(db, stmt, idx++, mfx->external_path); - __BIND_TEXT(db, stmt, idx++, app->setup_appid); - - ret = sqlite3_step(stmt); - if (ret != SQLITE_DONE) { - _LOGE("step failed: %s", sqlite3_errmsg(db)); - sqlite3_finalize(stmt); - return -1; - } - - sqlite3_reset(stmt); - - if (__insert_appcontrol_info(db, app)) { - sqlite3_finalize(stmt); - return -1; - } - if (__insert_category_info(db, app)) { - sqlite3_finalize(stmt); - return -1; - } - if (__insert_metadata_info(db, app)) { - sqlite3_finalize(stmt); - return -1; - } - if (__insert_datacontrol_info(db, app)) { - sqlite3_finalize(stmt); - return -1; - } - ss_list = __find_splashscreens(app->splashscreens); - if (__insert_splashscreen_info(db, app, ss_list)) { - g_list_free(ss_list); - sqlite3_finalize(stmt); - return -1; - } - g_list_free(ss_list); - if (__insert_app_localized_info(db, app)) { - sqlite3_finalize(stmt); - return -1; - } - } - - sqlite3_finalize(stmt); - - return 0; -} - -static int __insert_package_update_info(sqlite3 *db, manifest_x *mfx) -{ - static const char query[] = - "INSERT INTO package_update_info (package, update_version) " - "VALUES (?, ?)"; - int ret; - int idx; - sqlite3_stmt *stmt; - - ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL); - if (ret != SQLITE_OK) { - _LOGE("prepare failed: %s", sqlite3_errmsg(db)); - return -1; - } - - idx = 1; - __BIND_TEXT(db, stmt, idx++, mfx->package); - __BIND_TEXT(db, stmt, idx, mfx->version); - ret = sqlite3_step(stmt); - if (ret != SQLITE_DONE) { - _LOGE("step failed: %s", sqlite3_errmsg(db)); - sqlite3_finalize(stmt); - return -1; - } - sqlite3_finalize(stmt); - - return 0; -} - -static int __insert_package_localized_info(sqlite3 *db, manifest_x *mfx) -{ - static const char query[] = - "INSERT INTO package_localized_info (package, package_locale," - " package_label, package_icon, package_description," - " package_license, package_author) " - "VALUES (?, ?, ?, ?, ?, ?, ?)"; - int ret; - sqlite3_stmt *stmt; - int idx; - GList *tmp; - GList *locales; - const char *locale; - char *label; - char *icon; - char *description; - char *license; - char *author; - - ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL); - if (ret != SQLITE_OK) { - _LOGE("prepare failed: %s", sqlite3_errmsg(db)); - return -1; - } - - locales = __create_locale_list(mfx->label, mfx->license, mfx->icon, - mfx->description, mfx->author); - for (tmp = locales; tmp; tmp = tmp->next) { - locale = (const char *)tmp->data; - label = NULL; - icon = NULL; - description = NULL; - license = NULL; - author = NULL; - __extract_data(locale, mfx->label, mfx->license, mfx->icon, - mfx->description, mfx->author, - &label, &license, &icon, &description, &author); - if (!label && !license && !icon && !description && !author) - continue; - - idx = 1; - __BIND_TEXT(db, stmt, idx++, mfx->package); - __BIND_TEXT(db, stmt, idx++, locale); - __BIND_TEXT(db, stmt, idx++, label); - __BIND_TEXT(db, stmt, idx++, icon); - __BIND_TEXT(db, stmt, idx++, description); - __BIND_TEXT(db, stmt, idx++, license); - __BIND_TEXT(db, stmt, idx++, author); - - ret = sqlite3_step(stmt); - if (ret != SQLITE_DONE) { - _LOGE("step failed: %s", sqlite3_errmsg(db)); - g_list_free(locales); - sqlite3_finalize(stmt); - return -1; - } - - sqlite3_reset(stmt); - } - - g_list_free(locales); - sqlite3_finalize(stmt); - - return 0; -} - -static int __insert_package_info(sqlite3 *db, manifest_x *mfx) -{ - static const char query[] = - "INSERT INTO package_info (package, package_type," - " package_version, package_api_version, package_tep_name," - " package_zip_mount_file, install_location, package_size," - " package_removable, package_preload, package_readonly," - " package_update, package_appsetting, package_nodisplay," - " package_system, author_name, author_email, author_href," - " installed_time, installed_storage, storeclient_id," - " mainapp_id, package_url, root_path, external_path," - " csc_path, package_support_mode, package_support_disable) " - "VALUES (?, ?," - " ?, ?, ?," - " ?, ?, ?," - " LOWER(?), LOWER(?), LOWER(?)," - " LOWER(?), LOWER(?), LOWER(?)," - " LOWER(?), ?, ?, ?," - " ?, ?, ?," - " ?, ?, ?, ?," - " ?, ?, LOWER(?))"; - int ret; - sqlite3_stmt *stmt; - int idx = 1; - const char *author_name = NULL; - const char *author_email = NULL; - const char *author_href = NULL; - - ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL); - if (ret != SQLITE_OK) { - _LOGE("prepare failed: %s", sqlite3_errmsg(db)); - return -1; - } - - if (mfx->author && mfx->author->data) { - author_name = ((author_x *)mfx->author->data)->text; - author_email = ((author_x *)mfx->author->data)->email; - author_href = ((author_x *)mfx->author->data)->href; - } - - __BIND_TEXT(db, stmt, idx++, mfx->package); - __BIND_TEXT(db, stmt, idx++, mfx->type); - __BIND_TEXT(db, stmt, idx++, mfx->version); - __BIND_TEXT(db, stmt, idx++, mfx->api_version); - __BIND_TEXT(db, stmt, idx++, mfx->tep_name); - __BIND_TEXT(db, stmt, idx++, mfx->zip_mount_file); - __BIND_TEXT(db, stmt, idx++, mfx->installlocation); - __BIND_TEXT(db, stmt, idx++, mfx->package_size); - __BIND_TEXT(db, stmt, idx++, __get_bool(mfx->removable, true)); - __BIND_TEXT(db, stmt, idx++, __get_bool(mfx->preload, false)); - __BIND_TEXT(db, stmt, idx++, __get_bool(mfx->readonly, false)); - __BIND_TEXT(db, stmt, idx++, __get_bool(mfx->update, false)); - __BIND_TEXT(db, stmt, idx++, __get_bool(mfx->appsetting, false)); - __BIND_TEXT(db, stmt, idx++, __get_bool(mfx->nodisplay_setting, false)); - __BIND_TEXT(db, stmt, idx++, __get_bool(mfx->system, false)); - __BIND_TEXT(db, stmt, idx++, author_name); - __BIND_TEXT(db, stmt, idx++, author_email); - __BIND_TEXT(db, stmt, idx++, author_href); - __BIND_TEXT(db, stmt, idx++, mfx->installed_time); - __BIND_TEXT(db, stmt, idx++, mfx->installed_storage); - __BIND_TEXT(db, stmt, idx++, mfx->storeclient_id); - __BIND_TEXT(db, stmt, idx++, mfx->mainapp_id); - __BIND_TEXT(db, stmt, idx++, mfx->package_url); - __BIND_TEXT(db, stmt, idx++, mfx->root_path); - __BIND_TEXT(db, stmt, idx++, mfx->external_path); - __BIND_TEXT(db, stmt, idx++, mfx->csc_path); - __BIND_TEXT(db, stmt, idx++, - mfx->support_mode ? mfx->support_mode : "0"); - __BIND_TEXT(db, stmt, idx++, __get_bool(mfx->support_disable, false)); - - ret = sqlite3_step(stmt); - if (ret != SQLITE_DONE) { - _LOGE("step failed: %s", sqlite3_errmsg(db)); - sqlite3_finalize(stmt); - return -1; - } - - sqlite3_finalize(stmt); - - if (__insert_package_update_info(db, mfx)) - return -1; - if (__insert_package_localized_info(db, mfx)) - return -1; - if (__insert_application_info(db, mfx)) - return -1; - if (__insert_package_privilege_info(db, mfx)) - return -1; - if (__insert_package_appdefined_privilege_info(db, mfx)) - return -1; - if (__insert_package_dependency_info(db, mfx)) - return -1; - - return 0; -} - -static int __delete_package_info(sqlite3 *db, const char *pkgid) -{ - static const char query[] = - "DELETE FROM package_info WHERE package=?"; - int ret; - sqlite3_stmt *stmt; - - ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL); - if (ret != SQLITE_OK) { - _LOGE("prepare failed: %s", sqlite3_errmsg(db)); - return -1; - } - - __BIND_TEXT(db, stmt, 1, pkgid); - - ret = sqlite3_step(stmt); - if (ret != SQLITE_DONE) { - _LOGE("step failed: %s", sqlite3_errmsg(db)); - sqlite3_finalize(stmt); - return -1; - } - - sqlite3_finalize(stmt); - - return 0; -} - -API int pkgmgr_parser_insert_pkg_info(sqlite3 *db, manifest_x *mfx, uid_t uid) -{ - if (db == NULL || mfx == NULL) { - _LOGE("invalid parameter"); - return PM_PARSER_R_EINVAL; - } - - __BEGIN_TRANSACTION(db); - __DO_TRANSACTION(db, __insert_package_info(db, mfx)); - __END_TRANSACTION(db); - - sqlite3_close_v2(db); - - return PM_PARSER_R_OK; -} - -API int pkgmgr_parser_update_pkg_info(sqlite3 *db, manifest_x *mfx, uid_t uid) -{ - if (db == NULL || mfx == NULL) { - _LOGE("invalid parameter"); - return PM_PARSER_R_EINVAL; - } - - __BEGIN_TRANSACTION(db); - __DO_TRANSACTION(db, __delete_package_info(db, mfx->package)); - __DO_TRANSACTION(db, __insert_package_info(db, mfx)); - __END_TRANSACTION(db); - - sqlite3_close_v2(db); - - return PM_PARSER_R_OK; -} - -API int pkgmgr_parser_insert_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid) -{ - if (_parser_insert_manifest_info(mfx, uid) < 0) { - _LOGE("Fail to insert manifest uid[%d]", uid); - return PM_PARSER_R_ERROR; - } - - return PM_PARSER_R_OK; -} - -API int pkgmgr_parser_insert_manifest_info_in_db(manifest_x *mfx) +API int pkgmgr_parser_insert_manifest_info_in_db(manifest_x *mfx) { return pkgmgr_parser_insert_manifest_info_in_usr_db(mfx, __getuid()); } -API int pkgmgr_parser_delete_pkg_info(sqlite3 *db, const char *package, uid_t uid) -{ - if (db == NULL || package == NULL) { - _LOGE("invalid parameter"); - return PM_PARSER_R_EINVAL; - } - - __BEGIN_TRANSACTION(db); - __DO_TRANSACTION(db, __delete_package_info(db, package)); - __END_TRANSACTION(db); - - return PM_PARSER_R_OK; -} - API int pkgmgr_parser_delete_manifest_info_from_usr_db(manifest_x *mfx, uid_t uid) { diff --git a/src/common/database/pkg_set_db_handler.cc b/src/common/database/pkg_set_db_handler.cc index cda746ce..b07231ee 100644 --- a/src/common/database/pkg_set_db_handler.cc +++ b/src/common/database/pkg_set_db_handler.cc @@ -20,7 +20,7 @@ #include #include "pkgmgrinfo_debug.h" -#include "pkgmgr_parser_db.h" +#include "pkgmgrinfo_internal.h" namespace pkgmgr_common { namespace database { diff --git a/src/pkginfo_internal.c b/src/pkginfo_internal.c index 541276fa..a06c5d98 100644 --- a/src/pkginfo_internal.c +++ b/src/pkginfo_internal.c @@ -15,6 +15,9 @@ #include #include +#include + +#include "pkgmgr_parser.h" #include "pkgmgrinfo_basic.h" #include "pkgmgrinfo_private.h" #include "pkgmgrinfo_debug.h" @@ -54,6 +57,41 @@ do { \ } \ } while (0) \ +#define __BIND_TEXT(db, stmt, i, text) \ +do { \ + if (sqlite3_bind_text(stmt, i, text, -1, SQLITE_STATIC) != SQLITE_OK) {\ + _LOGE("bind error(index %d): %s", i, sqlite3_errmsg(db)); \ + sqlite3_finalize(stmt); \ + return -1; \ + } \ +} while (0) + +#define __BIND_INT(db, stmt, i, int) \ +do { \ + if (sqlite3_bind_int(stmt, i, int) != SQLITE_OK) { \ + _LOGE("bind error(index %d): %s", i, sqlite3_errmsg(db)); \ + sqlite3_finalize(stmt); \ + return -1; \ + } \ +} while (0) + +#define LDPI "ldpi" +#define MDPI "mdpi" +#define HDPI "hdpi" +#define XHDPI "xhdpi" +#define XXHDPI "xxhdpi" + +#define LDPI_MIN 0 +#define LDPI_MAX 240 +#define MDPI_MIN 241 +#define MDPI_MAX 300 +#define HDPI_MIN 301 +#define HDPI_MAX 380 +#define XHDPI_MIN 381 +#define XHDPI_MAX 480 +#define XXHDPI_MIN 481 +#define XXHDPI_MAX 600 + static int __free_packages(gpointer key, gpointer value, gpointer user_data) { @@ -782,4 +820,1595 @@ API int execute_write_queries(sqlite3 *db, const char **queries, int len) { // sqlite3_close_v2(db); return 0; +} + +/*###############################################################################*/ + +static int __check_dpi(const char *dpi_char, int dpi_int) +{ + if (dpi_char == NULL) + return -1; + + if (strcasecmp(dpi_char, LDPI) == 0) { + if (dpi_int >= LDPI_MIN && dpi_int <= LDPI_MAX) + return 0; + else + return -1; + } else if (strcasecmp(dpi_char, MDPI) == 0) { + if (dpi_int >= MDPI_MIN && dpi_int <= MDPI_MAX) + return 0; + else + return -1; + } else if (strcasecmp(dpi_char, HDPI) == 0) { + if (dpi_int >= HDPI_MIN && dpi_int <= HDPI_MAX) + return 0; + else + return -1; + } else if (strcasecmp(dpi_char, XHDPI) == 0) { + if (dpi_int >= XHDPI_MIN && dpi_int <= XHDPI_MAX) + return 0; + else + return -1; + } else if (strcasecmp(dpi_char, XXHDPI) == 0) { + if (dpi_int >= XXHDPI_MIN && dpi_int <= XXHDPI_MAX) + return 0; + else + return -1; + } else + return -1; +} + +static void __find_appcontrol_splashscreen_with_dpi(gpointer data, + gpointer user_data) +{ + splashscreen_x *ss = (splashscreen_x *)data; + GList **list = (GList **)user_data; + int dpi = -1; + int ret; + + if (ss->operation == NULL || ss->dpi == NULL) + return; + + ret = system_info_get_platform_int( + "http://tizen.org/feature/screen.dpi", &dpi); + if (ret != SYSTEM_INFO_ERROR_NONE) + return; + + if (__check_dpi(ss->dpi, dpi) != 0) + return; + + *list = g_list_prepend(*list, ss); +} + +static void __find_appcontrol_splashscreen(gpointer data, gpointer user_data) +{ + splashscreen_x *ss = (splashscreen_x *)data; + GList **list = (GList **)user_data; + splashscreen_x *ss_tmp; + GList *tmp; + + if (ss->operation == NULL || ss->dpi) + return; + + for (tmp = *list; tmp; tmp = tmp->next) { + ss_tmp = (splashscreen_x *)tmp->data; + if (ss_tmp->operation + && strcmp(ss_tmp->operation, ss->operation) == 0 + && strcmp(ss_tmp->orientation, ss->orientation) == 0) + return; + } + + *list = g_list_prepend(*list, ss); +} + +static gint __compare_splashscreen_with_orientation_dpi(gconstpointer a, + gconstpointer b) +{ + splashscreen_x *ss = (splashscreen_x *)a; + const char *orientation = (const char *)b; + int dpi = -1; + int ret; + + if (ss->operation || ss->dpi == NULL) + return -1; + + ret = system_info_get_platform_int( + "http://tizen.org/feature/screen.dpi", &dpi); + if (ret != SYSTEM_INFO_ERROR_NONE) + return -1; + + if (strcasecmp(ss->orientation, orientation) == 0 && + __check_dpi(ss->dpi, dpi) == 0) + return 0; + + return -1; +} + +static gint __compare_splashscreen_with_orientation(gconstpointer a, + gconstpointer b) +{ + splashscreen_x *ss = (splashscreen_x *)a; + const char *orientation = (const char *)b; + + if (ss->operation || ss->dpi) + return -1; + + if (strcasecmp(ss->orientation, orientation) == 0) + return 0; + + return -1; +} + +static splashscreen_x *__find_default_splashscreen(GList *splashscreens, + const char *orientation) +{ + GList *tmp; + + tmp = g_list_find_custom(splashscreens, orientation, + (GCompareFunc) + __compare_splashscreen_with_orientation_dpi); + if (tmp) + return (splashscreen_x *)tmp->data; + + tmp = g_list_find_custom(splashscreens, orientation, + (GCompareFunc)__compare_splashscreen_with_orientation); + if (tmp) + return (splashscreen_x *)tmp->data; + + return NULL; +} + +static GList *__find_splashscreens(GList *splashscreens) +{ + GList *list = NULL; + splashscreen_x *ss; + + if (splashscreens == NULL) + return NULL; + + g_list_foreach(splashscreens, + __find_appcontrol_splashscreen_with_dpi, &list); + g_list_foreach(splashscreens, + __find_appcontrol_splashscreen, &list); + + ss = __find_default_splashscreen(splashscreens, "portrait"); + if (ss) + list = g_list_prepend(list, ss); + ss = __find_default_splashscreen(splashscreens, "landscape"); + if (ss) + list = g_list_prepend(list, ss); + + return list; +} + +static int __insert_splashscreen_info(sqlite3 *db, application_x *app, + GList *ss_list) +{ + static const char query[] = + "INSERT INTO package_app_splash_screen (app_id, src, type," + " orientation, indicatordisplay, operation, color_depth) " + "VALUES (?, ?, ?, ?, ?, ?, ?)"; + int ret; + sqlite3_stmt *stmt; + int idx; + GList *tmp; + splashscreen_x *ss; + + if (app->splashscreens == NULL) + return 0; + + if (ss_list == NULL) + return 0; + + ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL); + if (ret != SQLITE_OK) { + _LOGE("prepare failed: %s", sqlite3_errmsg(db)); + return -1; + } + + for (tmp = ss_list; tmp; tmp = tmp->next) { + ss = (splashscreen_x *)tmp->data; + if (ss == NULL) + continue; + idx = 1; + __BIND_TEXT(db, stmt, idx++, app->appid); + __BIND_TEXT(db, stmt, idx++, ss->src); + __BIND_TEXT(db, stmt, idx++, ss->type); + __BIND_TEXT(db, stmt, idx++, ss->orientation); + __BIND_TEXT(db, stmt, idx++, ss->indicatordisplay); + __BIND_TEXT(db, stmt, idx++, ss->operation); + __BIND_TEXT(db, stmt, idx++, ss->color_depth); + + ret = sqlite3_step(stmt); + if (ret != SQLITE_DONE) { + _LOGE("step failed: %s", sqlite3_errmsg(db)); + sqlite3_finalize(stmt); + return -1; + } + + sqlite3_reset(stmt); + } + + sqlite3_finalize(stmt); + + return 0; +} + +static void __trimfunc(GList *trim_list) +{ + char *trim_data; + char *prev = NULL; + GList *list = g_list_first(trim_list); + + while (list) { + trim_data = (char *)list->data; + if (trim_data) { + if (prev) { + if (strcmp(trim_data, prev) == 0) { + trim_list = g_list_remove(trim_list, + trim_data); + list = g_list_first(trim_list); + prev = NULL; + continue; + } else + prev = trim_data; + } else { + prev = trim_data; + } + } + list = g_list_next(list); + } +} + +static int __insert_package_appdefined_privilege_info(sqlite3 *db, + manifest_x *mfx) +{ + static const char query[] = + "INSERT INTO package_appdefined_privilege_info " + "(package, privilege, license, type) " + "VALUES (?, ?, ?, ?)"; + int ret; + sqlite3_stmt *stmt; + int idx; + GList *tmp; + appdefined_privilege_x *priv; + + ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL); + if (ret != SQLITE_OK) { + _LOGE("prepare failed: %s", sqlite3_errmsg(db)); + return -1; + } + + for (tmp = mfx->appdefined_privileges; tmp; tmp = tmp->next) { + priv = (appdefined_privilege_x *)tmp->data; + if (priv == NULL) + continue; + + idx = 1; + __BIND_TEXT(db, stmt, idx++, mfx->package); + __BIND_TEXT(db, stmt, idx++, priv->value); + __BIND_TEXT(db, stmt, idx++, priv->license); + __BIND_TEXT(db, stmt, idx++, priv->type); + + ret = sqlite3_step(stmt); + if (ret != SQLITE_DONE) { + _LOGE("step failed: %s", sqlite3_errmsg(db)); + sqlite3_finalize(stmt); + return -1; + } + sqlite3_reset(stmt); + } + + sqlite3_finalize(stmt); + + return 0; +} + +static int __insert_package_dependency_info(sqlite3 *db, manifest_x *mfx) +{ + static const char query[] = + "INSERT INTO package_dependency_info" + " (package, depends_on, type, required_version) " + "VALUES (?, ?, ?, ?)"; + int ret; + sqlite3_stmt *stmt; + int idx; + GList *tmp; + dependency_x *dep; + + ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL); + if (ret != SQLITE_OK) { + _LOGE("prepare failed: %s", sqlite3_errmsg(db)); + return -1; + } + + for (tmp = mfx->dependencies; tmp; tmp = tmp->next) { + dep = (dependency_x *)tmp->data; + if (dep == NULL) + continue; + + idx = 1; + __BIND_TEXT(db, stmt, idx++, mfx->package); + __BIND_TEXT(db, stmt, idx++, dep->depends_on); + __BIND_TEXT(db, stmt, idx++, dep->type); + __BIND_TEXT(db, stmt, idx++, dep->required_version); + + ret = sqlite3_step(stmt); + if (ret != SQLITE_DONE) { + _LOGE("step failed: %s", sqlite3_errmsg(db)); + sqlite3_finalize(stmt); + return -1; + } + sqlite3_reset(stmt); + } + + sqlite3_finalize(stmt); + + return 0; +} + +static int __insert_mainapp_localized_info(sqlite3 *db, application_x *app, + const char *locale, const char *label, const char *icon) +{ + static const char query[] = + "INSERT OR REPLACE INTO package_localized_info (" + " package, package_locale, package_label, package_icon," + " package_description, package_license, package_author) " + "VALUES (?, ?," + " COALESCE((SELECT package_label FROM package_localized_info" + " WHERE package=? AND package_locale=?), ?)," + " COALESCE((SELECT package_icon FROM package_localized_info" + " WHERE package=? AND package_icon=?), ?)," + " (SELECT package_description FROM package_localized_info" + " WHERE package=? AND package_locale=?)," + " (SELECT package_description FROM package_localized_info" + " WHERE package=? AND package_locale=?)," + " (SELECT package_description FROM package_localized_info" + " WHERE package=? AND package_locale=?))"; + int ret; + sqlite3_stmt *stmt; + int idx = 1; + + ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL); + if (ret != SQLITE_OK) { + _LOGE("prepare failed: %s", sqlite3_errmsg(db)); + return -1; + } + + __BIND_TEXT(db, stmt, idx++, app->package); + __BIND_TEXT(db, stmt, idx++, locale); + __BIND_TEXT(db, stmt, idx++, app->package); + __BIND_TEXT(db, stmt, idx++, locale); + __BIND_TEXT(db, stmt, idx++, label); + __BIND_TEXT(db, stmt, idx++, app->package); + __BIND_TEXT(db, stmt, idx++, locale); + __BIND_TEXT(db, stmt, idx++, icon); + __BIND_TEXT(db, stmt, idx++, app->package); + __BIND_TEXT(db, stmt, idx++, locale); + __BIND_TEXT(db, stmt, idx++, app->package); + __BIND_TEXT(db, stmt, idx++, locale); + __BIND_TEXT(db, stmt, idx++, app->package); + __BIND_TEXT(db, stmt, idx++, locale); + + ret = sqlite3_step(stmt); + if (ret != SQLITE_DONE) { + _LOGE("step failed: %s", sqlite3_errmsg(db)); + sqlite3_finalize(stmt); + return -1; + } + + sqlite3_finalize(stmt); + + return 0; +} + +static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata) +{ + if (a == NULL || b == NULL) + return 0; + if (strcmp((char *)a, (char *)b) == 0) + return 0; + if (strcmp((char *)a, (char *)b) < 0) + return -1; + if (strcmp((char *)a, (char *)b) > 0) + return 1; + return 0; +} + +static GList *__create_locale_list(GList *lbls, GList *lcns, GList *icns, + GList *dcns, GList *aths) +{ + GList *locale = NULL; + GList *tmp; + label_x *lbl; + license_x *lcn; + icon_x *icn; + description_x *dcn; + author_x *ath; + + for (tmp = lbls; tmp; tmp = tmp->next) { + lbl = (label_x *)tmp->data; + if (lbl == NULL) + continue; + if (lbl->lang) + locale = g_list_insert_sorted_with_data( + locale, (gpointer)lbl->lang, + __comparefunc, NULL); + } + for (tmp = lcns; tmp; tmp = tmp->next) { + lcn = (license_x *)tmp->data; + if (lcn == NULL) + continue; + if (lcn->lang) + locale = g_list_insert_sorted_with_data( + locale, (gpointer)lcn->lang, + __comparefunc, NULL); + } + for (tmp = icns; tmp; tmp = tmp->next) { + icn = (icon_x *)tmp->data; + if (icn == NULL) + continue; + if (icn->lang) + locale = g_list_insert_sorted_with_data( + locale, (gpointer)icn->lang, + __comparefunc, NULL); + } + for (tmp = dcns; tmp; tmp = tmp->next) { + dcn = (description_x *)tmp->data; + if (dcn == NULL) + continue; + if (dcn->lang) + locale = g_list_insert_sorted_with_data( + locale, (gpointer)dcn->lang, + __comparefunc, NULL); + } + for (tmp = aths; tmp; tmp = tmp->next) { + ath = (author_x *)tmp->data; + if (ath == NULL) + continue; + if (ath->lang) + locale = g_list_insert_sorted_with_data( + locale, (gpointer)ath->lang, + __comparefunc, NULL); + } + __trimfunc(locale); + return locale; +} + +static gint __check_icon_resolution(const char *orig_icon_path, + char **new_icon_path) +{ + int ret; + char *dpi_path[2]; + char *icon_filename; + char modified_iconpath[BUFSIZE]; + char icon_path[BUFSIZE]; + int i; + int dpi = -1; + + if (orig_icon_path == NULL) + return -1; + + ret = system_info_get_platform_int( + "http://tizen.org/feature/screen.dpi", &dpi); + if (ret != SYSTEM_INFO_ERROR_NONE) + return -1; + + if (dpi >= LDPI_MIN && dpi <= LDPI_MAX) { + dpi_path[0] = "LDPI"; + dpi_path[1] = "ldpi"; + } else if (dpi >= MDPI_MIN && dpi <= MDPI_MAX) { + dpi_path[0] = "MDPI"; + dpi_path[1] = "mdpi"; + } else if (dpi >= HDPI_MIN && dpi <= HDPI_MAX) { + dpi_path[0] = "HDPI"; + dpi_path[1] = "hdpi"; + } else if (dpi >= XHDPI_MIN && dpi <= XHDPI_MAX) { + dpi_path[0] = "XHDPI"; + dpi_path[1] = "xhdpi"; + } else if (dpi >= XXHDPI_MIN && dpi <= XXHDPI_MAX) { + dpi_path[0] = "XXHDPI"; + dpi_path[1] = "xxhdpi"; + } else { + _LOGE("Unidentified dpi[%d]", dpi); + return -1; + } + + icon_filename = strrchr(orig_icon_path, '/'); + if (icon_filename == NULL) + return -1; + + snprintf(icon_path, + strlen(orig_icon_path) - (strlen(icon_filename) - 1), + "%s", orig_icon_path); + for (i = 0; i < 2; i++) { + ret = snprintf(modified_iconpath, BUFSIZE - 1, "%s/%s%s", + icon_path, dpi_path[i], icon_filename); + if (ret < 0 || ret > BUFSIZE -1) { + _LOGE("snprintf fail"); + return -1; + } + if (access(modified_iconpath, F_OK) != -1) { + /* if exists, return modified icon path */ + *new_icon_path = strdup(modified_iconpath); + return 0; + } + } + + return -1; +} + +static gint __compare_icon(gconstpointer a, gconstpointer b) +{ + icon_x *icon = (icon_x *)a; + char *icon_path; + + if (icon->lang != NULL && strcasecmp(icon->lang, DEFAULT_LOCALE) != 0) + return -1; + + if (icon->dpi != NULL) + return -1; + + if (__check_icon_resolution(icon->text, &icon_path) == 0) { + free(icon->text); + icon->text = icon_path; + } + + return 0; +} + +static gint __compare_icon_with_lang(gconstpointer a, gconstpointer b) +{ + icon_x *icon = (icon_x *)a; + char *lang = (char *)b; + char *icon_path; + + if (icon->dpi != NULL) + return -1; + + if (strcasecmp(icon->lang, lang) == 0) { + if (strcasecmp(icon->lang, DEFAULT_LOCALE) == 0) { + /* icon for no locale. check existance of + * folder-hierachied default icons + */ + if (__check_icon_resolution(icon->text, + &icon_path) == 0) { + free(icon->text); + icon->text = icon_path; + } + } + return 0; + } + + return -1; +} + +static gint __compare_icon_with_dpi(gconstpointer a, gconstpointer b) +{ + icon_x *icon = (icon_x *)a; + int dpi = GPOINTER_TO_INT(b); + + if (icon->lang != NULL && strcasecmp(icon->lang, DEFAULT_LOCALE) != 0) + return -1; + + if (icon->dpi == NULL) + return -1; + + if (__check_dpi(icon->dpi, dpi) == 0) + return 0; + + return -1; +} + +static gint __compare_icon_with_lang_dpi(gconstpointer a, gconstpointer b) +{ + int ret; + icon_x *icon = (icon_x *)a; + char *lang = (char *)b; + int dpi = -1; + + ret = system_info_get_platform_int( + "http://tizen.org/feature/screen.dpi", &dpi); + if (ret != SYSTEM_INFO_ERROR_NONE) + return -1; + + if (strcasecmp(icon->lang, lang) == 0 && + __check_dpi(icon->dpi, dpi) == 0) + return 0; + + return -1; +} + +static char *__find_icon(GList *icons, const char *lang) +{ + GList *tmp; + icon_x *icon; + int dpi = 0; + int ret; + + /* first, find icon whose locale and dpi with given lang and + * system's dpi has matched + */ + tmp = g_list_find_custom(icons, lang, + (GCompareFunc)__compare_icon_with_lang_dpi); + if (tmp != NULL) { + icon = (icon_x *)tmp->data; + return (char *)icon->text; + } + + /* if first has failed, find icon whose locale has matched */ + tmp = g_list_find_custom(icons, lang, + (GCompareFunc)__compare_icon_with_lang); + if (tmp != NULL) { + icon = (icon_x *)tmp->data; + return (char *)icon->text; + } + + /* if second has failed, find icon whose dpi has matched with + * system's dpi + */ + ret = system_info_get_platform_int( + "http://tizen.org/feature/screen.dpi", &dpi); + if (ret == SYSTEM_INFO_ERROR_NONE) { + tmp = g_list_find_custom(icons, GINT_TO_POINTER(dpi), + (GCompareFunc)__compare_icon_with_dpi); + if (tmp != NULL) { + icon = (icon_x *)tmp->data; + return (char *)icon->text; + } + } + + /* last, find default icon marked as "No Locale" */ + tmp = g_list_find_custom(icons, NULL, (GCompareFunc)__compare_icon); + if (tmp != NULL) { + icon = (icon_x *)tmp->data; + return (char *)icon->text; + } + + return NULL; +} + +static void __extract_data(const char *locale, GList *lbls, GList *lcns, + GList *icns, GList *dcns, GList *aths, char **label, + char **license, char **icon, char **description, char **author) +{ + GList *tmp; + label_x *lbl; + license_x *lcn; + description_x *dcn; + author_x *ath; + + for (tmp = lbls; tmp; tmp = tmp->next) { + lbl = (label_x *)tmp->data; + if (lbl == NULL) + continue; + if (lbl->lang) { + if (strcmp(lbl->lang, locale) == 0) { + *label = (char *)lbl->text; + break; + } + } + } + for (tmp = lcns; tmp; tmp = tmp->next) { + lcn = (license_x *)tmp->data; + if (lcn == NULL) + continue; + if (lcn->lang) { + if (strcmp(lcn->lang, locale) == 0) { + *license = (char *)lcn->text; + break; + } + } + } + + *icon = __find_icon(icns, locale); + + for (tmp = dcns; tmp; tmp = tmp->next) { + dcn = (description_x *)tmp->data; + if (dcn == NULL) + continue; + if (dcn->lang) { + if (strcmp(dcn->lang, locale) == 0) { + *description = (char *)dcn->text; + break; + } + } + } + for (tmp = aths; tmp; tmp = tmp->next) { + ath = (author_x *)tmp->data; + if (ath == NULL) + continue; + if (ath->lang) { + if (strcmp(ath->lang, locale) == 0) { + *author = (char *)ath->text; + break; + } + } + } +} + +static int __insert_app_localized_info(sqlite3 *db, application_x *app) +{ + static const char query[] = + "INSERT INTO package_app_localized_info (app_id, app_locale," + " app_label, app_icon) " + "VALUES (?, ?, ?, ?)"; + int ret; + sqlite3_stmt *stmt; + int idx; + GList *tmp; + GList *locales; + const char *locale; + char *label; + char *icon; + + ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL); + if (ret != SQLITE_OK) { + _LOGE("prepare failed: %s", sqlite3_errmsg(db)); + return -1; + } + + locales = __create_locale_list(app->label, NULL, app->icon, NULL, NULL); + for (tmp = locales; tmp; tmp = tmp->next) { + locale = (const char *)tmp->data; + label = NULL; + icon = NULL; + __extract_data(locale, app->label, NULL, app->icon, NULL, NULL, + &label, NULL, &icon, NULL, NULL); + if (!label && !icon) + continue; + + idx = 1; + __BIND_TEXT(db, stmt, idx++, app->appid); + __BIND_TEXT(db, stmt, idx++, locale); + __BIND_TEXT(db, stmt, idx++, label); + __BIND_TEXT(db, stmt, idx++, icon); + + ret = sqlite3_step(stmt); + if (ret != SQLITE_DONE) { + _LOGE("step failed: %s", sqlite3_errmsg(db)); + g_list_free(locales); + sqlite3_finalize(stmt); + return -1; + } + + sqlite3_reset(stmt); + + if (strcasecmp(app->mainapp, "true") == 0) { + if (__insert_mainapp_localized_info(db, app, locale, + label, icon)) + _LOGE("insert mainapp localized info failed"); + } + } + + g_list_free(locales); + sqlite3_finalize(stmt); + + return 0; +} + +static int __insert_package_privilege_info(sqlite3 *db, manifest_x *mfx) +{ + static const char query[] = + "INSERT INTO package_privilege_info (package, privilege, type) " + "VALUES (?, ?, ?)"; + int ret; + sqlite3_stmt *stmt; + int idx; + GList *tmp; + privilege_x *priv; + + ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL); + if (ret != SQLITE_OK) { + _LOGE("prepare failed: %s", sqlite3_errmsg(db)); + return -1; + } + + for (tmp = mfx->privileges; tmp; tmp = tmp->next) { + priv = (privilege_x *)tmp->data; + if (priv == NULL) + continue; + + idx = 1; + __BIND_TEXT(db, stmt, idx++, mfx->package); + __BIND_TEXT(db, stmt, idx++, priv->value); + __BIND_TEXT(db, stmt, idx++, priv->type); + + ret = sqlite3_step(stmt); + if (ret != SQLITE_DONE) { + _LOGE("step failed: %s", sqlite3_errmsg(db)); + sqlite3_finalize(stmt); + return -1; + } + sqlite3_reset(stmt); + } + + sqlite3_finalize(stmt); + + return 0; +} + +static int __insert_app_data_control_privilege_info(sqlite3 *db, + datacontrol_x *datacontrol) +{ + static const char query[] = + "INSERT INTO package_app_data_control_privilege (providerid," + " privilege, type) VALUES (?, ?, ?)"; + + int ret; + sqlite3_stmt *stmt; + int idx; + GList *privileges; + char *priv; + + if (datacontrol == NULL) + return 0; + + ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL); + if (ret != SQLITE_OK) { + _LOGE("prepare failed: %s", sqlite3_errmsg(db)); + return -1; + } + + for (privileges = datacontrol->privileges; privileges; + privileges = privileges->next) { + priv = (char *)privileges->data; + if (priv == NULL) + continue; + + idx = 1; + __BIND_TEXT(db, stmt, idx++, datacontrol->providerid); + __BIND_TEXT(db, stmt, idx++, priv); + __BIND_TEXT(db, stmt, idx++, datacontrol->type); + + ret = sqlite3_step(stmt); + if (ret != SQLITE_DONE) { + _LOGE("step failed: %s", sqlite3_errmsg(db)); + sqlite3_finalize(stmt); + return -1; + } + + sqlite3_reset(stmt); + } + + sqlite3_finalize(stmt); + return 0; +} + +static int __insert_datacontrol_info(sqlite3 *db, application_x *app) +{ + static const char query[] = + "INSERT INTO package_app_data_control (app_id, providerid," + " access, type, trusted) VALUES (?, ?, ?, ?, ?)"; + int ret; + sqlite3_stmt *stmt; + int idx; + GList *tmp; + datacontrol_x *dc; + + if (app->datacontrol == NULL) + return 0; + + ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL); + if (ret != SQLITE_OK) { + _LOGE("prepare failed: %s", sqlite3_errmsg(db)); + return -1; + } + + for (tmp = app->datacontrol; tmp; tmp = tmp->next) { + dc = (datacontrol_x *)tmp->data; + if (dc == NULL) + continue; + idx = 1; + __BIND_TEXT(db, stmt, idx++, app->appid); + __BIND_TEXT(db, stmt, idx++, dc->providerid); + __BIND_TEXT(db, stmt, idx++, dc->access); + __BIND_TEXT(db, stmt, idx++, dc->type); + __BIND_TEXT(db, stmt, idx++, dc->trusted); + + ret = sqlite3_step(stmt); + if (ret != SQLITE_DONE) { + _LOGE("step failed: %s", sqlite3_errmsg(db)); + sqlite3_finalize(stmt); + return -1; + } + + if (dc->privileges && + __insert_app_data_control_privilege_info(db, dc)) { + sqlite3_finalize(stmt); + return -1; + } + + sqlite3_reset(stmt); + } + + sqlite3_finalize(stmt); + + return 0; +} + +static int __insert_category_info(sqlite3 *db, application_x *app) +{ + static const char query[] = + "INSERT INTO package_app_app_category (app_id, category) " + "VALUES (?, ?)"; + int ret; + sqlite3_stmt *stmt; + int idx; + GList *tmp; + const char *category; + + if (app->category == NULL) + return 0; + + ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL); + if (ret != SQLITE_OK) { + _LOGE("prepare failed: %s", sqlite3_errmsg(db)); + return -1; + } + + for (tmp = app->category; tmp; tmp = tmp->next) { + category = (const char *)tmp->data; + if (category == NULL) + continue; + idx = 1; + __BIND_TEXT(db, stmt, idx++, app->appid); + __BIND_TEXT(db, stmt, idx++, category); + + ret = sqlite3_step(stmt); + if (ret != SQLITE_DONE) { + _LOGE("step failed: %s", sqlite3_errmsg(db)); + sqlite3_finalize(stmt); + return -1; + } + + sqlite3_reset(stmt); + } + + sqlite3_finalize(stmt); + + return 0; +} + +static int __insert_metadata_info(sqlite3 *db, application_x *app) +{ + static const char query[] = + "INSERT INTO package_app_app_metadata (app_id," + " md_key, md_value) VALUES (?, ?, ?)"; + int ret; + sqlite3_stmt *stmt; + int idx; + GList *tmp; + metadata_x *md; + + if (app->metadata == NULL) + return 0; + + ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL); + if (ret != SQLITE_OK) { + _LOGE("prepare failed: %s", sqlite3_errmsg(db)); + return -1; + } + + for (tmp = app->metadata; tmp; tmp = tmp->next) { + md = (metadata_x *)tmp->data; + if (md == NULL) + continue; + idx = 1; + __BIND_TEXT(db, stmt, idx++, app->appid); + __BIND_TEXT(db, stmt, idx++, md->key); + __BIND_TEXT(db, stmt, idx++, md->value); + + ret = sqlite3_step(stmt); + if (ret != SQLITE_DONE) { + _LOGE("step failed: %s", sqlite3_errmsg(db)); + sqlite3_finalize(stmt); + return -1; + } + + sqlite3_reset(stmt); + } + + sqlite3_finalize(stmt); + + return 0; +} + +static int __insert_appcontrol_privilege_info(sqlite3 *db, const char *appid, + appcontrol_x *ac) +{ + static const char query[] = + "INSERT INTO package_app_app_control_privilege (app_id," + " app_control, privilege) VALUES (?, ?, ?)"; + int ret; + sqlite3_stmt *stmt; + int idx; + char app_control[BUFSIZE]; + GList *tmp; + char *privilege; + + if (ac == NULL) + return 0; + + ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL); + if (ret != SQLITE_OK) { + _LOGE("prepare failed: %s", sqlite3_errmsg(db)); + return -1; + } + + for (tmp = ac->privileges; tmp; tmp = tmp->next) { + privilege = (char *)tmp->data; + if (privilege == NULL || !strlen(privilege)) + continue; + + idx = 1; + snprintf(app_control, sizeof(app_control), "%s|%s|%s", + ac->operation ? (strlen(ac->operation) > 0 ? + ac->operation : "NULL") : "NULL", + ac->uri ? (strlen(ac->uri) > 0 ? + ac->uri : "NULL") : "NULL", + ac->mime ? (strlen(ac->mime) > 0 ? + ac->mime : "NULL") : "NULL"); + __BIND_TEXT(db, stmt, idx++, appid); + __BIND_TEXT(db, stmt, idx++, app_control); + __BIND_TEXT(db, stmt, idx++, privilege); + + ret = sqlite3_step(stmt); + if (ret != SQLITE_DONE) { + _LOGE("step failed: %s", sqlite3_errmsg(db)); + sqlite3_finalize(stmt); + return -1; + } + + sqlite3_reset(stmt); + } + + sqlite3_finalize(stmt); + + return 0; +} + +static int __insert_appcontrol_info(sqlite3 *db, application_x *app) +{ + static const char query[] = + "INSERT INTO package_app_app_control (app_id, app_control," + " visibility, app_control_id) " + "VALUES (?, ?, ?, ?)"; + int ret; + sqlite3_stmt *stmt; + int idx; + char app_control[BUFSIZE]; + GList *tmp; + appcontrol_x *ac; + + if (app->appcontrol == NULL) + return 0; + + ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL); + if (ret != SQLITE_OK) { + _LOGE("prepare failed: %s", sqlite3_errmsg(db)); + return -1; + } + + for (tmp = app->appcontrol; tmp; tmp = tmp->next) { + ac = (appcontrol_x *)tmp->data; + if (ac == NULL) + continue; + idx = 1; + snprintf(app_control, sizeof(app_control), "%s|%s|%s", + ac->operation ? (strlen(ac->operation) > 0 ? + ac->operation : "NULL") : "NULL", + ac->uri ? (strlen(ac->uri) > 0 ? + ac->uri : "NULL") : "NULL", + ac->mime ? (strlen(ac->mime) > 0 ? + ac->mime : "NULL") : "NULL"); + __BIND_TEXT(db, stmt, idx++, app->appid); + __BIND_TEXT(db, stmt, idx++, app_control); + __BIND_TEXT(db, stmt, idx++, ac->visibility); + __BIND_TEXT(db, stmt, idx++, ac->id); + + ret = sqlite3_step(stmt); + if (ret != SQLITE_DONE) { + _LOGE("step failed: %s", sqlite3_errmsg(db)); + sqlite3_finalize(stmt); + return -1; + } + + if (__insert_appcontrol_privilege_info(db, app->appid, ac)) { + sqlite3_finalize(stmt); + return -1; + } + + sqlite3_reset(stmt); + } + + sqlite3_finalize(stmt); + + return 0; +} + +static const char *__get_bool(char *value, bool is_true) +{ + if (value != NULL) { + if (!strcmp(value, "")) + return (is_true) ? "true" : "false"; + return value; + } + + return (is_true) ? "true" : "false"; +} + +#define EFFECTIVE_APPID_KEY "http://tizen.org/metadata/effective-appid" +static const char *__find_effective_appid(GList *metadata_list) +{ + GList *tmp; + metadata_x *md; + + for (tmp = metadata_list; tmp; tmp = tmp->next) { + md = (metadata_x *)tmp->data; + if (md == NULL || md->key == NULL) + continue; + + if (strcmp(md->key, EFFECTIVE_APPID_KEY) == 0) { + if (md->value) + return md->value; + } + } + + return NULL; +} + +static int __convert_background_category(GList *category_list) +{ + int ret = 0; + GList *tmp; + char *category_data; + + if (category_list == NULL) + return 0; + + for (tmp = category_list; tmp; tmp = tmp->next) { + category_data = (char *)tmp->data; + if (category_data == NULL) + continue; + if (!strcmp(category_data, APP_BG_CATEGORY_MEDIA_STR)) + ret |= APP_BG_CATEGORY_MEDIA_VAL; + else if (!strcmp(category_data, APP_BG_CATEGORY_DOWNLOAD_STR)) + ret |= APP_BG_CATEGORY_DOWNLOAD_VAL; + else if (!strcmp(category_data, APP_BG_CATEGORY_BGNETWORK_STR)) + ret |= APP_BG_CATEGORY_BGNETWORK_VAL; + else if (!strcmp(category_data, APP_BG_CATEGORY_LOCATION_STR)) + ret |= APP_BG_CATEGORY_LOCATION_VAL; + else if (!strcmp(category_data, APP_BG_CATEGORY_SENSOR_STR)) + ret |= APP_BG_CATEGORY_SENSOR_VAL; + else if (!strcmp(category_data, APP_BG_CATEGORY_IOTCOMM_STR)) + ret |= APP_BG_CATEGORY_IOTCOMM_VAL; + else if (!strcmp(category_data, APP_BG_CATEGORY_SYSTEM)) + ret |= APP_BG_CATEGORY_SYSTEM_VAL; + else + _LOGE("Unidentified category [%s]", category_data); + } + + return ret; +} + +static int __insert_application_info(sqlite3 *db, manifest_x *mfx) +{ + static const char query[] = + "INSERT INTO package_app_info (app_id, app_component," + " app_exec, app_nodisplay, app_type, app_onboot, app_multiple," + " app_autorestart, app_taskmanage, app_hwacceleration," + " app_screenreader, app_mainapp, app_recentimage," + " app_launchcondition, app_indicatordisplay, app_portraitimg," + " app_landscapeimg, app_guestmodevisibility," + " app_permissiontype, app_preload, app_submode," + " app_submode_mainid, app_installed_storage, app_process_pool," + " app_launch_mode, app_ui_gadget, app_support_mode," + " app_support_disable, component_type, package, app_tep_name," + " app_zip_mount_file, app_background_category," + " app_package_type, app_root_path, app_api_version," + " app_effective_appid, app_splash_screen_display," + " app_package_system, app_removable," + " app_package_installed_time, app_support_ambient," + " app_external_path, app_setup_appid) " + "VALUES (?, ?, " + " ?, LOWER(?), ?, LOWER(?), LOWER(?)," + " LOWER(?), LOWER(?), ?," + " ?, LOWER(?), ?," + " ?, LOWER(?), ?," + " ?, LOWER(?)," + " ?, LOWER(?), LOWER(?)," + " ?, ?, LOWER(?)," + " COALESCE(?, 'single'), LOWER(?), ?," + " LOWER(?), ?, ?, ?," + " ?, ?," + " ?, ?, ?," + " ?, LOWER(?)," + " LOWER(?), LOWER(?)," + " ?, LOWER(?)," + " ?, ?)"; + int ret; + sqlite3_stmt *stmt; + int idx; + GList *tmp; + application_x *app; + int bg_category; + const char *effective_appid; + GList *ss_list; + + ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL); + if (ret != SQLITE_OK) { + _LOGE("prepare failed: %s", sqlite3_errmsg(db)); + return -1; + } + + for (tmp = mfx->application; tmp; tmp = tmp->next) { + app = (application_x *)tmp->data; + if (app == NULL) + continue; + + bg_category = __convert_background_category( + app->background_category); + effective_appid = __find_effective_appid(app->metadata); + + idx = 1; + __BIND_TEXT(db, stmt, idx++, app->appid); + __BIND_TEXT(db, stmt, idx++, app->component_type); + __BIND_TEXT(db, stmt, idx++, app->exec); + __BIND_TEXT(db, stmt, idx++, __get_bool(app->nodisplay, false)); + __BIND_TEXT(db, stmt, idx++, app->type); + __BIND_TEXT(db, stmt, idx++, __get_bool(app->onboot, false)); + __BIND_TEXT(db, stmt, idx++, __get_bool(app->multiple, false)); + __BIND_TEXT(db, stmt, idx++, + __get_bool(app->autorestart, false)); + __BIND_TEXT(db, stmt, idx++, + __get_bool(app->taskmanage, false)); + __BIND_TEXT(db, stmt, idx++, app->hwacceleration); + __BIND_TEXT(db, stmt, idx++, app->screenreader); + __BIND_TEXT(db, stmt, idx++, __get_bool(app->mainapp, false)); + __BIND_TEXT(db, stmt, idx++, app->recentimage); + __BIND_TEXT(db, stmt, idx++, app->launchcondition); + __BIND_TEXT(db, stmt, idx++, + __get_bool(app->indicatordisplay, true)); + __BIND_TEXT(db, stmt, idx++, app->portraitimg); + __BIND_TEXT(db, stmt, idx++, app->landscapeimg); + __BIND_TEXT(db, stmt, idx++, + __get_bool(app->guestmode_visibility, true)); + __BIND_TEXT(db, stmt, idx++, app->permission_type); + __BIND_TEXT(db, stmt, idx++, __get_bool(mfx->preload, false)); + __BIND_TEXT(db, stmt, idx++, __get_bool(app->submode, false)); + __BIND_TEXT(db, stmt, idx++, app->submode_mainid); + __BIND_TEXT(db, stmt, idx++, mfx->installed_storage); + __BIND_TEXT(db, stmt, idx++, + __get_bool(app->process_pool, false)); + __BIND_TEXT(db, stmt, idx++, app->launch_mode); + __BIND_TEXT(db, stmt, idx++, __get_bool(app->ui_gadget, false)); + __BIND_TEXT(db, stmt, idx++, + app->support_mode ? app->support_mode : "0"); + __BIND_TEXT(db, stmt, idx++, + __get_bool(mfx->support_disable, false)); + __BIND_TEXT(db, stmt, idx++, app->component_type); + __BIND_TEXT(db, stmt, idx++, mfx->package); + __BIND_TEXT(db, stmt, idx++, mfx->tep_name); + __BIND_TEXT(db, stmt, idx++, mfx->zip_mount_file); + __BIND_INT(db, stmt, idx++, bg_category); + __BIND_TEXT(db, stmt, idx++, mfx->type ? mfx->type : "tpk"); + __BIND_TEXT(db, stmt, idx++, mfx->root_path); + __BIND_TEXT(db, stmt, idx++, app->api_version); + __BIND_TEXT(db, stmt, idx++, effective_appid); + __BIND_TEXT(db, stmt, idx++, + __get_bool(app->splash_screen_display, true)); + __BIND_TEXT(db, stmt, idx++, __get_bool(mfx->system, false)); + __BIND_TEXT(db, stmt, idx++, __get_bool(mfx->removable, false)); + __BIND_TEXT(db, stmt, idx++, mfx->installed_time); + __BIND_TEXT(db, stmt, idx++, + __get_bool(app->support_ambient, false)); + __BIND_TEXT(db, stmt, idx++, mfx->external_path); + __BIND_TEXT(db, stmt, idx++, app->setup_appid); + + ret = sqlite3_step(stmt); + if (ret != SQLITE_DONE) { + _LOGE("step failed: %s", sqlite3_errmsg(db)); + sqlite3_finalize(stmt); + return -1; + } + + sqlite3_reset(stmt); + + if (__insert_appcontrol_info(db, app)) { + sqlite3_finalize(stmt); + return -1; + } + if (__insert_category_info(db, app)) { + sqlite3_finalize(stmt); + return -1; + } + if (__insert_metadata_info(db, app)) { + sqlite3_finalize(stmt); + return -1; + } + if (__insert_datacontrol_info(db, app)) { + sqlite3_finalize(stmt); + return -1; + } + ss_list = __find_splashscreens(app->splashscreens); + if (__insert_splashscreen_info(db, app, ss_list)) { + g_list_free(ss_list); + sqlite3_finalize(stmt); + return -1; + } + g_list_free(ss_list); + if (__insert_app_localized_info(db, app)) { + sqlite3_finalize(stmt); + return -1; + } + } + + sqlite3_finalize(stmt); + + return 0; +} + +static int __insert_package_update_info(sqlite3 *db, manifest_x *mfx) +{ + static const char query[] = + "INSERT INTO package_update_info (package, update_version) " + "VALUES (?, ?)"; + int ret; + int idx; + sqlite3_stmt *stmt; + + ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL); + if (ret != SQLITE_OK) { + _LOGE("prepare failed: %s", sqlite3_errmsg(db)); + return -1; + } + + idx = 1; + __BIND_TEXT(db, stmt, idx++, mfx->package); + __BIND_TEXT(db, stmt, idx, mfx->version); + ret = sqlite3_step(stmt); + if (ret != SQLITE_DONE) { + _LOGE("step failed: %s", sqlite3_errmsg(db)); + sqlite3_finalize(stmt); + return -1; + } + sqlite3_finalize(stmt); + + return 0; +} + +static int __insert_package_localized_info(sqlite3 *db, manifest_x *mfx) +{ + static const char query[] = + "INSERT INTO package_localized_info (package, package_locale," + " package_label, package_icon, package_description," + " package_license, package_author) " + "VALUES (?, ?, ?, ?, ?, ?, ?)"; + int ret; + sqlite3_stmt *stmt; + int idx; + GList *tmp; + GList *locales; + const char *locale; + char *label; + char *icon; + char *description; + char *license; + char *author; + + ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL); + if (ret != SQLITE_OK) { + _LOGE("prepare failed: %s", sqlite3_errmsg(db)); + return -1; + } + + locales = __create_locale_list(mfx->label, mfx->license, mfx->icon, + mfx->description, mfx->author); + for (tmp = locales; tmp; tmp = tmp->next) { + locale = (const char *)tmp->data; + label = NULL; + icon = NULL; + description = NULL; + license = NULL; + author = NULL; + __extract_data(locale, mfx->label, mfx->license, mfx->icon, + mfx->description, mfx->author, + &label, &license, &icon, &description, &author); + if (!label && !license && !icon && !description && !author) + continue; + + idx = 1; + __BIND_TEXT(db, stmt, idx++, mfx->package); + __BIND_TEXT(db, stmt, idx++, locale); + __BIND_TEXT(db, stmt, idx++, label); + __BIND_TEXT(db, stmt, idx++, icon); + __BIND_TEXT(db, stmt, idx++, description); + __BIND_TEXT(db, stmt, idx++, license); + __BIND_TEXT(db, stmt, idx++, author); + + ret = sqlite3_step(stmt); + if (ret != SQLITE_DONE) { + _LOGE("step failed: %s", sqlite3_errmsg(db)); + g_list_free(locales); + sqlite3_finalize(stmt); + return -1; + } + + sqlite3_reset(stmt); + } + + g_list_free(locales); + sqlite3_finalize(stmt); + + return 0; +} + +static int __insert_package_info(sqlite3 *db, manifest_x *mfx) +{ + static const char query[] = + "INSERT INTO package_info (package, package_type," + " package_version, package_api_version, package_tep_name," + " package_zip_mount_file, install_location, package_size," + " package_removable, package_preload, package_readonly," + " package_update, package_appsetting, package_nodisplay," + " package_system, author_name, author_email, author_href," + " installed_time, installed_storage, storeclient_id," + " mainapp_id, package_url, root_path, external_path," + " csc_path, package_support_mode, package_support_disable) " + "VALUES (?, ?," + " ?, ?, ?," + " ?, ?, ?," + " LOWER(?), LOWER(?), LOWER(?)," + " LOWER(?), LOWER(?), LOWER(?)," + " LOWER(?), ?, ?, ?," + " ?, ?, ?," + " ?, ?, ?, ?," + " ?, ?, LOWER(?))"; + int ret; + sqlite3_stmt *stmt; + int idx = 1; + const char *author_name = NULL; + const char *author_email = NULL; + const char *author_href = NULL; + + ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL); + if (ret != SQLITE_OK) { + _LOGE("prepare failed: %s", sqlite3_errmsg(db)); + return -1; + } + + if (mfx->author && mfx->author->data) { + author_name = ((author_x *)mfx->author->data)->text; + author_email = ((author_x *)mfx->author->data)->email; + author_href = ((author_x *)mfx->author->data)->href; + } + + __BIND_TEXT(db, stmt, idx++, mfx->package); + __BIND_TEXT(db, stmt, idx++, mfx->type); + __BIND_TEXT(db, stmt, idx++, mfx->version); + __BIND_TEXT(db, stmt, idx++, mfx->api_version); + __BIND_TEXT(db, stmt, idx++, mfx->tep_name); + __BIND_TEXT(db, stmt, idx++, mfx->zip_mount_file); + __BIND_TEXT(db, stmt, idx++, mfx->installlocation); + __BIND_TEXT(db, stmt, idx++, mfx->package_size); + __BIND_TEXT(db, stmt, idx++, __get_bool(mfx->removable, true)); + __BIND_TEXT(db, stmt, idx++, __get_bool(mfx->preload, false)); + __BIND_TEXT(db, stmt, idx++, __get_bool(mfx->readonly, false)); + __BIND_TEXT(db, stmt, idx++, __get_bool(mfx->update, false)); + __BIND_TEXT(db, stmt, idx++, __get_bool(mfx->appsetting, false)); + __BIND_TEXT(db, stmt, idx++, __get_bool(mfx->nodisplay_setting, false)); + __BIND_TEXT(db, stmt, idx++, __get_bool(mfx->system, false)); + __BIND_TEXT(db, stmt, idx++, author_name); + __BIND_TEXT(db, stmt, idx++, author_email); + __BIND_TEXT(db, stmt, idx++, author_href); + __BIND_TEXT(db, stmt, idx++, mfx->installed_time); + __BIND_TEXT(db, stmt, idx++, mfx->installed_storage); + __BIND_TEXT(db, stmt, idx++, mfx->storeclient_id); + __BIND_TEXT(db, stmt, idx++, mfx->mainapp_id); + __BIND_TEXT(db, stmt, idx++, mfx->package_url); + __BIND_TEXT(db, stmt, idx++, mfx->root_path); + __BIND_TEXT(db, stmt, idx++, mfx->external_path); + __BIND_TEXT(db, stmt, idx++, mfx->csc_path); + __BIND_TEXT(db, stmt, idx++, + mfx->support_mode ? mfx->support_mode : "0"); + __BIND_TEXT(db, stmt, idx++, __get_bool(mfx->support_disable, false)); + + ret = sqlite3_step(stmt); + if (ret != SQLITE_DONE) { + _LOGE("step failed: %s", sqlite3_errmsg(db)); + sqlite3_finalize(stmt); + return -1; + } + + sqlite3_finalize(stmt); + + if (__insert_package_update_info(db, mfx)) + return -1; + if (__insert_package_localized_info(db, mfx)) + return -1; + if (__insert_application_info(db, mfx)) + return -1; + if (__insert_package_privilege_info(db, mfx)) + return -1; + if (__insert_package_appdefined_privilege_info(db, mfx)) + return -1; + if (__insert_package_dependency_info(db, mfx)) + return -1; + + return 0; +} + +static int __delete_package_info(sqlite3 *db, const char *pkgid) +{ + static const char query[] = + "DELETE FROM package_info WHERE package=?"; + int ret; + sqlite3_stmt *stmt; + + ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL); + if (ret != SQLITE_OK) { + _LOGE("prepare failed: %s", sqlite3_errmsg(db)); + return -1; + } + + __BIND_TEXT(db, stmt, 1, pkgid); + + ret = sqlite3_step(stmt); + if (ret != SQLITE_DONE) { + _LOGE("step failed: %s", sqlite3_errmsg(db)); + sqlite3_finalize(stmt); + return -1; + } + + sqlite3_finalize(stmt); + + return 0; +} + +API int pkgmgr_parser_delete_pkg_info(sqlite3 *db, const char *package, uid_t uid) +{ + if (db == NULL || package == NULL) { + _LOGE("invalid parameter"); + return PM_PARSER_R_EINVAL; + } + + __BEGIN_TRANSACTION(db); + __DO_TRANSACTION(db, __delete_package_info(db, package)); + __END_TRANSACTION(db); + + return PM_PARSER_R_OK; +} + +API int pkgmgr_parser_update_pkg_info(sqlite3 *db, manifest_x *mfx, uid_t uid) +{ + if (db == NULL || mfx == NULL) { + _LOGE("invalid parameter"); + return PM_PARSER_R_EINVAL; + } + + __BEGIN_TRANSACTION(db); + __DO_TRANSACTION(db, __delete_package_info(db, mfx->package)); + __DO_TRANSACTION(db, __insert_package_info(db, mfx)); + __END_TRANSACTION(db); + + sqlite3_close_v2(db); + + return PM_PARSER_R_OK; +} + +API int pkgmgr_parser_insert_pkg_info(sqlite3 *db, manifest_x *mfx, uid_t uid) +{ + if (db == NULL || mfx == NULL) { + _LOGE("invalid parameter"); + return PM_PARSER_R_EINVAL; + } + + __BEGIN_TRANSACTION(db); + __DO_TRANSACTION(db, __insert_package_info(db, mfx)); + __END_TRANSACTION(db); + + sqlite3_close_v2(db); + + return PM_PARSER_R_OK; } \ No newline at end of file diff --git a/src/pkgmgrinfo_internal.h b/src/pkgmgrinfo_internal.h index 9743699d..ad499c25 100644 --- a/src/pkgmgrinfo_internal.h +++ b/src/pkgmgrinfo_internal.h @@ -22,6 +22,9 @@ #include #include +#include + +#include "pkgmgr_parser.h" #include "pkgmgrinfo_type.h" #include "pkgmgr-info.h" #ifdef __cplusplus @@ -37,6 +40,11 @@ int certinfo_internal_delete(sqlite3 *db, const char *pkgid); int get_query_result(sqlite3 *db, const char *query, GList **list, int *row, int *col); int pkginfo_internal_filter_get_depends_on(sqlite3 *db, const char *pkgid, GList **list); int execute_write_queries(sqlite3 *db, const char **queries, int len); + +int pkgmgr_parser_insert_pkg_info(sqlite3 *db, manifest_x *mfx, uid_t uid); +int pkgmgr_parser_update_pkg_info(sqlite3 *db, manifest_x *mfx, uid_t uid); +int pkgmgr_parser_delete_pkg_info(sqlite3 *db, const char *package, uid_t uid); + /** @} */ #ifdef __cplusplus }