X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fpkgmgrinfo_pkginfo.c;h=dc3048a6718e47069b2c46f969314a815028b350;hb=923c0a1db9905d7d727b13eaf4174e66699e940c;hp=2944e650e925d3afd6dba93038b33202dbf5c5ef;hpb=1cac40db855942f074fdd905cb7a51ebf0bc2c42;p=platform%2Fcore%2Fappfw%2Fpkgmgr-info.git diff --git a/src/pkgmgrinfo_pkginfo.c b/src/pkgmgrinfo_pkginfo.c index 2944e65..dc3048a 100644 --- a/src/pkgmgrinfo_pkginfo.c +++ b/src/pkgmgrinfo_pkginfo.c @@ -86,6 +86,16 @@ static void __destroy_each_node(gpointer data, gpointer user_data) node = NULL; } +static void __destroy_metadata_node(gpointer data) +{ + pkgmgrinfo_metadata_node_x *node = (pkgmgrinfo_metadata_node_x *)data; + if (node->key) + free(node->key); + if (node->value) + free(node->value); + free(node); +} + static void __cleanup_pkginfo(pkgmgr_pkginfo_x *data) { ret_if(data == NULL); @@ -107,7 +117,7 @@ long long _pkgmgr_calculate_dir_size(char *dirname) int q = 0; /*quotient*/ int r = 0; /*remainder*/ DIR *dp = NULL; - struct dirent ep, *result; + struct dirent *ep; struct stat fileinfo; char abs_filename[FILENAME_MAX] = { 0, }; retvm_if(dirname == NULL, PMINFO_R_ERROR, "dirname is NULL"); @@ -118,22 +128,20 @@ long long _pkgmgr_calculate_dir_size(char *dirname) return -1; } - for (ret = readdir_r(dp, &ep, &result); - ret == 0 && result != NULL; - ret = readdir_r(dp, &ep, &result)) { - if (!strcmp(ep.d_name, ".") || - !strcmp(ep.d_name, "..")) { + for (ep = readdir(dp); ep != NULL; ep = readdir(dp)) { + if (!strcmp(ep->d_name, ".") || + !strcmp(ep->d_name, "..")) { continue; } snprintf(abs_filename, FILENAME_MAX, "%s/%s", dirname, - ep.d_name); + ep->d_name); if (lstat(abs_filename, &fileinfo) < 0) perror(abs_filename); else { if (S_ISDIR(fileinfo.st_mode)) { total += fileinfo.st_size; - if (strcmp(ep.d_name, ".") - && strcmp(ep.d_name, "..")) { + if (strcmp(ep->d_name, ".") + && strcmp(ep->d_name, "..")) { ret = _pkgmgr_calculate_dir_size (abs_filename); total = total + ret; @@ -173,6 +181,51 @@ static int _pkginfo_add_description_info_into_list(const char *locale, return PMINFO_R_OK; } +static int _pkginfo_get_plugin_execution_info(sqlite3 *db, const char *pkgid, + GList **plugins) +{ + static const char query_raw[] = + "SELECT appid, plugin_type, plugin_name FROM package_plugin_info " + "WHERE pkgid=%Q"; + int ret; + char *query; + sqlite3_stmt *stmt; + plugin_x *plugin; + + query = sqlite3_mprintf(query_raw, pkgid); + if (query == NULL) { + LOGE("out of memory"); + return PMINFO_R_ERROR; + } + + ret = sqlite3_prepare_v2(db, query, strlen(query), + &stmt, NULL); + sqlite3_free(query); + if (ret != SQLITE_OK) { + LOGE("prepare failed: %s", sqlite3_errmsg(db)); + return PMINFO_R_ERROR; + } + + while (sqlite3_step(stmt) == SQLITE_ROW) { + plugin = calloc(1, sizeof(plugin_x)); + if (!plugin) { + LOGE("out of memory"); + sqlite3_finalize(stmt); + return PMINFO_R_ERROR; + } + plugin->pkgid = strdup(pkgid); + _save_column_str(stmt, 0, &plugin->appid); + _save_column_str(stmt, 1, &plugin->plugin_type); + _save_column_str(stmt, 2, &plugin->plugin_name); + *plugins = g_list_append(*plugins, + (gpointer)plugin); + } + + sqlite3_finalize(stmt); + + return PMINFO_R_OK; +} + static int _pkginfo_get_privilege(sqlite3 *db, const char *pkgid, GList **privileges) { @@ -200,6 +253,11 @@ static int _pkginfo_get_privilege(sqlite3 *db, const char *pkgid, while (sqlite3_step(stmt) == SQLITE_ROW) { privilege = calloc(1, sizeof(privilege_x)); + if (!privilege) { + LOGE("failed to alloc memory"); + sqlite3_finalize(stmt); + return PMINFO_R_ERROR; + } _save_column_str(stmt, 0, &privilege->value); _save_column_str(stmt, 1, &privilege->type); *privileges = g_list_append(*privileges, @@ -211,6 +269,93 @@ static int _pkginfo_get_privilege(sqlite3 *db, const char *pkgid, return PMINFO_R_OK; } +static int _pkginfo_get_appdefined_privilege(sqlite3 *db, const char *pkgid, + GList **privileges) +{ + static const char query_raw[] = + "SELECT DISTINCT privilege, license, type FROM " + "package_appdefined_privilege_info WHERE package=%Q"; + int ret; + char *query; + sqlite3_stmt *stmt; + appdefined_privilege_x *privilege; + + query = sqlite3_mprintf(query_raw, pkgid); + if (query == NULL) { + LOGE("out of memory"); + return PMINFO_R_ERROR; + } + + ret = sqlite3_prepare_v2(db, query, strlen(query), + &stmt, NULL); + sqlite3_free(query); + if (ret != SQLITE_OK) { + LOGE("prepare failed: %s", sqlite3_errmsg(db)); + return PMINFO_R_ERROR; + } + + while (sqlite3_step(stmt) == SQLITE_ROW) { + privilege = calloc(1, sizeof(appdefined_privilege_x)); + if (!privilege) { + LOGE("failed to alloc memory"); + sqlite3_finalize(stmt); + return PMINFO_R_ERROR; + } + _save_column_str(stmt, 0, &privilege->value); + _save_column_str(stmt, 1, &privilege->license); + _save_column_str(stmt, 2, &privilege->type); + *privileges = g_list_append(*privileges, + (gpointer)privilege); + } + + sqlite3_finalize(stmt); + + return PMINFO_R_OK; +} + +static int _pkginfo_get_dependency(sqlite3 *db, const char *pkgid, + GList **dependencies) +{ + static const char query_raw[] = + "SELECT DISTINCT depends_on, type, required_version " + "FROM package_dependency_info WHERE package=%Q"; + int ret; + char *query; + sqlite3_stmt *stmt; + dependency_x *dependency; + + query = sqlite3_mprintf(query_raw, pkgid); + if (query == NULL) { + LOGE("out of memory"); + return PMINFO_R_ERROR; + } + + ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL); + sqlite3_free(query); + if (ret != SQLITE_OK) { + LOGE("prepare failed: %s", sqlite3_errmsg(db)); + return PMINFO_R_ERROR; + } + + while (sqlite3_step(stmt) == SQLITE_ROW) { + dependency = calloc(1, sizeof(dependency_x)); + if (!dependency) { + LOGE("failed to alloc memory"); + sqlite3_finalize(stmt); + return PMINFO_R_ERROR; + } + _save_column_str(stmt, 0, &dependency->depends_on); + _save_column_str(stmt, 1, &dependency->type); + _save_column_str(stmt, 2, &dependency->required_version); + *dependencies = g_list_append(*dependencies, + (gpointer)dependency); + } + + sqlite3_finalize(stmt); + + return PMINFO_R_OK; +} + static const char join_localized_info[] = " LEFT OUTER JOIN package_localized_info" " ON pi.package=package_localized_info.package" @@ -220,45 +365,38 @@ static const char join_privilege_info[] = " ON pi.package=package_privilege_info.package"; static int _get_filtered_query(pkgmgrinfo_filter_x *filter, - const char *locale, char **query, GList **bind_params) + const char *locale, uid_t uid, char **query, GList **bind_params) { int joined = 0; char buf[MAX_QUERY_LEN] = { '\0' }; char buf2[MAX_QUERY_LEN] = { '\0' }; char *condition = NULL; - size_t len = 0; GSList *list = NULL; if (filter == NULL) return PMINFO_R_OK; - len += strlen(" WHERE 1=1 "); - strncat(buf, " WHERE 1=1 ", MAX_QUERY_LEN - len - 1); + snprintf(buf, sizeof(buf), "%s", " WHERE 1=1 "); for (list = filter->list; list; list = list->next) { - joined |= __get_filter_condition(list->data, &condition, + joined |= __get_filter_condition(list->data, uid, &condition, bind_params); if (condition == NULL) continue; - len += strlen(" AND "); - strncat(buf, " AND ", MAX_QUERY_LEN - len - 1); + strncat(buf, " AND ", sizeof(buf) - strlen(buf) - 1); - len += strlen(condition); - strncat(buf, condition, sizeof(buf) - len - 1); + strncat(buf, condition, sizeof(buf) - strlen(buf) - 1); free(condition); condition = NULL; } if (joined & E_PMINFO_PKGINFO_JOIN_LOCALIZED_INFO) { - strncat(buf2, join_localized_info, MAX_QUERY_LEN - len - 1); - len += strlen(join_localized_info); + strncat(buf2, join_localized_info, sizeof(buf2) - strlen(buf2) - 1); *bind_params = g_list_append(*bind_params, strdup(locale)); } - if (joined & E_PMINFO_PKGINFO_JOIN_PRIVILEGE_INFO) { - strncat(buf2, join_privilege_info, MAX_QUERY_LEN - len - 1); - len += strlen(join_privilege_info); - } - strncat(buf2, buf, MAX_QUERY_LEN - len - 1); + if (joined & E_PMINFO_PKGINFO_JOIN_PRIVILEGE_INFO) + strncat(buf2, join_privilege_info, sizeof(buf2) - strlen(buf2) - 1); + strncat(buf2, buf, sizeof(buf2) - strlen(buf2) - 1); *query = strdup(buf2); if (*query == NULL) @@ -330,16 +468,16 @@ static int _pkginfo_get_packages(uid_t uid, const char *locale, pkgmgrinfo_filter_x *filter, int flag, GHashTable *packages) { static const char query_raw[] = - "SELECT DISTINCT pi.package, pi.package_version, " - "pi.install_location, pi.package_removable, " - "pi.package_preload, pi.package_readonly, pi.package_update, " - "pi.package_appsetting, pi.package_system, pi.package_type, " - "pi.package_size, pi.installed_time, pi.installed_storage, " - "pi.storeclient_id, pi.mainapp_id, pi.package_url, " - "pi.root_path, pi.csc_path, pi.package_nodisplay, " - "pi.package_api_version, pi.package_support_disable, " - "pi.package_tep_name, pi.package_zip_mount_file, pi.external_path, " - "pi.package_support_mode"; + "SELECT DISTINCT pi.package, pi.installed_storage, pi.external_path"; + static const char query_basic[] = + ", pi.package_version, pi.install_location, " + "pi.package_removable, pi.package_preload, pi.package_readonly, " + "pi.package_update, pi.package_appsetting, pi.package_system, " + "pi.package_type, pi.package_size, pi.installed_time, " + "pi.storeclient_id, pi.mainapp_id, pi.package_url, pi.root_path, " + "pi.csc_path, pi.package_nodisplay, pi.package_api_version, " + "pi.package_support_disable, pi.package_tep_name, " + "pi.package_zip_mount_file, pi.package_support_mode"; static const char query_author[] = ", pi.author_name, pi.author_email, pi.author_href"; static const char query_label[] = @@ -357,7 +495,6 @@ static int _pkginfo_get_packages(uid_t uid, const char *locale, static const char query_from_clause[] = " FROM package_info as pi"; int ret = PMINFO_R_ERROR; int idx = 0; - int query_len = 0; char *dbpath; char *tmp_record = NULL; char *constraints = NULL; @@ -366,17 +503,18 @@ static int _pkginfo_get_packages(uid_t uid, const char *locale, author_x *author = NULL; GList *bind_params = NULL; sqlite3 *db; - sqlite3_stmt *stmt; + sqlite3_stmt *stmt = NULL; pkgmgrinfo_filter_x *tmp_filter = NULL; bool is_check_storage = true; + const uid_t global_user_uid = GLOBAL_USER; dbpath = getUserPkgParserDBPathUID(uid); if (dbpath == NULL) return PMINFO_R_ERROR; - ret = sqlite3_open_v2(dbpath, &db, SQLITE_OPEN_READONLY, NULL); + ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY); if (ret != SQLITE_OK) { - _LOGD("failed to open db: %d", ret); + _LOGD("failed to open db(%s): %d", dbpath, ret); free(dbpath); return PMINFO_R_ERROR; } @@ -394,39 +532,34 @@ static int _pkginfo_get_packages(uid_t uid, const char *locale, is_check_storage = __check_package_storage_status(tmp_filter); - query_len = strlen(query_raw); snprintf(query, MAX_QUERY_LEN - 1, "%s", query_raw); - if (flag & PMINFO_PKGINFO_GET_AUTHOR) { - strncat(query, query_author, MAX_QUERY_LEN - query_len - 1); - query_len += strlen(query_author); - } + if (flag & PMINFO_APPINFO_GET_BASICINFO) + strncat(query, query_basic, sizeof(query) - strlen(query) - 1); + if (flag & PMINFO_PKGINFO_GET_AUTHOR) + strncat(query, query_author, sizeof(query) - strlen(query) - 1); if (flag & PMINFO_PKGINFO_GET_LABEL) { - strncat(query, query_label, MAX_QUERY_LEN - query_len - 1); - query_len += strlen(query_label); + strncat(query, query_label, sizeof(query) - strlen(query) - 1); bind_params = g_list_append(bind_params, strdup(locale)); } if (flag & PMINFO_PKGINFO_GET_ICON) { - strncat(query, query_icon, MAX_QUERY_LEN - query_len - 1); - query_len += strlen(query_icon); + strncat(query, query_icon, sizeof(query) - strlen(query) - 1); bind_params = g_list_append(bind_params, strdup(locale)); } if (flag & PMINFO_PKGINFO_GET_DESCRIPTION) { - strncat(query, query_description, MAX_QUERY_LEN - query_len - 1); - query_len += strlen(query_description); + strncat(query, query_description, sizeof(query) - strlen(query) - 1); bind_params = g_list_append(bind_params, strdup(locale)); } - strncat(query, query_from_clause, MAX_QUERY_LEN - query_len - 1); - query_len += strlen(query_from_clause); + strncat(query, query_from_clause, sizeof(query) - strlen(query) - 1); - ret = _get_filtered_query(tmp_filter, locale, &constraints, &bind_params); + ret = _get_filtered_query(tmp_filter, locale, uid, &constraints, &bind_params); if (ret != PMINFO_R_OK) { LOGE("Failed to get WHERE clause"); goto catch; } if (constraints) - strncat(query, constraints, MAX_QUERY_LEN - query_len - 1); + strncat(query, constraints, sizeof(query) - strlen(query) - 1); ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL); if (ret != SQLITE_OK) { @@ -445,53 +578,53 @@ static int _pkginfo_get_packages(uid_t uid, const char *locale, info = calloc(1, sizeof(package_x)); if (info == NULL) { LOGE("out of memory"); - sqlite3_finalize(stmt); - sqlite3_close_v2(db); - return PMINFO_R_ERROR; + ret = PMINFO_R_ERROR; + goto catch; } idx = 0; _save_column_str(stmt, idx++, &info->package); - if (g_hash_table_contains(packages, - (gconstpointer)info->package)) { - free(info->package); - free(info); - continue; - } - _save_column_str(stmt, idx++, &info->version); - _save_column_str(stmt, idx++, &info->installlocation); - _save_column_str(stmt, idx++, &info->removable); - _save_column_str(stmt, idx++, &info->preload); - _save_column_str(stmt, idx++, &info->readonly); - _save_column_str(stmt, idx++, &info->update); - _save_column_str(stmt, idx++, &info->appsetting); - _save_column_str(stmt, idx++, &info->system); - _save_column_str(stmt, idx++, &info->type); - _save_column_str(stmt, idx++, &info->package_size); - _save_column_str(stmt, idx++, &info->installed_time); _save_column_str(stmt, idx++, &info->installed_storage); - _save_column_str(stmt, idx++, &info->storeclient_id); - _save_column_str(stmt, idx++, &info->mainapp_id); - _save_column_str(stmt, idx++, &info->package_url); - _save_column_str(stmt, idx++, &info->root_path); - _save_column_str(stmt, idx++, &info->csc_path); - _save_column_str(stmt, idx++, &info->nodisplay_setting); - _save_column_str(stmt, idx++, &info->api_version); - _save_column_str(stmt, idx++, &info->support_disable); - _save_column_str(stmt, idx++, &info->tep_name); - _save_column_str(stmt, idx++, &info->zip_mount_file); _save_column_str(stmt, idx++, &info->external_path); - _save_column_str(stmt, idx++, &info->support_mode); + + if (flag & PMINFO_APPINFO_GET_BASICINFO) { + _save_column_str(stmt, idx++, &info->version); + _save_column_str(stmt, idx++, &info->installlocation); + _save_column_str(stmt, idx++, &info->removable); + _save_column_str(stmt, idx++, &info->preload); + _save_column_str(stmt, idx++, &info->readonly); + _save_column_str(stmt, idx++, &info->update); + _save_column_str(stmt, idx++, &info->appsetting); + _save_column_str(stmt, idx++, &info->system); + _save_column_str(stmt, idx++, &info->type); + _save_column_str(stmt, idx++, &info->package_size); + _save_column_str(stmt, idx++, &info->installed_time); + _save_column_str(stmt, idx++, &info->storeclient_id); + _save_column_str(stmt, idx++, &info->mainapp_id); + _save_column_str(stmt, idx++, &info->package_url); + _save_column_str(stmt, idx++, &info->root_path); + _save_column_str(stmt, idx++, &info->csc_path); + _save_column_str(stmt, idx++, &info->nodisplay_setting); + _save_column_str(stmt, idx++, &info->api_version); + _save_column_str(stmt, idx++, &info->support_disable); + _save_column_str(stmt, idx++, &info->tep_name); + _save_column_str(stmt, idx++, &info->zip_mount_file); + _save_column_str(stmt, idx++, &info->support_mode); + } + info->for_all_users = - strdup((uid != GLOBAL_USER) ? "false" : "true"); + strdup((uid != global_user_uid) ? "false" : "true"); + + if (_pkginfo_get_plugin_execution_info(db, info->package, &info->plugin)) { + ret = PMINFO_R_ERROR; + goto catch; + } if (flag & PMINFO_PKGINFO_GET_AUTHOR) { /* TODO : author should be retrieved at package_localized_info */ author = calloc(1, sizeof(author_x)); if (author == NULL) { - pkgmgrinfo_basic_free_package(info); - sqlite3_finalize(stmt); - sqlite3_close_v2(db); - return PMINFO_R_ERROR; + ret = PMINFO_R_ERROR; + goto catch; } _save_column_str(stmt, idx++, &author->text); _save_column_str(stmt, idx++, &author->email); @@ -504,10 +637,8 @@ static int _pkginfo_get_packages(uid_t uid, const char *locale, _save_column_str(stmt, idx++, &tmp_record); if (_add_label_info_into_list(locale, tmp_record, &info->label)) { - pkgmgrinfo_basic_free_package(info); - sqlite3_finalize(stmt); - sqlite3_close_v2(db); - return PMINFO_R_ERROR; + ret = PMINFO_R_ERROR; + goto catch; } } @@ -515,10 +646,8 @@ static int _pkginfo_get_packages(uid_t uid, const char *locale, tmp_record = NULL; _save_column_str(stmt, idx++, &tmp_record); if (_add_icon_info_into_list(locale, tmp_record, &info->icon)) { - pkgmgrinfo_basic_free_package(info); - sqlite3_finalize(stmt); - sqlite3_close_v2(db); - return PMINFO_R_ERROR; + ret = PMINFO_R_ERROR; + goto catch; } } @@ -527,20 +656,32 @@ static int _pkginfo_get_packages(uid_t uid, const char *locale, _save_column_str(stmt, idx++, &tmp_record); if (_pkginfo_add_description_info_into_list(locale, tmp_record, &info->description)) { - pkgmgrinfo_basic_free_package(info); - sqlite3_finalize(stmt); - sqlite3_close_v2(db); - return PMINFO_R_ERROR; + ret = PMINFO_R_ERROR; + goto catch; } } if (flag & PMINFO_PKGINFO_GET_PRIVILEGE) { if (_pkginfo_get_privilege(db, info->package, &info->privileges)) { - pkgmgrinfo_basic_free_package(info); - sqlite3_finalize(stmt); - sqlite3_close_v2(db); - return PMINFO_R_ERROR; + ret = PMINFO_R_ERROR; + goto catch; + } + } + + if (flag & PMINFO_PKGINFO_GET_APPDEFINED_PRIVILEGE) { + if (_pkginfo_get_appdefined_privilege(db, info->package, + &info->appdefined_privileges)) { + ret = PMINFO_R_ERROR; + goto catch; + } + } + + if (flag & PMINFO_PKGINFO_GET_DEPENDENCY) { + if (_pkginfo_get_dependency(db, info->package, + &info->dependencies)) { + ret = PMINFO_R_ERROR; + goto catch; } } @@ -559,6 +700,9 @@ static int _pkginfo_get_packages(uid_t uid, const char *locale, ret = PMINFO_R_OK; catch: + sqlite3_finalize(stmt); + sqlite3_close_v2(db); + if (constraints) free(constraints); @@ -569,8 +713,6 @@ catch: pkgmgrinfo_pkginfo_filter_destroy(tmp_filter); g_list_free_full(bind_params, free); - sqlite3_close_v2(db); - sqlite3_finalize(stmt); return ret; } @@ -605,18 +747,30 @@ static int _pkginfo_get_filtered_foreach_pkginfo(uid_t uid, ret = pkgmgrinfo_pkginfo_filter_create((void *)&tmp_filter); if (ret != PMINFO_R_OK) { _LOGE("Failed to create filter"); + g_hash_table_destroy(list); + free(locale); return PMINFO_R_ERROR; } } - if (__check_disable_filter_exist(tmp_filter) == false) - pkgmgrinfo_pkginfo_filter_add_bool(tmp_filter, + if (__check_disable_filter_exist(tmp_filter) == false) { + ret = pkgmgrinfo_pkginfo_filter_add_bool(tmp_filter, PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, false); + if (ret != PMINFO_R_OK) { + _LOGE("Failed to add filter"); + g_hash_table_destroy(list); + free(locale); + if (filter == NULL) + pkgmgrinfo_pkginfo_filter_destroy(tmp_filter); + return PMINFO_R_ERROR; + } + } - ret = _pkginfo_get_packages(uid, locale, filter, flag, list); + ret = _pkginfo_get_packages(uid, locale, tmp_filter, + flag | PMINFO_PKGINFO_GET_BASICINFO, list); if (ret == PMINFO_R_OK && uid != GLOBAL_USER) - ret = _pkginfo_get_packages(GLOBAL_USER, locale, filter, - flag, list); + ret = _pkginfo_get_packages(GLOBAL_USER, locale, tmp_filter, + flag | PMINFO_PKGINFO_GET_BASICINFO, list); if (ret != PMINFO_R_OK) { g_hash_table_destroy(list); @@ -662,7 +816,8 @@ static int _pkgmgrinfo_get_pkginfo(const char *pkgid, uid_t uid, if (locale == NULL) return PMINFO_R_ERROR; - list = g_hash_table_new(g_str_hash, g_str_equal); + list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, + __free_packages); if (list == NULL) { free(locale); return PMINFO_R_ERROR; @@ -674,8 +829,14 @@ static int _pkgmgrinfo_get_pkginfo(const char *pkgid, uid_t uid, ret = _pkginfo_get_packages(GLOBAL_USER, locale, filter, PMINFO_PKGINFO_GET_ALL, list); + if (ret != PMINFO_R_OK) { + g_hash_table_destroy(list); + free(locale); + return ret; + } + if (!g_hash_table_size(list)) { - _LOGI("pkginfo for [%s] is not existed for user [%d]", + _LOGD("pkginfo for [%s] is not existed for user [%d]", pkgid, uid); g_hash_table_destroy(list); free(locale); @@ -695,6 +856,7 @@ static int _pkgmgrinfo_get_pkginfo(const char *pkgid, uid_t uid, info->locale = locale; /* just free list only */ + g_hash_table_steal(list, (gconstpointer)pkgid); g_hash_table_destroy(list); *handle = info; @@ -783,7 +945,8 @@ API int pkgmgrinfo_pkginfo_get_usr_disabled_pkginfo(const char *pkgid, return PMINFO_R_ERROR; } - list = g_hash_table_new(g_str_hash, g_str_equal); + list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, + __free_packages); if (list == NULL) { pkgmgrinfo_pkginfo_filter_destroy(filter); free(locale); @@ -804,7 +967,7 @@ API int pkgmgrinfo_pkginfo_get_usr_disabled_pkginfo(const char *pkgid, } if (!g_hash_table_size(list)) { - _LOGI("disabled pkginfo for [%s] is not existed for user [%d]", + _LOGD("disabled pkginfo for [%s] is not existed for user [%d]", pkgid, uid); g_hash_table_destroy(list); free(locale); @@ -824,6 +987,7 @@ API int pkgmgrinfo_pkginfo_get_usr_disabled_pkginfo(const char *pkgid, info->locale = locale; /* just free list only */ + g_hash_table_steal(list, (gconstpointer)pkgid); g_hash_table_destroy(list); *handle = info; @@ -883,13 +1047,25 @@ API int pkgmgrinfo_pkginfo_get_all_pkginfo(const char *pkgid, API int pkgmgrinfo_pkginfo_get_usr_list_full(pkgmgrinfo_pkg_list_cb pkg_list_cb, int flag, void *user_data, uid_t uid) { + int ret; + pkgmgrinfo_pkginfo_filter_h filter; + if (pkg_list_cb == NULL) { LOGE("invalid parameter"); return PMINFO_R_EINVAL; } - return _pkginfo_get_filtered_foreach_pkginfo(uid, NULL, flag, + /* create an empty filter */ + ret = pkgmgrinfo_pkginfo_filter_create(&filter); + if (ret != PMINFO_R_OK) + return ret; + + ret = _pkginfo_get_filtered_foreach_pkginfo(uid, filter, flag, pkg_list_cb, user_data); + + pkgmgrinfo_pkginfo_filter_destroy(filter); + + return ret; } API int pkgmgrinfo_pkginfo_get_list_full(pkgmgrinfo_pkg_list_cb pkg_list_cb, @@ -902,13 +1078,25 @@ API int pkgmgrinfo_pkginfo_get_list_full(pkgmgrinfo_pkg_list_cb pkg_list_cb, API int pkgmgrinfo_pkginfo_get_usr_list(pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data, uid_t uid) { + int ret; + pkgmgrinfo_pkginfo_filter_h filter; + if (pkg_list_cb == NULL) { LOGE("invalid parameter"); return PMINFO_R_EINVAL; } - return _pkginfo_get_filtered_foreach_pkginfo(uid, NULL, + /* create an empty filter */ + ret = pkgmgrinfo_pkginfo_filter_create(&filter); + if (ret != PMINFO_R_OK) + return ret; + + ret = _pkginfo_get_filtered_foreach_pkginfo(uid, filter, PMINFO_PKGINFO_GET_ALL, pkg_list_cb, user_data); + + pkgmgrinfo_pkginfo_filter_destroy(filter); + + return ret; } API int pkgmgrinfo_pkginfo_get_list(pkgmgrinfo_pkg_list_cb pkg_list_cb, @@ -1072,6 +1260,24 @@ API int pkgmgrinfo_pkginfo_get_zip_mount_file(pkgmgrinfo_pkginfo_h handle, char return PMINFO_R_OK; } +API int pkgmgrinfo_pkginfo_get_external_image_path(pkgmgrinfo_pkginfo_h handle, char **ext_image_path) +{ + pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle; + + retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n"); + retvm_if(ext_image_path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n"); + + if (info->pkg_info == NULL) + return PMINFO_R_ERROR; + + if (info->pkg_info->external_path == NULL) + return PMINFO_R_ENOENT; + + *ext_image_path = (char *)info->pkg_info->external_path; + + return PMINFO_R_OK; +} + API int pkgmgrinfo_pkginfo_get_install_location(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_install_location *location) { char *val; @@ -1274,6 +1480,8 @@ API int pkgmgrinfo_pkginfo_get_installed_storage(pkgmgrinfo_pkginfo_h handle, pk *storage = PMINFO_INTERNAL_STORAGE; else if (strcmp(info->pkg_info->installed_storage, "installed_external") == 0) *storage = PMINFO_EXTERNAL_STORAGE; + else if (strcmp(info->pkg_info->installed_storage, "installed_extended") == 0) + *storage = PMINFO_EXTENDED_STORAGE; else return PMINFO_R_ERROR; @@ -1484,8 +1692,6 @@ API int pkgmgrinfo_pkginfo_is_movable(pkgmgrinfo_pkginfo_h handle, bool *movable val = (char *)info->pkg_info->installlocation; if (strcmp(val, "internal-only") == 0) *movable = 0; - else if (strcmp(val, "prefer-external") == 0) - *movable = 1; else *movable = 1; @@ -1626,6 +1832,8 @@ API int pkgmgrinfo_pkginfo_filter_destroy(pkgmgrinfo_pkginfo_filter_h handle) g_slist_free(filter->list); } + g_slist_free_full(filter->list_metadata, __destroy_metadata_node); + free(filter); return PMINFO_R_OK; @@ -1798,6 +2006,7 @@ API int pkgmgrinfo_pkginfo_usr_filter_count(pkgmgrinfo_pkginfo_filter_h handle, PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, false); if (ret != PMINFO_R_OK) { free(locale); + g_hash_table_destroy(list); return PMINFO_R_ERROR; } } @@ -1853,6 +2062,7 @@ API int pkgmgrinfo_pkginfo_foreach_privilege(pkgmgrinfo_pkginfo_h handle, retvm_if(privilege_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL"); int ret; privilege_x *privilege; + appdefined_privilege_x *appdefined_privilege; GList *tmp; pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle; @@ -1865,8 +2075,262 @@ API int pkgmgrinfo_pkginfo_foreach_privilege(pkgmgrinfo_pkginfo_h handle, continue; ret = privilege_func(privilege->value, user_data); if (ret < 0) + return PMINFO_R_OK; + } + + for (tmp = info->pkg_info->appdefined_privileges; tmp; + tmp = tmp->next) { + appdefined_privilege = (appdefined_privilege_x *)tmp->data; + if (appdefined_privilege == NULL) + continue; + ret = privilege_func(appdefined_privilege->value, user_data); + if (ret < 0) + return PMINFO_R_OK; + } + return PMINFO_R_OK; +} + +API int pkgmgrinfo_pkginfo_foreach_plugin(pkgmgrinfo_pkginfo_h handle, + pkgmgrinfo_plugin_list_cb plugin_func, void *user_data) +{ + retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL"); + retvm_if(plugin_func == NULL, PMINFO_R_EINVAL, + "Callback function is NULL"); + int ret; + plugin_x *plugin; + GList *tmp; + pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle; + + if (info->pkg_info == NULL) + return PMINFO_R_ERROR; + + for (tmp = info->pkg_info->plugin; tmp; tmp = tmp->next) { + plugin = (plugin_x *)tmp->data; + if (plugin == NULL) + continue; + ret = plugin_func(plugin->pkgid, plugin->appid, + plugin->plugin_type, plugin->plugin_name, user_data); + if (ret < 0) + return PMINFO_R_OK; + } + + return PMINFO_R_OK; +} + +API int pkgmgrinfo_pkginfo_foreach_appdefined_privilege( + pkgmgrinfo_pkginfo_h handle, + pkgmgrinfo_pkg_appdefined_privilege_list_cb privilege_func, + void *user_data) +{ + retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL"); + retvm_if(privilege_func == NULL, PMINFO_R_EINVAL, + "Callback function is NULL"); + int ret; + appdefined_privilege_x *privilege; + GList *tmp; + pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle; + + if (info->pkg_info == NULL) + return PMINFO_R_ERROR; + + for (tmp = info->pkg_info->appdefined_privileges; tmp; + tmp = tmp->next) { + privilege = (appdefined_privilege_x *)tmp->data; + if (privilege == NULL) + continue; + ret = privilege_func(privilege->value, privilege->license, + user_data); + if (ret < 0) + break; + } + return PMINFO_R_OK; +} + +API int pkgmgrinfo_pkginfo_foreach_dependency(pkgmgrinfo_pkginfo_h handle, + pkgmgrinfo_pkg_dependency_list_cb dependency_cb, + void *user_data) +{ + int ret; + pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle; + GList *tmp; + dependency_x *dependency; + + if (handle == NULL || dependency_cb == NULL) { + LOGE("invalid parameter"); + return PMINFO_R_EINVAL; + } + + if (info->pkg_info == NULL) + return PMINFO_R_ERROR; + + for (tmp = info->pkg_info->dependencies; tmp; tmp = tmp->next) { + dependency = (dependency_x *)tmp->data; + if (dependency == NULL) + continue; + ret = dependency_cb(info->pkg_info->package, + dependency->depends_on, dependency->type, + dependency->required_version, user_data); + if (ret < 0) + break; + } + + return PMINFO_R_OK; +} + +struct depends_on { + char *from; + char *to; + char *type; + char *version; +}; + +static int _get_depends_on(sqlite3 *db, const char *pkgid, GQueue **queue, + GHashTable **table, GList **pkg_list) +{ + static const char query[] = + "SELECT package, depends_on, type, required_version " + "FROM package_dependency_info WHERE depends_on=?"; + int ret; + sqlite3_stmt *stmt; + struct depends_on *req; + + /* already checked */ + if (!g_hash_table_insert(*table, strdup(pkgid), GINT_TO_POINTER(1))) + return PMINFO_R_OK; + + ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL); + if (ret != SQLITE_OK) { + LOGE("prepare failed: %s", sqlite3_errmsg(db)); + return PMINFO_R_ERROR; + } + + ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_STATIC); + if (ret != SQLITE_OK) { + LOGE("bind failed: %s", sqlite3_errmsg(db)); + sqlite3_finalize(stmt); + return PMINFO_R_ERROR; + } + + while (sqlite3_step(stmt) == SQLITE_ROW) { + req = calloc(1, sizeof(struct depends_on)); + if (req == NULL) { + LOGE("out of memory"); + sqlite3_finalize(stmt); + return PMINFO_R_ERROR; + } + _save_column_str(stmt, 0, &req->from); + _save_column_str(stmt, 1, &req->to); + _save_column_str(stmt, 2, &req->type); + _save_column_str(stmt, 3, &req->version); + + *pkg_list = g_list_append(*pkg_list, req); + g_queue_push_tail(*queue, strdup(req->from)); + } + + sqlite3_finalize(stmt); + + return PMINFO_R_OK; +} + +static int _pkginfo_foreach_depends_on(uid_t uid, const char *pkgid, + GList **pkg_list) +{ + int ret; + char *dbpath; + sqlite3 *db; + GQueue *queue; + GHashTable *table; + char *item; + + dbpath = getUserPkgParserDBPathUID(uid); + if (dbpath == NULL) + return PMINFO_R_ERROR; + + ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY); + if (ret != SQLITE_OK) { + LOGD("failed to open db(%s): %d", dbpath, ret); + free(dbpath); + return PMINFO_R_ERROR; + } + free(dbpath); + + queue = g_queue_new(); + if (queue == NULL) { + LOGE("out of memory"); + sqlite3_close_v2(db); + return PMINFO_R_ERROR; + } + + table = g_hash_table_new_full(g_str_hash, g_str_equal, free, NULL); + + g_queue_push_tail(queue, strdup(pkgid)); + while (!g_queue_is_empty(queue)) { + item = g_queue_pop_head(queue); + ret = _get_depends_on(db, item, &queue, &table, pkg_list); + free(item); + if (ret != PMINFO_R_OK) { + LOGE("failed to get pkgs depends on %s", pkgid); + g_hash_table_destroy(table); + g_queue_free_full(queue, free); + sqlite3_close_v2(db); + return PMINFO_R_ERROR; + } + } + + g_hash_table_destroy(table); + g_queue_free_full(queue, free); + sqlite3_close_v2(db); + + return PMINFO_R_OK; +} + +static void __free_depends_on(gpointer data) +{ + struct depends_on *dep = (struct depends_on *)data; + + free(dep->from); + free(dep->to); + free(dep->type); + free(dep->version); + free(dep); +} + +API int pkgmgrinfo_pkginfo_foreach_depends_on(pkgmgrinfo_pkginfo_h handle, + pkgmgrinfo_pkg_dependency_list_cb dependency_cb, + void *user_data) +{ + int ret; + pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle; + GList *pkg_list = NULL; + GList *l; + struct depends_on *dep; + + if (handle == NULL || dependency_cb == NULL || info->pkg_info == NULL) { + LOGE("invalid parameter"); + return PMINFO_R_EINVAL; + } + + ret = _pkginfo_foreach_depends_on(info->uid, info->pkg_info->package, + &pkg_list); + if (ret == PMINFO_R_OK && info->uid != GLOBAL_USER) + ret = _pkginfo_foreach_depends_on(GLOBAL_USER, + info->pkg_info->package, &pkg_list); + + if (ret != PMINFO_R_OK) { + g_list_free_full(pkg_list, __free_depends_on); + return ret; + } + + for (l = pkg_list; l != NULL; l = l->next) { + dep = (struct depends_on *)l->data; + ret = dependency_cb(dep->from, dep->to, dep->type, dep->version, + user_data); + if (ret < 0) break; } + + g_list_free_full(pkg_list, __free_depends_on); + return PMINFO_R_OK; } @@ -1908,7 +2372,7 @@ int __compare_package_version(const char *version, int *major, *major = atoi(major_str); *minor = atoi(minor_str); *macro = 0; - *minor = 0; + *nano = 0; macro_str = strtok_r(NULL, ".", &save_str); if (macro_str == NULL) { _LOGD("macro version is NULL");