libnm-core: make nm_setting_verify() take an NMConnection

nm_setting_verify() took a GSList of other NMSettings, but really it
would just be simpler all around to pass the NMConnection instead...

This means that several formerly NMSetting-branded functions that
operated on lists-of-settings now get replaced with
NMConnection-branded functions instead.
This commit is contained in:
Dan Winship 2014-10-21 22:30:31 -04:00
parent b108790833
commit 9e5c7d915b
33 changed files with 216 additions and 246 deletions

View file

@ -45,6 +45,7 @@ libnm_core_headers = \
libnm_core_private_headers = \
$(core)/crypto.h \
$(core)/nm-connection-private.h \
$(core)/nm-core-internal.h \
$(core)/nm-property-compare.h \
$(core)/nm-setting-private.h \

View file

@ -0,0 +1,35 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2014 Red Hat, Inc.
*/
#ifndef __NM_CONNECTION_PRIVATE_H__
#define __NM_CONNECTION_PRIVATE_H__
#include "nm-setting.h"
#include "nm-connection.h"
NMSetting *_nm_connection_find_base_type_setting (NMConnection *connection);
const char *_nm_connection_detect_slave_type (NMConnection *connection,
NMSetting **out_s_port);
gboolean _nm_connection_verify_required_interface_name (NMConnection *connection,
GError **error);
#endif /* __NM_CONNECTION_PRIVATE_H__ */

View file

