diff options
author | Frederic Martinsons <frederic.martinsons@unabiz.com> | 2023-01-28 10:28:55 +0100 |
---|---|---|
committer | Aleksander Morgado <aleksander@aleksander.es> | 2023-02-17 10:46:44 +0000 |
commit | 02aafa2948cd9446b21e40855405bda1885c7f15 (patch) | |
tree | ce9d623230a4872f11cd4f334159666de06b0bc7 /libmm-glib/mm-common-helpers.c | |
parent | 511f7121602f639239368dd60b2bea6e06007375 (diff) |
libmm-glib,common-helpers: Add multiple apn-type management
Fixes #676
Signed-off-by: Frederic Martinsons <frederic.martinsons@gmail.com>
Diffstat (limited to 'libmm-glib/mm-common-helpers.c')
-rw-r--r-- | libmm-glib/mm-common-helpers.c | 35 |
1 files changed, 23 insertions, 12 deletions
diff --git a/libmm-glib/mm-common-helpers.c b/libmm-glib/mm-common-helpers.c index ac75abcf..d233a801 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 |