diff --git a/src/swupd.h b/src/swupd.h index 23b9a7d7..6e46a8fa 100644 --- a/src/swupd.h +++ b/src/swupd.h @@ -169,6 +169,7 @@ extern int main_verify(int current_version); extern enum swupd_code walk_tree(struct manifest *, const char *, bool, const regex_t *, struct file_counts *); extern int get_latest_version(char *v_url); +extern int get_int_from_url(const char *url); extern enum swupd_code read_versions(int *current_version, int *server_version, char *path_prefix); extern int get_current_version(char *path_prefix); extern bool get_distribution_string(char *path_prefix, char *dist); diff --git a/src/version.c b/src/version.c index a057f739..8a80c547 100644 --- a/src/version.c +++ b/src/version.c @@ -34,36 +34,43 @@ #define MAX_VERSION_STR_SIZE 11 -int get_server_format(int server_version) +int get_int_from_url(const char *url) { - if (server_version < 0) { - return -1; - } - - int ret, err = -1; - char *url; - - char format_string[MAX_VERSION_STR_SIZE]; - struct curl_file_data format = { + int err, value; + char tmp_string[MAX_VERSION_STR_SIZE]; + struct curl_file_data tmp_data = { MAX_VERSION_STR_SIZE, 0, - format_string + tmp_string }; - string_or_die(&url, "%s/%d/format", globals.version_url, server_version); - ret = swupd_curl_get_file_memory(url, &format); - free_string(&url); - - if (ret) { + value = swupd_curl_get_file_memory(url, &tmp_data); + if (value) { return -1; } - format.data[format.len] = '\0'; - err = strtoi_err(format.data, &ret); + tmp_data.data[tmp_data.len] = '\0'; + err = strtoi_err(tmp_data.data, &value); if (err != 0) { return -1; } - return ret; + return value; +} + +int get_server_format(int server_version) +{ + char *url; + int value; + + if (server_version < 0) { + return -1; + } + + string_or_die(&url, "%s/%d/format", globals.version_url, server_version); + value = get_int_from_url(url); + free_string(&url); + + return value; } int get_current_format(void)