summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/NetworkManagerUtils.c62
-rw-r--r--src/NetworkManagerUtils.h3
2 files changed, 65 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;
+}
+
+
diff --git a/src/NetworkManagerUtils.h b/src/NetworkManagerUtils.h
index 958ca7a98..87c898771 100644
--- a/src/NetworkManagerUtils.h
+++ b/src/NetworkManagerUtils.h
@@ -429,5 +429,8 @@ void nm_utils_g_value_set_object_path_array (GValue *value,
GSList *objects,
NMUtilsObjectFunc filter_func,
gpointer user_data);
+guint nm_utils_parse_debug_string (const char *string,
+ const GDebugKey *keys,
+ guint nkeys);
#endif /* __NETWORKMANAGER_UTILS_H__ */