diff options
Diffstat (limited to 'src/settings/plugins/ifcfg-rh/shvar.c')
| -rw-r--r-- | src/settings/plugins/ifcfg-rh/shvar.c | 125 |
1 files changed, 55 insertions, 70 deletions
diff --git a/src/settings/plugins/ifcfg-rh/shvar.c b/src/settings/plugins/ifcfg-rh/shvar.c index fe82fbdd..9120b870 100644 --- a/src/settings/plugins/ifcfg-rh/shvar.c +++ b/src/settings/plugins/ifcfg-rh/shvar.c @@ -39,7 +39,6 @@ #include "nm-core-internal.h" #include "nm-core-utils.h" #include "nm-utils/nm-enum-utils.h" -#include "nm-utils/nm-io-utils.h" #include "c-list/src/c-list.h" /*****************************************************************************/ @@ -91,8 +90,8 @@ struct _shvarFile { * * Returns: the parsed boolean value or @fallback. */ -int -svParseBoolean (const char *value, int fallback) +gint +svParseBoolean (const char *value, gint fallback) { if (!value) return fallback; @@ -149,8 +148,8 @@ static char * _escape_ansic (const char *source) { const char *p; - char *dest; - char *q; + gchar *dest; + gchar *q; nm_assert (source); @@ -822,7 +821,6 @@ svOpenFileInternal (const char *name, gboolean create, GError **error) if (nm_utils_fd_get_contents (closefd ? nm_steal_fd (&fd) : fd, closefd, 10 * 1024 * 1024, - NM_UTILS_FILE_GET_CONTENTS_FLAG_NONE, &arena, NULL, &local) < 0) { @@ -872,61 +870,8 @@ svCreateFile (const char *name) /*****************************************************************************/ -static gboolean -_is_all_digits (const char *str) -{ - return str[0] - && NM_STRCHAR_ALL (str, ch, g_ascii_isdigit (ch)); -} - -#define IS_NUMBERED_TAG(key, tab_name) \ - ({ \ - const char *_key = (key); \ - \ - ( (strncmp (_key, tab_name, NM_STRLEN (tab_name)) == 0) \ - && _is_all_digits (&_key[NM_STRLEN (tab_name)])); \ - }) - -static gboolean -_svKeyMatchesType (const char *key, SvKeyType match_key_type) -{ - if (NM_FLAGS_HAS (match_key_type, SV_KEY_TYPE_ANY)) - return TRUE; - - if (NM_FLAGS_HAS (match_key_type, SV_KEY_TYPE_ROUTE_SVFORMAT)) { - if ( IS_NUMBERED_TAG (key, "ADDRESS") - || IS_NUMBERED_TAG (key, "NETMASK") - || IS_NUMBERED_TAG (key, "GATEWAY") - || IS_NUMBERED_TAG (key, "METRIC") - || IS_NUMBERED_TAG (key, "OPTIONS")) - return TRUE; - } - if (NM_FLAGS_HAS (match_key_type, SV_KEY_TYPE_IP4_ADDRESS)) { - if ( IS_NUMBERED_TAG (key, "IPADDR") - || IS_NUMBERED_TAG (key, "PREFIX") - || IS_NUMBERED_TAG (key, "NETMASK") - || IS_NUMBERED_TAG (key, "GATEWAY")) - return TRUE; - } - if (NM_FLAGS_HAS (match_key_type, SV_KEY_TYPE_USER)) { - if (g_str_has_prefix (key, "NM_USER_")) - return TRUE; - } - if (NM_FLAGS_HAS (match_key_type, SV_KEY_TYPE_TC)) { - if ( IS_NUMBERED_TAG (key, "QDISC") - || IS_NUMBERED_TAG (key, "FILTER")) - return TRUE; - } - if (NM_FLAGS_HAS (match_key_type, SV_KEY_TYPE_SRIOV_VF)) { - if (IS_NUMBERED_TAG (key, "SRIOV_VF")) - return TRUE; - } - - return FALSE; -} - GHashTable * -svGetKeys (shvarFile *s, SvKeyType match_key_type) +svGetKeys (shvarFile *s) { GHashTable *keys = NULL; CList *current; @@ -936,9 +881,7 @@ svGetKeys (shvarFile *s, SvKeyType match_key_type) c_list_for_each (current, &s->lst_head) { line = c_list_entry (current, shvarLine, lst); - if ( line->key - && line->line - && _svKeyMatchesType (line->key, match_key_type)) { + if (line->key && line->line) { /* we don't clone the keys. The keys are only valid * until @s gets modified. */ if (!keys) @@ -1101,8 +1044,8 @@ svGetValueStr_cp (shvarFile *s, const char *key) * * Returns: the parsed boolean value or @fallback. */ -int -svGetValueBoolean (shvarFile *s, const char *key, int fallback) +gint +svGetValueBoolean (shvarFile *s, const char *key, gint fallback) { gs_free char *to_free = NULL; const char *value; @@ -1177,6 +1120,21 @@ svGetValueEnum (shvarFile *s, const char *key, /*****************************************************************************/ +static gboolean +_is_all_digits (const char *str) +{ + return str[0] + && NM_STRCHAR_ALL (str, ch, g_ascii_isdigit (ch)); +} + +#define IS_NUMBERED_TAG(key, tab_name) \ + ({ \ + const char *_key = (key); \ + \ + ( (strncmp (_key, tab_name, NM_STRLEN (tab_name)) == 0) \ + && _is_all_digits (&_key[NM_STRLEN (tab_name)])); \ + }) + gboolean svUnsetAll (shvarFile *s, SvKeyType match_key_type) { @@ -1192,11 +1150,38 @@ svUnsetAll (shvarFile *s, SvKeyType match_key_type) if (!line->key) continue; - if (_svKeyMatchesType (line->key, match_key_type)) { - if (nm_clear_g_free (&line->line)) { - ASSERT_shvarLine (line); - changed = TRUE; - } + if (NM_FLAGS_HAS (match_key_type, SV_KEY_TYPE_ANY)) + goto do_clear; + if (NM_FLAGS_HAS (match_key_type, SV_KEY_TYPE_ROUTE_SVFORMAT)) { + if ( IS_NUMBERED_TAG (line->key, "ADDRESS") + || IS_NUMBERED_TAG (line->key, "NETMASK") + || IS_NUMBERED_TAG (line->key, "GATEWAY") + || IS_NUMBERED_TAG (line->key, "METRIC") + || IS_NUMBERED_TAG (line->key, "OPTIONS")) + goto do_clear; + } + if (NM_FLAGS_HAS (match_key_type, SV_KEY_TYPE_IP4_ADDRESS)) { + if ( IS_NUMBERED_TAG (line->key, "IPADDR") + || IS_NUMBERED_TAG (line->key, "PREFIX") + || IS_NUMBERED_TAG (line->key, "NETMASK") + || IS_NUMBERED_TAG (line->key, "GATEWAY")) + goto do_clear; + } + if (NM_FLAGS_HAS (match_key_type, SV_KEY_TYPE_USER)) { + if (g_str_has_prefix (line->key, "NM_USER_")) + goto do_clear; + } + if (NM_FLAGS_HAS (match_key_type, SV_KEY_TYPE_TC)) { + if ( IS_NUMBERED_TAG (line->key, "QDISC") + || IS_NUMBERED_TAG (line->key, "FILTER")) + goto do_clear; + } + + continue; +do_clear: + if (nm_clear_g_free (&line->line)) { + ASSERT_shvarLine (line); + changed = TRUE; } } |