Skip to content

Commit

Permalink
client: add ni_ifconfig_kind name mapping utils
Browse files Browse the repository at this point in the history
  • Loading branch information
mtomaschewski committed Jan 24, 2023
1 parent fd332f7 commit f0a3730
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
24 changes: 24 additions & 0 deletions client/read-config.c
Expand Up @@ -204,6 +204,30 @@ ni_ifconfig_kind_guess(ni_ifconfig_kind_t kind)
}
}

static const ni_intmap_t ni_ifconfig_kind_map[] = {
{ "policy", NI_IFCONFIG_KIND_POLICY },
{ "config", NI_IFCONFIG_KIND_CONFIG },
{ NULL, NI_IFCONFIG_KIND_DEFAULT }
};

const char *
ni_ifconfig_kind_to_name(ni_ifconfig_kind_t kind)
{
return ni_format_uint_mapped(kind, ni_ifconfig_kind_map);
}

ni_bool_t
ni_ifconfig_kind_by_name(const char *name, ni_ifconfig_kind_t *kind)
{
unsigned int type;

if (!kind || ni_parse_uint_mapped(name, ni_ifconfig_kind_map, &type) < 0)
return FALSE;

*kind = type;
return TRUE;
}

const ni_ifconfig_type_t *
ni_ifconfig_guess_wicked_type(const ni_ifconfig_type_t *map,
const char *root, const char *path)
Expand Down
3 changes: 3 additions & 0 deletions client/read-config.h
Expand Up @@ -63,4 +63,7 @@ extern ni_bool_t ni_ifconfig_read_subtype(xml_document_array_t *,
extern ni_bool_t ni_ifconfig_read(xml_document_array_t *, const char *,
const char *, ni_ifconfig_kind_t, ni_bool_t, ni_bool_t);

extern const char * ni_ifconfig_kind_to_name(ni_ifconfig_kind_t);
extern ni_bool_t ni_ifconfig_kind_by_name(const char *, ni_ifconfig_kind_t *);

#endif /* WICKED_CLIENT_READ_CONFIG_H */

0 comments on commit f0a3730

Please sign in to comment.