systemd: add nm_sd_dns_name_normalize() accessor

This commit is contained in:
Thomas Haller 2021-02-10 10:09:56 +01:00
parent e12e4ef849
commit 1e15ea9dd5
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728
2 changed files with 20 additions and 0 deletions

View file

@ -93,6 +93,24 @@ nm_sd_hostname_is_valid(const char *s, bool allow_trailing_dot)
: (ValidHostnameFlags) 0);
}
char *
nm_sd_dns_name_normalize(const char *s)
{
nm_auto_free char *n = NULL;
int r;
r = dns_name_normalize(s, 0, &n);
if (r < 0)
return NULL;
nm_assert(n);
/* usually we try not to mix malloc/g_malloc and free/g_free. In practice,
* they are the same. So here we return a buffer allocated with malloc(),
* and the caller should free it with g_free(). */
return g_steal_pointer(&n);
}
/*****************************************************************************/
static gboolean

View file

@ -28,6 +28,8 @@ nm_sd_dns_name_to_wire_format(const char *domain, guint8 *buffer, size_t len, gb
int nm_sd_dns_name_is_valid(const char *s);
gboolean nm_sd_hostname_is_valid(const char *s, bool allow_trailing_dot);
char *nm_sd_dns_name_normalize(const char *s);
/*****************************************************************************/
gboolean nm_sd_http_url_is_valid_https(const char *url);