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.
This commit is contained in:
@@ -3627,3 +3627,65 @@ nm_utils_g_value_set_strv (GValue *value, GPtrArray *strings)
|
|||||||
|
|
||||||
g_value_take_boxed (value, strv);
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -429,5 +429,8 @@ void nm_utils_g_value_set_object_path_array (GValue *value,
|
|||||||
GSList *objects,
|
GSList *objects,
|
||||||
NMUtilsObjectFunc filter_func,
|
NMUtilsObjectFunc filter_func,
|
||||||
gpointer user_data);
|
gpointer user_data);
|
||||||
|
guint nm_utils_parse_debug_string (const char *string,
|
||||||
|
const GDebugKey *keys,
|
||||||
|
guint nkeys);
|
||||||
|
|
||||||
#endif /* __NETWORKMANAGER_UTILS_H__ */
|
#endif /* __NETWORKMANAGER_UTILS_H__ */
|
||||||
|
Reference in New Issue
Block a user