diff options
author | Frederic Martinsons <frederic.martinsons@unabiz.com> | 2023-01-28 10:28:55 +0100 |
---|---|---|
committer | Aleksander Morgado <aleksandermj@chromium.org> | 2023-02-24 13:36:27 +0000 |
commit | 22808717d3c6033cf4d0648cf93de1871a45f4e9 (patch) | |
tree | fa1bf63158f44d43bb8cd920e8363b74c152fc38 | |
parent | d121c5d70a254afb3f290203add94b9dfbe81d13 (diff) | |
download | ModemManager-22808717d3c6033cf4d0648cf93de1871a45f4e9.tar.gz |
libmm-glib,common-helpers: Add multiple apn-type management
Fixes #676
Signed-off-by: Frederic Martinsons <frederic.martinsons@gmail.com>
(cherry picked from commit 02aafa2948cd9446b21e40855405bda1885c7f15)
-rw-r--r-- | libmm-glib/mm-common-helpers.c | 35 | ||||
-rw-r--r-- | libmm-glib/tests/test-common-helpers.c | 27 |
2 files changed, 50 insertions, 12 deletions
diff --git a/libmm-glib/mm-common-helpers.c b/libmm-glib/mm-common-helpers.c index 7ef1c727b..8bccee746 100644 --- a/libmm-glib/mm-common-helpers.c +++ b/libmm-glib/mm-common-helpers.c @@ -211,26 +211,37 @@ _flags_from_string (GType type, guint error_value, GError **error) { + g_auto(GStrv) flags_strings = NULL; g_autoptr(GFlagsClass) flags_class = NULL; - guint value; + guint value = 0; guint i; flags_class = G_FLAGS_CLASS (g_type_class_ref (type)); + flags_strings = g_strsplit (str, "|", -1); - for (i = 0; flags_class->values[i].value_nick; i++) { - if (!g_ascii_strcasecmp (str, flags_class->values[i].value_nick)) { - value = flags_class->values[i].value; - return value; + for (i = 0; flags_strings[i]; i++) { + guint j; + gboolean found = FALSE; + + for (j = 0; flags_class->values[j].value_nick; j++) { + if (!g_ascii_strcasecmp (flags_strings[i], flags_class->values[j].value_nick)) { + value |= flags_class->values[j].value; + found = TRUE; + } + } + + if (!found) { + g_set_error (error, + MM_CORE_ERROR, + MM_CORE_ERROR_INVALID_ARGS, + "Couldn't match '%s' with a valid %s value", + flags_strings[i], + g_type_name (type)); + return error_value; } } - g_set_error (error, - MM_CORE_ERROR, - MM_CORE_ERROR_INVALID_ARGS, - "Couldn't match '%s' with a valid %s value", - str, - g_type_name (type)); - return error_value; + return value; } MMModemCapability diff --git a/libmm-glib/tests/test-common-helpers.c b/libmm-glib/tests/test-common-helpers.c index fc428baff..b8923ab34 100644 --- a/libmm-glib/tests/test-common-helpers.c +++ b/libmm-glib/tests/test-common-helpers.c @@ -915,6 +915,15 @@ ip_type_from_string (void) ip_type = mm_common_get_ip_type_from_string ("ipv4v6", &error); g_assert_no_error (error); g_assert (ip_type == MM_BEARER_IP_FAMILY_IPV4V6); + + ip_type = mm_common_get_ip_type_from_string ("ipv4v6|type-unknown", &error); + g_assert_error (error, MM_CORE_ERROR, MM_CORE_ERROR_INVALID_ARGS); + g_assert (ip_type == MM_BEARER_IP_FAMILY_NONE); + g_clear_error (&error); + + ip_type = mm_common_get_ip_type_from_string ("ipv4|ipv6", &error); + g_assert_no_error (error); + g_assert (ip_type == (MM_BEARER_IP_FAMILY_IPV4 | MM_BEARER_IP_FAMILY_IPV6)); } static void @@ -1150,6 +1159,15 @@ apn_type_from_string (void) apn_type = mm_common_get_apn_type_from_string ("emergency", &error); g_assert_no_error (error); g_assert (apn_type == MM_BEARER_APN_TYPE_EMERGENCY); + + apn_type = mm_common_get_apn_type_from_string ("emergency|type-unknown", &error); + g_assert_error (error, MM_CORE_ERROR, MM_CORE_ERROR_INVALID_ARGS); + g_assert (apn_type == MM_BEARER_APN_TYPE_NONE); + g_clear_error (&error); + + apn_type = mm_common_get_apn_type_from_string ("emergency|local", &error); + g_assert_no_error (error); + g_assert (apn_type == (MM_BEARER_APN_TYPE_EMERGENCY | MM_BEARER_APN_TYPE_LOCAL)); } static void @@ -1166,6 +1184,15 @@ _3gpp_facility_from_string (void) facility = mm_common_get_3gpp_facility_from_string ("ph-sim", &error); g_assert_no_error (error); g_assert (facility == MM_MODEM_3GPP_FACILITY_PH_SIM); + + facility = mm_common_get_3gpp_facility_from_string ("ph-sim|type-unknown", &error); + g_assert_error (error, MM_CORE_ERROR, MM_CORE_ERROR_INVALID_ARGS); + g_assert (facility == MM_MODEM_3GPP_FACILITY_NONE); + g_clear_error (&error); + + facility = mm_common_get_3gpp_facility_from_string ("ph-fsim|provider-pers", &error); + g_assert_no_error (error); + g_assert (facility == (MM_MODEM_3GPP_FACILITY_PH_FSIM | MM_MODEM_3GPP_FACILITY_PROVIDER_PERS)); } static void |