add internal api for version comparison. 04/100304/4 accepted/tizen/3.0/common/20161203.012114 accepted/tizen/3.0/ivi/20161201.075319 accepted/tizen/3.0/mobile/20161201.075035 accepted/tizen/3.0/tv/20161201.075201 accepted/tizen/3.0/wearable/20161201.075238 submit/tizen_3.0/20161130.132739 submit/tizen_3.0/20161201.023740 submit/tizen_3.0/20161201.024602
authorjongmyeongko <jongmyeong.ko@samsung.com>
Sat, 26 Nov 2016 00:29:28 +0000 (09:29 +0900)
committerjongmyeong ko <jongmyeong.ko@samsung.com>
Wed, 30 Nov 2016 07:41:40 +0000 (23:41 -0800)
Change-Id: I10cbc25ce0517856352558ba5a5de45da481c3b2
Signed-off-by: jongmyeongko <jongmyeong.ko@samsung.com>
include/pkgmgr-info.h
include/pkgmgrinfo_type.h
packaging/pkgmgr-info.spec
src/pkgmgrinfo_pkginfo.c

index bbd7d8a..684317f 100644 (file)
@@ -5790,6 +5790,10 @@ static int set_app_installed_storage(const char *appid, INSTALL_LOCATION locatio
 int pkgmgrinfo_pkginfo_set_installed_storage(const char *pkgid, INSTALL_LOCATION location, const char *external_pkg_path);
 int pkgmgrinfo_pkginfo_set_usr_installed_storage(const char *pkgid, INSTALL_LOCATION location, const char *external_pkg_path, uid_t uid);
 
+/* version compare */
+int pkgmgrinfo_compare_package_version(const char *current_version,
+               const char *target_version, pkgmgrinfo_version_compare_type *res);
+
 /**
  * @brief      TEMP
  */
index 228e77a..4bb96b9 100644 (file)
@@ -386,6 +386,15 @@ typedef enum {
 } pkgmgrinfo_cert_type;
 
 /**
+ * @brief version comparison Types
+ */
+typedef enum {
+       PMINFO_VERSION_OLD = -1,
+       PMINFO_VERSION_SAME,
+       PMINFO_VERSION_NEW,
+} pkgmgrinfo_version_compare_type;
+
+/**
  * @brief Install Location Types to be used when setting data in DB
  */
 typedef enum {
@@ -393,9 +402,9 @@ typedef enum {
        INSTALL_EXTERNAL,               /**< External Installation*/
 } INSTALL_LOCATION;
 
- /**
 * @brief permission Types
 */
+/**
+ * @brief permission Types
+ */
 typedef enum {
        PMINFO_PERMISSION_NORMAL = 0,           /**< permission normal*/
        PMINFO_PERMISSION_SIGNATURE,            /**< permission type is signature*/
index a9f93a5..575cc73 100644 (file)
@@ -1,6 +1,6 @@
 Name:       pkgmgr-info
 Summary:    Packager Manager infomation api for package
-Version:    0.1.1
+Version:    0.1.2
 Release:    1
 Group:      Application Framework/Package Management
 License:    Apache-2.0
index fec1406..2944e65 100644 (file)
@@ -1604,7 +1604,7 @@ API int pkgmgrinfo_pkginfo_filter_create(pkgmgrinfo_pkginfo_filter_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;
@@ -1869,3 +1869,126 @@ API int pkgmgrinfo_pkginfo_foreach_privilege(pkgmgrinfo_pkginfo_h handle,
        }
        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;
+       *minor = 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,
+               &current_version_major, &current_version_minor,
+               &current_version_macro, &current_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;
+}