diff options
Diffstat (limited to 'libnm-core/nm-utils-private.h')
| -rw-r--r-- | libnm-core/nm-utils-private.h | 80 |
1 files changed, 46 insertions, 34 deletions
diff --git a/libnm-core/nm-utils-private.h b/libnm-core/nm-utils-private.h index 46af26ed..a1a1369a 100644 --- a/libnm-core/nm-utils-private.h +++ b/libnm-core/nm-utils-private.h @@ -103,8 +103,31 @@ 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 (NMSetting *setting, const char *property); +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, + const char *setting, + const char *property); + /* JSON to GValue conversion macros */ +static inline void +_nm_auto_unset_and_free_gvalue (GValue **ptr) +{ + if (*ptr) { + g_value_unset (*ptr); + g_free (*ptr); + } +} +#define nm_auto_unset_and_free_gvalue nm_auto(_nm_auto_unset_and_free_gvalue) + typedef struct { const char *key1; const char *key2; @@ -121,16 +144,13 @@ _nm_utils_json_extract_int (char *conf, _NMUtilsTeamPropertyKeys key, gboolean is_port) { - gs_free GValue *t_value = NULL; - int ret; + nm_auto_unset_and_free_gvalue GValue *t_value = NULL; t_value = _nm_utils_team_config_get (conf, key.key1, key.key2, key.key3, is_port); - if (!t_value) + if ( !t_value + || !G_VALUE_HOLDS_INT (t_value)) return key.default_int; - - ret = g_value_get_int (t_value); - g_value_unset (t_value); - return ret; + return g_value_get_int (t_value); } static inline gboolean @@ -138,16 +158,13 @@ _nm_utils_json_extract_boolean (char *conf, _NMUtilsTeamPropertyKeys key, gboolean is_port) { - gs_free GValue *t_value = NULL; - gboolean ret; + nm_auto_unset_and_free_gvalue GValue *t_value = NULL; t_value = _nm_utils_team_config_get (conf, key.key1, key.key2, key.key3, is_port); - if (!t_value) + if ( !t_value + || !G_VALUE_HOLDS_BOOLEAN (t_value)) return key.default_bool; - - ret = g_value_get_boolean (t_value); - g_value_unset (t_value); - return ret; + return g_value_get_boolean (t_value); } static inline char * @@ -155,16 +172,13 @@ _nm_utils_json_extract_string (char *conf, _NMUtilsTeamPropertyKeys key, gboolean is_port) { - gs_free GValue *t_value = NULL; - char *ret; + nm_auto_unset_and_free_gvalue GValue *t_value = NULL; t_value = _nm_utils_team_config_get (conf, key.key1, key.key2, key.key3, is_port); - if (!t_value) + if ( !t_value + || !G_VALUE_HOLDS_STRING (t_value)) return g_strdup (key.default_str); - - ret = g_value_dup_string (t_value); - g_value_unset (t_value); - return ret; + return g_value_dup_string (t_value); } static inline char ** @@ -172,39 +186,37 @@ _nm_utils_json_extract_strv (char *conf, _NMUtilsTeamPropertyKeys key, gboolean is_port) { - gs_free GValue *t_value = NULL; - char **ret; + nm_auto_unset_and_free_gvalue GValue *t_value = NULL; t_value = _nm_utils_team_config_get (conf, key.key1, key.key2, key.key3, is_port); - if (!t_value) + if ( !t_value + || !G_TYPE_CHECK_VALUE_TYPE (t_value, G_TYPE_STRV)) return NULL; - - ret = g_strdupv (g_value_get_boxed (t_value)); - g_value_unset (t_value); - return ret; + return g_strdupv (g_value_get_boxed (t_value)) + ?: g_new0 (char *, 1); } static inline GPtrArray * _nm_utils_json_extract_ptr_array (char *conf, - _NMUtilsTeamPropertyKeys key, - gboolean is_port) + _NMUtilsTeamPropertyKeys key, + gboolean is_port) { - gs_free GValue *t_value = NULL; + nm_auto_unset_and_free_gvalue GValue *t_value = NULL; GPtrArray *data, *ret; guint i; ret = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_team_link_watcher_unref); + t_value = _nm_utils_team_config_get (conf, key.key1, key.key2, key.key3, is_port); - if (!t_value) + if ( !t_value + || !G_TYPE_CHECK_VALUE_TYPE (t_value, G_TYPE_PTR_ARRAY)) return ret; data = g_value_get_boxed (t_value); if (!data) return ret; - for (i = 0; i < data->len; i++) g_ptr_array_add (ret, nm_team_link_watcher_dup (data->pdata[i])); - g_value_unset (t_value); return ret; } |