core: again allow calling AddAndActivateConnection() without a connection

When settings are NULL or empty in impl_manager_add_and_activate_connection(),
the connection is created and completed by nm_utils_complete_generic() or
nm_device_complete_connection().

Also, do not assert in nm_connection_is_type(). Returning FALSE there is
sufficient.

Related commit a878cd8145
This commit is contained in:
Jiří Klimeš 2013-11-01 13:59:57 +01:00
parent fc9eae55b3
commit 8ec031fb0e
2 changed files with 11 additions and 9 deletions

View file

@ -956,7 +956,8 @@ nm_connection_is_type (NMConnection *connection, const char *type)
g_return_val_if_fail (type != NULL, FALSE);
s_con = nm_connection_get_setting_connection (connection);
g_assert (s_con);
if (!s_con)
return FALSE;
type2 = nm_setting_connection_get_connection_type (s_con);

View file

@ -3299,15 +3299,16 @@ impl_manager_add_and_activate_connection (NMManager *self,
NMDevice *device = NULL;
gboolean vpn = FALSE;
if (!settings || !g_hash_table_size (settings)) {
error = g_error_new_literal (NM_MANAGER_ERROR, NM_MANAGER_ERROR_UNKNOWN_CONNECTION,
"Settings required to create a connection.");
goto error;
}
/* Try to create a new connection with the given settings */
/* Try to create a new connection with the given settings.
* We allow empty settings for AddAndActivateConnection(). In that case,
* the connection will be completed in nm_utils_complete_generic() or
* nm_device_complete_connection() below. Just make sure we don't expect
* specific data being in the connection till then (especially in
* validate_activation_request()).
*/
connection = nm_connection_new ();
nm_connection_replace_settings (connection, settings, NULL);
if (settings && g_hash_table_size (settings))
nm_connection_replace_settings (connection, settings, NULL);
subject = validate_activation_request (self,
context,