diff options
author | Aleksander Morgado <aleksander@lanedo.com> | 2013-03-30 14:53:17 +0100 |
---|---|---|
committer | Aleksander Morgado <aleksander@lanedo.com> | 2013-04-02 09:53:46 +0200 |
commit | c1e70924d8197c51bb8dedb2d232f03dff87aa7b (patch) | |
tree | 00564f9f9cf6a90e0ef4d188f5b7c5f9050f6960 /src/mm-broadband-modem.c | |
parent | bb4f4f4e9e91d79974d1bb4ce3d42c5b0bbc734d (diff) |
broadband-modem: update CMGL parsing logic
Pantech UMW190 modem uses a custom +CMGL response which includes only
three fields before the actual PDU, e.g:
+CMGL: <index>,<status>,<something>\r\n<PDU>
instead of what we had before:
+CMGL: <index>,<status>,<alpha>,<length>\r\n<PDU>
The CMGL parsing logic is now updated to use a regex to match the reply, and
also considering the UMW190 specific case.
Actually, we end up reading only the two first fields (index and status) which
are the ones we really need, so we skip the <length> and the <alpha> if given.
Added also unit tests to cover all these known cases.
Partially fixes https://bugzilla.gnome.org/show_bug.cgi?id=696723 (missing the
actual PDU parsing fixes).
Diffstat (limited to 'src/mm-broadband-modem.c')
-rw-r--r-- | src/mm-broadband-modem.c | 45 |
1 files changed, 17 insertions, 28 deletions
diff --git a/src/mm-broadband-modem.c b/src/mm-broadband-modem.c index 8ec4d1e6..de09d1cb 100644 --- a/src/mm-broadband-modem.c +++ b/src/mm-broadband-modem.c @@ -5748,6 +5748,8 @@ sms_pdu_part_list_ready (MMBroadbandModem *self, { const gchar *response; GError *error = NULL; + GList *info_list; + GList *l; /* Always always always unlock mem1 storage. Warned you've been. */ mm_broadband_modem_unlock_sms_storages (self, TRUE, FALSE); @@ -5759,46 +5761,33 @@ sms_pdu_part_list_ready (MMBroadbandModem *self, return; } - while (*response) { - MMSmsPart *part; - gint idx; - gint status; - gint tpdu_len; - gchar pdu[SMS_MAX_PDU_LEN + 1]; - gint offset; - gint rv; - - rv = sscanf (response, - "+CMGL: %d,%d,,%d %" G_STRINGIFY (SMS_MAX_PDU_LEN) "s %n", - &idx, &status, &tpdu_len, pdu, &offset); - if (4 != rv) { - g_simple_async_result_set_error (ctx->result, - MM_CORE_ERROR, - MM_CORE_ERROR_INVALID_ARGS, - "Couldn't parse SMS list response: " - "only %d fields parsed", - rv); - list_parts_context_complete_and_free (ctx); - return; - } + info_list = mm_3gpp_parse_pdu_cmgl_response (response, &error); + if (error) { + g_simple_async_result_take_error (ctx->result, error); + list_parts_context_complete_and_free (ctx); + return; + } - /* Will try to keep on the loop */ - response += offset; + for (l = info_list; l; l = g_list_next (l)) { + MM3gppPduInfo *info = l->data; + MMSmsPart *part; - part = mm_sms_part_new_from_pdu (idx, pdu, &error); + part = mm_sms_part_new_from_pdu (info->index, info->pdu, &error); if (part) { - mm_dbg ("Correctly parsed PDU (%d)", idx); + mm_dbg ("Correctly parsed PDU (%d)", info->index); mm_iface_modem_messaging_take_part (MM_IFACE_MODEM_MESSAGING (self), part, - sms_state_from_index (status), + sms_state_from_index (info->status), ctx->list_storage); } else { /* Don't treat the error as critical */ - mm_dbg ("Error parsing PDU (%d): %s", idx, error->message); + mm_dbg ("Error parsing PDU (%d): %s", info->index, error->message); g_clear_error (&error); } } + mm_3gpp_pdu_info_list_free (info_list); + /* We consider all done */ g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE); list_parts_context_complete_and_free (ctx); |