diff options
author | Dan Williams <dcbw@redhat.com> | 2014-11-06 17:51:09 -0600 |
---|---|---|
committer | Dan Williams <dcbw@redhat.com> | 2014-11-07 12:18:32 -0600 |
commit | 22762324e841df851219cec0a79bb063824c5dfc (patch) | |
tree | 5b0d7c9eef6f3c2cd71472e868f072b9473825cb /libnm | |
parent | cbabd135818fd4749ad0b827ba1f0bc444b92a97 (diff) | |
download | NetworkManager-22762324e841df851219cec0a79bb063824c5dfc.tar.gz |
libnm,core: enhance nm_utils_hexstr2bin()
Make the type return GBytes since most in-tree users want that.
Allow the function to accept many more formats as valid hex, including
bytes delimited by ':' and a leading '0x'.
Diffstat (limited to 'libnm')
-rw-r--r-- | libnm/libnm.ver | 1 | ||||
-rw-r--r-- | libnm/nm-device.c | 15 |
2 files changed, 14 insertions, 2 deletions
diff --git a/libnm/libnm.ver b/libnm/libnm.ver index baf83ca548..d1957ececc 100644 --- a/libnm/libnm.ver +++ b/libnm/libnm.ver @@ -756,7 +756,6 @@ global: nm_utils_deinit; nm_utils_escape_ssid; nm_utils_file_is_pkcs12; - nm_utils_hex2byte; nm_utils_hexstr2bin; nm_utils_hwaddr_atoba; nm_utils_hwaddr_aton; diff --git a/libnm/nm-device.c b/libnm/nm-device.c index ba5dbacb85..a6d5fe3067 100644 --- a/libnm/nm-device.c +++ b/libnm/nm-device.c @@ -1249,6 +1249,19 @@ nm_device_get_available_connections (NMDevice *device) return NM_DEVICE_GET_PRIVATE (device)->available_connections; } +static inline guint8 +hex2byte (const char *hex) +{ + int a, b; + a = g_ascii_xdigit_value (*hex++); + if (a < 0) + return -1; + b = g_ascii_xdigit_value (*hex++); + if (b < 0) + return -1; + return (a << 4) | b; +} + static char * get_decoded_property (GUdevDevice *device, const char *property) { @@ -1264,7 +1277,7 @@ get_decoded_property (GUdevDevice *device, const char *property) n = unescaped = g_malloc0 (len + 1); while (*p) { if ((len >= 4) && (*p == '\\') && (*(p+1) == 'x')) { - *n++ = (char) nm_utils_hex2byte (p + 2); + *n++ = (char) hex2byte (p + 2); p += 4; len -= 4; } else { |