aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@lanedo.com>2013-02-22 21:48:45 +0100
committerAleksander Morgado <aleksander@lanedo.com>2013-02-22 21:54:57 +0100
commit3f8b11e3f0af19b0df0fb510b76cdcae42a3dd5d (patch)
tree41af827442da9210e34eae91a2cf28abd2989088
parentc19ee43cbea5c553b5ad2d5bb10f88abad574965 (diff)
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.
-rw-r--r--src/mm-broadband-modem.c47
1 files changed, 16 insertions, 31 deletions
diff --git a/src/mm-broadband-modem.c b/src/mm-broadband-modem.c
index 7f2ceb18..9f45904f 100644
--- a/src/mm-broadband-modem.c
+++ b/src/mm-broadband-modem.c
@@ -4356,9 +4356,8 @@ decode_ussd_response (MMBroadbandModem *self,
const gchar *reply,
GError **error)
{
- gchar **items, **iter, *p;
- gchar *str = NULL;
- gint encoding = -1;
+ gchar *p;
+ gchar *str;
gchar *decoded;
/* Look for the first ',' */
@@ -4372,41 +4371,27 @@ decode_ussd_response (MMBroadbandModem *self,
return NULL;
}
- items = g_strsplit_set (p + 1, " ,", -1);
- for (iter = items; iter && *iter; iter++) {
- if (*iter[0] == '\0')
- continue;
- 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;
+ /* Assume the string is the next field, and strip quotes. While doing this,
+ * we also skip any other additional field we may have afterwards */
+ if (p[1] == '"') {
+ str = g_strdup (&p[2]);
+ p = strchr (str, '"');
+ if (p)
+ *p = '\0';
+ } else {
+ str = g_strdup (&p[1]);
+ p = strchr (str, ',');
+ if (p)
+ *p = '\0';
}
- /* 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 (!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);
+
+ g_free (str);
return decoded;
}