Commit 95ab69b7 authored by Thomas Haller's avatar Thomas Haller

libnm: coerce empty strings to NULL for D-Bus properties

On D-Bus level, string (s) or object paths (o) cannot be NULL.
Thus, whenver server exposes such an object, it gets automatically
coerced to "" or "/", respectively.

On client side, libnm should coerce certain properties back, for which
"" is just not a sensible value.

For example, an empty NM_DEVICE_ETHERNET_HW_ADDRESS should be instead
exposed as NULL.

Technically, this is an API change. However, all users were well advised
to expect both NULL and "" as possible return values and handle them
accordingly.
parent 21d7aa92
......@@ -170,7 +170,7 @@ nm_access_point_get_bssid (NMAccessPoint *ap)
{
g_return_val_if_fail (NM_IS_ACCESS_POINT (ap), NULL);
return NM_ACCESS_POINT_GET_PRIVATE (ap)->bssid;
return nm_str_not_empty (NM_ACCESS_POINT_GET_PRIVATE (ap)->bssid);
}
/**
......
......@@ -129,7 +129,7 @@ nm_active_connection_get_id (NMActiveConnection *connection)
{
g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), NULL);
return NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->id;
return nm_str_not_empty (NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->id);
}
/**
......@@ -146,7 +146,7 @@ nm_active_connection_get_uuid (NMActiveConnection *connection)
{
g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), NULL);
return NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->uuid;
return nm_str_not_empty (NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->uuid);
}
/**
......@@ -163,7 +163,7 @@ nm_active_connection_get_connection_type (NMActiveConnection *connection)
{
g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), NULL);
return NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->type;
return nm_str_not_empty (NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->type);
}
/**
......@@ -461,6 +461,7 @@ get_property (GObject *object,
static gboolean
demarshal_specific_object_path (NMObject *object, GParamSpec *pspec, GVariant *value, gpointer field)
{
const char *v;
char **param = (char **) field;
/* We have to demarshal this manually, because the D-Bus property name
......@@ -471,8 +472,10 @@ demarshal_specific_object_path (NMObject *object, GParamSpec *pspec, GVariant *v
if (!g_variant_is_of_type (value, G_VARIANT_TYPE_OBJECT_PATH))
return FALSE;
v = g_variant_get_string (value, NULL);
g_free (*param);
*param = g_variant_dup_string (value, NULL);
*param = nm_streq0 (v, "/") ? NULL : g_strdup (v);
return TRUE;
}
......
......@@ -64,7 +64,7 @@ nm_device_bond_get_hw_address (NMDeviceBond *device)
{
g_return_val_if_fail (NM_IS_DEVICE_BOND (device), NULL);
return NM_DEVICE_BOND_GET_PRIVATE (device)->hw_address;
return nm_str_not_empty (NM_DEVICE_BOND_GET_PRIVATE (device)->hw_address);
}
/**
......
......@@ -64,7 +64,7 @@ nm_device_bridge_get_hw_address (NMDeviceBridge *device)
{
g_return_val_if_fail (NM_IS_DEVICE_BRIDGE (device), NULL);
return NM_DEVICE_BRIDGE_GET_PRIVATE (device)->hw_address;
return nm_str_not_empty (NM_DEVICE_BRIDGE_GET_PRIVATE (device)->hw_address);
}
/**
......
......@@ -65,7 +65,7 @@ nm_device_bt_get_hw_address (NMDeviceBt *device)
{
g_return_val_if_fail (NM_IS_DEVICE_BT (device), NULL);
return NM_DEVICE_BT_GET_PRIVATE (device)->hw_address;
return nm_str_not_empty (NM_DEVICE_BT_GET_PRIVATE (device)->hw_address);
}
/**
......
......@@ -69,7 +69,7 @@ nm_device_ethernet_get_hw_address (NMDeviceEthernet *device)
{
g_return_val_if_fail (NM_IS_DEVICE_ETHERNET (device), NULL);
return NM_DEVICE_ETHERNET_GET_PRIVATE (device)->hw_address;
return nm_str_not_empty (NM_DEVICE_ETHERNET_GET_PRIVATE (device)->hw_address);
}
/**
......@@ -86,7 +86,7 @@ nm_device_ethernet_get_permanent_hw_address (NMDeviceEthernet *device)
{
g_return_val_if_fail (NM_IS_DEVICE_ETHERNET (device), NULL);
return NM_DEVICE_ETHERNET_GET_PRIVATE (device)->perm_hw_address;
return nm_str_not_empty (NM_DEVICE_ETHERNET_GET_PRIVATE (device)->perm_hw_address);
}
/**
......
......@@ -59,7 +59,7 @@ nm_device_generic_get_hw_address (NMDeviceGeneric *device)
{
g_return_val_if_fail (NM_IS_DEVICE_GENERIC (device), NULL);
return NM_DEVICE_GENERIC_GET_PRIVATE (device)->hw_address;
return nm_str_not_empty (NM_DEVICE_GENERIC_GET_PRIVATE (device)->hw_address);
}
/*****************************************************************************/
......@@ -69,7 +69,7 @@ get_type_description (NMDevice *device)
{
NMDeviceGenericPrivate *priv = NM_DEVICE_GENERIC_GET_PRIVATE (device);
return priv->type_description;
return nm_str_not_empty (priv->type_description);
}
static const char *
......@@ -150,14 +150,15 @@ get_property (GObject *object,
GValue *value,
GParamSpec *pspec)
{
NMDeviceGenericPrivate *priv = NM_DEVICE_GENERIC_GET_PRIVATE (object);
NMDeviceGeneric *self = NM_DEVICE_GENERIC (object);
NMDeviceGenericPrivate *priv = NM_DEVICE_GENERIC_GET_PRIVATE (self);
switch (prop_id) {
case PROP_HW_ADDRESS:
g_value_set_string (value, priv->hw_address);
break;
case PROP_TYPE_DESCRIPTION:
g_value_set_string (value, priv->type_description);
g_value_set_string (value, get_type_description ((NMDevice *) self));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
......
......@@ -61,7 +61,7 @@ nm_device_infiniband_get_hw_address (NMDeviceInfiniband *device)
{
g_return_val_if_fail (NM_IS_DEVICE_INFINIBAND (device), NULL);
return NM_DEVICE_INFINIBAND_GET_PRIVATE (device)->hw_address;
return nm_str_not_empty (NM_DEVICE_INFINIBAND_GET_PRIVATE (device)->hw_address);
}
/**
......
......@@ -111,7 +111,7 @@ nm_device_ip_tunnel_get_local (NMDeviceIPTunnel *device)
{
g_return_val_if_fail (NM_IS_DEVICE_IP_TUNNEL (device), NULL);
return NM_DEVICE_IP_TUNNEL_GET_PRIVATE (device)->local;
return nm_str_not_empty (NM_DEVICE_IP_TUNNEL_GET_PRIVATE (device)->local);
}
/**
......@@ -127,7 +127,7 @@ nm_device_ip_tunnel_get_remote (NMDeviceIPTunnel *device)
{
g_return_val_if_fail (NM_IS_DEVICE_IP_TUNNEL (device), NULL);
return NM_DEVICE_IP_TUNNEL_GET_PRIVATE (device)->remote;
return nm_str_not_empty (NM_DEVICE_IP_TUNNEL_GET_PRIVATE (device)->remote);
}
/**
......@@ -192,7 +192,7 @@ nm_device_ip_tunnel_get_input_key (NMDeviceIPTunnel *device)
{
g_return_val_if_fail (NM_IS_DEVICE_IP_TUNNEL (device), NULL);
return NM_DEVICE_IP_TUNNEL_GET_PRIVATE (device)->input_key;
return nm_str_not_empty (NM_DEVICE_IP_TUNNEL_GET_PRIVATE (device)->input_key);
}
/**
......@@ -208,7 +208,7 @@ nm_device_ip_tunnel_get_output_key (NMDeviceIPTunnel *device)
{
g_return_val_if_fail (NM_IS_DEVICE_IP_TUNNEL (device), NULL);
return NM_DEVICE_IP_TUNNEL_GET_PRIVATE (device)->output_key;
return nm_str_not_empty (NM_DEVICE_IP_TUNNEL_GET_PRIVATE (device)->output_key);
}
/**
......
......@@ -86,7 +86,7 @@ nm_device_macvlan_get_mode (NMDeviceMacvlan *device)
{
g_return_val_if_fail (NM_IS_DEVICE_MACVLAN (device), NULL);
return NM_DEVICE_MACVLAN_GET_PRIVATE (device)->mode;
return nm_str_not_empty (NM_DEVICE_MACVLAN_GET_PRIVATE (device)->mode);
}
/**
......@@ -141,7 +141,7 @@ nm_device_macvlan_get_hw_address (NMDeviceMacvlan *device)
{
g_return_val_if_fail (NM_IS_DEVICE_MACVLAN (device), NULL);
return NM_DEVICE_MACVLAN_GET_PRIVATE (device)->hw_address;
return nm_str_not_empty (NM_DEVICE_MACVLAN_GET_PRIVATE (device)->hw_address);
}
......
......@@ -63,7 +63,7 @@ nm_device_olpc_mesh_get_hw_address (NMDeviceOlpcMesh *device)
{
g_return_val_if_fail (NM_IS_DEVICE_OLPC_MESH (device), NULL);
return NM_DEVICE_OLPC_MESH_GET_PRIVATE (device)->hw_address;
return nm_str_not_empty (NM_DEVICE_OLPC_MESH_GET_PRIVATE (device)->hw_address);
}
/**
......
......@@ -66,7 +66,7 @@ nm_device_team_get_hw_address (NMDeviceTeam *device)
{
g_return_val_if_fail (NM_IS_DEVICE_TEAM (device), NULL);
return NM_DEVICE_TEAM_GET_PRIVATE (device)->hw_address;
return nm_str_not_empty (NM_DEVICE_TEAM_GET_PRIVATE (device)->hw_address);
}
/**
......@@ -119,7 +119,7 @@ nm_device_team_get_config (NMDeviceTeam *device)
{
g_return_val_if_fail (NM_IS_DEVICE_TEAM (device), NULL);
return NM_DEVICE_TEAM_GET_PRIVATE (device)->config;
return nm_str_not_empty (NM_DEVICE_TEAM_GET_PRIVATE (device)->config);
}
static const char *
......
......@@ -74,7 +74,7 @@ nm_device_tun_get_hw_address (NMDeviceTun *device)
{
g_return_val_if_fail (NM_IS_DEVICE_TUN (device), NULL);
return NM_DEVICE_TUN_GET_PRIVATE (device)->hw_address;
return nm_str_not_empty (NM_DEVICE_TUN_GET_PRIVATE (device)->hw_address);
}
/**
......@@ -92,7 +92,7 @@ nm_device_tun_get_mode (NMDeviceTun *device)
{
g_return_val_if_fail (NM_IS_DEVICE_TUN (device), NULL);
return NM_DEVICE_TUN_GET_PRIVATE (device)->mode;
return nm_str_not_empty (NM_DEVICE_TUN_GET_PRIVATE (device)->mode);
}
/**
......
......@@ -66,7 +66,7 @@ nm_device_vlan_get_hw_address (NMDeviceVlan *device)
{
g_return_val_if_fail (NM_IS_DEVICE_VLAN (device), NULL);
return NM_DEVICE_VLAN_GET_PRIVATE (device)->hw_address;
return nm_str_not_empty (NM_DEVICE_VLAN_GET_PRIVATE (device)->hw_address);
}
/**
......
......@@ -95,7 +95,7 @@ nm_device_vxlan_get_hw_address (NMDeviceVxlan *device)
{
g_return_val_if_fail (NM_IS_DEVICE_VXLAN (device), NULL);
return NM_DEVICE_VXLAN_GET_PRIVATE (device)->hw_address;
return nm_str_not_empty (NM_DEVICE_VXLAN_GET_PRIVATE (device)->hw_address);
}
/**
......@@ -162,7 +162,7 @@ nm_device_vxlan_get_group (NMDeviceVxlan *device)
{
g_return_val_if_fail (NM_IS_DEVICE_VXLAN (device), NULL);
return NM_DEVICE_VXLAN_GET_PRIVATE (device)->group;
return nm_str_not_empty (NM_DEVICE_VXLAN_GET_PRIVATE (device)->group);
}
/**
......@@ -178,7 +178,7 @@ nm_device_vxlan_get_local (NMDeviceVxlan *device)
{
g_return_val_if_fail (NM_IS_DEVICE_VXLAN (device), NULL);
return NM_DEVICE_VXLAN_GET_PRIVATE (device)->local;
return nm_str_not_empty (NM_DEVICE_VXLAN_GET_PRIVATE (device)->local);
}
/**
......
......@@ -100,7 +100,7 @@ nm_device_wifi_get_hw_address (NMDeviceWifi *device)
{
g_return_val_if_fail (NM_IS_DEVICE_WIFI (device), NULL);
return NM_DEVICE_WIFI_GET_PRIVATE (device)->hw_address;
return nm_str_not_empty (NM_DEVICE_WIFI_GET_PRIVATE (device)->hw_address);
}
/**
......@@ -117,7 +117,7 @@ nm_device_wifi_get_permanent_hw_address (NMDeviceWifi *device)
{
g_return_val_if_fail (NM_IS_DEVICE_WIFI (device), NULL);
return NM_DEVICE_WIFI_GET_PRIVATE (device)->perm_hw_address;
return nm_str_not_empty (NM_DEVICE_WIFI_GET_PRIVATE (device)->perm_hw_address);
}
/**
......
......@@ -91,7 +91,7 @@ nm_device_wimax_get_hw_address (NMDeviceWimax *wimax)
{
g_return_val_if_fail (NM_IS_DEVICE_WIMAX (wimax), NULL);
return NM_DEVICE_WIMAX_GET_PRIVATE (wimax)->hw_address;
return nm_str_not_empty (NM_DEVICE_WIMAX_GET_PRIVATE (wimax)->hw_address);
}
/**
......@@ -300,7 +300,7 @@ nm_device_wimax_get_bsid (NMDeviceWimax *self)
{
g_return_val_if_fail (NM_IS_DEVICE_WIMAX (self), NULL);
return NM_DEVICE_WIMAX_GET_PRIVATE (self)->bsid;
return nm_str_not_empty (NM_DEVICE_WIMAX_GET_PRIVATE (self)->bsid);
}
static gboolean
......
......@@ -996,7 +996,7 @@ nm_device_get_iface (NMDevice *device)
{
g_return_val_if_fail (NM_IS_DEVICE (device), NULL);
return NM_DEVICE_GET_PRIVATE (device)->iface;
return nm_str_not_empty (NM_DEVICE_GET_PRIVATE (device)->iface);
}
/**
......@@ -1014,7 +1014,7 @@ nm_device_get_ip_iface (NMDevice *device)
{
g_return_val_if_fail (NM_IS_DEVICE (device), NULL);
return NM_DEVICE_GET_PRIVATE (device)->ip_iface;
return nm_str_not_empty (NM_DEVICE_GET_PRIVATE (device)->ip_iface);
}
/**
......@@ -1048,7 +1048,7 @@ nm_device_get_udi (NMDevice *device)
{
g_return_val_if_fail (NM_IS_DEVICE (device), NULL);
return NM_DEVICE_GET_PRIVATE (device)->udi;
return nm_str_not_empty (NM_DEVICE_GET_PRIVATE (device)->udi);
}
/**
......@@ -1065,7 +1065,7 @@ nm_device_get_driver (NMDevice *device)
{
g_return_val_if_fail (NM_IS_DEVICE (device), NULL);
return NM_DEVICE_GET_PRIVATE (device)->driver;
return nm_str_not_empty (NM_DEVICE_GET_PRIVATE (device)->driver);
}
/**
......@@ -1082,7 +1082,7 @@ nm_device_get_driver_version (NMDevice *device)
{
g_return_val_if_fail (NM_IS_DEVICE (device), NULL);
return NM_DEVICE_GET_PRIVATE (device)->driver_version;
return nm_str_not_empty (NM_DEVICE_GET_PRIVATE (device)->driver_version);
}
/**
......@@ -1099,7 +1099,7 @@ nm_device_get_firmware_version (NMDevice *device)
{
g_return_val_if_fail (NM_IS_DEVICE (device), NULL);
return NM_DEVICE_GET_PRIVATE (device)->firmware_version;
return nm_str_not_empty (NM_DEVICE_GET_PRIVATE (device)->firmware_version);
}
/**
......@@ -1124,7 +1124,7 @@ nm_device_get_type_description (NMDevice *device)
g_return_val_if_fail (NM_IS_DEVICE (device), NULL);
if (priv->type_description)
return priv->type_description;
return nm_str_not_empty (priv->type_description);
if (NM_DEVICE_GET_CLASS (device)->get_type_description) {
desc = NM_DEVICE_GET_CLASS (device)->get_type_description (device);
......@@ -1137,7 +1137,7 @@ nm_device_get_type_description (NMDevice *device)
typename += 8;
priv->type_description = g_ascii_strdown (typename, -1);
return priv->type_description;
return nm_str_not_empty (priv->type_description);
}
/**
......
......@@ -395,7 +395,7 @@ nm_ip_config_get_gateway (NMIPConfig *config)
{
g_return_val_if_fail (NM_IS_IP_CONFIG (config), NULL);
return NM_IP_CONFIG_GET_PRIVATE (config)->gateway;
return nm_str_not_empty (NM_IP_CONFIG_GET_PRIVATE (config)->gateway);
}
/**
......
......@@ -382,7 +382,7 @@ nm_manager_get_version (NMManager *manager)
{
g_return_val_if_fail (NM_IS_MANAGER (manager), NULL);
return NM_MANAGER_GET_PRIVATE (manager)->version;
return nm_str_not_empty (NM_MANAGER_GET_PRIVATE (manager)->version);
}
NMState
......
......@@ -79,7 +79,7 @@ nm_vpn_connection_get_banner (NMVpnConnection *vpn)
if (priv->vpn_state != NM_VPN_CONNECTION_STATE_ACTIVATED)
return NULL;
return priv->banner;
return nm_str_not_empty (priv->banner);
}
/**
......
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