mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager
synced 2024-10-15 12:34:55 +00:00
libnm, libnm-glib: belatedly replace _nm_client_is_object_path()
_nm_client_is_object_path() had been copied from g_variant_is_object_path() with a note that it should be replaced when we depended on GLib > 2.24, but it got missed when we actually updated the dependency. Fix it now. (Also fix a nearby typo.)
This commit is contained in:
parent
50d45acecb
commit
7e791ce3fe
|
@ -1704,50 +1704,6 @@ nm_client_new_finish (GAsyncResult *result, GError **error)
|
|||
return g_object_ref (g_simple_async_result_get_op_res_gpointer (simple));
|
||||
}
|
||||
|
||||
/*
|
||||
* Validate D-Bus object path.
|
||||
* The function is copied and adjusted version of
|
||||
* g_variant_serialiser_is_object_path() from glib.
|
||||
* FIXME: The function can be replaced by g_variant_is_object_path()
|
||||
* when we start using GLib >= 2.24
|
||||
*/
|
||||
static gboolean
|
||||
_nm_client_is_object_path (const char *string)
|
||||
{
|
||||
gsize i;
|
||||
|
||||
if (!g_utf8_validate (string, -1, NULL))
|
||||
return FALSE;
|
||||
|
||||
/* The path must begin with an ASCII '/' (integer 47) character */
|
||||
if (string[0] != '/')
|
||||
return FALSE;
|
||||
|
||||
for (i = 1; string[i]; i++) {
|
||||
/* Each element must only contain the ASCII characters
|
||||
* "[A-Z][a-z][0-9]_"
|
||||
*/
|
||||
if (g_ascii_isalnum (string[i]) || string[i] == '_')
|
||||
;
|
||||
/* must consist of elements separated by slash characters. */
|
||||
else if (string[i] == '/') {
|
||||
/* No element may be the empty string. */
|
||||
/* Multiple '/' characters cannot occur in sequence. */
|
||||
if (string[i - 1] == '/')
|
||||
return FALSE;
|
||||
} else
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* A trailing '/' character is not allowed unless the path is the
|
||||
* root path (a single '/' character).
|
||||
*/
|
||||
if (i > 1 && string[i - 1] == '/')
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/*
|
||||
* constructor() shouldn't be overriden in most cases, rather constructed()
|
||||
* method is preferred and more useful.
|
||||
|
@ -1785,8 +1741,8 @@ constructor (GType type,
|
|||
if (dbus_path == NULL) {
|
||||
g_value_set_static_string (construct_params[i].value, NM_DBUS_PATH);
|
||||
} else {
|
||||
if (!_nm_client_is_object_path (dbus_path)) {
|
||||
g_warning ("Passsed D-Bus object path '%s' is invalid; using default '%s' instead",
|
||||
if (!g_variant_is_object_path (dbus_path)) {
|
||||
g_warning ("Passed D-Bus object path '%s' is invalid; using default '%s' instead",
|
||||
dbus_path, NM_DBUS_PATH);
|
||||
g_value_set_static_string (construct_params[i].value, NM_DBUS_PATH);
|
||||
}
|
||||
|
|
|
@ -1669,50 +1669,6 @@ nm_client_new_finish (GAsyncResult *result, GError **error)
|
|||
return g_object_ref (g_simple_async_result_get_op_res_gpointer (simple));
|
||||
}
|
||||
|
||||
/*
|
||||
* Validate D-Bus object path.
|
||||
* The function is copied and adjusted version of
|
||||
* g_variant_serialiser_is_object_path() from glib.
|
||||
* FIXME: The function can be replaced by g_variant_is_object_path()
|
||||
* when we start using GLib >= 2.24
|
||||
*/
|
||||
static gboolean
|
||||
_nm_client_is_object_path (const char *string)
|
||||
{
|
||||
gsize i;
|
||||
|
||||
if (!g_utf8_validate (string, -1, NULL))
|
||||
return FALSE;
|
||||
|
||||
/* The path must begin with an ASCII '/' (integer 47) character */
|
||||
if (string[0] != '/')
|
||||
return FALSE;
|
||||
|
||||
for (i = 1; string[i]; i++) {
|
||||
/* Each element must only contain the ASCII characters
|
||||
* "[A-Z][a-z][0-9]_"
|
||||
*/
|
||||
if (g_ascii_isalnum (string[i]) || string[i] == '_')
|
||||
;
|
||||
/* must consist of elements separated by slash characters. */
|
||||
else if (string[i] == '/') {
|
||||
/* No element may be the empty string. */
|
||||
/* Multiple '/' characters cannot occur in sequence. */
|
||||
if (string[i - 1] == '/')
|
||||
return FALSE;
|
||||
} else
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* A trailing '/' character is not allowed unless the path is the
|
||||
* root path (a single '/' character).
|
||||
*/
|
||||
if (i > 1 && string[i - 1] == '/')
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/*
|
||||
* constructor() shouldn't be overriden in most cases, rather constructed()
|
||||
* method is preferred and more useful.
|
||||
|
@ -1749,8 +1705,8 @@ constructor (GType type,
|
|||
if (dbus_path == NULL) {
|
||||
g_value_set_static_string (construct_params[i].value, NM_DBUS_PATH);
|
||||
} else {
|
||||
if (!_nm_client_is_object_path (dbus_path)) {
|
||||
g_warning ("Passsed D-Bus object path '%s' is invalid; using default '%s' instead",
|
||||
if (!g_variant_is_object_path (dbus_path)) {
|
||||
g_warning ("Passed D-Bus object path '%s' is invalid; using default '%s' instead",
|
||||
dbus_path, NM_DBUS_PATH);
|
||||
g_value_set_static_string (construct_params[i].value, NM_DBUS_PATH);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue