diff options
author | Thomas Haller <thaller@redhat.com> | 2013-10-09 10:41:39 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2013-10-25 22:32:47 +0200 |
commit | df4e1597282100a6716f15d1c94caba4d162e7b1 (patch) | |
tree | 1ad908e26194475542eb07fa4c168760976aef8f | |
parent | 3f3f2a82d086cb5d89eedd011ede581639a080dd (diff) | |
download | NetworkManager-df4e1597282100a6716f15d1c94caba4d162e7b1.tar.gz |
libnm-util: expose nm_setting_bond_validate_option as public API
Co-Authored-By: Jiří Klimeš <jklimes@redhat.com>
Signed-off-by: Thomas Haller <thaller@redhat.com>
-rw-r--r-- | libnm-util/libnm-util.ver | 1 | ||||
-rw-r--r-- | libnm-util/nm-setting-bond.c | 46 | ||||
-rw-r--r-- | libnm-util/nm-setting-bond.h | 5 |
3 files changed, 35 insertions, 17 deletions
diff --git a/libnm-util/libnm-util.ver b/libnm-util/libnm-util.ver index d3e430cc34..dd8fcfa3c9 100644 --- a/libnm-util/libnm-util.ver +++ b/libnm-util/libnm-util.ver @@ -207,6 +207,7 @@ global: nm_setting_bond_get_valid_options; nm_setting_bond_new; nm_setting_bond_remove_option; + nm_setting_bond_validate_option; nm_setting_bridge_error_get_type; nm_setting_bridge_error_quark; nm_setting_bridge_get_ageing_time; diff --git a/libnm-util/nm-setting-bond.c b/libnm-util/nm-setting-bond.c index 12f7941d0b..66eab2cbda 100644 --- a/libnm-util/nm-setting-bond.c +++ b/libnm-util/nm-setting-bond.c @@ -271,29 +271,43 @@ validate_ip (const char *name, const char *value) return success; } -/* If value is NULL, validates name only */ -static gboolean -validate_option (const char *name, const char *value) +/** + * nm_setting_bond_validate_option: + * @name: the name of the option to validate + * @value: the value of the option to validate + * + * Checks whether @name is a valid bond option and @value is a valid value for + * the @name. If @value is NULL, the function only validates the option name. + * + * Returns: TRUE, if the @value is valid for the given name. + * If the @name is not a valid option, FALSE will be returned. + * + * Since: 0.9.10 + **/ +gboolean +nm_setting_bond_validate_option (const char *name, + const char *value) { guint i; - g_return_val_if_fail (name != NULL, FALSE); - g_return_val_if_fail (name[0] != '\0', FALSE); + if (!name || !name[0]) + return FALSE; for (i = 0; i < G_N_ELEMENTS (defaults); i++) { if (g_strcmp0 (defaults[i].opt, name) == 0) { if (value == NULL) return TRUE; - else if (defaults[i].opt_type == TYPE_INT) + switch (defaults[i].opt_type) { + case TYPE_INT: return validate_int (name, value, &defaults[i]); - else if (defaults[i].opt_type == TYPE_STR) + case TYPE_STR: return validate_list (name, value, &defaults[i]); - else if (defaults[i].opt_type == TYPE_BOTH) + case TYPE_BOTH: return validate_int (name, value, &defaults[i]) || validate_list (name, value, &defaults[i]); - else if (defaults[i].opt_type == TYPE_IP) + case TYPE_IP: return validate_ip (name, value); - + } return FALSE; } } @@ -316,7 +330,7 @@ nm_setting_bond_get_option_by_name (NMSettingBond *setting, const char *name) { g_return_val_if_fail (NM_IS_SETTING_BOND (setting), NULL); - g_return_val_if_fail (validate_option (name, NULL), NULL); + g_return_val_if_fail (nm_setting_bond_validate_option (name, NULL), NULL); return g_hash_table_lookup (NM_SETTING_BOND_GET_PRIVATE (setting)->options, name); } @@ -342,7 +356,7 @@ gboolean nm_setting_bond_add_option (NMSettingBond *setting, NMSettingBondPrivate *priv; g_return_val_if_fail (NM_IS_SETTING_BOND (setting), FALSE); - g_return_val_if_fail (validate_option (name, value), FALSE); + g_return_val_if_fail (nm_setting_bond_validate_option (name, value), FALSE); g_return_val_if_fail (value != NULL, FALSE); priv = NM_SETTING_BOND_GET_PRIVATE (setting); @@ -383,7 +397,7 @@ nm_setting_bond_remove_option (NMSettingBond *setting, gboolean found; g_return_val_if_fail (NM_IS_SETTING_BOND (setting), FALSE); - g_return_val_if_fail (validate_option (name, NULL), FALSE); + g_return_val_if_fail (nm_setting_bond_validate_option (name, NULL), FALSE); found = g_hash_table_remove (NM_SETTING_BOND_GET_PRIVATE (setting)->options, name); if (found) @@ -428,13 +442,13 @@ nm_setting_bond_get_option_default (NMSettingBond *setting, const char *name) guint i; g_return_val_if_fail (NM_IS_SETTING_BOND (setting), NULL); - g_return_val_if_fail (validate_option (name, NULL), NULL); + g_return_val_if_fail (nm_setting_bond_validate_option (name, NULL), NULL); for (i = 0; i < G_N_ELEMENTS (defaults); i++) { if (g_strcmp0 (defaults[i].opt, name) == 0) return defaults[i].val; } - /* Any option that passes validate_option() should also be found in defaults */ + /* Any option that passes nm_setting_bond_validate_option() should also be found in defaults */ g_assert_not_reached (); } @@ -476,7 +490,7 @@ verify (NMSetting *setting, GSList *all_settings, GError **error) g_hash_table_iter_init (&iter, priv->options); while (g_hash_table_iter_next (&iter, (gpointer) &key, (gpointer) &value)) { - if (!value[0] || !validate_option (key, value)) { + if (!value[0] || !nm_setting_bond_validate_option (key, value)) { g_set_error (error, NM_SETTING_BOND_ERROR, NM_SETTING_BOND_ERROR_INVALID_OPTION, diff --git a/libnm-util/nm-setting-bond.h b/libnm-util/nm-setting-bond.h index 06fcf28eae..383e0eadb3 100644 --- a/libnm-util/nm-setting-bond.h +++ b/libnm-util/nm-setting-bond.h @@ -18,7 +18,7 @@ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301 USA. * - * (C) Copyright 2011 - 2012 Red Hat, Inc. + * (C) Copyright 2011 - 2013 Red Hat, Inc. */ #ifndef NM_SETTING_BOND_H @@ -105,6 +105,9 @@ gboolean nm_setting_bond_add_option (NMSettingBond *setting, gboolean nm_setting_bond_remove_option (NMSettingBond *setting, const char *name); +gboolean nm_setting_bond_validate_option (const char *name, + const char *value); + const char **nm_setting_bond_get_valid_options (NMSettingBond *setting); const char * nm_setting_bond_get_option_default (NMSettingBond *setting, |