diff options
| author | Sebastien Bacher <seb128@ubuntu.com> | 2021-01-11 18:07:03 +0100 |
|---|---|---|
| committer | Sebastien Bacher <seb128@ubuntu.com> | 2021-01-11 18:15:57 +0100 |
| commit | 2567f558da3eb9911678227d4aeb15162e707d89 (patch) | |
| tree | 13c80b0e091c8ba585b14b966cda998f95f1936d /libnm-core/nm-setting-match.c | |
| parent | 02d99ffd62ede29cffcb45fcbe33d044b7406d3a (diff) | |
| parent | f54032b30e1ddd84f10a339e0caf493772e049a7 (diff) | |
Merge branch 'debian/master' into ubuntu/master
Diffstat (limited to 'libnm-core/nm-setting-match.c')
| -rw-r--r-- | libnm-core/nm-setting-match.c | 841 |
1 files changed, 406 insertions, 435 deletions
diff --git a/libnm-core/nm-setting-match.c b/libnm-core/nm-setting-match.c index 940cc68d..5709a403 100644 --- a/libnm-core/nm-setting-match.c +++ b/libnm-core/nm-setting-match.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: LGPL-2.1+ +/* SPDX-License-Identifier: LGPL-2.1+ */ /* * Copyright (C) 2018 Red Hat, Inc. */ @@ -18,12 +18,11 @@ /*****************************************************************************/ -NM_GOBJECT_PROPERTIES_DEFINE (NMSettingMatch, - PROP_INTERFACE_NAME, - PROP_KERNEL_COMMAND_LINE, - PROP_DRIVER, - PROP_PATH, -); +NM_GOBJECT_PROPERTIES_DEFINE(NMSettingMatch, + PROP_INTERFACE_NAME, + PROP_KERNEL_COMMAND_LINE, + PROP_DRIVER, + PROP_PATH, ); /** * NMSettingMatch: @@ -33,18 +32,18 @@ NM_GOBJECT_PROPERTIES_DEFINE (NMSettingMatch, * Since: 1.14 */ struct _NMSettingMatch { - NMSetting parent; - GArray *interface_name; - GArray *kernel_command_line; - GArray *driver; - GArray *path; + NMSetting parent; + GArray * interface_name; + GArray * kernel_command_line; + GArray * driver; + GArray * path; }; struct _NMSettingMatchClass { - NMSettingClass parent; + NMSettingClass parent; }; -G_DEFINE_TYPE (NMSettingMatch, nm_setting_match, NM_TYPE_SETTING) +G_DEFINE_TYPE(NMSettingMatch, nm_setting_match, NM_TYPE_SETTING) /*****************************************************************************/ @@ -57,11 +56,11 @@ G_DEFINE_TYPE (NMSettingMatch, nm_setting_match, NM_TYPE_SETTING) * Since: 1.14 **/ guint -nm_setting_match_get_num_interface_names (NMSettingMatch *setting) +nm_setting_match_get_num_interface_names(NMSettingMatch *setting) { - g_return_val_if_fail (NM_IS_SETTING_MATCH (setting), 0); + g_return_val_if_fail(NM_IS_SETTING_MATCH(setting), 0); - return nm_g_array_len (setting->interface_name); + return nm_g_array_len(setting->interface_name); } /** @@ -74,13 +73,14 @@ nm_setting_match_get_num_interface_names (NMSettingMatch *setting) * Since: 1.14 **/ const char * -nm_setting_match_get_interface_name (NMSettingMatch *setting, int idx) +nm_setting_match_get_interface_name(NMSettingMatch *setting, int idx) { - g_return_val_if_fail (NM_IS_SETTING_MATCH (setting), NULL); + g_return_val_if_fail(NM_IS_SETTING_MATCH(setting), NULL); - g_return_val_if_fail (setting->interface_name && idx >= 0 && idx < setting->interface_name->len, NULL); + g_return_val_if_fail(setting->interface_name && idx >= 0 && idx < setting->interface_name->len, + NULL); - return g_array_index (setting->interface_name, const char *, idx); + return g_array_index(setting->interface_name, const char *, idx); } /** @@ -93,15 +93,14 @@ nm_setting_match_get_interface_name (NMSettingMatch *setting, int idx) * Since: 1.14 **/ void -nm_setting_match_add_interface_name (NMSettingMatch *setting, - const char *interface_name) +nm_setting_match_add_interface_name(NMSettingMatch *setting, const char *interface_name) { - g_return_if_fail (NM_IS_SETTING_MATCH (setting)); - g_return_if_fail (interface_name != NULL); - g_return_if_fail (interface_name[0] != '\0'); + g_return_if_fail(NM_IS_SETTING_MATCH(setting)); + g_return_if_fail(interface_name != NULL); + g_return_if_fail(interface_name[0] != '\0'); - nm_strvarray_add (nm_strvarray_ensure (&setting->interface_name), interface_name); - _notify (setting, PROP_INTERFACE_NAME); + nm_strvarray_add(nm_strvarray_ensure(&setting->interface_name), interface_name); + _notify(setting, PROP_INTERFACE_NAME); } /** @@ -114,14 +113,14 @@ nm_setting_match_add_interface_name (NMSettingMatch *setting, * Since: 1.14 **/ void -nm_setting_match_remove_interface_name (NMSettingMatch *setting, int idx) +nm_setting_match_remove_interface_name(NMSettingMatch *setting, int idx) { - g_return_if_fail (NM_IS_SETTING_MATCH (setting)); + g_return_if_fail(NM_IS_SETTING_MATCH(setting)); - g_return_if_fail (setting->interface_name && idx >= 0 && idx < setting->interface_name->len); + g_return_if_fail(setting->interface_name && idx >= 0 && idx < setting->interface_name->len); - g_array_remove_index (setting->interface_name, idx); - _notify (setting, PROP_INTERFACE_NAME); + g_array_remove_index(setting->interface_name, idx); + _notify(setting, PROP_INTERFACE_NAME); } /** @@ -136,26 +135,18 @@ nm_setting_match_remove_interface_name (NMSettingMatch *setting, int idx) * Since: 1.14 **/ gboolean -nm_setting_match_remove_interface_name_by_value (NMSettingMatch *setting, - const char *interface_name) +nm_setting_match_remove_interface_name_by_value(NMSettingMatch *setting, const char *interface_name) { - guint i; + g_return_val_if_fail(NM_IS_SETTING_MATCH(setting), FALSE); + g_return_val_if_fail(interface_name != NULL, FALSE); + g_return_val_if_fail(interface_name[0] != '\0', FALSE); - g_return_val_if_fail (NM_IS_SETTING_MATCH (setting), FALSE); - g_return_val_if_fail (interface_name != NULL, FALSE); - g_return_val_if_fail (interface_name[0] != '\0', FALSE); + if (nm_strvarray_remove_first(setting->interface_name, interface_name)) { + _notify(setting, PROP_INTERFACE_NAME); + return TRUE; + } - if (!setting->interface_name) - return FALSE; - - for (i = 0; i < setting->interface_name->len; i++) { - if (nm_streq (interface_name, g_array_index (setting->interface_name, const char *, i))) { - g_array_remove_index (setting->interface_name, i); - _notify (setting, PROP_INTERFACE_NAME); - return TRUE; - } - } - return FALSE; + return FALSE; } /** @@ -167,14 +158,14 @@ nm_setting_match_remove_interface_name_by_value (NMSettingMatch *setting, * Since: 1.14 **/ void -nm_setting_match_clear_interface_names (NMSettingMatch *setting) +nm_setting_match_clear_interface_names(NMSettingMatch *setting) { - g_return_if_fail (NM_IS_SETTING_MATCH (setting)); + g_return_if_fail(NM_IS_SETTING_MATCH(setting)); - if (nm_g_array_len (setting->interface_name) != 0) { - nm_clear_pointer (&setting->interface_name, g_array_unref); - _notify (setting, PROP_INTERFACE_NAME); - } + if (nm_g_array_len(setting->interface_name) != 0) { + nm_clear_pointer(&setting->interface_name, g_array_unref); + _notify(setting, PROP_INTERFACE_NAME); + } } /** @@ -192,11 +183,11 @@ nm_setting_match_clear_interface_names (NMSettingMatch *setting) * Since: 1.14 **/ const char *const * -nm_setting_match_get_interface_names (NMSettingMatch *setting, guint *length) +nm_setting_match_get_interface_names(NMSettingMatch *setting, guint *length) { - g_return_val_if_fail (NM_IS_SETTING_MATCH (setting), NULL); + g_return_val_if_fail(NM_IS_SETTING_MATCH(setting), NULL); - return nm_strvarray_get_strv (&setting->interface_name, length); + return nm_strvarray_get_strv(&setting->interface_name, length); } /*****************************************************************************/ @@ -210,11 +201,11 @@ nm_setting_match_get_interface_names (NMSettingMatch *setting, guint *length) * Since: 1.26 **/ guint -nm_setting_match_get_num_kernel_command_lines (NMSettingMatch *setting) +nm_setting_match_get_num_kernel_command_lines(NMSettingMatch *setting) { - g_return_val_if_fail (NM_IS_SETTING_MATCH (setting), 0); + g_return_val_if_fail(NM_IS_SETTING_MATCH(setting), 0); - return nm_g_array_len (setting->kernel_command_line); + return nm_g_array_len(setting->kernel_command_line); } /** @@ -227,13 +218,14 @@ nm_setting_match_get_num_kernel_command_lines (NMSettingMatch *setting) * Since: 1.26 **/ const char * -nm_setting_match_get_kernel_command_line (NMSettingMatch *setting, guint idx) +nm_setting_match_get_kernel_command_line(NMSettingMatch *setting, guint idx) { - g_return_val_if_fail (NM_IS_SETTING_MATCH (setting), NULL); + g_return_val_if_fail(NM_IS_SETTING_MATCH(setting), NULL); - g_return_val_if_fail (setting->kernel_command_line && idx < setting->kernel_command_line->len, NULL); + g_return_val_if_fail(setting->kernel_command_line && idx < setting->kernel_command_line->len, + NULL); - return g_array_index (setting->kernel_command_line, const char *, idx); + return g_array_index(setting->kernel_command_line, const char *, idx); } /** @@ -246,15 +238,14 @@ nm_setting_match_get_kernel_command_line (NMSettingMatch *setting, guint idx) * Since: 1.26 **/ void -nm_setting_match_add_kernel_command_line (NMSettingMatch *setting, - const char *kernel_command_line) +nm_setting_match_add_kernel_command_line(NMSettingMatch *setting, const char *kernel_command_line) { - g_return_if_fail (NM_IS_SETTING_MATCH (setting)); - g_return_if_fail (kernel_command_line != NULL); - g_return_if_fail (kernel_command_line[0] != '\0'); + g_return_if_fail(NM_IS_SETTING_MATCH(setting)); + g_return_if_fail(kernel_command_line != NULL); + g_return_if_fail(kernel_command_line[0] != '\0'); - nm_strvarray_add (nm_strvarray_ensure (&setting->kernel_command_line), kernel_command_line); - _notify (setting, PROP_KERNEL_COMMAND_LINE); + nm_strvarray_add(nm_strvarray_ensure(&setting->kernel_command_line), kernel_command_line); + _notify(setting, PROP_KERNEL_COMMAND_LINE); } /** @@ -267,14 +258,14 @@ nm_setting_match_add_kernel_command_line (NMSettingMatch *setting, * Since: 1.26 **/ void -nm_setting_match_remove_kernel_command_line (NMSettingMatch *setting, guint idx) +nm_setting_match_remove_kernel_command_line(NMSettingMatch *setting, guint idx) { - g_return_if_fail (NM_IS_SETTING_MATCH (setting)); + g_return_if_fail(NM_IS_SETTING_MATCH(setting)); - g_return_if_fail (setting->kernel_command_line && idx < setting->kernel_command_line->len); + g_return_if_fail(setting->kernel_command_line && idx < setting->kernel_command_line->len); - g_array_remove_index (setting->kernel_command_line, idx); - _notify (setting, PROP_KERNEL_COMMAND_LINE); + g_array_remove_index(setting->kernel_command_line, idx); + _notify(setting, PROP_KERNEL_COMMAND_LINE); } /** @@ -289,26 +280,19 @@ nm_setting_match_remove_kernel_command_line (NMSettingMatch *setting, guint idx) * Since: 1.26 **/ gboolean -nm_setting_match_remove_kernel_command_line_by_value (NMSettingMatch *setting, - const char *kernel_command_line) +nm_setting_match_remove_kernel_command_line_by_value(NMSettingMatch *setting, + const char * kernel_command_line) { - guint i; - - g_return_val_if_fail (NM_IS_SETTING_MATCH (setting), FALSE); - g_return_val_if_fail (kernel_command_line != NULL, FALSE); - g_return_val_if_fail (kernel_command_line[0] != '\0', FALSE); + g_return_val_if_fail(NM_IS_SETTING_MATCH(setting), FALSE); + g_return_val_if_fail(kernel_command_line != NULL, FALSE); + g_return_val_if_fail(kernel_command_line[0] != '\0', FALSE); - if (!setting->kernel_command_line) - return FALSE; + if (nm_strvarray_remove_first(setting->kernel_command_line, kernel_command_line)) { + _notify(setting, PROP_KERNEL_COMMAND_LINE); + return TRUE; + } - for (i = 0; i < setting->kernel_command_line->len; i++) { - if (nm_streq (kernel_command_line, g_array_index (setting->kernel_command_line, const char *, i))) { - g_array_remove_index (setting->kernel_command_line, i); - _notify (setting, PROP_KERNEL_COMMAND_LINE); - return TRUE; - } - } - return FALSE; + return FALSE; } /** @@ -320,14 +304,14 @@ nm_setting_match_remove_kernel_command_line_by_value (NMSettingMatch *setting, * Since: 1.26 **/ void -nm_setting_match_clear_kernel_command_lines (NMSettingMatch *setting) +nm_setting_match_clear_kernel_command_lines(NMSettingMatch *setting) { - g_return_if_fail (NM_IS_SETTING_MATCH (setting)); + g_return_if_fail(NM_IS_SETTING_MATCH(setting)); - if (nm_g_array_len (setting->kernel_command_line) != 0) { - nm_clear_pointer (&setting->kernel_command_line, g_array_unref); - _notify (setting, PROP_KERNEL_COMMAND_LINE); - } + if (nm_g_array_len(setting->kernel_command_line) != 0) { + nm_clear_pointer(&setting->kernel_command_line, g_array_unref); + _notify(setting, PROP_KERNEL_COMMAND_LINE); + } } /** @@ -342,11 +326,11 @@ nm_setting_match_clear_kernel_command_lines (NMSettingMatch *setting) * Since: 1.26 **/ const char *const * -nm_setting_match_get_kernel_command_lines (NMSettingMatch *setting, guint *length) +nm_setting_match_get_kernel_command_lines(NMSettingMatch *setting, guint *length) { - g_return_val_if_fail (NM_IS_SETTING_MATCH (setting), NULL); + g_return_val_if_fail(NM_IS_SETTING_MATCH(setting), NULL); - return nm_strvarray_get_strv (&setting->kernel_command_line, length); + return nm_strvarray_get_strv(&setting->kernel_command_line, length); } /*****************************************************************************/ @@ -360,11 +344,11 @@ nm_setting_match_get_kernel_command_lines (NMSettingMatch *setting, guint *lengt * Since: 1.26 **/ guint -nm_setting_match_get_num_drivers (NMSettingMatch *setting) +nm_setting_match_get_num_drivers(NMSettingMatch *setting) { - g_return_val_if_fail (NM_IS_SETTING_MATCH (setting), 0); + g_return_val_if_fail(NM_IS_SETTING_MATCH(setting), 0); - return nm_g_array_len (setting->driver); + return nm_g_array_len(setting->driver); } /** @@ -377,13 +361,13 @@ nm_setting_match_get_num_drivers (NMSettingMatch *setting) * Since: 1.26 **/ const char * -nm_setting_match_get_driver (NMSettingMatch *setting, guint idx) +nm_setting_match_get_driver(NMSettingMatch *setting, guint idx) { - g_return_val_if_fail (NM_IS_SETTING_MATCH (setting), NULL); + g_return_val_if_fail(NM_IS_SETTING_MATCH(setting), NULL); - g_return_val_if_fail (setting->driver && idx < setting->driver->len, NULL); + g_return_val_if_fail(setting->driver && idx < setting->driver->len, NULL); - return g_array_index (setting->driver, const char *, idx); + return g_array_index(setting->driver, const char *, idx); } /** @@ -396,15 +380,14 @@ nm_setting_match_get_driver (NMSettingMatch *setting, guint idx) * Since: 1.26 **/ void -nm_setting_match_add_driver (NMSettingMatch *setting, - const char *driver) +nm_setting_match_add_driver(NMSettingMatch *setting, const char *driver) { - g_return_if_fail (NM_IS_SETTING_MATCH (setting)); - g_return_if_fail (driver != NULL); - g_return_if_fail (driver[0] != '\0'); + g_return_if_fail(NM_IS_SETTING_MATCH(setting)); + g_return_if_fail(driver != NULL); + g_return_if_fail(driver[0] != '\0'); - nm_strvarray_add (nm_strvarray_ensure (&setting->driver), driver); - _notify (setting, PROP_DRIVER); + nm_strvarray_add(nm_strvarray_ensure(&setting->driver), driver); + _notify(setting, PROP_DRIVER); } /** @@ -417,14 +400,14 @@ nm_setting_match_add_driver (NMSettingMatch *setting, * Since: 1.26 **/ void -nm_setting_match_remove_driver (NMSettingMatch *setting, guint idx) +nm_setting_match_remove_driver(NMSettingMatch *setting, guint idx) { - g_return_if_fail (NM_IS_SETTING_MATCH (setting)); + g_return_if_fail(NM_IS_SETTING_MATCH(setting)); - g_return_if_fail (setting->driver && idx < setting->driver->len); + g_return_if_fail(setting->driver && idx < setting->driver->len); - g_array_remove_index (setting->driver, idx); - _notify (setting, PROP_DRIVER); + g_array_remove_index(setting->driver, idx); + _notify(setting, PROP_DRIVER); } /** @@ -439,26 +422,18 @@ nm_setting_match_remove_driver (NMSettingMatch *setting, guint idx) * Since: 1.26 **/ gboolean -nm_setting_match_remove_driver_by_value (NMSettingMatch *setting, - const char *driver) +nm_setting_match_remove_driver_by_value(NMSettingMatch *setting, const char *driver) { - guint i; - - g_return_val_if_fail (NM_IS_SETTING_MATCH (setting), FALSE); - g_return_val_if_fail (driver != NULL, FALSE); - g_return_val_if_fail (driver[0] != '\0', FALSE); + g_return_val_if_fail(NM_IS_SETTING_MATCH(setting), FALSE); + g_return_val_if_fail(driver != NULL, FALSE); + g_return_val_if_fail(driver[0] != '\0', FALSE); - if (!setting->driver) - return FALSE; + if (nm_strvarray_remove_first(setting->driver, driver)) { + _notify(setting, PROP_DRIVER); + return TRUE; + } - for (i = 0; i < setting->driver->len; i++) { - if (nm_streq (driver, g_array_index (setting->driver, const char *, i))) { - g_array_remove_index (setting->driver, i); - _notify (setting, PROP_DRIVER); - return TRUE; - } - } - return FALSE; + return FALSE; } /** @@ -470,14 +445,14 @@ nm_setting_match_remove_driver_by_value (NMSettingMatch *setting, * Since: 1.26 **/ void -nm_setting_match_clear_drivers (NMSettingMatch *setting) +nm_setting_match_clear_drivers(NMSettingMatch *setting) { - g_return_if_fail (NM_IS_SETTING_MATCH (setting)); + g_return_if_fail(NM_IS_SETTING_MATCH(setting)); - if (nm_g_array_len (setting->driver) != 0) { - nm_clear_pointer (&setting->driver, g_array_unref); - _notify (setting, PROP_DRIVER); - } + if (nm_g_array_len(setting->driver) != 0) { + nm_clear_pointer(&setting->driver, g_array_unref); + _notify(setting, PROP_DRIVER); + } } /** @@ -492,11 +467,11 @@ nm_setting_match_clear_drivers (NMSettingMatch *setting) * Since: 1.26 **/ const char *const * -nm_setting_match_get_drivers (NMSettingMatch *setting, guint *length) +nm_setting_match_get_drivers(NMSettingMatch *setting, guint *length) { - g_return_val_if_fail (NM_IS_SETTING_MATCH (setting), NULL); + g_return_val_if_fail(NM_IS_SETTING_MATCH(setting), NULL); - return nm_strvarray_get_strv (&setting->driver, length); + return nm_strvarray_get_strv(&setting->driver, length); } /*****************************************************************************/ @@ -510,11 +485,11 @@ nm_setting_match_get_drivers (NMSettingMatch *setting, guint *length) * Since: 1.26 **/ guint -nm_setting_match_get_num_paths (NMSettingMatch *setting) +nm_setting_match_get_num_paths(NMSettingMatch *setting) { - g_return_val_if_fail (NM_IS_SETTING_MATCH (setting), 0); + g_return_val_if_fail(NM_IS_SETTING_MATCH(setting), 0); - return nm_g_array_len (setting->path); + return nm_g_array_len(setting->path); } /** @@ -527,13 +502,13 @@ nm_setting_match_get_num_paths (NMSettingMatch *setting) * Since: 1.26 **/ const char * -nm_setting_match_get_path (NMSettingMatch *setting, guint idx) +nm_setting_match_get_path(NMSettingMatch *setting, guint idx) { - g_return_val_if_fail (NM_IS_SETTING_MATCH (setting), NULL); + g_return_val_if_fail(NM_IS_SETTING_MATCH(setting), NULL); - g_return_val_if_fail (setting->path && idx < setting->path->len, NULL); + g_return_val_if_fail(setting->path && idx < setting->path->len, NULL); - return g_array_index (setting->path, const char *, idx); + return g_array_index(setting->path, const char *, idx); } /** @@ -546,15 +521,14 @@ nm_setting_match_get_path (NMSettingMatch *setting, guint idx) * Since: 1.26 **/ void -nm_setting_match_add_path (NMSettingMatch *setting, - const char *path) +nm_setting_match_add_path(NMSettingMatch *setting, const char *path) { - g_return_if_fail (NM_IS_SETTING_MATCH (setting)); - g_return_if_fail (path != NULL); - g_return_if_fail (path[0] != '\0'); + g_return_if_fail(NM_IS_SETTING_MATCH(setting)); + g_return_if_fail(path != NULL); + g_return_if_fail(path[0] != '\0'); - nm_strvarray_add (nm_strvarray_ensure (&setting->path), path); - _notify (setting, PROP_PATH); + nm_strvarray_add(nm_strvarray_ensure(&setting->path), path); + _notify(setting, PROP_PATH); } /** @@ -567,14 +541,14 @@ nm_setting_match_add_path (NMSettingMatch *setting, * Since: 1.26 **/ void -nm_setting_match_remove_path (NMSettingMatch *setting, guint idx) +nm_setting_match_remove_path(NMSettingMatch *setting, guint idx) { - g_return_if_fail (NM_IS_SETTING_MATCH (setting)); + g_return_if_fail(NM_IS_SETTING_MATCH(setting)); - g_return_if_fail (setting->path && idx < setting->path->len); + g_return_if_fail(setting->path && idx < setting->path->len); - g_array_remove_index (setting->path, idx); - _notify (setting, PROP_PATH); + g_array_remove_index(setting->path, idx); + _notify(setting, PROP_PATH); } /** @@ -589,26 +563,18 @@ nm_setting_match_remove_path (NMSettingMatch *setting, guint idx) * Since: 1.26 **/ gboolean -nm_setting_match_remove_path_by_value (NMSettingMatch *setting, - const char *path) +nm_setting_match_remove_path_by_value(NMSettingMatch *setting, const char *path) { - guint i; + g_return_val_if_fail(NM_IS_SETTING_MATCH(setting), FALSE); + g_return_val_if_fail(path != NULL, FALSE); + g_return_val_if_fail(path[0] != '\0', FALSE); - g_return_val_if_fail (NM_IS_SETTING_MATCH (setting), FALSE); - g_return_val_if_fail (path != NULL, FALSE); - g_return_val_if_fail (path[0] != '\0', FALSE); + if (nm_strvarray_remove_first(setting->path, path)) { + _notify(setting, PROP_PATH); + return TRUE; + } - if (!setting->path) - return FALSE; - - for (i = 0; i < setting->path->len; i++) { - if (nm_streq (path, g_array_index (setting->path, const char *, i))) { - g_array_remove_index (setting->path, i); - _notify (setting, PROP_PATH); - return TRUE; - } - } - return FALSE; + return FALSE; } /** @@ -620,14 +586,14 @@ nm_setting_match_remove_path_by_value (NMSettingMatch *setting, * Since: 1.26 **/ void -nm_setting_match_clear_paths (NMSettingMatch *setting) +nm_setting_match_clear_paths(NMSettingMatch *setting) { - g_return_if_fail (NM_IS_SETTING_MATCH (setting)); + g_return_if_fail(NM_IS_SETTING_MATCH(setting)); - if (nm_g_array_len (setting->path) != 0) { - nm_clear_pointer (&setting->path, g_array_unref); - _notify (setting, PROP_PATH); - } + if (nm_g_array_len(setting->path) != 0) { + nm_clear_pointer(&setting->path, g_array_unref); + _notify(setting, PROP_PATH); + } } /** @@ -642,71 +608,68 @@ nm_setting_match_clear_paths (NMSettingMatch *setting) * Since: 1.26 **/ const char *const * -nm_setting_match_get_paths (NMSettingMatch *setting, guint *length) +nm_setting_match_get_paths(NMSettingMatch *setting, guint *length) { - g_return_val_if_fail (NM_IS_SETTING_MATCH (setting), NULL); + g_return_val_if_fail(NM_IS_SETTING_MATCH(setting), NULL); - return nm_strvarray_get_strv (&setting->path, length); + return nm_strvarray_get_strv(&setting->path, length); } /*****************************************************************************/ static void -get_property (GObject *object, guint prop_id, - GValue *value, GParamSpec *pspec) -{ - NMSettingMatch *self = NM_SETTING_MATCH (object); - - switch (prop_id) { - case PROP_INTERFACE_NAME: - g_value_set_boxed (value, nm_strvarray_get_strv_non_empty (self->interface_name, NULL)); - break; - case PROP_KERNEL_COMMAND_LINE: - g_value_set_boxed (value, nm_strvarray_get_strv_non_empty (self->kernel_command_line, NULL)); - break; - case PROP_DRIVER: - g_value_set_boxed (value, nm_strvarray_get_strv_non_empty (self->driver, NULL)); - break; - case PROP_PATH: - g_value_set_boxed (value, nm_strvarray_get_strv_non_empty (self->path, NULL)); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } +get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) +{ + NMSettingMatch *self = NM_SETTING_MATCH(object); + + switch (prop_id) { + case PROP_INTERFACE_NAME: + g_value_set_boxed(value, nm_strvarray_get_strv_non_empty(self->interface_name, NULL)); + break; + case PROP_KERNEL_COMMAND_LINE: + g_value_set_boxed(value, nm_strvarray_get_strv_non_empty(self->kernel_command_line, NULL)); + break; + case PROP_DRIVER: + g_value_set_boxed(value, nm_strvarray_get_strv_non_empty(self->driver, NULL)); + break; + case PROP_PATH: + g_value_set_boxed(value, nm_strvarray_get_strv_non_empty(self->path, NULL)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); + break; + } } static void -set_property (GObject *object, guint prop_id, - const GValue *value, GParamSpec *pspec) -{ - NMSettingMatch *self = NM_SETTING_MATCH (object); - - switch (prop_id) { - case PROP_INTERFACE_NAME: - nm_strvarray_set_strv (&self->interface_name, g_value_get_boxed (value)); - break; - case PROP_KERNEL_COMMAND_LINE: - nm_strvarray_set_strv (&self->kernel_command_line, g_value_get_boxed (value)); - break; - case PROP_DRIVER: - nm_strvarray_set_strv (&self->driver, g_value_get_boxed (value)); - break; - case PROP_PATH: - nm_strvarray_set_strv (&self->path, g_value_get_boxed (value)); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } +set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) +{ + NMSettingMatch *self = NM_SETTING_MATCH(object); + + switch (prop_id) { + case PROP_INTERFACE_NAME: + nm_strvarray_set_strv(&self->interface_name, g_value_get_boxed(value)); + break; + case PROP_KERNEL_COMMAND_LINE: + nm_strvarray_set_strv(&self->kernel_command_line, g_value_get_boxed(value)); + break; + case PROP_DRIVER: + nm_strvarray_set_strv(&self->driver, g_value_get_boxed(value)); + break; + case PROP_PATH: + nm_strvarray_set_strv(&self->path, g_value_get_boxed(value)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); + break; + } } /*****************************************************************************/ static void -nm_setting_match_init (NMSettingMatch *setting) -{ -} +nm_setting_match_init(NMSettingMatch *setting) +{} /** * nm_setting_match_new: @@ -718,211 +681,219 @@ nm_setting_match_init (NMSettingMatch *setting) * Since: 1.14 **/ NMSetting * -nm_setting_match_new (void) +nm_setting_match_new(void) { - return (NMSetting *) g_object_new (NM_TYPE_SETTING_MATCH, NULL); + return (NMSetting *) g_object_new(NM_TYPE_SETTING_MATCH, NULL); } static gboolean -verify (NMSetting *setting, NMConnection *connection, GError **error) -{ - NMSettingMatch *self = NM_SETTING_MATCH (setting); - guint i; - - if (self->interface_name) { - for (i = 0; i < self->interface_name->len; i++) { - if (nm_str_is_empty (g_array_index (self->interface_name, const char *, i))) { - g_set_error (error, - NM_CONNECTION_ERROR, - NM_CONNECTION_ERROR_INVALID_PROPERTY, - _("is empty")); - g_prefix_error (error, "%s.%s: ", NM_SETTING_MATCH_SETTING_NAME, - NM_SETTING_MATCH_INTERFACE_NAME); - return FALSE; - } - } - } - - if (self->kernel_command_line) { - for (i = 0; i < self->kernel_command_line->len; i++) { - if (nm_str_is_empty (g_array_index (self->kernel_command_line, const char *, i))) { - g_set_error (error, - NM_CONNECTION_ERROR, - NM_CONNECTION_ERROR_INVALID_PROPERTY, - _("is empty")); - g_prefix_error (error, "%s.%s: ", NM_SETTING_MATCH_SETTING_NAME, - NM_SETTING_MATCH_KERNEL_COMMAND_LINE); - return FALSE; - } - } - } - - if (self->driver) { - for (i = 0; i < self->driver->len; i++) { - if (nm_str_is_empty (g_array_index (self->driver, const char *, i))) { - g_set_error (error, - NM_CONNECTION_ERROR, - NM_CONNECTION_ERROR_INVALID_PROPERTY, - _("is empty")); - g_prefix_error (error, "%s.%s: ", NM_SETTING_MATCH_SETTING_NAME, - NM_SETTING_MATCH_DRIVER); - return FALSE; - } - } - } - - if (self->path) { - for (i = 0; i < self->path->len; i++) { - if (nm_str_is_empty (g_array_index (self->path, const char *, i))) { - g_set_error (error, - NM_CONNECTION_ERROR, - NM_CONNECTION_ERROR_INVALID_PROPERTY, - _("is empty")); - g_prefix_error (error, "%s.%s: ", NM_SETTING_MATCH_SETTING_NAME, - NM_SETTING_MATCH_PATH); - return FALSE; - } - } - } - - return TRUE; +verify(NMSetting *setting, NMConnection *connection, GError **error) +{ + NMSettingMatch *self = NM_SETTING_MATCH(setting); + guint i; + + if (self->interface_name) { + for (i = 0; i < self->interface_name->len; i++) { + if (nm_str_is_empty(g_array_index(self->interface_name, const char *, i))) { + g_set_error(error, + NM_CONNECTION_ERROR, + NM_CONNECTION_ERROR_INVALID_PROPERTY, + _("is empty")); + g_prefix_error(error, + "%s.%s: ", + NM_SETTING_MATCH_SETTING_NAME, + NM_SETTING_MATCH_INTERFACE_NAME); + return FALSE; + } + } + } + + if (self->kernel_command_line) { + for (i = 0; i < self->kernel_command_line->len; i++) { + if (nm_str_is_empty(g_array_index(self->kernel_command_line, const char *, i))) { + g_set_error(error, + NM_CONNECTION_ERROR, + NM_CONNECTION_ERROR_INVALID_PROPERTY, + _("is empty")); + g_prefix_error(error, + "%s.%s: ", + NM_SETTING_MATCH_SETTING_NAME, + NM_SETTING_MATCH_KERNEL_COMMAND_LINE); + return FALSE; + } + } + } + + if (self->driver) { + for (i = 0; i < self->driver->len; i++) { + if (nm_str_is_empty(g_array_index(self->driver, const char *, i))) { + g_set_error(error, + NM_CONNECTION_ERROR, + NM_CONNECTION_ERROR_INVALID_PROPERTY, + _("is empty")); + g_prefix_error(error, + "%s.%s: ", + NM_SETTING_MATCH_SETTING_NAME, + NM_SETTING_MATCH_DRIVER); + return FALSE; + } + } + } + + if (self->path) { + for (i = 0; i < self->path->len; i++) { + if (nm_str_is_empty(g_array_index(self->path, const char *, i))) { + g_set_error(error, + NM_CONNECTION_ERROR, + NM_CONNECTION_ERROR_INVALID_PROPERTY, + _("is empty")); + g_prefix_error(error, + "%s.%s: ", + NM_SETTING_MATCH_SETTING_NAME, + NM_SETTING_MATCH_PATH); + return FALSE; + } + } + } + + return TRUE; } static void -finalize (GObject *object) +finalize(GObject *object) { - NMSettingMatch *self = NM_SETTING_MATCH (object); + NMSettingMatch *self = NM_SETTING_MATCH(object); - nm_clear_pointer (&self->interface_name, g_array_unref); - nm_clear_pointer (&self->kernel_command_line, g_array_unref); - nm_clear_pointer (&self->driver, g_array_unref); - nm_clear_pointer (&self->path, g_array_unref); + nm_clear_pointer(&self->interface_name, g_array_unref); + nm_clear_pointer(&self->kernel_command_line, g_array_unref); + nm_clear_pointer(&self->driver, g_array_unref); + nm_clear_pointer(&self->path, g_array_unref); - G_OBJECT_CLASS (nm_setting_match_parent_class)->finalize (object); + G_OBJECT_CLASS(nm_setting_match_parent_class)->finalize(object); } static void -nm_setting_match_class_init (NMSettingMatchClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - NMSettingClass *setting_class = NM_SETTING_CLASS (klass); - - object_class->get_property = get_property; - object_class->set_property = set_property; - object_class->finalize = finalize; - - setting_class->verify = verify; - - /** - * NMSettingMatch:interface-name - * - * A list of interface names to match. Each element is a shell wildcard - * pattern. - * - * An element can be prefixed with a pipe symbol (|) or an ampersand (&). - * The former means that the element is optional and the latter means that - * it is mandatory. If there are any optional elements, than the match - * evaluates to true if at least one of the optional element matches - * (logical OR). If there are any mandatory elements, then they all - * must match (logical AND). By default, an element is optional. This means - * that an element "foo" behaves the same as "|foo". An element can also be inverted - * with exclamation mark (!) between the pipe symbol (or the ampersand) and before - * the pattern. Note that "!foo" is a shortcut for the mandatory match "&!foo". Finally, - * a backslash can be used at the beginning of the element (after the optional special characters) - * to escape the start of the pattern. For example, "&\\!a" is an mandatory match for literally "!a". - * - * Since: 1.14 - **/ - obj_properties[PROP_INTERFACE_NAME] = - g_param_spec_boxed (NM_SETTING_MATCH_INTERFACE_NAME, "", "", - G_TYPE_STRV, - NM_SETTING_PARAM_FUZZY_IGNORE | - G_PARAM_READWRITE | - G_PARAM_STATIC_STRINGS); - - /** - * NMSettingMatch:kernel-command-line - * - * A list of kernel command line arguments to match. This may be used to check - * whether a specific kernel command line option is set (or if prefixed with - * the exclamation mark unset). The argument must either be a single word, or - * an assignment (i.e. two words, separated "="). In the former case the kernel - * command line is searched for the word appearing as is, or as left hand side - * of an assignment. In the latter case, the exact assignment is looked for - * with right and left hand side matching. - * - * See NMSettingMatch:interface-name for how special characters '|', '&', - * '!' and '\\' are used for optional and mandatory matches and inverting the - * pattern. - * - * Since: 1.26 - **/ - obj_properties[PROP_KERNEL_COMMAND_LINE] = - g_param_spec_boxed (NM_SETTING_MATCH_KERNEL_COMMAND_LINE, "", "", - G_TYPE_STRV, - NM_SETTING_PARAM_FUZZY_IGNORE | - G_PARAM_READWRITE | - G_PARAM_STATIC_STRINGS); - - /** - * NMSettingMatch:driver - * - * A list of driver names to match. Each element is a shell wildcard pattern. - * - * See NMSettingMatch:interface-name for how special characters '|', '&', - * '!' and '\\' are used for optional and mandatory matches and inverting the - * pattern. - * - * Since: 1.26 - **/ - obj_properties[PROP_DRIVER] = - g_param_spec_boxed (NM_SETTING_MATCH_DRIVER, "", "", - G_TYPE_STRV, - NM_SETTING_PARAM_FUZZY_IGNORE | - G_PARAM_READWRITE | - G_PARAM_STATIC_STRINGS); - - /** - * NMSettingMatch:path - * - * A list of paths to match against the ID_PATH udev property of - * devices. ID_PATH represents the topological persistent path of a - * device. It typically contains a subsystem string (pci, usb, platform, - * etc.) and a subsystem-specific identifier. - * - * For PCI devices the path has the form - * "pci-$domain:$bus:$device.$function", where each variable is an - * hexadecimal value; for example "pci-0000:0a:00.0". - * - * The path of a device can be obtained with "udevadm info - * /sys/class/net/$dev | grep ID_PATH=" or by looking at the "path" - * property exported by NetworkManager ("nmcli -f general.path device - * show $dev"). - * - * Each element of the list is a shell wildcard pattern. - * - * See NMSettingMatch:interface-name for how special characters '|', '&', - * '!' and '\\' are used for optional and mandatory matches and inverting the - * pattern. - * - * Since: 1.26 - **/ - /* ---ifcfg-rh--- - * property: path - * variable: MATCH_PATH - * description: space-separated list of paths to match against the udev - * property ID_PATHS of devices - * example: MATCH_PATH="pci-0000:01:00.0 pci-0000:0c:00.0" - * ---end--- - */ - obj_properties[PROP_PATH] = - g_param_spec_boxed (NM_SETTING_MATCH_PATH, "", "", - G_TYPE_STRV, - NM_SETTING_PARAM_FUZZY_IGNORE | - G_PARAM_READWRITE | - G_PARAM_STATIC_STRINGS); - - g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties); - - _nm_setting_class_commit (setting_class, NM_META_SETTING_TYPE_MATCH); +nm_setting_match_class_init(NMSettingMatchClass *klass) +{ + GObjectClass * object_class = G_OBJECT_CLASS(klass); + NMSettingClass *setting_class = NM_SETTING_CLASS(klass); + + object_class->get_property = get_property; + object_class->set_property = set_property; + object_class->finalize = finalize; + + setting_class->verify = verify; + + /** + * NMSettingMatch:interface-name + * + * A list of interface names to match. Each element is a shell wildcard + * pattern. + * + * An element can be prefixed with a pipe symbol (|) or an ampersand (&). + * The former means that the element is optional and the latter means that + * it is mandatory. If there are any optional elements, than the match + * evaluates to true if at least one of the optional element matches + * (logical OR). If there are any mandatory elements, then they all + * must match (logical AND). By default, an element is optional. This means + * that an element "foo" behaves the same as "|foo". An element can also be inverted + * with exclamation mark (!) between the pipe symbol (or the ampersand) and before + * the pattern. Note that "!foo" is a shortcut for the mandatory match "&!foo". Finally, + * a backslash can be used at the beginning of the element (after the optional special characters) + * to escape the start of the pattern. For example, "&\\!a" is an mandatory match for literally "!a". + * + * Since: 1.14 + **/ + obj_properties[PROP_INTERFACE_NAME] = g_param_spec_boxed( + NM_SETTING_MATCH_INTERFACE_NAME, + "", + "", + G_TYPE_STRV, + NM_SETTING_PARAM_FUZZY_IGNORE | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + + /** + * NMSettingMatch:kernel-command-line + * + * A list of kernel command line arguments to match. This may be used to check + * whether a specific kernel command line option is set (or if prefixed with + * the exclamation mark unset). The argument must either be a single word, or + * an assignment (i.e. two words, separated "="). In the former case the kernel + * command line is searched for the word appearing as is, or as left hand side + * of an assignment. In the latter case, the exact assignment is looked for + * with right and left hand side matching. + * + * See NMSettingMatch:interface-name for how special characters '|', '&', + * '!' and '\\' are used for optional and mandatory matches and inverting the + * pattern. + * + * Since: 1.26 + **/ + obj_properties[PROP_KERNEL_COMMAND_LINE] = g_param_spec_boxed( + NM_SETTING_MATCH_KERNEL_COMMAND_LINE, + "", + "", + G_TYPE_STRV, + NM_SETTING_PARAM_FUZZY_IGNORE | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + + /** + * NMSettingMatch:driver + * + * A list of driver names to match. Each element is a shell wildcard pattern. + * + * See NMSettingMatch:interface-name for how special characters '|', '&', + * '!' and '\\' are used for optional and mandatory matches and inverting the + * pattern. + * + * Since: 1.26 + **/ + obj_properties[PROP_DRIVER] = g_param_spec_boxed( + NM_SETTING_MATCH_DRIVER, + "", + "", + G_TYPE_STRV, + NM_SETTING_PARAM_FUZZY_IGNORE | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + + /** + * NMSettingMatch:path + * + * A list of paths to match against the ID_PATH udev property of + * devices. ID_PATH represents the topological persistent path of a + * device. It typically contains a subsystem string (pci, usb, platform, + * etc.) and a subsystem-specific identifier. + * + * For PCI devices the path has the form + * "pci-$domain:$bus:$device.$function", where each variable is an + * hexadecimal value; for example "pci-0000:0a:00.0". + * + * The path of a device can be obtained with "udevadm info + * /sys/class/net/$dev | grep ID_PATH=" or by looking at the "path" + * property exported by NetworkManager ("nmcli -f general.path device + * show $dev"). + * + * Each element of the list is a shell wildcard pattern. + * + * See NMSettingMatch:interface-name for how special characters '|', '&', + * '!' and '\\' are used for optional and mandatory matches and inverting the + * pattern. + * + * Since: 1.26 + **/ + /* ---ifcfg-rh--- + * property: path + * variable: MATCH_PATH + * description: space-separated list of paths to match against the udev + * property ID_PATHS of devices + * example: MATCH_PATH="pci-0000:01:00.0 pci-0000:0c:00.0" + * ---end--- + */ + obj_properties[PROP_PATH] = g_param_spec_boxed(NM_SETTING_MATCH_PATH, + "", + "", + G_TYPE_STRV, + NM_SETTING_PARAM_FUZZY_IGNORE | G_PARAM_READWRITE + | G_PARAM_STATIC_STRINGS); + + g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); + + _nm_setting_class_commit(setting_class, NM_META_SETTING_TYPE_MATCH); } |