broadband-modem: fix CUSD response parsing

When reading the string reply in a +CUSD indication, don't blindly split
using whitespace or comma as field separator, as the string may be a text string
with both whitespaces and commas, e.g.:

+CUSD: 0,"hey hey, something here<LF>***<LF>and something more here"

Also, skip reading the encoding field for now, as we don't use it yet.
This commit is contained in:
Aleksander Morgado
2013-02-22 21:48:45 +01:00
parent c19ee43cbe
commit 3f8b11e3f0

View File

@@ -4356,9 +4356,8 @@ decode_ussd_response (MMBroadbandModem *self,
const gchar *reply, const gchar *reply,
GError **error) GError **error)
{ {
gchar **items, **iter, *p; gchar *p;
gchar *str = NULL; gchar *str;
gint encoding = -1;
gchar *decoded; gchar *decoded;
/* Look for the first ',' */ /* Look for the first ',' */
@@ -4372,41 +4371,27 @@ decode_ussd_response (MMBroadbandModem *self,
return NULL; return NULL;
} }
items = g_strsplit_set (p + 1, " ,", -1); /* Assume the string is the next field, and strip quotes. While doing this,
for (iter = items; iter && *iter; iter++) { * we also skip any other additional field we may have afterwards */
if (*iter[0] == '\0') if (p[1] == '"') {
continue; str = g_strdup (&p[2]);
if (str == NULL) p = strchr (str, '"');
str = *iter; if (p)
else if (encoding == -1) { *p = '\0';
encoding = atoi (*iter); } else {
mm_dbg ("USSD data coding scheme %d", encoding); str = g_strdup (&p[1]);
break; /* All done */ p = strchr (str, ',');
} if (p)
*p = '\0';
} }
if (!str) {
g_set_error (error,
MM_CORE_ERROR,
MM_CORE_ERROR_FAILED,
"Cannot decode USSD response (%s): not enough fields",
reply);
return NULL;
}
/* Strip quotes */
if (str[0] == '"')
str++;
p = strchr (str, '"');
if (p)
*p = '\0';
/* If reply doesn't seem to be hex; just return itself... */ /* If reply doesn't seem to be hex; just return itself... */
if (!mm_utils_ishexstr (str)) if (!mm_utils_ishexstr (str))
decoded = g_strdup (str); decoded = g_strdup (str);
else else
decoded = mm_iface_modem_3gpp_ussd_decode (MM_IFACE_MODEM_3GPP_USSD (self), str, error); decoded = mm_iface_modem_3gpp_ussd_decode (MM_IFACE_MODEM_3GPP_USSD (self), str, error);
g_strfreev (items);
g_free (str);
return decoded; return decoded;
} }