X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fpkgmgrinfo_pkginfo.c;h=8423b8a9bea0ffa06ebd5c209fbfc295fb8598d2;hb=5bd3f7adcef7105b577414ee69779c7cc527cb99;hp=a71f79e5b014881443aedc6b29104f38abb8d462;hpb=b14aab87afa07886f2a23629be66c794c896521a;p=platform%2Fcore%2Fappfw%2Fpkgmgr-info.git diff --git a/src/pkgmgrinfo_pkginfo.c b/src/pkgmgrinfo_pkginfo.c index a71f79e..8423b8a 100644 --- a/src/pkgmgrinfo_pkginfo.c +++ b/src/pkgmgrinfo_pkginfo.c @@ -32,9 +32,6 @@ #include #include -#include -#include -#include #include #include @@ -46,16 +43,9 @@ #include "pkgmgr_parser_db.h" #include "pkgmgr_parser_internal.h" -static int _pkginfo_get_pkginfo(const char *pkgid, uid_t uid, - pkgmgr_pkginfo_x **pkginfo); -static char *_get_filtered_query(const char *query_raw, - pkgmgrinfo_filter_x *filter); - static bool _get_bool_value(const char *str) { - if (str == NULL) - return false; - else if (!strcasecmp(str, "true")) + if (str && !strcmp(str, "true")) return true; else return false; @@ -103,37 +93,6 @@ static void __cleanup_pkginfo(pkgmgr_pkginfo_x *data) return; } -static int __child_element(xmlTextReaderPtr reader, int depth) -{ - int ret = xmlTextReaderRead(reader); - int cur = xmlTextReaderDepth(reader); - while (ret == 1) { - - switch (xmlTextReaderNodeType(reader)) { - case XML_READER_TYPE_ELEMENT: - if (cur == depth + 1) - return 1; - break; - case XML_READER_TYPE_TEXT: - /*text is handled by each function separately*/ - if (cur == depth + 1) - return 0; - break; - case XML_READER_TYPE_END_ELEMENT: - if (cur == depth) - return 0; - break; - default: - if (cur <= depth) - return 0; - break; - } - ret = xmlTextReaderRead(reader); - cur = xmlTextReaderDepth(reader); - } - return ret; -} - long long _pkgmgr_calculate_dir_size(char *dirname) { long long total = 0; @@ -141,233 +100,54 @@ long long _pkgmgr_calculate_dir_size(char *dirname) int q = 0; /*quotient*/ int r = 0; /*remainder*/ DIR *dp = NULL; - struct dirent *ep = NULL; + struct dirent ep, *result; struct stat fileinfo; char abs_filename[FILENAME_MAX] = { 0, }; retvm_if(dirname == NULL, PMINFO_R_ERROR, "dirname is NULL"); dp = opendir(dirname); - if (dp != NULL) { - while ((ep = readdir(dp)) != NULL) { - if (!strcmp(ep->d_name, ".") || - !strcmp(ep->d_name, "..")) { - continue; - } - snprintf(abs_filename, FILENAME_MAX, "%s/%s", dirname, - 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, "..")) { - ret = _pkgmgr_calculate_dir_size - (abs_filename); - total = total + ret; - } - } else if (S_ISLNK(fileinfo.st_mode)) { - continue; - } else { - /*It is a file. Calculate the actual - size occupied (in terms of 4096 blocks)*/ - q = (fileinfo.st_size / BLOCK_SIZE); - r = (fileinfo.st_size % BLOCK_SIZE); - if (r) { - q = q + 1; - } - total += q * BLOCK_SIZE; - } - } - } - (void)closedir(dp); - } else { + if (dp == NULL) { _LOGE("Couldn't open the directory\n"); return -1; } - return total; - -} - -static gint __list_strcmp(gconstpointer a, gconstpointer b) -{ - return strcmp((char *)a, (char *)b); -} - -static int _pkginfo_get_list(sqlite3 *db, const char *locale, - pkgmgrinfo_filter_x *filter, GList **list) -{ - static const char query_raw[] = - "SELECT DISTINCT package_info.package FROM package_info" - " LEFT OUTER JOIN package_localized_info" - " ON package_info.package=package_localized_info.package" - " AND package_localized_info.package_locale=%Q " - " LEFT OUTER JOIN package_privilege_info" - " ON package_info.package=package_privilege_info.package"; - int ret; - char *query; - char *query_localized; - sqlite3_stmt *stmt; - char *pkgid = NULL; - - query = _get_filtered_query(query_raw, filter); - if (query == NULL) - return -1; - query_localized = sqlite3_mprintf(query, locale); - free(query); - if (query_localized == NULL) - return -1; - - ret = sqlite3_prepare_v2(db, query_localized, - strlen(query_localized), &stmt, NULL); - sqlite3_free(query_localized); - if (ret != SQLITE_OK) { - LOGE("prepare failed: %s", sqlite3_errmsg(db)); - return -1; - } - - while (sqlite3_step(stmt) == SQLITE_ROW) { - _save_column_str(stmt, 0, (const char **)&pkgid); - if (pkgid != NULL) - *list = g_list_insert_sorted(*list, pkgid, - __list_strcmp); - } - - sqlite3_finalize(stmt); - - return 0; -} - -static int _pkginfo_get_filtered_list(pkgmgrinfo_filter_x *filter, uid_t uid, - GList **list) -{ - int ret; - sqlite3 *db; - const char *dbpath; - char *locale; - GList *tmp; - GList *tmp2; - - locale = _get_system_locale(); - if (locale == NULL) - return PMINFO_R_ERROR; - - dbpath = getUserPkgParserDBPathUID(uid); - if (dbpath == NULL) { - free(locale); - return PMINFO_R_ERROR; - } - - ret = sqlite3_open_v2(dbpath, &db, SQLITE_OPEN_READONLY, NULL); - if (ret != SQLITE_OK) { - _LOGE("failed to open db: %d", ret); - free(locale); - return PMINFO_R_ERROR; - } - - if (_pkginfo_get_list(db, locale, filter, list)) { - free(locale); - sqlite3_close_v2(db); - return PMINFO_R_ERROR; - } - sqlite3_close_v2(db); - - if (uid == GLOBAL_USER) { - free(locale); - return PMINFO_R_OK; - } - - /* search again from global */ - dbpath = getUserPkgParserDBPathUID(GLOBAL_USER); - if (dbpath == NULL) { - free(locale); - return PMINFO_R_ERROR; - } - - ret = sqlite3_open_v2(dbpath, &db, SQLITE_OPEN_READONLY, NULL); - if (ret != SQLITE_OK) { - _LOGE("failed to open db: %d", ret); - free(locale); - return PMINFO_R_ERROR; - } - - if (_pkginfo_get_list(db, locale, filter, list)) { - free(locale); - sqlite3_close_v2(db); - return PMINFO_R_ERROR; - } - sqlite3_close_v2(db); - /* remove duplicate element: - * since the list is sorted, we can remove duplicates in linear time - */ - for (tmp = *list, tmp2 = g_list_next(tmp); tmp; - tmp = tmp2, tmp2 = g_list_next(tmp)) { - if (tmp->prev == NULL || tmp->data == NULL) + 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, "..")) { continue; - if (strcmp((const char *)tmp->prev->data, - (const char *)tmp->data) == 0) - *list = g_list_delete_link(*list, tmp); - } - - free(locale); - - return PMINFO_R_OK; -} - - -static int _pkginfo_get_filtered_foreach_pkginfo(pkgmgrinfo_filter_x *filter, - pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data, uid_t uid) -{ - int ret; - pkgmgr_pkginfo_x *info; - GList *list = NULL; - GList *tmp; - char *pkgid; - int stop = 0; - - ret = _pkginfo_get_filtered_list(filter, uid, &list); - if (ret != PMINFO_R_OK) - return PMINFO_R_ERROR; - - for (tmp = list; tmp; tmp = tmp->next) { - pkgid = (char *)tmp->data; - if (stop == 0) { - ret = _pkginfo_get_pkginfo(pkgid, uid, &info); - if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER) - ret = _pkginfo_get_pkginfo(pkgid, GLOBAL_USER, - &info); - if (ret != PMINFO_R_OK) { - free(pkgid); + } + snprintf(abs_filename, FILENAME_MAX, "%s/%s", dirname, + 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, "..")) { + ret = _pkgmgr_calculate_dir_size + (abs_filename); + total = total + ret; + } + } else if (S_ISLNK(fileinfo.st_mode)) { continue; + } else { + /*It is a file. Calculate the actual + size occupied (in terms of 4096 blocks)*/ + q = (fileinfo.st_size / BLOCK_SIZE); + r = (fileinfo.st_size % BLOCK_SIZE); + if (r) { + q = q + 1; + } + total += q * BLOCK_SIZE; } - if (pkg_list_cb(info, user_data) < 0) - stop = 1; - pkgmgrinfo_pkginfo_destroy_pkginfo(info); } - free(pkgid); } + (void)closedir(dp); + return total; - g_list_free(list); - - return PMINFO_R_OK; -} - -API int pkgmgrinfo_pkginfo_get_usr_list(pkgmgrinfo_pkg_list_cb pkg_list_cb, - void *user_data, uid_t uid) -{ - if (pkg_list_cb == NULL) { - LOGE("invalid parameter"); - return PMINFO_R_EINVAL; - } - - return _pkginfo_get_filtered_foreach_pkginfo(NULL, pkg_list_cb, - user_data, uid); -} - -API int pkgmgrinfo_pkginfo_get_list(pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data) -{ - return pkgmgrinfo_pkginfo_get_usr_list(pkg_list_cb, user_data, GLOBAL_USER); } static int _pkginfo_get_author(sqlite3 *db, const char *pkgid, @@ -565,7 +345,7 @@ static int _pkginfo_get_privilege(sqlite3 *db, const char *pkgid, int ret; char *query; sqlite3_stmt *stmt; - const char *privilege; + char *privilege; query = sqlite3_mprintf(query_raw, pkgid); if (query == NULL) { @@ -594,226 +374,445 @@ static int _pkginfo_get_privilege(sqlite3 *db, const char *pkgid, return PMINFO_R_OK; } -static char *_get_filtered_query(const char *query_raw, - pkgmgrinfo_filter_x *filter) +static const char join_localized_info[] = + " LEFT OUTER JOIN package_localized_info" + " ON pi.package=package_localized_info.package" + " AND package_localized_info.package_locale=?"; +static const char join_privilege_info[] = + " LEFT OUTER JOIN package_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) { - char buf[MAX_QUERY_LEN] = { 0, }; - char *condition; - size_t len; - GSList *list; - GSList *head = NULL; + 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) - head = filter->list; + if (filter == NULL) + return PMINFO_R_OK; - strncat(buf, query_raw, MAX_QUERY_LEN - 1); - len = strlen(buf); - for (list = head; list; list = list->next) { - /* TODO: revise condition getter function */ - __get_filter_condition(list->data, &condition); + len += strlen(" WHERE 1=1 "); + strncat(buf, " WHERE 1=1 ", MAX_QUERY_LEN - len - 1); + for (list = filter->list; list; list = list->next) { + joined |= __get_filter_condition(list->data, &condition, + bind_params); if (condition == NULL) continue; - if (buf[strlen(query_raw)] == '\0') { - len += strlen(" WHERE "); - strncat(buf, " WHERE ", MAX_QUERY_LEN - len - 1); - } else { - len += strlen(" AND "); - strncat(buf, " AND ", MAX_QUERY_LEN -len - 1); - } + + len += strlen(" AND "); + strncat(buf, " AND ", MAX_QUERY_LEN - len - 1); + len += strlen(condition); strncat(buf, condition, sizeof(buf) - len - 1); free(condition); condition = NULL; } - return strdup(buf); + if (joined & E_PMINFO_PKGINFO_JOIN_LOCALIZED_INFO) { + strncat(buf2, join_localized_info, MAX_QUERY_LEN - len - 1); + len += strlen(join_localized_info); + *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); + + *query = strdup(buf2); + if (*query == NULL) + return PMINFO_R_ERROR; + + return PMINFO_R_OK; } -static int _pkginfo_get_package(sqlite3 *db, const char *pkgid, - const char *locale, package_x **package) +static void __free_packages(gpointer data) { - static const char query_raw[] = - "SELECT package, package_version, " - "install_location, package_removable, package_preload, " - "package_readonly, package_update, package_appsetting, " - "package_system, package_type, package_size, installed_time, " - "installed_storage, storeclient_id, mainapp_id, package_url, " - "root_path, csc_path, package_nodisplay, package_api_version, " - "package_support_disable, package_tep_name " - "FROM package_info WHERE package=%Q"; + pkgmgrinfo_basic_free_package((package_x *)data); +} + +static int __bind_params(sqlite3_stmt *stmt, GList *params) +{ + GList *tmp_list = NULL; + int idx = 0; int ret; - char *query; + + if (stmt == NULL || params == NULL) + return PMINFO_R_EINVAL; + + tmp_list = params; + while (tmp_list) { + ret = sqlite3_bind_text(stmt, ++idx, (char *)tmp_list->data, -1, SQLITE_STATIC); + if (ret != SQLITE_OK) + return PMINFO_R_ERROR; + tmp_list = tmp_list->next; + } + + return PMINFO_R_OK; +} + +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 " + "FROM package_info as pi "; + int ret = PMINFO_R_ERROR; + int idx = 0; + const char *dbpath; + char *constraints = NULL; + char query[MAX_QUERY_LEN] = { '\0' }; + package_x *info = NULL; + GList *bind_params = NULL; + sqlite3 *db; sqlite3_stmt *stmt; - int idx; - package_x *info; + pkgmgrinfo_filter_x *tmp_filter = NULL; - query = sqlite3_mprintf(query_raw, pkgid); - if (query == NULL) { - LOGE("out of memory"); + dbpath = getUserPkgParserDBPathUID(uid); + if (dbpath == NULL) return PMINFO_R_ERROR; - } - ret = sqlite3_prepare_v2(db, query, strlen(query), - &stmt, NULL); - sqlite3_free(query); + ret = sqlite3_open_v2(dbpath, &db, SQLITE_OPEN_READONLY, NULL); if (ret != SQLITE_OK) { - LOGE("prepare failed: %s", sqlite3_errmsg(db)); + _LOGD("failed to open db: %d", ret); return PMINFO_R_ERROR; } - ret = sqlite3_step(stmt); - if (ret == SQLITE_DONE) { - sqlite3_finalize(stmt); - return PMINFO_R_ENOENT; - } else if (ret != SQLITE_ROW) { - LOGE("step failed: %s", sqlite3_errmsg(db)); - sqlite3_finalize(stmt); - return PMINFO_R_ERROR; + if (filter != NULL) { + tmp_filter = filter; + } else { + ret = pkgmgrinfo_pkginfo_filter_create((void *)&tmp_filter); + if (ret != PMINFO_R_OK) { + _LOGE("Failed to create filter"); + return PMINFO_R_ERROR; + } } - info = calloc(1, sizeof(package_x)); - if (info == NULL) { - LOGE("out of memory"); - sqlite3_finalize(stmt); - return PMINFO_R_ERROR; + /* add package_disable='false' clause by default */ + pkgmgrinfo_pkginfo_filter_add_bool(tmp_filter, PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, false); + + ret = _get_filtered_query(tmp_filter, locale, &constraints, &bind_params); + if (ret != PMINFO_R_OK) { + LOGE("Failed to get WHERE clause"); + goto catch; } - idx = 0; - _save_column_str(stmt, idx++, &info->package); - _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); - - if (_pkginfo_get_author(db, info->package, &info->author)) { - pkgmgrinfo_basic_free_package(info); - sqlite3_finalize(stmt); - return PMINFO_R_ERROR; + + if (constraints) + snprintf(query, MAX_QUERY_LEN - 1, "%s%s", query_raw, constraints); + else + snprintf(query, MAX_QUERY_LEN - 1, "%s", query_raw); + + ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL); + if (ret != SQLITE_OK) { + LOGE("prepare failed: %s", sqlite3_errmsg(db)); + ret = PMINFO_R_ERROR; + goto catch; } - if (_pkginfo_get_label(db, info->package, locale, &info->label)) { - pkgmgrinfo_basic_free_package(info); - sqlite3_finalize(stmt); - return PMINFO_R_ERROR; + ret = __bind_params(stmt, bind_params); + if (ret != SQLITE_OK) { + LOGE("Failed to bind parameters"); + goto catch; } - if (_pkginfo_get_icon(db, info->package, locale, &info->icon)) { - pkgmgrinfo_basic_free_package(info); - sqlite3_finalize(stmt); - return PMINFO_R_ERROR; + while (sqlite3_step(stmt) == SQLITE_ROW) { + info = calloc(1, sizeof(package_x)); + if (info == NULL) { + LOGE("out of memory"); + sqlite3_finalize(stmt); + sqlite3_close_v2(db); + return PMINFO_R_ERROR; + } + 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); + info->for_all_users = + strdup((uid != GLOBAL_USER) ? "false" : "true"); + + if (flag & PMINFO_PKGINFO_GET_AUTHOR) { + if (_pkginfo_get_author(db, info->package, + &info->author)) { + pkgmgrinfo_basic_free_package(info); + sqlite3_finalize(stmt); + sqlite3_close_v2(db); + return PMINFO_R_ERROR; + } + } + + if (flag & PMINFO_PKGINFO_GET_LABEL) { + if (_pkginfo_get_label(db, info->package, locale, + &info->label)) { + pkgmgrinfo_basic_free_package(info); + sqlite3_finalize(stmt); + sqlite3_close_v2(db); + return PMINFO_R_ERROR; + } + } + + if (flag & PMINFO_PKGINFO_GET_ICON) { + if (_pkginfo_get_icon(db, info->package, locale, + &info->icon)) { + pkgmgrinfo_basic_free_package(info); + sqlite3_finalize(stmt); + sqlite3_close_v2(db); + return PMINFO_R_ERROR; + } + } + + if (flag & PMINFO_PKGINFO_GET_DESCRIPTION) { + if (_pkginfo_get_description(db, info->package, locale, + &info->description)) { + pkgmgrinfo_basic_free_package(info); + sqlite3_finalize(stmt); + sqlite3_close_v2(db); + return PMINFO_R_ERROR; + } + } + + 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; + } + } + + g_hash_table_insert(packages, (gpointer)info->package, + (gpointer)info); } - if (_pkginfo_get_description(db, info->package, locale, - &info->description)) { + ret = PMINFO_R_OK; + +catch: + if (constraints) + free(constraints); + + if (ret != PMINFO_R_OK && info != NULL) pkgmgrinfo_basic_free_package(info); - sqlite3_finalize(stmt); + + if (filter == NULL) + pkgmgrinfo_pkginfo_filter_destroy(tmp_filter); + + g_list_free_full(bind_params, free); + sqlite3_close_v2(db); + sqlite3_finalize(stmt); + + return ret; +} + +static int _pkginfo_get_filtered_foreach_pkginfo(uid_t uid, + pkgmgrinfo_filter_x *filter, int flag, + pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data) +{ + int ret; + char *locale; + package_x *pkg; + pkgmgr_pkginfo_x info; + GHashTable *list; + GHashTableIter iter; + gpointer value; + + locale = _get_system_locale(); + if (locale == NULL) + return PMINFO_R_ERROR; + + list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, + __free_packages); + if (list == NULL) { + free(locale); return PMINFO_R_ERROR; } - if (_pkginfo_get_privilege(db, info->package, &info->privileges)) { - pkgmgrinfo_basic_free_package(info); - sqlite3_finalize(stmt); + ret = _pkginfo_get_packages(uid, locale, filter, flag, list); + if (ret == PMINFO_R_OK && uid != GLOBAL_USER) + ret = _pkginfo_get_packages(GLOBAL_USER, locale, filter, + flag, list); + + if (ret != PMINFO_R_OK) { + g_hash_table_destroy(list); + free(locale); return PMINFO_R_ERROR; } - *package = info; - sqlite3_finalize(stmt); + g_hash_table_iter_init(&iter, list); + while (g_hash_table_iter_next(&iter, NULL, &value)) { + pkg = (package_x *)value; + info.uid = uid; + info.pkg_info = pkg; + info.locale = locale; + if (pkg_list_cb(&info, user_data) < 0) + break; + } + + g_hash_table_destroy(list); + free(locale); return PMINFO_R_OK; } -static int _pkginfo_get_pkginfo(const char *pkgid, uid_t uid, - pkgmgr_pkginfo_x **pkginfo) +API int pkgmgrinfo_pkginfo_get_usr_pkginfo(const char *pkgid, uid_t uid, + pkgmgrinfo_pkginfo_h *handle) { int ret; - sqlite3 *db; - const char *dbpath; char *locale; + GHashTable *list; + pkgmgrinfo_pkginfo_filter_h filter; pkgmgr_pkginfo_x *info; - dbpath = getUserPkgParserDBPathUID(uid); - if (dbpath == NULL) - return PMINFO_R_ERROR; + if (pkgid == NULL || handle == NULL) { + LOGE("invalid parameter"); + return PMINFO_R_EINVAL; + } locale = _get_system_locale(); if (locale == NULL) return PMINFO_R_ERROR; - ret = sqlite3_open_v2(dbpath, &db, SQLITE_OPEN_READONLY, NULL); - if (ret != SQLITE_OK) { - _LOGE("failed to open db: %d", ret); + ret = pkgmgrinfo_pkginfo_filter_create(&filter); + if (ret != PMINFO_R_OK) { + free(locale); + return ret; + } + + ret = pkgmgrinfo_pkginfo_filter_add_string(filter, + PMINFO_PKGINFO_PROP_PACKAGE_ID, pkgid); + if (ret != PMINFO_R_OK) { + pkgmgrinfo_pkginfo_filter_destroy(filter); free(locale); return PMINFO_R_ERROR; } - info = calloc(1, sizeof(pkgmgr_pkginfo_x)); - if (info == NULL) { - _LOGE("out of memory"); + list = g_hash_table_new(g_str_hash, g_str_equal); + if (list == NULL) { + pkgmgrinfo_pkginfo_filter_destroy(filter); free(locale); - sqlite3_close_v2(db); return PMINFO_R_ERROR; } - ret = _pkginfo_get_package(db, pkgid, locale, &info->pkg_info); + ret = _pkginfo_get_packages(uid, locale, filter, + PMINFO_PKGINFO_GET_ALL, list); + if (!g_hash_table_size(list) && uid != GLOBAL_USER) + ret = _pkginfo_get_packages(GLOBAL_USER, locale, filter, + PMINFO_PKGINFO_GET_ALL, list); + + pkgmgrinfo_pkginfo_filter_destroy(filter); if (ret != PMINFO_R_OK) { - free(info); + g_hash_table_destroy(list); free(locale); - sqlite3_close_v2(db); return ret; } - info->locale = locale; + if (!g_hash_table_size(list)) { + _LOGI("pkginfo for [%s] is not existed for user [%d]", + pkgid, uid); + g_hash_table_destroy(list); + free(locale); + return PMINFO_R_ENOENT; + } + + info = calloc(1, sizeof(pkgmgr_pkginfo_x)); + if (info == NULL) { + _LOGE("out of memory"); + g_hash_table_destroy(list); + free(locale); + return PMINFO_R_ERROR; + } + info->uid = uid; - info->pkg_info->for_all_users = strdup( - uid != GLOBAL_USER ? "false" : "true"); + info->pkg_info = (package_x *)g_hash_table_lookup(list, pkgid); + info->locale = locale; - *pkginfo = info; + /* just free list only */ + g_hash_table_destroy(list); - sqlite3_close_v2(db); + *handle = info; return ret; } -API int pkgmgrinfo_pkginfo_get_usr_pkginfo(const char *pkgid, uid_t uid, +API int pkgmgrinfo_pkginfo_get_pkginfo(const char *pkgid, pkgmgrinfo_pkginfo_h *handle) { - int ret; + return pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, _getuid(), handle); +} - if (pkgid == NULL || handle == NULL) { +API int pkgmgrinfo_pkginfo_get_usr_list_full(pkgmgrinfo_pkg_list_cb pkg_list_cb, + int flag, void *user_data, uid_t uid) +{ + if (pkg_list_cb == NULL) { LOGE("invalid parameter"); return PMINFO_R_EINVAL; } - ret = _pkginfo_get_pkginfo(pkgid, uid, (pkgmgr_pkginfo_x **)handle); - if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER) - ret = _pkginfo_get_pkginfo(pkgid, GLOBAL_USER, - (pkgmgr_pkginfo_x **)handle); + return _pkginfo_get_filtered_foreach_pkginfo(uid, NULL, flag, + pkg_list_cb, user_data); +} - if (ret != PMINFO_R_OK) - _LOGE("failed to get pkginfo of %s for user %d", pkgid, uid); +API int pkgmgrinfo_pkginfo_get_list_full(pkgmgrinfo_pkg_list_cb pkg_list_cb, + int flag, void *user_data) +{ + return pkgmgrinfo_pkginfo_get_usr_list_full(pkg_list_cb, flag, + user_data, _getuid()); +} - return ret; +API int pkgmgrinfo_pkginfo_get_usr_list(pkgmgrinfo_pkg_list_cb pkg_list_cb, + void *user_data, uid_t uid) +{ + if (pkg_list_cb == NULL) { + LOGE("invalid parameter"); + return PMINFO_R_EINVAL; + } + + return _pkginfo_get_filtered_foreach_pkginfo(uid, NULL, + PMINFO_PKGINFO_GET_ALL, pkg_list_cb, user_data); } -API int pkgmgrinfo_pkginfo_get_pkginfo(const char *pkgid, pkgmgrinfo_pkginfo_h *handle) +API int pkgmgrinfo_pkginfo_get_list(pkgmgrinfo_pkg_list_cb pkg_list_cb, + void *user_data) { - return pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, GLOBAL_USER, handle); + return pkgmgrinfo_pkginfo_get_usr_list(pkg_list_cb, user_data, + _getuid()); } API int pkgmgrinfo_pkginfo_get_pkgname(pkgmgrinfo_pkginfo_h handle, char **pkg_name) @@ -853,8 +852,10 @@ API int pkgmgrinfo_pkginfo_get_type(pkgmgrinfo_pkginfo_h handle, char **type) retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n"); retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n"); - if (info->pkg_info == NULL || info->pkg_info->type == NULL) + if (info->pkg_info == NULL) return PMINFO_R_ERROR; + if (info->pkg_info->type == NULL) + info->pkg_info->type = strdup(""); *type = (char *)info->pkg_info->type; @@ -868,220 +869,109 @@ API int pkgmgrinfo_pkginfo_get_version(pkgmgrinfo_pkginfo_h handle, char **versi retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n"); retvm_if(version == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n"); - if (info->pkg_info == NULL || info->pkg_info->version == NULL) + if (info->pkg_info == NULL) return PMINFO_R_ERROR; + if (info->pkg_info->version == NULL) + info->pkg_info->version = strdup(""); *version = (char *)info->pkg_info->version; return PMINFO_R_OK; } -API int pkgmgrinfo_pkginfo_get_tep_name(pkgmgrinfo_pkginfo_h handle, char **tep_name) +API int pkgmgrinfo_pkginfo_get_api_version(pkgmgrinfo_pkginfo_h handle, char **api_version) { pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle; retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n"); - retvm_if(tep_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n"); - - if (info->pkg_info == NULL || info->pkg_info->tep_name == NULL) - return PMINFO_R_ERROR; - - *tep_name = (char *)info->pkg_info->tep_name; + retvm_if(api_version == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n"); - return PMINFO_R_OK; -} - -API int pkgmgrinfo_pkginfo_get_install_location(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_install_location *location) -{ - char *val; - pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle; - - retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n"); - retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n"); - - if (info->pkg_info == NULL || info->pkg_info->installlocation == NULL) + if (info->pkg_info == NULL) return PMINFO_R_ERROR; + if (info->pkg_info->api_version == NULL) + info->pkg_info->api_version = strdup(""); - val = (char *)info->pkg_info->installlocation; - if (strcmp(val, "internal-only") == 0) - *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY; - else if (strcmp(val, "prefer-external") == 0) - *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL; - else - *location = PMINFO_INSTALL_LOCATION_AUTO; + *api_version = (char *)info->pkg_info->api_version; return PMINFO_R_OK; } -API int pkgmgrinfo_pkginfo_get_package_size(pkgmgrinfo_pkginfo_h handle, int *size) +API int pkgmgrinfo_pkginfo_get_tep_name(pkgmgrinfo_pkginfo_h handle, char **tep_name) { pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle; retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n"); - retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n"); + retvm_if(tep_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n"); - if (info->pkg_info == NULL || info->pkg_info->package_size == NULL) + if (info->pkg_info == NULL || info->pkg_info->tep_name == NULL) return PMINFO_R_ERROR; - *size = atoi((char *)info->pkg_info->package_size); + *tep_name = (char *)info->pkg_info->tep_name; return PMINFO_R_OK; } -API int pkgmgrinfo_pkginfo_get_total_size(pkgmgrinfo_pkginfo_h handle, int *size) -{ - char *pkgid; - char device_path[PKG_STRING_LEN_MAX] = { '\0', }; - long long rw_size = 0; - long long ro_size = 0; - long long tmp_size = 0; - long long total_size = 0; - struct stat fileinfo; - int ret; - - retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n"); - retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n"); - - ret = pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid); - if (ret < 0) - return PMINFO_R_ERROR; - - /* RW area */ - snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/bin", PKG_RW_PATH, pkgid); - if (lstat(device_path, &fileinfo) == 0) { - if (!S_ISLNK(fileinfo.st_mode)) { - tmp_size = _pkgmgr_calculate_dir_size(device_path); - if (tmp_size > 0) - rw_size += tmp_size; - } - } - - snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/info", PKG_RW_PATH, pkgid); - if (lstat(device_path, &fileinfo) == 0) { - if (!S_ISLNK(fileinfo.st_mode)) { - tmp_size = _pkgmgr_calculate_dir_size(device_path); - if (tmp_size > 0) - rw_size += tmp_size; - } - } - - snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/res", PKG_RW_PATH, pkgid); - if (lstat(device_path, &fileinfo) == 0) { - if (!S_ISLNK(fileinfo.st_mode)) { - tmp_size = _pkgmgr_calculate_dir_size(device_path); - if (tmp_size > 0) - rw_size += tmp_size; - } - } - - snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RW_PATH, pkgid); - if (lstat(device_path, &fileinfo) == 0) { - if (!S_ISLNK(fileinfo.st_mode)) { - tmp_size = _pkgmgr_calculate_dir_size(device_path); - if (tmp_size > 0) - rw_size += tmp_size; - } - } - - snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/shared", PKG_RW_PATH, pkgid); - if (lstat(device_path, &fileinfo) == 0) { - if (!S_ISLNK(fileinfo.st_mode)) { - tmp_size = _pkgmgr_calculate_dir_size(device_path); - if (tmp_size > 0) - rw_size += tmp_size; - } - } - - snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/setting", PKG_RW_PATH, pkgid); - if (lstat(device_path, &fileinfo) == 0) { - if (!S_ISLNK(fileinfo.st_mode)) { - tmp_size = _pkgmgr_calculate_dir_size(device_path); - if (tmp_size > 0) - rw_size += tmp_size; - } - } +API int pkgmgrinfo_pkginfo_get_zip_mount_file(pkgmgrinfo_pkginfo_h handle, char **zip_mount_file) +{ + pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle; - /* RO area */ - snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/bin", PKG_RO_PATH, pkgid); - if (lstat(device_path, &fileinfo) == 0) { - if (!S_ISLNK(fileinfo.st_mode)) { - tmp_size = _pkgmgr_calculate_dir_size(device_path); - if (tmp_size > 0) - ro_size += tmp_size; - } - } + retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n"); + retvm_if(zip_mount_file == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n"); - snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/info", PKG_RO_PATH, pkgid); - if (lstat(device_path, &fileinfo) == 0) { - if (!S_ISLNK(fileinfo.st_mode)) { - tmp_size = _pkgmgr_calculate_dir_size(device_path); - if (tmp_size > 0) - ro_size += tmp_size; - } - } + if (info->pkg_info == NULL) + return PMINFO_R_ERROR; + if (info->pkg_info->zip_mount_file == NULL) + info->pkg_info->zip_mount_file = strdup(""); - snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/res", PKG_RO_PATH, pkgid); - if (lstat(device_path, &fileinfo) == 0) { - if (!S_ISLNK(fileinfo.st_mode)) { - tmp_size = _pkgmgr_calculate_dir_size(device_path); - if (tmp_size > 0) - ro_size += tmp_size; - } - } + *zip_mount_file = (char *)info->pkg_info->zip_mount_file; - snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RO_PATH, pkgid); - if (lstat(device_path, &fileinfo) == 0) { - if (!S_ISLNK(fileinfo.st_mode)) { - tmp_size = _pkgmgr_calculate_dir_size(device_path); - if (tmp_size > 0) - ro_size += tmp_size; - } - } + return PMINFO_R_OK; +} - snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/shared", PKG_RO_PATH, pkgid); - if (lstat(device_path, &fileinfo) == 0) { - if (!S_ISLNK(fileinfo.st_mode)) { - tmp_size = _pkgmgr_calculate_dir_size(device_path); - if (tmp_size > 0) - ro_size += tmp_size; - } - } +API int pkgmgrinfo_pkginfo_get_install_location(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_install_location *location) +{ + char *val; + pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle; - snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/setting", PKG_RO_PATH, pkgid); - if (lstat(device_path, &fileinfo) == 0) { - if (!S_ISLNK(fileinfo.st_mode)) { - tmp_size = _pkgmgr_calculate_dir_size(device_path); - if (tmp_size > 0) - ro_size += tmp_size; - } - } + retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n"); + retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n"); + + if (info->pkg_info == NULL || info->pkg_info->installlocation == NULL) + return PMINFO_R_ERROR; - /* Total size */ - total_size = rw_size + ro_size; - *size = (int)total_size; + val = (char *)info->pkg_info->installlocation; + if (strcmp(val, "internal-only") == 0) + *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY; + else if (strcmp(val, "prefer-external") == 0) + *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL; + else + *location = PMINFO_INSTALL_LOCATION_AUTO; return PMINFO_R_OK; } -API int pkgmgrinfo_pkginfo_get_data_size(pkgmgrinfo_pkginfo_h handle, int *size) +API int pkgmgrinfo_pkginfo_get_package_size(pkgmgrinfo_pkginfo_h handle, int *size) { - char *pkgid; - char device_path[PKG_STRING_LEN_MAX] = { '\0', }; - long long total_size = 0; + pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle; + char *temp = NULL; retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n"); retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n"); - if (pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid) < 0) + if (info->pkg_info == NULL) return PMINFO_R_ERROR; - snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RW_PATH, pkgid); - if (access(device_path, R_OK) == 0) - total_size = _pkgmgr_calculate_dir_size(device_path); - if (total_size < 0) - return PMINFO_R_ERROR; + if (info->pkg_info->package_size == NULL) { + temp = strdup(""); + if (temp == NULL) { + _LOGE("out of memory"); + return PMINFO_R_ERROR; + } else { + info->pkg_info->package_size = temp; + } + } - *size = (int)total_size; + *size = atoi((char *)info->pkg_info->package_size); return PMINFO_R_OK; } @@ -1099,7 +989,7 @@ API int pkgmgrinfo_pkginfo_get_icon(pkgmgrinfo_pkginfo_h handle, char **icon) locale = info->locale; retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL"); - if (info->pkg_info == NULL) + if (info->pkg_info == NULL || info->pkg_info->icon == NULL) return PMINFO_R_ERROR; for (tmp = info->pkg_info->icon; tmp; tmp = tmp->next) { @@ -1121,7 +1011,9 @@ API int pkgmgrinfo_pkginfo_get_icon(pkgmgrinfo_pkginfo_h handle, char **icon) return PMINFO_R_OK; } - return PMINFO_R_ERROR; + *icon = ""; + + return PMINFO_R_OK; } API int pkgmgrinfo_pkginfo_get_label(pkgmgrinfo_pkginfo_h handle, char **label) @@ -1137,6 +1029,9 @@ API int pkgmgrinfo_pkginfo_get_label(pkgmgrinfo_pkginfo_h handle, char **label) locale = info->locale; retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL"); + if (info->pkg_info == NULL || info->pkg_info->label == NULL) + return PMINFO_R_ERROR; + for (tmp = info->pkg_info->label; tmp != NULL; tmp = tmp->next) { ptr = (label_x *)tmp->data; if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL || @@ -1156,7 +1051,9 @@ API int pkgmgrinfo_pkginfo_get_label(pkgmgrinfo_pkginfo_h handle, char **label) return PMINFO_R_OK; } - return PMINFO_R_ERROR; + *label = ""; + + return PMINFO_R_OK; } API int pkgmgrinfo_pkginfo_get_description(pkgmgrinfo_pkginfo_h handle, char **description) @@ -1172,6 +1069,9 @@ API int pkgmgrinfo_pkginfo_get_description(pkgmgrinfo_pkginfo_h handle, char **d locale = info->locale; retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL"); + if (info->pkg_info == NULL || info->pkg_info->description == NULL) + return PMINFO_R_ERROR; + for (tmp = info->pkg_info->description; tmp; tmp = tmp->next) { ptr = (description_x *)tmp->data; if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL || @@ -1191,7 +1091,9 @@ API int pkgmgrinfo_pkginfo_get_description(pkgmgrinfo_pkginfo_h handle, char **d return PMINFO_R_OK; } - return PMINFO_R_ERROR; + *description = ""; + + return PMINFO_R_OK; } API int pkgmgrinfo_pkginfo_get_author_name(pkgmgrinfo_pkginfo_h handle, char **author_name) @@ -1206,8 +1108,10 @@ API int pkgmgrinfo_pkginfo_get_author_name(pkgmgrinfo_pkginfo_h handle, char **a return PMINFO_R_ERROR; author = (author_x *)info->pkg_info->author->data; - if (author == NULL || author->text == NULL) + if (author == NULL) return PMINFO_R_ERROR; + if (author->text == NULL) + author->text = strdup(""); *author_name = (char *)author->text; @@ -1226,8 +1130,10 @@ API int pkgmgrinfo_pkginfo_get_author_email(pkgmgrinfo_pkginfo_h handle, char ** return PMINFO_R_ERROR; author = (author_x *)info->pkg_info->author->data; - if (author == NULL || author->email == NULL) + if (author == NULL) return PMINFO_R_ERROR; + if (author->email == NULL) + author->email = strdup(""); *author_email = (char *)author->email; @@ -1246,8 +1152,10 @@ API int pkgmgrinfo_pkginfo_get_author_href(pkgmgrinfo_pkginfo_h handle, char **a return PMINFO_R_ERROR; author = (author_x *)info->pkg_info->author->data; - if (author == NULL || author->href == NULL) + if (author == NULL) return PMINFO_R_ERROR; + if (author->href == NULL) + author->href = strdup(""); *author_href = (char *)author->href; @@ -1296,8 +1204,10 @@ API int pkgmgrinfo_pkginfo_get_storeclientid(pkgmgrinfo_pkginfo_h handle, char * retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n"); retvm_if(storeclientid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n"); - if (info->pkg_info == NULL || info->pkg_info->storeclient_id == NULL) + if (info->pkg_info == NULL) return PMINFO_R_ERROR; + if (info->pkg_info->storeclient_id == NULL) + info->pkg_info->storeclient_id = strdup(""); *storeclientid = (char *)info->pkg_info->storeclient_id; @@ -1326,120 +1236,16 @@ API int pkgmgrinfo_pkginfo_get_url(pkgmgrinfo_pkginfo_h handle, char **url) retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n"); retvm_if(url == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n"); - if (info->pkg_info == NULL || info->pkg_info->package_url == NULL) + if (info->pkg_info == NULL) return PMINFO_R_ERROR; + if (info->pkg_info->package_url == NULL) + info->pkg_info->package_url = strdup(""); *url = (char *)info->pkg_info->package_url; return PMINFO_R_OK; } -API int pkgmgrinfo_pkginfo_get_size_from_xml(const char *manifest, int *size) -{ - const char *val = NULL; - const xmlChar *node; - xmlTextReaderPtr reader; - retvm_if(manifest == NULL, PMINFO_R_EINVAL, "Input argument is NULL\n"); - retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n"); - - xmlInitParser(); - reader = xmlReaderForFile(manifest, NULL, 0); - - if (reader){ - if (__child_element(reader, -1)) { - node = xmlTextReaderConstName(reader); - if (!node) { - _LOGE("xmlTextReaderConstName value is NULL\n"); - xmlFreeTextReader(reader); - xmlCleanupParser(); - return PMINFO_R_ERROR; - } - - if (!strcmp(ASC_CHAR(node), "manifest")) { - if (xmlTextReaderGetAttribute(reader, XML_CHAR("size"))) - val = ASC_CHAR(xmlTextReaderGetAttribute(reader, XML_CHAR("size"))); - - if (val) { - *size = atoi(val); - } else { - *size = 0; - _LOGE("package size is not specified\n"); - xmlFreeTextReader(reader); - xmlCleanupParser(); - return PMINFO_R_ERROR; - } - } else { - _LOGE("Unable to create xml reader\n"); - xmlFreeTextReader(reader); - xmlCleanupParser(); - return PMINFO_R_ERROR; - } - } - } else { - _LOGE("xmlReaderForFile value is NULL\n"); - xmlCleanupParser(); - return PMINFO_R_ERROR; - } - - xmlFreeTextReader(reader); - xmlCleanupParser(); - - return PMINFO_R_OK; -} - -API int pkgmgrinfo_pkginfo_get_location_from_xml(const char *manifest, pkgmgrinfo_install_location *location) -{ - const char *val = NULL; - const xmlChar *node; - xmlTextReaderPtr reader; - retvm_if(manifest == NULL, PMINFO_R_EINVAL, "Input argument is NULL\n"); - retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n"); - - xmlInitParser(); - reader = xmlReaderForFile(manifest, NULL, 0); - - if (reader) { - if ( __child_element(reader, -1)) { - node = xmlTextReaderConstName(reader); - if (!node) { - _LOGE("xmlTextReaderConstName value is NULL\n"); - xmlFreeTextReader(reader); - xmlCleanupParser(); - return PMINFO_R_ERROR; - } - - if (!strcmp(ASC_CHAR(node), "manifest")) { - if (xmlTextReaderGetAttribute(reader, XML_CHAR("install-location"))) - val = ASC_CHAR(xmlTextReaderGetAttribute(reader, XML_CHAR("install-location"))); - - if (val) { - if (strcmp(val, "internal-only") == 0) - *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY; - else if (strcmp(val, "prefer-external") == 0) - *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL; - else - *location = PMINFO_INSTALL_LOCATION_AUTO; - } - } else { - _LOGE("Unable to create xml reader\n"); - xmlFreeTextReader(reader); - xmlCleanupParser(); - return PMINFO_R_ERROR; - } - } - } else { - _LOGE("xmlReaderForFile value is NULL\n"); - xmlCleanupParser(); - return PMINFO_R_ERROR; - } - - xmlFreeTextReader(reader); - xmlCleanupParser(); - - return PMINFO_R_OK; -} - - API int pkgmgrinfo_pkginfo_get_root_path(pkgmgrinfo_pkginfo_h handle, char **path) { pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle; @@ -1462,8 +1268,10 @@ API int pkgmgrinfo_pkginfo_get_csc_path(pkgmgrinfo_pkginfo_h handle, char **path retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n"); retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n"); - if (info->pkg_info == NULL || info->pkg_info->csc_path == NULL) + if (info->pkg_info == NULL) return PMINFO_R_ERROR; + if (info->pkg_info->csc_path == NULL) + info->pkg_info->csc_path = strdup(""); *path = (char *)info->pkg_info->csc_path; @@ -1506,7 +1314,6 @@ API int pkgmgrinfo_pkginfo_is_accessible(pkgmgrinfo_pkginfo_h handle, bool *acce } /*check whether application is in internal or not */ - fp = fopen(app_dir_path, "r"); if (fp == NULL) { _LOGD(" app path in internal memory not accesible\n"); *accessible = 0; @@ -1778,9 +1585,9 @@ API int pkgmgrinfo_pkginfo_filter_add_bool(pkgmgrinfo_pkginfo_filter_h handle, return PMINFO_R_ERROR; } if (value) - val = strndup("('true','True')", 15); + val = strndup("true", 4); else - val = strndup("('false','False')", 17); + val = strndup("false", 5); if (val == NULL) { _LOGE("Out of Memory\n"); free(node); @@ -1854,27 +1661,48 @@ API int pkgmgrinfo_pkginfo_filter_add_string(pkgmgrinfo_pkginfo_filter_h handle, API int pkgmgrinfo_pkginfo_usr_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count, uid_t uid) { int ret; - GList *list = NULL; + char *locale; + GHashTable *list = NULL; if (handle == NULL || count == NULL) { _LOGE("invalid parameter"); return PMINFO_R_EINVAL; } - ret = _pkginfo_get_filtered_list((pkgmgrinfo_filter_x *)handle, uid, &list); - if (ret != PMINFO_R_OK) + locale = _get_system_locale(); + if (locale == NULL) + return PMINFO_R_ERROR; + + list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, + __free_packages); + if (list == NULL) { + free(locale); + return PMINFO_R_ERROR; + } + + ret = _pkginfo_get_packages(uid, locale, + (pkgmgrinfo_filter_x *)handle, 0, list); + if (ret == PMINFO_R_OK && uid != GLOBAL_USER) + ret = _pkginfo_get_packages(GLOBAL_USER, locale, handle, 0, + list); + + if (ret != PMINFO_R_OK) { + g_hash_table_destroy(list); + free(locale); return PMINFO_R_ERROR; + } - *count = g_list_length(list); + *count = g_hash_table_size(list); - g_list_free_full(list, free); + g_hash_table_destroy(list); + free(locale); return PMINFO_R_OK; } API int pkgmgrinfo_pkginfo_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count) { - return pkgmgrinfo_pkginfo_usr_filter_count(handle, count, GLOBAL_USER); + return pkgmgrinfo_pkginfo_usr_filter_count(handle, count, _getuid()); } API int pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo( @@ -1886,14 +1714,14 @@ API int pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo( return PMINFO_R_EINVAL; } - return _pkginfo_get_filtered_foreach_pkginfo(handle, pkg_cb, user_data, - uid); + return _pkginfo_get_filtered_foreach_pkginfo(uid, handle, + PMINFO_PKGINFO_GET_ALL, pkg_cb, user_data); } API int pkgmgrinfo_pkginfo_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h handle, pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data) { - return pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(handle, pkg_cb, user_data, GLOBAL_USER); + return pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(handle, pkg_cb, user_data, _getuid()); } API int pkgmgrinfo_pkginfo_foreach_privilege(pkgmgrinfo_pkginfo_h handle, @@ -1919,319 +1747,3 @@ API int pkgmgrinfo_pkginfo_foreach_privilege(pkgmgrinfo_pkginfo_h handle, } return PMINFO_R_OK; } - -API int pkgmgrinfo_create_pkgusrdbinfo(const char *pkgid, uid_t uid, pkgmgrinfo_pkgdbinfo_h *handle) -{ - retvm_if(!pkgid, PMINFO_R_EINVAL, "pkgid is NULL"); - retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL"); - - char *manifest = NULL; - manifest_x *mfx = NULL; - *handle = NULL; - manifest = pkgmgr_parser_get_usr_manifest_file(pkgid, uid); - retvm_if(manifest == NULL, PMINFO_R_EINVAL, "pkg[%s] dont have manifest file", pkgid); - - mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid); - if (manifest) { - free(manifest); - manifest = NULL; - } - retvm_if(mfx == NULL, PMINFO_R_EINVAL, "pkg[%s] parsing fail", pkgid); - - *handle = (void *)mfx; - - return PMINFO_R_OK; -} - -API int pkgmgrinfo_create_pkgdbinfo(const char *pkgid, pkgmgrinfo_pkgdbinfo_h *handle) -{ - retvm_if(!pkgid, PMINFO_R_EINVAL, "pkgid is NULL"); - retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL"); - - char *manifest = NULL; - manifest_x *mfx = NULL; - *handle = NULL; - manifest = pkgmgr_parser_get_manifest_file(pkgid); - retvm_if(manifest == NULL, PMINFO_R_EINVAL, "pkg[%s] dont have manifest file", pkgid); - - mfx = pkgmgr_parser_process_manifest_xml(manifest); - if (manifest) { - free(manifest); - manifest = NULL; - } - retvm_if(mfx == NULL, PMINFO_R_EINVAL, "pkg[%s] parsing fail", pkgid); - - *handle = (void *)mfx; - - return PMINFO_R_OK; -} - -API int pkgmgrinfo_set_type_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *type) -{ - int len; - manifest_x *mfx = (manifest_x *)handle; - - retvm_if(!type, PMINFO_R_EINVAL, "Argument supplied is NULL"); - retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL"); - - len = strlen(type); - retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit"); - - if (mfx->type) - free((void *)mfx->type); - - mfx->type = strndup(type, PKG_TYPE_STRING_LEN_MAX); - - return PMINFO_R_OK; -} - -API int pkgmgrinfo_set_version_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *version) -{ - int len; - manifest_x *mfx = (manifest_x *)handle; - - retvm_if(!version, PMINFO_R_EINVAL, "Argument supplied is NULL"); - retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL"); - - len = strlen(version); - retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit"); - - if (mfx->version) - free((void *)mfx->version); - - mfx->version = strndup(version, PKG_VERSION_STRING_LEN_MAX); - return PMINFO_R_OK; -} - -API int pkgmgrinfo_set_install_location_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, INSTALL_LOCATION location) -{ - manifest_x *mfx = (manifest_x *)handle; - - retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL"); - retvm_if((location < 0) || (location > 1), PMINFO_R_EINVAL, "Argument supplied is NULL"); - - if (mfx->installlocation) - free((void *)mfx->installlocation); - - if (location == INSTALL_INTERNAL) - mfx->installlocation = strdup("internal-only"); - else if (location == INSTALL_EXTERNAL) - mfx->installlocation = strdup("prefer-external"); - - return PMINFO_R_OK; -} - -API int pkgmgrinfo_set_size_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *size) -{ - manifest_x *mfx = (manifest_x *)handle; - - retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL"); - retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL"); - - if (mfx->package_size) - free((void *)mfx->package_size); - - mfx->package_size = strdup(size); - - return PMINFO_R_OK; -} - -API int pkgmgrinfo_set_label_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *label_txt, const char *locale) -{ - int len; - manifest_x *mfx = (manifest_x *)handle; - label_x *label; - - retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL"); - retvm_if(!label_txt, PMINFO_R_EINVAL, "Argument supplied is NULL"); - - len = strlen(label_txt); - retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit"); - - label = calloc(1, sizeof(label_x)); - retvm_if(label == NULL, PMINFO_R_EINVAL, "Malloc Failed"); - - if (locale) - label->lang = strdup(locale); - else - label->lang = strdup(DEFAULT_LOCALE); - label->text = strdup(label_txt); - mfx->label = g_list_append(mfx->label, label); - - return PMINFO_R_OK; -} - -API int pkgmgrinfo_set_icon_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *icon_txt, const char *locale) -{ - int len; - manifest_x *mfx = (manifest_x *)handle; - icon_x *icon; - - retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL"); - retvm_if(!icon_txt, PMINFO_R_EINVAL, "Argument supplied is NULL"); - - len = strlen(icon_txt); - retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit"); - - icon = calloc(1, sizeof(icon_x)); - retvm_if(icon == NULL, PMINFO_R_EINVAL, "Malloc Failed"); - - if (locale) - icon->lang = strdup(locale); - else - icon->lang = strdup(DEFAULT_LOCALE); - icon->text = strdup(icon_txt); - mfx->icon = g_list_append(mfx->icon, icon); - - return PMINFO_R_OK; -} - -API int pkgmgrinfo_set_description_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *desc_txt, const char *locale) -{ - int len = strlen(desc_txt); - manifest_x *mfx = (manifest_x *)handle; - description_x *description; - - retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL"); - retvm_if(!desc_txt, PMINFO_R_EINVAL, "Argument supplied is NULL"); - - len = strlen(desc_txt); - retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit"); - - description = calloc(1, sizeof(description_x)); - retvm_if(description == NULL, PMINFO_R_EINVAL, "Malloc Failed"); - - if (locale) - description->lang = strdup(locale); - else - description->lang = strdup(DEFAULT_LOCALE); - description->text = strdup(desc_txt); - mfx->description = g_list_append(mfx->description, description); - - return PMINFO_R_OK; -} - -API int pkgmgrinfo_set_author_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *author_name, - const char *author_email, const char *author_href, const char *locale) -{ - manifest_x *mfx = (manifest_x *)handle; - author_x *author; - - retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL"); - - author = calloc(1, sizeof(author_x)); - retvm_if(author == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL"); - - if (author_name) - author->text = strdup(author_name); - if (author_email) - author->email = strdup(author_email); - if (author_href) - author->href = strdup(author_href); - if (locale) - author->lang = strdup(locale); - else - author->lang = strdup(DEFAULT_LOCALE); - mfx->author = g_list_append(mfx->author, author); - return PMINFO_R_OK; -} - -API int pkgmgrinfo_set_removable_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, int removable) -{ - manifest_x *mfx = (manifest_x *)handle; - - retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL"); - retvm_if((removable < 0) || (removable > 1), PMINFO_R_EINVAL, "Argument supplied is NULL"); - - if (mfx->removable) - free((void *)mfx->removable); - - if (removable == 0) - mfx->removable = strdup("false"); - else if (removable == 1) - mfx->removable = strdup("true"); - - return PMINFO_R_OK; -} - -API int pkgmgrinfo_set_preload_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, int preload) -{ - manifest_x *mfx = (manifest_x *)handle; - - retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL"); - retvm_if((preload < 0) || (preload > 1), PMINFO_R_EINVAL, "Argument supplied is NULL"); - - if (mfx->preload) - free((void *)mfx->preload); - - if (preload == 0) - mfx->preload = strdup("false"); - else if (preload == 1) - mfx->preload = strdup("true"); - - return PMINFO_R_OK; -} - -API int pkgmgrinfo_set_installed_storage_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, INSTALL_LOCATION location) -{ - manifest_x *mfx = (manifest_x *)handle; - - retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL"); - retvm_if((location < 0) || (location > 1), PMINFO_R_EINVAL, "Argument supplied is NULL"); - - if (mfx->installed_storage) - free((void *)mfx->installed_storage); - - if (location == INSTALL_INTERNAL) - mfx->installed_storage = strdup("installed_internal"); - else if (location == INSTALL_EXTERNAL) - mfx->installed_storage = strdup("installed_external"); - - return PMINFO_R_OK; -} - -API int pkgmgrinfo_save_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle) -{ - int ret; - manifest_x *mfx = (manifest_x *)handle; - mfx = (manifest_x *)handle; - - retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL"); - - ret = pkgmgr_parser_update_manifest_info_in_db(mfx); - if (ret == 0) { - _LOGE("Successfully stored info in DB\n"); - return PMINFO_R_OK; - } else { - _LOGE("Failed to store info in DB\n"); - return PMINFO_R_ERROR; - } -} - -API int pkgmgrinfo_save_pkgusrdbinfo(pkgmgrinfo_pkgdbinfo_h handle, uid_t uid) -{ - int ret; - manifest_x *mfx = (manifest_x *)handle; - - retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL"); - - ret = pkgmgr_parser_update_manifest_info_in_usr_db(mfx, uid); - if (ret == 0) { - _LOGE("Successfully stored info in DB\n"); - return PMINFO_R_OK; - } else { - _LOGE("Failed to store info in DB\n"); - return PMINFO_R_ERROR; - } -} - -API int pkgmgrinfo_destroy_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle) -{ - manifest_x *mfx = (manifest_x *)handle; - - retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL"); - - pkgmgrinfo_basic_free_package(mfx); - - return PMINFO_R_OK; -}