diff options
author | Thomas Haller <thaller@redhat.com> | 2019-09-30 08:26:30 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2019-09-30 08:26:30 +0200 |
commit | e54047608e803e380418c66363cd3ccba45f89b5 (patch) | |
tree | 58943bd6133d67bf1e8a9eceb0f162468c2e2cdb | |
parent | dce1aa87c28a7ecd4611984d543295e8623a1331 (diff) | |
parent | 29a451d33a3630f034c9394ef376dc4887177bfe (diff) | |
download | NetworkManager-e54047608e803e380418c66363cd3ccba45f89b5.tar.gz |
libnm: merge branch 'th/libnm-properties-override'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/283
34 files changed, 629 insertions, 697 deletions
diff --git a/libnm-core/nm-core-internal.h b/libnm-core/nm-core-internal.h index 9f4f19839f..97c7f94546 100644 --- a/libnm-core/nm-core-internal.h +++ b/libnm-core/nm-core-internal.h @@ -712,10 +712,7 @@ typedef void (*NMSettInfoPropGPropFromDBusFcn) (GVariant *from, const NMSettInfoSetting *nmtst_sett_info_settings (void); -struct _NMSettInfoProperty { - const char *name; - GParamSpec *param_spec; - +typedef struct { const GVariantType *dbus_type; NMSettInfoPropToDBusFcn to_dbus_fcn; @@ -726,6 +723,14 @@ struct _NMSettInfoProperty { * on the GValue value of the GObject property. */ NMSettInfoPropGPropToDBusFcn gprop_to_dbus_fcn; NMSettInfoPropGPropFromDBusFcn gprop_from_dbus_fcn; +} NMSettInfoPropertType; + +struct _NMSettInfoProperty { + const char *name; + + GParamSpec *param_spec; + + const NMSettInfoPropertType *property_type; }; typedef struct { diff --git a/libnm-core/nm-setting-bluetooth.c b/libnm-core/nm-setting-bluetooth.c index 2d9e72c100..2b93494e6a 100644 --- a/libnm-core/nm-setting-bluetooth.c +++ b/libnm-core/nm-setting-bluetooth.c @@ -295,12 +295,7 @@ nm_setting_bluetooth_class_init (NMSettingBluetoothClass *klass) G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); - - _properties_override_add_transform (properties_override, - obj_properties[PROP_BDADDR], - G_VARIANT_TYPE_BYTESTRING, - _nm_utils_hwaddr_to_dbus, - _nm_utils_hwaddr_from_dbus); + _nm_properties_override_gobj (properties_override, obj_properties[PROP_BDADDR], &nm_sett_info_propert_type_mac_addrees); /** * NMSettingBluetooth:type: diff --git a/libnm-core/nm-setting-bond.c b/libnm-core/nm-setting-bond.c index 100951d86a..fad09f4314 100644 --- a/libnm-core/nm-setting-bond.c +++ b/libnm-core/nm-setting-bond.c @@ -970,12 +970,7 @@ nm_setting_bond_class_init (NMSettingBondClass *klass) G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); - - _properties_override_add_transform (properties_override, - obj_properties[PROP_OPTIONS], - G_VARIANT_TYPE ("a{ss}"), - _nm_utils_strdict_to_dbus, - _nm_utils_strdict_from_dbus); + _nm_properties_override_gobj (properties_override, obj_properties[PROP_OPTIONS], &nm_sett_info_propert_type_strdict); /* ---dbus--- * property: interface-name @@ -985,11 +980,7 @@ nm_setting_bond_class_init (NMSettingBondClass *klass) * bond's interface name. * ---end--- */ - _properties_override_add_dbus_only (properties_override, - "interface-name", - G_VARIANT_TYPE_STRING, - _nm_setting_get_deprecated_virtual_interface_name, - NULL); + _nm_properties_override_dbus (properties_override, "interface-name", &nm_sett_info_propert_type_deprecated_interface_name); g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties); diff --git a/libnm-core/nm-setting-bridge-port.c b/libnm-core/nm-setting-bridge-port.c index 1e4112496d..f5f6da248a 100644 --- a/libnm-core/nm-setting-bridge-port.c +++ b/libnm-core/nm-setting-bridge-port.c @@ -573,17 +573,10 @@ nm_setting_bridge_port_class_init (NMSettingBridgePortClass *klass) G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); - - _properties_override_add_override (properties_override, - obj_properties[PROP_VLANS], - G_VARIANT_TYPE ("aa{sv}"), - _nm_utils_bridge_vlans_to_dbus, - _nm_utils_bridge_vlans_from_dbus, - NULL); + _nm_properties_override_gobj (properties_override, obj_properties[PROP_VLANS], &nm_sett_info_propert_type_bridge_vlans); g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties); _nm_setting_class_commit_full (setting_class, NM_META_SETTING_TYPE_BRIDGE_PORT, NULL, properties_override); - } diff --git a/libnm-core/nm-setting-bridge.c b/libnm-core/nm-setting-bridge.c index ab4d227888..a8cd4a1b43 100644 --- a/libnm-core/nm-setting-bridge.c +++ b/libnm-core/nm-setting-bridge.c @@ -1209,12 +1209,7 @@ nm_setting_bridge_class_init (NMSettingBridgeClass *klass) G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); - - _properties_override_add_transform (properties_override, - obj_properties[PROP_MAC_ADDRESS], - G_VARIANT_TYPE_BYTESTRING, - _nm_utils_hwaddr_to_dbus, - _nm_utils_hwaddr_from_dbus); + _nm_properties_override_gobj (properties_override, obj_properties[PROP_MAC_ADDRESS], &nm_sett_info_propert_type_mac_addrees); /** * NMSettingBridge:stp: @@ -1466,13 +1461,7 @@ nm_setting_bridge_class_init (NMSettingBridgeClass *klass) G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); - - _properties_override_add_override (properties_override, - obj_properties[PROP_VLANS], - G_VARIANT_TYPE ("aa{sv}"), - _nm_utils_bridge_vlans_to_dbus, - _nm_utils_bridge_vlans_from_dbus, - NULL); + _nm_properties_override_gobj (properties_override, obj_properties[PROP_VLANS], &nm_sett_info_propert_type_bridge_vlans); /* ---dbus--- * property: interface-name @@ -1482,11 +1471,7 @@ nm_setting_bridge_class_init (NMSettingBridgeClass *klass) * bridge's interface name. * ---end--- */ - _properties_override_add_dbus_only (properties_override, - "interface-name", - G_VARIANT_TYPE_STRING, - _nm_setting_get_deprecated_virtual_interface_name, - NULL); + _nm_properties_override_dbus (properties_override, "interface-name", &nm_sett_info_propert_type_deprecated_interface_name); g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties); diff --git a/libnm-core/nm-setting-connection.c b/libnm-core/nm-setting-connection.c index d1e58b1fde..d29a189b26 100644 --- a/libnm-core/nm-setting-connection.c +++ b/libnm-core/nm-setting-connection.c @@ -1735,13 +1735,13 @@ nm_setting_connection_class_init (NMSettingConnectionClass *klass) G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); - - _properties_override_add_override (properties_override, - obj_properties[PROP_INTERFACE_NAME], - G_VARIANT_TYPE_STRING, - NULL, - nm_setting_connection_set_interface_name, - nm_setting_connection_no_interface_name); + _nm_properties_override_gobj (properties_override, + obj_properties[PROP_INTERFACE_NAME], + NM_SETT_INFO_PROPERT_TYPE ( + .dbus_type = G_VARIANT_TYPE_STRING, + .from_dbus_fcn = nm_setting_connection_set_interface_name, + .missing_from_dbus_fcn = nm_setting_connection_no_interface_name, + )); /** * NMSettingConnection:type: @@ -1920,13 +1920,12 @@ nm_setting_connection_class_init (NMSettingConnectionClass *klass) G_PARAM_CONSTRUCT | NM_SETTING_PARAM_FUZZY_IGNORE | G_PARAM_STATIC_STRINGS); - - _properties_override_add_override (properties_override, - obj_properties[PROP_TIMESTAMP], - G_VARIANT_TYPE_UINT64, - _to_dbus_fcn_timestamp, - NULL, - NULL); + _nm_properties_override_gobj (properties_override, + obj_properties[PROP_TIMESTAMP], + NM_SETT_INFO_PROPERT_TYPE ( + .dbus_type = G_VARIANT_TYPE_UINT64, + .to_dbus_fcn = _to_dbus_fcn_timestamp, + )); /** * NMSettingConnection:read-only: diff --git a/libnm-core/nm-setting-dcb.c b/libnm-core/nm-setting-dcb.c index aa45668ff5..c3b512ce17 100644 --- a/libnm-core/nm-setting-dcb.c +++ b/libnm-core/nm-setting-dcb.c @@ -743,6 +743,12 @@ _nm_setting_dcb_uint_array_from_dbus (GVariant *dbus_value, set_gvalue_from_array (prop_value, (guint *) array, length); } +static const NMSettInfoPropertType nm_sett_info_propert_type_dcb_au = { + .dbus_type = NM_G_VARIANT_TYPE ("au"), + .gprop_to_dbus_fcn = _nm_setting_dcb_uint_array_to_dbus, + .gprop_from_dbus_fcn = _nm_setting_dcb_uint_array_from_dbus, +}; + /*****************************************************************************/ static void @@ -1097,12 +1103,7 @@ nm_setting_dcb_class_init (NMSettingDcbClass *klass) G_TYPE_ARRAY, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - - _properties_override_add_transform (properties_override, - obj_properties[PROP_PRIORITY_FLOW_CONTROL], - G_VARIANT_TYPE ("au"), - _nm_setting_dcb_uint_array_to_dbus, - _nm_setting_dcb_uint_array_from_dbus); + _nm_properties_override_gobj (properties_override, obj_properties[PROP_PRIORITY_FLOW_CONTROL], &nm_sett_info_propert_type_dcb_au); /** * NMSettingDcb:priority-group-flags: @@ -1145,12 +1146,7 @@ nm_setting_dcb_class_init (NMSettingDcbClass *klass) G_TYPE_ARRAY, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - - _properties_override_add_transform (properties_override, - obj_properties[PROP_PRIORITY_GROUP_ID], - G_VARIANT_TYPE ("au"), - _nm_setting_dcb_uint_array_to_dbus, - _nm_setting_dcb_uint_array_from_dbus); + _nm_properties_override_gobj (properties_override, obj_properties[PROP_PRIORITY_GROUP_ID], &nm_sett_info_propert_type_dcb_au); /** * NMSettingDcb:priority-group-bandwidth: (type GArray(guint)) @@ -1172,12 +1168,7 @@ nm_setting_dcb_class_init (NMSettingDcbClass *klass) G_TYPE_ARRAY, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - - _properties_override_add_transform (properties_override, - obj_properties[PROP_PRIORITY_GROUP_BANDWIDTH], - G_VARIANT_TYPE ("au"), - _nm_setting_dcb_uint_array_to_dbus, - _nm_setting_dcb_uint_array_from_dbus); + _nm_properties_override_gobj (properties_override, obj_properties[PROP_PRIORITY_GROUP_BANDWIDTH], &nm_sett_info_propert_type_dcb_au); /** * NMSettingDcb:priority-bandwidth: (type GArray(guint)) @@ -1201,12 +1192,7 @@ nm_setting_dcb_class_init (NMSettingDcbClass *klass) G_TYPE_ARRAY, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - - _properties_override_add_transform (properties_override, - obj_properties[PROP_PRIORITY_BANDWIDTH], - G_VARIANT_TYPE ("au"), - _nm_setting_dcb_uint_array_to_dbus, - _nm_setting_dcb_uint_array_from_dbus); + _nm_properties_override_gobj (properties_override, obj_properties[PROP_PRIORITY_BANDWIDTH], &nm_sett_info_propert_type_dcb_au); /** * NMSettingDcb:priority-strict-bandwidth: (type GArray(gboolean)) @@ -1228,12 +1214,7 @@ nm_setting_dcb_class_init (NMSettingDcbClass *klass) G_TYPE_ARRAY, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - - _properties_override_add_transform (properties_override, - obj_properties[PROP_PRIORITY_STRICT_BANDWIDTH], - G_VARIANT_TYPE ("au"), - _nm_setting_dcb_uint_array_to_dbus, - _nm_setting_dcb_uint_array_from_dbus); + _nm_properties_override_gobj (properties_override, obj_properties[PROP_PRIORITY_STRICT_BANDWIDTH], &nm_sett_info_propert_type_dcb_au); /** * NMSettingDcb:priority-traffic-class: (type GArray(guint)) @@ -1254,12 +1235,7 @@ nm_setting_dcb_class_init (NMSettingDcbClass *klass) G_TYPE_ARRAY, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - - _properties_override_add_transform (properties_override, - obj_properties[PROP_PRIORITY_TRAFFIC_CLASS], - G_VARIANT_TYPE ("au"), - _nm_setting_dcb_uint_array_to_dbus, - _nm_setting_dcb_uint_array_from_dbus); + _nm_properties_override_gobj (properties_override, obj_properties[PROP_PRIORITY_TRAFFIC_CLASS], &nm_sett_info_propert_type_dcb_au); g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties); diff --git a/libnm-core/nm-setting-gsm.c b/libnm-core/nm-setting-gsm.c index b4ca97e6d8..07906d0336 100644 --- a/libnm-core/nm-setting-gsm.c +++ b/libnm-core/nm-setting-gsm.c @@ -847,17 +847,8 @@ nm_setting_gsm_class_init (NMSettingGsmClass *klass) G_PARAM_STATIC_STRINGS); /* Ignore incoming deprecated properties */ - _properties_override_add_dbus_only (properties_override, - "allowed-bands", - G_VARIANT_TYPE_UINT32, - NULL, - NULL); - - _properties_override_add_dbus_only (properties_override, - "network-type", - G_VARIANT_TYPE_INT32, - NULL, - NULL); + _nm_properties_override_dbus (properties_override, "allowed-bands", &nm_sett_info_propert_type_deprecated_ignore_u); + _nm_properties_override_dbus (properties_override, "network-type", &nm_sett_info_propert_type_deprecated_ignore_i); g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties); diff --git a/libnm-core/nm-setting-infiniband.c b/libnm-core/nm-setting-infiniband.c index ddfdc8ab75..f06c616fd7 100644 --- a/libnm-core/nm-setting-infiniband.c +++ b/libnm-core/nm-setting-infiniband.c @@ -414,12 +414,7 @@ nm_setting_infiniband_class_init (NMSettingInfinibandClass *klass) G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); - - _properties_override_add_transform (properties_override, - obj_properties[PROP_MAC_ADDRESS], - G_VARIANT_TYPE_BYTESTRING, - _nm_utils_hwaddr_to_dbus, - _nm_utils_hwaddr_from_dbus); + _nm_properties_override_gobj (properties_override, obj_properties[PROP_MAC_ADDRESS], &nm_sett_info_propert_type_mac_addrees); /** * NMSettingInfiniband:mtu: diff --git a/libnm-core/nm-setting-ip-config.c b/libnm-core/nm-setting-ip-config.c index de367b2d31..9fc2206f8c 100644 --- a/libnm-core/nm-setting-ip-config.c +++ b/libnm-core/nm-setting-ip-config.c @@ -5194,12 +5194,12 @@ _nm_sett_info_property_override_create_array_ip_config (void) { GArray *properties_override = _nm_sett_info_property_override_create_array (); - _properties_override_add_override (properties_override, - obj_properties[PROP_GATEWAY], - G_VARIANT_TYPE_STRING, - NULL, - ip_gateway_set, - NULL); + _nm_properties_override_gobj (properties_override, + obj_properties[PROP_GATEWAY], + NM_SETT_INFO_PROPERT_TYPE ( + .dbus_type = G_VARIANT_TYPE_STRING, + .from_dbus_fcn = ip_gateway_set, + )); /* ---dbus--- * property: routing-rules @@ -5207,11 +5207,13 @@ _nm_sett_info_property_override_create_array_ip_config (void) * description: Array of dictionaries for routing rules. * ---end--- */ - _properties_override_add_dbus_only (properties_override, - NM_SETTING_IP_CONFIG_ROUTING_RULES, - G_VARIANT_TYPE ("aa{sv}"), - _routing_rules_dbus_only_synth, - _routing_rules_dbus_only_set); + _nm_properties_override_dbus (properties_override, + NM_SETTING_IP_CONFIG_ROUTING_RULES, + NM_SETT_INFO_PROPERT_TYPE ( + .dbus_type = NM_G_VARIANT_TYPE ("aa{sv}"), + .to_dbus_fcn = _routing_rules_dbus_only_synth, + .from_dbus_fcn = _routing_rules_dbus_only_set, + )); return properties_override; } diff --git a/libnm-core/nm-setting-ip4-config.c b/libnm-core/nm-setting-ip4-config.c index 9df80d1f04..1a92019b34 100644 --- a/libnm-core/nm-setting-ip4-config.c +++ b/libnm-core/nm-setting-ip4-config.c @@ -796,12 +796,14 @@ nm_setting_ip4_config_class_init (NMSettingIP4ConfigClass *klass) * integers) * ---end--- */ - _properties_override_add_transform (properties_override, - g_object_class_find_property (G_OBJECT_CLASS (setting_class), - NM_SETTING_IP_CONFIG_DNS), - G_VARIANT_TYPE ("au"), - ip4_dns_to_dbus, - ip4_dns_from_dbus); + _nm_properties_override_gobj (properties_override, + g_object_class_find_property (G_OBJECT_CLASS (setting_class), + NM_SETTING_IP_CONFIG_DNS), + NM_SETT_INFO_PROPERT_TYPE ( + .dbus_type = NM_G_VARIANT_TYPE ("au"), + .gprop_to_dbus_fcn = ip4_dns_to_dbus, + .gprop_from_dbus_fcn = ip4_dns_from_dbus, + )); /* ---dbus--- * property: addresses @@ -818,19 +820,20 @@ nm_setting_ip4_config_class_init (NMSettingIP4ConfigClass *klass) * for that subnet. * ---end--- */ - _properties_override_add_override (properties_override, - g_object_class_find_property (G_OBJECT_CLASS (setting_class), - NM_SETTING_IP_CONFIG_ADDRESSES), - G_VARIANT_TYPE ("aau"), - ip4_addresses_get, - ip4_addresses_set, - NULL); - - _properties_override_add_dbus_only (properties_override, - "address-labels", - G_VARIANT_TYPE_STRING_ARRAY, - ip4_address_labels_get, - NULL); + _nm_properties_override_gobj (properties_override, + g_object_class_find_property (G_OBJECT_CLASS (setting_class), + NM_SETTING_IP_CONFIG_ADDRESSES), + NM_SETT_INFO_PROPERT_TYPE ( + .dbus_type = NM_G_VARIANT_TYPE ("aau"), + .to_dbus_fcn = ip4_addresses_get, + .from_dbus_fcn = ip4_addresses_set, + )); + _nm_properties_override_dbus (properties_override, + "address-labels", + NM_SETT_INFO_PROPERT_TYPE ( + .dbus_type = G_VARIANT_TYPE_STRING_ARRAY, + .to_dbus_fcn = ip4_address_labels_get, + )); /* ---dbus--- * property: address-data @@ -841,11 +844,13 @@ nm_setting_ip4_config_class_init (NMSettingIP4ConfigClass *klass) * also exist on some addresses. * ---end--- */ - _properties_override_add_dbus_only (properties_override, - "address-data", - G_VARIANT_TYPE ("aa{sv}"), - ip4_address_data_get, - ip4_address_data_set); + _nm_properties_override_dbus (properties_override, + "address-data", + NM_SETT_INFO_PROPERT_TYPE ( + .dbus_type = NM_G_VARIANT_TYPE ("aa{sv}"), + .to_dbus_fcn = ip4_address_data_get, + .from_dbus_fcn = ip4_address_data_set, + )); /* ---dbus--- * property: routes @@ -864,13 +869,14 @@ nm_setting_ip4_config_class_init (NMSettingIP4ConfigClass *klass) * property.) * ---end--- */ - _properties_override_add_override (properties_override, - g_object_class_find_property (G_OBJECT_CLASS (setting_class), - NM_SETTING_IP_CONFIG_ROUTES), - G_VARIANT_TYPE ("aau"), - ip4_routes_get, - ip4_routes_set, - NULL); + _nm_properties_override_gobj (properties_override, + g_object_class_find_property (G_OBJECT_CLASS (setting_class), + NM_SETTING_IP_CONFIG_ROUTES), + NM_SETT_INFO_PROPERT_TYPE ( + .dbus_type = NM_G_VARIANT_TYPE ("aau"), + .to_dbus_fcn = ip4_routes_get, + .from_dbus_fcn = ip4_routes_set, + )); /* ---dbus--- * property: route-data @@ -885,11 +891,13 @@ nm_setting_ip4_config_class_init (NMSettingIP4ConfigClass *klass) * also exist on some routes. * ---end--- */ - _properties_override_add_dbus_only (properties_override, - "route-data", - G_VARIANT_TYPE ("aa{sv}"), - ip4_route_data_get, - ip4_route_data_set); + _nm_properties_override_dbus (properties_override, + "route-data", + NM_SETT_INFO_PROPERT_TYPE ( + .dbus_type = NM_G_VARIANT_TYPE ("aa{sv}"), + .to_dbus_fcn = ip4_route_data_get, + .from_dbus_fcn = ip4_route_data_set, + )); g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties); diff --git a/libnm-core/nm-setting-ip6-config.c b/libnm-core/nm-setting-ip6-config.c index b19ec126ed..b326b83ced 100644 --- a/libnm-core/nm-setting-ip6-config.c +++ b/libnm-core/nm-setting-ip6-config.c @@ -880,12 +880,14 @@ nm_setting_ip6_config_class_init (NMSettingIP6ConfigClass *klass) * description: Array of IP addresses of DNS servers (in network byte order) * ---end--- */ - _properties_override_add_transform (properties_override, - g_object_class_find_property (G_OBJECT_CLASS (setting_class), - NM_SETTING_IP_CONFIG_DNS), - G_VARIANT_TYPE ("aay"), - ip6_dns_to_dbus, - ip6_dns_from_dbus); + _nm_properties_override_gobj (properties_override, + g_object_class_find_property (G_OBJECT_CLASS (setting_class), + NM_SETTING_IP_CONFIG_DNS), + NM_SETT_INFO_PROPERT_TYPE ( + .dbus_type = NM_G_VARIANT_TYPE ("aay"), + .gprop_to_dbus_fcn = ip6_dns_to_dbus, + .gprop_from_dbus_fcn = ip6_dns_from_dbus, + )); /* ---dbus--- * property: addresses @@ -901,13 +903,14 @@ nm_setting_ip6_config_class_init (NMSettingIP6ConfigClass *klass) * that subnet. * ---end--- */ - _properties_override_add_override (properties_override, - g_object_class_find_property (G_OBJECT_CLASS (setting_class), - NM_SETTING_IP_CONFIG_ADDRESSES), - G_VARIANT_TYPE ("a(ayuay)"), - ip6_addresses_get, - ip6_addresses_set, - NULL); + _nm_properties_override_gobj (properties_override, + g_object_class_find_property (G_OBJECT_CLASS (setting_class), + NM_SETTING_IP_CONFIG_ADDRESSES), + NM_SETT_INFO_PROPERT_TYPE ( + .dbus_type = NM_G_VARIANT_TYPE ("a(ayuay)"), + .to_dbus_fcn = ip6_addresses_get, + .from_dbus_fcn = ip6_addresses_set, + )); /* ---dbus--- * property: address-data @@ -918,11 +921,13 @@ nm_setting_ip6_config_class_init (NMSettingIP6ConfigClass *klass) * also exist on some addresses. * ---end--- */ - _properties_override_add_dbus_only (properties_override, - "address-data", - G_VARIANT_TYPE ("aa{sv}"), - ip6_address_data_get, - ip6_address_data_set); + _nm_properties_override_dbus (properties_override, + "address-data", + NM_SETT_INFO_PROPERT_TYPE ( + .dbus_type = NM_G_VARIANT_TYPE ("aa{sv}"), + .to_dbus_fcn = ip6_address_data_get, + .from_dbus_fcn = ip6_address_data_set, + )); /* ---dbus--- * property: routes @@ -938,13 +943,14 @@ nm_setting_ip6_config_class_init (NMSettingIP6ConfigClass *klass) * default metric for the device. * ---end--- */ - _properties_override_add_override (properties_override, - g_object_class_find_property (G_OBJECT_CLASS (setting_class), - NM_SETTING_IP_CONFIG_ROUTES), - G_VARIANT_TYPE ("a(ayuayu)"), - ip6_routes_get, - ip6_routes_set, - NULL); + _nm_properties_override_gobj (properties_override, + g_object_class_find_property (G_OBJECT_CLASS (setting_class), + NM_SETTING_IP_CONFIG_ROUTES), + NM_SETT_INFO_PROPERT_TYPE ( + .dbus_type = NM_G_VARIANT_TYPE ("a(ayuayu)"), + .to_dbus_fcn = ip6_routes_get, + .from_dbus_fcn = ip6_routes_set, + )); /* ---dbus--- * property: route-data @@ -959,11 +965,13 @@ nm_setting_ip6_config_class_init (NMSettingIP6ConfigClass *klass) * also exist on some routes. * ---end--- */ - _properties_override_add_dbus_only (properties_override, - "route-data", - G_VARIANT_TYPE ("aa{sv}"), - ip6_route_data_get, - ip6_route_data_set); + _nm_properties_override_dbus (properties_override, + "route-data", + NM_SETT_INFO_PROPERT_TYPE ( + .dbus_type = NM_G_VARIANT_TYPE ("aa{sv}"), + .to_dbus_fcn = ip6_route_data_get, + .from_dbus_fcn = ip6_route_data_set, + )); g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties); diff --git a/libnm-core/nm-setting-olpc-mesh.c b/libnm-core/nm-setting-olpc-mesh.c index b88b458f3a..b104b352dc 100644 --- a/libnm-core/nm-setting-olpc-mesh.c +++ b/libnm-core/nm-setting-olpc-mesh.c @@ -250,12 +250,7 @@ nm_setting_olpc_mesh_class_init (NMSettingOlpcMeshClass *klass) NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - - _properties_override_add_transform (properties_override, - obj_properties[PROP_DHCP_ANYCAST_ADDRESS], - G_VARIANT_TYPE_BYTESTRING, - _nm_utils_hwaddr_to_dbus, - _nm_utils_hwaddr_from_dbus); + _nm_properties_override_gobj (properties_override, obj_properties[PROP_DHCP_ANYCAST_ADDRESS], &nm_sett_info_propert_type_mac_addrees); g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties); diff --git a/libnm-core/nm-setting-private.h b/libnm-core/nm-setting-private.h index deb82c17d2..a85237e0bb 100644 --- a/libnm-core/nm-setting-private.h +++ b/libnm-core/nm-setting-private.h @@ -67,14 +67,16 @@ gboolean _nm_setting_clear_secrets (NMSetting *setting, */ #define NM_SETTING_PARAM_REAPPLY_IMMEDIATELY (1 << (6 + G_PARAM_USER_SHIFT)) -#define NM_SETTING_PARAM_GENDATA_BACKED (1 << (7 + G_PARAM_USER_SHIFT)) +/* property_to_dbus() should ignore the property flags, and instead always calls to_dbus_fcn() + */ +#define NM_SETTING_PARAM_TO_DBUS_IGNORE_FLAGS (1 << (7 + G_PARAM_USER_SHIFT)) + +extern const NMSettInfoPropertType nm_sett_info_propert_type_deprecated_interface_name; +extern const NMSettInfoPropertType nm_sett_info_propert_type_deprecated_ignore_i; +extern const NMSettInfoPropertType nm_sett_info_propert_type_deprecated_ignore_u; -GVariant *_nm_setting_get_deprecated_virtual_interface_name (const NMSettInfoSetting *sett_info, - guint property_idx, - NMConnection *connection, - NMSetting *setting, - NMConnectionSerializationFlags flags, - const NMConnectionSerializationOptions *options); +extern const NMSettInfoPropertType nm_sett_info_propert_type_plain_i; +extern const NMSettInfoPropertType nm_sett_info_propert_type_plain_u; NMSettingVerifyResult _nm_setting_verify (NMSetting *setting, NMConnection *connection, @@ -143,40 +145,44 @@ _nm_setting_class_commit (NMSettingClass *setting_class, __VA_ARGS__ \ })) +#define NM_SETT_INFO_PROPERT_TYPE(...) \ + ({ \ + static const NMSettInfoPropertType _g = { \ + __VA_ARGS__ \ + }; \ + \ + &_g; \ + }) + #define NM_SETT_INFO_PROPERTY(...) \ (&((const NMSettInfoProperty) { \ __VA_ARGS__ \ })) -void _properties_override_add_struct (GArray *properties_override, - const NMSettInfoProperty *prop_info); - -void _properties_override_add__helper (GArray *properties_override, - NMSettInfoProperty *prop_info); - -#define _properties_override_add(properties_override, \ - ...) \ - (_properties_override_add_struct (properties_override, \ - NM_SETT_INFO_PROPERTY (__VA_ARGS__))) - -void _properties_override_add_dbus_only (GArray *properties_override, - const char *property_name, - const GVariantType *dbus_type, - NMSettInfoPropToDBusFcn to_dbus_fcn, - NMSettInfoPropFromDBusFcn from_dbus_fcn); - -void _properties_override_add_override (GArray *properties_override, - GParamSpec *param_spec, - const GVariantType *dbus_type, - NMSettInfoPropToDBusFcn to_dbus_fcn, - NMSettInfoPropFromDBusFcn from_dbus_fcn, - NMSettInfoPropMissingFromDBusFcn missing_from_dbus_fcn); - -void _properties_override_add_transform (GArray *properties_override, - GParamSpec *param_spec, - const GVariantType *dbus_type, - NMSettInfoPropGPropToDBusFcn gprop_to_dbus_fcn, - NMSettInfoPropGPropFromDBusFcn gprop_from_dbus_fcn); +gboolean _nm_properties_override_assert (const NMSettInfoProperty *prop_info); + +static inline void +_nm_properties_override (GArray *properties_override, + const NMSettInfoProperty *prop_info) +{ + nm_assert (properties_override); + nm_assert (_nm_properties_override_assert (prop_info)); + g_array_append_vals (properties_override, prop_info, 1); +} + +#define _nm_properties_override_gobj(properties_override, p_param_spec, p_property_type) \ + _nm_properties_override ((properties_override), \ + NM_SETT_INFO_PROPERTY ( \ + .param_spec = (p_param_spec), \ + .property_type = (p_property_type), \ + )) + +#define _nm_properties_override_dbus(properties_override, p_name, p_property_type) \ + _nm_properties_override ((properties_override), \ + NM_SETT_INFO_PROPERTY ( \ + .name = (""p_name""), \ + .property_type = (p_property_type), \ + )) /*****************************************************************************/ diff --git a/libnm-core/nm-setting-serial.c b/libnm-core/nm-setting-serial.c index 1f7f3c3c62..8b10323838 100644 --- a/libnm-core/nm-setting-serial.c +++ b/libnm-core/nm-setting-serial.c @@ -288,12 +288,13 @@ nm_setting_serial_class_init (NMSettingSerialClass *klass) G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS); - - _properties_override_add_transform (properties_override, - obj_properties[PROP_PARITY], - G_VARIANT_TYPE_BYTE, - parity_to_dbus, - parity_from_dbus); + _nm_properties_override_gobj (properties_override, + obj_properties[PROP_PARITY], + NM_SETT_INFO_PROPERT_TYPE ( + .dbus_type = G_VARIANT_TYPE_BYTE, + .gprop_to_dbus_fcn = parity_to_dbus, + .gprop_from_dbus_fcn = parity_from_dbus, + )); /** * NMSettingSerial:stopbits: diff --git a/libnm-core/nm-setting-sriov.c b/libnm-core/nm-setting-sriov.c index b9ac21bfcc..e7f8632e41 100644 --- a/libnm-core/nm-setting-sriov.c +++ b/libnm-core/nm-setting-sriov.c @@ -1326,13 +1326,13 @@ nm_setting_sriov_class_init (NMSettingSriovClass *klass) G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); - - _properties_override_add_override (properties_override, - obj_properties[PROP_VFS], - G_VARIANT_TYPE ("aa{sv}"), - vfs_to_dbus, - vfs_from_dbus, - NULL); + _nm_properties_override_gobj (properties_override, + obj_properties[PROP_VFS], + NM_SETT_INFO_PROPERT_TYPE ( + .dbus_type = NM_G_VARIANT_TYPE ("aa{sv}"), + .to_dbus_fcn = vfs_to_dbus, + .from_dbus_fcn = vfs_from_dbus, + )); /** * NMSettingSriov:autoprobe-drivers diff --git a/libnm-core/nm-setting-tc-config.c b/libnm-core/nm-setting-tc-config.c index be5b4dbcf2..92c658ff36 100644 --- a/libnm-core/nm-setting-tc-config.c +++ b/libnm-core/nm-setting-tc-config.c @@ -1800,13 +1800,13 @@ nm_setting_tc_config_class_init (NMSettingTCConfigClass *klass) G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); - - _properties_override_add_override (properties_override, - obj_properties[PROP_QDISCS], - G_VARIANT_TYPE ("aa{sv}"), - tc_qdiscs_get, - tc_qdiscs_set, - NULL); + _nm_properties_override_gobj (properties_override, + obj_properties[PROP_QDISCS], + NM_SETT_INFO_PROPERT_TYPE ( + .dbus_type = NM_G_VARIANT_TYPE ("aa{sv}"), + .to_dbus_fcn = tc_qdiscs_get, + .from_dbus_fcn = tc_qdiscs_set, + )); /** * NMSettingTCConfig:tfilters: (type GPtrArray(NMTCTfilter)) @@ -1826,13 +1826,13 @@ nm_setting_tc_config_class_init (NMSettingTCConfigClass *klass) G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); - - _properties_override_add_override (properties_override, - obj_properties[PROP_TFILTERS], - G_VARIANT_TYPE ("aa{sv}"), - tc_tfilters_get, - tc_tfilters_set, - NULL); + _nm_properties_override_gobj (properties_override, + obj_properties[PROP_TFILTERS], + NM_SETT_INFO_PROPERT_TYPE ( + .dbus_type = NM_G_VARIANT_TYPE ("aa{sv}"), + .to_dbus_fcn = tc_tfilters_get, + .from_dbus_fcn = tc_tfilters_set, + )); g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties); diff --git a/libnm-core/nm-setting-team-port.c b/libnm-core/nm-setting-team-port.c index 8fead27820..49c59f69b8 100644 --- a/libnm-core/nm-setting-team-port.c +++ b/libnm-core/nm-setting-team-port.c @@ -536,13 +536,6 @@ nm_setting_team_port_class_init (NMSettingTeamPortClass *klass) setting_class->duplicate_copy_properties = duplicate_copy_properties; setting_class->init_from_dbus = init_from_dbus; -#define _property_override(_properties_override, _param_spec, _variant_type, _is_link_watcher) \ - _properties_override_add ((_properties_override), \ - .param_spec = (_param_spec), \ - .dbus_type = G_VARIANT_TYPE (""_variant_type""), \ - .to_dbus_fcn = _nm_team_settings_property_to_dbus, \ - .gprop_from_dbus_fcn = ((_is_link_watcher) ? _nm_team_settings_property_from_dbus_link_watchers : NULL)) - /** * NMSettingTeamPort:config: * @@ -563,7 +556,7 @@ nm_setting_team_port_class_init (NMSettingTeamPortClass *klass) G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); - _property_override (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_CONFIG], "s", FALSE); + _nm_properties_override_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_CONFIG], &nm_sett_info_propert_type_team_s); /** * NMSettingTeamPort:queue-id: @@ -578,7 +571,7 @@ nm_setting_team_port_class_init (NMSettingTeamPortClass *klass) G_MININT32, G_MAXINT32, -1, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - _property_override (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_PORT_QUEUE_ID], "i", FALSE); + _nm_properties_override_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_PORT_QUEUE_ID], &nm_sett_info_propert_type_team_i); /** * NMSettingTeamPort:prio: @@ -592,7 +585,7 @@ nm_setting_team_port_class_init (NMSettingTeamPortClass *klass) G_MININT32, G_MAXINT32, 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - _property_override (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_PORT_PRIO], "i", FALSE); + _nm_properties_override_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_PORT_PRIO], &nm_sett_info_propert_type_team_i); /** * NMSettingTeamPort:sticky: @@ -606,7 +599,7 @@ nm_setting_team_port_class_init (NMSettingTeamPortClass *klass) FALSE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - _property_override (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_PORT_STICKY], "b", FALSE); + _nm_properties_override_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_PORT_STICKY], &nm_sett_info_propert_type_team_b); /** * NMSettingTeamPort:lacp-prio: @@ -620,7 +613,7 @@ nm_setting_team_port_class_init (NMSettingTeamPortClass *klass) G_MININT32, G_MAXINT32, -1, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - _property_override (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_PORT_LACP_PRIO], "i", FALSE); + _nm_properties_override_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_PORT_LACP_PRIO], &nm_sett_info_propert_type_team_i); /** * NMSettingTeamPort:lacp-key: @@ -634,7 +627,7 @@ nm_setting_team_port_class_init (NMSettingTeamPortClass *klass) G_MININT32, G_MAXINT32, -1, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - _property_override (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_PORT_LACP_KEY], "i", FALSE); + _nm_properties_override_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_PORT_LACP_KEY], &nm_sett_info_propert_type_team_i); /** * NMSettingTeamPort:link-watchers: (type GPtrArray(NMTeamLinkWatcher)) @@ -655,7 +648,7 @@ nm_setting_team_port_class_init (NMSettingTeamPortClass *klass) G_TYPE_PTR_ARRAY, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - _property_override (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_LINK_WATCHERS], "aa{sv}", TRUE); + _nm_properties_override_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_LINK_WATCHERS], &nm_sett_info_propert_type_team_link_watchers); g_object_class_install_properties (object_class, G_N_ELEMENTS (obj_properties), obj_properties); diff --git a/libnm-core/nm-setting-team.c b/libnm-core/nm-setting-team.c index 4f9b571a8d..27f11dcf9b 100644 --- a/libnm-core/nm-setting-team.c +++ b/libnm-core/nm-setting-team.c @@ -1483,13 +1483,6 @@ nm_setting_team_class_init (NMSettingTeamClass *klass) setting_class->duplicate_copy_properties = duplicate_copy_properties; setting_class->init_from_dbus = init_from_dbus; -#define _property_override(_properties_override, _param_spec, _variant_type, _is_link_watcher) \ - _properties_override_add ((_properties_override), \ - .param_spec = (_param_spec), \ - .dbus_type = G_VARIANT_TYPE (""_variant_type""), \ - .to_dbus_fcn = _nm_team_settings_property_to_dbus, \ - .gprop_from_dbus_fcn = ((_is_link_watcher) ? _nm_team_settings_property_from_dbus_link_watchers : NULL)) - /** * NMSettingTeam:config: * @@ -1510,7 +1503,7 @@ nm_setting_team_class_init (NMSettingTeamClass *klass) G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); - _property_override (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_CONFIG], "s", FALSE); + _nm_properties_override_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_CONFIG], &nm_sett_info_propert_type_team_s); /** * NMSettingTeam:notify-peers-count: @@ -1524,7 +1517,7 @@ nm_setting_team_class_init (NMSettingTeamClass *klass) G_MININT32, G_MAXINT32, -1, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - _property_override (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_NOTIFY_PEERS_COUNT], "i", FALSE); + _nm_properties_override_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_NOTIFY_PEERS_COUNT], &nm_sett_info_propert_type_team_i); /** * NMSettingTeam:notify-peers-interval: @@ -1538,7 +1531,7 @@ nm_setting_team_class_init (NMSettingTeamClass *klass) G_MININT32, G_MAXINT32, -1, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - _property_override (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_NOTIFY_PEERS_INTERVAL], "i", FALSE); + _nm_properties_override_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_NOTIFY_PEERS_INTERVAL], &nm_sett_info_propert_type_team_i); /** * NMSettingTeam:mcast-rejoin-count: @@ -1552,7 +1545,7 @@ nm_setting_team_class_init (NMSettingTeamClass *klass) G_MININT32, G_MAXINT32, -1, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - _property_override (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_MCAST_REJOIN_COUNT], "i", FALSE); + _nm_properties_override_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_MCAST_REJOIN_COUNT], &nm_sett_info_propert_type_team_i); /** * NMSettingTeam:mcast-rejoin-interval: @@ -1566,7 +1559,7 @@ nm_setting_team_class_init (NMSettingTeamClass *klass) G_MININT32, G_MAXINT32, -1, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - _property_override (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_MCAST_REJOIN_INTERVAL], "i", FALSE); + _nm_properties_override_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_MCAST_REJOIN_INTERVAL], &nm_sett_info_propert_type_team_i); /** * NMSettingTeam:runner: @@ -1582,7 +1575,7 @@ nm_setting_team_class_init (NMSettingTeamClass *klass) NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - _property_override (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_RUNNER], "s", FALSE); + _nm_properties_override_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_RUNNER], &nm_sett_info_propert_type_team_s); /** * NMSettingTeam:runner-hwaddr-policy: @@ -1596,7 +1589,7 @@ nm_setting_team_class_init (NMSettingTeamClass *klass) NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - _property_override (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_RUNNER_HWADDR_POLICY], "s", FALSE); + _nm_properties_override_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_RUNNER_HWADDR_POLICY], &nm_sett_info_propert_type_team_s); /** * NMSettingTeam:runner-tx-hash: @@ -1611,7 +1604,7 @@ nm_setting_team_class_init (NMSettingTeamClass *klass) G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); - _property_override (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_RUNNER_TX_HASH], "as", FALSE); + _nm_properties_override_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_RUNNER_TX_HASH], &nm_sett_info_propert_type_team_as); /** * NMSettingTeam:runner-tx-balancer: @@ -1625,7 +1618,7 @@ nm_setting_team_class_init (NMSettingTeamClass *klass) NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - _property_override (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_RUNNER_TX_BALANCER], "s", FALSE); + _nm_properties_override_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_RUNNER_TX_BALANCER], &nm_sett_info_propert_type_team_s); /** * NMSettingTeam:runner-tx-balancer-interval: @@ -1639,7 +1632,7 @@ nm_setting_team_class_init (NMSettingTeamClass *klass) G_MININT32, G_MAXINT32, -1, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - _property_override (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_RUNNER_TX_BALANCER_INTERVAL], "i", FALSE); + _nm_properties_override_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_RUNNER_TX_BALANCER_INTERVAL], &nm_sett_info_propert_type_team_i); /** * NMSettingTeam:runner-active: @@ -1653,7 +1646,7 @@ nm_setting_team_class_init (NMSettingTeamClass *klass) TRUE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - _property_override (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_RUNNER_ACTIVE], "b", FALSE); + _nm_properties_override_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_RUNNER_ACTIVE], &nm_sett_info_propert_type_team_b); /** * NMSettingTeam:runner-fast-rate: @@ -1667,7 +1660,7 @@ nm_setting_team_class_init (NMSettingTeamClass *klass) FALSE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - _property_override (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_RUNNER_FAST_RATE], "b", FALSE); + _nm_properties_override_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_RUNNER_FAST_RATE], &nm_sett_info_propert_type_team_b); /** * NMSettingTeam:runner-sys-prio: @@ -1681,7 +1674,7 @@ nm_setting_team_class_init (NMSettingTeamClass *klass) G_MININT32, G_MAXINT32, -1, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - _property_override (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_RUNNER_SYS_PRIO], "i", FALSE); + _nm_properties_override_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_RUNNER_SYS_PRIO], &nm_sett_info_propert_type_team_i); /** * NMSettingTeam:runner-min-ports: @@ -1695,7 +1688,7 @@ nm_setting_team_class_init (NMSettingTeamClass *klass) G_MININT32, G_MAXINT32, -1, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - _property_override (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_RUNNER_MIN_PORTS], "i", FALSE); + _nm_properties_override_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_RUNNER_MIN_PORTS], &nm_sett_info_propert_type_team_i); /** * NMSettingTeam:runner-agg-select-policy: @@ -1709,7 +1702,7 @@ nm_setting_team_class_init (NMSettingTeamClass *klass) NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - _property_override (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_RUNNER_AGG_SELECT_POLICY], "s", FALSE); + _nm_properties_override_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_RUNNER_AGG_SELECT_POLICY], &nm_sett_info_propert_type_team_s); /** * NMSettingTeam:link-watchers: (type GPtrArray(NMTeamLinkWatcher)) @@ -1730,7 +1723,7 @@ nm_setting_team_class_init (NMSettingTeamClass *klass) G_TYPE_PTR_ARRAY, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - _property_override (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_LINK_WATCHERS], "aa{sv}", TRUE); + _nm_properties_override_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_LINK_WATCHERS], &nm_sett_info_propert_type_team_link_watchers); /* ---dbus--- * property: interface-name @@ -1740,11 +1733,7 @@ nm_setting_team_class_init (NMSettingTeamClass *klass) * team's interface name. * ---end--- */ - _properties_override_add_dbus_only (properties_override, - "interface-name", - G_VARIANT_TYPE_STRING, - _nm_setting_get_deprecated_virtual_interface_name, - NULL); + _nm_properties_override_dbus (properties_override, "interface-name", &nm_sett_info_propert_type_deprecated_interface_name); g_object_class_install_properties (object_class, G_N_ELEMENTS (obj_properties), obj_properties); diff --git a/libnm-core/nm-setting-user.c b/libnm-core/nm-setting-user.c index 2852888f5a..2e9ad3cf86 100644 --- a/libnm-core/nm-setting-user.c +++ b/libnm-core/nm-setting-user.c @@ -571,12 +571,7 @@ nm_setting_user_class_init (NMSettingUserClass *klass) G_TYPE_HASH_TABLE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - - _properties_override_add_transform (properties_override, - obj_properties[PROP_DATA], - G_VARIANT_TYPE ("a{ss}"), - _nm_utils_strdict_to_dbus, - _nm_utils_strdict_from_dbus); + _nm_properties_override_gobj (properties_override, obj_properties[PROP_DATA], &nm_sett_info_propert_type_strdict); g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties); diff --git a/libnm-core/nm-setting-vlan.c b/libnm-core/nm-setting-vlan.c index c57d8536a8..3c48c865dc 100644 --- a/libnm-core/nm-setting-vlan.c +++ b/libnm-core/nm-setting-vlan.c @@ -908,13 +908,13 @@ nm_setting_vlan_class_init (NMSettingVlanClass *klass) G_PARAM_CONSTRUCT | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); - - _properties_override_add_override (properties_override, - obj_properties[PROP_FLAGS], - G_VARIANT_TYPE_UINT32, - _override_flags_get, - NULL, - _override_flags_not_set); + _nm_properties_override_gobj (properties_override, + obj_properties[PROP_FLAGS], + NM_SETT_INFO_PROPERT_TYPE ( + .dbus_type = G_VARIANT_TYPE_UINT32, + .to_dbus_fcn = _override_flags_get, + .missing_from_dbus_fcn = _override_flags_not_set, + )); /** * NMSettingVlan:ingress-priority-map: @@ -974,11 +974,7 @@ nm_setting_vlan_class_init (NMSettingVlanClass *klass) * vlan's interface name. * ---end--- */ - _properties_override_add_dbus_only (properties_override, - "interface-name", - G_VARIANT_TYPE_STRING, - _nm_setting_get_deprecated_virtual_interface_name, - NULL); + _nm_properties_override_dbus (properties_override, "interface-name", &nm_sett_info_propert_type_deprecated_interface_name); g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties); diff --git a/libnm-core/nm-setting-vpn.c b/libnm-core/nm-setting-vpn.c index a337d857cf..bc30f47641 100644 --- a/libnm-core/nm-setting-vpn.c +++ b/libnm-core/nm-setting-vpn.c @@ -921,6 +921,9 @@ vpn_secrets_to_dbus (const NMSettInfoSetting *sett_info, const char *key, *value; NMSettingSecretFlags secret_flags; + if (NM_FLAGS_HAS (flags, NM_CONNECTION_SERIALIZE_NO_SECRETS)) + return NULL; + g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{ss}")); g_object_get (setting, property_name, &secrets, NULL); @@ -1129,12 +1132,7 @@ nm_setting_vpn_class_init (NMSettingVpnClass *klass) G_TYPE_HASH_TABLE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - - _properties_override_add_transform (properties_override, - obj_properties[PROP_DATA], - G_VARIANT_TYPE ("a{ss}"), - _nm_utils_strdict_to_dbus, - _nm_utils_strdict_from_dbus); + _nm_properties_override_gobj (properties_override, obj_properties[PROP_DATA], &nm_sett_info_propert_type_strdict); /** * NMSettingVpn:secrets: (type GHashTable(utf8,utf8)): @@ -1155,14 +1153,15 @@ nm_setting_vpn_class_init (NMSettingVpnClass *klass) G_TYPE_HASH_TABLE, G_PARAM_READWRITE | NM_SETTING_PARAM_SECRET | + NM_SETTING_PARAM_TO_DBUS_IGNORE_FLAGS | G_PARAM_STATIC_STRINGS); - - _properties_override_add_override (properties_override, - obj_properties[PROP_SECRETS], - G_VARIANT_TYPE ("a{ss}"), - vpn_secrets_to_dbus, - vpn_secrets_from_dbus, - NULL); + _nm_properties_override_gobj (properties_override, + obj_properties[PROP_SECRETS], + NM_SETT_INFO_PROPERT_TYPE ( + .dbus_type = NM_G_VARIANT_TYPE ("a{ss}"), + .to_dbus_fcn = vpn_secrets_to_dbus, + .from_dbus_fcn = vpn_secrets_from_dbus, + )); /** * NMSettingVpn:timeout: diff --git a/libnm-core/nm-setting-wimax.c b/libnm-core/nm-setting-wimax.c index 13ada1f56e..0824b66c78 100644 --- a/libnm-core/nm-setting-wimax.c +++ b/libnm-core/nm-setting-wimax.c @@ -236,12 +236,7 @@ nm_setting_wimax_class_init (NMSettingWimaxClass *klass) NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - - _properties_override_add_transform (properties_override, - obj_properties[PROP_MAC_ADDRESS], - G_VARIANT_TYPE_BYTESTRING, - _nm_utils_hwaddr_to_dbus, - _nm_utils_hwaddr_from_dbus); + _nm_properties_override_gobj (properties_override, obj_properties[PROP_MAC_ADDRESS], &nm_sett_info_propert_type_mac_addrees); g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties); diff --git a/libnm-core/nm-setting-wired.c b/libnm-core/nm-setting-wired.c index fee069883e..7de223d6ce 100644 --- a/libnm-core/nm-setting-wired.c +++ b/libnm-core/nm-setting-wired.c @@ -1306,13 +1306,12 @@ nm_setting_wired_class_init (NMSettingWiredClass *klass) G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS); - - _properties_override_add_override (properties_override, - obj_properties[PROP_AUTO_NEGOTIATE], - G_VARIANT_TYPE_BOOLEAN, - _override_autoneg_get, - NULL, - NULL); + _nm_properties_override_gobj (properties_override, + obj_properties[PROP_AUTO_NEGOTIATE], + NM_SETT_INFO_PROPERT_TYPE ( + .dbus_type = G_VARIANT_TYPE_BOOLEAN, + .to_dbus_fcn = _override_autoneg_get, + )); /** * NMSettingWired:mac-address: @@ -1344,12 +1343,7 @@ nm_setting_wired_class_init (NMSettingWiredClass *klass) G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); - - _properties_override_add_transform (properties_override, - obj_properties[PROP_MAC_ADDRESS], - G_VARIANT_TYPE_BYTESTRING, - _nm_utils_hwaddr_to_dbus, - _nm_utils_hwaddr_from_dbus); + _nm_properties_override_gobj (properties_override, obj_properties[PROP_MAC_ADDRESS], &nm_sett_info_propert_type_mac_addrees); /** * NMSettingWired:cloned-mac-address: @@ -1400,13 +1394,7 @@ nm_setting_wired_class_init (NMSettingWiredClass *klass) G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); - - _properties_override_add_override (properties_override, - obj_properties[PROP_CLONED_MAC_ADDRESS], - G_VARIANT_TYPE_BYTESTRING, - _nm_utils_hwaddr_cloned_get, - _nm_utils_hwaddr_cloned_set, - _nm_utils_hwaddr_cloned_not_set); + _nm_properties_override_gobj (properties_override, obj_properties[PROP_CLONED_MAC_ADDRESS], &nm_sett_info_propert_type_cloned_mac_address); /* ---dbus--- * property: assigned-mac-address @@ -1420,11 +1408,7 @@ nm_setting_wired_class_init (NMSettingWiredClass *klass) * "cloned-mac-address". * ---end--- */ - _properties_override_add_dbus_only (properties_override, - "assigned-mac-address", - G_VARIANT_TYPE_STRING, - _nm_utils_hwaddr_cloned_data_synth, - _nm_utils_hwaddr_cloned_data_set); + _nm_properties_override_dbus (properties_override, "assigned-mac-address", &nm_sett_info_propert_type_assigned_mac_address); /** * NMSettingWired:generate-mac-address-mask: @@ -1588,12 +1572,7 @@ nm_setting_wired_class_init (NMSettingWiredClass *klass) G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); - - _properties_override_add_transform (properties_override, - obj_properties[PROP_S390_OPTIONS], - G_VARIANT_TYPE ("a{ss}"), - _nm_utils_strdict_to_dbus, - _nm_utils_strdict_from_dbus); + _nm_properties_override_gobj (properties_override, obj_properties[PROP_S390_OPTIONS], &nm_sett_info_propert_type_strdict); /** * NMSettingWired:wake-on-lan: diff --git a/libnm-core/nm-setting-wireguard.c b/libnm-core/nm-setting-wireguard.c index baceb4d064..a0e3ffcde8 100644 --- a/libnm-core/nm-setting-wireguard.c +++ b/libnm-core/nm-setting-wireguard.c @@ -2571,11 +2571,13 @@ nm_setting_wireguard_class_init (NMSettingWireGuardClass *klass) * description: Array of dictionaries for the WireGuard peers. * ---end--- */ - _properties_override_add_dbus_only (properties_override, - NM_SETTING_WIREGUARD_PEERS, - G_VARIANT_TYPE ("aa{sv}"), - _peers_dbus_only_synth, - _peers_dbus_only_set); + _nm_properties_override_dbus (properties_override, + NM_SETTING_WIREGUARD_PEERS, + NM_SETT_INFO_PROPERT_TYPE ( + .dbus_type = NM_G_VARIANT_TYPE ("aa{sv}"), + .to_dbus_fcn = _peers_dbus_only_synth, + .from_dbus_fcn = _peers_dbus_only_set, + )); g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties); diff --git a/libnm-core/nm-setting-wireless-security.c b/libnm-core/nm-setting-wireless-security.c index c58ba1e380..c4b45d2247 100644 --- a/libnm-core/nm-setting-wireless-security.c +++ b/libnm-core/nm-setting-wireless-security.c @@ -1811,12 +1811,13 @@ nm_setting_wireless_security_class_init (NMSettingWirelessSecurityClass *klass) G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS); + _nm_properties_override_gobj (properties_override, + obj_properties[PROP_WEP_KEY_TYPE], + NM_SETT_INFO_PROPERT_TYPE ( + .dbus_type = G_VARIANT_TYPE_UINT32, + .gprop_to_dbus_fcn = wep_key_type_to_dbus, + )); - _properties_override_add_transform (properties_override, - obj_properties[PROP_WEP_KEY_TYPE], - G_VARIANT_TYPE_UINT32, - wep_key_type_to_dbus, - NULL); /** * NMSettingWirelessSecurity:wps-method: * diff --git a/libnm-core/nm-setting-wireless.c b/libnm-core/nm-setting-wireless.c index f72e1677aa..339fb3a0a3 100644 --- a/libnm-core/nm-setting-wireless.c +++ b/libnm-core/nm-setting-wireless.c @@ -1376,12 +1376,7 @@ nm_setting_wireless_class_init (NMSettingWirelessClass *klass) NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - - _properties_override_add_transform (properties_override, - obj_properties[PROP_BSSID], - G_VARIANT_TYPE_BYTESTRING, - _nm_utils_hwaddr_to_dbus, - _nm_utils_hwaddr_from_dbus); + _nm_properties_override_gobj (properties_override, obj_properties[PROP_BSSID], &nm_sett_info_propert_type_mac_addrees); /** * NMSettingWireless:rate: @@ -1455,12 +1450,7 @@ nm_setting_wireless_class_init (NMSettingWirelessClass *klass) NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - - _properties_override_add_transform (properties_override, - obj_properties[PROP_MAC_ADDRESS], - G_VARIANT_TYPE_BYTESTRING, - _nm_utils_hwaddr_to_dbus, - _nm_utils_hwaddr_from_dbus); + _nm_properties_override_gobj (properties_override, obj_properties[PROP_MAC_ADDRESS], &nm_sett_info_propert_type_mac_addrees); /** * NMSettingWireless:cloned-mac-address: @@ -1510,13 +1500,7 @@ nm_setting_wireless_class_init (NMSettingWirelessClass *klass) G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); - - _properties_override_add_override (properties_override, - obj_properties[PROP_CLONED_MAC_ADDRESS], - G_VARIANT_TYPE_BYTESTRING, - _nm_utils_hwaddr_cloned_get, - _nm_utils_hwaddr_cloned_set, - _nm_utils_hwaddr_cloned_not_set); + _nm_properties_override_gobj (properties_override, obj_properties[PROP_CLONED_MAC_ADDRESS], &nm_sett_info_propert_type_cloned_mac_address); /* ---dbus--- * property: assigned-mac-address @@ -1530,11 +1514,7 @@ nm_setting_wireless_class_init (NMSettingWirelessClass *klass) * "cloned-mac-address". * ---end--- */ - _properties_override_add_dbus_only (properties_override, - "assigned-mac-address", - G_VARIANT_TYPE_STRING, - _nm_utils_hwaddr_cloned_data_synth, - _nm_utils_hwaddr_cloned_data_set); + _nm_properties_override_dbus (properties_override, "assigned-mac-address", &nm_sett_info_propert_type_assigned_mac_address); /** * NMSettingWireless:generate-mac-address-mask: @@ -1631,13 +1611,12 @@ nm_setting_wireless_class_init (NMSettingWirelessClass *klass) G_PARAM_READWRITE | NM_SETTING_PARAM_FUZZY_IGNORE | G_PARAM_STATIC_STRINGS); - - _properties_override_add_override (properties_override, - obj_properties[PROP_SEEN_BSSIDS], - G_VARIANT_TYPE_STRING_ARRAY, - _to_dbus_fcn_seen_bssids, - NULL, - NULL); + _nm_properties_override_gobj (properties_override, + obj_properties[PROP_SEEN_BSSIDS], + NM_SETT_INFO_PROPERT_TYPE ( + .dbus_type = G_VARIANT_TYPE_STRING_ARRAY, + .to_dbus_fcn = _to_dbus_fcn_seen_bssids, + )); /** * NMSettingWireless:mtu: @@ -1755,11 +1734,12 @@ nm_setting_wireless_class_init (NMSettingWirelessClass *klass) * NetworkManager daemons. * ---end--- */ - _properties_override_add_dbus_only (properties_override, - "security", - G_VARIANT_TYPE_STRING, - nm_setting_wireless_get_security, - NULL); + _nm_properties_override_dbus (properties_override, + "security", + NM_SETT_INFO_PROPERT_TYPE ( + .dbus_type = G_VARIANT_TYPE_STRING, + .to_dbus_fcn = nm_setting_wireless_get_security, + )); /** * NMSettingWireless:wake-on-wlan: diff --git a/libnm-core/nm-setting.c b/libnm-core/nm-setting.c index dac2df82e8..6f77282b70 100644 --- a/libnm-core/nm-setting.c +++ b/libnm-core/nm-setting.c @@ -202,154 +202,33 @@ _gprop_to_dbus_fcn_flags (const GValue *val) return g_variant_new_uint32 (g_value_get_flags (val)); } -void -_properties_override_add_struct (GArray *properties_override, - const NMSettInfoProperty *prop_info) +gboolean +_nm_properties_override_assert (const NMSettInfoProperty *prop_info) { - NMSettInfoProperty *p; - - nm_assert (properties_override); nm_assert (prop_info); - nm_assert (prop_info->name || prop_info->param_spec); + nm_assert ((!!prop_info->name) != (!!prop_info->param_spec)); nm_assert (!prop_info->param_spec || !prop_info->name || nm_streq0 (prop_info->name, prop_info->param_spec->name)); - nm_assert (!_nm_sett_info_property_find_in_array ((NMSettInfoProperty *) properties_override->data, - properties_override->len, - prop_info->name ?: prop_info->param_spec->name)); - - nm_assert (!prop_info->gprop_from_dbus_fcn || prop_info->dbus_type); - nm_assert (!prop_info->from_dbus_fcn || prop_info->dbus_type); - nm_assert (!prop_info->to_dbus_fcn || prop_info->dbus_type); - - nm_assert (!prop_info->to_dbus_fcn || !prop_info->gprop_to_dbus_fcn); - nm_assert (!prop_info->from_dbus_fcn || !prop_info->gprop_from_dbus_fcn); - - nm_assert (!prop_info->gprop_to_dbus_fcn || prop_info->param_spec); - nm_assert (!prop_info->gprop_from_dbus_fcn || prop_info->param_spec); - - g_array_append_vals (properties_override, prop_info, 1); - if (!prop_info->name) { - /* for convenience, allow omitting "name" if "param_spec" is given. */ - p = &g_array_index (properties_override, - NMSettInfoProperty, - properties_override->len - 1); - nm_assert (p->param_spec); - p->name = p->param_spec->name; - } -} +#define _PROPERT_EXTRA(prop_info, member) \ + ({ \ + const NMSettInfoProperty *_prop_info = (prop_info); \ + \ + (_prop_info->property_type ? _prop_info->property_type->member : 0); \ + }) -/** - * _properties_override_add_dbus_only: - * @properties_override: an array collecting the overrides - * @property_name: the name of the property to override - * @dbus_type: the type of the property (in its D-Bus representation) - * @to_dbus_fcn: (allow-none): function to call to synthesize a value for the property - * @from_dbus_fcn: (allow-none): function to call to set the value of the property - * - * Registers a property named @property_name, which will be used in the D-Bus - * serialization of objects of this setting type, but which does not correspond to - * a #GObject property. - * - * When serializing a setting to D-Bus, @to_dbus_fcn will be called to synthesize - * a value for the property. (If it returns %NULL, no value will be added to the - * serialization. If @to_dbus_fcn is %NULL, the property will always be omitted - * in the serialization.) - * - * When deserializing a D-Bus representation into a setting, if @property_name - * is present, then @from_dbus_fcn will be called to set it. (If @from_dbus_fcn is %NULL - * then the property will be ignored when deserializing.) - */ -void -_properties_override_add_dbus_only (GArray *properties_override, - const char *property_name, - const GVariantType *dbus_type, - NMSettInfoPropToDBusFcn to_dbus_fcn, - NMSettInfoPropFromDBusFcn from_dbus_fcn) -{ - _properties_override_add (properties_override, - .name = property_name, - .dbus_type = dbus_type, - .to_dbus_fcn = to_dbus_fcn, - .from_dbus_fcn = from_dbus_fcn); -} + nm_assert (!_PROPERT_EXTRA (prop_info, gprop_from_dbus_fcn) || _PROPERT_EXTRA (prop_info, dbus_type)); + nm_assert (!_PROPERT_EXTRA (prop_info, from_dbus_fcn) || _PROPERT_EXTRA (prop_info, dbus_type)); + nm_assert (!_PROPERT_EXTRA (prop_info, to_dbus_fcn) || _PROPERT_EXTRA (prop_info, dbus_type)); -/** - * _properties_override_add_override: - * @properties_override: an array collecting the overrides - * @param_spec: the name of the property to override - * @dbus_type: the type of the property (in its D-Bus representation) - * @to_dbus_fcn: (allow-none): function to call to get the value of the property - * @from_dbus_fcn: (allow-none): function to call to set the value of the property - * @missing_from_dbus_fcn: (allow-none): function to call to indicate the property was not set - * - * Overrides the D-Bus representation of the #GObject property that shares the - * same name as @param_spec. - * - * When serializing a setting to D-Bus, if @to_dbus_fcn is non-%NULL, then it will - * be called to get the property's value. If it returns a #GVariant, the - * property will be added to the hash, and if it returns %NULL, the property - * will be omitted. (If @to_dbus_fcn is %NULL, the property will be read normally - * with g_object_get_property(), and added to the hash if it is not the default - * value.) - * - * When deserializing a D-Bus representation into a setting, if a value with - * the name of @param_spec is present, then @from_dbus_fcn will be called to set it. - * (If @from_dbus_fcn is %NULL then the property will be set normally with - * g_object_set_property().) - * - * If @missing_from_dbus_fcn is non-%NULL, then it will be called when deserializing a - * representation that does NOT contain a value for the property. This can be used, - * eg, if a new property needs to be initialized from some older deprecated property - * when it is not present. - */ -void -_properties_override_add_override (GArray *properties_override, - GParamSpec *param_spec, - const GVariantType *dbus_type, - NMSettInfoPropToDBusFcn to_dbus_fcn, - NMSettInfoPropFromDBusFcn from_dbus_fcn, - NMSettInfoPropMissingFromDBusFcn missing_from_dbus_fcn) -{ - nm_assert (param_spec); + nm_assert (!_PROPERT_EXTRA (prop_info, to_dbus_fcn) || !_PROPERT_EXTRA (prop_info, gprop_to_dbus_fcn)); + nm_assert (!_PROPERT_EXTRA (prop_info, from_dbus_fcn) || !_PROPERT_EXTRA (prop_info, gprop_from_dbus_fcn)); - _properties_override_add (properties_override, - .param_spec = param_spec, - .dbus_type = dbus_type, - .to_dbus_fcn = to_dbus_fcn, - .from_dbus_fcn = from_dbus_fcn, - .missing_from_dbus_fcn = missing_from_dbus_fcn); -} + nm_assert (!_PROPERT_EXTRA (prop_info, gprop_to_dbus_fcn) || prop_info->param_spec); + nm_assert (!_PROPERT_EXTRA (prop_info, gprop_from_dbus_fcn) || prop_info->param_spec); -/** - * _properties_override_add_transform: - * @properties_override: an array collecting the overrides - * @param_spec: the param spec of the property to transform. - * @dbus_type: the type of the property (in its D-Bus representation) - * @gprop_to_dbus_fcn: function to convert from object to D-Bus format - * @gprop_from_dbus_fcn: function to convert from D-Bus to object format - * - * Indicates that @property on @setting_class does not have the same format as - * its corresponding D-Bus representation, and so must be transformed when - * serializing/deserializing. - * - * The transformation will also be used by nm_setting_compare(), meaning that - * the underlying object property does not need to be of a type that - * nm_property_compare() recognizes, as long as it recognizes @dbus_type. - */ -void -_properties_override_add_transform (GArray *properties_override, - GParamSpec *param_spec, - const GVariantType *dbus_type, - NMSettInfoPropGPropToDBusFcn gprop_to_dbus_fcn, - NMSettInfoPropGPropFromDBusFcn gprop_from_dbus_fcn) -{ - nm_assert (param_spec); +#undef _PROPERT_EXTRA - _properties_override_add (properties_override, - .param_spec = param_spec, - .dbus_type = dbus_type, - .gprop_to_dbus_fcn = gprop_to_dbus_fcn, - .gprop_from_dbus_fcn = gprop_from_dbus_fcn); + return TRUE; } static NMSettInfoSetting _sett_info_settings[_NM_META_SETTING_TYPE_NUM]; @@ -461,6 +340,18 @@ _nm_setting_class_commit_full (NMSettingClass *setting_class, property_specs = g_object_class_list_properties (G_OBJECT_CLASS (setting_class), &n_property_specs); + for (i = 0; i < properties_override->len; i++) { + NMSettInfoProperty *p = &g_array_index (properties_override, NMSettInfoProperty, i); + + nm_assert ((!!p->name) != (!!p->param_spec)); + + if (!p->name) { + nm_assert (p->param_spec); + p->name = p->param_spec->name; + } else + nm_assert (!p->param_spec); + } + #if NM_MORE_ASSERTS > 10 /* assert that properties_override is constructed consistently. */ for (i = 0; i < override_len; i++) { @@ -502,43 +393,46 @@ _nm_setting_class_commit_full (NMSettingClass *setting_class, NMSettInfoProperty *p = &g_array_index (properties_override, NMSettInfoProperty, i); GType vtype; - if (p->dbus_type) - continue; + if (p->property_type) + goto has_property_type; nm_assert (p->param_spec); - nm_assert (!p->gprop_to_dbus_fcn); vtype = p->param_spec->value_type; if (vtype == G_TYPE_BOOLEAN) - p->dbus_type = G_VARIANT_TYPE_BOOLEAN; + p->property_type = NM_SETT_INFO_PROPERT_TYPE (.dbus_type = G_VARIANT_TYPE_BOOLEAN); else if (vtype == G_TYPE_UCHAR) - p->dbus_type = G_VARIANT_TYPE_BYTE; + p->property_type = NM_SETT_INFO_PROPERT_TYPE (.dbus_type = G_VARIANT_TYPE_BYTE); else if (vtype == G_TYPE_INT) - p->dbus_type = G_VARIANT_TYPE_INT32; + p->property_type = &nm_sett_info_propert_type_plain_i; else if (vtype == G_TYPE_UINT) - p->dbus_type = G_VARIANT_TYPE_UINT32; + p->property_type = &nm_sett_info_propert_type_plain_u; else if (vtype == G_TYPE_INT64) - p->dbus_type = G_VARIANT_TYPE_INT64; + p->property_type = NM_SETT_INFO_PROPERT_TYPE (.dbus_type = G_VARIANT_TYPE_INT64); else if (vtype == G_TYPE_UINT64) - p->dbus_type = G_VARIANT_TYPE_UINT64; + p->property_type = NM_SETT_INFO_PROPERT_TYPE (.dbus_type = G_VARIANT_TYPE_UINT64); else if (vtype == G_TYPE_STRING) - p->dbus_type = G_VARIANT_TYPE_STRING; + p->property_type = NM_SETT_INFO_PROPERT_TYPE (.dbus_type = G_VARIANT_TYPE_STRING); else if (vtype == G_TYPE_DOUBLE) - p->dbus_type = G_VARIANT_TYPE_DOUBLE; + p->property_type = NM_SETT_INFO_PROPERT_TYPE (.dbus_type = G_VARIANT_TYPE_DOUBLE); else if (vtype == G_TYPE_STRV) - p->dbus_type = G_VARIANT_TYPE_STRING_ARRAY; + p->property_type = NM_SETT_INFO_PROPERT_TYPE (.dbus_type = G_VARIANT_TYPE_STRING_ARRAY); else if (vtype == G_TYPE_BYTES) { - p->dbus_type = G_VARIANT_TYPE_BYTESTRING; - p->gprop_to_dbus_fcn = _gprop_to_dbus_fcn_bytes; + p->property_type = NM_SETT_INFO_PROPERT_TYPE (.dbus_type = G_VARIANT_TYPE_BYTESTRING, + .gprop_to_dbus_fcn = _gprop_to_dbus_fcn_bytes); } else if (g_type_is_a (vtype, G_TYPE_ENUM)) { - p->dbus_type = G_VARIANT_TYPE_INT32; - p->gprop_to_dbus_fcn = _gprop_to_dbus_fcn_enum; + p->property_type = NM_SETT_INFO_PROPERT_TYPE (.dbus_type = G_VARIANT_TYPE_INT32, + .gprop_to_dbus_fcn = _gprop_to_dbus_fcn_enum); } else if (g_type_is_a (vtype, G_TYPE_FLAGS)) { - p->dbus_type = G_VARIANT_TYPE_UINT32; - p->gprop_to_dbus_fcn = _gprop_to_dbus_fcn_flags; - } + p->property_type = NM_SETT_INFO_PROPERT_TYPE (.dbus_type = G_VARIANT_TYPE_UINT32, + .gprop_to_dbus_fcn = _gprop_to_dbus_fcn_flags); + } else + nm_assert_not_reached (); - nm_assert (p->dbus_type); +has_property_type: + nm_assert (p->property_type); + nm_assert (p->property_type->dbus_type); + nm_assert (g_variant_type_string_is_valid ((const char *) p->property_type->dbus_type)); } G_STATIC_ASSERT_EXPR (G_STRUCT_OFFSET (NMSettInfoProperty, name) == 0); @@ -548,13 +442,15 @@ _nm_setting_class_commit_full (NMSettingClass *setting_class, sett_info->setting_class = setting_class; if (detail) sett_info->detail = *detail; + nm_assert (properties_override->len > 0); sett_info->property_infos_len = properties_override->len; - sett_info->property_infos = (const NMSettInfoProperty *) g_array_free (properties_override, - properties_override->len == 0); + sett_info->property_infos = nm_memdup (properties_override->data, sizeof (NMSettInfoProperty) * properties_override->len); sett_info->property_infos_sorted = _property_infos_sort (sett_info->property_infos, sett_info->property_infos_len, setting_class); + + g_array_free (properties_override, TRUE); } const NMSettInfoProperty * @@ -685,18 +581,16 @@ property_to_dbus (const NMSettInfoSetting *sett_info, const NMSettInfoProperty *property = &sett_info->property_infos[property_idx]; GVariant *variant; - nm_assert (property->dbus_type); + nm_assert (property->property_type->dbus_type); if (!property->param_spec) { - if (!property->to_dbus_fcn) + if (!property->property_type->to_dbus_fcn) return NULL; - } else if (!ignore_flags) { + } else if ( !ignore_flags + && !NM_FLAGS_HAS (property->param_spec->flags, NM_SETTING_PARAM_TO_DBUS_IGNORE_FLAGS)) { if (!NM_FLAGS_HAS (property->param_spec->flags, G_PARAM_WRITABLE)) return NULL; - if (NM_FLAGS_ANY (property->param_spec->flags, NM_SETTING_PARAM_GENDATA_BACKED)) - return NULL; - if ( NM_FLAGS_HAS (property->param_spec->flags, NM_SETTING_PARAM_LEGACY) && !_nm_utils_is_manager_process) return NULL; @@ -705,13 +599,7 @@ property_to_dbus (const NMSettInfoSetting *sett_info, if (NM_FLAGS_HAS (flags, NM_CONNECTION_SERIALIZE_NO_SECRETS)) return NULL; - /* Check agent secrets. Secrets in the vpn.secrets property are special as - * the flag for each of them is specified as a separate key in the - * vpn.data property. They are handled separately in the to_dbus_fcn() - * of VPN setting. */ - if ( NM_FLAGS_HAS (flags, NM_CONNECTION_SERIALIZE_WITH_SECRETS_AGENT_OWNED) - && !nm_streq (nm_setting_get_name (setting), NM_SETTING_VPN_SETTING_NAME) - && !nm_streq (property->name, NM_SETTING_VPN_SECRETS)) { + if (NM_FLAGS_HAS (flags, NM_CONNECTION_SERIALIZE_WITH_SECRETS_AGENT_OWNED)) { NMSettingSecretFlags f; /* see also _nm_connection_serialize_secrets() */ @@ -726,8 +614,8 @@ property_to_dbus (const NMSettInfoSetting *sett_info, } } - if (property->to_dbus_fcn) { - variant = property->to_dbus_fcn (sett_info, property_idx, connection, setting, flags, options); + if (property->property_type->to_dbus_fcn) { + variant = property->property_type->to_dbus_fcn (sett_info, property_idx, connection, setting, flags, options); nm_g_variant_take_ref (variant); } else { nm_auto_unset_gvalue GValue prop_value = { 0, }; @@ -742,15 +630,15 @@ property_to_dbus (const NMSettInfoSetting *sett_info, && g_param_value_defaults (property->param_spec, &prop_value)) return NULL; - if (property->gprop_to_dbus_fcn) { - variant = property->gprop_to_dbus_fcn (&prop_value); + if (property->property_type->gprop_to_dbus_fcn) { + variant = property->property_type->gprop_to_dbus_fcn (&prop_value); nm_g_variant_take_ref (variant); } else - variant = g_dbus_gvalue_to_gvariant (&prop_value, property->dbus_type); + variant = g_dbus_gvalue_to_gvariant (&prop_value, property->property_type->dbus_type); } nm_assert (!variant || !g_variant_is_floating (variant)); - nm_assert (!variant || g_variant_is_of_type (variant, property->dbus_type)); + nm_assert (!variant || g_variant_is_of_type (variant, property->property_type->dbus_type)); return variant; } @@ -761,12 +649,12 @@ set_property_from_dbus (const NMSettInfoProperty *property, GValue *dst_value) { nm_assert (property->param_spec); - nm_assert (property->dbus_type); + nm_assert (property->property_type->dbus_type); - if (property->gprop_from_dbus_fcn) { - if (!g_variant_type_equal (g_variant_get_type (src_value), property->dbus_type)) + if (property->property_type->gprop_from_dbus_fcn) { + if (!g_variant_type_equal (g_variant_get_type (src_value), property->property_type->dbus_type)) return FALSE; - property->gprop_from_dbus_fcn (src_value, dst_value); + property->property_type->gprop_from_dbus_fcn (src_value, dst_value); } else if (dst_value->g_type == G_TYPE_BYTES) { if (!g_variant_is_of_type (src_value, G_VARIANT_TYPE_BYTESTRING)) return FALSE; @@ -1002,16 +890,16 @@ init_from_dbus (NMSetting *setting, g_hash_table_remove (keys, property_info->name); if ( value - && property_info->from_dbus_fcn) { + && property_info->property_type->from_dbus_fcn) { - if (!g_variant_type_equal (g_variant_get_type (value), property_info->dbus_type)) { + if (!g_variant_type_equal (g_variant_get_type (value), property_info->property_type->dbus_type)) { /* for backward behavior, fail unless best-effort is chosen. */ if (NM_FLAGS_HAS (parse_flags, NM_SETTING_PARSE_FLAGS_BEST_EFFORT)) continue; g_set_error (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_INVALID_PROPERTY, _("can't set property of type '%s' from value of type '%s'"), - property_info->dbus_type ? - g_variant_type_peek_string (property_info->dbus_type) : + property_info->property_type->dbus_type ? + g_variant_type_peek_string (property_info->property_type->dbus_type) : property_info->param_spec ? g_type_name (property_info->param_spec->value_type) : "(unknown)", g_variant_get_type_string (value)); @@ -1019,12 +907,12 @@ init_from_dbus (NMSetting *setting, return FALSE; } - if (!property_info->from_dbus_fcn (setting, - connection_dict, - property_info->name, - value, - parse_flags, - &local)) { + if (!property_info->property_type->from_dbus_fcn (setting, + connection_dict, + property_info->name, + value, + parse_flags, + &local)) { if (!NM_FLAGS_HAS (parse_flags, NM_SETTING_PARSE_FLAGS_STRICT)) continue; g_set_error (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_INVALID_PROPERTY, @@ -1034,12 +922,12 @@ init_from_dbus (NMSetting *setting, return FALSE; } } else if ( !value - && property_info->missing_from_dbus_fcn) { - if (!property_info->missing_from_dbus_fcn (setting, - connection_dict, - property_info->name, - parse_flags, - &local)) { + && property_info->property_type->missing_from_dbus_fcn) { + if (!property_info->property_type->missing_from_dbus_fcn (setting, + connection_dict, + property_info->name, + parse_flags, + &local)) { if (!NM_FLAGS_HAS (parse_flags, NM_SETTING_PARSE_FLAGS_STRICT)) continue; g_set_error (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_INVALID_PROPERTY, @@ -1059,8 +947,8 @@ init_from_dbus (NMSetting *setting, continue; g_set_error (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_INVALID_PROPERTY, _("can't set property of type '%s' from value of type '%s'"), - property_info->dbus_type - ? g_variant_type_peek_string (property_info->dbus_type) + property_info->property_type->dbus_type + ? g_variant_type_peek_string (property_info->property_type->dbus_type) : ( property_info->param_spec ? g_type_name (property_info->param_spec->value_type) : "(unknown)"), @@ -1107,9 +995,10 @@ nm_setting_get_dbus_property_type (NMSetting *setting, g_return_val_if_fail (property != NULL, NULL); - nm_assert (property->dbus_type); + nm_assert (property->property_type); + nm_assert (g_variant_type_string_is_valid ((const char *) property->property_type->dbus_type)); - return property->dbus_type; + return property->property_type->dbus_type; } gboolean @@ -2404,7 +2293,7 @@ nm_setting_to_string (NMSetting *setting) return g_string_free (string, FALSE); } -GVariant * +static GVariant * _nm_setting_get_deprecated_virtual_interface_name (const NMSettInfoSetting *sett_info, guint property_idx, NMConnection *connection, @@ -2427,6 +2316,29 @@ _nm_setting_get_deprecated_virtual_interface_name (const NMSettInfoSetting *sett return NULL; } +const NMSettInfoPropertType nm_sett_info_propert_type_deprecated_interface_name = { + .dbus_type = G_VARIANT_TYPE_STRING, + .to_dbus_fcn = _nm_setting_get_deprecated_virtual_interface_name, +}; + +const NMSettInfoPropertType nm_sett_info_propert_type_deprecated_ignore_i = { + .dbus_type = G_VARIANT_TYPE_INT32, + /* No functions set. This property type is to silently ignore the value on D-Bus. */ +}; + +const NMSettInfoPropertType nm_sett_info_propert_type_deprecated_ignore_u = { + .dbus_type = G_VARIANT_TYPE_UINT32, + /* No functions set. This property type is to silently ignore the value on D-Bus. */ +}; + +const NMSettInfoPropertType nm_sett_info_propert_type_plain_i = { + .dbus_type = G_VARIANT_TYPE_INT32, +}; + +const NMSettInfoPropertType nm_sett_info_propert_type_plain_u = { + .dbus_type = G_VARIANT_TYPE_UINT32, +}; + /*****************************************************************************/ static GenData * diff --git a/libnm-core/nm-team-utils.c b/libnm-core/nm-team-utils.c index 78c9182609..0be33b0383 100644 --- a/libnm-core/nm-team-utils.c +++ b/libnm-core/nm-team-utils.c @@ -2420,7 +2420,7 @@ _nm_setting_get_team_setting (struct _NMSetting *setting) return _nm_setting_team_port_get_team_setting (NM_SETTING_TEAM_PORT (setting)); } -GVariant * +static GVariant * _nm_team_settings_property_to_dbus (const NMSettInfoSetting *sett_info, guint property_idx, NMConnection *connection, @@ -2467,7 +2467,7 @@ _nm_team_settings_property_to_dbus (const NMSettInfoSetting *sett_info, return NULL; } -void +static void _nm_team_settings_property_from_dbus_link_watchers (GVariant *dbus_value, GValue *prop_value) { @@ -2475,6 +2475,32 @@ _nm_team_settings_property_from_dbus_link_watchers (GVariant *dbus_value, _nm_utils_team_link_watchers_from_variant (dbus_value, FALSE, NULL)); } +const NMSettInfoPropertType nm_sett_info_propert_type_team_b = { + .dbus_type = G_VARIANT_TYPE_BOOLEAN, + .to_dbus_fcn = _nm_team_settings_property_to_dbus, +}; + +const NMSettInfoPropertType nm_sett_info_propert_type_team_i = { + .dbus_type = G_VARIANT_TYPE_INT32, + .to_dbus_fcn = _nm_team_settings_property_to_dbus, +}; + +const NMSettInfoPropertType nm_sett_info_propert_type_team_s = { + .dbus_type = G_VARIANT_TYPE_STRING, + .to_dbus_fcn = _nm_team_settings_property_to_dbus, +}; + +const NMSettInfoPropertType nm_sett_info_propert_type_team_as = { + .dbus_type = NM_G_VARIANT_TYPE ("as"), + .to_dbus_fcn = _nm_team_settings_property_to_dbus, +}; + +const NMSettInfoPropertType nm_sett_info_propert_type_team_link_watchers = { + .dbus_type = NM_G_VARIANT_TYPE ("aa{sv}"), + .to_dbus_fcn = _nm_team_settings_property_to_dbus, + .gprop_from_dbus_fcn = _nm_team_settings_property_from_dbus_link_watchers, +}; + /*****************************************************************************/ NMTeamSetting * diff --git a/libnm-core/nm-team-utils.h b/libnm-core/nm-team-utils.h index 8d6b9985e9..6cab42d46a 100644 --- a/libnm-core/nm-team-utils.h +++ b/libnm-core/nm-team-utils.h @@ -11,6 +11,7 @@ #endif #include "nm-glib-aux/nm-value-type.h" +#include "nm-core-internal.h" struct _NMSetting; @@ -277,17 +278,10 @@ NMTeamSetting *_nm_setting_get_team_setting (struct _NMSetting *setting); /*****************************************************************************/ -#include "nm-connection.h" -#include "nm-core-internal.h" - -GVariant *_nm_team_settings_property_to_dbus (const NMSettInfoSetting *sett_info, - guint property_idx, - NMConnection *connection, - NMSetting *setting, - NMConnectionSerializationFlags flags, - const NMConnectionSerializationOptions *options); - -void _nm_team_settings_property_from_dbus_link_watchers (GVariant *dbus_value, - GValue *prop_value); +extern const NMSettInfoPropertType nm_sett_info_propert_type_team_b; +extern const NMSettInfoPropertType nm_sett_info_propert_type_team_i; +extern const NMSettInfoPropertType nm_sett_info_propert_type_team_s; +extern const NMSettInfoPropertType nm_sett_info_propert_type_team_as; +extern const NMSettInfoPropertType nm_sett_info_propert_type_team_link_watchers; #endif /* __NM_TEAM_UITLS_H__ */ diff --git a/libnm-core/nm-utils-private.h b/libnm-core/nm-utils-private.h index 8bda7a5583..72833c2650 100644 --- a/libnm-core/nm-utils-private.h +++ b/libnm-core/nm-utils-private.h @@ -47,41 +47,16 @@ gboolean _nm_utils_wps_method_validate (NMSettingWirelessSecurityWpsMethod wps_m /* D-Bus transform funcs */ -GVariant *_nm_utils_hwaddr_cloned_get (const NMSettInfoSetting *sett_info, - guint property_idx, - NMConnection *connection, - NMSetting *setting, - NMConnectionSerializationFlags flags, - const NMConnectionSerializationOptions *options); -gboolean _nm_utils_hwaddr_cloned_set (NMSetting *setting, - GVariant *connection_dict, - const char *property, - GVariant *value, - NMSettingParseFlags parse_flags, - GError **error); -gboolean _nm_utils_hwaddr_cloned_not_set (NMSetting *setting, - GVariant *connection_dict, - const char *property, - NMSettingParseFlags parse_flags, - GError **error); -GVariant * _nm_utils_hwaddr_cloned_data_synth (const NMSettInfoSetting *sett_info, - guint property_idx, - NMConnection *connection, - NMSetting *setting, - NMConnectionSerializationFlags flags, - const NMConnectionSerializationOptions *options); -gboolean _nm_utils_hwaddr_cloned_data_set (NMSetting *setting, - GVariant *connection_dict, - const char *property, - GVariant *value, - NMSettingParseFlags parse_flags, - GError **error); - -GVariant * _nm_utils_hwaddr_to_dbus (const GValue *prop_value); -void _nm_utils_hwaddr_from_dbus (GVariant *dbus_value, - GValue *prop_value); - -GVariant * _nm_utils_strdict_to_dbus (const GValue *prop_value); +extern const NMSettInfoPropertType nm_sett_info_propert_type_strdict; + +extern const NMSettInfoPropertType nm_sett_info_propert_type_mac_addrees; + +extern const NMSettInfoPropertType nm_sett_info_propert_type_cloned_mac_address; + +extern const NMSettInfoPropertType nm_sett_info_propert_type_assigned_mac_address; + +extern const NMSettInfoPropertType nm_sett_info_propert_type_bridge_vlans; + void _nm_utils_strdict_from_dbus (GVariant *dbus_value, GValue *prop_value); @@ -97,19 +72,6 @@ void _nm_utils_format_variant_attributes_full (GString *str, char key_value_separator); gboolean _nm_sriov_vf_parse_vlans (NMSriovVF *vf, const char *str, GError **error); -GVariant * _nm_utils_bridge_vlans_to_dbus (const NMSettInfoSetting *sett_info, - guint property_idx, - NMConnection *connection, - NMSetting *setting, - NMConnectionSerializationFlags flags, - const NMConnectionSerializationOptions *options); - -gboolean _nm_utils_bridge_vlans_from_dbus (NMSetting *setting, - GVariant *connection_dict, - const char *property, - GVariant *value, - NMSettingParseFlags parse_flags, - GError **error); gboolean _nm_utils_bridge_vlan_verify_list (GPtrArray *vlans, gboolean check_normalizable, GError **error, diff --git a/libnm-core/nm-utils.c b/libnm-core/nm-utils.c index ae48b16af4..a73deda72f 100644 --- a/libnm-core/nm-utils.c +++ b/libnm-core/nm-utils.c @@ -800,7 +800,7 @@ _nm_utils_hash_values_to_slist (GHashTable *hash) return list; } -GVariant * +static GVariant * _nm_utils_strdict_to_dbus (const GValue *prop_value) { GHashTable *hash; @@ -825,9 +825,15 @@ _nm_utils_strdict_to_dbus (const GValue *prop_value) if (len == 1) g_variant_builder_add (&builder, "{ss}", key, value); else { - gs_free NMUtilsNamedValue *idx = NULL; + gs_free NMUtilsNamedValue *idx_free = NULL; + NMUtilsNamedValue *idx; + + if (len > 300 / sizeof (NMUtilsNamedValue)) { + idx_free = g_new (NMUtilsNamedValue, len); + idx = idx_free; + } else + idx = g_alloca (sizeof (NMUtilsNamedValue) * len); - idx = g_new (NMUtilsNamedValue, len); i = 0; do { idx[i].name = key; @@ -862,6 +868,12 @@ _nm_utils_strdict_from_dbus (GVariant *dbus_value, g_value_take_boxed (prop_value, hash); } +const NMSettInfoPropertType nm_sett_info_propert_type_strdict = { + .dbus_type = NM_G_VARIANT_TYPE ("a{ss}"), + .gprop_to_dbus_fcn = _nm_utils_strdict_to_dbus, + .gprop_from_dbus_fcn = _nm_utils_strdict_from_dbus, +}; + GHashTable * _nm_utils_copy_strdict (GHashTable *strdict) { @@ -4305,7 +4317,7 @@ _nm_utils_hwaddr_to_dbus_impl (const char *str) return g_variant_new_fixed_array (G_VARIANT_TYPE_BYTE, buf, len, 1); } -GVariant * +static GVariant * _nm_utils_hwaddr_cloned_get (const NMSettInfoSetting *sett_info, guint property_idx, NMConnection *connection, @@ -4321,7 +4333,7 @@ _nm_utils_hwaddr_cloned_get (const NMSettInfoSetting *sett_info, return _nm_utils_hwaddr_to_dbus_impl (addr); } -gboolean +static gboolean _nm_utils_hwaddr_cloned_set (NMSetting *setting, GVariant *connection_dict, const char *property, @@ -4353,7 +4365,7 @@ _nm_utils_hwaddr_cloned_set (NMSetting *setting, return TRUE; } -gboolean +static gboolean _nm_utils_hwaddr_cloned_not_set (NMSetting *setting, GVariant *connection_dict, const char *property, @@ -4364,7 +4376,14 @@ _nm_utils_hwaddr_cloned_not_set (NMSetting *setting, return TRUE; } -GVariant * +const NMSettInfoPropertType nm_sett_info_propert_type_cloned_mac_address = { + .dbus_type = G_VARIANT_TYPE_BYTESTRING, + .to_dbus_fcn = _nm_utils_hwaddr_cloned_get, + .from_dbus_fcn = _nm_utils_hwaddr_cloned_set, + .missing_from_dbus_fcn = _nm_utils_hwaddr_cloned_not_set, +}; + +static GVariant * _nm_utils_hwaddr_cloned_data_synth (const NMSettInfoSetting *sett_info, guint property_idx, NMConnection *connection, @@ -4403,7 +4422,7 @@ _nm_utils_hwaddr_cloned_data_synth (const NMSettInfoSetting *sett_info, : NULL; } -gboolean +static gboolean _nm_utils_hwaddr_cloned_data_set (NMSetting *setting, GVariant *connection_dict, const char *property, @@ -4423,13 +4442,19 @@ _nm_utils_hwaddr_cloned_data_set (NMSetting *setting, return TRUE; } -GVariant * +const NMSettInfoPropertType nm_sett_info_propert_type_assigned_mac_address = { + .dbus_type = G_VARIANT_TYPE_STRING, + .to_dbus_fcn = _nm_utils_hwaddr_cloned_data_synth, + .from_dbus_fcn = _nm_utils_hwaddr_cloned_data_set, +}; + +static GVariant * _nm_utils_hwaddr_to_dbus (const GValue *prop_value) { return _nm_utils_hwaddr_to_dbus_impl (g_value_get_string (prop_value)); } -void +static void _nm_utils_hwaddr_from_dbus (GVariant *dbus_value, GValue *prop_value) { @@ -4441,6 +4466,12 @@ _nm_utils_hwaddr_from_dbus (GVariant *dbus_value, g_value_take_string (prop_value, str); } +const NMSettInfoPropertType nm_sett_info_propert_type_mac_addrees = { + .dbus_type = G_VARIANT_TYPE_BYTESTRING, + .gprop_to_dbus_fcn = _nm_utils_hwaddr_to_dbus, + .gprop_from_dbus_fcn = _nm_utils_hwaddr_from_dbus, +}; + /*****************************************************************************/ /* Validate secret-flags. Most settings don't validate them, which is a bug. @@ -5889,7 +5920,7 @@ nm_utils_base64secret_normalize (const char *base64_key, return TRUE; } -GVariant * +static GVariant * _nm_utils_bridge_vlans_to_dbus (const NMSettInfoSetting *sett_info, guint property_idx, NMConnection *connection, @@ -5931,7 +5962,7 @@ _nm_utils_bridge_vlans_to_dbus (const NMSettInfoSetting *sett_info, return g_variant_builder_end (&builder); } -gboolean +static gboolean _nm_utils_bridge_vlans_from_dbus (NMSetting *setting, GVariant *connection_dict, const char *property, @@ -5985,6 +6016,12 @@ _nm_utils_bridge_vlans_from_dbus (NMSetting *setting, return TRUE; } +const NMSettInfoPropertType nm_sett_info_propert_type_bridge_vlans = { + .dbus_type = NM_G_VARIANT_TYPE ("aa{sv}"), + .to_dbus_fcn = _nm_utils_bridge_vlans_to_dbus, + .from_dbus_fcn = _nm_utils_bridge_vlans_from_dbus, +}; + gboolean _nm_utils_bridge_vlan_verify_list (GPtrArray *vlans, gboolean check_normalizable, diff --git a/libnm-core/tests/test-setting.c b/libnm-core/tests/test-setting.c index ee0caa3d19..1cbdf07cd0 100644 --- a/libnm-core/tests/test-setting.c +++ b/libnm-core/tests/test-setting.c @@ -3318,14 +3318,63 @@ test_empty_setting (void) /*****************************************************************************/ +static guint +_PROP_IDX_PACK (NMMetaSettingType meta_type, + guint idx) +{ + return (((guint) meta_type) & 0xFFu) + | (idx << 8); +} + +static const char * +_PROP_IDX_OWNER (GHashTable *h_property_types, + const NMSettInfoPropertType *property_type) +{ + const NMSettInfoSetting *sett_info_settings = nmtst_sett_info_settings (); + const NMSettInfoSetting *sis; + const NMMetaSettingInfo *msi; + GArray *arr; + guint idx; + NMMetaSettingType meta_type; + guint prop_idx; + char sbuf[300]; + + g_assert (h_property_types); + g_assert (property_type); + + arr = g_hash_table_lookup (h_property_types, property_type); + + g_assert (arr); + g_assert (arr->len > 0); + + idx = g_array_index (arr, guint, 0); + + meta_type = (idx & 0xFFu); + prop_idx = idx >> 8; + + g_assert (meta_type < _NM_META_SETTING_TYPE_NUM); + + sis = &sett_info_settings[meta_type]; + msi = &nm_meta_setting_infos[meta_type]; + + g_assert (prop_idx < sis->property_infos_len); + + nm_sprintf_buf (sbuf, "%s.%s", msi->setting_name, sis->property_infos[prop_idx].name); + + return g_intern_string (sbuf); +} + static void test_setting_metadata (void) { const NMSettInfoSetting *sett_info_settings = nmtst_sett_info_settings (); NMMetaSettingType meta_type; + gs_unref_hashtable GHashTable *h_property_types = NULL; G_STATIC_ASSERT (_NM_META_SETTING_TYPE_NUM == NM_META_SETTING_TYPE_UNKNOWN); + h_property_types = g_hash_table_new_full (nm_direct_hash, NULL, NULL, (GDestroyNotify) g_array_unref); + for (meta_type = 0; meta_type < _NM_META_SETTING_TYPE_NUM; meta_type++) { const NMMetaSettingInfo *msi = &nm_meta_setting_infos[meta_type]; nm_auto_unref_gtypeclass NMSettingClass *klass = NULL; @@ -3348,6 +3397,8 @@ test_setting_metadata (void) klass = g_type_class_ref (gtype); g_assert (klass); g_assert (NM_IS_SETTING_CLASS (klass)); + + g_assert (msi == klass->setting_info); } g_assert (sett_info_settings); @@ -3381,18 +3432,33 @@ test_setting_metadata (void) for (prop_idx = 0; prop_idx < sis->property_infos_len; prop_idx++) { const NMSettInfoProperty *sip = &sis->property_infos[prop_idx]; + GArray *property_types_data; + guint prop_idx_val; g_assert (sip->name); if (prop_idx > 0) g_assert_cmpint (strcmp (sis->property_infos[prop_idx - 1].name, sip->name), <, 0); - g_assert (sip->dbus_type); - g_assert (g_variant_type_string_is_valid ((const char *) sip->dbus_type)); + g_assert (sip->property_type); + g_assert (sip->property_type->dbus_type); + g_assert (g_variant_type_string_is_valid ((const char *) sip->property_type->dbus_type)); + + g_assert (!sip->property_type->to_dbus_fcn || !sip->property_type->gprop_to_dbus_fcn); + g_assert (!sip->property_type->from_dbus_fcn || !sip->property_type->gprop_from_dbus_fcn); if (!g_hash_table_insert (h_properties, (char *) sip->name, sip->param_spec)) g_assert_not_reached (); + property_types_data = g_hash_table_lookup (h_property_types, sip->property_type); + if (!property_types_data) { + property_types_data = g_array_new (FALSE, FALSE, sizeof (guint)); + if (!g_hash_table_insert (h_property_types, (gpointer) sip->property_type, property_types_data)) + g_assert_not_reached (); + } + prop_idx_val = _PROP_IDX_PACK (meta_type, prop_idx); + g_array_append_val (property_types_data, prop_idx_val); + if (sip->param_spec) { nm_auto_unset_gvalue GValue val = G_VALUE_INIT; @@ -3421,6 +3487,9 @@ test_setting_metadata (void) else g_assert_cmpstr (g_value_get_string (&val), ==, default_value); } + + if (NM_FLAGS_HAS (sip->param_spec->flags, NM_SETTING_PARAM_TO_DBUS_IGNORE_FLAGS)) + g_assert (sip->property_type->to_dbus_fcn); } } @@ -3469,6 +3538,51 @@ test_setting_metadata (void) } else g_assert_cmpint (meta_type, !=, NM_META_SETTING_TYPE_ETHTOOL); } + + { + gs_free NMSettInfoPropertType **a_property_types = NULL; + guint a_property_types_len; + guint prop_idx; + guint prop_idx_2; + + a_property_types = (NMSettInfoPropertType **) g_hash_table_get_keys_as_array (h_property_types, &a_property_types_len); + + for (prop_idx = 0; prop_idx < a_property_types_len; prop_idx++) { + const NMSettInfoPropertType *pt = a_property_types[prop_idx]; + + for (prop_idx_2 = prop_idx + 1; prop_idx_2 < a_property_types_len; prop_idx_2++) { + const NMSettInfoPropertType *pt_2 = a_property_types[prop_idx_2]; + + if ( !g_variant_type_equal (pt->dbus_type, pt_2->dbus_type) + || pt->to_dbus_fcn != pt_2->to_dbus_fcn + || pt->from_dbus_fcn != pt_2->from_dbus_fcn + || pt->missing_from_dbus_fcn != pt_2->missing_from_dbus_fcn + || pt->gprop_to_dbus_fcn != pt_2->gprop_to_dbus_fcn + || pt->gprop_from_dbus_fcn != pt_2->gprop_from_dbus_fcn) + continue; + + if ( (pt == &nm_sett_info_propert_type_plain_i && pt_2 == &nm_sett_info_propert_type_deprecated_ignore_i) + || (pt_2 == &nm_sett_info_propert_type_plain_i && pt == &nm_sett_info_propert_type_deprecated_ignore_i) + || (pt == &nm_sett_info_propert_type_plain_u && pt_2 == &nm_sett_info_propert_type_deprecated_ignore_u) + || (pt_2 == &nm_sett_info_propert_type_plain_u && pt == &nm_sett_info_propert_type_deprecated_ignore_u)) { + /* These are known to be duplicated. This is the case for + * "gsm.network-type" and plain properies like "802-11-wireless-security.fils" ("i" D-Bus type) + * "gsm.allowed-bands" and plain properies like "802-11-olpc-mesh.channel" ("u" D-Bus type) + * While the content/behaviour of the property types are identical, their purpose + * is different. So allowe them. + */ + continue; + } + + /* the property-types with same content should all be shared. Here we have two that + * are the same content, but different instances. Bug. */ + g_error ("The identical property type for D-Bus type \"%s\" is used by: %s and %s", + (const char *) pt->dbus_type, + _PROP_IDX_OWNER (h_property_types, pt), + _PROP_IDX_OWNER (h_property_types, pt_2)); + } + } + } } /*****************************************************************************/ diff --git a/shared/nm-glib-aux/nm-macros-internal.h b/shared/nm-glib-aux/nm-macros-internal.h index 9292f3699d..09f96ef6ba 100644 --- a/shared/nm-glib-aux/nm-macros-internal.h +++ b/shared/nm-glib-aux/nm-macros-internal.h @@ -1262,6 +1262,14 @@ nm_clear_g_cancellable_disconnect (GCancellable *cancellable, gulong *cancellabl /*****************************************************************************/ +/* GVariantType is basically a C string. But G_VARIANT_TYPE() is not suitable + * to initialize a static variable (because it evaluates a function check that + * the string is valid). Add an alternative macro that does the plain cast. + * + * Here you loose the assertion check that G_VARIANT_TYPE() to ensure the + * string is valid. */ +#define NM_G_VARIANT_TYPE(fmt) ((const GVariantType *) (""fmt"")) + static inline GVariant * nm_g_variant_ref (GVariant *v) { |