diff --git a/libnm-core/nm-utils-private.h b/libnm-core/nm-utils-private.h index 03c8790764..aaf80363f5 100644 --- a/libnm-core/nm-utils-private.h +++ b/libnm-core/nm-utils-private.h @@ -78,4 +78,85 @@ void _nm_utils_bytes_from_dbus (GVariant *dbus_value, char * _nm_utils_hwaddr_canonical_or_invalid (const char *mac, gssize length); + +/* JSON to GValue conversion macros */ + +typedef struct { + const char *key1; + const char *key2; + const char *key3; +} _NMUtilsTeamPropertyKeys; + +static inline int +_nm_utils_json_extract_int (char *conf, + _NMUtilsTeamPropertyKeys key) +{ + gs_free GValue *t_value = NULL; + int ret; + + t_value = _nm_utils_team_config_get (conf, key.key1, key.key2, key.key3, FALSE); + if (!t_value) + return 0; + + ret = g_value_get_int (t_value); + g_value_unset (t_value); + return ret; +} + +static inline gboolean +_nm_utils_json_extract_boolean (char *conf, + _NMUtilsTeamPropertyKeys key) +{ + gs_free GValue *t_value = NULL; + gboolean ret; + + t_value = _nm_utils_team_config_get (conf, key.key1, key.key2, key.key3, FALSE); + if (!t_value) + return FALSE; + + ret = g_value_get_boolean (t_value); + g_value_unset (t_value); + return ret; +} + +static inline char * +_nm_utils_json_extract_string (char *conf, + _NMUtilsTeamPropertyKeys key) +{ + gs_free GValue *t_value = NULL; + char *ret; + + t_value = _nm_utils_team_config_get (conf, key.key1, key.key2, key.key3, FALSE); + if (!t_value) + return NULL; + + ret = g_value_dup_string (t_value); + g_value_unset (t_value); + return ret; +} + +static inline char ** +_nm_utils_json_extract_strv (char *conf, + _NMUtilsTeamPropertyKeys key) +{ + gs_free GValue *t_value = NULL; + char **ret; + + t_value = _nm_utils_team_config_get (conf, key.key1, key.key2, key.key3, FALSE); + if (!t_value) + return NULL; + + ret = g_strdupv (g_value_get_boxed (t_value)); + g_value_unset (t_value); + return ret; +} + +static inline void +_nm_utils_json_append_gvalue (char **conf, + _NMUtilsTeamPropertyKeys key, + const GValue *val) +{ + _nm_utils_team_config_set (conf, key.key1, key.key2, key.key3, val); +} + #endif