* limitations under the License.
*
*/
-
+
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <stdbool.h>
#include <unistd.h>
#include <ctype.h>
#include <sys/smack.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"
-
-#define FILTER_QUERY_COUNT_PACKAGE "select count(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='%s' where "
-
-static int _pkginfo_get_pkg(const char *pkgid, const char *locale,
- 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 && !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 int __count_cb(void *data, int ncols, char **coltxt, char **colname)
+static gint __pkg_disable_chk_func(gconstpointer data1, gconstpointer data2)
{
- int *p = (int*)data;
- *p = atoi(coltxt[0]);
- _LOGE("count value is %d\n", *p);
- return 0;
+ 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_each_node(gpointer data, gpointer user_data)
{
ret_if(data == NULL);
- pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)data;
+ pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)data;
if (node->value) {
free(node->value);
node->value = NULL;
node = NULL;
}
+static void __destroy_metadata_node(gpointer data)
+{
+ pkgmgrinfo_metadata_node_x *node = (pkgmgrinfo_metadata_node_x *)data;
+ if (node->key)
+ free(node->key);
+ if (node->value)
+ free(node->value);
+ free(node);
+}
+
static void __cleanup_pkginfo(pkgmgr_pkginfo_x *data)
{
ret_if(data == NULL);
- if (data->locale){
+ if (data->locale) {
free((void *)data->locale);
data->locale = NULL;
}
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;
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;
+ if (dp == NULL) {
+ _LOGE("Couldn't open the directory\n");
+ return -1;
+ }
+
+ for (ret = readdir_r(dp, &ep, &result);
+ ret == 0 && result != NULL;
+ ret = readdir_r(dp, &ep, &result)) {
+ if (!strcmp(ep.d_name, ".") ||
+ !strcmp(ep.d_name, "..")) {
+ 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 {
- _LOGE("Couldn't open the directory\n");
- return -1;
}
+ (void)closedir(dp);
return total;
}
-static GSList *_pkginfo_get_filtered_list(const char *locale,
- pkgmgrinfo_filter_x *filter)
+static int _pkginfo_add_description_info_into_list(const char *locale,
+ char *record, GList **description)
+{
+ description_x *info;
+
+ info = calloc(1, sizeof(description_x));
+ if (info == NULL) {
+ LOGE("out of memory");
+ return PMINFO_R_ERROR;
+ }
+ info->lang = strdup(locale);
+ info->text = record;
+ *description = g_list_append(*description, info);
+
+ return PMINFO_R_OK;
+}
+
+static int _pkginfo_get_privilege(sqlite3 *db, const char *pkgid,
+ GList **privileges)
{
static const char query_raw[] =
- "SELECT 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 ";
+ "SELECT DISTINCT privilege, type FROM package_privilege_info "
+ "WHERE package=%Q";
int ret;
char *query;
- char *query_localized;
sqlite3_stmt *stmt;
- GSList *list = NULL;
- char *pkgid;
-
- query = _get_filtered_query(query_raw, filter);
- if (query == NULL)
- return NULL;
- query_localized = sqlite3_mprintf(query, locale);
- free(query);
- if (query_localized == NULL)
- return NULL;
-
- ret = sqlite3_prepare_v2(GET_DB(manifest_db), query_localized,
- strlen(query_localized), &stmt, NULL);
- sqlite3_free(query_localized);
+ privilege_x *privilege;
+
+ query = sqlite3_mprintf(query_raw, pkgid);
+ if (query == NULL) {
+ LOGE("out of memory");
+ return PMINFO_R_ERROR;
+ }
+
+ ret = sqlite3_prepare_v2(db, query, strlen(query),
+ &stmt, NULL);
+ sqlite3_free(query);
if (ret != SQLITE_OK) {
- LOGE("prepare failed: %s", sqlite3_errmsg(GET_DB(manifest_db)));
- return NULL;
+ LOGE("prepare failed: %s", sqlite3_errmsg(db));
+ return PMINFO_R_ERROR;
}
while (sqlite3_step(stmt) == SQLITE_ROW) {
- _save_column_str(stmt, 0, (const char **)&pkgid);
- list = g_slist_append(list, pkgid);
+ privilege = calloc(1, sizeof(privilege_x));
+ _save_column_str(stmt, 0, &privilege->value);
+ _save_column_str(stmt, 1, &privilege->type);
+ *privileges = g_list_append(*privileges,
+ (gpointer)privilege);
}
sqlite3_finalize(stmt);
- return list;
+ 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)
+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, uid_t uid, char **query, GList **bind_params)
{
- pkgmgr_pkginfo_x *info;
- GSList *list;
- GSList *tmp;
- char *pkgid;
- char *locale;
- int stop = 0;
+ 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 (__open_manifest_db(uid) < 0)
- return PMINFO_R_ERROR;
+ if (filter == NULL)
+ return PMINFO_R_OK;
- locale = _get_system_locale();
- if (locale == NULL) {
- __close_manifest_db();
- return PMINFO_R_ERROR;
- }
+ 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, uid, &condition,
+ bind_params);
+ if (condition == NULL)
+ continue;
- list = _pkginfo_get_filtered_list(locale, filter);
- if (list == NULL) {
- free(locale);
- __close_manifest_db();
- return PMINFO_R_OK;
+ 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;
}
- for (tmp = list; tmp; tmp = tmp->next) {
- pkgid = (char *)tmp->data;
- if (stop == 0) {
- if (_pkginfo_get_pkg(pkgid, locale, &info)) {
- free(pkgid);
- continue;
- }
- if (pkg_list_cb(info, user_data) < 0)
- stop = 1;
- pkgmgrinfo_pkginfo_destroy_pkginfo(info);
- }
- free(pkgid);
+ 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);
- free(locale);
- g_slist_free(list);
- __close_manifest_db();
+ *query = strdup(buf2);
+ if (*query == NULL)
+ return PMINFO_R_ERROR;
return PMINFO_R_OK;
}
-API int pkgmgrinfo_pkginfo_get_usr_list(pkgmgrinfo_pkg_list_cb pkg_list_cb,
- void *user_data, uid_t uid)
+static void __free_packages(gpointer data)
{
- 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);
+ pkgmgrinfo_basic_free_package((package_x *)data);
}
-API int pkgmgrinfo_pkginfo_get_list(pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data)
+static bool __check_disable_filter_exist(pkgmgrinfo_filter_x *filter)
{
- return pkgmgrinfo_pkginfo_get_usr_list(pkg_list_cb, user_data, GLOBAL_USER);
+ GSList *link;
+
+ if (filter == NULL)
+ return false;
+
+ link = g_slist_find_custom(filter->list, NULL, __pkg_disable_chk_func);
+ if (link)
+ return true;
+
+ return false;
}
-static int _pkginfo_get_author(const char *pkgid, author_x **author)
+static int __bind_params(sqlite3_stmt *stmt, GList *params)
{
- 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;
+ GList *tmp_list = NULL;
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(GET_DB(manifest_db), query, strlen(query),
- &stmt, NULL);
- sqlite3_free(query);
- if (ret != SQLITE_OK) {
- LOGE("prepare failed: %s", sqlite3_errmsg(GET_DB(manifest_db)));
- return PMINFO_R_ERROR;
- }
+ int ret;
- if (sqlite3_step(stmt) == SQLITE_ERROR) {
- LOGE("step error: %s", sqlite3_errmsg(GET_DB(manifest_db)));
- sqlite3_finalize(stmt);
- return PMINFO_R_ERROR;
- }
+ if (stmt == NULL || params == NULL)
+ return PMINFO_R_EINVAL;
- /* one author per one package */
- info = calloc(1, sizeof(author_x));
- if (info == NULL) {
- LOGE("out of memory");
- sqlite3_finalize(stmt);
- return PMINFO_R_ERROR;
+ 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;
}
- _save_column_str(stmt, idx++, &info->text);
- _save_column_str(stmt, idx++, &info->email);
- _save_column_str(stmt, idx++, &info->href);
-
- *author = info;
+ return PMINFO_R_OK;
+}
- sqlite3_finalize(stmt);
+static bool __check_package_storage_status(pkgmgrinfo_filter_x *tmp_filter)
+{
+ GSList *tmp_list = NULL;
+ pkgmgrinfo_node_x *tmp_node = NULL;
+ int property = -1;
- return PMINFO_R_OK;
+ property = _pminfo_pkginfo_convert_to_prop_bool(PMINFO_PKGINFO_PROP_PACKAGE_CHECK_STORAGE);
+ for (tmp_list = tmp_filter->list; tmp_list != NULL;
+ tmp_list = g_slist_next(tmp_list)) {
+ tmp_node = (pkgmgrinfo_node_x *)tmp_list->data;
+ if (property == tmp_node->prop) {
+ if (strcmp(tmp_node->value, "true") == 0)
+ return true;
+ else
+ return false;
+ }
+ }
+ return true;
}
-static int _pkginfo_get_label(const char *pkgid, const char *locale,
- label_x **label)
+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 package_label, package_locale "
- "FROM package_localized_info "
- "WHERE package=%Q AND package_locale IN (%Q, %Q)";
- int ret;
- char *query;
+ "SELECT DISTINCT pi.package, pi.package_version, "
+ "pi.install_location, pi.package_removable, "
+ "pi.package_preload, pi.package_readonly, pi.package_update, "
+ "pi.package_appsetting, pi.package_system, pi.package_type, "
+ "pi.package_size, pi.installed_time, pi.installed_storage, "
+ "pi.storeclient_id, pi.mainapp_id, pi.package_url, "
+ "pi.root_path, pi.csc_path, pi.package_nodisplay, "
+ "pi.package_api_version, pi.package_support_disable, "
+ "pi.package_tep_name, pi.package_zip_mount_file, pi.external_path, "
+ "pi.package_support_mode";
+ static const char query_author[] =
+ ", pi.author_name, pi.author_email, pi.author_href";
+ static const char query_label[] =
+ ", COALESCE("
+ "(SELECT package_label FROM package_localized_info WHERE pi.package=package AND package_locale=?), "
+ "(SELECT package_label FROM package_localized_info WHERE pi.package=package AND package_locale='No Locale'))";
+ static const char query_icon[] =
+ ", COALESCE("
+ "(SELECT package_icon FROM package_localized_info WHERE pi.package=package AND package_locale=?), "
+ "(SELECT package_icon FROM package_localized_info WHERE pi.package=package AND package_locale='No Locale'))";
+ static const char query_description[] =
+ ", COALESCE("
+ "(SELECT package_description FROM package_localized_info WHERE pi.package=package AND package_locale=?), "
+ "(SELECT package_description FROM package_localized_info WHERE pi.package=package AND package_locale='No Locale'))";
+ static const char query_from_clause[] = " FROM package_info as pi";
+ int ret = PMINFO_R_ERROR;
+ int idx = 0;
+ int query_len = 0;
+ char *dbpath;
+ char *tmp_record = NULL;
+ char *constraints = NULL;
+ char query[MAX_QUERY_LEN] = { '\0' };
+ package_x *info = NULL;
+ author_x *author = NULL;
+ GList *bind_params = NULL;
+ sqlite3 *db;
sqlite3_stmt *stmt;
- int idx;
- label_x *info;
+ pkgmgrinfo_filter_x *tmp_filter = NULL;
+ bool is_check_storage = true;
- query = sqlite3_mprintf(query_raw, pkgid, locale, DEFAULT_LOCALE);
- if (query == NULL) {
- LOGE("out of memory");
+ dbpath = getUserPkgParserDBPathUID(uid);
+ if (dbpath == NULL)
return PMINFO_R_ERROR;
- }
- ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query),
- &stmt, NULL);
- sqlite3_free(query);
+ ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY);
if (ret != SQLITE_OK) {
- LOGE("prepare failed: %s", sqlite3_errmsg(GET_DB(manifest_db)));
+ _LOGD("failed to open db: %d", ret);
+ free(dbpath);
return PMINFO_R_ERROR;
}
+ free(dbpath);
- while (sqlite3_step(stmt) == SQLITE_ROW) {
- info = calloc(1, sizeof(label_x));
- if (info == NULL) {
- LOGE("out of memory");
- sqlite3_finalize(stmt);
- if (*label) {
- LISTHEAD(*label, info);
- *label = info;
- }
+ 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;
}
- idx = 0;
- _save_column_str(stmt, idx++, &info->text);
- _save_column_str(stmt, idx++, &info->lang);
- LISTADD(*label, info);
}
- if (*label) {
- LISTHEAD(*label, info);
- *label = info;
+ is_check_storage = __check_package_storage_status(tmp_filter);
+
+ query_len = strlen(query_raw);
+ snprintf(query, MAX_QUERY_LEN - 1, "%s", query_raw);
+ if (flag & PMINFO_PKGINFO_GET_AUTHOR) {
+ strncat(query, query_author, MAX_QUERY_LEN - query_len - 1);
+ query_len += strlen(query_author);
+ }
+ if (flag & PMINFO_PKGINFO_GET_LABEL) {
+ strncat(query, query_label, MAX_QUERY_LEN - query_len - 1);
+ query_len += strlen(query_label);
+ bind_params = g_list_append(bind_params, strdup(locale));
+ }
+ if (flag & PMINFO_PKGINFO_GET_ICON) {
+ strncat(query, query_icon, MAX_QUERY_LEN - query_len - 1);
+ query_len += strlen(query_icon);
+ bind_params = g_list_append(bind_params, strdup(locale));
+ }
+ if (flag & PMINFO_PKGINFO_GET_DESCRIPTION) {
+ strncat(query, query_description, MAX_QUERY_LEN - query_len - 1);
+ query_len += strlen(query_description);
+ bind_params = g_list_append(bind_params, strdup(locale));
}
- sqlite3_finalize(stmt);
+ strncat(query, query_from_clause, MAX_QUERY_LEN - query_len - 1);
+ query_len += strlen(query_from_clause);
- return PMINFO_R_OK;
-}
+ ret = _get_filtered_query(tmp_filter, locale, uid, &constraints, &bind_params);
+ if (ret != PMINFO_R_OK) {
+ LOGE("Failed to get WHERE clause");
+ goto catch;
+ }
-static int _pkginfo_get_icon(const char *pkgid, const char *locale,
- icon_x **icon)
-{
- 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;
+ if (constraints)
+ strncat(query, constraints, MAX_QUERY_LEN - query_len - 1);
- 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);
+ if (ret != SQLITE_OK) {
+ LOGE("prepare failed: %s", sqlite3_errmsg(db));
+ ret = PMINFO_R_ERROR;
+ goto catch;
}
- ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query),
- &stmt, NULL);
- sqlite3_free(query);
+ ret = __bind_params(stmt, bind_params);
if (ret != SQLITE_OK) {
- LOGE("prepare failed: %s", sqlite3_errmsg(GET_DB(manifest_db)));
- return PMINFO_R_ERROR;
+ LOGE("Failed to bind parameters");
+ goto catch;
}
while (sqlite3_step(stmt) == SQLITE_ROW) {
- info = calloc(1, sizeof(icon_x));
+ info = calloc(1, sizeof(package_x));
if (info == NULL) {
LOGE("out of memory");
- sqlite3_finalize(stmt);
- if (*icon) {
- LISTHEAD(*icon, info);
- *icon = info;
- }
- return PMINFO_R_ERROR;
+ ret = PMINFO_R_ERROR;
+ goto catch;
}
idx = 0;
- _save_column_str(stmt, idx++, &info->text);
- _save_column_str(stmt, idx++, &info->lang);
- LISTADD(*icon, info);
- }
+ _save_column_str(stmt, idx++, &info->package);
+ if (g_hash_table_contains(packages,
+ (gconstpointer)info->package)) {
+ free(info->package);
+ free(info);
+ info = NULL;
+ continue;
+ }
+ _save_column_str(stmt, idx++, &info->version);
+ _save_column_str(stmt, idx++, &info->installlocation);
+ _save_column_str(stmt, idx++, &info->removable);
+ _save_column_str(stmt, idx++, &info->preload);
+ _save_column_str(stmt, idx++, &info->readonly);
+ _save_column_str(stmt, idx++, &info->update);
+ _save_column_str(stmt, idx++, &info->appsetting);
+ _save_column_str(stmt, idx++, &info->system);
+ _save_column_str(stmt, idx++, &info->type);
+ _save_column_str(stmt, idx++, &info->package_size);
+ _save_column_str(stmt, idx++, &info->installed_time);
+ _save_column_str(stmt, idx++, &info->installed_storage);
+ _save_column_str(stmt, idx++, &info->storeclient_id);
+ _save_column_str(stmt, idx++, &info->mainapp_id);
+ _save_column_str(stmt, idx++, &info->package_url);
+ _save_column_str(stmt, idx++, &info->root_path);
+ _save_column_str(stmt, idx++, &info->csc_path);
+ _save_column_str(stmt, idx++, &info->nodisplay_setting);
+ _save_column_str(stmt, idx++, &info->api_version);
+ _save_column_str(stmt, idx++, &info->support_disable);
+ _save_column_str(stmt, idx++, &info->tep_name);
+ _save_column_str(stmt, idx++, &info->zip_mount_file);
+ _save_column_str(stmt, idx++, &info->external_path);
+ _save_column_str(stmt, idx++, &info->support_mode);
+ info->for_all_users =
+ strdup((uid != GLOBAL_USER) ? "false" : "true");
+
+ if (flag & PMINFO_PKGINFO_GET_AUTHOR) {
+ /* TODO : author should be retrieved at package_localized_info */
+ author = calloc(1, sizeof(author_x));
+ if (author == NULL) {
+ ret = PMINFO_R_ERROR;
+ goto catch;
+ }
+ _save_column_str(stmt, idx++, &author->text);
+ _save_column_str(stmt, idx++, &author->email);
+ _save_column_str(stmt, idx++, &author->href);
+ info->author = g_list_append(info->author, author);
+ }
+
+ if (flag & PMINFO_PKGINFO_GET_LABEL) {
+ tmp_record = NULL;
+ _save_column_str(stmt, idx++, &tmp_record);
+
+ if (_add_label_info_into_list(locale, tmp_record, &info->label)) {
+ ret = PMINFO_R_ERROR;
+ goto catch;
+ }
+ }
- if (*icon) {
- LISTHEAD(*icon, info);
- *icon = info;
+ if (flag & PMINFO_PKGINFO_GET_ICON) {
+ tmp_record = NULL;
+ _save_column_str(stmt, idx++, &tmp_record);
+ if (_add_icon_info_into_list(locale, tmp_record, &info->icon)) {
+ ret = PMINFO_R_ERROR;
+ goto catch;
+ }
+ }
+
+ if (flag & PMINFO_PKGINFO_GET_DESCRIPTION) {
+ tmp_record = NULL;
+ _save_column_str(stmt, idx++, &tmp_record);
+ if (_pkginfo_add_description_info_into_list(locale, tmp_record,
+ &info->description)) {
+ ret = PMINFO_R_ERROR;
+ goto catch;
+ }
+ }
+
+ if (flag & PMINFO_PKGINFO_GET_PRIVILEGE) {
+ if (_pkginfo_get_privilege(db, info->package,
+ &info->privileges)) {
+ ret = PMINFO_R_ERROR;
+ goto catch;
+ }
+ }
+
+ if (is_check_storage &&
+ __pkginfo_check_installed_storage(info) != PMINFO_R_OK) {
+ ret = PMINFO_R_ERROR;
+ pkgmgrinfo_basic_free_package(info);
+ info = NULL;
+ continue;
+ }
+
+ g_hash_table_insert(packages, (gpointer)info->package,
+ (gpointer)info);
}
+ ret = PMINFO_R_OK;
+
+catch:
+ if (constraints)
+ free(constraints);
+
+ if (ret != PMINFO_R_OK && info != NULL)
+ pkgmgrinfo_basic_free_package(info);
+
+ if (filter == NULL)
+ pkgmgrinfo_pkginfo_filter_destroy(tmp_filter);
+
+ g_list_free_full(bind_params, free);
+ sqlite3_close_v2(db);
sqlite3_finalize(stmt);
- return PMINFO_R_OK;
+ return ret;
}
-static int _pkginfo_get_description(const char *pkgid, const char *locale,
- description_x **description)
+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 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;
+ char *locale;
+ package_x *pkg;
+ pkgmgr_pkginfo_x info;
+ pkgmgrinfo_filter_x *tmp_filter = NULL;
+ GHashTable *list;
+ GHashTableIter iter;
+ gpointer value;
- query = sqlite3_mprintf(query_raw, pkgid, locale, DEFAULT_LOCALE);
- if (query == NULL) {
- LOGE("out of memory");
+ locale = _get_system_locale();
+ if (locale == NULL)
return PMINFO_R_ERROR;
- }
- ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query),
- &stmt, NULL);
- sqlite3_free(query);
- if (ret != SQLITE_OK) {
- LOGE("prepare failed: %s", sqlite3_errmsg(GET_DB(manifest_db)));
+ list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
+ __free_packages);
+ if (list == NULL) {
+ free(locale);
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);
- if (*description) {
- LISTHEAD(*description, info);
- *description = info;
- }
+ if (filter != NULL) {
+ tmp_filter = (pkgmgrinfo_filter_x *)filter;
+ } else {
+ ret = pkgmgrinfo_pkginfo_filter_create((void *)&tmp_filter);
+ if (ret != PMINFO_R_OK) {
+ _LOGE("Failed to create filter");
+ g_hash_table_destroy(list);
return PMINFO_R_ERROR;
}
- idx = 0;
- _save_column_str(stmt, idx++, &info->text);
- _save_column_str(stmt, idx++, &info->lang);
- LISTADD(*description, info);
}
- if (*description) {
- LISTHEAD(*description, info);
- *description = info;
+ if (__check_disable_filter_exist(tmp_filter) == false)
+ pkgmgrinfo_pkginfo_filter_add_bool(tmp_filter,
+ PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, false);
+
+ ret = _pkginfo_get_packages(uid, locale, tmp_filter, flag, list);
+ if (ret == PMINFO_R_OK && uid != GLOBAL_USER)
+ ret = _pkginfo_get_packages(GLOBAL_USER, locale, tmp_filter,
+ flag, list);
+
+ if (ret != PMINFO_R_OK) {
+ g_hash_table_destroy(list);
+ free(locale);
+ if (filter == NULL)
+ pkgmgrinfo_pkginfo_filter_destroy(tmp_filter);
+ return PMINFO_R_ERROR;
+ }
+
+ 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;
}
- sqlite3_finalize(stmt);
+ g_hash_table_destroy(list);
+ free(locale);
+
+ if (filter == NULL)
+ pkgmgrinfo_pkginfo_filter_destroy(tmp_filter);
return PMINFO_R_OK;
}
-static int _pkginfo_get_privilege(const char *pkgid, privileges_x **privileges)
+static int _pkgmgrinfo_get_pkginfo(const char *pkgid, uid_t uid,
+ pkgmgrinfo_pkginfo_filter_h filter, 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;
- privileges_x *p;
- privilege_x *info;
+ char *locale;
+ GHashTable *list;
+ pkgmgr_pkginfo_x *info;
- /* privilege list should stored in privileges_x... */
- p = calloc(1, sizeof(privileges_x));
- if (p == NULL) {
- LOGE("out of memory");
- return PMINFO_R_ERROR;
+ if (pkgid == NULL || filter == NULL || handle == NULL) {
+ LOGE("invalid parameter");
+ return PMINFO_R_EINVAL;
}
- *privileges = p;
- query = sqlite3_mprintf(query_raw, pkgid);
- if (query == NULL) {
- LOGE("out of memory");
- free(p);
+ locale = _get_system_locale();
+ if (locale == NULL)
return PMINFO_R_ERROR;
- }
- ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query),
- &stmt, NULL);
- sqlite3_free(query);
- if (ret != SQLITE_OK) {
- LOGE("prepare failed: %s", sqlite3_errmsg(GET_DB(manifest_db)));
- free(p);
+ list = g_hash_table_new(g_str_hash, g_str_equal);
+ if (list == NULL) {
+ free(locale);
return PMINFO_R_ERROR;
}
- while (sqlite3_step(stmt) == SQLITE_ROW) {
- info = calloc(1, sizeof(privilege_x));
- if (info == NULL) {
- LOGE("out of memory");
- sqlite3_finalize(stmt);
- if (p->privilege) {
- LISTHEAD(p->privilege, info);
- p->privilege = info;
- }
- return PMINFO_R_ERROR;
- }
- _save_column_str(stmt, 0, &info->text);
- LISTADD(p->privilege, 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);
+
+ 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;
}
- if (p->privilege) {
- LISTHEAD(p->privilege, info);
- p->privilege = info;
- }
+ info->uid = uid;
+ info->pkg_info = (package_x *)g_hash_table_lookup(list, pkgid);
+ info->locale = locale;
- sqlite3_finalize(stmt);
+ /* just free list only */
+ g_hash_table_destroy(list);
- return PMINFO_R_OK;
+ *handle = info;
+
+ return ret;
}
-static char *_get_filtered_query(const char *query_raw,
- pkgmgrinfo_filter_x *filter)
+API int pkgmgrinfo_pkginfo_get_usr_pkginfo(const char *pkgid, uid_t uid,
+ pkgmgrinfo_pkginfo_h *handle)
{
- char buf[MAX_QUERY_LEN] = { 0, };
- char *condition;
- size_t len;
- GSList *list;
- GSList *head = NULL;
+ int ret;
+ pkgmgrinfo_pkginfo_filter_h filter;
- if (filter)
- head = filter->list;
+ if (pkgid == NULL || handle == NULL) {
+ LOGE("invalid parameter");
+ return PMINFO_R_EINVAL;
+ }
- 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;
+ 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;
+ }
+
+ 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;
}
- return strdup(buf);
+ ret = _pkgmgrinfo_get_pkginfo(pkgid, uid, filter, handle);
+ pkgmgrinfo_pkginfo_filter_destroy(filter);
+
+ return ret;
}
-static int _pkginfo_get_pkg(const char *pkgid, const char *locale,
- pkgmgr_pkginfo_x **pkginfo)
+API int pkgmgrinfo_pkginfo_get_pkginfo(const char *pkgid,
+ pkgmgrinfo_pkginfo_h *handle)
+{
+ return pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, _getuid(), handle);
+}
+
+API int pkgmgrinfo_pkginfo_get_usr_disabled_pkginfo(const char *pkgid,
+ uid_t uid, pkgmgrinfo_pkginfo_h *handle)
{
- static const char query_raw[] =
- "SELECT for_all_users, 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 "
- "FROM package_info WHERE package=%Q";
int ret;
- char *query;
- sqlite3_stmt *stmt;
- int idx;
+ char *locale;
+ GHashTable *list;
+ pkgmgrinfo_pkginfo_filter_h filter;
pkgmgr_pkginfo_x *info;
- package_x *pkg;
- 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(GET_DB(manifest_db), query, strlen(query),
- &stmt, NULL);
- sqlite3_free(query);
- if (ret != SQLITE_OK) {
- LOGE("prepare failed: %s", sqlite3_errmsg(GET_DB(manifest_db)));
+ locale = _get_system_locale();
+ if (locale == NULL)
return PMINFO_R_ERROR;
- }
- ret = sqlite3_step(stmt);
- if (ret == SQLITE_DONE) {
- LOGE("cannot find pkg");
- sqlite3_finalize(stmt);
- return PMINFO_R_ENOENT;
- } else if (ret != SQLITE_ROW) {
- LOGE("step failed: %s", sqlite3_errmsg(GET_DB(manifest_db)));
- sqlite3_finalize(stmt);
- return PMINFO_R_ERROR;
+ ret = pkgmgrinfo_pkginfo_filter_create(&filter);
+ if (ret != PMINFO_R_OK) {
+ free(locale);
+ return ret;
}
- pkg = calloc(1, sizeof(package_x));
- if (pkg == NULL) {
- LOGE("out of memory");
- 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);
+ free(locale);
return PMINFO_R_ERROR;
}
- idx = 0;
- _save_column_str(stmt, idx++, &pkg->for_all_users);
- _save_column_str(stmt, idx++, &pkg->package);
- _save_column_str(stmt, idx++, &pkg->version);
- _save_column_str(stmt, idx++, &pkg->installlocation);
- _save_column_str(stmt, idx++, &pkg->removable);
- _save_column_str(stmt, idx++, &pkg->preload);
- _save_column_str(stmt, idx++, &pkg->readonly);
- _save_column_str(stmt, idx++, &pkg->update);
- _save_column_str(stmt, idx++, &pkg->appsetting);
- _save_column_str(stmt, idx++, &pkg->system);
- _save_column_str(stmt, idx++, &pkg->type);
- _save_column_str(stmt, idx++, &pkg->package_size);
- _save_column_str(stmt, idx++, &pkg->installed_time);
- _save_column_str(stmt, idx++, &pkg->installed_storage);
- _save_column_str(stmt, idx++, &pkg->storeclient_id);
- _save_column_str(stmt, idx++, &pkg->mainapp_id);
- _save_column_str(stmt, idx++, &pkg->package_url);
- _save_column_str(stmt, idx++, &pkg->root_path);
- _save_column_str(stmt, idx++, &pkg->csc_path);
- _save_column_str(stmt, idx++, &pkg->nodisplay_setting);
- _save_column_str(stmt, idx++, &pkg->api_version);
- if (_pkginfo_get_author(pkg->package, &pkg->author)) {
- pkgmgrinfo_basic_free_package(pkg);
- sqlite3_finalize(stmt);
+ ret = pkgmgrinfo_pkginfo_filter_add_bool(filter,
+ PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, true);
+ if (ret != PMINFO_R_OK) {
+ pkgmgrinfo_pkginfo_filter_destroy(filter);
+ free(locale);
return PMINFO_R_ERROR;
}
- if (_pkginfo_get_label(pkg->package, locale, &pkg->label)) {
- pkgmgrinfo_basic_free_package(pkg);
- sqlite3_finalize(stmt);
+ list = g_hash_table_new(g_str_hash, g_str_equal);
+ if (list == NULL) {
+ pkgmgrinfo_pkginfo_filter_destroy(filter);
+ free(locale);
return PMINFO_R_ERROR;
}
- if (_pkginfo_get_icon(pkg->package, locale, &pkg->icon)) {
- pkgmgrinfo_basic_free_package(pkg);
- sqlite3_finalize(stmt);
- return PMINFO_R_ERROR;
- }
+ 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);
- if (_pkginfo_get_description(pkg->package, locale,
- &pkg->description)) {
- pkgmgrinfo_basic_free_package(pkg);
- sqlite3_finalize(stmt);
- return PMINFO_R_ERROR;
+ pkgmgrinfo_pkginfo_filter_destroy(filter);
+ if (ret != PMINFO_R_OK) {
+ g_hash_table_destroy(list);
+ free(locale);
+ return ret;
}
- if (_pkginfo_get_privilege(pkg->package, &pkg->privileges)) {
- pkgmgrinfo_basic_free_package(pkg);
- sqlite3_finalize(stmt);
- return PMINFO_R_ERROR;
+ if (!g_hash_table_size(list)) {
+ _LOGI("disabled 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");
- pkgmgrinfo_basic_free_package(pkg);
- sqlite3_finalize(stmt);
+ _LOGE("out of memory");
+ g_hash_table_destroy(list);
+ free(locale);
return PMINFO_R_ERROR;
}
- info->pkg_info = pkg;
- *pkginfo = info;
+ info->uid = uid;
+ info->pkg_info = (package_x *)g_hash_table_lookup(list, pkgid);
+ info->locale = locale;
- sqlite3_finalize(stmt);
+ /* just free list only */
+ g_hash_table_destroy(list);
- return PMINFO_R_OK;
+ *handle = info;
+
+ return ret;
}
-API int pkgmgrinfo_pkginfo_get_usr_pkginfo(const char *pkgid, uid_t uid,
+API int pkgmgrinfo_pkginfo_get_usr_all_pkginfo(const char *pkgid, uid_t uid,
pkgmgrinfo_pkginfo_h *handle)
{
- pkgmgr_pkginfo_x *pkginfo = NULL;
- char *locale;
+
+ int ret;
+ pkgmgrinfo_pkginfo_filter_h filter;
if (pkgid == NULL || handle == NULL) {
LOGE("invalid parameter");
return PMINFO_R_EINVAL;
}
- if (__open_manifest_db(uid) < 0)
- return PMINFO_R_ERROR;
+ 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;
+ }
- locale = _get_system_locale();
- if (locale == NULL) {
- __close_manifest_db();
+ 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;
}
- if (_pkginfo_get_pkg(pkgid, locale, &pkginfo)) {
- LOGE("failed to get pkginfo of %s for user %d", pkgid, uid);
- free(locale);
- __close_manifest_db();
+ ret = _pkgmgrinfo_get_pkginfo(pkgid, uid, filter, handle);
+ pkgmgrinfo_pkginfo_filter_destroy(filter);
+
+ return ret;
+}
+
+API int pkgmgrinfo_pkginfo_get_disabled_pkginfo(const char *pkgid,
+ pkgmgrinfo_pkginfo_h *handle)
+{
+ return pkgmgrinfo_pkginfo_get_usr_disabled_pkginfo(pkgid, _getuid(),
+ handle);
+}
+
+API int pkgmgrinfo_pkginfo_get_all_pkginfo(const char *pkgid,
+ pkgmgrinfo_pkginfo_h *handle)
+{
+ return pkgmgrinfo_pkginfo_get_usr_all_pkginfo(pkgid, _getuid(), handle);
+}
+
+API int pkgmgrinfo_pkginfo_get_usr_list_full(pkgmgrinfo_pkg_list_cb pkg_list_cb,
+ int flag, void *user_data, uid_t uid)
+{
+ int ret;
+ pkgmgrinfo_pkginfo_filter_h filter;
+
+ if (pkg_list_cb == NULL) {
+ LOGE("invalid parameter");
+ return PMINFO_R_EINVAL;
+ }
+
+ /* create an empty filter */
+ ret = pkgmgrinfo_pkginfo_filter_create(&filter);
+ if (ret != PMINFO_R_OK)
+ return ret;
+
+ ret = _pkginfo_get_filtered_foreach_pkginfo(uid, filter, flag,
+ pkg_list_cb, user_data);
+
+ pkgmgrinfo_pkginfo_filter_destroy(filter);
+
+ return ret;
+}
+
+API int pkgmgrinfo_pkginfo_get_list_full(pkgmgrinfo_pkg_list_cb pkg_list_cb,
+ int flag, void *user_data)
+{
+ return pkgmgrinfo_pkginfo_get_usr_list_full(pkg_list_cb, flag,
+ user_data, _getuid());
+}
+
+API int pkgmgrinfo_pkginfo_get_usr_list(pkgmgrinfo_pkg_list_cb pkg_list_cb,
+ void *user_data, uid_t uid)
+{
+ int ret;
+ pkgmgrinfo_pkginfo_filter_h filter;
+
+ if (pkg_list_cb == NULL) {
+ LOGE("invalid parameter");
+ return PMINFO_R_EINVAL;
+ }
+
+ /* create an empty filter */
+ ret = pkgmgrinfo_pkginfo_filter_create(&filter);
+ if (ret != PMINFO_R_OK)
+ return ret;
+
+ ret = _pkginfo_get_filtered_foreach_pkginfo(uid, filter,
+ PMINFO_PKGINFO_GET_ALL, pkg_list_cb, user_data);
+
+ pkgmgrinfo_pkginfo_filter_destroy(filter);
+
+ return ret;
+}
+
+API int pkgmgrinfo_pkginfo_get_list(pkgmgrinfo_pkg_list_cb pkg_list_cb,
+ 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 (pkg_list_cb == NULL) {
+ LOGE("invalid parameter");
+ return PMINFO_R_EINVAL;
+ }
+
+ ret = pkgmgrinfo_pkginfo_filter_create(&filter);
+ if (ret != PMINFO_R_OK)
+ 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;
}
- pkginfo->uid = uid;
- pkginfo->locale = locale;
- *handle = pkginfo;
+ ret = _pkginfo_get_filtered_foreach_pkginfo(uid, filter,
+ PMINFO_PKGINFO_GET_ALL, pkg_list_cb, user_data);
- __close_manifest_db();
+ pkgmgrinfo_pkginfo_filter_destroy(filter);
- return PMINFO_R_OK;
+ 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;
}
-API int pkgmgrinfo_pkginfo_get_install_location(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_install_location *location)
+API int pkgmgrinfo_pkginfo_get_api_version(pkgmgrinfo_pkginfo_h handle, char **api_version)
{
- 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(api_version == 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->api_version == NULL)
+ *api_version = "";
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)
+API int pkgmgrinfo_pkginfo_get_zip_mount_file(pkgmgrinfo_pkginfo_h handle, char **zip_mount_file)
{
- 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;
+ 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(zip_mount_file == 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)
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;
- }
- }
+ if (info->pkg_info->zip_mount_file == NULL)
+ *zip_mount_file = "";
+ else
+ *zip_mount_file = (char *)info->pkg_info->zip_mount_file;
- 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;
- }
- }
+ return PMINFO_R_OK;
+}
- 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;
- }
- }
+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/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;
- }
- }
+ 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");
- 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;
- }
- }
+ 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;
}
API int pkgmgrinfo_pkginfo_get_icon(pkgmgrinfo_pkginfo_h handle, char **icon)
{
- char *locale;
icon_x *ptr;
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 || info->pkg_info->icon == NULL)
+ return PMINFO_R_ERROR;
- for (ptr = info->pkg_info->icon; ptr != NULL; ptr = ptr->next) {
- if (ptr->lang == NULL)
- continue;
+ ptr = (icon_x *)info->pkg_info->icon->data;
+ if (ptr == NULL)
+ return PMINFO_R_ERROR;
- if (strcmp(ptr->lang, locale) == 0) {
- *icon = (char *)ptr->text;
- if (strcasecmp(*icon, "(null)") == 0) {
- locale = DEFAULT_LOCALE;
- continue;
- } else {
- return PMINFO_R_OK;
- }
- } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
- *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)
{
- char *locale;
label_x *ptr;
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 (ptr = info->pkg_info->label; ptr != NULL; ptr = ptr->next) {
- if (ptr->lang == NULL)
- continue;
+ ptr = (label_x *)info->pkg_info->label->data;
+ if (ptr == NULL)
+ return PMINFO_R_ERROR;
- if (strcmp(ptr->lang, locale) == 0) {
- *label = (char *)ptr->text;
- if (strcasecmp(*label, "(null)") == 0) {
- locale = DEFAULT_LOCALE;
- continue;
- } else {
- return PMINFO_R_OK;
- }
- } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
- *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)
{
- char *locale;
description_x *ptr;
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 (ptr = info->pkg_info->description; ptr != NULL; ptr = ptr->next) {
- if (ptr->lang == NULL)
- continue;
+ ptr = (description_x *)info->pkg_info->description->data;
+ if (ptr == NULL)
+ return PMINFO_R_ERROR;
- if (strcmp(ptr->lang, locale) == 0) {
- *description = (char *)ptr->text;
- if (strcasecmp(*description, PKGMGR_PARSER_EMPTY_STR) == 0) {
- locale = DEFAULT_LOCALE;
- continue;
- } else {
- return PMINFO_R_OK;
- }
- } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
- *description = (char *)ptr->text;
- return PMINFO_R_OK;
- }
- }
+ if (ptr->text == NULL)
+ *description = "";
+ else
+ *description = (char *)ptr->text;
- return PMINFO_R_ERROR;
+ return PMINFO_R_OK;
}
API int pkgmgrinfo_pkginfo_get_author_name(pkgmgrinfo_pkginfo_h handle, char **author_name)
{
- char *locale;
- author_x *ptr;
pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
+ author_x *author;
retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
retvm_if(author_name == 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->author == NULL)
+ return PMINFO_R_ERROR;
- for (ptr = info->pkg_info->author; ptr != NULL; ptr = ptr->next) {
- if (ptr->lang == NULL)
- continue;
+ author = (author_x *)info->pkg_info->author->data;
+ if (author == NULL)
+ return PMINFO_R_ERROR;
- if (strcmp(ptr->lang, locale) == 0) {
- *author_name = (char *)ptr->text;
- if (strcasecmp(*author_name, PKGMGR_PARSER_EMPTY_STR) == 0) {
- locale = DEFAULT_LOCALE;
- continue;
- } else {
- return PMINFO_R_OK;
- }
- } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
- *author_name = (char *)ptr->text;
- return PMINFO_R_OK;
- }
- }
+ if (author->text == NULL)
+ *author_name = "";
+ else
+ *author_name = (char *)author->text;
- return PMINFO_R_ERROR;
+ return PMINFO_R_OK;
}
API int pkgmgrinfo_pkginfo_get_author_email(pkgmgrinfo_pkginfo_h handle, char **author_email)
{
pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
+ author_x *author;
retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
retvm_if(author_email == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
- if (info->pkg_info == NULL || info->pkg_info->author == NULL ||
- info->pkg_info->author->email == NULL)
+ if (info->pkg_info == NULL || info->pkg_info->author == NULL)
+ return PMINFO_R_ERROR;
+
+ author = (author_x *)info->pkg_info->author->data;
+ if (author == NULL)
return PMINFO_R_ERROR;
- *author_email = (char *)info->pkg_info->author->email;
+ if (author->email == NULL)
+ *author_email = "";
+ else
+ *author_email = (char *)author->email;
return PMINFO_R_OK;
}
API int pkgmgrinfo_pkginfo_get_author_href(pkgmgrinfo_pkginfo_h handle, char **author_href)
{
pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
+ author_x *author;
retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
retvm_if(author_href == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
- if (info->pkg_info == NULL || info->pkg_info->author == NULL ||
- info->pkg_info->author->href == NULL)
+ if (info->pkg_info == NULL || info->pkg_info->author == NULL)
+ return PMINFO_R_ERROR;
+
+ author = (author_x *)info->pkg_info->author->data;
+ if (author == NULL)
return PMINFO_R_ERROR;
- *author_href = (char *)info->pkg_info->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
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)
- return PMINFO_R_ERROR;
-
- *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();
+ if (info->pkg_info == NULL)
return PMINFO_R_ERROR;
- }
- xmlFreeTextReader(reader);
- xmlCleanupParser();
+ 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_root_path(pkgmgrinfo_pkginfo_h handle, char **path)
{
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");
- if (info->pkg_info == NULL || info->pkg_info->csc_path == NULL)
+ if (info->pkg_info == NULL)
return PMINFO_R_ERROR;
- *path = (char *)info->pkg_info->csc_path;
+ 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_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");
+
+ 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");
}
API int pkgmgrinfo_pkginfo_is_removable(pkgmgrinfo_pkginfo_h handle, bool *removable)
{
- char *val;
pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
if (info->pkg_info == NULL || info->pkg_info->removable == NULL)
return PMINFO_R_ERROR;
- val = (char *)info->pkg_info->removable;
- if (strcasecmp(val, "true") == 0)
- *removable = 1;
- else if (strcasecmp(val, "false") == 0)
- *removable = 0;
- else
- *removable = 1;
+ *removable = _get_bool_value(info->pkg_info->removable);
return PMINFO_R_OK;
}
API int pkgmgrinfo_pkginfo_is_preload(pkgmgrinfo_pkginfo_h handle, bool *preload)
{
- char *val;
pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
if (info->pkg_info == NULL || info->pkg_info->preload == NULL)
return PMINFO_R_ERROR;
- val = (char *)info->pkg_info->preload;
- if (strcasecmp(val, "true") == 0)
- *preload = 1;
- else if (strcasecmp(val, "false") == 0)
- *preload = 0;
- else
- *preload = 0;
+ *preload = _get_bool_value(info->pkg_info->preload);
return PMINFO_R_OK;
}
API int pkgmgrinfo_pkginfo_is_system(pkgmgrinfo_pkginfo_h handle, bool *system)
{
- char *val;
pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
if (info->pkg_info == NULL || info->pkg_info->system == NULL)
return PMINFO_R_ERROR;
- val = (char *)info->pkg_info->system;
- if (strcasecmp(val, "true") == 0)
- *system = 1;
- else if (strcasecmp(val, "false") == 0)
- *system = 0;
- else
- *system = 0;
+ *system = _get_bool_value(info->pkg_info->system);
return PMINFO_R_OK;
}
API int pkgmgrinfo_pkginfo_is_readonly(pkgmgrinfo_pkginfo_h handle, bool *readonly)
{
- char *val;
pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
if (info->pkg_info == NULL || info->pkg_info->readonly == NULL)
return PMINFO_R_ERROR;
- val = (char *)info->pkg_info->readonly;
- if (strcasecmp(val, "true") == 0)
- *readonly = 1;
- else if (strcasecmp(val, "false") == 0)
- *readonly = 0;
- else
- *readonly = 0;
+ *readonly = _get_bool_value(info->pkg_info->readonly);
return PMINFO_R_OK;
}
API int pkgmgrinfo_pkginfo_is_update(pkgmgrinfo_pkginfo_h handle, bool *update)
{
- char *val;
pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
if (info->pkg_info == NULL || info->pkg_info->update == NULL)
return PMINFO_R_ERROR;
- val = (char *)info->pkg_info->update;
- if (strcasecmp(val, "true") == 0)
- *update = 1;
- else if (strcasecmp(val, "false") == 0)
- *update = 0;
- else
- *update = 1;
+ *update = _get_bool_value(info->pkg_info->update);
return PMINFO_R_OK;
}
-API int pkgmgrinfo_pkginfo_is_for_all_users(pkgmgrinfo_pkginfo_h handle, bool *for_all_users)
+API int pkgmgrinfo_pkginfo_is_support_disable(pkgmgrinfo_pkginfo_h handle, bool *support_disable)
+{
+ pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
+
+ retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
+ retvm_if(support_disable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
+
+ if (info->pkg_info == NULL || info->pkg_info->support_disable == NULL)
+ return PMINFO_R_ERROR;
+
+ *support_disable = _get_bool_value(info->pkg_info->support_disable);
+
+ return PMINFO_R_OK;
+}
+
+API int pkgmgrinfo_pkginfo_is_global(pkgmgrinfo_pkginfo_h handle, bool *global)
{
- char *val;
pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
- retvm_if(for_all_users == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
+ retvm_if(global == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
if (info->pkg_info == NULL || info->pkg_info->for_all_users == NULL)
return PMINFO_R_ERROR;
- val = (char *)info->pkg_info->for_all_users;
- if (strcasecmp(val, "1") == 0)
- *for_all_users = 1;
- else if (strcasecmp(val, "0") == 0)
- *for_all_users = 0;
- else
- *for_all_users = 1;
+ *global = _get_bool_value(info->pkg_info->for_all_users);
return PMINFO_R_OK;
}
+API int pkgmgrinfo_pkginfo_is_for_all_users(pkgmgrinfo_pkginfo_h handle, bool *for_all_users)
+{
+ return pkgmgrinfo_pkginfo_is_global(handle, for_all_users);
+}
API int pkgmgrinfo_pkginfo_destroy_pkginfo(pkgmgrinfo_pkginfo_h 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;
g_slist_free(filter->list);
}
+ g_slist_free_full(filter->list_metadata, __destroy_metadata_node);
+
free(filter);
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);
API int pkgmgrinfo_pkginfo_usr_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count, uid_t uid)
{
- retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
- retvm_if(count == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
- char *locale = NULL;
- char *condition = NULL;
- char *error_message = NULL;
- char query[MAX_QUERY_LEN] = {'\0'};
- char where[MAX_QUERY_LEN] = {'\0'};
- GSList *list;
- int ret = 0;
+ int ret;
+ char *locale;
+ GHashTable *list = NULL;
+
+ if (handle == NULL || count == NULL) {
+ _LOGE("invalid parameter");
+ return PMINFO_R_EINVAL;
+ }
- pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
- filter->uid = uid;
- /*Get current locale*/
locale = _get_system_locale();
- if (locale == NULL) {
- _LOGE("manifest locale is NULL\n");
+ if (locale == NULL)
return PMINFO_R_ERROR;
- }
- ret = __open_manifest_db(uid);
- if (ret == -1) {
- _LOGE("Fail to open manifest DB\n");
+ list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
+ __free_packages);
+ if (list == NULL) {
free(locale);
return PMINFO_R_ERROR;
}
- /*Start constructing query*/
- snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_COUNT_PACKAGE, locale);
-
- /*Get where clause*/
- for (list = filter->list; list; list = g_slist_next(list)) {
- __get_filter_condition(list->data, &condition);
- if (condition) {
- strncat(where, condition, sizeof(where) - strlen(where) -1);
- where[sizeof(where) - 1] = '\0';
- free(condition);
- condition = NULL;
- }
- if (g_slist_next(list)) {
- strncat(where, " and ", sizeof(where) - strlen(where) - 1);
- where[sizeof(where) - 1] = '\0';
+ 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) {
+ free(locale);
+ g_hash_table_destroy(list);
+ return PMINFO_R_ERROR;
}
}
- if (strlen(where) > 0) {
- strncat(query, where, sizeof(query) - strlen(query) - 1);
- query[sizeof(query) - 1] = '\0';
- }
- /*Execute Query*/
- if (SQLITE_OK !=
- sqlite3_exec(GET_DB(manifest_db), query, __count_cb, (void *)count, &error_message)) {
- _LOGE("Don't execute query = %s error message = %s\n", query,
- error_message);
- sqlite3_free(error_message);
- ret = PMINFO_R_ERROR;
- *count = 0;
- goto err;
- }
- ret = PMINFO_R_OK;
-err:
- if (locale) {
+ 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);
- locale = NULL;
+ return PMINFO_R_ERROR;
}
- __close_manifest_db();
- return ret;
+
+ *count = g_hash_table_size(list);
+
+ 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(
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 = -1;
- privilege_x *ptr = NULL;
+ int ret;
+ privilege_x *privilege;
+ GList *tmp;
pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
- ptr = info->pkg_info->privileges->privilege;
- for (; ptr; ptr = ptr->next) {
- if (ptr->text){
- ret = privilege_func(ptr->text, user_data);
- if (ret < 0)
- break;
- }
- }
- 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);
+ if (info->pkg_info == NULL)
+ return PMINFO_R_ERROR;
- mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
- if (manifest) {
- free(manifest);
- manifest = NULL;
+ for (tmp = info->pkg_info->privileges; tmp; tmp = tmp->next) {
+ privilege = (privilege_x *)tmp->data;
+ if (privilege == NULL)
+ continue;
+ ret = privilege_func(privilege->value, user_data);
+ if (ret < 0)
+ break;
}
- 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)
+int __compare_package_version(const char *version, int *major,
+ int *minor, int *macro, int *nano)
{
- retvm_if(!pkgid, PMINFO_R_EINVAL, "pkgid is NULL");
- retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
+ char *version_temp = NULL;
+ char *major_str = NULL;
+ char *minor_str = NULL;
+ char *macro_str = NULL;
+ char *nano_str = NULL;
+ char *save_str = 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;
+ if (version == NULL || major == NULL || minor == NULL ||
+ macro == NULL || nano == NULL) {
+ return PMINFO_R_EINVAL;
}
- 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");
-
- LISTADD(mfx->label, label);
- if (locale)
- mfx->label->lang = strdup(locale);
- else
- mfx->label->lang = strdup(DEFAULT_LOCALE);
- mfx->label->text = strdup(label_txt);
-
- 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");
-
- LISTADD(mfx->icon, icon);
- if (locale)
- mfx->icon->lang = strdup(locale);
- else
- mfx->icon->lang = strdup(DEFAULT_LOCALE);
- mfx->icon->text = strdup(icon_txt);
-
- 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");
-
- LISTADD(mfx->description, description);
- if (locale)
- mfx->description->lang = strdup(locale);
- else
- mfx->description->lang = strdup(DEFAULT_LOCALE);
- mfx->description->text = strdup(desc_txt);
-
- 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");
-
- LISTADD(mfx->author, author);
- if (author_name)
- mfx->author->text = strdup(author_name);
- if (author_email)
- mfx->author->email = strdup(author_email);
- if (author_href)
- mfx->author->href = strdup(author_href);
- if (locale)
- mfx->author->lang = strdup(locale);
- else
- mfx->author->lang = strdup(DEFAULT_LOCALE);
- 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");
+ version_temp = strdup(version);
+ if (version_temp == NULL) {
+ LOGE("Out of memory");
return PMINFO_R_ERROR;
}
-}
-API int pkgmgrinfo_save_pkgusrdbinfo(pkgmgrinfo_pkgdbinfo_h handle, uid_t uid)
-{
- int ret;
- manifest_x *mfx = (manifest_x *)handle;
+ major_str = strtok_r(version_temp, ".", &save_str);
+ if (major_str == NULL) {
+ _LOGE("major version is NULL");
+ free(version_temp);
+ return PMINFO_R_ERROR;
+ }
- retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
+ minor_str = strtok_r(NULL, ".", &save_str);
+ if (minor_str == NULL) {
+ _LOGE("minor version is NULL");
+ free(version_temp);
+ return PMINFO_R_ERROR;
+ }
- 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;
+ *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 {
- _LOGE("Failed to store info in DB\n");
- return PMINFO_R_ERROR;
+ *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_destroy_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle)
+API int pkgmgrinfo_compare_package_version(const char *current_version,
+ const char *target_version,
+ pkgmgrinfo_version_compare_type *res)
{
- manifest_x *mfx = (manifest_x *)handle;
-
- retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
+ 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;
+ }
- pkgmgrinfo_basic_free_package(mfx);
+ 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;
}