mirror of
https://github.com/clearlinux/swupd-client.git
synced 2026-10-03 23:38:25 +00:00
version: Add helper function to parse an int from an url
Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
This commit is contained in:
@@ -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);
|
||||
|
||||
+26
-19
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user