aboutsummaryrefslogtreecommitdiff
path: root/src/mm-modem-helpers.c
diff options
context:
space:
mode:
authorDan Williams <dan@ioncontrol.co>2025-05-30 18:54:05 -0500
committerDan Williams <dan@ioncontrol.co>2025-05-30 18:54:05 -0500
commit37f17d4b5859d8a37d1a9350abc9fcb15917de07 (patch)
tree7af9420327a7deea70df1bbcaa004724fed1aec7 /src/mm-modem-helpers.c
parent3ed7f378765b45a84ce6c0b4de6751769fefc221 (diff)
parentdad2d49b696c66ccf868bc89b35a6529f9e15777 (diff)
Merge request !1336 from 'dtmf-serialize'
Serialize DTMF requests and allow setting DTMF duration at call creation time https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/merge_requests/1336 Closes #970
Diffstat (limited to 'src/mm-modem-helpers.c')
-rw-r--r--src/mm-modem-helpers.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/mm-modem-helpers.c b/src/mm-modem-helpers.c
index a79ca956..5cbf0836 100644
--- a/src/mm-modem-helpers.c
+++ b/src/mm-modem-helpers.c
@@ -5871,3 +5871,53 @@ mm_parse_cpin_response (const gchar *response,
return MM_MODEM_LOCK_UNKNOWN;
}
+
+/*****************************************************************************/
+
+guint
+mm_dtmf_duration_normalize (guint duration_ms)
+{
+ /* Default to 500ms */
+ if (duration_ms == 0)
+ return 500;
+
+ /* round to next highest 100ms */
+ if (duration_ms % 100)
+ duration_ms = ((duration_ms + 100) / 100) * 100;
+
+ return CLAMP (duration_ms, 100, 1000);
+}
+
+GPtrArray *
+mm_dtmf_split (const gchar *dtmf)
+{
+ GPtrArray *array;
+ const gchar *p = dtmf;
+ GString *cur = NULL;
+
+ array = g_ptr_array_new ();
+
+ while (*p) {
+ if (*p == MM_CALL_DTMF_PAUSE_CHAR) {
+ if (cur) {
+ g_ptr_array_add (array, g_string_free (cur, FALSE));
+ cur = NULL;
+ }
+ g_ptr_array_add (array, g_strdup (","));
+ } else {
+ if (!cur)
+ cur = g_string_new (NULL);
+ g_string_append_c (cur, *p);
+ }
+ p++;
+ }
+ if (cur)
+ g_ptr_array_add (array, g_string_free (cur, FALSE));
+
+ if (array->len == 0) {
+ g_ptr_array_free (array, TRUE);
+ return NULL;
+ }
+
+ return array;
+}