summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Winship <danw@gnome.org>2013-10-07 13:57:52 -0400
committerDan Winship <danw@gnome.org>2013-10-24 12:25:08 -0400
commitf4c3e2f6438995ea6881aed5e957635256de862e (patch)
tree8801dd26aaa08fce74400947a694eb9fd9ab57fa
parent83c5a69126fe2363bab5c06881d34562b1674bcf (diff)
downloadNetworkManager-f4c3e2f6438995ea6881aed5e957635256de862e.tar.gz
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.
-rw-r--r--libnm-util/nm-setting-bluetooth.c17
-rw-r--r--libnm-util/nm-setting-bond.c11
-rw-r--r--libnm-util/nm-setting-connection.c30
-rw-r--r--libnm-util/nm-setting-private.h2
-rw-r--r--libnm-util/nm-setting-wireless-security.c11
-rw-r--r--libnm-util/nm-setting.c22
6 files changed, 35 insertions, 58 deletions
diff --git a/libnm-util/nm-setting-bluetooth.c b/libnm-util/nm-setting-bluetooth.c
index 99c316c300..f63a3769a2 100644
--- a/libnm-util/nm-setting-bluetooth.c
+++ b/libnm-util/nm-setting-bluetooth.c
@@ -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,
diff --git a/libnm-util/nm-setting-bond.c b/libnm-util/nm-setting-bond.c
index 000e0ee215..8d5b9c0d7a 100644
--- a/libnm-util/nm-setting-bond.c
+++ b/libnm-util/nm-setting-bond.c
@@ -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,
diff --git a/libnm-util/nm-setting-connection.c b/libnm-util/nm-setting-connection.c
index 266dbefc70..7507d4eda1 100644
--- a/libnm-util/nm-setting-connection.c
+++ b/libnm-util/nm-setting-connection.c
@@ -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,
diff --git a/libnm-util/nm-setting-private.h b/libnm-util/nm-setting-private.h
index 69e4be3046..485a667d37 100644
--- a/libnm-util/nm-setting-private.h
+++ b/libnm-util/nm-setting-private.h
@@ -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 */
diff --git a/libnm-util/nm-setting-wireless-security.c b/libnm-util/nm-setting-wireless-security.c
index 4c8cb1b2d5..2c6984b464 100644
--- a/libnm-util/nm-setting-wireless-security.c
+++ b/libnm-util/nm-setting-wireless-security.c
@@ -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,
diff --git a/libnm-util/nm-setting.c b/libnm-util/nm-setting.c
index a36da29428..6568c87684 100644
--- a/libnm-util/nm-setting.c
+++ b/libnm-util/nm-setting.c
@@ -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