aboutsummaryrefslogtreecommitdiff
path: root/src/mm-modem-helpers.c
diff options
context:
space:
mode:
authorNick Stevens <Nick.Stevens@digi.com>2015-09-17 21:31:28 +0000
committerAleksander Morgado <aleksander@aleksander.es>2015-09-22 09:24:18 +0200
commiteaf65ed98dd7e04b985be6b4241e9adab66750aa (patch)
treede288543475ca669e4a129aa2323390ed64f1c20 /src/mm-modem-helpers.c
parent0ca68657fbcd5bace3d303a0babe2da292784385 (diff)
core: process SMS +CGMR response with regex
Variability in the response style from certain modems causes the parsing of the +CGMR response to fail. For example, the Telit HE910 inserts an empty string ("") in the second field of the response, causing the sscanf implementation to fail. This patch converts the parsing of the CGMR response to a regex that allows for more flexibility and robustness, and adds unit tests around the parsing call. Signed-off-by: Nick Stevens <Nick.Stevens@digi.com>
Diffstat (limited to 'src/mm-modem-helpers.c')
-rw-r--r--src/mm-modem-helpers.c73
1 files changed, 72 insertions, 1 deletions
diff --git a/src/mm-modem-helpers.c b/src/mm-modem-helpers.c
index fb0b7fa1..5c9c269c 100644
--- a/src/mm-modem-helpers.c
+++ b/src/mm-modem-helpers.c
@@ -1201,6 +1201,77 @@ mm_3gpp_parse_cmgf_test_response (const gchar *reply,
/*************************************************************************/
+MM3gppPduInfo *
+mm_3gpp_parse_cmgr_read_response (const gchar *reply,
+ guint index,
+ GError **error)
+{
+ GRegex *r;
+ GMatchInfo *match_info;
+ gint count;
+ gint status;
+ gchar *pdu;
+ MM3gppPduInfo *info = NULL;
+
+ /* +CMGR: <stat>,<alpha>,<length>(whitespace)<pdu> */
+ /* The <alpha> and <length> fields are matched, but not currently used */
+ r = g_regex_new ("\\+CMGR:\\s*(\\d+)\\s*,([^,]*),\\s*(\\d+)\\s*([^\\r\\n]*)", 0, 0, NULL);
+ g_assert (r);
+
+ if (!g_regex_match_full (r, reply, strlen (reply), 0, 0, &match_info, NULL)) {
+ g_set_error (error,
+ MM_CORE_ERROR,
+ MM_CORE_ERROR_FAILED,
+ "Failed to parse CMGR read result: response didn't match '%s'",
+ reply);
+ goto done;
+ }
+
+ /* g_match_info_get_match_count includes match #0 */
+ if ((count = g_match_info_get_match_count (match_info)) != 5) {
+ g_set_error (error,
+ MM_CORE_ERROR,
+ MM_CORE_ERROR_FAILED,
+ "Failed to match CMGR fields (matched %d) '%s'",
+ count,
+ reply);
+ goto done;
+ }
+
+ if (!mm_get_int_from_match_info (match_info, 1, &status)) {
+ g_set_error (error,
+ MM_CORE_ERROR,
+ MM_CORE_ERROR_FAILED,
+ "Failed to extract CMGR status field '%s'",
+ reply);
+ goto done;
+ }
+
+
+ pdu = mm_get_string_unquoted_from_match_info (match_info, 4);
+ if (!pdu) {
+ g_set_error (error,
+ MM_CORE_ERROR,
+ MM_CORE_ERROR_FAILED,
+ "Failed to extract CMGR pdu field '%s'",
+ reply);
+ goto done;
+ }
+
+ info = g_new0 (MM3gppPduInfo, 1);
+ info->index = index;
+ info->status = status;
+ info->pdu = pdu;
+
+done:
+ g_match_info_free (match_info);
+ g_regex_unref (r);
+
+ return info;
+}
+
+/*************************************************************************/
+
static MMSmsStorage
storage_from_str (const gchar *str)
{
@@ -1698,7 +1769,7 @@ done:
/*************************************************************************/
-static void
+void
mm_3gpp_pdu_info_free (MM3gppPduInfo *info)
{
g_free (info->pdu);