From cc93cf46adb8957ff21eb295c7680954ee1aabc2 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 27 Sep 2018 15:39:29 +0200 Subject: [PATCH] all/trivial: rename hexstr<>bin conversion functions "bin2str" and "str2bin" are not very clear. These strings are hex-strings. Rename. (cherry picked from commit 6714440669d27a59a6e0bcadd642c28f0c9d5737) --- libnm-core/nm-core-internal.h | 16 +++++----- libnm-core/nm-utils.c | 32 +++++++++---------- src/devices/nm-device.c | 12 +++---- src/dhcp/nm-dhcp-utils.c | 2 +- .../plugins/ifcfg-rh/nms-ifcfg-rh-reader.c | 2 +- 5 files changed, 32 insertions(+), 32 deletions(-) diff --git a/libnm-core/nm-core-internal.h b/libnm-core/nm-core-internal.h index e677f51cf8..ac87fa337a 100644 --- a/libnm-core/nm-core-internal.h +++ b/libnm-core/nm-core-internal.h @@ -219,15 +219,15 @@ 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_bin2str (gconstpointer addr, gsize length, gboolean upper_case); -void _nm_utils_bin2str_full (gconstpointer addr, gsize length, const char delimiter, gboolean upper_case, char *out); +char *_nm_utils_bin2hexstr (gconstpointer addr, gsize length, gboolean upper_case); +void _nm_utils_bin2hexstr_full (gconstpointer addr, gsize length, const char delimiter, gboolean upper_case, char *out); -guint8 *_nm_utils_str2bin_full (const char *asc, - gboolean delimiter_required, - const char *delimiter_candidates, - guint8 *buffer, - gsize buffer_length, - gsize *out_len); +guint8 *_nm_utils_hexstr2bin_full (const char *asc, + gboolean delimiter_required, + const char *delimiter_candidates, + guint8 *buffer, + gsize buffer_length, + gsize *out_len); GSList * _nm_utils_hash_values_to_slist (GHashTable *hash); diff --git a/libnm-core/nm-utils.c b/libnm-core/nm-utils.c index d595b53a75..25c702aaa3 100644 --- a/libnm-core/nm-utils.c +++ b/libnm-core/nm-utils.c @@ -3613,12 +3613,12 @@ nm_utils_hwaddr_len (int type) } guint8 * -_nm_utils_str2bin_full (const char *asc, - gboolean delimiter_required, - const char *delimiter_candidates, - guint8 *buffer, - gsize buffer_length, - gsize *out_len) +_nm_utils_hexstr2bin_full (const char *asc, + gboolean delimiter_required, + const char *delimiter_candidates, + guint8 *buffer, + gsize buffer_length, + gsize *out_len) { const char *in = asc; guint8 *out = buffer; @@ -3688,7 +3688,7 @@ _nm_utils_str2bin_full (const char *asc, return buffer; } -#define hwaddr_aton(asc, buffer, buffer_length, out_len) _nm_utils_str2bin_full ((asc), TRUE, ":-", (buffer), (buffer_length), (out_len)) +#define hwaddr_aton(asc, buffer, buffer_length, out_len) _nm_utils_hexstr2bin_full ((asc), TRUE, ":-", (buffer), (buffer_length), (out_len)) /** * nm_utils_hexstr2bin: @@ -3714,7 +3714,7 @@ nm_utils_hexstr2bin (const char *hex) buffer_length = strlen (hex) / 2 + 3; buffer = g_malloc (buffer_length); - if (!_nm_utils_str2bin_full (hex, FALSE, ":", buffer, buffer_length, &len)) { + if (!_nm_utils_hexstr2bin_full (hex, FALSE, ":", buffer, buffer_length, &len)) { g_free (buffer); return NULL; } @@ -3815,7 +3815,7 @@ nm_utils_hwaddr_aton (const char *asc, gpointer buffer, gsize length) } void -_nm_utils_bin2str_full (gconstpointer addr, gsize length, const char delimiter, gboolean upper_case, char *out) +_nm_utils_bin2hexstr_full (gconstpointer addr, gsize length, const char delimiter, gboolean upper_case, char *out) { const guint8 *in = addr; const char *LOOKUP = upper_case ? "0123456789ABCDEF" : "0123456789abcdef"; @@ -3865,7 +3865,7 @@ nm_utils_bin2hexstr (gconstpointer src, gsize len, int final_len) g_return_val_if_fail (final_len < 0 || (gsize) final_len < buflen, NULL); result = g_malloc (buflen); - _nm_utils_bin2str_full (src, len, '\0', FALSE, result); + _nm_utils_bin2hexstr_full (src, len, '\0', FALSE, result); /* Cut converted key off at the correct length for this cipher type */ if (final_len >= 0 && (gsize) final_len < buflen) @@ -3892,7 +3892,7 @@ nm_utils_hwaddr_ntoa (gconstpointer addr, gsize length) g_return_val_if_fail (length > 0, g_strdup ("")); result = g_malloc (length * 3); - _nm_utils_bin2str_full (addr, length, ':', TRUE, result); + _nm_utils_bin2hexstr_full (addr, length, ':', TRUE, result); return result; } @@ -3905,12 +3905,12 @@ nm_utils_hwaddr_ntoa_buf (gconstpointer addr, gsize addr_len, gboolean upper_cas if (buf_len < addr_len * 3) g_return_val_if_reached (NULL); - _nm_utils_bin2str_full (addr, addr_len, ':', upper_case, buf); + _nm_utils_bin2hexstr_full (addr, addr_len, ':', upper_case, buf); return buf; } /** - * _nm_utils_bin2str: + * _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. @@ -3920,7 +3920,7 @@ nm_utils_hwaddr_ntoa_buf (gconstpointer addr, gsize addr_len, gboolean upper_cas * Return value: (transfer full): the textual form of @addr */ char * -_nm_utils_bin2str (gconstpointer addr, gsize length, gboolean upper_case) +_nm_utils_bin2hexstr (gconstpointer addr, gsize length, gboolean upper_case) { char *result; @@ -3928,7 +3928,7 @@ _nm_utils_bin2str (gconstpointer addr, gsize length, gboolean upper_case) g_return_val_if_fail (length > 0, g_strdup ("")); result = g_malloc (length * 3); - _nm_utils_bin2str_full (addr, length, ':', upper_case, result); + _nm_utils_bin2hexstr_full (addr, length, ':', upper_case, result); return result; } @@ -4596,7 +4596,7 @@ _nm_utils_dhcp_duid_valid (const char *duid, GBytes **out_duid_bin) return TRUE; } - if (_nm_utils_str2bin_full (duid, FALSE, ":", duid_arr, sizeof (duid_arr), &duid_len)) { + if (_nm_utils_hexstr2bin_full (duid, FALSE, ":", duid_arr, sizeof (duid_arr), &duid_len)) { /* MAX DUID length is 128 octects + the type code (2 octects). */ if ( duid_len > 2 && duid_len <= (128 + 2)) { diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index a6074a8a7e..4905b5a8c3 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -14384,9 +14384,9 @@ 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_bin2str (g_bytes_get_data (client_id, NULL), - g_bytes_get_size (client_id), - FALSE)); + _nm_utils_bin2hexstr (g_bytes_get_data (client_id, NULL), + g_bytes_get_size (client_id), + FALSE)); } hostname = nm_dhcp_client_get_hostname (priv->dhcp4.client); @@ -14424,9 +14424,9 @@ 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_bin2str (iid.id_u8, - sizeof (NMUtilsIPv6IfaceId), - FALSE)); + _nm_utils_bin2hexstr (iid.id_u8, + sizeof (NMUtilsIPv6IfaceId), + FALSE)); } 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 6bbc670b28..f6d97b5ffc 100644 --- a/src/dhcp/nm-dhcp-utils.c +++ b/src/dhcp/nm-dhcp-utils.c @@ -729,7 +729,7 @@ nm_dhcp_utils_duid_to_string (GBytes *duid) g_return_val_if_fail (duid != NULL, NULL); data = g_bytes_get_data (duid, &len); - return _nm_utils_bin2str (data, len, FALSE); + return _nm_utils_bin2hexstr (data, len, FALSE); } /** diff --git a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c index 09a379914b..f8c4d18d4e 100644 --- a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c +++ b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c @@ -189,7 +189,7 @@ _secret_password_raw_to_bytes (const char *ifcfg_key, password_raw += 2; secret = nm_secret_buf_new (strlen (password_raw) / 2 + 3); - if (!_nm_utils_str2bin_full (password_raw, FALSE, ":", secret->bin, secret->len, &len)) { + if (!_nm_utils_hexstr2bin_full (password_raw, FALSE, ":", secret->bin, secret->len, &len)) { g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Invalid hex password in %s", ifcfg_key);