broadband-modem: don't assume the returned string is always hex-encoded

This commit is contained in:
Aleksander Morgado
2013-02-22 19:43:49 +01:00
parent ca49af0c5d
commit b1bb8e30b4
3 changed files with 32 additions and 1 deletions
+25
View File
@@ -929,6 +929,31 @@ mm_utils_hexstr2bin (const gchar *hex, gsize *out_len)
/* End from hostap */
gboolean
mm_utils_ishexstr (const gchar *hex)
{
gsize len;
gsize i;
/* Length not multiple of 2? */
len = strlen (hex);
if (len % 2 != 0)
return FALSE;
for (i = 0; i < len; i++) {
/* Non-hex char? */
if (hex[i] >= '0' && hex[i] <= '9')
continue;
if (hex[i] >= 'a' && hex[i] <= 'f')
continue;
if (hex[i] >= 'A' && hex[i] <= 'F')
continue;
return FALSE;
}
return TRUE;
}
gchar *
mm_utils_bin2hexstr (const guint8 *bin, gsize len)
{
+1
View File
@@ -99,6 +99,7 @@ const gchar *mm_sms_delivery_state_get_string_extended (guint delivery_state);
gint mm_utils_hex2byte (const gchar *hex);
gchar *mm_utils_hexstr2bin (const gchar *hex, gsize *out_len);
gchar *mm_utils_bin2hexstr (const guint8 *bin, gsize len);
gboolean mm_utils_ishexstr (const gchar *hex);
gboolean mm_utils_check_for_single_value (guint32 value);
+6 -1
View File
@@ -4373,8 +4373,13 @@ decode_ussd_response (MMBroadbandModem *self,
if (p)
*p = '\0';
decoded = mm_iface_modem_3gpp_ussd_decode (MM_IFACE_MODEM_3GPP_USSD (self), str, error);
/* If reply doesn't seem to be hex; just return itself... */
if (!mm_utils_ishexstr (str))
decoded = g_strdup (str);
else
decoded = mm_iface_modem_3gpp_ussd_decode (MM_IFACE_MODEM_3GPP_USSD (self), str, error);
g_strfreev (items);
return decoded;
}