From be317e8b80cd984149ea152c9d00c6bb814e7c88 Mon Sep 17 00:00:00 2001 From: Carlo Lobrano Date: Wed, 9 Mar 2016 11:27:43 +0100 Subject: broadband-modem: fix +CPMS empty parameter support * Add new async virtual method init_current_storages to MMIfaceModemMessaging * Add logic of init_current_storages to MMBroadbandModem * Add step "INIT_CURRENT_STORAGES" in MMIfaceModemMessaging initialization in order to load and store current SMS storages for mem1 and mem2. * Add usage of current sms storage value for mem1 in place of an empty string parameter when the command AT+CPMS is used. https://bugs.freedesktop.org/show_bug.cgi?id=93135 --- src/mm-modem-helpers.c | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) (limited to 'src/mm-modem-helpers.c') diff --git a/src/mm-modem-helpers.c b/src/mm-modem-helpers.c index 58394ee6..74e55462 100644 --- a/src/mm-modem-helpers.c +++ b/src/mm-modem-helpers.c @@ -1507,6 +1507,82 @@ mm_3gpp_parse_cpms_test_response (const gchar *reply, return FALSE; } +/********************************************************************** + * AT+CPMS? + * +CPMS: ,,,,,, ,, + */ + +#define CPMS_QUERY_REGEX "\\+CPMS:\\s*\"(?P.*)\",[0-9]+,[0-9]+,\"(?P.*)\",[0-9]+,[0-9]+,\"(?P.*)\",[0-9]+,[0-9]" + +gboolean +mm_3gpp_parse_cpms_query_response (const gchar *reply, + MMSmsStorage *memr, + MMSmsStorage *memw, + GError **error) +{ + GRegex *r = NULL; + gboolean ret = FALSE; + GMatchInfo *match_info = NULL; + + r = g_regex_new (CPMS_QUERY_REGEX, G_REGEX_RAW, 0, NULL); + + g_assert(r); + + if (!g_regex_match (r, reply, 0, &match_info)) { + g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, + "Could not parse CPMS query reponse '%s'", reply); + goto end; + } + + if (!g_match_info_matches(match_info)) { + g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, + "Could not find matches in CPMS query reply '%s'", reply); + goto end; + } + + if (!mm_3gpp_get_cpms_storage_match (match_info, "memr", memr, error)) { + goto end; + } + + if (!mm_3gpp_get_cpms_storage_match (match_info, "memw", memw, error)) { + goto end; + } + + ret = TRUE; + +end: + if (r != NULL) + g_regex_unref (r); + + if (match_info != NULL) + g_match_info_free (match_info); + + return ret; +} + +gboolean +mm_3gpp_get_cpms_storage_match (GMatchInfo *match_info, + const gchar *match_name, + MMSmsStorage *storage, + GError **error) +{ + gboolean ret = TRUE; + gchar *str = NULL; + + str = g_match_info_fetch_named(match_info, match_name); + if (str == NULL || str[0] == '\0') { + g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, + "Could not find '%s' from CPMS reply", match_name); + ret = FALSE; + } else { + *storage = storage_from_str (str); + } + + g_free (str); + + return ret; +} + /*************************************************************************/ gboolean -- cgit v1.2.3-70-g09d2