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 b537c0388a)
This commit is contained in:
Thomas Haller 2018-09-27 16:05:29 +02:00
parent f4973558dc
commit 2a8bef4454
4 changed files with 12 additions and 28 deletions

View file

@ -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,

View file

@ -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

View file

@ -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"));

View file

@ -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);
}
/**