diff options
author | Aleksander Morgado <aleksander@lanedo.com> | 2012-02-01 09:42:29 +0100 |
---|---|---|
committer | Aleksander Morgado <aleksander@lanedo.com> | 2012-03-15 14:14:58 +0100 |
commit | 2bb43e00207f101673cc178d41c667c17ee6ea2f (patch) | |
tree | ea7708af80aa32b01a789f79d03f8c149aa5158d | |
parent | 4c6765857b53a204afd70fc247a2f1bc817d82b3 (diff) |
modem-helpers: new CMGF format query result parser
-rw-r--r-- | src/mm-modem-helpers.c | 57 | ||||
-rw-r--r-- | src/mm-modem-helpers.h | 5 |
2 files changed, 62 insertions, 0 deletions
diff --git a/src/mm-modem-helpers.c b/src/mm-modem-helpers.c index 0b4cc348..823ef514 100644 --- a/src/mm-modem-helpers.c +++ b/src/mm-modem-helpers.c @@ -294,6 +294,63 @@ mm_3gpp_parse_scan_response (const gchar *reply, /*************************************************************************/ +#define CMGF_TAG "+CMGF:" + +gboolean +mm_3gpp_parse_cmgf_format_response (const gchar *reply, + gboolean *sms_pdu_supported, + gboolean *sms_text_supported, + GError **error) +{ + GRegex *r; + GMatchInfo *match_info; + char *s; + guint32 min = -1, max = -1; + + /* Strip whitespace and response tag */ + if (g_str_has_prefix (reply, CMGF_TAG)) + reply += strlen (CMGF_TAG); + while (isspace (*reply)) + reply++; + + r = g_regex_new ("\\(?\\s*(\\d+)\\s*[-,]?\\s*(\\d+)?\\s*\\)?", 0, 0, error); + if (!r) + return FALSE; + + 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 CMGF query result '%s'", + reply); + g_match_info_free (match_info); + g_regex_unref (r); + return FALSE; + } + + s = g_match_info_fetch (match_info, 1); + if (s) + min = atoi (s); + g_free (s); + + s = g_match_info_fetch (match_info, 2); + if (s) + max = atoi (s); + g_free (s); + + /* CMGF=0 for PDU mode */ + *sms_pdu_supported = (min == 0); + + /* CMGF=1 for Text mode */ + *sms_text_supported = (max >= 1); + + g_match_info_free (match_info); + g_regex_unref (r); + return TRUE; +} + +/*************************************************************************/ + static void mm_3gpp_pdp_context_free (MM3gppPdpContext *pdp) { diff --git a/src/mm-modem-helpers.h b/src/mm-modem-helpers.h index 44442658..203c33be 100644 --- a/src/mm-modem-helpers.h +++ b/src/mm-modem-helpers.h @@ -64,6 +64,11 @@ gboolean mm_3gpp_parse_creg_response (GMatchInfo *info, gboolean *out_cgreg, GError **error); +gboolean mm_3gpp_parse_cmgf_format_response (const gchar *reply, + gboolean *sms_pdu_supported, + gboolean *sms_text_supported, + GError **error); + GRegex *mm_3gpp_ciev_regex_get (void); GRegex *mm_3gpp_cusd_regex_get (void); |