Commit 53a57306 authored by Slava Monich's avatar Slava Monich

[connman] Improve plugin version check

Versions may look like "1.32+git35+tmp.20181021133657.8.ge08ba21" and we
should be able to parse and compare those. Let's pick first 3 decimal
numbers from the version string and compare the result numerically.
That should do it for the foreseeable future.
parent 2a52fcc8
......@@ -50,9 +50,50 @@ static gint compare_priority(gconstpointer a, gconstpointer b)
return plugin2->desc->priority - plugin1->desc->priority;
}
#define NUM_VER 3
static gboolean parse_version(const char *str, guint *v)
{
gboolean ok = FALSE;
memset(v, 0, sizeof(v[0]) * NUM_VER);
if (str) {
int i;
for (i = 0; i < NUM_VER && *str; i++) {
while (*str && !g_ascii_isdigit(*str)) str++;
while (*str && g_ascii_isdigit(*str)) {
ok = TRUE;
v[i] *= 10;
v[i] += *str++ - '0';
if (v[i] >= 0x7fffffff/10) {
return FALSE;
}
}
}
}
return ok;
}
static int compare_versions(const guint* v1, const guint* v2)
{
int i;
for (i = 0; i < NUM_VER; i++) {
if (v1[i] < v2[i])
return -1;
else if (v1[i] > v2[i])
return 1;
}
return 0;
}
static bool add_plugin(void *handle, struct connman_plugin_desc *desc)
{
struct connman_plugin *plugin;
guint connman_version[NUM_VER], plugin_version[NUM_VER];
if (!desc->init)
return false;
......@@ -64,13 +105,26 @@ static bool add_plugin(void *handle, struct connman_plugin_desc *desc)
return false;
}
/* This better work */
parse_version(CONNMAN_VERSION, connman_version);
/* Allow older versions (API must be backward compatible) */
if (!desc->version || strcmp(desc->version, CONNMAN_VERSION) > 0) {
connman_error("Invalid version %s for %s", desc->version,
if (!parse_version(desc->version, plugin_version)) {
connman_error("Failed to parse version %s of %s", desc->version,
desc->description);
return false;
}
if (compare_versions(plugin_version, connman_version) > 0) {
connman_error("%s version %s (%u.%u.%u) is newer than "
"connman version %s (%u.%u.%u)", desc->description,
desc->version, plugin_version[0],
plugin_version[1], plugin_version[2],
CONNMAN_VERSION, connman_version[0],
connman_version[1], connman_version[2]);
return false;
}
plugin = g_try_new0(struct connman_plugin, 1);
if (!plugin)
return false;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment