From 2a8bef4454d6b1e8aeded8bbd2122538a5da41a4 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 27 Sep 2018 16:05:29 +0200 Subject: [PATCH] all: drop _nm_utils_bin2hexstr() We already have nm_utils_bin2hexstr() and _nm_utils_bin2hexstr_full(). This is confusing. - nm_utils_bin2hexstr() is public API of libnm. Also, it has a last argument @final_len to truncate the string at that length. It uses no delimiter and lower-case characters. - _nm_utils_bin2hexstr_full() does not do any truncation, but it has options to specify a delimiter, the character case, and to update a given buffer in-place. Also, like nm_utils_bin2hexstr() and _nm_utils_bin2hexstr() it can allocate a new buffer on demand. - _nm_utils_bin2hexstr() would use ':' as delimiter and make the case configurable. Also, it would always allocate the returned buffer. It's too much and confusing. Drop _nm_utils_bin2hexstr() which is internal API and just a wrapper around _nm_utils_bin2hexstr_full(). (cherry picked from commit b537c0388a0ca7320d01c9ba2c6b5b4fe45f267f) --- libnm-core/nm-core-internal.h | 1 - libnm-core/nm-utils.c | 19 ------------------- src/devices/nm-device.c | 16 ++++++++++------ src/dhcp/nm-dhcp-utils.c | 4 ++-- 4 files changed, 12 insertions(+), 28 deletions(-) diff --git a/libnm-core/nm-core-internal.h b/libnm-core/nm-core-internal.h index f4108f8193..7b80a3d948 100644 --- a/libnm-core/nm-core-internal.h +++ b/libnm-core/nm-core-internal.h @@ -219,7 +219,6 @@ guint nm_setting_ethtool_init_features (NMSettingEthtool *setting, guint8 *_nm_utils_hwaddr_aton (const char *asc, gpointer buffer, gsize buffer_length, gsize *out_length); const char *nm_utils_hwaddr_ntoa_buf (gconstpointer addr, gsize addr_len, gboolean upper_case, char *buf, gsize buf_len); -char *_nm_utils_bin2hexstr (gconstpointer addr, gsize length, gboolean upper_case); char *_nm_utils_bin2hexstr_full (gconstpointer addr, gsize length, const char delimiter, gboolean upper_case, char *out); guint8 *_nm_utils_hexstr2bin_full (const char *asc, diff --git a/libnm-core/nm-utils.c b/libnm-core/nm-utils.c index 70bbcd9b41..0251e19408 100644 --- a/libnm-core/nm-utils.c +++ b/libnm-core/nm-utils.c @@ -3936,25 +3936,6 @@ nm_utils_hwaddr_ntoa_buf (gconstpointer addr, gsize addr_len, gboolean upper_cas return _nm_utils_bin2hexstr_full (addr, addr_len, ':', upper_case, buf); } -/** - * _nm_utils_bin2hexstr: - * @addr: (type guint8) (array length=length): a binary hardware address - * @length: the length of @addr - * @upper_case: the case for the hexadecimal digits. - * - * Converts @addr to textual form. - * - * Return value: (transfer full): the textual form of @addr - */ -char * -_nm_utils_bin2hexstr (gconstpointer addr, gsize length, gboolean upper_case) -{ - g_return_val_if_fail (addr, g_strdup ("")); - g_return_val_if_fail (length > 0, g_strdup ("")); - - return _nm_utils_bin2hexstr_full (addr, length, ':', upper_case, NULL); -} - /** * nm_utils_hwaddr_valid: * @asc: the ASCII representation of a hardware address diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 4905b5a8c3..b4c0edac39 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -14384,9 +14384,11 @@ nm_device_spawn_iface_helper (NMDevice *self) if (client_id) { g_ptr_array_add (argv, g_strdup ("--dhcp4-clientid")); g_ptr_array_add (argv, - _nm_utils_bin2hexstr (g_bytes_get_data (client_id, NULL), - g_bytes_get_size (client_id), - FALSE)); + _nm_utils_bin2hexstr_full (g_bytes_get_data (client_id, NULL), + g_bytes_get_size (client_id), + ':', + FALSE, + NULL)); } hostname = nm_dhcp_client_get_hostname (priv->dhcp4.client); @@ -14424,9 +14426,11 @@ nm_device_spawn_iface_helper (NMDevice *self) if (nm_device_get_ip_iface_identifier (self, &iid, FALSE)) { g_ptr_array_add (argv, g_strdup ("--iid")); g_ptr_array_add (argv, - _nm_utils_bin2hexstr (iid.id_u8, - sizeof (NMUtilsIPv6IfaceId), - FALSE)); + _nm_utils_bin2hexstr_full (iid.id_u8, + sizeof (NMUtilsIPv6IfaceId), + ':', + FALSE, + NULL)); } g_ptr_array_add (argv, g_strdup ("--addr-gen-mode")); diff --git a/src/dhcp/nm-dhcp-utils.c b/src/dhcp/nm-dhcp-utils.c index f6d97b5ffc..9b1653b8f9 100644 --- a/src/dhcp/nm-dhcp-utils.c +++ b/src/dhcp/nm-dhcp-utils.c @@ -726,10 +726,10 @@ nm_dhcp_utils_duid_to_string (GBytes *duid) gconstpointer data; gsize len; - g_return_val_if_fail (duid != NULL, NULL); + g_return_val_if_fail (duid, NULL); data = g_bytes_get_data (duid, &len); - return _nm_utils_bin2hexstr (data, len, FALSE); + return _nm_utils_bin2hexstr_full (data, len, ':', FALSE, NULL); } /**