From 6af2e26639bf211ffd8f6d7721ff27ea2cd49476 Mon Sep 17 00:00:00 2001 From: Mohammed Sadiq Date: Tue, 7 Jul 2020 18:09:22 +0530 Subject: [PATCH] util: Add API to test for USSD command --- src/util.c | 23 +++++++++++++++++++++++ src/util.h | 1 + 2 files changed, 24 insertions(+) diff --git a/src/util.c b/src/util.c index 69749b4..a58c487 100644 --- a/src/util.c +++ b/src/util.c @@ -144,6 +144,29 @@ calls_date_time_is_same_year (GDateTime *a, } +gboolean +calls_number_is_ussd (const char *number) +{ + /* USSD numbers start with *, #, **, ## or *# and are finished by # */ + if (!number || + (*number != '*' && *number != '#')) + return FALSE; + + number++; + + if (*number == '#') + number++; + + while (g_ascii_isdigit (*number) || *number == '*') + number++; + + if (g_str_equal (number, "#")) + return TRUE; + + return FALSE; +} + + gboolean calls_find_in_store (GListModel *list, gpointer item, diff --git a/src/util.h b/src/util.h index bb34f32..1615035 100644 --- a/src/util.h +++ b/src/util.h @@ -137,6 +137,7 @@ gboolean calls_date_time_is_yesterday (GDateTime *now, GDateTime *t); gboolean calls_date_time_is_same_year (GDateTime *a, GDateTime *b); +gboolean calls_number_is_ussd (const char *number); gboolean calls_find_in_store (GListModel *list, gpointer item,