#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 bool _get_bool_value(const char *str)
{
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 gint __pkg_disable_chk_func(gconstpointer data1, gconstpointer data2)
+{
+ 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);
GList **privileges)
{
static const char query_raw[] =
- "SELECT DISTINCT privilege FROM package_privilege_info "
+ "SELECT DISTINCT privilege, type FROM package_privilege_info "
"WHERE package=%Q";
int ret;
char *query;
" ON pi.package=package_privilege_info.package";
static int _get_filtered_query(pkgmgrinfo_filter_x *filter,
- const char *locale, char **query, GList **bind_params)
+ const char *locale, uid_t uid, char **query, GList **bind_params)
{
int joined = 0;
char buf[MAX_QUERY_LEN] = { '\0' };
len += strlen(" WHERE 1=1 ");
strncat(buf, " WHERE 1=1 ", MAX_QUERY_LEN - len - 1);
for (list = filter->list; list; list = list->next) {
- joined |= __get_filter_condition(list->data, &condition,
+ joined |= __get_filter_condition(list->data, uid, &condition,
bind_params);
if (condition == NULL)
continue;
pkgmgrinfo_basic_free_package((package_x *)data);
}
+static bool __check_disable_filter_exist(pkgmgrinfo_filter_x *filter)
+{
+ 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 __bind_params(sqlite3_stmt *stmt, GList *params)
{
GList *tmp_list = NULL;
return PMINFO_R_OK;
}
+static bool __check_package_storage_status(pkgmgrinfo_filter_x *tmp_filter)
+{
+ GSList *tmp_list = NULL;
+ pkgmgrinfo_node_x *tmp_node = NULL;
+ int property = -1;
+
+ 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_packages(uid_t uid, const char *locale,
pkgmgrinfo_filter_x *filter, int flag, GHashTable *packages)
{
"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_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[] =
sqlite3 *db;
sqlite3_stmt *stmt;
pkgmgrinfo_filter_x *tmp_filter = NULL;
+ bool is_check_storage = true;
dbpath = getUserPkgParserDBPathUID(uid);
if (dbpath == NULL)
return PMINFO_R_ERROR;
- ret = sqlite3_open_v2(dbpath, &db, SQLITE_OPEN_READONLY, NULL);
+ ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY);
if (ret != SQLITE_OK) {
_LOGD("failed to open db: %d", ret);
free(dbpath);
}
}
- /* add package_disable='false' clause by default */
- pkgmgrinfo_pkginfo_filter_add_bool(tmp_filter, PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, false);
+ is_check_storage = __check_package_storage_status(tmp_filter);
query_len = strlen(query_raw);
snprintf(query, MAX_QUERY_LEN - 1, "%s", query_raw);
strncat(query, query_from_clause, MAX_QUERY_LEN - query_len - 1);
query_len += strlen(query_from_clause);
- ret = _get_filtered_query(tmp_filter, locale, &constraints, &bind_params);
+ ret = _get_filtered_query(tmp_filter, locale, uid, &constraints, &bind_params);
if (ret != PMINFO_R_OK) {
LOGE("Failed to get WHERE clause");
goto catch;
info = calloc(1, sizeof(package_x));
if (info == NULL) {
LOGE("out of memory");
- sqlite3_finalize(stmt);
- sqlite3_close_v2(db);
- return PMINFO_R_ERROR;
+ ret = PMINFO_R_ERROR;
+ goto catch;
}
idx = 0;
_save_column_str(stmt, idx++, &info->package);
(gconstpointer)info->package)) {
free(info->package);
free(info);
+ info = NULL;
continue;
}
_save_column_str(stmt, idx++, &info->version);
_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");
/* TODO : author should be retrieved at package_localized_info */
author = calloc(1, sizeof(author_x));
if (author == NULL) {
- pkgmgrinfo_basic_free_package(info);
- sqlite3_finalize(stmt);
- sqlite3_close_v2(db);
- return PMINFO_R_ERROR;
+ ret = PMINFO_R_ERROR;
+ goto catch;
}
_save_column_str(stmt, idx++, &author->text);
_save_column_str(stmt, idx++, &author->email);
_save_column_str(stmt, idx++, &tmp_record);
if (_add_label_info_into_list(locale, tmp_record, &info->label)) {
- pkgmgrinfo_basic_free_package(info);
- sqlite3_finalize(stmt);
- sqlite3_close_v2(db);
- return PMINFO_R_ERROR;
+ ret = PMINFO_R_ERROR;
+ goto catch;
}
}
tmp_record = NULL;
_save_column_str(stmt, idx++, &tmp_record);
if (_add_icon_info_into_list(locale, tmp_record, &info->icon)) {
- pkgmgrinfo_basic_free_package(info);
- sqlite3_finalize(stmt);
- sqlite3_close_v2(db);
- return PMINFO_R_ERROR;
+ ret = PMINFO_R_ERROR;
+ goto catch;
}
}
_save_column_str(stmt, idx++, &tmp_record);
if (_pkginfo_add_description_info_into_list(locale, tmp_record,
&info->description)) {
- pkgmgrinfo_basic_free_package(info);
- sqlite3_finalize(stmt);
- sqlite3_close_v2(db);
- return PMINFO_R_ERROR;
+ ret = PMINFO_R_ERROR;
+ goto catch;
}
}
if (flag & PMINFO_PKGINFO_GET_PRIVILEGE) {
if (_pkginfo_get_privilege(db, info->package,
&info->privileges)) {
- pkgmgrinfo_basic_free_package(info);
- sqlite3_finalize(stmt);
- sqlite3_close_v2(db);
- return PMINFO_R_ERROR;
+ ret = PMINFO_R_ERROR;
+ goto catch;
}
}
- if (__pkginfo_check_installed_storage(info) != PMINFO_R_OK) {
+ if (is_check_storage &&
+ __pkginfo_check_installed_storage(info) != PMINFO_R_OK) {
ret = PMINFO_R_ERROR;
pkgmgrinfo_basic_free_package(info);
info = NULL;
char *locale;
package_x *pkg;
pkgmgr_pkginfo_x info;
+ pkgmgrinfo_filter_x *tmp_filter = NULL;
GHashTable *list;
GHashTableIter iter;
gpointer value;
return PMINFO_R_ERROR;
}
- ret = _pkginfo_get_packages(uid, locale, filter, flag, list);
+ 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;
+ }
+ }
+
+ 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, filter,
+ 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_destroy(list);
free(locale);
+ if (filter == NULL)
+ pkgmgrinfo_pkginfo_filter_destroy(tmp_filter);
+
return PMINFO_R_OK;
}
+static int _pkgmgrinfo_get_pkginfo(const char *pkgid, uid_t uid,
+ pkgmgrinfo_pkginfo_filter_h filter, pkgmgrinfo_pkginfo_h *handle)
+{
+ int ret;
+ char *locale;
+ GHashTable *list;
+ pkgmgr_pkginfo_x *info;
+
+ if (pkgid == NULL || filter == NULL || handle == NULL) {
+ LOGE("invalid parameter");
+ return PMINFO_R_EINVAL;
+ }
+
+ locale = _get_system_locale();
+ if (locale == NULL)
+ return PMINFO_R_ERROR;
+
+ list = g_hash_table_new(g_str_hash, g_str_equal);
+ if (list == NULL) {
+ free(locale);
+ 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 (!g_hash_table_size(list)) {
+ _LOGI("pkginfo for [%s] is not existed for user [%d]",
+ pkgid, uid);
+ g_hash_table_destroy(list);
+ free(locale);
+ return PMINFO_R_ENOENT;
+ }
+
+ info = calloc(1, sizeof(pkgmgr_pkginfo_x));
+ if (info == NULL) {
+ _LOGE("out of memory");
+ g_hash_table_destroy(list);
+ free(locale);
+ return PMINFO_R_ERROR;
+ }
+
+ info->uid = uid;
+ info->pkg_info = (package_x *)g_hash_table_lookup(list, pkgid);
+ info->locale = locale;
+
+ /* just free list only */
+ g_hash_table_destroy(list);
+
+ *handle = info;
+
+ return ret;
+}
+
API int pkgmgrinfo_pkginfo_get_usr_pkginfo(const char *pkgid, uid_t uid,
pkgmgrinfo_pkginfo_h *handle)
{
int ret;
+ pkgmgrinfo_pkginfo_filter_h filter;
+
+ if (pkgid == NULL || handle == 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_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;
+ }
+
+ ret = _pkgmgrinfo_get_pkginfo(pkgid, uid, filter, handle);
+ pkgmgrinfo_pkginfo_filter_destroy(filter);
+
+ return ret;
+}
+
+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)
+{
+ int ret;
char *locale;
GHashTable *list;
pkgmgrinfo_pkginfo_filter_h filter;
return PMINFO_R_ERROR;
}
+ 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;
+ }
+
list = g_hash_table_new(g_str_hash, g_str_equal);
if (list == NULL) {
pkgmgrinfo_pkginfo_filter_destroy(filter);
}
if (!g_hash_table_size(list)) {
- _LOGI("pkginfo for [%s] is not existed for user [%d]",
+ _LOGI("disabled pkginfo for [%s] is not existed for user [%d]",
pkgid, uid);
g_hash_table_destroy(list);
free(locale);
return ret;
}
-API int pkgmgrinfo_pkginfo_get_pkginfo(const char *pkgid,
+API int pkgmgrinfo_pkginfo_get_usr_all_pkginfo(const char *pkgid, uid_t uid,
pkgmgrinfo_pkginfo_h *handle)
{
- return pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, _getuid(), handle);
+
+ int ret;
+ pkgmgrinfo_pkginfo_filter_h filter;
+
+ if (pkgid == NULL || handle == 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_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_CHECK_STORAGE, 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);
+
+ 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;
}
- return _pkginfo_get_filtered_foreach_pkginfo(uid, NULL, flag,
+ /* create an empty filter */
+ ret = pkgmgrinfo_pkginfo_filter_create(&filter);
+ if (ret != PMINFO_R_OK)
+ return ret;
+
+ ret = _pkginfo_get_filtered_foreach_pkginfo(uid, filter, flag,
pkg_list_cb, user_data);
+
+ pkgmgrinfo_pkginfo_filter_destroy(filter);
+
+ return ret;
}
API int pkgmgrinfo_pkginfo_get_list_full(pkgmgrinfo_pkg_list_cb pkg_list_cb,
API int pkgmgrinfo_pkginfo_get_usr_list(pkgmgrinfo_pkg_list_cb pkg_list_cb,
void *user_data, uid_t uid)
{
+ int ret;
+ pkgmgrinfo_pkginfo_filter_h filter;
+
if (pkg_list_cb == NULL) {
LOGE("invalid parameter");
return PMINFO_R_EINVAL;
}
- return _pkginfo_get_filtered_foreach_pkginfo(uid, NULL,
+ /* create an empty filter */
+ ret = pkgmgrinfo_pkginfo_filter_create(&filter);
+ if (ret != PMINFO_R_OK)
+ return ret;
+
+ ret = _pkginfo_get_filtered_foreach_pkginfo(uid, filter,
PMINFO_PKGINFO_GET_ALL, pkg_list_cb, user_data);
+
+ pkgmgrinfo_pkginfo_filter_destroy(filter);
+
+ return ret;
}
API int pkgmgrinfo_pkginfo_get_list(pkgmgrinfo_pkg_list_cb pkg_list_cb,
_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;
+ }
+
+ 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_disabled_list(pkgmgrinfo_pkg_list_cb pkg_list_cb,
+ void *user_data)
+{
+ 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)
{
pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
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, "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 (__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;
+ }
+ }
+
ret = _pkginfo_get_packages(uid, locale,
(pkgmgrinfo_filter_x *)handle, 0, list);
if (ret == PMINFO_R_OK && uid != GLOBAL_USER)
}
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;
+}