diff options
author | Aleksander Morgado <aleksander@aleksander.es> | 2019-06-16 11:57:08 +0200 |
---|---|---|
committer | Aleksander Morgado <aleksander@aleksander.es> | 2019-07-11 23:00:50 +0200 |
commit | 1cc31df4252a10c7c54a627d4e3eeb7a0837dfbd (patch) | |
tree | 0f2a69c8594862b2dc2e104b598a835057ba8de8 /src/mm-modem-helpers.c | |
parent | 67cc9992664601888fce7bcbc602a4dbf4ef07aa (diff) |
helpers: new '+CLCC' test response parser
Diffstat (limited to 'src/mm-modem-helpers.c')
-rw-r--r-- | src/mm-modem-helpers.c | 115 |
1 files changed, 115 insertions, 0 deletions
diff --git a/src/mm-modem-helpers.c b/src/mm-modem-helpers.c index f94b26f3..b9d364d2 100644 --- a/src/mm-modem-helpers.c +++ b/src/mm-modem-helpers.c @@ -575,6 +575,121 @@ mm_voice_ccwa_regex_get (void) NULL); } +static void +call_info_free (MMCallInfo *info) +{ + if (!info) + return; + g_free (info->number); + g_slice_free (MMCallInfo, info); +} + +gboolean +mm_3gpp_parse_clcc_response (const gchar *str, + GList **out_list, + GError **error) +{ + GRegex *r; + GList *list = NULL; + GError *inner_error = NULL; + GMatchInfo *match_info = NULL; + + static const MMCallDirection call_direction[] = { + [0] = MM_CALL_DIRECTION_OUTGOING, + [1] = MM_CALL_DIRECTION_INCOMING, + }; + + static const MMCallState call_state[] = { + [0] = MM_CALL_STATE_ACTIVE, + [1] = MM_CALL_STATE_HELD, + [2] = MM_CALL_STATE_DIALING, /* Dialing (MOC) */ + [3] = MM_CALL_STATE_RINGING_OUT, /* Alerting (MOC) */ + [4] = MM_CALL_STATE_RINGING_IN, /* Incoming (MTC) */ + [5] = MM_CALL_STATE_WAITING, /* Waiting (MTC) */ + }; + + g_assert (out_list); + + /* + * 1 2 3 4 5 6 7 8 9 10 + * +CLCC: <idx>,<dir>,<stat>,<mode>,<mpty>[,<number>,<type>[,<alpha>[,<priority>[,<CLI validity>]]]] + * +CLCC: <idx>,<dir>,<stat>,<mode>,<mpty>[,<number>,<type>[,<alpha>[,<priority>[,<CLI validity>]]]] + * ... + */ + + r = g_regex_new ("\\+CLCC:\\s*(\\d+),\\s*(\\d+),\\s*(\\d+),\\s*(\\d+),\\s*(\\d+)" /* mandatory fields */ + "(?:,\\s*([^,]*),\\s*(\\d+)" /* number and type */ + "(?:,\\s*([^,]*)" /* alpha */ + "(?:,\\s*(\\d*)" /* priority */ + "(?:,\\s*(\\d*)" /* CLI validity */ + ")?)?)?)?$", + G_REGEX_RAW | G_REGEX_MULTILINE | G_REGEX_NEWLINE_CRLF, + G_REGEX_MATCH_NEWLINE_CRLF, + NULL); + g_assert (r != NULL); + + g_regex_match_full (r, str, strlen (str), 0, 0, &match_info, &inner_error); + if (inner_error) + goto out; + + /* Parse the results */ + while (g_match_info_matches (match_info)) { + MMCallInfo *call_info; + guint aux; + + call_info = g_slice_new0 (MMCallInfo); + + if (!mm_get_uint_from_match_info (match_info, 1, &call_info->index)) { + mm_warn ("couldn't parse call index from +CLCC line"); + goto next; + } + + if (!mm_get_uint_from_match_info (match_info, 2, &aux) || + (aux >= G_N_ELEMENTS (call_direction))) { + mm_warn ("couldn't parse call direction from +CLCC line"); + goto next; + } + call_info->direction = call_direction[aux]; + + if (!mm_get_uint_from_match_info (match_info, 3, &aux) || + (aux >= G_N_ELEMENTS (call_state))) { + mm_warn ("couldn't parse call state from +CLCC line"); + goto next; + } + call_info->state = call_state[aux]; + + if (g_match_info_get_match_count (match_info) >= 7) + call_info->number = mm_get_string_unquoted_from_match_info (match_info, 6); + + list = g_list_append (list, call_info); + call_info = NULL; + + next: + call_info_free (call_info); + g_match_info_next (match_info, NULL); + } + +out: + g_clear_pointer (&match_info, g_match_info_free); + g_regex_unref (r); + + if (inner_error) { + mm_3gpp_call_info_list_free (list); + g_propagate_error (error, inner_error); + return FALSE; + } + + *out_list = list; + + return TRUE; +} + +void +mm_3gpp_call_info_list_free (GList *call_info_list) +{ + g_list_free_full (call_info_list, (GDestroyNotify) call_info_free); +} + /*************************************************************************/ static MMFlowControl |