diff options
author | Teijo Kinnunen <teijo.kinnunen@uros.com> | 2021-03-03 16:27:32 +0200 |
---|---|---|
committer | Teijo Kinnunen <teijo.kinnunen@uros.com> | 2021-03-09 08:52:55 +0200 |
commit | 0919abaa2ffa6d3ca42fcd73d7ed2040fabd61be (patch) | |
tree | ecb1b44700f36295b7172aa9045e5e2b50bb507f /libmm-glib/mm-common-helpers.c | |
parent | 66e93751b802beb5072e72bc911df3edf64b9a37 (diff) |
mmcli,sim: implement --sim-set-preferred-networks function
Diffstat (limited to 'libmm-glib/mm-common-helpers.c')
-rw-r--r-- | libmm-glib/mm-common-helpers.c | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/libmm-glib/mm-common-helpers.c b/libmm-glib/mm-common-helpers.c index 43fff922..f2faf71c 100644 --- a/libmm-glib/mm-common-helpers.c +++ b/libmm-glib/mm-common-helpers.c @@ -1313,6 +1313,56 @@ mm_common_parse_key_value_string (const gchar *str, return TRUE; } +MMModemAccessTechnology +mm_common_get_access_technology_from_string (const gchar *str, + GError **error) +{ + GError *inner_error = NULL; + MMModemAccessTechnology technologies; + gchar **technology_strings; + GFlagsClass *flags_class; + + technologies = MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN; + + flags_class = G_FLAGS_CLASS (g_type_class_ref (MM_TYPE_MODEM_ACCESS_TECHNOLOGY)); + technology_strings = g_strsplit (str, "|", -1); + + if (technology_strings) { + guint i; + + for (i = 0; technology_strings[i]; i++) { + guint j; + gboolean found = FALSE; + + for (j = 0; flags_class->values[j].value_nick; j++) { + if (!g_ascii_strcasecmp (technology_strings[i], flags_class->values[j].value_nick)) { + technologies |= flags_class->values[j].value; + found = TRUE; + break; + } + } + + if (!found) { + inner_error = g_error_new ( + MM_CORE_ERROR, + MM_CORE_ERROR_INVALID_ARGS, + "Couldn't match '%s' with a valid MMModemAccessTechnology value", + technology_strings[i]); + break; + } + } + } + + if (inner_error) { + g_propagate_error (error, inner_error); + technologies = MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN; + } + + g_type_class_unref (flags_class); + g_strfreev (technology_strings); + return technologies; +} + /*****************************************************************************/ gboolean @@ -1612,6 +1662,26 @@ mm_get_string_unquoted_from_match_info (GMatchInfo *match_info, return str; } +gboolean +mm_is_string_mccmnc (const gchar *str) +{ + gsize len; + guint i; + + if (!str) + return FALSE; + + len = strlen (str); + if (len < 5 || len > 6) + return FALSE; + + for (i = 0; i < len; i++) + if (str[i] < '0' || str[i] > '9') + return FALSE; + + return TRUE; +} + /*****************************************************************************/ const gchar * |