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;
}
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,
+ ¤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;
+}