diff options
author | Lubomir Rintel <lkundrak@v3.sk> | 2017-05-22 20:11:40 +0200 |
---|---|---|
committer | Lubomir Rintel <lkundrak@v3.sk> | 2017-05-31 20:14:17 +0200 |
commit | 02e527f644799cfbc155b6773e16df9df9da6efd (patch) | |
tree | 37e2bb7f7f1c1e6bdde1e2139579e4a92693a101 | |
parent | 15daf29220ed4d9a5fddf6fe87fc9b790f996211 (diff) | |
download | NetworkManager-02e527f644799cfbc155b6773e16df9df9da6efd.tar.gz |
core/connections: pick base setting from settings the connection actually has
We will need multiple base settings for Bluetooth NAP servers: bluetooth and
bridge. We want to identify the device as "bluetooth" to the user, but leave
the Bridge factory handle it.
The "connection.type" is somewhat redundant -- let's keep it for what the user
sees. And identify the actual base setting to pick the right factory by the
actually present setting.
-rw-r--r-- | libnm-core/nm-connection.c | 37 | ||||
-rw-r--r-- | libnm-core/tests/test-general.c | 2 |
2 files changed, 17 insertions, 22 deletions
diff --git a/libnm-core/nm-connection.c b/libnm-core/nm-connection.c index ce0200ba54..f000d0c4d9 100644 --- a/libnm-core/nm-connection.c +++ b/libnm-core/nm-connection.c @@ -592,10 +592,12 @@ _nm_connection_find_base_type_setting (NMConnection *connection) continue; if (setting) { - /* FIXME: currently, if there is more than one matching base type, - * we cannot detect the base setting. - * See: https://bugzilla.gnome.org/show_bug.cgi?id=696936#c8 */ - return NULL; + NMSettingConnection *s_con = nm_connection_get_setting_connection (connection); + + if (!s_con) + return NULL; + return nm_connection_get_setting_by_name (connection, + nm_setting_connection_get_connection_type (s_con)); } setting = s_iter; } @@ -1609,19 +1611,16 @@ nm_connection_to_dbus (NMConnection *connection, gboolean nm_connection_is_type (NMConnection *connection, const char *type) { - NMSettingConnection *s_con; - const char *type2; + NMSetting *setting; g_return_val_if_fail (NM_IS_CONNECTION (connection), FALSE); g_return_val_if_fail (type != NULL, FALSE); - s_con = nm_connection_get_setting_connection (connection); - if (!s_con) + setting = nm_connection_get_setting_by_name (connection, type); + if (!setting) return FALSE; - type2 = nm_setting_connection_get_connection_type (s_con); - - return (g_strcmp0 (type2, type) == 0); + return _nm_setting_is_base_type (setting); } static int @@ -1850,22 +1849,19 @@ nm_connection_get_id (NMConnection *connection) * nm_connection_get_connection_type: * @connection: the #NMConnection * - * A shortcut to return the type from the connection's #NMSettingConnection. - * - * Returns: the type from the connection's 'connection' setting + * Returns: the connection's base type. **/ const char * nm_connection_get_connection_type (NMConnection *connection) { - NMSettingConnection *s_con; + NMSetting *setting; g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL); - s_con = nm_connection_get_setting_connection (connection); - if (!s_con) + setting = _nm_connection_find_base_type_setting (connection); + if (!setting) return NULL; - - return nm_setting_connection_get_connection_type (s_con); + return nm_setting_get_name (setting); } /** @@ -1880,9 +1876,8 @@ nm_connection_get_connection_type (NMConnection *connection) gboolean nm_connection_is_virtual (NMConnection *connection) { - const char *type; + const char *type = nm_connection_get_connection_type (connection); - type = nm_connection_get_connection_type (connection); g_return_val_if_fail (type != NULL, FALSE); if ( !strcmp (type, NM_SETTING_BOND_SETTING_NAME) diff --git a/libnm-core/tests/test-general.c b/libnm-core/tests/test-general.c index f80f013dc9..435088eb91 100644 --- a/libnm-core/tests/test-general.c +++ b/libnm-core/tests/test-general.c @@ -3558,7 +3558,7 @@ _test_connection_normalize_type_normalizable_type (const char *type, nm_connection_add_setting (con, s_base); } - g_assert (!nm_connection_get_connection_type (con)); + g_assert (!nm_setting_connection_get_connection_type (s_con)); g_assert (nm_connection_get_setting_by_name (con, type) == s_base); nmtst_assert_connection_verifies_after_normalization (con, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_MISSING_PROPERTY); |