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:
@@ -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)
|
|
||||||
str = *iter;
|
|
||||||
else if (encoding == -1) {
|
|
||||||
encoding = atoi (*iter);
|
|
||||||
mm_dbg ("USSD data coding scheme %d", encoding);
|
|
||||||
break; /* All done */
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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, '"');
|
p = strchr (str, '"');
|
||||||
if (p)
|
if (p)
|
||||||
*p = '\0';
|
*p = '\0';
|
||||||
|
} else {
|
||||||
|
str = g_strdup (&p[1]);
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user