libmm-glib,common-helpers: Add multiple apn-type management

Fixes #676

Signed-off-by: Frederic Martinsons <frederic.martinsons@gmail.com>
This commit is contained in:
Frederic Martinsons
2023-01-28 10:28:55 +01:00
committed by Aleksander Morgado
parent 511f712160
commit 02aafa2948
2 changed files with 50 additions and 12 deletions

View File

@@ -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

View File

@@ -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