summaryrefslogtreecommitdiff
path: root/src/NetworkManagerUtils.c
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2016-02-13 16:06:36 +0100
committerThomas Haller <thaller@redhat.com>2016-02-21 18:31:39 +0100
commita51a1cde3621d682bc70e8771d48a8af797bd24e (patch)
treee74c76c65377ba7ca161ed9ec9be575704759097 /src/NetworkManagerUtils.c
parent6ee744f41d0c3484c2626a37fd3cd5a7b58af3ca (diff)
utils: add nm_utils_parse_debug_string() to replace g_parse_debug_string()
g_parse_debug_string() interprets the string "help" special and accepts an "all" tag to invert the result. We don't want that.
Diffstat (limited to 'src/NetworkManagerUtils.c')
-rw-r--r--src/NetworkManagerUtils.c62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/NetworkManagerUtils.c b/src/NetworkManagerUtils.c
index 9e3928f72..5379c5403 100644
--- a/src/NetworkManagerUtils.c
+++ b/src/NetworkManagerUtils.c
@@ -3627,3 +3627,65 @@ nm_utils_g_value_set_strv (GValue *value, GPtrArray *strings)
g_value_take_boxed (value, strv);
}
+
+/*****************************************************************************/
+
+static gboolean
+debug_key_matches (const gchar *key,
+ const gchar *token,
+ guint length)
+{
+ /* may not call GLib functions: see note in g_parse_debug_string() */
+ for (; length; length--, key++, token++) {
+ char k = (*key == '_') ? '-' : g_ascii_tolower (*key );
+ char t = (*token == '_') ? '-' : g_ascii_tolower (*token);
+
+ if (k != t)
+ return FALSE;
+ }
+
+ return *key == '\0';
+}
+
+/**
+ * nm_utils_parse_debug_string:
+ * @string: the string to parse
+ * @keys: the debug keys
+ * @nkeys: number of entires in @keys
+ *
+ * Similar to g_parse_debug_string(), but does not special
+ * case "help" or "all".
+ *
+ * Returns: the flags
+ */
+guint
+nm_utils_parse_debug_string (const char *string,
+ const GDebugKey *keys,
+ guint nkeys)
+{
+ guint i;
+ guint result = 0;
+ const char *q;
+
+ if (string == NULL)
+ return 0;
+
+ while (*string) {
+ q = strpbrk (string, ":;, \t");
+ if (!q)
+ q = string + strlen (string);
+
+ for (i = 0; i < nkeys; i++) {
+ if (debug_key_matches (keys[i].key, string, q - string))
+ result |= keys[i].value;
+ }
+
+ string = q;
+ if (*string)
+ string++;
+ }
+
+ return result;
+}
+
+