mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-01 02:30:11 +01:00
libnm: merge branch 'th/connection-get-setting-cleanup'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1618
This commit is contained in:
commit
20cf4ff31a
5 changed files with 113 additions and 85 deletions
|
|
@ -370,6 +370,20 @@ nm_settings_connection_get_connection(NMSettingsConnection *self)
|
|||
return NM_SETTINGS_CONNECTION_GET_PRIVATE(self)->connection;
|
||||
}
|
||||
|
||||
gpointer
|
||||
nm_settings_connection_get_setting(NMSettingsConnection *self, NMMetaSettingType meta_type)
|
||||
{
|
||||
NMConnection *connection;
|
||||
|
||||
nm_assert(NM_IS_SETTINGS_CONNECTION(self));
|
||||
|
||||
connection = NM_SETTINGS_CONNECTION_GET_PRIVATE(self)->connection;
|
||||
|
||||
nm_assert(NM_IS_SIMPLE_CONNECTION(connection));
|
||||
|
||||
return _nm_connection_get_setting_by_metatype_unsafe(connection, meta_type);
|
||||
}
|
||||
|
||||
void
|
||||
_nm_settings_connection_set_connection(NMSettingsConnection *self,
|
||||
NMConnection *new_connection,
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@
|
|||
#ifndef __NETWORKMANAGER_SETTINGS_CONNECTION_H__
|
||||
#define __NETWORKMANAGER_SETTINGS_CONNECTION_H__
|
||||
|
||||
#include "libnm-core-intern/nm-meta-setting-base.h"
|
||||
|
||||
#include "nm-dbus-object.h"
|
||||
#include "nm-connection.h"
|
||||
#include "NetworkManagerUtils.h"
|
||||
|
|
@ -211,6 +213,8 @@ NMSettings *nm_settings_connection_get_settings(NMSettingsConnection *self);
|
|||
NMManager *nm_settings_connection_get_manager(NMSettingsConnection *self);
|
||||
|
||||
NMConnection *nm_settings_connection_get_connection(NMSettingsConnection *self);
|
||||
gpointer nm_settings_connection_get_setting(NMSettingsConnection *self,
|
||||
NMMetaSettingType meta_type);
|
||||
|
||||
void _nm_settings_connection_set_connection(NMSettingsConnection *self,
|
||||
NMConnection *new_connection,
|
||||
|
|
|
|||
|
|
@ -276,26 +276,7 @@ nm_connection_remove_setting(NMConnection *connection, GType setting_type)
|
|||
}
|
||||
|
||||
static gpointer
|
||||
_connection_get_setting(NMConnection *connection, GType setting_type)
|
||||
{
|
||||
NMSetting *setting;
|
||||
const NMMetaSettingInfo *setting_info;
|
||||
|
||||
nm_assert(NM_IS_CONNECTION(connection));
|
||||
nm_assert(g_type_is_a(setting_type, NM_TYPE_SETTING));
|
||||
|
||||
setting_info = _nm_meta_setting_info_from_gtype(setting_type);
|
||||
if (!setting_info)
|
||||
g_return_val_if_reached(NULL);
|
||||
|
||||
setting = NM_CONNECTION_GET_PRIVATE(connection)->settings[setting_info->meta_type];
|
||||
|
||||
nm_assert(!setting || G_TYPE_CHECK_INSTANCE_TYPE(setting, setting_type));
|
||||
return setting;
|
||||
}
|
||||
|
||||
static gpointer
|
||||
_connection_get_setting_by_meta_type(NMConnectionPrivate *priv, NMMetaSettingType meta_type)
|
||||
_get_setting_by_metatype(NMConnectionPrivate *priv, NMMetaSettingType meta_type)
|
||||
{
|
||||
nm_assert(priv);
|
||||
nm_assert(_NM_INT_NOT_NEGATIVE(meta_type));
|
||||
|
|
@ -304,20 +285,15 @@ _connection_get_setting_by_meta_type(NMConnectionPrivate *priv, NMMetaSettingTyp
|
|||
return priv->settings[meta_type];
|
||||
}
|
||||
|
||||
static gpointer
|
||||
_connection_get_setting_check(NMConnection *connection, GType setting_type)
|
||||
/* The "unsafe" part here is that _nm_connection_get_setting_by_metatype() has a compile
|
||||
* time check that meta_type is valid. With the unsafe variant, the caller must ensure that,
|
||||
* and we only get an nm_assert() check -- which is basically nothing. */
|
||||
gpointer
|
||||
_nm_connection_get_setting_by_metatype_unsafe(NMConnection *connection, NMMetaSettingType meta_type)
|
||||
{
|
||||
g_return_val_if_fail(NM_IS_CONNECTION(connection), NULL);
|
||||
|
||||
return _connection_get_setting(connection, setting_type);
|
||||
}
|
||||
|
||||
static gpointer
|
||||
_connection_get_setting_by_meta_type_check(NMConnection *connection, NMMetaSettingType meta_type)
|
||||
{
|
||||
g_return_val_if_fail(NM_IS_CONNECTION(connection), NULL);
|
||||
|
||||
return _connection_get_setting_by_meta_type(NM_CONNECTION_GET_PRIVATE(connection), meta_type);
|
||||
return _get_setting_by_metatype(NM_CONNECTION_GET_PRIVATE(connection), meta_type);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -334,19 +310,34 @@ _connection_get_setting_by_meta_type_check(NMConnection *connection, NMMetaSetti
|
|||
NMSetting *
|
||||
nm_connection_get_setting(NMConnection *connection, GType setting_type)
|
||||
{
|
||||
g_return_val_if_fail(g_type_is_a(setting_type, NM_TYPE_SETTING), NULL);
|
||||
NMSetting *setting;
|
||||
const NMMetaSettingInfo *setting_info;
|
||||
|
||||
return _connection_get_setting_check(connection, setting_type);
|
||||
g_return_val_if_fail(NM_IS_CONNECTION(connection), NULL);
|
||||
|
||||
setting_info = _nm_meta_setting_info_from_gtype(setting_type);
|
||||
|
||||
if (!setting_info)
|
||||
g_return_val_if_reached(NULL);
|
||||
|
||||
setting = NM_CONNECTION_GET_PRIVATE(connection)->settings[setting_info->meta_type];
|
||||
|
||||
nm_assert(!setting || G_TYPE_CHECK_INSTANCE_TYPE(setting, setting_type));
|
||||
|
||||
return setting;
|
||||
}
|
||||
|
||||
NMSettingIPConfig *
|
||||
nm_connection_get_setting_ip_config(NMConnection *connection, int addr_family)
|
||||
{
|
||||
g_return_val_if_fail(NM_IS_CONNECTION(connection), NULL);
|
||||
|
||||
nm_assert_addr_family(addr_family);
|
||||
|
||||
return NM_SETTING_IP_CONFIG(_connection_get_setting(
|
||||
connection,
|
||||
(addr_family == AF_INET) ? NM_TYPE_SETTING_IP4_CONFIG : NM_TYPE_SETTING_IP6_CONFIG));
|
||||
return NM_SETTING_IP_CONFIG(_get_setting_by_metatype(NM_CONNECTION_GET_PRIVATE(connection),
|
||||
(addr_family == AF_INET)
|
||||
? NM_META_SETTING_TYPE_IP4_CONFIG
|
||||
: NM_META_SETTING_TYPE_IP6_CONFIG));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -363,12 +354,14 @@ nm_connection_get_setting_ip_config(NMConnection *connection, int addr_family)
|
|||
NMSetting *
|
||||
nm_connection_get_setting_by_name(NMConnection *connection, const char *name)
|
||||
{
|
||||
GType type;
|
||||
const NMMetaSettingInfo *setting_info;
|
||||
|
||||
g_return_val_if_fail(NM_IS_CONNECTION(connection), NULL);
|
||||
|
||||
type = nm_setting_lookup_type(name);
|
||||
return type ? _connection_get_setting(connection, type) : NULL;
|
||||
setting_info = nm_meta_setting_infos_by_name(name);
|
||||
return setting_info ? _get_setting_by_metatype(NM_CONNECTION_GET_PRIVATE(connection),
|
||||
setting_info->meta_type)
|
||||
: NULL;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
|
@ -1672,8 +1665,8 @@ _normalize_802_1x_empty_strings(NMConnection *self)
|
|||
NMSetting8021x *s_8021x;
|
||||
gboolean changed = FALSE;
|
||||
|
||||
s_8021x = _connection_get_setting_by_meta_type(NM_CONNECTION_GET_PRIVATE(self),
|
||||
NM_META_SETTING_TYPE_802_1X);
|
||||
s_8021x =
|
||||
_get_setting_by_metatype(NM_CONNECTION_GET_PRIVATE(self), NM_META_SETTING_TYPE_802_1X);
|
||||
if (!s_8021x)
|
||||
return FALSE;
|
||||
|
||||
|
|
@ -1823,7 +1816,7 @@ _nm_connection_verify(NMConnection *connection, GError **error)
|
|||
|
||||
priv = NM_CONNECTION_GET_PRIVATE(connection);
|
||||
|
||||
if (!_connection_get_setting_by_meta_type(priv, NM_META_SETTING_TYPE_CONNECTION)) {
|
||||
if (!_get_setting_by_metatype(priv, NM_META_SETTING_TYPE_CONNECTION)) {
|
||||
g_set_error_literal(error,
|
||||
NM_CONNECTION_ERROR,
|
||||
NM_CONNECTION_ERROR_MISSING_SETTING,
|
||||
|
|
@ -1868,9 +1861,9 @@ _nm_connection_verify(NMConnection *connection, GError **error)
|
|||
g_clear_error(&verify_error);
|
||||
}
|
||||
|
||||
s_ip4 = _connection_get_setting_by_meta_type(priv, NM_META_SETTING_TYPE_IP4_CONFIG);
|
||||
s_ip6 = _connection_get_setting_by_meta_type(priv, NM_META_SETTING_TYPE_IP6_CONFIG);
|
||||
s_proxy = _connection_get_setting_by_meta_type(priv, NM_META_SETTING_TYPE_PROXY);
|
||||
s_ip4 = _get_setting_by_metatype(priv, NM_META_SETTING_TYPE_IP4_CONFIG);
|
||||
s_ip6 = _get_setting_by_metatype(priv, NM_META_SETTING_TYPE_IP6_CONFIG);
|
||||
s_proxy = _get_setting_by_metatype(priv, NM_META_SETTING_TYPE_PROXY);
|
||||
|
||||
nm_assert(normalizable_error_type != NM_SETTING_VERIFY_ERROR);
|
||||
if (NM_IN_SET(normalizable_error_type,
|
||||
|
|
@ -3262,7 +3255,7 @@ nm_connection_get_virtual_device_description(NMConnection *connection)
|
|||
NMSetting8021x *
|
||||
nm_connection_get_setting_802_1x(NMConnection *connection)
|
||||
{
|
||||
return _connection_get_setting_by_meta_type_check(connection, NM_META_SETTING_TYPE_802_1X);
|
||||
return _nm_connection_get_setting_by_metatype(connection, NM_META_SETTING_TYPE_802_1X);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -3276,7 +3269,7 @@ nm_connection_get_setting_802_1x(NMConnection *connection)
|
|||
NMSettingBluetooth *
|
||||
nm_connection_get_setting_bluetooth(NMConnection *connection)
|
||||
{
|
||||
return _connection_get_setting_by_meta_type_check(connection, NM_META_SETTING_TYPE_BLUETOOTH);
|
||||
return _nm_connection_get_setting_by_metatype(connection, NM_META_SETTING_TYPE_BLUETOOTH);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -3290,7 +3283,7 @@ nm_connection_get_setting_bluetooth(NMConnection *connection)
|
|||
NMSettingBond *
|
||||
nm_connection_get_setting_bond(NMConnection *connection)
|
||||
{
|
||||
return _connection_get_setting_by_meta_type_check(connection, NM_META_SETTING_TYPE_BOND);
|
||||
return _nm_connection_get_setting_by_metatype(connection, NM_META_SETTING_TYPE_BOND);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -3304,7 +3297,7 @@ nm_connection_get_setting_bond(NMConnection *connection)
|
|||
NMSettingTeam *
|
||||
nm_connection_get_setting_team(NMConnection *connection)
|
||||
{
|
||||
return _connection_get_setting_by_meta_type_check(connection, NM_META_SETTING_TYPE_TEAM);
|
||||
return _nm_connection_get_setting_by_metatype(connection, NM_META_SETTING_TYPE_TEAM);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -3318,7 +3311,7 @@ nm_connection_get_setting_team(NMConnection *connection)
|
|||
NMSettingTeamPort *
|
||||
nm_connection_get_setting_team_port(NMConnection *connection)
|
||||
{
|
||||
return _connection_get_setting_by_meta_type_check(connection, NM_META_SETTING_TYPE_TEAM_PORT);
|
||||
return _nm_connection_get_setting_by_metatype(connection, NM_META_SETTING_TYPE_TEAM_PORT);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -3332,7 +3325,7 @@ nm_connection_get_setting_team_port(NMConnection *connection)
|
|||
NMSettingBridge *
|
||||
nm_connection_get_setting_bridge(NMConnection *connection)
|
||||
{
|
||||
return _connection_get_setting_by_meta_type_check(connection, NM_META_SETTING_TYPE_BRIDGE);
|
||||
return _nm_connection_get_setting_by_metatype(connection, NM_META_SETTING_TYPE_BRIDGE);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -3346,7 +3339,7 @@ nm_connection_get_setting_bridge(NMConnection *connection)
|
|||
NMSettingCdma *
|
||||
nm_connection_get_setting_cdma(NMConnection *connection)
|
||||
{
|
||||
return _connection_get_setting_by_meta_type_check(connection, NM_META_SETTING_TYPE_CDMA);
|
||||
return _nm_connection_get_setting_by_metatype(connection, NM_META_SETTING_TYPE_CDMA);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -3360,7 +3353,7 @@ nm_connection_get_setting_cdma(NMConnection *connection)
|
|||
NMSettingConnection *
|
||||
nm_connection_get_setting_connection(NMConnection *connection)
|
||||
{
|
||||
return _connection_get_setting_by_meta_type_check(connection, NM_META_SETTING_TYPE_CONNECTION);
|
||||
return _nm_connection_get_setting_by_metatype(connection, NM_META_SETTING_TYPE_CONNECTION);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -3374,7 +3367,7 @@ nm_connection_get_setting_connection(NMConnection *connection)
|
|||
NMSettingDcb *
|
||||
nm_connection_get_setting_dcb(NMConnection *connection)
|
||||
{
|
||||
return _connection_get_setting_by_meta_type_check(connection, NM_META_SETTING_TYPE_DCB);
|
||||
return _nm_connection_get_setting_by_metatype(connection, NM_META_SETTING_TYPE_DCB);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -3390,7 +3383,7 @@ nm_connection_get_setting_dcb(NMConnection *connection)
|
|||
NMSettingDummy *
|
||||
nm_connection_get_setting_dummy(NMConnection *connection)
|
||||
{
|
||||
return _connection_get_setting_by_meta_type_check(connection, NM_META_SETTING_TYPE_DUMMY);
|
||||
return _nm_connection_get_setting_by_metatype(connection, NM_META_SETTING_TYPE_DUMMY);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -3404,7 +3397,7 @@ nm_connection_get_setting_dummy(NMConnection *connection)
|
|||
NMSettingGeneric *
|
||||
nm_connection_get_setting_generic(NMConnection *connection)
|
||||
{
|
||||
return _connection_get_setting_by_meta_type_check(connection, NM_META_SETTING_TYPE_GENERIC);
|
||||
return _nm_connection_get_setting_by_metatype(connection, NM_META_SETTING_TYPE_GENERIC);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -3418,7 +3411,7 @@ nm_connection_get_setting_generic(NMConnection *connection)
|
|||
NMSettingGsm *
|
||||
nm_connection_get_setting_gsm(NMConnection *connection)
|
||||
{
|
||||
return _connection_get_setting_by_meta_type_check(connection, NM_META_SETTING_TYPE_GSM);
|
||||
return _nm_connection_get_setting_by_metatype(connection, NM_META_SETTING_TYPE_GSM);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -3432,7 +3425,7 @@ nm_connection_get_setting_gsm(NMConnection *connection)
|
|||
NMSettingInfiniband *
|
||||
nm_connection_get_setting_infiniband(NMConnection *connection)
|
||||
{
|
||||
return _connection_get_setting_by_meta_type_check(connection, NM_META_SETTING_TYPE_INFINIBAND);
|
||||
return _nm_connection_get_setting_by_metatype(connection, NM_META_SETTING_TYPE_INFINIBAND);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -3451,7 +3444,7 @@ nm_connection_get_setting_infiniband(NMConnection *connection)
|
|||
NMSettingIPConfig *
|
||||
nm_connection_get_setting_ip4_config(NMConnection *connection)
|
||||
{
|
||||
return _connection_get_setting_by_meta_type_check(connection, NM_META_SETTING_TYPE_IP4_CONFIG);
|
||||
return _nm_connection_get_setting_by_metatype(connection, NM_META_SETTING_TYPE_IP4_CONFIG);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -3467,7 +3460,7 @@ nm_connection_get_setting_ip4_config(NMConnection *connection)
|
|||
NMSettingIPTunnel *
|
||||
nm_connection_get_setting_ip_tunnel(NMConnection *connection)
|
||||
{
|
||||
return _connection_get_setting_by_meta_type_check(connection, NM_META_SETTING_TYPE_IP_TUNNEL);
|
||||
return _nm_connection_get_setting_by_metatype(connection, NM_META_SETTING_TYPE_IP_TUNNEL);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -3486,7 +3479,7 @@ nm_connection_get_setting_ip_tunnel(NMConnection *connection)
|
|||
NMSettingIPConfig *
|
||||
nm_connection_get_setting_ip6_config(NMConnection *connection)
|
||||
{
|
||||
return _connection_get_setting_by_meta_type_check(connection, NM_META_SETTING_TYPE_IP6_CONFIG);
|
||||
return _nm_connection_get_setting_by_metatype(connection, NM_META_SETTING_TYPE_IP6_CONFIG);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -3502,7 +3495,7 @@ nm_connection_get_setting_ip6_config(NMConnection *connection)
|
|||
NMSettingMacsec *
|
||||
nm_connection_get_setting_macsec(NMConnection *connection)
|
||||
{
|
||||
return _connection_get_setting_by_meta_type_check(connection, NM_META_SETTING_TYPE_MACSEC);
|
||||
return _nm_connection_get_setting_by_metatype(connection, NM_META_SETTING_TYPE_MACSEC);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -3518,7 +3511,7 @@ nm_connection_get_setting_macsec(NMConnection *connection)
|
|||
NMSettingMacvlan *
|
||||
nm_connection_get_setting_macvlan(NMConnection *connection)
|
||||
{
|
||||
return _connection_get_setting_by_meta_type_check(connection, NM_META_SETTING_TYPE_MACVLAN);
|
||||
return _nm_connection_get_setting_by_metatype(connection, NM_META_SETTING_TYPE_MACVLAN);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -3532,7 +3525,7 @@ nm_connection_get_setting_macvlan(NMConnection *connection)
|
|||
NMSettingOlpcMesh *
|
||||
nm_connection_get_setting_olpc_mesh(NMConnection *connection)
|
||||
{
|
||||
return _connection_get_setting_by_meta_type_check(connection, NM_META_SETTING_TYPE_OLPC_MESH);
|
||||
return _nm_connection_get_setting_by_metatype(connection, NM_META_SETTING_TYPE_OLPC_MESH);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -3548,7 +3541,7 @@ nm_connection_get_setting_olpc_mesh(NMConnection *connection)
|
|||
NMSettingOvsBridge *
|
||||
nm_connection_get_setting_ovs_bridge(NMConnection *connection)
|
||||
{
|
||||
return _connection_get_setting_by_meta_type_check(connection, NM_META_SETTING_TYPE_OVS_BRIDGE);
|
||||
return _nm_connection_get_setting_by_metatype(connection, NM_META_SETTING_TYPE_OVS_BRIDGE);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -3564,8 +3557,7 @@ nm_connection_get_setting_ovs_bridge(NMConnection *connection)
|
|||
NMSettingOvsInterface *
|
||||
nm_connection_get_setting_ovs_interface(NMConnection *connection)
|
||||
{
|
||||
return _connection_get_setting_by_meta_type_check(connection,
|
||||
NM_META_SETTING_TYPE_OVS_INTERFACE);
|
||||
return _nm_connection_get_setting_by_metatype(connection, NM_META_SETTING_TYPE_OVS_INTERFACE);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -3581,7 +3573,7 @@ nm_connection_get_setting_ovs_interface(NMConnection *connection)
|
|||
NMSettingOvsPatch *
|
||||
nm_connection_get_setting_ovs_patch(NMConnection *connection)
|
||||
{
|
||||
return _connection_get_setting_by_meta_type_check(connection, NM_META_SETTING_TYPE_OVS_PATCH);
|
||||
return _nm_connection_get_setting_by_metatype(connection, NM_META_SETTING_TYPE_OVS_PATCH);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -3597,7 +3589,7 @@ nm_connection_get_setting_ovs_patch(NMConnection *connection)
|
|||
NMSettingOvsPort *
|
||||
nm_connection_get_setting_ovs_port(NMConnection *connection)
|
||||
{
|
||||
return _connection_get_setting_by_meta_type_check(connection, NM_META_SETTING_TYPE_OVS_PORT);
|
||||
return _nm_connection_get_setting_by_metatype(connection, NM_META_SETTING_TYPE_OVS_PORT);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -3611,7 +3603,7 @@ nm_connection_get_setting_ovs_port(NMConnection *connection)
|
|||
NMSettingPpp *
|
||||
nm_connection_get_setting_ppp(NMConnection *connection)
|
||||
{
|
||||
return _connection_get_setting_by_meta_type_check(connection, NM_META_SETTING_TYPE_PPP);
|
||||
return _nm_connection_get_setting_by_metatype(connection, NM_META_SETTING_TYPE_PPP);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -3625,7 +3617,7 @@ nm_connection_get_setting_ppp(NMConnection *connection)
|
|||
NMSettingPppoe *
|
||||
nm_connection_get_setting_pppoe(NMConnection *connection)
|
||||
{
|
||||
return _connection_get_setting_by_meta_type_check(connection, NM_META_SETTING_TYPE_PPPOE);
|
||||
return _nm_connection_get_setting_by_metatype(connection, NM_META_SETTING_TYPE_PPPOE);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -3641,7 +3633,7 @@ nm_connection_get_setting_pppoe(NMConnection *connection)
|
|||
NMSettingProxy *
|
||||
nm_connection_get_setting_proxy(NMConnection *connection)
|
||||
{
|
||||
return _connection_get_setting_by_meta_type_check(connection, NM_META_SETTING_TYPE_PROXY);
|
||||
return _nm_connection_get_setting_by_metatype(connection, NM_META_SETTING_TYPE_PROXY);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -3655,7 +3647,7 @@ nm_connection_get_setting_proxy(NMConnection *connection)
|
|||
NMSettingSerial *
|
||||
nm_connection_get_setting_serial(NMConnection *connection)
|
||||
{
|
||||
return _connection_get_setting_by_meta_type_check(connection, NM_META_SETTING_TYPE_SERIAL);
|
||||
return _nm_connection_get_setting_by_metatype(connection, NM_META_SETTING_TYPE_SERIAL);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -3671,7 +3663,7 @@ nm_connection_get_setting_serial(NMConnection *connection)
|
|||
NMSettingTCConfig *
|
||||
nm_connection_get_setting_tc_config(NMConnection *connection)
|
||||
{
|
||||
return _connection_get_setting_by_meta_type_check(connection, NM_META_SETTING_TYPE_TC_CONFIG);
|
||||
return _nm_connection_get_setting_by_metatype(connection, NM_META_SETTING_TYPE_TC_CONFIG);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -3687,7 +3679,7 @@ nm_connection_get_setting_tc_config(NMConnection *connection)
|
|||
NMSettingTun *
|
||||
nm_connection_get_setting_tun(NMConnection *connection)
|
||||
{
|
||||
return _connection_get_setting_by_meta_type_check(connection, NM_META_SETTING_TYPE_TUN);
|
||||
return _nm_connection_get_setting_by_metatype(connection, NM_META_SETTING_TYPE_TUN);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -3701,7 +3693,7 @@ nm_connection_get_setting_tun(NMConnection *connection)
|
|||
NMSettingVpn *
|
||||
nm_connection_get_setting_vpn(NMConnection *connection)
|
||||
{
|
||||
return _connection_get_setting_by_meta_type_check(connection, NM_META_SETTING_TYPE_VPN);
|
||||
return _nm_connection_get_setting_by_metatype(connection, NM_META_SETTING_TYPE_VPN);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -3717,7 +3709,7 @@ nm_connection_get_setting_vpn(NMConnection *connection)
|
|||
NMSettingVxlan *
|
||||
nm_connection_get_setting_vxlan(NMConnection *connection)
|
||||
{
|
||||
return _connection_get_setting_by_meta_type_check(connection, NM_META_SETTING_TYPE_VXLAN);
|
||||
return _nm_connection_get_setting_by_metatype(connection, NM_META_SETTING_TYPE_VXLAN);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -3731,7 +3723,7 @@ nm_connection_get_setting_vxlan(NMConnection *connection)
|
|||
NMSettingWimax *
|
||||
nm_connection_get_setting_wimax(NMConnection *connection)
|
||||
{
|
||||
return _connection_get_setting_by_meta_type_check(connection, NM_META_SETTING_TYPE_WIMAX);
|
||||
return _nm_connection_get_setting_by_metatype(connection, NM_META_SETTING_TYPE_WIMAX);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -3745,7 +3737,7 @@ nm_connection_get_setting_wimax(NMConnection *connection)
|
|||
NMSettingWired *
|
||||
nm_connection_get_setting_wired(NMConnection *connection)
|
||||
{
|
||||
return _connection_get_setting_by_meta_type_check(connection, NM_META_SETTING_TYPE_WIRED);
|
||||
return _nm_connection_get_setting_by_metatype(connection, NM_META_SETTING_TYPE_WIRED);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -3759,7 +3751,7 @@ nm_connection_get_setting_wired(NMConnection *connection)
|
|||
NMSettingAdsl *
|
||||
nm_connection_get_setting_adsl(NMConnection *connection)
|
||||
{
|
||||
return _connection_get_setting_by_meta_type_check(connection, NM_META_SETTING_TYPE_ADSL);
|
||||
return _nm_connection_get_setting_by_metatype(connection, NM_META_SETTING_TYPE_ADSL);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -3773,7 +3765,7 @@ nm_connection_get_setting_adsl(NMConnection *connection)
|
|||
NMSettingWireless *
|
||||
nm_connection_get_setting_wireless(NMConnection *connection)
|
||||
{
|
||||
return _connection_get_setting_by_meta_type_check(connection, NM_META_SETTING_TYPE_WIRELESS);
|
||||
return _nm_connection_get_setting_by_metatype(connection, NM_META_SETTING_TYPE_WIRELESS);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -3787,8 +3779,8 @@ nm_connection_get_setting_wireless(NMConnection *connection)
|
|||
NMSettingWirelessSecurity *
|
||||
nm_connection_get_setting_wireless_security(NMConnection *connection)
|
||||
{
|
||||
return _connection_get_setting_by_meta_type_check(connection,
|
||||
NM_META_SETTING_TYPE_WIRELESS_SECURITY);
|
||||
return _nm_connection_get_setting_by_metatype(connection,
|
||||
NM_META_SETTING_TYPE_WIRELESS_SECURITY);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -3802,7 +3794,7 @@ nm_connection_get_setting_wireless_security(NMConnection *connection)
|
|||
NMSettingBridgePort *
|
||||
nm_connection_get_setting_bridge_port(NMConnection *connection)
|
||||
{
|
||||
return _connection_get_setting_by_meta_type_check(connection, NM_META_SETTING_TYPE_BRIDGE_PORT);
|
||||
return _nm_connection_get_setting_by_metatype(connection, NM_META_SETTING_TYPE_BRIDGE_PORT);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -3816,7 +3808,7 @@ nm_connection_get_setting_bridge_port(NMConnection *connection)
|
|||
NMSettingVlan *
|
||||
nm_connection_get_setting_vlan(NMConnection *connection)
|
||||
{
|
||||
return _connection_get_setting_by_meta_type_check(connection, NM_META_SETTING_TYPE_VLAN);
|
||||
return _nm_connection_get_setting_by_metatype(connection, NM_META_SETTING_TYPE_VLAN);
|
||||
}
|
||||
|
||||
NMSettingBluetooth *
|
||||
|
|
|
|||
|
|
@ -110,6 +110,10 @@ nm_setting_lookup_type(const char *name)
|
|||
{
|
||||
const NMMetaSettingInfo *setting_info;
|
||||
|
||||
/* various callers check whether the result is valid with plain `if (gtype)`.
|
||||
* Assert that G_TYPE_INVALID is zero. */
|
||||
G_STATIC_ASSERT(G_TYPE_INVALID == 0);
|
||||
|
||||
g_return_val_if_fail(name, G_TYPE_INVALID);
|
||||
|
||||
setting_info = nm_meta_setting_infos_by_name(name);
|
||||
|
|
|
|||
|
|
@ -455,6 +455,20 @@ _nm_connection_get_setting(NMConnection *connection, GType type)
|
|||
return (gpointer) nm_connection_get_setting(connection, type);
|
||||
}
|
||||
|
||||
gpointer _nm_connection_get_setting_by_metatype_unsafe(NMConnection *connection,
|
||||
NMMetaSettingType meta_type);
|
||||
|
||||
/* This variant is the most efficient one, because it does not require resolving a
|
||||
* name/GType first. The NMMetaSettingType enum allows for a direct lookup. */
|
||||
#define _nm_connection_get_setting_by_metatype(connection, meta_type) \
|
||||
({ \
|
||||
/* Static assert that meta_type is in the valid range. If you don't want that,
|
||||
* because the argument is no a compile time constant, use _nm_connection_get_setting_by_metatype_unsafe(). */ \
|
||||
G_STATIC_ASSERT((meta_type) < _NM_META_SETTING_TYPE_NUM && ((int) meta_type) >= 0); \
|
||||
\
|
||||
_nm_connection_get_setting_by_metatype_unsafe((connection), (meta_type)); \
|
||||
})
|
||||
|
||||
NMSettingIPConfig *nm_connection_get_setting_ip_config(NMConnection *connection, int addr_family);
|
||||
|
||||
/*****************************************************************************/
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue