Commit 3a54d050 authored by Dan Winship's avatar Dan Winship

libnm-core: change all mac-address properties to G_TYPE_STRING

Make all mac-address properties (including NMSettingBluetooth:bdaddr,
NMSettingOlpcMesh:dhcp-anycast-addr, and NMSettingWireless:bssid) be
strings, using _nm_setting_class_transform_property() to handle
translating to/from binary form when dealing with D-Bus.

Update everything accordingly for the change, and also add a test for
transformed setting properties to test-general.
parent f4957eb0
This diff is collapsed.
......@@ -810,22 +810,6 @@ vpn_data_item (const char *key, const char *value, gpointer user_data)
return secret_flags_to_string (v); \
}
#define DEFINE_HWADDR_GETTER(func_name, property_name) \
static char * \
func_name (NMSetting *setting) \
{ \
GValue val = G_VALUE_INIT; \
GArray *array; \
char *hwaddr = NULL; \
g_value_init (&val, DBUS_TYPE_G_UCHAR_ARRAY); \
g_object_get_property (G_OBJECT (setting), property_name, &val); \
array = g_value_get_boxed (&val); \
if (array && array->len) \
hwaddr = nm_utils_hwaddr_ntoa (array->data, array->len); \
g_value_unset (&val); \
return hwaddr; \
}
/* --- NM_SETTING_802_1X_SETTING_NAME property get functions --- */
DEFINE_GETTER (nmc_property_802_1X_get_eap, NM_SETTING_802_1X_EAP)
DEFINE_GETTER (nmc_property_802_1X_get_identity, NM_SETTING_802_1X_IDENTITY)
......@@ -966,7 +950,7 @@ DEFINE_GETTER (nmc_property_adsl_get_vpi, NM_SETTING_ADSL_VPI)
DEFINE_GETTER (nmc_property_adsl_get_vci, NM_SETTING_ADSL_VCI)
/* --- NM_SETTING_BLUETOOTH_SETTING_NAME property get functions --- */
DEFINE_HWADDR_GETTER (nmc_property_bluetooth_get_bdaddr, NM_SETTING_BLUETOOTH_BDADDR)
DEFINE_GETTER (nmc_property_bluetooth_get_bdaddr, NM_SETTING_BLUETOOTH_BDADDR)
DEFINE_GETTER (nmc_property_bluetooth_get_type, NM_SETTING_BLUETOOTH_TYPE)
static char *
......@@ -989,7 +973,7 @@ nmc_property_bond_get_options (NMSetting *setting)
}
/* --- NM_SETTING_BRIDGE_SETTING_NAME property get functions --- */
DEFINE_HWADDR_GETTER (nmc_property_bridge_get_mac_address, NM_SETTING_BRIDGE_MAC_ADDRESS)
DEFINE_GETTER (nmc_property_bridge_get_mac_address, NM_SETTING_BRIDGE_MAC_ADDRESS)
DEFINE_GETTER (nmc_property_bridge_get_stp, NM_SETTING_BRIDGE_STP)
DEFINE_GETTER (nmc_property_bridge_get_priority, NM_SETTING_BRIDGE_PRIORITY)
DEFINE_GETTER (nmc_property_bridge_get_forward_delay, NM_SETTING_BRIDGE_FORWARD_DELAY)
......@@ -1181,7 +1165,7 @@ DEFINE_SECRET_FLAGS_GETTER (nmc_property_gsm_get_pin_flags, NM_SETTING_GSM_PIN_F
DEFINE_GETTER (nmc_property_gsm_get_home_only, NM_SETTING_GSM_HOME_ONLY)
/* --- NM_SETTING_INFINIBAND_SETTING_NAME property get functions --- */
DEFINE_HWADDR_GETTER (nmc_property_ib_get_mac_address, NM_SETTING_INFINIBAND_MAC_ADDRESS)
DEFINE_GETTER (nmc_property_ib_get_mac_address, NM_SETTING_INFINIBAND_MAC_ADDRESS)
DEFINE_GETTER (nmc_property_ib_get_transport_mode, NM_SETTING_INFINIBAND_TRANSPORT_MODE)
static char *
......@@ -1247,7 +1231,7 @@ nmc_property_ipv6_get_ip6_privacy (NMSetting *setting)
/* --- NM_SETTING_OLPC_MESH_SETTING_NAME property get functions --- */
DEFINE_GETTER (nmc_property_olpc_get_channel, NM_SETTING_OLPC_MESH_CHANNEL)
DEFINE_HWADDR_GETTER (nmc_property_olpc_get_anycast_address, NM_SETTING_OLPC_MESH_DHCP_ANYCAST_ADDRESS)
DEFINE_GETTER (nmc_property_olpc_get_anycast_address, NM_SETTING_OLPC_MESH_DHCP_ANYCAST_ADDRESS)
static char *
nmc_property_olpc_get_ssid (NMSetting *setting)
......@@ -1352,15 +1336,15 @@ nmc_property_vpn_get_secrets (NMSetting *setting)
/* --- NM_SETTING_WIMAX_SETTING_NAME property get functions --- */
DEFINE_GETTER (nmc_property_wimax_get_network_name, NM_SETTING_WIMAX_NETWORK_NAME)
DEFINE_HWADDR_GETTER (nmc_property_wimax_get_mac_address, NM_SETTING_WIMAX_MAC_ADDRESS)
DEFINE_GETTER (nmc_property_wimax_get_mac_address, NM_SETTING_WIMAX_MAC_ADDRESS)
/* --- NM_SETTING_WIRED_SETTING_NAME property get functions --- */
DEFINE_GETTER (nmc_property_wired_get_port, NM_SETTING_WIRED_PORT)
DEFINE_GETTER (nmc_property_wired_get_speed, NM_SETTING_WIRED_SPEED)
DEFINE_GETTER (nmc_property_wired_get_duplex, NM_SETTING_WIRED_DUPLEX)
DEFINE_GETTER (nmc_property_wired_get_auto_negotiate, NM_SETTING_WIRED_AUTO_NEGOTIATE)
DEFINE_HWADDR_GETTER (nmc_property_wired_get_mac_address, NM_SETTING_WIRED_MAC_ADDRESS)
DEFINE_HWADDR_GETTER (nmc_property_wired_get_cloned_mac_address, NM_SETTING_WIRED_CLONED_MAC_ADDRESS)
DEFINE_GETTER (nmc_property_wired_get_mac_address, NM_SETTING_WIRED_MAC_ADDRESS)
DEFINE_GETTER (nmc_property_wired_get_cloned_mac_address, NM_SETTING_WIRED_CLONED_MAC_ADDRESS)
DEFINE_GETTER (nmc_property_wired_get_mac_address_blacklist, NM_SETTING_WIRED_MAC_ADDRESS_BLACKLIST)
DEFINE_GETTER (nmc_property_wired_get_s390_subchannels, NM_SETTING_WIRED_S390_SUBCHANNELS)
DEFINE_GETTER (nmc_property_wired_get_s390_nettype, NM_SETTING_WIRED_S390_NETTYPE)
......@@ -1383,11 +1367,11 @@ nmc_property_wired_get_mtu (NMSetting *setting)
DEFINE_GETTER (nmc_property_wireless_get_mode, NM_SETTING_WIRELESS_MODE)
DEFINE_GETTER (nmc_property_wireless_get_band, NM_SETTING_WIRELESS_BAND)
DEFINE_GETTER (nmc_property_wireless_get_channel, NM_SETTING_WIRELESS_CHANNEL)
DEFINE_HWADDR_GETTER (nmc_property_wireless_get_bssid, NM_SETTING_WIRELESS_BSSID)
DEFINE_GETTER (nmc_property_wireless_get_bssid, NM_SETTING_WIRELESS_BSSID)
DEFINE_GETTER (nmc_property_wireless_get_rate, NM_SETTING_WIRELESS_RATE)
DEFINE_GETTER (nmc_property_wireless_get_tx_power, NM_SETTING_WIRELESS_TX_POWER)
DEFINE_HWADDR_GETTER (nmc_property_wireless_get_mac_address, NM_SETTING_WIRELESS_MAC_ADDRESS)
DEFINE_HWADDR_GETTER (nmc_property_wireless_get_cloned_mac_address, NM_SETTING_WIRELESS_CLONED_MAC_ADDRESS)
DEFINE_GETTER (nmc_property_wireless_get_mac_address, NM_SETTING_WIRELESS_MAC_ADDRESS)
DEFINE_GETTER (nmc_property_wireless_get_cloned_mac_address, NM_SETTING_WIRELESS_CLONED_MAC_ADDRESS)
DEFINE_GETTER (nmc_property_wireless_get_mac_address_blacklist, NM_SETTING_WIRELESS_MAC_ADDRESS_BLACKLIST)
DEFINE_GETTER (nmc_property_wireless_get_seen_bssids, NM_SETTING_WIRELESS_SEEN_BSSIDS)
DEFINE_GETTER (nmc_property_wireless_get_hidden, NM_SETTING_WIRELESS_HIDDEN)
......@@ -2061,18 +2045,14 @@ nmc_property_set_ssid (NMSetting *setting, const char *prop, const char *val, GE
static gboolean
nmc_property_set_mac (NMSetting *setting, const char *prop, const char *val, GError **error)
{
GByteArray *array;
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
array = nm_utils_hwaddr_atoba (val, ETH_ALEN);
if (!array) {
if (!nm_utils_hwaddr_valid (val, ETH_ALEN)) {
g_set_error (error, 1, 0, _("'%s' is not a valid Ethernet MAC"), val);
return FALSE;
}
g_object_set (setting, prop, array, NULL);
g_byte_array_free (array, TRUE);
g_object_set (setting, prop, val, NULL);
return TRUE;
}
......@@ -2830,18 +2810,14 @@ nmc_property_bond_allowed_options (NMSetting *setting, const char *prop)
static gboolean
nmc_property_ib_set_mac (NMSetting *setting, const char *prop, const char *val, GError **error)
{
GByteArray *array;
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
array = nm_utils_hwaddr_atoba (val, INFINIBAND_ALEN);
if (!array) {
if (!nm_utils_hwaddr_valid (val, INFINIBAND_ALEN)) {
g_set_error (error, 1, 0, _("'%s' is not a valid InfiniBand MAC"), val);
return FALSE;
}
g_object_set (setting, prop, array, NULL);
g_byte_array_free (array, TRUE);
g_object_set (setting, prop, val, NULL);
return TRUE;
}
......
......@@ -57,7 +57,7 @@ typedef struct {
int arptype;
char *interface_name;
GByteArray *mac_address;
char *mac_address;
char *label;
NmtNewtEntry *entry;
......@@ -259,8 +259,8 @@ update_entry (NmtDeviceEntry *deventry)
}
if (priv->mac_address) {
mac = nm_utils_hwaddr_ntoa (priv->mac_address->data, priv->mac_address->len);
mac_device = find_device_by_mac_address (deventry, mac);
mac = g_strdup (priv->mac_address);
mac_device = find_device_by_mac_address (deventry, priv->mac_address);
} else {
mac = NULL;
mac_device = NULL;
......@@ -312,25 +312,21 @@ nmt_device_entry_set_interface_name (NmtDeviceEntry *deventry,
static gboolean
nmt_device_entry_set_mac_address (NmtDeviceEntry *deventry,
GByteArray *mac_address)
const char *mac_address)
{
NmtDeviceEntryPrivate *priv = NMT_DEVICE_ENTRY_GET_PRIVATE (deventry);
gboolean changed;
if (mac_address)
g_return_val_if_fail (mac_address->len == nm_utils_hwaddr_len (priv->arptype), FALSE);
if (mac_address && !priv->mac_address) {
priv->mac_address = g_boxed_copy (DBUS_TYPE_G_UCHAR_ARRAY, mac_address);
priv->mac_address = g_strdup (mac_address);
changed = TRUE;
} else if (!mac_address && priv->mac_address) {
g_clear_pointer (&priv->mac_address, g_byte_array_unref);
g_clear_pointer (&priv->mac_address, g_free);
changed = TRUE;
} else if ( mac_address && priv->mac_address
&& !nm_utils_hwaddr_matches (mac_address->data, mac_address->len,
priv->mac_address->data, priv->mac_address->len)) {
g_byte_array_unref (priv->mac_address);
priv->mac_address = g_boxed_copy (DBUS_TYPE_G_UCHAR_ARRAY, mac_address);
&& !nm_utils_hwaddr_matches (mac_address, -1, priv->mac_address, -1)) {
g_free (priv->mac_address);
priv->mac_address = g_strdup (mac_address);
changed = TRUE;
} else
changed = FALSE;
......@@ -356,21 +352,11 @@ entry_text_changed (GObject *object,
if (!device_entry_parse (deventry, text, &ifname, &mac))
return;
if (ifname) {
nmt_device_entry_set_interface_name (deventry, ifname);
g_free (ifname);
} else
nmt_device_entry_set_interface_name (deventry, NULL);
if (mac) {
GByteArray *mac_address;
nmt_device_entry_set_interface_name (deventry, ifname);
g_free (ifname);
mac_address = nm_utils_hwaddr_atoba (mac, nm_utils_hwaddr_len (priv->arptype));
nmt_device_entry_set_mac_address (deventry, mac_address);
g_byte_array_unref (mac_address);
g_free (mac);
} else
nmt_device_entry_set_mac_address (deventry, NULL);
nmt_device_entry_set_mac_address (deventry, mac);
g_free (mac);
}
static void
......@@ -410,8 +396,7 @@ nmt_device_entry_finalize (GObject *object)
NmtDeviceEntryPrivate *priv = NMT_DEVICE_ENTRY_GET_PRIVATE (object);
g_free (priv->interface_name);
if (priv->mac_address)
g_byte_array_unref (priv->mac_address);
g_free (priv->mac_address);
G_OBJECT_CLASS (nmt_device_entry_parent_class)->finalize (object);
}
......@@ -461,7 +446,7 @@ nmt_device_entry_set_property (GObject *object,
NmtDeviceEntry *deventry = NMT_DEVICE_ENTRY (object);
NmtDeviceEntryPrivate *priv = NMT_DEVICE_ENTRY_GET_PRIVATE (deventry);
const char *interface_name;
GByteArray *mac_address;
const char *mac_address;
switch (prop_id) {
case PROP_LABEL:
......@@ -480,7 +465,7 @@ nmt_device_entry_set_property (GObject *object,
update_entry (deventry);
break;
case PROP_MAC_ADDRESS:
mac_address = g_value_get_boxed (value);
mac_address = g_value_get_string (value);
if (nmt_device_entry_set_mac_address (deventry, mac_address))
update_entry (deventry);
break;
......@@ -512,7 +497,7 @@ nmt_device_entry_get_property (GObject *object,
g_value_set_string (value, priv->interface_name);
break;
case PROP_MAC_ADDRESS:
g_value_set_boxed (value, priv->mac_address);
g_value_set_string (value, priv->mac_address);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
......@@ -587,8 +572,8 @@ nmt_device_entry_class_init (NmtDeviceEntryClass *deventry_class)
*/
g_object_class_install_property
(object_class, PROP_MAC_ADDRESS,
g_param_spec_boxed ("mac-address", "", "",
DBUS_TYPE_G_UCHAR_ARRAY,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
g_param_spec_string ("mac-address", "", "",
NULL,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
}
......@@ -152,8 +152,6 @@ nmt_mac_entry_set_property (GObject *object,
GParamSpec *pspec)
{
NmtMacEntryPrivate *priv = NMT_MAC_ENTRY_GET_PRIVATE (object);
GByteArray *addr;
char *addr_str;
switch (prop_id) {
case PROP_MAC_LENGTH:
......@@ -161,13 +159,7 @@ nmt_mac_entry_set_property (GObject *object,
priv->mac_str_length = priv->mac_length * 3 - 1;
break;
case PROP_MAC_ADDRESS:
addr = g_value_get_boxed (value);
if (addr) {
addr_str = nm_utils_hwaddr_ntoa (addr->data, addr->len);
nmt_newt_entry_set_text (NMT_NEWT_ENTRY (object), addr_str);
g_free (addr_str);
} else
nmt_newt_entry_set_text (NMT_NEWT_ENTRY (object), "");
nmt_newt_entry_set_text (NMT_NEWT_ENTRY (object), g_value_get_string (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
......@@ -182,15 +174,13 @@ nmt_mac_entry_get_property (GObject *object,
GParamSpec *pspec)
{
NmtMacEntryPrivate *priv = NMT_MAC_ENTRY_GET_PRIVATE (object);
GByteArray *addr;
switch (prop_id) {
case PROP_MAC_LENGTH:
g_value_set_int (value, priv->mac_length);
break;
case PROP_MAC_ADDRESS:
addr = nm_utils_hwaddr_atoba (nmt_newt_entry_get_text (NMT_NEWT_ENTRY (object)), ETH_ALEN);
g_value_take_boxed (value, addr);
g_value_set_boxed (value, nmt_newt_entry_get_text (NMT_NEWT_ENTRY (object)));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
......@@ -225,13 +215,13 @@ nmt_mac_entry_class_init (NmtMacEntryClass *entry_class)
/**
* NmtMacEntry:mac-address:
*
* The MAC address, in binary (in the same format used by the various
* #NMSetting "mac-address" properties).
* The MAC address, as a string (as with the various #NMSetting
* "mac-address" properties).
*/
g_object_class_install_property
(object_class, PROP_MAC_ADDRESS,
g_param_spec_boxed ("mac-address", "", "",
DBUS_TYPE_G_UCHAR_ARRAY,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
g_param_spec_string ("mac-address", "", "",
NULL,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
}
......@@ -29,6 +29,8 @@
#include "nm-setting-cdma.h"
#include "nm-setting-gsm.h"
#include "nm-setting-private.h"
#include "nm-utils.h"
#include "nm-utils-private.h"
/**
* SECTION:nm-setting-bluetooth
......@@ -65,7 +67,7 @@ NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_BLUETOOTH)
#define NM_SETTING_BLUETOOTH_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_BLUETOOTH, NMSettingBluetoothPrivate))
typedef struct {
GByteArray *bdaddr;
char *bdaddr;
char *type;
} NMSettingBluetoothPrivate;
......@@ -115,7 +117,7 @@ nm_setting_bluetooth_get_connection_type (NMSettingBluetooth *setting)
*
* Returns: the Bluetooth address
**/
const GByteArray *
const char *
nm_setting_bluetooth_get_bdaddr (NMSettingBluetooth *setting)
{
g_return_val_if_fail (NM_IS_SETTING_BLUETOOTH (setting), NULL);
......@@ -137,7 +139,7 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
return FALSE;
}
if (priv->bdaddr && priv->bdaddr->len != ETH_ALEN) {
if (!nm_utils_hwaddr_valid (priv->bdaddr, ETH_ALEN)) {
g_set_error_literal (error,
NM_SETTING_BLUETOOTH_ERROR,
NM_SETTING_BLUETOOTH_ERROR_INVALID_PROPERTY,
......@@ -199,8 +201,7 @@ finalize (GObject *object)
{
NMSettingBluetoothPrivate *priv = NM_SETTING_BLUETOOTH_GET_PRIVATE (object);
if (priv->bdaddr)
g_byte_array_free (priv->bdaddr, TRUE);
g_free (priv->bdaddr);
g_free (priv->type);
G_OBJECT_CLASS (nm_setting_bluetooth_parent_class)->finalize (object);
......@@ -214,9 +215,8 @@ set_property (GObject *object, guint prop_id,
switch (prop_id) {
case PROP_BDADDR:
if (priv->bdaddr)
g_byte_array_free (priv->bdaddr, TRUE);
priv->bdaddr = g_value_dup_boxed (value);
g_free (priv->bdaddr);
priv->bdaddr = g_value_dup_string (value);
break;
case PROP_TYPE:
g_free (priv->type);
......@@ -236,7 +236,7 @@ get_property (GObject *object, guint prop_id,
switch (prop_id) {
case PROP_BDADDR:
g_value_set_boxed (value, nm_setting_bluetooth_get_bdaddr (setting));
g_value_set_string (value, nm_setting_bluetooth_get_bdaddr (setting));
break;
case PROP_TYPE:
g_value_set_string (value, nm_setting_bluetooth_get_connection_type (setting));
......@@ -270,11 +270,15 @@ nm_setting_bluetooth_class_init (NMSettingBluetoothClass *setting_class)
**/
g_object_class_install_property
(object_class, PROP_BDADDR,
g_param_spec_boxed (NM_SETTING_BLUETOOTH_BDADDR, "", "",
DBUS_TYPE_G_UCHAR_ARRAY,
G_PARAM_READWRITE |
NM_SETTING_PARAM_INFERRABLE |
G_PARAM_STATIC_STRINGS));
g_param_spec_string (NM_SETTING_BLUETOOTH_BDADDR, "", "",
NULL,
G_PARAM_READWRITE |
NM_SETTING_PARAM_INFERRABLE |
G_PARAM_STATIC_STRINGS));
_nm_setting_class_transform_property (parent_class, NM_SETTING_BLUETOOTH_BDADDR,
DBUS_TYPE_G_UCHAR_ARRAY,
_nm_utils_hwaddr_to_dbus,
_nm_utils_hwaddr_from_dbus);
/**
* NMSettingBluetooth:type:
......
......@@ -93,7 +93,7 @@ typedef struct {
GType nm_setting_bluetooth_get_type (void);
NMSetting * nm_setting_bluetooth_new (void);
const GByteArray *nm_setting_bluetooth_get_bdaddr (NMSettingBluetooth *setting);
const char * nm_setting_bluetooth_get_bdaddr (NMSettingBluetooth *setting);
const char * nm_setting_bluetooth_get_connection_type (NMSettingBluetooth *setting);
G_END_DECLS
......
......@@ -29,7 +29,6 @@
#include "nm-setting-private.h"
#include "nm-utils.h"
#include "nm-utils-private.h"
#include "nm-dbus-glib-types.h"
/**
* SECTION:nm-setting-bridge
......@@ -64,7 +63,7 @@ NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_BRIDGE)
#define NM_SETTING_BRIDGE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_BRIDGE, NMSettingBridgePrivate))
typedef struct {
GByteArray *mac_address;
char * mac_address;
gboolean stp;
guint16 priority;
guint16 forward_delay;
......@@ -104,7 +103,7 @@ nm_setting_bridge_new (void)
*
* Returns: the #NMSettingBridge:mac-address property of the setting
**/
const GByteArray *
const char *
nm_setting_bridge_get_mac_address (NMSettingBridge *setting)
{
g_return_val_if_fail (NM_IS_SETTING_BRIDGE (setting), NULL);
......@@ -234,7 +233,7 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
{
NMSettingBridgePrivate *priv = NM_SETTING_BRIDGE_GET_PRIVATE (setting);
if (priv->mac_address && priv->mac_address->len != ETH_ALEN) {
if (priv->mac_address && !nm_utils_hwaddr_valid (priv->mac_address, ETH_ALEN)) {
g_set_error_literal (error,
NM_SETTING_BRIDGE_ERROR,
NM_SETTING_BRIDGE_ERROR_INVALID_PROPERTY,
......@@ -284,8 +283,7 @@ finalize (GObject *object)
{
NMSettingBridgePrivate *priv = NM_SETTING_BRIDGE_GET_PRIVATE (object);
if (priv->mac_address)
g_byte_array_free (priv->mac_address, TRUE);
g_free (priv->mac_address);
G_OBJECT_CLASS (nm_setting_bridge_parent_class)->finalize (object);
}
......@@ -298,9 +296,8 @@ set_property (GObject *object, guint prop_id,
switch (prop_id) {
case PROP_MAC_ADDRESS:
if (priv->mac_address)
g_byte_array_free (priv->mac_address, TRUE);
priv->mac_address = g_value_dup_boxed (value);
g_free (priv->mac_address);
priv->mac_address = g_value_dup_string (value);
break;
case PROP_STP:
priv->stp = g_value_get_boolean (value);
......@@ -335,7 +332,7 @@ get_property (GObject *object, guint prop_id,
switch (prop_id) {
case PROP_MAC_ADDRESS:
g_value_set_boxed (value, nm_setting_bridge_get_mac_address (setting));
g_value_set_string (value, nm_setting_bridge_get_mac_address (setting));
break;
case PROP_STP:
g_value_set_boolean (value, priv->stp);
......@@ -385,11 +382,15 @@ nm_setting_bridge_class_init (NMSettingBridgeClass *setting_class)
**/
g_object_class_install_property
(object_class, PROP_MAC_ADDRESS,
g_param_spec_boxed (NM_SETTING_BRIDGE_MAC_ADDRESS, "", "",
DBUS_TYPE_G_UCHAR_ARRAY,
G_PARAM_READWRITE |
NM_SETTING_PARAM_INFERRABLE |
G_PARAM_STATIC_STRINGS));
g_param_spec_string (NM_SETTING_BRIDGE_MAC_ADDRESS, "", "",
NULL,
G_PARAM_READWRITE |
NM_SETTING_PARAM_INFERRABLE |
G_PARAM_STATIC_STRINGS));
_nm_setting_class_transform_property (parent_class, NM_SETTING_BRIDGE_MAC_ADDRESS,
DBUS_TYPE_G_UCHAR_ARRAY,
_nm_utils_hwaddr_to_dbus,
_nm_utils_hwaddr_from_dbus);
/**
* NMSettingBridge:stp:
......
......@@ -78,7 +78,7 @@ GType nm_setting_bridge_get_type (void);
NMSetting * nm_setting_bridge_new (void);
const GByteArray *nm_setting_bridge_get_mac_address (NMSettingBridge *setting);
const char * nm_setting_bridge_get_mac_address (NMSettingBridge *setting);
gboolean nm_setting_bridge_get_stp (NMSettingBridge *setting);
......
......@@ -61,7 +61,7 @@ NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_INFINIBAND)
#define NM_SETTING_INFINIBAND_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_INFINIBAND, NMSettingInfinibandPrivate))
typedef struct {
GByteArray *mac_address;
char *mac_address;
char *transport_mode;
guint32 mtu;
int p_key;
......@@ -98,7 +98,7 @@ nm_setting_infiniband_new (void)
*
* Returns: the #NMSettingInfiniband:mac-address property of the setting
**/
const GByteArray *
const char *
nm_setting_infiniband_get_mac_address (NMSettingInfiniband *setting)
{
g_return_val_if_fail (NM_IS_SETTING_INFINIBAND (setting), NULL);
......@@ -202,7 +202,7 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
NMSettingInfinibandPrivate *priv = NM_SETTING_INFINIBAND_GET_PRIVATE (setting);
guint32 normerr_max_mtu = 0;
if (priv->mac_address && priv->mac_address->len != INFINIBAND_ALEN) {
if (priv->mac_address && !nm_utils_hwaddr_valid (priv->mac_address, INFINIBAND_ALEN)) {
g_set_error_literal (error,
NM_SETTING_INFINIBAND_ERROR,
NM_SETTING_INFINIBAND_ERROR_INVALID_PROPERTY,
......@@ -320,8 +320,7 @@ finalize (GObject *object)
NMSettingInfinibandPrivate *priv = NM_SETTING_INFINIBAND_GET_PRIVATE (object);
g_free (priv->transport_mode);
if (priv->mac_address)
g_byte_array_free (priv->mac_address, TRUE);
g_free (priv->mac_address);
g_free (priv->parent);
g_free (priv->virtual_iface_name);
......@@ -336,9 +335,8 @@ set_property (GObject *object, guint prop_id,
switch (prop_id) {
case PROP_MAC_ADDRESS:
if (priv->mac_address)
g_byte_array_free (priv->mac_address, TRUE);
priv->mac_address = g_value_dup_boxed (value);
g_free (priv->mac_address);
priv->mac_address = g_value_dup_string (value);
break;
case PROP_MTU:
priv->mtu = g_value_get_uint (value);
......@@ -370,7 +368,7 @@ get_property (GObject *object, guint prop_id,
switch (prop_id) {
case PROP_MAC_ADDRESS:
g_value_set_boxed (value, nm_setting_infiniband_get_mac_address (setting));
g_value_set_string (value, nm_setting_infiniband_get_mac_address (setting));
break;
case PROP_MTU:
g_value_set_uint (value, nm_setting_infiniband_get_mtu (setting));
......@@ -415,11 +413,15 @@ nm_setting_infiniband_class_init (NMSettingInfinibandClass *setting_class)
**/
g_object_class_install_property
(object_class, PROP_MAC_ADDRESS,
g_param_spec_boxed (NM_SETTING_INFINIBAND_MAC_ADDRESS, "", "",
DBUS_TYPE_G_UCHAR_ARRAY,
G_PARAM_READWRITE |
NM_SETTING_PARAM_INFERRABLE |
G_PARAM_STATIC_STRINGS));
g_param_spec_string (NM_SETTING_INFINIBAND_MAC_ADDRESS, "", "",
NULL,
G_PARAM_READWRITE |
NM_SETTING_PARAM_INFERRABLE |
G_PARAM_STATIC_STRINGS));
_nm_setting_class_transform_property (parent_class, NM_SETTING_INFINIBAND_MAC_ADDRESS,
DBUS_TYPE_G_UCHAR_ARRAY,
_nm_utils_hwaddr_to_dbus,
_nm_utils_hwaddr_from_dbus);
/**
* NMSettingInfiniband:mtu:
......
......@@ -75,7 +75,7 @@ typedef struct {
GType nm_setting_infiniband_get_type (void);
NMSetting * nm_setting_infiniband_new (void);
const GByteArray *nm_setting_infiniband_get_mac_address (NMSettingInfiniband *setting);
const char * nm_setting_infiniband_get_mac_address (NMSettingInfiniband *setting);
guint32 nm_setting_infiniband_get_mtu (NMSettingInfiniband *setting);
const char * nm_setting_infiniband_get_transport_mode (NMSettingInfiniband *setting);
int nm_setting_infiniband_get_p_key (NMSettingInfiniband *setting);
......
......@@ -52,7 +52,7 @@ NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_OLPC_MESH)
typedef struct {
GByteArray *ssid;
guint32 channel;
GByteArray *dhcp_anycast_addr;
char *dhcp_anycast_addr;
} NMSettingOlpcMeshPrivate;
enum {
......@@ -97,7 +97,7 @@ nm_setting_olpc_mesh_get_channel (NMSettingOlpcMesh *setting)
return NM_SETTING_OLPC_MESH_GET_PRIVATE (setting)->channel;
}
const GByteArray *
const char *
nm_setting_olpc_mesh_get_dhcp_anycast_address (NMSettingOlpcMesh *setting)
{
g_return_val_if_fail (NM_IS_SETTING_OLPC_MESH (setting), NULL);
......@@ -138,7 +138,7 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
return FALSE;
}
if (priv->dhcp_anycast_addr && priv->dhcp_anycast_addr->len != ETH_ALEN) {
if (priv->dhcp_anycast_addr && !nm_utils_hwaddr_valid (priv->dhcp_anycast_addr, ETH_ALEN)) {
g_set_error_literal (error,
NM_SETTING_OLPC_MESH_ERROR,
NM_SETTING_OLPC_MESH_ERROR_INVALID_PROPERTY,
......@@ -157,8 +157,7 @@ finalize (GObject *object)
if (priv->ssid)
g_byte_array_free (priv->ssid, TRUE);
if (priv->dhcp_anycast_addr)
g_byte_array_free (priv->dhcp_anycast_addr, TRUE);
g_free (priv->dhcp_anycast_addr);
G_OBJECT_CLASS (nm_setting_olpc_mesh_parent_class)->finalize (object);
}
......@@ -179,9 +178,8 @@ set_property (GObject *object, guint prop_id,
priv->channel = g_value_get_uint (value);
break;
case PROP_DHCP_ANYCAST_ADDRESS:
if (priv->dhcp_anycast_addr)
g_byte_array_free (priv->dhcp_anycast_addr, TRUE);
priv->dhcp_anycast_addr = g_value_dup_boxed (value);
g_free (priv->dhcp_anycast_addr);
priv->dhcp_anycast_addr = g_value_dup_string (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
......@@ -203,7 +201,7 @@ get_property (GObject *object, guint prop_id,
g_value_set_uint (value, nm_setting_olpc_mesh_get_channel (setting));
break;
case PROP_DHCP_ANYCAST_ADDRESS:
g_value_set_boxed (value, nm_setting_olpc_mesh_get_dhcp_anycast_address (setting));
g_value_set_string (value, nm_setting_olpc_mesh_get_dhcp_anycast_address (setting));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
......@@ -262,8 +260,12 @@ nm_setting_olpc_mesh_class_init (NMSettingOlpcMeshClass *setting_class)
**/
g_object_class_install_property
(object_class, PROP_DHCP_ANYCAST_ADDRESS,
g_param_spec_boxed (NM_SETTING_OLPC_MESH_DHCP_ANYCAST_ADDRESS, "", "",
DBUS_TYPE_G_UCHAR_ARRAY,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
g_param_spec_string (NM_SETTING_OLPC_MESH_DHCP_ANYCAST_ADDRESS, "", "",
NULL,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
_nm_setting_class_transform_property (parent_class, NM_SETTING_OLPC_MESH_DHCP_ANYCAST_ADDRESS,
DBUS_TYPE_G_UCHAR_ARRAY,
_nm_utils_hwaddr_to_dbus,
_nm_utils_hwaddr_from_dbus);
}
......@@ -76,7 +76,7 @@ GType nm_setting_olpc_mesh_get_type (void);
NMSetting * nm_setting_olpc_mesh_new (void);
const GByteArray *nm_setting_olpc_mesh_get_ssid (NMSettingOlpcMesh *setting);
guint32 nm_setting_olpc_mesh_get_channel (NMSettingOlpcMesh *setting);
const GByteArray *nm_setting_olpc_mesh_get_dhcp_anycast_address (NMSettingOlpcMesh *setting);
const char * nm_setting_olpc_mesh_get_dhcp_anycast_address (NMSettingOlpcMesh *setting);
G_END_DECLS
......
......@@ -27,6 +27,8 @@
#include "nm-setting-wimax.h"
#include "nm-setting-private.h"
#include "nm-utils.h"
#include "nm-utils-private.h"
/**
* SECTION:nm-setting-wimax
......@@ -62,7 +64,7 @@ NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_WIMAX)
typedef struct {
char *network_name;
GByteArray *mac_address;
char *mac_address;
} NMSettingWimaxPrivate;
enum {
......@@ -112,7 +114,7 @@ nm_setting_wimax_get_network_name (NMSettingWimax *setting)
*
* Returns: the MAC address
**/
const GByteArray *
const char *
nm_setting_wimax_get_mac_address (NMSettingWimax *setting)
{
g_return_val_if_fail (NM_IS_SETTING_WIMAX (setting), NULL);
......@@ -143,7 +145,7 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
return FALSE;
}
if (priv->mac_address && priv->mac_address->len != ETH_ALEN) {
if (priv->mac_address && !nm_utils_hwaddr_valid (priv->mac_address, ETH_ALEN)) {
g_set_error_literal (error,