@ -24,6 +24,7 @@
#include <glib/gi18n.h>
#include <string.h>
#include "nm-connection.h"
#include "nm-connection-private.h"
#include "nm-utils.h"
#include "nm-setting-private.h"
#include "nm-core-internal.h"
@ -500,13 +501,35 @@ nm_connection_diff (NMConnection *a,
return *out_settings ? FALSE : TRUE;
}
NMSetting *
_nm_connection_find_base_type_setting (NMConnection *connection)
{
NMConnectionPrivate *priv = NM_CONNECTION_GET_PRIVATE (connection);
GHashTableIter iter;
NMSetting *setting = NULL, *s_iter;
g_hash_table_iter_init (&iter, priv->settings);
while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &s_iter)) {
if (!_nm_setting_is_base_type (s_iter))
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;
}
setting = s_iter;
}
return setting;
}
static gboolean
_normalize_connection_type (NMConnection *self)
{
NMSettingConnection *s_con = nm_connection_get_setting_connection (self);
NMSetting *s_base = NULL;
const char *type;
GSList *all_settings;
type = nm_setting_connection_get_connection_type (s_con);
@ -521,26 +544,57 @@ _normalize_connection_type (NMConnection *self)
return TRUE;
}
} else {
all_settings = _nm_utils_hash_values_to_slist (NM_CONNECTION_GET_PRIVATE (self)->settings);
s_base = _nm_setting_find_in_list_base_type (all_settings);
s_base = _nm_connection_find_base_type_setting (self);
g_return_val_if_fail (s_base, FALSE);
type = nm_setting_get_name (s_base);
g_object_set (s_con, NM_SETTING_CONNECTION_TYPE, type, NULL);
g_slist_free (all_settings);
return TRUE;
}
return FALSE;
}
const char *
_nm_connection_detect_slave_type (NMConnection *connection, NMSetting **out_s_port)
{
NMConnectionPrivate *priv = NM_CONNECTION_GET_PRIVATE (connection);
GHashTableIter iter;
const char *slave_type = NULL;
NMSetting *s_port = NULL, *s_iter;
g_hash_table_iter_init (&iter, priv->settings);
while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &s_iter)) {
const char *name = nm_setting_get_name (s_iter);
const char *i_slave_type = NULL;
if (!strcmp (name, NM_SETTING_BRIDGE_PORT_SETTING_NAME))
i_slave_type = NM_SETTING_BRIDGE_SETTING_NAME;
else if (!strcmp (name, NM_SETTING_TEAM_PORT_SETTING_NAME))
i_slave_type = NM_SETTING_TEAM_SETTING_NAME;
else
continue;
if (slave_type) {
/* there are more then one matching port types, cannot detect the slave type. */
slave_type = NULL;
s_port = NULL;
break;
}
slave_type = i_slave_type;
s_port = s_iter;
}
if (out_s_port)
*out_s_port = s_port;
return slave_type;
}
static gboolean
_normalize_connection_slave_type (NMConnection *self)
{
NMSettingConnection *s_con = nm_connection_get_setting_connection (self);
const char *slave_type, *port_type;
GSList *all_settings;
if (!s_con)
return FALSE;
@ -563,14 +617,10 @@ _normalize_connection_slave_type (NMConnection *self)
}
}
} else {
all_settings = _nm_utils_hash_values_to_slist (NM_CONNECTION_GET_PRIVATE (self)->settings);
if ((slave_type = _nm_setting_slave_type_detect_from_settings (all_settings, NULL))) {
if ((slave_type = _nm_connection_detect_slave_type (self, NULL))) {
g_object_set (s_con, NM_SETTING_CONNECTION_SLAVE_TYPE, slave_type, NULL);
g_slist_free (all_settings);
return TRUE;
}
g_slist_free (all_settings);
}
return FALSE;
}
@ -721,8 +771,7 @@ _nm_connection_verify (NMConnection *connection, GError **error)
/* Order NMSettingConnection so that it will be verified first.
* The reason is, that errors in this setting might be more fundamental
* and should be checked and reported with higher priority.
* Another reason is, that some settings look especially at the
* NMSettingConnection, so they find it first in the all_settings list. */
*/
if (value == s_con)
all_settings = g_slist_append (all_settings, value);
else
@ -742,7 +791,7 @@ _nm_connection_verify (NMConnection *connection, GError **error)
* @NM_SETTING_VERIFY_NORMALIZABLE, so, if we encounter such an error type,
* we remember it instead (to return it as output).
**/
verify_result = _nm_setting_verify (NM_SETTING (setting_i->data), all_settings, &verify_error);
verify_result = _nm_setting_verify (NM_SETTING (setting_i->data), connection, &verify_error);
if (verify_result == NM_SETTING_VERIFY_NORMALIZABLE ||
verify_result == NM_SETTING_VERIFY_NORMALIZABLE_ERROR) {
if ( verify_result == NM_SETTING_VERIFY_NORMALIZABLE_ERROR
@ -1334,6 +1383,24 @@ nm_connection_get_interface_name (NMConnection *connection)
return s_con ? nm_setting_connection_get_interface_name (s_con) : NULL;
}
gboolean
_nm_connection_verify_required_interface_name (NMConnection *connection,
GError **error)
{
const char *interface_name;
interface_name = nm_connection_get_interface_name (connection);
if (interface_name)
return TRUE;
g_set_error_literal (error,
NM_CONNECTION_ERROR,
NM_CONNECTION_ERROR_MISSING_PROPERTY,
_("property is missing"));
g_prefix_error (error, "%s.%s: ", NM_SETTING_CONNECTION_SETTING_NAME, NM_SETTING_CONNECTION_INTERFACE_NAME);
return FALSE;
}
/**
* nm_connection_get_uuid:
* @connection: the #NMConnection

View file

@ -2601,7 +2601,7 @@ verify_cert (GBytes *bytes, const char *prop_name, GError **error)
}
static gboolean
verify (NMSetting *setting, GSList *all_settings, GError **error)
verify (NMSetting *setting, NMConnection *connection, GError **error)
{
NMSetting8021x *self = NM_SETTING_802_1X (setting);
NMSetting8021xPrivate *priv = NM_SETTING_802_1X_GET_PRIVATE (self);

View file

@ -177,7 +177,7 @@ nm_setting_adsl_get_vci (NMSettingAdsl *setting)
}
static gboolean
verify (NMSetting *setting, GSList *all_settings, GError **error)
verify (NMSetting *setting, NMConnection *connection, GError **error)
{
NMSettingAdslPrivate *priv = NM_SETTING_ADSL_GET_PRIVATE (setting);

View file

@ -107,7 +107,7 @@ nm_setting_bluetooth_get_bdaddr (NMSettingBluetooth *setting)
}
static gboolean
verify (NMSetting *setting, GSList *all_settings, GError **error)
verify (NMSetting *setting, NMConnection *connection, GError **error)
{
NMSettingBluetoothPrivate *priv = NM_SETTING_BLUETOOTH_GET_PRIVATE (setting);
@ -148,12 +148,12 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
}
/* Make sure the corresponding 'type' setting is present */
if ( all_settings
if ( connection
&& !strcmp (priv->type, NM_SETTING_BLUETOOTH_TYPE_DUN)) {
gboolean gsm = FALSE, cdma = FALSE;
gsm = !!nm_setting_find_in_list (all_settings, NM_SETTING_GSM_SETTING_NAME);
cdma = !!nm_setting_find_in_list (all_settings, NM_SETTING_CDMA_SETTING_NAME);
gsm = !!nm_connection_get_setting_gsm (connection);
cdma = !!nm_connection_get_setting_cdma (connection);
if (!gsm && !cdma) {
/* We can't return MISSING_SETTING here, because we don't know

View file

@ -29,7 +29,7 @@
#include "nm-setting-bond.h"
#include "nm-utils.h"
#include "nm-utils-private.h"
#include "nm-setting-private.h"
#include "nm-connection-private.h"
#include "nm-setting-infiniband.h"
/**
@ -432,7 +432,7 @@ nm_setting_bond_get_option_default (NMSettingBond *setting, const char *name)
}
static gboolean
verify (NMSetting *setting, GSList *all_settings, GError **error)
verify (NMSetting *setting, NMConnection *connection, GError **error)
{
NMSettingBondPrivate *priv = NM_SETTING_BOND_GET_PRIVATE (setting);
GHashTableIter iter;
@ -539,7 +539,7 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
}
}
if (nm_setting_find_in_list (all_settings, NM_SETTING_INFINIBAND_SETTING_NAME)) {
if (nm_connection_get_setting_infiniband (connection)) {
if (strcmp (value, "active-backup") != 0) {
g_set_error (error,
NM_CONNECTION_ERROR,
@ -642,7 +642,7 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
return FALSE;
}
return _nm_setting_verify_required_virtual_interface_name (all_settings, error);
return _nm_connection_verify_required_interface_name (connection, error);
}
static void

View file

@ -27,7 +27,7 @@
#include "nm-setting-bridge-port.h"
#include "nm-utils.h"
#include "nm-utils-private.h"
#include "nm-setting-private.h"
#include "nm-connection-private.h"
#include "nm-setting-connection.h"
#include "nm-setting-bridge.h"
@ -112,7 +112,7 @@ nm_setting_bridge_port_get_hairpin_mode (NMSettingBridgePort *setting)
#define BR_MAX_PATH_COST 65535
static gboolean
verify (NMSetting *setting, GSList *all_settings, GError **error)
verify (NMSetting *setting, NMConnection *connection, GError **error)
{
NMSettingBridgePortPrivate *priv = NM_SETTING_BRIDGE_PORT_GET_PRIVATE (setting);
@ -141,15 +141,19 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
}
if (all_settings) {
if (connection) {
NMSettingConnection *s_con;
const char *slave_type;
s_con = NM_SETTING_CONNECTION (_nm_setting_find_in_list_required (all_settings,
NM_SETTING_CONNECTION_SETTING_NAME,
error));
if (!s_con)
s_con = nm_connection_get_setting_connection (connection);
if (!s_con) {
g_set_error (error,
NM_CONNECTION_ERROR,
NM_CONNECTION_ERROR_MISSING_SETTING,
_("missing setting"));
g_prefix_error (error, "%s: ", NM_SETTING_CONNECTION_SETTING_NAME);
return FALSE;
}
slave_type = nm_setting_connection_get_slave_type (s_con);
if ( slave_type

View file

@ -25,7 +25,7 @@
#include <glib/gi18n.h>
#include "nm-setting-bridge.h"
#include "nm-setting-private.h"
#include "nm-connection-private.h"
#include "nm-utils.h"
#include "nm-utils-private.h"
@ -210,7 +210,7 @@ check_range (guint32 val,
}
static gboolean
verify (NMSetting *setting, GSList *all_settings, GError **error)
verify (NMSetting *setting, NMConnection *connection, GError **error)
{
NMSettingBridgePrivate *priv = NM_SETTING_BRIDGE_GET_PRIVATE (setting);
@ -251,7 +251,7 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
error))
return FALSE;
return _nm_setting_verify_required_virtual_interface_name (all_settings, error);
return _nm_connection_verify_required_interface_name (connection, error);
}
static void

View file

@ -129,7 +129,7 @@ nm_setting_cdma_get_password_flags (NMSettingCdma *setting)
}
static gboolean
verify (NMSetting *setting, GSList *all_settings, GError **error)
verify (NMSetting *setting, NMConnection *connection, GError **error)
{
NMSettingCdmaPrivate *priv = NM_SETTING_CDMA_GET_PRIVATE (setting);

View file

@ -26,7 +26,7 @@
#include "nm-utils.h"
#include "nm-utils-private.h"
#include "nm-setting-connection.h"
#include "nm-setting-private.h"
#include "nm-connection-private.h"
#include "nm-setting-bond.h"
#include "nm-setting-bridge.h"
#include "nm-setting-team.h"
@ -748,7 +748,7 @@ _set_error_missing_base_setting (GError **error, const char *type)
}
static gboolean
verify (NMSetting *setting, GSList *all_settings, GError **error)
verify (NMSetting *setting, NMConnection *connection, GError **error)
{
NMSettingConnectionPrivate *priv = NM_SETTING_CONNECTION_GET_PRIVATE (setting);
gboolean is_slave;
@ -805,7 +805,7 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
}
if (!priv->type) {
if (!(normerr_base_type = _nm_setting_find_in_list_base_type (all_settings))) {
if (!connection || !(normerr_base_type = _nm_connection_find_base_type_setting (connection))) {
g_set_error_literal (error,
NM_CONNECTION_ERROR,
NM_CONNECTION_ERROR_MISSING_PROPERTY,
@ -837,18 +837,18 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
}
/* Make sure the corresponding 'type' item is present */
if ( all_settings
&& !nm_setting_find_in_list (all_settings, priv->type)) {
if ( connection
&& !nm_connection_get_setting_by_name (connection, priv->type)) {
NMSetting *s_base;
GSList *all_settings2;
NMConnection *connection2;
s_base = g_object_new (base_type, NULL);
all_settings2 = g_slist_prepend (all_settings, s_base);
connection2 = nm_simple_connection_new_clone (connection);
nm_connection_add_setting (connection2, s_base);
normerr_base_setting = nm_setting_verify (s_base, all_settings2, NULL);
normerr_base_setting = nm_setting_verify (s_base, connection2, NULL);
g_slist_free_1 (all_settings2);
g_object_unref (s_base);
g_object_unref (connection2);
if (!normerr_base_setting) {
_set_error_missing_base_setting (error, priv->type);
@ -880,16 +880,16 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
return FALSE;
}
if ( slave_setting_type
&& all_settings /* only check for an existing slave-setting when having @all_settings */
&& !nm_setting_find_in_list (all_settings, slave_setting_type))
&& connection
&& !nm_connection_get_setting_by_name (connection, slave_setting_type))
normerr_slave_setting_type = slave_setting_type;
} else {
if (priv->master) {
const char *slave_type;
NMSetting *s_port;
if ( all_settings
&& (slave_type = _nm_setting_slave_type_detect_from_settings (all_settings, &s_port))) {
if ( connection
&& (slave_type = _nm_connection_detect_slave_type (connection, &s_port))) {
normerr_missing_slave_type = slave_type;
normerr_missing_slave_type_port = nm_setting_get_name (s_port);
} else {

View file

@ -619,7 +619,7 @@ check_priority (gint val,
}
static gboolean
verify (NMSetting *setting, GSList *all_settings, GError **error)
verify (NMSetting *setting, NMConnection *connection, GError **error)
{
NMSettingDcbPrivate *priv = NM_SETTING_DCB_GET_PRIVATE (setting);

View file

@ -213,7 +213,7 @@ nm_setting_gsm_get_home_only (NMSettingGsm *setting)
}
static gboolean
verify (NMSetting *setting, GSList *all_settings, GError **error)
verify (NMSetting *setting, NMConnection *connection, GError **error)
{
NMSettingGsmPrivate *priv = NM_SETTING_GSM_GET_PRIVATE (setting);

View file

@ -178,7 +178,7 @@ nm_setting_infiniband_get_virtual_interface_name (NMSettingInfiniband *setting)
}
static gboolean
verify (NMSetting *setting, GSList *all_settings, GError **error)
verify (NMSetting *setting, NMConnection *connection, GError **error)
{
NMSettingConnection *s_con;
NMSettingInfinibandPrivate *priv = NM_SETTING_INFINIBAND_GET_PRIVATE (setting);
@ -237,7 +237,7 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
}
}
s_con = NM_SETTING_CONNECTION (nm_setting_find_in_list (all_settings, NM_SETTING_CONNECTION_SETTING_NAME));
s_con = nm_connection_get_setting_connection (connection);
if (s_con) {
const char *interface_name = nm_setting_connection_get_interface_name (s_con);

View file

@ -868,7 +868,7 @@ verify_label (const char *label)
}
static gboolean
verify (NMSetting *setting, GSList *all_settings, GError **error)
verify (NMSetting *setting, NMConnection *connection, GError **error)
{
NMSettingIP4ConfigPrivate *priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
GSList *iter, *l_iter;

View file

@ -786,7 +786,7 @@ nm_setting_ip6_config_get_ip6_privacy (NMSettingIP6Config *setting)
}
static gboolean
verify (NMSetting *setting, GSList *all_settings, GError **error)
verify (NMSetting *setting, NMConnection *connection, GError **error)
{
NMSettingIP6ConfigPrivate *priv = NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting);
GSList *iter;

View file

@ -94,7 +94,7 @@ nm_setting_olpc_mesh_get_dhcp_anycast_address (NMSettingOlpcMesh *setting)
}
static gboolean
verify (NMSetting *setting, GSList *all_settings, GError **error)
verify (NMSetting *setting, NMConnection *connection, GError **error)
{
NMSettingOlpcMeshPrivate *priv = NM_SETTING_OLPC_MESH_GET_PRIVATE (setting);
gsize length;

View file

@ -352,7 +352,7 @@ nm_setting_ppp_get_lcp_echo_interval (NMSettingPpp *setting)
}
static gboolean
verify (NMSetting *setting, GSList *all_settings, GError **error)
verify (NMSetting *setting, NMConnection *connection, GError **error)
{
NMSettingPppPrivate *priv = NM_SETTING_PPP_GET_PRIVATE (setting);

View file

@ -130,7 +130,7 @@ nm_setting_pppoe_get_password_flags (NMSettingPppoe *setting)
}
static gboolean
verify (NMSetting *setting, GSList *all_settings, GError **error)
verify (NMSetting *setting, NMConnection *connection, GError **error)
{
NMSettingPppoePrivate *priv = NM_SETTING_PPPOE_GET_PRIVATE (setting);

View file

@ -91,26 +91,15 @@ gboolean _nm_setting_clear_secrets_with_flags (NMSetting *setting,
static void __attribute__((constructor)) register_setting (void) \
{ g_type_init (); g_type_ensure (x); }
NMSetting *nm_setting_find_in_list (GSList *settings_list, const char *setting_name);
NMSetting * _nm_setting_find_in_list_required (GSList *all_settings,
const char *setting_name,
GError **error);
NMSettingVerifyResult _nm_setting_verify_required_virtual_interface_name (GSList *all_settings,
GError **error);
GVariant *_nm_setting_get_deprecated_virtual_interface_name (NMSetting *setting,
NMConnection *connection,
const char *property);
NMSettingVerifyResult _nm_setting_verify (NMSetting *setting,
GSList *all_settings,
NMConnection *connection,
GError **error);
NMSetting *_nm_setting_find_in_list_base_type (GSList *all_settings);
gboolean _nm_setting_slave_type_is_valid (const char *slave_type, const char **out_port_type);
const char * _nm_setting_slave_type_detect_from_settings (GSList *all_settings, NMSetting **out_s_port);
GVariant *_nm_setting_to_dbus (NMSetting *setting,
NMConnection *connection,

View file

@ -146,7 +146,7 @@ nm_setting_serial_get_send_delay (NMSettingSerial *setting)
}
static gboolean
verify (NMSetting *setting, GSList *all_settings, GError **error)
verify (NMSetting *setting, NMConnection *connection, GError **error)
{
return TRUE;
}

View file

@ -26,7 +26,7 @@
#include "nm-setting-team-port.h"
#include "nm-utils.h"
#include "nm-utils-private.h"
#include "nm-setting-private.h"
#include "nm-connection-private.h"
#include "nm-setting-connection.h"
#include "nm-setting-team.h"
@ -82,17 +82,21 @@ nm_setting_team_port_get_config (NMSettingTeamPort *setting)
}
static gboolean
verify (NMSetting *setting, GSList *all_settings, GError **error)
verify (NMSetting *setting, NMConnection *connection, GError **error)
{
if (all_settings) {
if (connection) {
NMSettingConnection *s_con;
const char *slave_type;
s_con = NM_SETTING_CONNECTION (_nm_setting_find_in_list_required (all_settings,
NM_SETTING_CONNECTION_SETTING_NAME,
error));
if (!s_con)
s_con = nm_connection_get_setting_connection (connection);
if (!s_con) {
g_set_error (error,
NM_CONNECTION_ERROR,
NM_CONNECTION_ERROR_MISSING_SETTING,
_("missing setting"));
g_prefix_error (error, "%s: ", NM_SETTING_CONNECTION_SETTING_NAME);
return FALSE;
}
slave_type = nm_setting_connection_get_slave_type (s_con);
if ( slave_type

View file

@ -25,7 +25,7 @@
#include "nm-setting-team.h"
#include "nm-utils.h"
#include "nm-utils-private.h"
#include "nm-setting-private.h"
#include "nm-connection-private.h"
/**
* SECTION:nm-setting-team
@ -79,9 +79,9 @@ nm_setting_team_get_config (NMSettingTeam *setting)
}
static gboolean
verify (NMSetting *setting, GSList *all_settings, GError **error)
verify (NMSetting *setting, NMConnection *connection, GError **error)
{
return _nm_setting_verify_required_virtual_interface_name (all_settings, error);
return _nm_connection_verify_required_interface_name (connection, error);
}
static void

View file

@ -28,6 +28,7 @@
#include "nm-setting-connection.h"
#include "nm-setting-private.h"
#include "nm-setting-wired.h"
#include "nm-connection-private.h"
/**
* SECTION:nm-setting-vlan
@ -479,18 +480,18 @@ nm_setting_vlan_init (NMSettingVlan *setting)
}
static gboolean
verify (NMSetting *setting, GSList *all_settings, GError **error)
verify (NMSetting *setting, NMConnection *connection, GError **error)
{
NMSettingVlanPrivate *priv = NM_SETTING_VLAN_GET_PRIVATE (setting);
NMSettingConnection *s_con = NULL;
NMSettingWired *s_wired = NULL;
GSList *iter;
NMSettingConnection *s_con;
NMSettingWired *s_wired;
for (iter = all_settings; iter; iter = iter->next) {
if (NM_IS_SETTING_CONNECTION (iter->data))
s_con = iter->data;
else if (NM_IS_SETTING_WIRED (iter->data))
s_wired = iter->data;
if (connection) {
s_con = nm_connection_get_setting_connection (connection);
s_wired = nm_connection_get_setting_wired (connection);
} else {
s_con = NULL;
s_wired = NULL;
}
if (priv->parent) {
@ -529,7 +530,7 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
/* If parent is NULL, the parent must be specified via
* NMSettingWired:mac-address.
*/
if ( all_settings
if ( connection
&& (!s_wired || !nm_setting_wired_get_mac_address (s_wired))) {
g_set_error (error,
NM_CONNECTION_ERROR,

View file

@ -367,7 +367,7 @@ nm_setting_vpn_foreach_secret (NMSettingVpn *setting,
}
static gboolean
verify (NMSetting *setting, GSList *all_settings, GError **error)
verify (NMSetting *setting, NMConnection *connection, GError **error)
{
NMSettingVpnPrivate *priv = NM_SETTING_VPN_GET_PRIVATE (setting);

View file

@ -104,7 +104,7 @@ nm_setting_wimax_get_mac_address (NMSettingWimax *setting)
}
static gboolean
verify (NMSetting *setting, GSList *all_settings, GError **error)
verify (NMSetting *setting, NMConnection *connection, GError **error)
{
NMSettingWimaxPrivate *priv = NM_SETTING_WIMAX_GET_PRIVATE (setting);

View file

@ -555,7 +555,7 @@ nm_setting_wired_get_valid_s390_options (NMSettingWired *setting)
}
static gboolean
verify (NMSetting *setting, GSList *all_settings, GError **error)
verify (NMSetting *setting, NMConnection *connection, GError **error)
{
NMSettingWiredPrivate *priv = NM_SETTING_WIRED_GET_PRIVATE (setting);
const char *valid_ports[] = { "tp", "aui", "bnc", "mii", NULL };

View file

@ -844,7 +844,7 @@ no_secrets:
}
static gboolean
verify (NMSetting *setting, GSList *all_settings, GError **error)
verify (NMSetting *setting, NMConnection *connection, GError **error)
{
NMSettingWirelessSecurity *self = NM_SETTING_WIRELESS_SECURITY (setting);
NMSettingWirelessSecurityPrivate *priv = NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE (self);
@ -904,7 +904,7 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
if ( (strcmp (priv->key_mgmt, "ieee8021x") == 0)
|| (strcmp (priv->key_mgmt, "wpa-eap") == 0)) {
/* Need an 802.1x setting too */
if (!nm_setting_find_in_list (all_settings, NM_SETTING_802_1X_SETTING_NAME)) {
if (connection && !nm_connection_get_setting_802_1x (connection)) {
g_set_error (error,
NM_CONNECTION_ERROR,
NM_CONNECTION_ERROR_MISSING_SETTING,

View file

@ -676,7 +676,7 @@ nm_setting_wireless_get_seen_bssid (NMSettingWireless *setting,
}
static gboolean
verify (NMSetting *setting, GSList *all_settings, GError **error)
verify (NMSetting *setting, NMConnection *connection, GError **error)
{
NMSettingWirelessPrivate *priv = NM_SETTING_WIRELESS_GET_PRIVATE (setting);
const char *valid_modes[] = { NM_SETTING_WIRELESS_MODE_INFRA, NM_SETTING_WIRELESS_MODE_ADHOC, NM_SETTING_WIRELESS_MODE_AP, NULL };

View file

@ -283,64 +283,6 @@ _nm_setting_slave_type_is_valid (const char *slave_type, const char **out_port_t
return found;
}
NMSetting *
_nm_setting_find_in_list_base_type (GSList *all_settings)
{
GSList *iter;
NMSetting *setting = NULL;
for (iter = all_settings; iter; iter = iter->next) {
NMSetting *s_iter = NM_SETTING (iter->data);
if (!_nm_setting_is_base_type (s_iter))
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;
}
setting = s_iter;
}
return setting;
}
const char *
_nm_setting_slave_type_detect_from_settings (GSList *all_settings, NMSetting **out_s_port)
{
GSList *iter;
const char *slave_type = NULL;
NMSetting *s_port = NULL;
for (iter = all_settings; iter; iter = iter->next) {
NMSetting *s_iter = NM_SETTING (iter->data);
const char *name = nm_setting_get_name (s_iter);
const char *i_slave_type = NULL;
if (!strcmp (name, NM_SETTING_BRIDGE_PORT_SETTING_NAME))
i_slave_type = NM_SETTING_BRIDGE_SETTING_NAME;
else if (!strcmp (name, NM_SETTING_TEAM_PORT_SETTING_NAME))
i_slave_type = NM_SETTING_TEAM_SETTING_NAME;
else
continue;
if (slave_type) {
/* there are more then one matching port types, cannot detect the slave type. */
slave_type = NULL;
s_port = NULL;
break;
}
slave_type = i_slave_type;
s_port = s_iter;
}
if (out_s_port)
*out_s_port = s_port;
return slave_type;
}
/*************************************************************/
typedef struct {
@ -900,28 +842,6 @@ nm_setting_duplicate (NMSetting *setting)
return NM_SETTING (dup);
}
static gint
find_setting_by_name (gconstpointer a, gconstpointer b)
{
NMSetting *setting = NM_SETTING (a);
const char *str = (const char *) b;
return strcmp (nm_setting_get_name (setting), str);
}
NMSetting *
nm_setting_find_in_list (GSList *settings_list,
const char *setting_name)
{
GSList *found;
found = g_slist_find_custom (settings_list, setting_name, find_setting_by_name);
if (found)
return found->data;
else
return NULL;
}
/**
* nm_setting_get_name:
* @setting: the #NMSetting
@ -945,21 +865,21 @@ nm_setting_get_name (NMSetting *setting)
/**
* nm_setting_verify:
* @setting: the #NMSetting to verify
* @all_settings: (element-type NMSetting): a #GSList of all settings
* in the connection from which @setting came
* @connection: (allow-none): the #NMConnection that @setting came from, or
* %NULL if @setting is being verified in isolation.
* @error: location to store error, or %NULL
*
* Validates the setting. Each setting's properties have allowed values, and
* some are dependent on other values (hence the need for @all_settings). The
* some are dependent on other values (hence the need for @connection). The
* returned #GError contains information about which property of the setting
* failed validation, and in what way that property failed validation.
*
* Returns: %TRUE if the setting is valid, %FALSE if it is not
**/
gboolean
nm_setting_verify (NMSetting *setting, GSList *all_settings, GError **error)
nm_setting_verify (NMSetting *setting, NMConnection *connection, GError **error)
{
NMSettingVerifyResult result = _nm_setting_verify (setting, all_settings, error);
NMSettingVerifyResult result = _nm_setting_verify (setting, connection, error);
if (result == NM_SETTING_VERIFY_NORMALIZABLE)
g_clear_error (error);
@ -968,13 +888,14 @@ nm_setting_verify (NMSetting *setting, GSList *all_settings, GError **error)
}
NMSettingVerifyResult
_nm_setting_verify (NMSetting *setting, GSList *all_settings, GError **error)
_nm_setting_verify (NMSetting *setting, NMConnection *connection, GError **error)
{
g_return_val_if_fail (NM_IS_SETTING (setting), NM_SETTING_VERIFY_ERROR);
g_return_val_if_fail (!connection || NM_IS_CONNECTION (connection), NM_SETTING_VERIFY_ERROR);
g_return_val_if_fail (!error || *error == NULL, NM_SETTING_VERIFY_ERROR);
if (NM_SETTING_GET_CLASS (setting)->verify)
return NM_SETTING_GET_CLASS (setting)->verify (setting, all_settings, error);
return NM_SETTING_GET_CLASS (setting)->verify (setting, connection, error);
return NM_SETTING_VERIFY_SUCCESS;
}
@ -1734,49 +1655,6 @@ nm_setting_to_string (NMSetting *setting)
return g_string_free (string, FALSE);
}
NMSetting *
_nm_setting_find_in_list_required (GSList *all_settings,
const char *setting_name,
GError **error)
{
NMSetting *setting;
g_return_val_if_fail (!error || !*error, NULL);
g_return_val_if_fail (all_settings, NULL);
g_return_val_if_fail (setting_name, NULL);
setting = nm_setting_find_in_list (all_settings, setting_name);
if (!setting) {
g_set_error_literal (error,
NM_CONNECTION_ERROR,
NM_CONNECTION_ERROR_MISSING_SETTING,
_("missing setting"));
g_prefix_error (error, "%s: ", setting_name);
}
return setting;
}
NMSettingVerifyResult
_nm_setting_verify_required_virtual_interface_name (GSList *all_settings,
GError **error)
{
NMSettingConnection *s_con;
const char *interface_name;
s_con = NM_SETTING_CONNECTION (nm_setting_find_in_list (all_settings, NM_SETTING_CONNECTION_SETTING_NAME));
interface_name = s_con ? nm_setting_connection_get_interface_name (s_con) : NULL;
if (!interface_name) {
g_set_error_literal (error,
NM_CONNECTION_ERROR,
NM_CONNECTION_ERROR_MISSING_PROPERTY,
_("property is missing"));
g_prefix_error (error, "%s.%s: ", NM_SETTING_CONNECTION_SETTING_NAME, NM_SETTING_CONNECTION_INTERFACE_NAME);
return NM_SETTING_VERIFY_ERROR;
}
return NM_SETTING_VERIFY_SUCCESS;
}
GVariant *
_nm_setting_get_deprecated_virtual_interface_name (NMSetting *setting,
NMConnection *connection,

View file

@ -159,7 +159,7 @@ typedef struct {
/* Virtual functions */
gint (*verify) (NMSetting *setting,
GSList *all_settings,
NMConnection *connection,
GError **error);
GPtrArray *(*need_secrets) (NMSetting *setting);
@ -221,7 +221,7 @@ NMSetting *nm_setting_duplicate (NMSetting *setting);
const char *nm_setting_get_name (NMSetting *setting);
gboolean nm_setting_verify (NMSetting *setting,
GSList *all_settings,
NMConnection *connection,
GError **error);
gboolean nm_setting_compare (NMSetting *a,

View file

@ -25,6 +25,7 @@
#include <nm-glib-compat.h>
#include "nm-setting-dcb.h"
#include "nm-connection.h"
#include "nm-errors.h"
#define DCB_FLAGS_ALL (NM_SETTING_DCB_FLAG_ENABLE | \
NM_SETTING_DCB_FLAG_ADVERTISE | \

View file

@ -1013,17 +1013,7 @@ complete_connection (NMDevice *device,
* if the network isn't broadcasting the SSID for example.
*/
if (!ap) {
GSList *settings = NULL;
gboolean valid;
settings = g_slist_prepend (settings, s_wifi);
if (s_wsec)
settings = g_slist_prepend (settings, s_wsec);
if (s_8021x)
settings = g_slist_prepend (settings, s_8021x);
valid = nm_setting_verify (NM_SETTING (s_wifi), settings, error);
g_slist_free (settings);
if (!valid)
if (!nm_setting_verify (NM_SETTING (s_wifi), connection, error))
return FALSE;
hidden = TRUE;