From 28047305db85d5a885ef58bc0369bf92d0e0e55e Mon Sep 17 00:00:00 2001 From: Mu Qiao Date: Tue, 21 Feb 2012 19:11:59 +0800 Subject: [PATCH] ifnet: fix IP comparison (bgo #670508) IP comparison was not working due to different IP formats. Now this is fixed. --- src/settings/plugins/ifnet/net_parser.c | 52 +++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/src/settings/plugins/ifnet/net_parser.c b/src/settings/plugins/ifnet/net_parser.c index a206eda8d6..2e96bb9dac 100644 --- a/src/settings/plugins/ifnet/net_parser.c +++ b/src/settings/plugins/ifnet/net_parser.c @@ -417,6 +417,34 @@ ifnet_get_data (const char *conn_name, const char *key) return NULL; } +/* format ip values for comparison */ +static gchar* +format_ip_for_comparison (gchar * value) +{ + gchar **ipset; + guint length, i; + GString *formated_string = g_string_new (NULL); + gchar *formatted = NULL; + + ipset = g_strsplit (value, "\"", 0); + length = g_strv_length (ipset); + + for (i = 0; i < length; i++) + { + strip_string (ipset[i], ' '); + if (ipset[i][0] != '\0') + g_string_append_printf (formated_string, + "%s ", ipset[i]); + } + formatted = g_strdup (formated_string->str); + formatted[formated_string->len - 1] = '\0'; + + g_string_free (formated_string, TRUE); + g_strfreev (ipset); + + return formatted; +} + void ifnet_set_data (const char *conn_name, const char *key, const char *value) { @@ -434,6 +462,30 @@ ifnet_set_data (const char *conn_name, const char *key, const char *value) } /* Remove existing key value pair */ if (g_hash_table_lookup_extended (conn, key, &old_key, &old_value)) { + + /* This ugly hack is due to baselayout compatibility. We have to + * deal with different ip format. So sometimes we have the same ips + * but different strings. + */ + if (stripped && + (!strcmp (key, "config") + || !strcmp (key, "routes") + || !strcmp (key, "pppd") + || !strcmp (key, "chat"))) + { + gchar *old_ips = format_ip_for_comparison (old_value); + gchar *new_ips = format_ip_for_comparison (value); + if(!strcmp (old_ips, new_ips)) + { + g_free (stripped); + g_free (old_ips); + g_free (new_ips); + return; + } + g_free (old_ips); + g_free (new_ips); + } + if (stripped && !strcmp (old_value, stripped)) { g_free (stripped); return;