From 92898e84d6aebc3ab11799476d7ab8c0d1627949 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Klime=C5=A1?= Date: Tue, 3 Jun 2014 12:38:07 +0200 Subject: [PATCH 1/3] tui: fix a crash when editing IPv6 routes --- tui/nm-editor-bindings.c | 14 +++++++------- tui/nmt-route-entry.c | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tui/nm-editor-bindings.c b/tui/nm-editor-bindings.c index 7f76f14fa1..5be13588ee 100644 --- a/tui/nm-editor-bindings.c +++ b/tui/nm-editor-bindings.c @@ -772,7 +772,7 @@ ip6_addresses_to_strv (GBinding *binding, for (i = 0; i < addrs->len; i++) { addrbytes = addrs->pdata[i]; if (IP6_ADDRESS_SET (addrbytes)) - inet_ntop (AF_INET, addrbytes->data, buf, sizeof (buf)); + inet_ntop (AF_INET6, addrbytes->data, buf, sizeof (buf)); else buf[0] = '\0'; strings[i] = g_strdup (buf); @@ -1002,7 +1002,7 @@ ip6_route_transform_to_next_hop_string (GBinding *binding, addrbytes = &in6addr_any; if (IN6_ADDR_SET (addrbytes)) - inet_ntop (AF_INET, &addrbytes, buf, sizeof (buf)); + inet_ntop (AF_INET6, addrbytes, buf, sizeof (buf)); else buf[0] = '\0'; g_value_set_string (target_value, buf); @@ -1035,7 +1035,7 @@ ip6_route_transform_from_dest_string (GBinding *binding, { NMIP6Route *route; const char *text; - const struct in6_addr *addrbytes; + struct in6_addr addrbytes; guint32 prefix; text = g_value_get_string (source_value); @@ -1047,7 +1047,7 @@ ip6_route_transform_from_dest_string (GBinding *binding, g_binding_get_source_property (binding), &route, NULL); - nm_ip6_route_set_dest (route, addrbytes); + nm_ip6_route_set_dest (route, &addrbytes); nm_ip6_route_set_prefix (route, prefix); g_value_take_boxed (target_value, route); @@ -1062,21 +1062,21 @@ ip6_route_transform_from_next_hop_string (GBinding *binding, { NMIP6Route *route; const char *text; - const struct in6_addr *addrbytes; + struct in6_addr addrbytes; text = g_value_get_string (source_value); if (*text) { if (!ip_string_parse (text, AF_INET6, &addrbytes, NULL)) return FALSE; } else - addrbytes = 0; + addrbytes = in6addr_any; /* Fetch the original property value */ g_object_get (g_binding_get_source (binding), g_binding_get_source_property (binding), &route, NULL); - nm_ip6_route_set_next_hop (route, addrbytes); + nm_ip6_route_set_next_hop (route, &addrbytes); g_value_take_boxed (target_value, route); return TRUE; diff --git a/tui/nmt-route-entry.c b/tui/nmt-route-entry.c index db8c254d74..1b20ca646c 100644 --- a/tui/nmt-route-entry.c +++ b/tui/nmt-route-entry.c @@ -206,7 +206,7 @@ nmt_route_entry_set_property (GObject *object, priv->ip4_route = g_value_dup_boxed (value); break; case PROP_IP6_ROUTE: - g_return_if_fail (priv->family == AF_INET); + g_return_if_fail (priv->family == AF_INET6); if (priv->ip6_route) nm_ip6_route_unref (priv->ip6_route); priv->ip6_route = g_value_dup_boxed (value); From 5ee85fe46e86fdc9e063c22700697802435503a6 Mon Sep 17 00:00:00 2001 From: Dan Winship Date: Tue, 3 Jun 2014 09:13:43 -0400 Subject: [PATCH 2/3] tui: fix setting Clone MAC Address properties NmtMacEntry wasn't notifying its mac-address property when it changed, so the change never got saved to the NMSetting. https://bugzilla.gnome.org/show_bug.cgi?id=731160 --- tui/nmt-mac-entry.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tui/nmt-mac-entry.c b/tui/nmt-mac-entry.c index d76c097f20..b065640812 100644 --- a/tui/nmt-mac-entry.c +++ b/tui/nmt-mac-entry.c @@ -28,6 +28,8 @@ #include "config.h" +#include + #include #include @@ -128,6 +130,17 @@ nmt_mac_entry_init (NmtMacEntry *entry) nmt_newt_entry_set_validator (NMT_NEWT_ENTRY (entry), mac_validator, NULL); } +static void +nmt_mac_entry_notify (GObject *object, + GParamSpec *pspec) +{ + if (G_OBJECT_CLASS (nmt_mac_entry_parent_class)->notify) + G_OBJECT_CLASS (nmt_mac_entry_parent_class)->notify (object, pspec); + + if (pspec->owner_type == NMT_TYPE_NEWT_ENTRY && !strcmp (pspec->name, "text")) + g_object_notify (object, "mac-address"); +} + static void nmt_mac_entry_set_property (GObject *object, guint prop_id, @@ -189,6 +202,7 @@ nmt_mac_entry_class_init (NmtMacEntryClass *entry_class) g_type_class_add_private (entry_class, sizeof (NmtMacEntryPrivate)); /* virtual methods */ + object_class->notify = nmt_mac_entry_notify; object_class->set_property = nmt_mac_entry_set_property; object_class->get_property = nmt_mac_entry_get_property; From d57795d474aaae7865d4d052605d5ddec65c429d Mon Sep 17 00:00:00 2001 From: Dan Winship Date: Tue, 3 Jun 2014 09:36:17 -0400 Subject: [PATCH 3/3] tui: fix NmtMacEntry validation/display NmtMacEntry would allow you to input 1 character more than it should have. Fix that. Also, the code to insert ":"s automatically was bumping against some weirdness in NmtNewtEntry that made it so that the ":" didn't get displayed until you typed one more character after the one where it got inserted. Hack around that by manually requesting a redraw. https://bugzilla.gnome.org/show_bug.cgi?id=731160 --- tui/nmt-mac-entry.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tui/nmt-mac-entry.c b/tui/nmt-mac-entry.c index b065640812..5e1c41743e 100644 --- a/tui/nmt-mac-entry.c +++ b/tui/nmt-mac-entry.c @@ -82,7 +82,7 @@ mac_filter (NmtNewtEntry *entry, { NmtMacEntryPrivate *priv = NMT_MAC_ENTRY_GET_PRIVATE (entry); - if (position > priv->mac_str_length) + if (position >= priv->mac_str_length) return FALSE; return g_ascii_isxdigit (ch) || ch == ':'; @@ -116,8 +116,13 @@ mac_validator (NmtNewtEntry *entry, if (g_ascii_isxdigit (p[0]) && !p[1]) { char *fixed = g_strdup_printf ("%.*s:%c", (int)(p - text), text, *p); - g_object_set (G_OBJECT (entry), "text", fixed, NULL); - return TRUE; + nmt_newt_entry_set_text (entry, fixed); + g_free (fixed); + + /* FIXME: NmtNewtEntry doesn't correctly deal with us calling set_text() + * from inside the validator. + */ + nmt_newt_widget_needs_rebuild (NMT_NEWT_WIDGET (entry)); } return FALSE;