[PATCH v2] modem-helpers: allow unquoted strings in +CCLK responses

Aleksander Morgado aleksander at aleksander.es
Wed Aug 9 14:28:11 UTC 2017


Also:
  * define the leading '+' as a escaped value
  * allow any number of spaces between '+CCLK' and the string value.
---

Hey,

Yes, it makes sense to add unit tests also for the multiple spaces change, see this v2 patch.

Cheers!

---
 src/mm-modem-helpers.c         |  7 +++++--
 src/tests/test-modem-helpers.c | 21 +++++++++++++++++++++
 2 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/src/mm-modem-helpers.c b/src/mm-modem-helpers.c
index 83a48648..b2806dfa 100644
--- a/src/mm-modem-helpers.c
+++ b/src/mm-modem-helpers.c
@@ -4157,8 +4157,11 @@ mm_parse_cclk_response (const char *response,

     g_assert (iso8601p || tzp); /* at least one */

-    /* Sample reply: +CCLK: "15/03/05,14:14:26-32" */
-    r = g_regex_new ("[+]CCLK: \"(\\d+)/(\\d+)/(\\d+),(\\d+):(\\d+):(\\d+)([-+]\\d+)?\"", 0, 0, NULL);
+    /* Sample replies:
+     *  +CCLK: "15/03/05,14:14:26-32"
+     *  +CCLK: 17/07/26,11:42:15+01
+     */
+    r = g_regex_new ("\\+CCLK:\\s*\"?(\\d+)/(\\d+)/(\\d+),(\\d+):(\\d+):(\\d+)([-+]\\d+)?\"?", 0, 0, NULL);
     g_assert (r != NULL);

     if (!g_regex_match_full (r, response, -1, 0, 0, &match_info, &match_error)) {
diff --git a/src/tests/test-modem-helpers.c b/src/tests/test-modem-helpers.c
index ca3202ab..52e6302a 100644
--- a/src/tests/test-modem-helpers.c
+++ b/src/tests/test-modem-helpers.c
@@ -3203,6 +3203,27 @@ static const CclkTest cclk_tests[] = {
     { "+CCLK: \"15/02/28,20:30:40-32\"", TRUE, TRUE, TRUE,
         "2015-02-28T20:30:40-08:00", -480 },

+    { "+CCLK: 17/07/26,11:42:15+01", TRUE, TRUE, FALSE,
+      "2017-07-26T11:42:15+00:15", 15 },
+    { "+CCLK: 17/07/26,11:42:15+01", TRUE, FALSE, TRUE,
+      "2017-07-26T11:42:15+00:15", 15 },
+    { "+CCLK: 17/07/26,11:42:15+01", TRUE, TRUE, TRUE,
+      "2017-07-26T11:42:15+00:15", 15 },
+
+    { "+CCLK:   \"15/02/28,20:30:40-32\"", TRUE, TRUE, FALSE,
+        "2015-02-28T20:30:40-08:00", -480 },
+    { "+CCLK:   \"15/02/28,20:30:40-32\"", TRUE, FALSE, TRUE,
+        "2015-02-28T20:30:40-08:00", -480 },
+    { "+CCLK:   \"15/02/28,20:30:40-32\"", TRUE, TRUE, TRUE,
+        "2015-02-28T20:30:40-08:00", -480 },
+
+    { "+CCLK:   17/07/26,11:42:15+01", TRUE, TRUE, FALSE,
+      "2017-07-26T11:42:15+00:15", 15 },
+    { "+CCLK:   17/07/26,11:42:15+01", TRUE, FALSE, TRUE,
+      "2017-07-26T11:42:15+00:15", 15 },
+    { "+CCLK:   17/07/26,11:42:15+01", TRUE, TRUE, TRUE,
+      "2017-07-26T11:42:15+00:15", 15 },
+
     { "+CCLK: \"XX/XX/XX,XX:XX:XX+XX\"", FALSE, TRUE, FALSE,
         NULL, MM_NETWORK_TIMEZONE_OFFSET_UNKNOWN },

--
2.13.1


More information about the ModemManager-devel mailing list