mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager
synced 2024-07-21 18:24:49 +00:00
libnm-util: centralize find_setting_by_name code
Several settings types' verify() functions need to find a particular setting from the all_settings list that NMConnection passes them. Add a convenience function for this.
This commit is contained in:
parent
83c5a69126
commit
f4c3e2f643
|
@ -132,15 +132,6 @@ nm_setting_bluetooth_get_bdaddr (NMSettingBluetooth *setting)
|
|||
return NM_SETTING_BLUETOOTH_GET_PRIVATE (setting)->bdaddr;
|
||||
}
|
||||
|
||||
static gint
|
||||
find_setting_by_name (gconstpointer a, gconstpointer b)
|
||||
{
|
||||
NMSetting *setting = NM_SETTING (a);
|
||||
const char *str = (const char *) b;
|
||||
|
||||
return strcmp (nm_setting_get_name (setting), str);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
verify (NMSetting *setting, GSList *all_settings, GError **error)
|
||||
{
|
||||
|
@ -187,12 +178,8 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
|
|||
&& !strcmp (priv->type, NM_SETTING_BLUETOOTH_TYPE_DUN)) {
|
||||
gboolean gsm = FALSE, cdma = FALSE;
|
||||
|
||||
gsm = !!g_slist_find_custom (all_settings,
|
||||
(gpointer) NM_SETTING_GSM_SETTING_NAME,
|
||||
find_setting_by_name);
|
||||
cdma = !!g_slist_find_custom (all_settings,
|
||||
(gpointer) NM_SETTING_CDMA_SETTING_NAME,
|
||||
find_setting_by_name);
|
||||
gsm = !!nm_setting_find_in_list (all_settings, NM_SETTING_GSM_SETTING_NAME);
|
||||
cdma = !!nm_setting_find_in_list (all_settings, NM_SETTING_CDMA_SETTING_NAME);
|
||||
|
||||
if (!gsm && !cdma) {
|
||||
g_set_error (error,
|
||||
|
|
|
@ -348,15 +348,6 @@ nm_setting_bond_get_option_default (NMSettingBond *setting, const char *name)
|
|||
g_assert_not_reached ();
|
||||
}
|
||||
|
||||
static gint
|
||||
find_setting_by_name (gconstpointer a, gconstpointer b)
|
||||
{
|
||||
NMSetting *setting = NM_SETTING (a);
|
||||
const char *str = (const char *) b;
|
||||
|
||||
return strcmp (nm_setting_get_name (setting), str);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
verify (NMSetting *setting, GSList *all_settings, GError **error)
|
||||
{
|
||||
|
@ -485,7 +476,7 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
|
|||
}
|
||||
}
|
||||
|
||||
if (g_slist_find_custom (all_settings, NM_SETTING_INFINIBAND_SETTING_NAME, find_setting_by_name)) {
|
||||
if (nm_setting_find_in_list (all_settings, NM_SETTING_INFINIBAND_SETTING_NAME)) {
|
||||
if (strcmp (value, "active-backup") != 0) {
|
||||
g_set_error (error,
|
||||
NM_SETTING_BOND_ERROR,
|
||||
|
|
|
@ -678,15 +678,6 @@ nm_setting_connection_get_gateway_ping_timeout (NMSettingConnection *setting)
|
|||
}
|
||||
|
||||
|
||||
static gint
|
||||
find_setting_by_name (gconstpointer a, gconstpointer b)
|
||||
{
|
||||
NMSetting *setting = NM_SETTING (a);
|
||||
const char *str = (const char *) b;
|
||||
|
||||
return strcmp (nm_setting_get_name (setting), str);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
verify (NMSetting *setting, GSList *all_settings, GError **error)
|
||||
{
|
||||
|
@ -781,7 +772,7 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
|
|||
}
|
||||
|
||||
/* Make sure the corresponding 'type' item is present */
|
||||
if (all_settings && !g_slist_find_custom (all_settings, priv->type, find_setting_by_name)) {
|
||||
if (all_settings && !nm_setting_find_in_list (all_settings, priv->type)) {
|
||||
g_set_error (error,
|
||||
NM_SETTING_CONNECTION_ERROR,
|
||||
NM_SETTING_CONNECTION_ERROR_TYPE_SETTING_NOT_FOUND,
|
||||
|
@ -796,14 +787,11 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
|
|||
*/
|
||||
if (priv->slave_type && all_settings &&
|
||||
!strcmp(priv->slave_type, NM_SETTING_BOND_SETTING_NAME)) {
|
||||
GSList *list;
|
||||
|
||||
list = g_slist_find_custom (all_settings, NM_SETTING_IP4_CONFIG_SETTING_NAME,
|
||||
find_setting_by_name);
|
||||
if (list) {
|
||||
NMSettingIP4Config *s_ip4 = g_slist_nth_data (list, 0);
|
||||
g_assert (s_ip4);
|
||||
NMSettingIP4Config *s_ip4;
|
||||
NMSettingIP6Config *s_ip6;
|
||||
|
||||
s_ip4 = NM_SETTING_IP4_CONFIG (nm_setting_find_in_list (all_settings, NM_SETTING_IP4_CONFIG_SETTING_NAME));
|
||||
if (s_ip4) {
|
||||
if (strcmp (nm_setting_ip4_config_get_method (s_ip4),
|
||||
NM_SETTING_IP4_CONFIG_METHOD_DISABLED)) {
|
||||
g_set_error_literal (error,
|
||||
|
@ -815,12 +803,8 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
|
|||
}
|
||||
}
|
||||
|
||||
list = g_slist_find_custom (all_settings, NM_SETTING_IP6_CONFIG_SETTING_NAME,
|
||||
find_setting_by_name);
|
||||
if (list) {
|
||||
NMSettingIP6Config *s_ip6 = g_slist_nth_data (list, 0);
|
||||
g_assert (s_ip6);
|
||||
|
||||
s_ip6 = NM_SETTING_IP6_CONFIG (nm_setting_find_in_list (all_settings, NM_SETTING_IP6_CONFIG_SETTING_NAME));
|
||||
if (s_ip6) {
|
||||
if (strcmp (nm_setting_ip6_config_get_method (s_ip6),
|
||||
NM_SETTING_IP6_CONFIG_METHOD_IGNORE)) {
|
||||
g_set_error_literal (error,
|
||||
|
|
|
@ -51,5 +51,7 @@ gint _nm_setting_compare_priority (gconstpointer a, gconstpointer b);
|
|||
static void __attribute__((constructor)) register_setting (void) \
|
||||
{ g_type_init (); g_type_ensure (x); }
|
||||
|
||||
NMSetting *nm_setting_find_in_list (GSList *settings_list, const char *setting_name);
|
||||
|
||||
#endif /* NM_SETTING_PRIVATE_H */
|
||||
|
||||
|
|
|
@ -777,15 +777,6 @@ no_secrets:
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static gint
|
||||
find_setting_by_name (gconstpointer a, gconstpointer b)
|
||||
{
|
||||
NMSetting *setting = NM_SETTING (a);
|
||||
const char *str = (const char *) b;
|
||||
|
||||
return strcmp (nm_setting_get_name (setting), str);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
verify (NMSetting *setting, GSList *all_settings, GError **error)
|
||||
{
|
||||
|
@ -847,7 +838,7 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
|
|||
if ( (strcmp (priv->key_mgmt, "ieee8021x") == 0)
|
||||
|| (strcmp (priv->key_mgmt, "wpa-eap") == 0)) {
|
||||
/* Need an 802.1x setting too */
|
||||
if (!g_slist_find_custom (all_settings, NM_SETTING_802_1X_SETTING_NAME, find_setting_by_name)) {
|
||||
if (!nm_setting_find_in_list (all_settings, NM_SETTING_802_1X_SETTING_NAME)) {
|
||||
g_set_error (error,
|
||||
NM_SETTING_WIRELESS_SECURITY_ERROR,
|
||||
NM_SETTING_WIRELESS_SECURITY_ERROR_MISSING_802_1X_SETTING,
|
||||
|
|
|
@ -415,6 +415,28 @@ nm_setting_duplicate (NMSetting *setting)
|
|||
return NM_SETTING (dup);
|
||||
}
|
||||
|
||||
static gint
|
||||
find_setting_by_name (gconstpointer a, gconstpointer b)
|
||||
{
|
||||
NMSetting *setting = NM_SETTING (a);
|
||||
const char *str = (const char *) b;
|
||||
|
||||
return strcmp (nm_setting_get_name (setting), str);
|
||||
}
|
||||
|
||||
NMSetting *
|
||||
nm_setting_find_in_list (GSList *settings_list,
|
||||
const char *setting_name)
|
||||
{
|
||||
GSList *found;
|
||||
|
||||
found = g_slist_find_custom (settings_list, setting_name, find_setting_by_name);
|
||||
if (found)
|
||||
return found->data;
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_setting_get_name:
|
||||
* @setting: the #NMSetting
|
||||
|
|
Loading…
Reference in a new issue