aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@aleksander.es>2019-06-07 18:06:40 +0200
committerAleksander Morgado <aleksander@aleksander.es>2019-06-28 09:48:28 +0200
commit312e5dd623f6f26060fd904ee3dac5fd635777ff (patch)
tree7b26b0a5c100b4db6453ffde24cbc4d4a8d1c4c7
parent4656b5b606bbe7fce3426bf34dc2d231be757687 (diff)
modem-helpers: ignore format of unneeded fields in +CLIP URC
The regex was expecting empty values in several of the fields, which is wrong. Instead of matching empty fields, just ignore all fields that we don't require in our logic.
-rw-r--r--src/mm-modem-helpers.c12
-rw-r--r--src/tests/test-modem-helpers.c46
2 files changed, 54 insertions, 4 deletions
diff --git a/src/mm-modem-helpers.c b/src/mm-modem-helpers.c
index cf008d73..e1c9fc9d 100644
--- a/src/mm-modem-helpers.c
+++ b/src/mm-modem-helpers.c
@@ -544,11 +544,15 @@ mm_voice_cring_regex_get (void)
GRegex *
mm_voice_clip_regex_get (void)
{
- /* Example:
- * <CR><LF>+CLIP: "+393351391306",145,,,,0<CR><LF>
- * \_ Number \_ Type \_ Validity
+ /*
+ * Only first 2 fields are mandatory:
+ * +CLIP: <number>,<type>[,<subaddr>,<satype>[,[<alpha>][,<CLI_validity>]]]
+ *
+ * Example:
+ * <CR><LF>+CLIP: "+393351391306",145,,,,0<CR><LF>
+ * \_ Number \_ Type
*/
- return g_regex_new ("\\r\\n\\+CLIP:\\s*(\\S+),\\s*(\\d+),\\s*,\\s*,\\s*,\\s*(\\d+)\\r\\n",
+ return g_regex_new ("\\r\\n\\+CLIP:\\s*([^,\\s]*)\\s*,\\s*(\\d+)\\s*,?(.*)\\r\\n",
G_REGEX_RAW | G_REGEX_OPTIMIZE,
0,
NULL);
diff --git a/src/tests/test-modem-helpers.c b/src/tests/test-modem-helpers.c
index d5b09abd..0e8674d2 100644
--- a/src/tests/test-modem-helpers.c
+++ b/src/tests/test-modem-helpers.c
@@ -19,6 +19,7 @@
#include <stdlib.h>
#include <math.h>
+#define _LIBMM_INSIDE_MM
#include <libmm-glib.h>
#include "mm-modem-helpers.h"
#include "mm-log.h"
@@ -3926,6 +3927,49 @@ test_csim_response (void)
}
/*****************************************************************************/
+/* +CLIP URC */
+
+typedef struct {
+ const gchar *str;
+ const gchar *number;
+ guint type;
+} ClipUrcTest;
+
+static const ClipUrcTest clip_urc_tests[] = {
+ { "\r\n+CLIP: \"123456789\",129\r\n", "123456789", 129 },
+ { "\r\n+CLIP: \"123456789\",129,,,,0\r\n", "123456789", 129 },
+};
+
+static void
+test_clip_indication (void)
+{
+ GRegex *r;
+ guint i;
+
+ r = mm_voice_clip_regex_get ();
+
+ for (i = 0; i < G_N_ELEMENTS (clip_urc_tests); i++) {
+ GMatchInfo *match_info = NULL;
+ gchar *number;
+ guint type;
+
+ g_assert (g_regex_match (r, clip_urc_tests[i].str, 0, &match_info));
+ g_assert (g_match_info_matches (match_info));
+
+ number = mm_get_string_unquoted_from_match_info (match_info, 1);
+ g_assert_cmpstr (number, ==, clip_urc_tests[i].number);
+
+ g_assert (mm_get_uint_from_match_info (match_info, 2, &type));
+ g_assert_cmpuint (type, ==, clip_urc_tests[i].type);
+
+ g_free (number);
+ g_match_info_free (match_info);
+ }
+
+ g_regex_unref (r);
+}
+
+/*****************************************************************************/
typedef struct {
gchar *str;
@@ -4236,6 +4280,8 @@ int main (int argc, char **argv)
g_test_suite_add (suite, TESTCASE (test_cesq_response, NULL));
g_test_suite_add (suite, TESTCASE (test_cesq_response_to_signal, NULL));
+ g_test_suite_add (suite, TESTCASE (test_clip_indication, NULL));
+
g_test_suite_add (suite, TESTCASE (test_parse_uint_list, NULL));
g_test_suite_add (suite, TESTCASE (test_bcd_to_string, NULL));