libnm-glib-aux: add nm_utils_is_not_empty_hostname

Checks whether the hostname is not empty or "(none)".
This commit is contained in:
Jan Vaclav
2025-02-24 11:47:01 +01:00
parent 6292b0c9dc
commit 21c46d6e5f
2 changed files with 16 additions and 3 deletions

View File

@@ -6004,8 +6004,8 @@ nm_utils_is_localhost(const char *name)
return FALSE;
}
gboolean
nm_utils_is_specific_hostname(const char *name)
static gboolean
_nm_utils_check_hostname(const char *name, bool allow_localhost)
{
if (nm_str_is_empty(name))
return FALSE;
@@ -6016,7 +6016,7 @@ nm_utils_is_specific_hostname(const char *name)
return FALSE;
}
if (nm_utils_is_localhost(name))
if (!allow_localhost && nm_utils_is_localhost(name))
return FALSE;
/* FIXME: properly validate the hostname, like systemd's hostname_is_valid() */
@@ -6024,6 +6024,18 @@ nm_utils_is_specific_hostname(const char *name)
return TRUE;
}
gboolean
nm_utils_is_specific_hostname(const char *name)
{
return _nm_utils_check_hostname(name, FALSE);
}
gboolean
nm_utils_is_not_empty_hostname(const char *name)
{
return _nm_utils_check_hostname(name, TRUE);
}
/*****************************************************************************/
typedef struct {

View File

@@ -3419,6 +3419,7 @@ char *_nm_utils_format_variant_attributes(GHashTable *a
gboolean nm_utils_is_localhost(const char *name);
gboolean nm_utils_is_specific_hostname(const char *name);
gboolean nm_utils_is_not_empty_hostname(const char *name);
struct passwd;