about summary refs log tree commit diff
path: root/clients/tui/nmt-mac-entry.c
diff options
context:
space:
mode:
Diffstat (limited to 'clients/tui/nmt-mac-entry.c')
-rw-r--r--clients/tui/nmt-mac-entry.c43
1 files changed, 40 insertions, 3 deletions
diff --git a/clients/tui/nmt-mac-entry.c b/clients/tui/nmt-mac-entry.c
index d0f07e12..da7f55fa 100644
--- a/clients/tui/nmt-mac-entry.c
+++ b/clients/tui/nmt-mac-entry.c
@@ -28,11 +28,13 @@
 
 #include "nm-default.h"
 
+#include "nmt-mac-entry.h"
+
 #include <string.h>
 
 #include "NetworkManager.h"
+#include "nm-common-macros.h"
 
-#include "nmt-mac-entry.h"
 
 G_DEFINE_TYPE (NmtMacEntry, nmt_mac_entry, NMT_TYPE_NEWT_ENTRY)
 
@@ -41,6 +43,7 @@ G_DEFINE_TYPE (NmtMacEntry, nmt_mac_entry, NMT_TYPE_NEWT_ENTRY)
 typedef struct {
 	int mac_length;
 	int mac_str_length;
+	NmtMacEntryType entry_type;
 
 } NmtMacEntryPrivate;
 
@@ -48,6 +51,7 @@ enum {
 	PROP_0,
 	PROP_MAC_LENGTH,
 	PROP_MAC_ADDRESS,
+	PROP_ENTRY_TYPE,
 
 	LAST_PROP
 };
@@ -57,6 +61,7 @@ enum {
  * @width: the width in characters of the entry
  * @mac_length: the length in bytes of the hardware address
  *   (either %ETH_ALEN or %INFINIBAND_ALEN)
+ * @entry_type: the type of the entry.
  *
  * Creates a new #NmtMacEntry.
  *
@@ -64,11 +69,13 @@ enum {
  */
 NmtNewtWidget *
 nmt_mac_entry_new (int width,
-                   int mac_length)
+                   int mac_length,
+                   NmtMacEntryType entry_type)
 {
 	return g_object_new (NMT_TYPE_MAC_ENTRY,
 	                     "width", width,
 	                     "mac-length", mac_length,
+	                     "entry-type", (int) entry_type,
 	                     NULL);
 }
 
@@ -81,6 +88,9 @@ mac_filter (NmtNewtEntry *entry,
 {
 	NmtMacEntryPrivate *priv = NMT_MAC_ENTRY_GET_PRIVATE (entry);
 
+	if (priv->entry_type != NMT_MAC_ENTRY_TYPE_MAC)
+		return TRUE;
+
 	if (position >= priv->mac_str_length)
 		return FALSE;
 
@@ -98,6 +108,11 @@ mac_validator (NmtNewtEntry *entry,
 	if (!*text)
 		return TRUE;
 
+	if (priv->entry_type == NMT_MAC_ENTRY_TYPE_CLONED) {
+		if (NM_CLONED_MAC_IS_SPECIAL (text))
+			return TRUE;
+	}
+
 	p = text;
 	while (   g_ascii_isxdigit (p[0])
 	       && g_ascii_isxdigit (p[1])
@@ -112,7 +127,9 @@ mac_validator (NmtNewtEntry *entry,
 	if (!*p)
 		return (p - text == priv->mac_str_length);
 
-	if (g_ascii_isxdigit (p[0]) && !p[1]) {
+	if (   g_ascii_isxdigit (p[0])
+	    && !p[1]
+	    && p - text < priv->mac_str_length) {
 		char *fixed = g_strdup_printf ("%.*s:%c", (int)(p - text), text, *p);
 
 		nmt_newt_entry_set_text (entry, fixed);
@@ -161,6 +178,10 @@ nmt_mac_entry_set_property (GObject      *object,
 	case PROP_MAC_ADDRESS:
 		nmt_newt_entry_set_text (NMT_NEWT_ENTRY (object), g_value_get_string (value));
 		break;
+	case PROP_ENTRY_TYPE:
+		/* construct-only */
+		priv->entry_type = g_value_get_int (value);
+		break;
 	default:
 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 		break;
@@ -182,6 +203,9 @@ nmt_mac_entry_get_property (GObject    *object,
 	case PROP_MAC_ADDRESS:
 		g_value_set_string (value, nmt_newt_entry_get_text (NMT_NEWT_ENTRY (object)));
 		break;
+	case PROP_ENTRY_TYPE:
+		g_value_set_int (value, priv->entry_type);
+		break;
 	default:
 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 		break;
@@ -224,4 +248,17 @@ nmt_mac_entry_class_init (NmtMacEntryClass *entry_class)
 		                      NULL,
 		                      G_PARAM_READWRITE |
 		                      G_PARAM_STATIC_STRINGS));
+	/**
+	 * NmtMacEntry:entry-type:
+	 *
+	 * The type of the #NmtMacEntry. Can be either used for plain
+	 * MAC addresses or for the extended format for cloned MAC addresses.
+	 */
+	g_object_class_install_property
+		(object_class, PROP_ENTRY_TYPE,
+		 g_param_spec_int ("entry-type", "", "",
+		                   NMT_MAC_ENTRY_TYPE_MAC, NMT_MAC_ENTRY_TYPE_CLONED, NMT_MAC_ENTRY_TYPE_MAC,
+		                   G_PARAM_READWRITE |
+		                   G_PARAM_CONSTRUCT_ONLY |
+		                   G_PARAM_STATIC_STRINGS));
 }