#include <ctype.h>
#include <sys/smack.h>
#include <linux/limits.h>
-#include <libgen.h>
#include <sys/stat.h>
-#include <libxml/parser.h>
-#include <libxml/xmlreader.h>
-#include <libxml/xmlschemas.h>
-#include <sqlite3.h>
#include <glib.h>
-#include "pkgmgr_parser.h"
#include "pkgmgrinfo_basic.h"
#include "pkgmgrinfo_private.h"
#include "pkgmgrinfo_debug.h"
#include "pkgmgr-info.h"
-#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);
+#include "manager/pkginfo_manager.h"
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;
static gint __compare_func(gconstpointer data1, gconstpointer data2)
{
- pkgmgrinfo_node_x *node1 = (pkgmgrinfo_node_x*)data1;
- pkgmgrinfo_node_x *node2 = (pkgmgrinfo_node_x*)data2;
+ pkgmgrinfo_node_x *node1 = (pkgmgrinfo_node_x *)data1;
+ pkgmgrinfo_node_x *node2 = (pkgmgrinfo_node_x *)data2;
if (node1->prop == node2->prop)
return 0;
else if (node1->prop > node2->prop)
return -1;
}
-static void __destroy_each_node(gpointer data, gpointer user_data)
+static gint __pkg_disable_chk_func(gconstpointer data1, gconstpointer data2)
{
- ret_if(data == NULL);
- pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)data;
- if (node->value) {
- free(node->value);
- node->value = NULL;
- }
- if (node->key) {
+ pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)data1;
+
+ if (node->prop == E_PMINFO_PKGINFO_PROP_PACKAGE_DISABLE)
+ return 0;
+ else
+ return 1;
+}
+
+static void __destroy_metadata_node(gpointer data)
+{
+ pkgmgrinfo_metadata_node_x *node = (pkgmgrinfo_metadata_node_x *)data;
+ if (node->key)
free(node->key);
- node->key = NULL;
- }
+ if (node->value)
+ free(node->value);
free(node);
- node = NULL;
}
static void __cleanup_pkginfo(pkgmgr_pkginfo_x *data)
{
ret_if(data == NULL);
- if (data->locale){
+ if (data->locale) {
free((void *)data->locale);
data->locale = NULL;
}
return;
}
-static int __child_element(xmlTextReaderPtr reader, int depth)
+static void __free_packages(gpointer data)
{
- 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;
+ pkgmgrinfo_basic_free_package((package_x *)data);
}
-long long _pkgmgr_calculate_dir_size(char *dirname)
+static bool __check_disable_filter_exist(pkgmgrinfo_filter_x *filter)
{
- long long total = 0;
- long long ret = 0;
- int q = 0; /*quotient*/
- int r = 0; /*remainder*/
- DIR *dp = 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) {
- _LOGE("Couldn't open the directory\n");
- return -1;
- }
+ GSList *link;
- 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;
- }
- 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);
- return total;
+ if (filter == NULL)
+ return false;
-}
+ link = g_slist_find_custom(filter->list, NULL, __pkg_disable_chk_func);
+ if (link)
+ return true;
-static gint __list_strcmp(gconstpointer a, gconstpointer b)
-{
- return strcmp((char *)a, (char *)b);
+ return false;
}
-static int _pkginfo_get_list(sqlite3 *db, const char *locale,
- pkgmgrinfo_filter_x *filter, GList **list)
+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)
{
- 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;
+ package_x *pkg;
+ pkgmgr_pkginfo_x info;
+ GHashTable *list;
+ GHashTableIter iter;
+ gpointer value;
+
+ list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
+ __free_packages);
+ if (list == NULL)
+ return PMINFO_R_ERROR;
+
+ if (__check_disable_filter_exist(filter) == false) {
+ ret = pkgmgrinfo_pkginfo_filter_add_bool(filter,
+ PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, false);
+ if (ret != PMINFO_R_OK) {
+ _LOGE("Failed to add filter");
+ g_hash_table_destroy(list);
+ return PMINFO_R_ERROR;
+ }
+ }
- 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;
+ ret = _pkginfo_get_packages(uid, filter, flag, list);
+ if (ret == PMINFO_R_ERROR) {
+ g_hash_table_destroy(list);
+ return ret;
}
- while (sqlite3_step(stmt) == SQLITE_ROW) {
- _save_column_str(stmt, 0, &pkgid);
- if (pkgid != NULL)
- *list = g_list_insert_sorted(*list, pkgid,
- __list_strcmp);
+ 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 = pkg->locale;
+ if (pkg_list_cb(&info, user_data) < 0)
+ break;
}
- sqlite3_finalize(stmt);
+ g_hash_table_destroy(list);
- return 0;
+ return PMINFO_R_OK;
}
-static int _pkginfo_get_filtered_list(pkgmgrinfo_filter_x *filter, uid_t uid,
- GList **list)
+static int _pkgmgrinfo_get_pkginfo(const char *pkgid, uid_t uid,
+ pkgmgrinfo_pkginfo_filter_h filter, pkgmgrinfo_pkginfo_h *handle)
{
int ret;
- sqlite3 *db;
- const char *dbpath;
- char *locale;
- GList *tmp;
- GList *tmp2;
-
- locale = _get_system_locale();
- if (locale == NULL)
- return PMINFO_R_ERROR;
+ GHashTable *list;
+ pkgmgr_pkginfo_x *info;
- dbpath = getUserPkgParserDBPathUID(uid);
- if (dbpath == NULL) {
- free(locale);
- return PMINFO_R_ERROR;
+ if (pkgid == NULL || filter == NULL || handle == NULL) {
+ LOGE("invalid parameter");
+ return PMINFO_R_EINVAL;
}
- ret = sqlite3_open_v2(dbpath, &db, SQLITE_OPEN_READONLY, NULL);
- if (ret != SQLITE_OK) {
- _LOGE("failed to open db: %d", ret);
- free(locale);
+ list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
+ __free_packages);
+ if (list == NULL)
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;
+ ret = _pkginfo_get_packages(uid, filter, PMINFO_PKGINFO_GET_ALL, list);
+ if (ret != PMINFO_R_OK) {
+ g_hash_table_destroy(list);
+ return ret;
}
- /* search again from global */
- dbpath = getUserPkgParserDBPathUID(GLOBAL_USER);
- if (dbpath == NULL) {
- free(locale);
- return PMINFO_R_ERROR;
+ if (!g_hash_table_size(list) || !g_hash_table_lookup(list, pkgid)) {
+ _LOGD("pkginfo for [%s] is not existed for user [%d]",
+ pkgid, uid);
+ g_hash_table_destroy(list);
+ return PMINFO_R_ENOENT;
}
- ret = sqlite3_open_v2(dbpath, &db, SQLITE_OPEN_READONLY, NULL);
- if (ret != SQLITE_OK) {
- _LOGE("failed to open db: %d", ret);
- free(locale);
+ info = calloc(1, sizeof(pkgmgr_pkginfo_x));
+ if (info == NULL) {
+ _LOGE("out of memory");
+ g_hash_table_destroy(list);
return PMINFO_R_ERROR;
}
- if (_pkginfo_get_list(db, locale, filter, list)) {
- free(locale);
- sqlite3_close_v2(db);
+ info->uid = uid;
+ info->pkg_info = (package_x *)g_hash_table_lookup(list, pkgid);
+ info->locale = strdup(info->pkg_info->locale);
+ if (info->locale == NULL) {
+ _LOGE("Out of memory");
+ g_hash_table_destroy(list);
+ free(info);
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)
- continue;
- if (strcmp((const char *)tmp->prev->data,
- (const char *)tmp->data) == 0)
- *list = g_list_delete_link(*list, tmp);
- }
+ /* just free list only */
+ g_hash_table_steal(list, (gconstpointer)pkgid);
+ g_hash_table_destroy(list);
- free(locale);
+ *handle = info;
- return PMINFO_R_OK;
+ return ret;
}
-
-static int _pkginfo_get_filtered_foreach_pkginfo(pkgmgrinfo_filter_x *filter,
- pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data, uid_t uid)
+API int pkgmgrinfo_pkginfo_get_usr_pkginfo(const char *pkgid, uid_t uid,
+ pkgmgrinfo_pkginfo_h *handle)
{
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;
+ pkgmgrinfo_pkginfo_filter_h filter;
- 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);
- continue;
- }
- if (pkg_list_cb(info, user_data) < 0)
- stop = 1;
- pkgmgrinfo_pkginfo_destroy_pkginfo(info);
- }
- free(pkgid);
- }
-
- 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) {
+ if (pkgid == NULL || handle == 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,
- GList **author)
-{
- static const char query_raw[] =
- "SELECT author_name, author_email, author_href "
- "FROM package_info WHERE package=%Q";
- int ret;
- char *query;
- sqlite3_stmt *stmt;
- int idx = 0;
- author_x *info;
-
- 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;
- }
+ ret = pkgmgrinfo_pkginfo_filter_create(&filter);
+ if (ret != PMINFO_R_OK)
+ return ret;
- if (sqlite3_step(stmt) == SQLITE_ERROR) {
- LOGE("step error: %s", sqlite3_errmsg(db));
- sqlite3_finalize(stmt);
+ ret = pkgmgrinfo_pkginfo_filter_add_string(filter,
+ PMINFO_PKGINFO_PROP_PACKAGE_ID, pkgid);
+ if (ret != PMINFO_R_OK) {
+ pkgmgrinfo_pkginfo_filter_destroy(filter);
return PMINFO_R_ERROR;
}
- /* one author per one package */
- info = calloc(1, sizeof(author_x));
- if (info == NULL) {
- LOGE("out of memory");
- sqlite3_finalize(stmt);
+ ret = pkgmgrinfo_pkginfo_filter_add_bool(filter,
+ PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, false);
+ if (ret != PMINFO_R_OK) {
+ pkgmgrinfo_pkginfo_filter_destroy(filter);
return PMINFO_R_ERROR;
}
+ ret = _pkgmgrinfo_get_pkginfo(pkgid, uid, filter, handle);
+ pkgmgrinfo_pkginfo_filter_destroy(filter);
- _save_column_str(stmt, idx++, &info->text);
- _save_column_str(stmt, idx++, &info->email);
- _save_column_str(stmt, idx++, &info->href);
-
- /* TODO: revised */
- *author = g_list_append(*author, info);
-
- sqlite3_finalize(stmt);
-
- return PMINFO_R_OK;
+ return ret;
}
-static int _pkginfo_get_label(sqlite3 *db, const char *pkgid,
- const char *locale, GList **label)
+API int pkgmgrinfo_pkginfo_get_pkginfo(const char *pkgid,
+ pkgmgrinfo_pkginfo_h *handle)
{
- static const char query_raw[] =
- "SELECT package_label, package_locale "
- "FROM package_localized_info "
- "WHERE package=%Q AND package_locale IN (%Q, %Q)";
- int ret;
- char *query;
- sqlite3_stmt *stmt;
- int idx;
- label_x *info;
-
- query = sqlite3_mprintf(query_raw, pkgid, locale, DEFAULT_LOCALE);
- 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) {
- info = calloc(1, sizeof(label_x));
- if (info == NULL) {
- LOGE("out of memory");
- sqlite3_finalize(stmt);
- return PMINFO_R_ERROR;
- }
- idx = 0;
- _save_column_str(stmt, idx++, &info->text);
- _save_column_str(stmt, idx++, &info->lang);
- *label = g_list_append(*label, info);
- }
-
- sqlite3_finalize(stmt);
-
- return PMINFO_R_OK;
+ return pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, _getuid(), handle);
}
-static int _pkginfo_get_icon(sqlite3 *db, const char *pkgid, const char *locale,
- GList **icon)
+API int pkgmgrinfo_pkginfo_get_usr_disabled_pkginfo(const char *pkgid,
+ uid_t uid, pkgmgrinfo_pkginfo_h *handle)
{
- static const char query_raw[] =
- "SELECT package_icon, package_locale "
- "FROM package_localized_info "
- "WHERE package=%Q AND package_locale IN (%Q, %Q)";
int ret;
- char *query;
- sqlite3_stmt *stmt;
- int idx;
- icon_x *info;
-
- query = sqlite3_mprintf(query_raw, pkgid, locale, DEFAULT_LOCALE);
- if (query == NULL) {
- LOGE("out of memory");
- return PMINFO_R_ERROR;
- }
+ pkgmgrinfo_pkginfo_filter_h filter;
- 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;
+ if (pkgid == NULL || handle == NULL) {
+ LOGE("invalid parameter");
+ return PMINFO_R_EINVAL;
}
- while (sqlite3_step(stmt) == SQLITE_ROW) {
- info = calloc(1, sizeof(icon_x));
- if (info == NULL) {
- LOGE("out of memory");
- sqlite3_finalize(stmt);
- return PMINFO_R_ERROR;
- }
- idx = 0;
- _save_column_str(stmt, idx++, &info->text);
- _save_column_str(stmt, idx++, &info->lang);
- *icon = g_list_append(*icon, info);
+ ret = pkgmgrinfo_pkginfo_filter_create(&filter);
+ if (ret != PMINFO_R_OK) {
+ return ret;
}
- sqlite3_finalize(stmt);
-
- return PMINFO_R_OK;
-}
-
-static int _pkginfo_get_description(sqlite3 *db, const char *pkgid,
- const char *locale, GList **description)
-{
- static const char query_raw[] =
- "SELECT package_description, package_locale "
- "FROM package_localized_info "
- "WHERE package=%Q AND package_locale IN (%Q, %Q)";
- int ret;
- char *query;
- sqlite3_stmt *stmt;
- int idx;
- description_x *info;
-
- query = sqlite3_mprintf(query_raw, pkgid, locale, DEFAULT_LOCALE);
- if (query == NULL) {
- LOGE("out of memory");
+ ret = pkgmgrinfo_pkginfo_filter_add_string(filter,
+ PMINFO_PKGINFO_PROP_PACKAGE_ID, pkgid);
+ if (ret != PMINFO_R_OK) {
+ pkgmgrinfo_pkginfo_filter_destroy(filter);
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));
+ ret = pkgmgrinfo_pkginfo_filter_add_bool(filter,
+ PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, true);
+ if (ret != PMINFO_R_OK) {
+ pkgmgrinfo_pkginfo_filter_destroy(filter);
return PMINFO_R_ERROR;
}
- while (sqlite3_step(stmt) == SQLITE_ROW) {
- info = calloc(1, sizeof(description_x));
- if (info == NULL) {
- LOGE("out of memory");
- sqlite3_finalize(stmt);
- return PMINFO_R_ERROR;
- }
- idx = 0;
- _save_column_str(stmt, idx++, &info->text);
- _save_column_str(stmt, idx++, &info->lang);
- *description = g_list_append(*description, info);
- }
-
- sqlite3_finalize(stmt);
-
- return PMINFO_R_OK;
+ ret = _pkgmgrinfo_get_pkginfo(pkgid, uid, filter, handle);
+ if (ret == PMINFO_R_ENOENT)
+ LOGE("disabled pkginfo for [%s] is not existed for user [%d]",
+ pkgid, uid);
+ pkgmgrinfo_pkginfo_filter_destroy(filter);
+ return ret;
}
-static int _pkginfo_get_privilege(sqlite3 *db, const char *pkgid,
- GList **privileges)
+API int pkgmgrinfo_pkginfo_get_usr_all_pkginfo(const char *pkgid, uid_t uid,
+ pkgmgrinfo_pkginfo_h *handle)
{
- static const char query_raw[] =
- "SELECT privilege FROM package_privilege_info WHERE package=%Q";
int ret;
- char *query;
- sqlite3_stmt *stmt;
- char *privilege;
+ pkgmgrinfo_pkginfo_filter_h filter;
- query = sqlite3_mprintf(query_raw, pkgid);
- if (query == NULL) {
- LOGE("out of memory");
- return PMINFO_R_ERROR;
+ if (pkgid == NULL || handle == NULL) {
+ LOGE("invalid parameter");
+ return PMINFO_R_EINVAL;
}
- ret = sqlite3_prepare_v2(db, query, strlen(query),
- &stmt, NULL);
- sqlite3_free(query);
- if (ret != SQLITE_OK) {
- LOGE("prepare failed: %s", sqlite3_errmsg(db));
+ ret = pkgmgrinfo_pkginfo_filter_create(&filter);
+ if (ret != PMINFO_R_OK)
+ 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);
return PMINFO_R_ERROR;
}
- while (sqlite3_step(stmt) == SQLITE_ROW) {
- privilege = NULL;
- _save_column_str(stmt, 0, &privilege);
- if (privilege)
- *privileges = g_list_append(*privileges,
- (gpointer)privilege);
+ ret = pkgmgrinfo_pkginfo_filter_add_bool(filter,
+ PMINFO_PKGINFO_PROP_PACKAGE_CHECK_STORAGE, false);
+ if (ret != PMINFO_R_OK) {
+ pkgmgrinfo_pkginfo_filter_destroy(filter);
+ return PMINFO_R_ERROR;
}
- sqlite3_finalize(stmt);
+ ret = _pkgmgrinfo_get_pkginfo(pkgid, uid, filter, handle);
+ pkgmgrinfo_pkginfo_filter_destroy(filter);
- return PMINFO_R_OK;
+ return ret;
}
-static char *_get_filtered_query(const char *query_raw,
- pkgmgrinfo_filter_x *filter)
+API int pkgmgrinfo_pkginfo_get_disabled_pkginfo(const char *pkgid,
+ pkgmgrinfo_pkginfo_h *handle)
{
- char buf[MAX_QUERY_LEN] = { 0, };
- char *condition;
- size_t len;
- GSList *list;
- GSList *head = NULL;
-
- if (filter)
- head = filter->list;
-
- 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);
- 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(condition);
- strncat(buf, condition, sizeof(buf) - len - 1);
- free(condition);
- condition = NULL;
- }
+ return pkgmgrinfo_pkginfo_get_usr_disabled_pkginfo(pkgid, _getuid(),
+ handle);
+}
- return strdup(buf);
+API int pkgmgrinfo_pkginfo_get_all_pkginfo(const char *pkgid,
+ pkgmgrinfo_pkginfo_h *handle)
+{
+ return pkgmgrinfo_pkginfo_get_usr_all_pkginfo(pkgid, _getuid(), handle);
}
-static int _pkginfo_get_package(sqlite3 *db, const char *pkgid,
- const char *locale, package_x **package)
+API int pkgmgrinfo_pkginfo_get_usr_list_full(pkgmgrinfo_pkg_list_cb pkg_list_cb,
+ int flag, void *user_data, uid_t uid)
{
- 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 AND package_disable='false'";
int ret;
- char *query;
- sqlite3_stmt *stmt;
- int idx;
- package_x *info;
-
- 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;
- }
+ pkgmgrinfo_pkginfo_filter_h filter;
- 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;
- }
-
- info = calloc(1, sizeof(package_x));
- if (info == NULL) {
- LOGE("out of memory");
- sqlite3_finalize(stmt);
- return PMINFO_R_ERROR;
- }
- 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 (_pkginfo_get_label(db, info->package, locale, &info->label)) {
- pkgmgrinfo_basic_free_package(info);
- sqlite3_finalize(stmt);
- return PMINFO_R_ERROR;
+ if (pkg_list_cb == NULL) {
+ LOGE("invalid parameter");
+ return PMINFO_R_EINVAL;
}
- if (_pkginfo_get_icon(db, info->package, locale, &info->icon)) {
- pkgmgrinfo_basic_free_package(info);
- sqlite3_finalize(stmt);
- return PMINFO_R_ERROR;
- }
+ /* create an empty filter */
+ ret = pkgmgrinfo_pkginfo_filter_create(&filter);
+ if (ret != PMINFO_R_OK)
+ return ret;
- if (_pkginfo_get_description(db, info->package, locale,
- &info->description)) {
- pkgmgrinfo_basic_free_package(info);
- sqlite3_finalize(stmt);
- return PMINFO_R_ERROR;
- }
+ ret = _pkginfo_get_filtered_foreach_pkginfo(uid, filter, flag,
+ pkg_list_cb, user_data);
- if (_pkginfo_get_privilege(db, info->package, &info->privileges)) {
- pkgmgrinfo_basic_free_package(info);
- sqlite3_finalize(stmt);
- return PMINFO_R_ERROR;
- }
+ pkgmgrinfo_pkginfo_filter_destroy(filter);
- *package = info;
- sqlite3_finalize(stmt);
+ return ret;
+}
- return PMINFO_R_OK;
+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());
}
-static int _pkginfo_get_pkginfo(const char *pkgid, uid_t uid,
- pkgmgr_pkginfo_x **pkginfo)
+API int pkgmgrinfo_pkginfo_get_usr_list(pkgmgrinfo_pkg_list_cb pkg_list_cb,
+ void *user_data, uid_t uid)
{
int ret;
- sqlite3 *db;
- const char *dbpath;
- char *locale;
- pkgmgr_pkginfo_x *info;
-
- dbpath = getUserPkgParserDBPathUID(uid);
- if (dbpath == NULL)
- return PMINFO_R_ERROR;
-
- 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);
- free(locale);
- return PMINFO_R_ERROR;
- }
+ pkgmgrinfo_pkginfo_filter_h filter;
- info = calloc(1, sizeof(pkgmgr_pkginfo_x));
- if (info == NULL) {
- _LOGE("out of memory");
- free(locale);
- sqlite3_close_v2(db);
- return PMINFO_R_ERROR;
+ if (pkg_list_cb == NULL) {
+ LOGE("invalid parameter");
+ return PMINFO_R_EINVAL;
}
- ret = _pkginfo_get_package(db, pkgid, locale, &info->pkg_info);
- if (ret != PMINFO_R_OK) {
- free(info);
- free(locale);
- sqlite3_close_v2(db);
+ /* create an empty filter */
+ ret = pkgmgrinfo_pkginfo_filter_create(&filter);
+ if (ret != PMINFO_R_OK)
return ret;
- }
-
- info->locale = locale;
- info->uid = uid;
- info->pkg_info->for_all_users = strdup(
- uid != GLOBAL_USER ? "false" : "true");
- *pkginfo = info;
+ ret = _pkginfo_get_filtered_foreach_pkginfo(uid, filter,
+ PMINFO_PKGINFO_GET_ALL, pkg_list_cb, user_data);
- sqlite3_close_v2(db);
+ pkgmgrinfo_pkginfo_filter_destroy(filter);
return ret;
}
-API int pkgmgrinfo_pkginfo_get_usr_pkginfo(const char *pkgid, uid_t uid,
- 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_list(pkg_list_cb, user_data,
+ _getuid());
+}
+
+API int pkgmgrinfo_pkginfo_get_usr_disabled_list(
+ pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data, uid_t uid)
{
int ret;
+ pkgmgrinfo_pkginfo_filter_h filter;
- if (pkgid == NULL || handle == NULL) {
+ 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);
-
+ ret = pkgmgrinfo_pkginfo_filter_create(&filter);
if (ret != PMINFO_R_OK)
- _LOGE("failed to get pkginfo of %s for user %d", pkgid, uid);
+ return ret;
+
+ ret = pkgmgrinfo_pkginfo_filter_add_bool(filter,
+ PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, true);
+ if (ret != PMINFO_R_OK) {
+ pkgmgrinfo_pkginfo_filter_destroy(filter);
+ return PMINFO_R_ERROR;
+ }
+
+ 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_pkginfo(const char *pkgid, pkgmgrinfo_pkginfo_h *handle)
+API int pkgmgrinfo_pkginfo_get_disabled_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_disabled_list(pkg_list_cb, user_data,
+ _getuid());
}
API int pkgmgrinfo_pkginfo_get_pkgname(pkgmgrinfo_pkginfo_h handle, char **pkg_name)
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;
- *type = (char *)info->pkg_info->type;
+ if (info->pkg_info->type == NULL)
+ *type = "";
+ else
+ *type = (char *)info->pkg_info->type;
return PMINFO_R_OK;
}
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;
- *version = (char *)info->pkg_info->version;
+ if (info->pkg_info->version == NULL)
+ *version = "";
+ else
+ *version = (char *)info->pkg_info->version;
return PMINFO_R_OK;
}
retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
retvm_if(api_version == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
- if (info->pkg_info == NULL || info->pkg_info->api_version == NULL)
+ if (info->pkg_info == NULL)
return PMINFO_R_ERROR;
- *api_version = (char *)info->pkg_info->api_version;
+ if (info->pkg_info->api_version == NULL)
+ *api_version = "";
+ else
+ *api_version = (char *)info->pkg_info->api_version;
return PMINFO_R_OK;
}
if (info->pkg_info == NULL || info->pkg_info->tep_name == NULL)
return PMINFO_R_ERROR;
- if (strlen(info->pkg_info->tep_name) == 0)
- return PMINFO_R_ERROR;
-
*tep_name = (char *)info->pkg_info->tep_name;
return PMINFO_R_OK;
}
-API int pkgmgrinfo_pkginfo_get_install_location(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_install_location *location)
+API int pkgmgrinfo_pkginfo_get_zip_mount_file(pkgmgrinfo_pkginfo_h handle, char **zip_mount_file)
{
- 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");
+ retvm_if(zip_mount_file == 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;
- 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;
+ if (info->pkg_info->zip_mount_file == NULL)
+ *zip_mount_file = "";
else
- *location = PMINFO_INSTALL_LOCATION_AUTO;
+ *zip_mount_file = (char *)info->pkg_info->zip_mount_file;
return PMINFO_R_OK;
}
-API int pkgmgrinfo_pkginfo_get_package_size(pkgmgrinfo_pkginfo_h handle, int *size)
+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(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value 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 || info->pkg_info->package_size == NULL)
+ if (info->pkg_info == NULL)
return PMINFO_R_ERROR;
- *size = atoi((char *)info->pkg_info->package_size);
+ 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_total_size(pkgmgrinfo_pkginfo_h handle, int *size)
+API int pkgmgrinfo_pkginfo_get_install_location(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_install_location *location)
{
- 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;
+ char *val;
+ 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(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
- ret = pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
- if (ret < 0)
+ if (info->pkg_info == NULL || info->pkg_info->installlocation == NULL)
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;
- }
- }
-
- /* 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;
- }
- }
-
- 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;
- }
- }
-
- 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;
- }
- }
-
- 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;
- }
- }
-
- 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;
- }
- }
-
- 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;
- }
- }
-
- /* 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;
}
API int pkgmgrinfo_pkginfo_get_icon(pkgmgrinfo_pkginfo_h handle, char **icon)
{
- const char *locale;
icon_x *ptr;
- GList *tmp;
pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
- 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) {
- ptr = (icon_x *)tmp->data;
- if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
- !strcasecmp(ptr->text, "(null)") ||
- strcmp(ptr->lang, locale))
- continue;
- *icon = (char *)ptr->text;
- return PMINFO_R_OK;
- }
+ ptr = (icon_x *)info->pkg_info->icon->data;
+ if (ptr == NULL)
+ return PMINFO_R_ERROR;
- locale = DEFAULT_LOCALE;
- for (tmp = info->pkg_info->icon; tmp; tmp = tmp->next) {
- ptr = (icon_x *)tmp->data;
- if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
- strcmp(ptr->lang, locale))
- continue;
- *icon = (char *)ptr->text;
- return PMINFO_R_OK;
- }
+ /* TODO : should we return empty string if there was no icon? */
+ if (ptr->text == NULL)
+ *icon = "";
+ else
+ *icon = ptr->text;
- return PMINFO_R_ERROR;
+ return PMINFO_R_OK;
}
API int pkgmgrinfo_pkginfo_get_label(pkgmgrinfo_pkginfo_h handle, char **label)
{
- const char *locale;
label_x *ptr;
- GList *tmp;
pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
- 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 ||
- strcmp(ptr->lang, locale))
- continue;
- *label = (char *)ptr->text;
- return PMINFO_R_OK;
- }
+ ptr = (label_x *)info->pkg_info->label->data;
+ if (ptr == NULL)
+ return PMINFO_R_ERROR;
- locale = DEFAULT_LOCALE;
- 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 ||
- strcmp(ptr->lang, locale))
- continue;
- *label = (char *)ptr->text;
- return PMINFO_R_OK;
- }
+ /* TODO : should we return empty string if there was no label? */
+ if (ptr->text == NULL)
+ *label = "";
+ else
+ *label = ptr->text;
- return PMINFO_R_ERROR;
+ return PMINFO_R_OK;
}
API int pkgmgrinfo_pkginfo_get_description(pkgmgrinfo_pkginfo_h handle, char **description)
{
- const char *locale;
description_x *ptr;
- GList *tmp;
pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
retvm_if(description == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
- 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 ||
- strcmp(ptr->lang, locale))
- continue;
- *description = (char *)ptr->text;
- return PMINFO_R_OK;
- }
+ ptr = (description_x *)info->pkg_info->description->data;
+ if (ptr == NULL)
+ return PMINFO_R_ERROR;
- locale = DEFAULT_LOCALE;
- for (tmp = info->pkg_info->description; tmp; tmp = tmp->next) {
- ptr = (description_x *)tmp->data;
- if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
- strcmp(ptr->lang, locale))
- continue;
+ if (ptr->text == NULL)
+ *description = "";
+ else
*description = (char *)ptr->text;
- return PMINFO_R_OK;
- }
- return PMINFO_R_ERROR;
+ return PMINFO_R_OK;
}
API int pkgmgrinfo_pkginfo_get_author_name(pkgmgrinfo_pkginfo_h handle, char **author_name)
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;
- *author_name = (char *)author->text;
+ if (author->text == NULL)
+ *author_name = "";
+ else
+ *author_name = (char *)author->text;
return PMINFO_R_OK;
}
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;
- *author_email = (char *)author->email;
+ if (author->email == NULL)
+ *author_email = "";
+ else
+ *author_email = (char *)author->email;
return PMINFO_R_OK;
}
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;
- *author_href = (char *)author->href;
+ if (author->href == NULL)
+ *author_href = "";
+ else
+ *author_href = (char *)author->href;
return PMINFO_R_OK;
}
if (info->pkg_info == NULL || info->pkg_info->installed_storage == NULL)
return PMINFO_R_ERROR;
- if (strcmp(info->pkg_info->installed_storage,"installed_internal") == 0)
+ if (strcmp(info->pkg_info->installed_storage, "installed_internal") == 0)
*storage = PMINFO_INTERNAL_STORAGE;
- else if (strcmp(info->pkg_info->installed_storage,"installed_external") == 0)
+ 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;
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;
- *storeclientid = (char *)info->pkg_info->storeclient_id;
+ if (info->pkg_info->storeclient_id == NULL)
+ *storeclientid = "";
+ else
+ *storeclientid = (char *)info->pkg_info->storeclient_id;
return PMINFO_R_OK;
}
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;
- *url = (char *)info->pkg_info->package_url;
+ if (info->pkg_info->package_url == NULL)
+ *url = "";
+ else
+ *url = (char *)info->pkg_info->package_url;
return PMINFO_R_OK;
}
-API int pkgmgrinfo_pkginfo_get_size_from_xml(const char *manifest, int *size)
+API int pkgmgrinfo_pkginfo_get_root_path(pkgmgrinfo_pkginfo_h handle, char **path)
{
- 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");
+ pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
- 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;
- }
+ 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 (!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();
+ if (info->pkg_info == NULL || info->pkg_info->root_path == NULL)
return PMINFO_R_ERROR;
- }
- xmlFreeTextReader(reader);
- xmlCleanupParser();
+ *path = (char *)info->pkg_info->root_path;
return PMINFO_R_OK;
}
-API int pkgmgrinfo_pkginfo_get_location_from_xml(const char *manifest, pkgmgrinfo_install_location *location)
+API int pkgmgrinfo_pkginfo_get_csc_path(pkgmgrinfo_pkginfo_h handle, char **path)
{
- 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");
+ pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
- 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;
- }
+ 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 (!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();
+ if (info->pkg_info == NULL)
return PMINFO_R_ERROR;
- }
- xmlFreeTextReader(reader);
- xmlCleanupParser();
+ if (info->pkg_info->csc_path == NULL)
+ *path = "";
+ else
+ *path = (char *)info->pkg_info->csc_path;
return PMINFO_R_OK;
}
+API int pkgmgrinfo_pkginfo_get_res_type(pkgmgrinfo_pkginfo_h handle,
+ char **res_type)
+{
+ pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
-API int pkgmgrinfo_pkginfo_get_root_path(pkgmgrinfo_pkginfo_h handle, char **path)
+ retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
+ retvm_if(res_type == 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->res_type == NULL)
+ return PMINFO_R_ENOENT;
+
+ *res_type = (char *)info->pkg_info->res_type;
+
+ return PMINFO_R_OK;
+}
+
+API int pkgmgrinfo_pkginfo_get_res_version(pkgmgrinfo_pkginfo_h handle,
+ char **res_version)
{
pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
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");
+ retvm_if(res_version == NULL, PMINFO_R_EINVAL,
+ "Argument supplied to hold return value is NULL\n");
- if (info->pkg_info == NULL || info->pkg_info->root_path == NULL)
+ if (info->pkg_info == NULL)
return PMINFO_R_ERROR;
- *path = (char *)info->pkg_info->root_path;
+ if (info->pkg_info->res_version == NULL)
+ return PMINFO_R_ENOENT;
+
+ *res_version = (char *)info->pkg_info->res_version;
return PMINFO_R_OK;
}
-API int pkgmgrinfo_pkginfo_get_csc_path(pkgmgrinfo_pkginfo_h handle, char **path)
+API int pkgmgrinfo_pkginfo_get_light_user_switch_mode(pkgmgrinfo_pkginfo_h handle, char **mode)
{
pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
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");
+ retvm_if(mode == 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->light_user_switch_mode == NULL)
+ return PMINFO_R_ERROR;
+
+ *mode = (char *)info->pkg_info->light_user_switch_mode;
+
+ return PMINFO_R_OK;
+}
- if (info->pkg_info == NULL || info->pkg_info->csc_path == NULL)
- return PMINFO_R_ERROR;
+API int pkgmgrinfo_pkginfo_get_support_mode(pkgmgrinfo_pkginfo_h handle, int *support_mode)
+{
+ retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
+ retvm_if(support_mode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
- *path = (char *)info->pkg_info->csc_path;
+ pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
+ if (info->pkg_info->support_mode)
+ *support_mode = atoi(info->pkg_info->support_mode);
+ else
+ *support_mode = 0;
return PMINFO_R_OK;
}
-
API int pkgmgrinfo_pkginfo_is_accessible(pkgmgrinfo_pkginfo_h handle, bool *accessible)
{
retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
retvm_if(accessible == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
-#if 0 //smack issue occured, check later
+#if 0 /* smack issue occured, check later */
char *pkgid = NULL;
pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
- if (pkgid == NULL){
+ if (pkgid == NULL) {
_LOGD("invalid func parameters\n");
return PMINFO_R_ERROR;
}
char app_mmc_path[FILENAME_MAX] = { 0, };
char app_dir_path[FILENAME_MAX] = { 0, };
char app_mmc_internal_path[FILENAME_MAX] = { 0, };
- snprintf(app_dir_path, FILENAME_MAX,"%s%s", PKG_INSTALLATION_PATH, pkgid);
- snprintf(app_mmc_path, FILENAME_MAX,"%s%s", PKG_SD_PATH, pkgid);
- snprintf(app_mmc_internal_path, FILENAME_MAX,"%s%s/.mmc", PKG_INSTALLATION_PATH, pkgid);
+ snprintf(app_dir_path, FILENAME_MAX, "%s%s", PKG_INSTALLATION_PATH, pkgid);
+ snprintf(app_mmc_path, FILENAME_MAX, "%s%s", PKG_SD_PATH, pkgid);
+ snprintf(app_mmc_internal_path, FILENAME_MAX, "%s%s/.mmc", PKG_INSTALLATION_PATH, pkgid);
/*check whether application is in external memory or not */
fp = fopen(app_mmc_path, "r");
- if (fp == NULL){
+ if (fp == NULL) {
_LOGD(" app path in external memory not accesible\n");
} else {
fclose(fp);
}
/*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;
/*check whether the application is installed in SD card
but SD card is not present*/
fp = fopen(app_mmc_internal_path, "r");
- if (fp == NULL){
+ if (fp == NULL) {
*accessible = 1;
_LOGD("pkgmgr_get_pkg_external_validation() : INTERNAL_MEM \n");
return PMINFO_R_OK;
- }
- else{
+ } else {
*accessible = 0;
_LOGD("pkgmgr_get_pkg_external_validation() : ERROR_MMC_STATUS \n");
}
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;
return pkgmgrinfo_pkginfo_is_global(handle, for_all_users);
}
+API int pkgmgrinfo_pkginfo_is_lib(pkgmgrinfo_pkginfo_h handle, bool *lib)
+{
+ pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
+
+ retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
+ retvm_if(lib == NULL, PMINFO_R_EINVAL,
+ "Argument supplied to hold return value is NULL\n");
+
+ if (info->pkg_info == NULL || info->pkg_info->lib == NULL)
+ return PMINFO_R_ERROR;
+
+ *lib = _get_bool_value(info->pkg_info->lib);
+
+ return PMINFO_R_OK;
+}
+
API int pkgmgrinfo_pkginfo_destroy_pkginfo(pkgmgrinfo_pkginfo_h handle)
{
pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle output parameter is NULL\n");
- filter = (pkgmgrinfo_filter_x*)calloc(1, sizeof(pkgmgrinfo_filter_x));
+ filter = (pkgmgrinfo_filter_x *)calloc(1, sizeof(pkgmgrinfo_filter_x));
if (filter == NULL) {
_LOGE("Out of Memory!!!");
return PMINFO_R_ERROR;
retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
- if (filter->list) {
- g_slist_foreach(filter->list, __destroy_each_node, NULL);
- g_slist_free(filter->list);
- }
+ if (filter->list)
+ g_slist_free_full(filter->list,
+ (GDestroyNotify)_pkgmgrinfo_node_destroy);
+
+ if (filter->list_metadata)
+ g_slist_free_full(filter->list_metadata,
+ __destroy_metadata_node);
+ if (filter->list_pkg_metadata)
+ g_slist_free_full(filter->list_pkg_metadata,
+ __destroy_metadata_node);
free(filter);
/*If API is called multiple times for same property, we should override the previous values.
Last value set will be used for filtering.*/
link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
- if (link)
+ if (link) {
+ _pkgmgrinfo_node_destroy(link->data);
filter->list = g_slist_delete_link(filter->list, link);
+ }
filter->list = g_slist_append(filter->list, (gpointer)node);
return PMINFO_R_OK;
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);
/*If API is called multiple times for same property, we should override the previous values.
Last value set will be used for filtering.*/
link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
- if (link)
+ if (link) {
+ _pkgmgrinfo_node_destroy(link->data);
filter->list = g_slist_delete_link(filter->list, link);
+ }
filter->list = g_slist_append(filter->list, (gpointer)node);
return PMINFO_R_OK;
/*If API is called multiple times for same property, we should override the previous values.
Last value set will be used for filtering.*/
link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
- if (link)
+ if (link) {
+ _pkgmgrinfo_node_destroy(link->data);
filter->list = g_slist_delete_link(filter->list, link);
+ }
filter->list = g_slist_append(filter->list, (gpointer)node);
return PMINFO_R_OK;
API int pkgmgrinfo_pkginfo_usr_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count, uid_t uid)
{
int ret;
- GList *list = NULL;
+ int query_count;
+ 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)
+ list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
+ __free_packages);
+ if (list == NULL)
return PMINFO_R_ERROR;
- *count = g_list_length(list);
-
- g_list_free_full(list, free);
+ if (__check_disable_filter_exist((pkgmgrinfo_filter_x *)handle) == false) {
+ ret = pkgmgrinfo_pkginfo_filter_add_bool(handle,
+ PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, false);
+ if (ret != PMINFO_R_OK) {
+ g_hash_table_destroy(list);
+ return PMINFO_R_ERROR;
+ }
+ }
+ ret = _pkginfo_get_packages(uid, handle, PMINFO_PKGINFO_GET_BASICINFO, list);
+ query_count = g_hash_table_size(list);
+ g_hash_table_destroy(list);
+ if (ret == PMINFO_R_ERROR)
+ return ret;
+ *count = query_count;
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(
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,
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;
- const char *privilege;
+ privilege_x *privilege;
+ appdefined_privilege_x *appdefined_privilege;
GList *tmp;
pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
return PMINFO_R_ERROR;
for (tmp = info->pkg_info->privileges; tmp; tmp = tmp->next) {
- privilege = (const char *)tmp->data;
+ privilege = (privilege_x *)tmp->data;
+ if (privilege == NULL)
+ 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, user_data);
+ 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;
+}
+
+static void __free_depends_on(gpointer data)
+{
+ dependency_x *dep = (dependency_x *)data;
+ pkgmgrinfo_basic_free_dependency(dep);
+}
+
+/* This API is not exported at the header file */
+API int pkgmgrinfo_pkginfo_foreach_depends_on_by_pkgid(const char *pkgid,
+ pkgmgrinfo_pkg_dependency_list_cb dependency_cb,
+ void *user_data, uid_t uid)
+{
+ int ret;
+ GList *pkg_list = NULL;
+ GList *l;
+ dependency_x *dep;
+
+ if (pkgid == NULL || dependency_cb == NULL) {
+ LOGE("invalid parameter");
+ return PMINFO_R_EINVAL;
+ }
+
+ ret = _pkginfo_get_depends_on(uid, pkgid, &pkg_list);
+ if (ret != PMINFO_R_OK)
+ return PMINFO_R_ERROR;
+
+ for (l = pkg_list; l != NULL; l = g_list_next(l)) {
+ dep = (dependency_x *)l->data;
+ ret = dependency_cb(dep->pkgid, dep->depends_on,
+ dep->type, dep->required_version, user_data);
if (ret < 0)
break;
}
+ g_list_free_full(pkg_list, __free_depends_on);
+
+ return PMINFO_R_OK;
+}
+
+API int pkgmgrinfo_pkginfo_foreach_depends_on(pkgmgrinfo_pkginfo_h handle,
+ pkgmgrinfo_pkg_dependency_list_cb dependency_cb,
+ void *user_data)
+{
+ pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
+
+ if (handle == NULL || dependency_cb == NULL || info->pkg_info == NULL) {
+ LOGE("invalid parameter");
+ return PMINFO_R_EINVAL;
+ }
+
+ return pkgmgrinfo_pkginfo_foreach_depends_on_by_pkgid(
+ info->pkg_info->package, dependency_cb, user_data,
+ info->uid);
+}
+
+API int pkgmgrinfo_pkginfo_foreach_res_allowed_package(
+ pkgmgrinfo_pkginfo_h handle,
+ pkgmgrinfo_res_allowed_package_list_cb res_allowed_package_cb,
+ void *user_data)
+{
+ int ret;
+ pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
+ GList *res_pkgs;
+ res_allowed_package_x *res_allowed_package;
+
+ if (handle == NULL || res_allowed_package_cb == NULL) {
+ LOGE("invalid parameter");
+ return PMINFO_R_EINVAL;
+ }
+
+ if (info->pkg_info == NULL)
+ return PMINFO_R_ERROR;
+
+ for (res_pkgs = info->pkg_info->res_allowed_packages; res_pkgs;
+ res_pkgs = res_pkgs->next) {
+ res_allowed_package = (res_allowed_package_x *)res_pkgs->data;
+ if (res_allowed_package == NULL)
+ continue;
+
+ ret = res_allowed_package_cb(
+ res_allowed_package->allowed_package,
+ res_allowed_package->required_privileges,
+ user_data);
+ if (ret < 0)
+ return PMINFO_R_OK;
+ }
+
+ return PMINFO_R_OK;
+}
+
+API int pkgmgrinfo_pkginfo_foreach_required_privilege(
+ required_privilege_h handle,
+ pkgmgrinfo_pkg_privilege_list_cb privilege_func,
+ void *user_data)
+{
+ int ret;
+ GList *privs;
+
+ if (privilege_func == NULL) {
+ LOGE("invalid parameter");
+ return PMINFO_R_EINVAL;
+ }
+
+ for (privs = (GList *)handle; privs; privs = privs->next) {
+ ret = privilege_func((char *)privs->data, user_data);
+ if (ret < 0)
+ return PMINFO_R_OK;
+ }
+
+ return PMINFO_R_OK;
+}
+
+int __compare_package_version(const char *version, int *major,
+ int *minor, int *macro, int *nano)
+{
+ char *version_temp = NULL;
+ char *major_str = NULL;
+ char *minor_str = NULL;
+ char *macro_str = NULL;
+ char *nano_str = NULL;
+ char *save_str = NULL;
+
+ if (version == NULL || major == NULL || minor == NULL ||
+ macro == NULL || nano == NULL) {
+ return PMINFO_R_EINVAL;
+ }
+
+ version_temp = strdup(version);
+ if (version_temp == NULL) {
+ LOGE("Out of memory");
+ return PMINFO_R_ERROR;
+ }
+
+ major_str = strtok_r(version_temp, ".", &save_str);
+ if (major_str == NULL) {
+ _LOGE("major version is NULL");
+ free(version_temp);
+ return PMINFO_R_ERROR;
+ }
+
+ minor_str = strtok_r(NULL, ".", &save_str);
+ if (minor_str == NULL) {
+ _LOGE("minor version is NULL");
+ free(version_temp);
+ return PMINFO_R_ERROR;
+ }
+
+ *major = atoi(major_str);
+ *minor = atoi(minor_str);
+ *macro = 0;
+ *nano = 0;
+ macro_str = strtok_r(NULL, ".", &save_str);
+ if (macro_str == NULL) {
+ _LOGD("macro version is NULL");
+ } else {
+ *macro = atoi(macro_str);
+ nano_str = strtok_r(NULL, ".", &save_str);
+ if (nano_str) {
+ *nano = atoi(nano_str);
+ _LOGD("nano version exists");
+ }
+ }
+ _LOGD("version = [%s] -> major = [%d], minor = [%d]," \
+ " macro = [%d], nano = [%d]", version, *major,
+ *minor, *macro, *nano);
+
+ free(version_temp);
+
+ return PMINFO_R_OK;
+}
+
+API int pkgmgrinfo_compare_package_version(const char *current_version,
+ const char *target_version,
+ pkgmgrinfo_version_compare_type *res)
+{
+ int ret = 0;
+ int current_version_major = 0;
+ int current_version_minor = 0;
+ int current_version_macro = 0;
+ int current_version_nano = 0;
+ int target_version_major = 0;
+ int target_version_minor = 0;
+ int target_version_macro = 0;
+ int target_version_nano = 0;
+
+ if (current_version == NULL || target_version == NULL ||
+ res == NULL) {
+ _LOGE("Invalid parameter");
+ return PMINFO_R_EINVAL;
+ }
+
+ ret = __compare_package_version(target_version,
+ &target_version_major, &target_version_minor,
+ &target_version_macro, &target_version_nano);
+ if (ret < 0) {
+ _LOGE("Failed to compare target version(%d)", ret);
+ return PMINFO_R_ERROR;
+ }
+
+ ret = __compare_package_version(current_version,
+ ¤t_version_major, ¤t_version_minor,
+ ¤t_version_macro, ¤t_version_nano);
+ if (ret < 0) {
+ _LOGE("Failed to compare current version(%d)", ret);
+ return PMINFO_R_ERROR;
+ }
+
+ _LOGD("new[%d.%d.%d.%d] old[%d.%d.%d.%d]", target_version_major,
+ target_version_minor, target_version_macro,
+ target_version_nano, current_version_major,
+ current_version_minor, current_version_macro,
+ target_version_nano);
+
+ if (target_version_major > current_version_major)
+ *res = PMINFO_VERSION_NEW;
+ else if (target_version_major < current_version_major)
+ *res = PMINFO_VERSION_OLD;
+ else if (target_version_minor > current_version_minor)
+ *res = PMINFO_VERSION_NEW;
+ else if (target_version_minor < current_version_minor)
+ *res = PMINFO_VERSION_OLD;
+ else if (target_version_macro > current_version_macro)
+ *res = PMINFO_VERSION_NEW;
+ else if (target_version_macro < current_version_macro)
+ *res = PMINFO_VERSION_OLD;
+ else if (target_version_nano > current_version_nano)
+ *res = PMINFO_VERSION_NEW;
+ else if (target_version_nano < current_version_nano)
+ *res = PMINFO_VERSION_OLD;
+ else
+ *res = PMINFO_VERSION_SAME;
+
+ return PMINFO_R_OK;
+}
+
+API int pkgmgrinfo_pkginfo_foreach_metadata(pkgmgrinfo_pkginfo_h handle,
+ pkgmgrinfo_pkg_metadata_list_cb metadata_func, void *user_data)
+{
+ retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
+ retvm_if(metadata_func == NULL, PMINFO_R_EINVAL,
+ "Callback function is NULL");
+ int ret = -1;
+ metadata_x *ptr;
+ GList *tmp;
+ pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
+
+ if (info->pkg_info == NULL)
+ return PMINFO_R_ERROR;
+
+ for (tmp = info->pkg_info->metadata; tmp; tmp = tmp->next) {
+ ptr = (metadata_x *)tmp->data;
+ if (ptr == NULL)
+ continue;
+ if (ptr->key) {
+ ret = metadata_func(ptr->key, ptr->value ?
+ ptr->value : "", user_data);
+ if (ret < 0)
+ break;
+ }
+ }
+ return PMINFO_R_OK;
+}
+
+API int pkgmgrinfo_pkginfo_metadata_filter_create(
+ pkgmgrinfo_pkginfo_metadata_filter_h *handle)
+{
+ return pkgmgrinfo_pkginfo_filter_create(handle);
+}
+
+API int pkgmgrinfo_pkginfo_metadata_filter_destroy(
+ pkgmgrinfo_pkginfo_metadata_filter_h handle)
+{
+ return pkgmgrinfo_pkginfo_filter_destroy(handle);
+}
+
+API int pkgmgrinfo_pkginfo_metadata_filter_add(
+ pkgmgrinfo_pkginfo_metadata_filter_h handle,
+ const char *key, const char *value)
+{
+ pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
+ pkgmgrinfo_metadata_node_x *node;
+
+ /* value can be NULL.
+ * In that case all pkgs with specified key should be displayed
+ */
+ if (handle == NULL || key == NULL) {
+ LOGE("invalid parameter");
+ return PMINFO_R_EINVAL;
+ }
+
+ node = calloc(1, sizeof(pkgmgrinfo_metadata_node_x));
+ if (node == NULL) {
+ LOGE("out of memory");
+ return PMINFO_R_ERROR;
+ }
+
+ node->key = strdup(key);
+ if (value && strlen(value))
+ node->value = strdup(value);
+
+ filter->list_pkg_metadata = g_slist_append(filter->list_pkg_metadata,
+ (gpointer)node);
+
return PMINFO_R_OK;
}
+
+API int pkgmgrinfo_pkginfo_usr_metadata_filter_foreach(
+ pkgmgrinfo_pkginfo_metadata_filter_h handle,
+ pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data, uid_t uid)
+{
+ if (handle == NULL || pkg_cb == NULL) {
+ LOGE("invalid parameter");
+ return PMINFO_R_EINVAL;
+ }
+
+ pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
+
+ if (pkgmgrinfo_pkginfo_filter_add_bool(filter,
+ PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, false))
+ return PMINFO_R_ERROR;
+
+ return _pkginfo_get_filtered_foreach_pkginfo(uid, handle,
+ PMINFO_PKGINFO_GET_ALL, pkg_cb,
+ user_data);
+}
+
+API int pkgmgrinfo_pkginfo_metadata_filter_foreach(
+ pkgmgrinfo_pkginfo_metadata_filter_h handle,
+ pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data)
+{
+ return pkgmgrinfo_pkginfo_usr_metadata_filter_foreach(handle, pkg_cb,
+ user_data, _getuid());
+}
+
+API int pkgmgrinfo_pkginfo_get_metadata_value(
+ pkgmgrinfo_pkginfo_h handle, const char *metadata_key,
+ char **metadata_value)
+{
+ retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
+ retvm_if(metadata_key == NULL, PMINFO_R_EINVAL, "metadata_key is NULL");
+ retvm_if(metadata_value == NULL, PMINFO_R_EINVAL,
+ "metadata_value is NULL");
+
+ GList *list_md = NULL;
+ metadata_x *metadata = NULL;
+ pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
+
+ list_md = info->pkg_info->metadata;
+
+ for (; list_md; list_md = list_md->next) {
+ metadata = (metadata_x *)list_md->data;
+ if (metadata && metadata->key) {
+ if (strcasecmp(metadata->key, metadata_key) == 0) {
+ if (metadata->value == NULL)
+ *metadata_value = "";
+ else
+ *metadata_value =
+ (char *)metadata->value;
+ return PMINFO_R_OK;
+ }
+ }
+ }
+
+ return PMINFO_R_EINVAL;
+}