From 41634d51993d04c7fc7c56c624f1e781ac4faa2d Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 10 Feb 2021 15:14:59 +0100 Subject: [PATCH] dhcp: add nm_dhcp_option_add_option_utf8safe_escape() helper --- src/core/dhcp/nm-dhcp-options.c | 14 ++++++++++++++ src/core/dhcp/nm-dhcp-options.h | 5 +++++ 2 files changed, 19 insertions(+) diff --git a/src/core/dhcp/nm-dhcp-options.c b/src/core/dhcp/nm-dhcp-options.c index c10077a43..c3ef8478e 100644 --- a/src/core/dhcp/nm-dhcp-options.c +++ b/src/core/dhcp/nm-dhcp-options.c @@ -241,6 +241,20 @@ nm_dhcp_option_add_option(GHashTable * options, nm_dhcp_option_take_option(options, requests, option, g_strdup(value)); } +void +nm_dhcp_option_add_option_utf8safe_escape(GHashTable * options, + const NMDhcpOption *requests, + guint option, + const guint8 * data, + gsize n_data) +{ + gs_free char *to_free = NULL; + const char * escaped; + + escaped = nm_utils_buf_utf8safe_escape((char *) data, n_data, 0, &to_free); + nm_dhcp_option_add_option(options, requests, option, escaped ?: ""); +} + void nm_dhcp_option_add_option_u64(GHashTable * options, const NMDhcpOption *requests, diff --git a/src/core/dhcp/nm-dhcp-options.h b/src/core/dhcp/nm-dhcp-options.h index c2a403a4b..9e6e4d1cf 100644 --- a/src/core/dhcp/nm-dhcp-options.h +++ b/src/core/dhcp/nm-dhcp-options.h @@ -195,6 +195,11 @@ void nm_dhcp_option_add_option(GHashTable * options, const NMDhcpOption *requests, guint option, const char * value); +void nm_dhcp_option_add_option_utf8safe_escape(GHashTable * options, + const NMDhcpOption *requests, + guint option, + const guint8 * data, + gsize n_data); void nm_dhcp_option_add_option_u64(GHashTable * options, const NMDhcpOption *requests, guint option,