From 33491bc4279481db8ae47213e34a6d695a0e8830 Mon Sep 17 00:00:00 2001 From: Michael Biebl Date: Sun, 6 Jul 2014 02:16:10 +0200 Subject: Imported Upstream version 0.9.10.0 --- cli/src/settings.c | 7502 ++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 6372 insertions(+), 1130 deletions(-) (limited to 'cli/src/settings.c') diff --git a/cli/src/settings.c b/cli/src/settings.c index 1b3d0fd0..0fc708b3 100644 --- a/cli/src/settings.c +++ b/cli/src/settings.c @@ -14,43 +14,50 @@ * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * (C) Copyright 2010 - 2012 Red Hat, Inc. + * (C) Copyright 2010 - 2014 Red Hat, Inc. */ #include "config.h" -#include "net/if_arp.h" +#include +#include #include #include #include #include "utils.h" +#include "common.h" #include "settings.h" +/* Forward declarations */ +static char *wep_key_type_to_string (NMWepKeyType type); /* Helper macro to define fields */ -#define SETTING_FIELD(setting, width) { setting, N_(setting), width, NULL, 0 } +#define SETTING_FIELD(setting, width) { setting, N_(setting), width, NULL, FALSE, FALSE, 0 } /* Available fields for NM_SETTING_CONNECTION_SETTING_NAME */ -static NmcOutputField nmc_fields_setting_connection[] = { - SETTING_FIELD ("name", 15), /* 0 */ - SETTING_FIELD (NM_SETTING_CONNECTION_ID, 25), /* 1 */ - SETTING_FIELD (NM_SETTING_CONNECTION_UUID, 38), /* 2 */ - SETTING_FIELD (NM_SETTING_CONNECTION_TYPE, 17), /* 3 */ - SETTING_FIELD (NM_SETTING_CONNECTION_AUTOCONNECT, 13), /* 4 */ - SETTING_FIELD (NM_SETTING_CONNECTION_TIMESTAMP, 10), /* 5 */ - SETTING_FIELD (NM_SETTING_CONNECTION_READ_ONLY, 10), /* 6 */ - SETTING_FIELD (NM_SETTING_CONNECTION_PERMISSIONS, 30), /* 7 */ - SETTING_FIELD (NM_SETTING_CONNECTION_ZONE, 10), /* 8 */ - SETTING_FIELD (NM_SETTING_CONNECTION_MASTER, 20), /* 9 */ - SETTING_FIELD (NM_SETTING_CONNECTION_SLAVE_TYPE, 20), /* 10 */ - SETTING_FIELD (NM_SETTING_CONNECTION_SECONDARIES, 40), /* 11 */ - {NULL, NULL, 0, NULL, 0} +NmcOutputField nmc_fields_setting_connection[] = { + SETTING_FIELD ("name", 15), /* 0 */ + SETTING_FIELD (NM_SETTING_CONNECTION_ID, 25), /* 1 */ + SETTING_FIELD (NM_SETTING_CONNECTION_UUID, 38), /* 2 */ + SETTING_FIELD (NM_SETTING_CONNECTION_INTERFACE_NAME, 20), /* 3 */ + SETTING_FIELD (NM_SETTING_CONNECTION_TYPE, 17), /* 4 */ + SETTING_FIELD (NM_SETTING_CONNECTION_AUTOCONNECT, 13), /* 5 */ + SETTING_FIELD (NM_SETTING_CONNECTION_TIMESTAMP, 10), /* 6 */ + SETTING_FIELD (NM_SETTING_CONNECTION_READ_ONLY, 10), /* 7 */ + SETTING_FIELD (NM_SETTING_CONNECTION_PERMISSIONS, 30), /* 8 */ + SETTING_FIELD (NM_SETTING_CONNECTION_ZONE, 10), /* 9 */ + SETTING_FIELD (NM_SETTING_CONNECTION_MASTER, 20), /* 10 */ + SETTING_FIELD (NM_SETTING_CONNECTION_SLAVE_TYPE, 20), /* 11 */ + SETTING_FIELD (NM_SETTING_CONNECTION_SECONDARIES, 40), /* 12 */ + SETTING_FIELD (NM_SETTING_CONNECTION_GATEWAY_PING_TIMEOUT, 30), /* 13 */ + {NULL, NULL, 0, NULL, FALSE, FALSE, 0} }; #define NMC_FIELDS_SETTING_CONNECTION_ALL "name"","\ NM_SETTING_CONNECTION_ID","\ NM_SETTING_CONNECTION_UUID","\ + NM_SETTING_CONNECTION_INTERFACE_NAME","\ NM_SETTING_CONNECTION_TYPE","\ NM_SETTING_CONNECTION_AUTOCONNECT","\ NM_SETTING_CONNECTION_TIMESTAMP","\ @@ -59,11 +66,12 @@ static NmcOutputField nmc_fields_setting_connection[] = { NM_SETTING_CONNECTION_ZONE","\ NM_SETTING_CONNECTION_MASTER","\ NM_SETTING_CONNECTION_SLAVE_TYPE","\ - NM_SETTING_CONNECTION_SECONDARIES + NM_SETTING_CONNECTION_SECONDARIES","\ + NM_SETTING_CONNECTION_GATEWAY_PING_TIMEOUT #define NMC_FIELDS_SETTING_CONNECTION_COMMON NMC_FIELDS_SETTING_CONNECTION_ALL /* Available fields for NM_SETTING_WIRED_SETTING_NAME */ -static NmcOutputField nmc_fields_setting_wired[] = { +NmcOutputField nmc_fields_setting_wired[] = { SETTING_FIELD ("name", 17), /* 0 */ SETTING_FIELD (NM_SETTING_WIRED_PORT, 8), /* 1 */ SETTING_FIELD (NM_SETTING_WIRED_SPEED, 10), /* 2 */ @@ -76,7 +84,7 @@ static NmcOutputField nmc_fields_setting_wired[] = { SETTING_FIELD (NM_SETTING_WIRED_S390_SUBCHANNELS, 20), /* 9 */ SETTING_FIELD (NM_SETTING_WIRED_S390_NETTYPE, 15), /* 10 */ SETTING_FIELD (NM_SETTING_WIRED_S390_OPTIONS, 20), /* 11 */ - {NULL, NULL, 0, NULL, 0} + {NULL, NULL, 0, NULL, FALSE, FALSE, 0} }; #define NMC_FIELDS_SETTING_WIRED_ALL "name"","\ NM_SETTING_WIRED_PORT","\ @@ -93,7 +101,7 @@ static NmcOutputField nmc_fields_setting_wired[] = { #define NMC_FIELDS_SETTING_WIRED_COMMON NMC_FIELDS_SETTING_WIRED_ALL /* Available fields for NM_SETTING_802_1X_SETTING_NAME */ -static NmcOutputField nmc_fields_setting_8021X[] = { +NmcOutputField nmc_fields_setting_8021X[] = { SETTING_FIELD ("name", 10), /* 0 */ SETTING_FIELD (NM_SETTING_802_1X_EAP, 10), /* 1 */ SETTING_FIELD (NM_SETTING_802_1X_IDENTITY, 15), /* 2 */ @@ -127,7 +135,7 @@ static NmcOutputField nmc_fields_setting_8021X[] = { SETTING_FIELD (NM_SETTING_802_1X_PIN, 8), /* 30 */ SETTING_FIELD (NM_SETTING_802_1X_PIN_FLAGS, 20), /* 31 */ SETTING_FIELD (NM_SETTING_802_1X_SYSTEM_CA_CERTS, 17), /* 32 */ - {NULL, NULL, 0, NULL, 0} + {NULL, NULL, 0, NULL, FALSE, FALSE, 0} }; #define NMC_FIELDS_SETTING_802_1X_ALL "name"","\ NM_SETTING_802_1X_EAP","\ @@ -165,7 +173,7 @@ static NmcOutputField nmc_fields_setting_8021X[] = { #define NMC_FIELDS_SETTING_802_1X_COMMON NMC_FIELDS_SETTING_802_1X_ALL /* Available fields for NM_SETTING_WIRELESS_SETTING_NAME */ -static NmcOutputField nmc_fields_setting_wireless[] = { +NmcOutputField nmc_fields_setting_wireless[] = { SETTING_FIELD ("name", 17), /* 0 */ SETTING_FIELD (NM_SETTING_WIRELESS_SSID, 34), /* 1 */ SETTING_FIELD (NM_SETTING_WIRELESS_MODE, 15), /* 2 */ @@ -179,9 +187,8 @@ static NmcOutputField nmc_fields_setting_wireless[] = { SETTING_FIELD (NM_SETTING_WIRELESS_MAC_ADDRESS_BLACKLIST, 39), /* 10 */ SETTING_FIELD (NM_SETTING_WIRELESS_MTU, 6), /* 11 */ SETTING_FIELD (NM_SETTING_WIRELESS_SEEN_BSSIDS, 35), /* 12 */ - SETTING_FIELD (NM_SETTING_WIRELESS_SEC, 25), /* 13 */ - SETTING_FIELD (NM_SETTING_WIRELESS_HIDDEN, 10), /* 14 */ - {NULL, NULL, 0, NULL, 0} + SETTING_FIELD (NM_SETTING_WIRELESS_HIDDEN, 10), /* 13 */ + {NULL, NULL, 0, NULL, FALSE, FALSE, 0} }; #define NMC_FIELDS_SETTING_WIRELESS_ALL "name"","\ NM_SETTING_WIRELESS_SSID","\ @@ -196,12 +203,11 @@ static NmcOutputField nmc_fields_setting_wireless[] = { NM_SETTING_WIRELESS_MAC_ADDRESS_BLACKLIST","\ NM_SETTING_WIRELESS_MTU","\ NM_SETTING_WIRELESS_SEEN_BSSIDS","\ - NM_SETTING_WIRELESS_SEC","\ NM_SETTING_WIRELESS_HIDDEN #define NMC_FIELDS_SETTING_WIRELESS_COMMON NMC_FIELDS_SETTING_WIRELESS_ALL /* Available fields for NM_SETTING_WIRELESS_SECURITY_SETTING_NAME */ -static NmcOutputField nmc_fields_setting_wireless_security[] = { +NmcOutputField nmc_fields_setting_wireless_security[] = { SETTING_FIELD ("name", 25), /* 0 */ SETTING_FIELD (NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, 10), /* 1 */ SETTING_FIELD (NM_SETTING_WIRELESS_SECURITY_WEP_TX_KEYIDX, 15), /* 2 */ @@ -220,7 +226,7 @@ static NmcOutputField nmc_fields_setting_wireless_security[] = { SETTING_FIELD (NM_SETTING_WIRELESS_SECURITY_PSK_FLAGS, 20), /* 15 */ SETTING_FIELD (NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD, 15), /* 16 */ SETTING_FIELD (NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD_FLAGS, 20), /* 17 */ - {NULL, NULL, 0, NULL, 0} + {NULL, NULL, 0, NULL, FALSE, FALSE, 0} }; #define NMC_FIELDS_SETTING_WIRELESS_SECURITY_ALL "name"","\ NM_SETTING_WIRELESS_SECURITY_KEY_MGMT","\ @@ -243,7 +249,7 @@ static NmcOutputField nmc_fields_setting_wireless_security[] = { #define NMC_FIELDS_SETTING_WIRELESS_SECURITY_COMMON NMC_FIELDS_SETTING_WIRELESS_SECURITY_ALL /* Available fields for NM_SETTING_IP4_CONFIG_SETTING_NAME */ -static NmcOutputField nmc_fields_setting_ip4_config[] = { +NmcOutputField nmc_fields_setting_ip4_config[] = { SETTING_FIELD ("name", 8), /* 0 */ SETTING_FIELD (NM_SETTING_IP4_CONFIG_METHOD, 10), /* 1 */ SETTING_FIELD (NM_SETTING_IP4_CONFIG_DNS, 20), /* 2 */ @@ -257,7 +263,7 @@ static NmcOutputField nmc_fields_setting_ip4_config[] = { SETTING_FIELD (NM_SETTING_IP4_CONFIG_DHCP_HOSTNAME, 14), /* 10 */ SETTING_FIELD (NM_SETTING_IP4_CONFIG_NEVER_DEFAULT, 15), /* 11 */ SETTING_FIELD (NM_SETTING_IP4_CONFIG_MAY_FAIL, 12), /* 12 */ - {NULL, NULL, 0, NULL, 0} + {NULL, NULL, 0, NULL, FALSE, FALSE, 0} }; #define NMC_FIELDS_SETTING_IP4_CONFIG_ALL "name"","\ NM_SETTING_IP4_CONFIG_METHOD","\ @@ -275,7 +281,7 @@ static NmcOutputField nmc_fields_setting_ip4_config[] = { #define NMC_FIELDS_SETTING_IP4_CONFIG_COMMON NMC_FIELDS_SETTING_IP4_CONFIG_ALL /* Available fields for NM_SETTING_IP6_CONFIG_SETTING_NAME */ -static NmcOutputField nmc_fields_setting_ip6_config[] = { +NmcOutputField nmc_fields_setting_ip6_config[] = { SETTING_FIELD ("name", 8), /* 0 */ SETTING_FIELD (NM_SETTING_IP6_CONFIG_METHOD, 10), /* 1 */ SETTING_FIELD (NM_SETTING_IP6_CONFIG_DNS, 20), /* 2 */ @@ -288,7 +294,7 @@ static NmcOutputField nmc_fields_setting_ip6_config[] = { SETTING_FIELD (NM_SETTING_IP6_CONFIG_MAY_FAIL, 12), /* 9 */ SETTING_FIELD (NM_SETTING_IP6_CONFIG_IP6_PRIVACY, 15), /* 10 */ SETTING_FIELD (NM_SETTING_IP6_CONFIG_DHCP_HOSTNAME, 14), /* 11 */ - {NULL, NULL, 0, NULL, 0} + {NULL, NULL, 0, NULL, FALSE, FALSE, 0} }; #define NMC_FIELDS_SETTING_IP6_CONFIG_ALL "name"","\ NM_SETTING_IP6_CONFIG_METHOD","\ @@ -305,14 +311,14 @@ static NmcOutputField nmc_fields_setting_ip6_config[] = { #define NMC_FIELDS_SETTING_IP6_CONFIG_COMMON NMC_FIELDS_SETTING_IP4_CONFIG_ALL /* Available fields for NM_SETTING_SERIAL_SETTING_NAME */ -static NmcOutputField nmc_fields_setting_serial[] = { +NmcOutputField nmc_fields_setting_serial[] = { SETTING_FIELD ("name", 10), /* 0 */ SETTING_FIELD (NM_SETTING_SERIAL_BAUD, 10), /* 1 */ SETTING_FIELD (NM_SETTING_SERIAL_BITS, 10), /* 2 */ SETTING_FIELD (NM_SETTING_SERIAL_PARITY, 10), /* 3 */ SETTING_FIELD (NM_SETTING_SERIAL_STOPBITS, 10), /* 4 */ SETTING_FIELD (NM_SETTING_SERIAL_SEND_DELAY, 12), /* 5 */ - {NULL, NULL, 0, NULL, 0} + {NULL, NULL, 0, NULL, FALSE, FALSE, 0} }; #define NMC_FIELDS_SETTING_SERIAL_ALL "name"","\ NM_SETTING_SERIAL_BAUD","\ @@ -323,7 +329,7 @@ static NmcOutputField nmc_fields_setting_serial[] = { #define NMC_FIELDS_SETTING_SERIAL_COMMON NMC_FIELDS_SETTING_SERIAL_ALL /* Available fields for NM_SETTING_PPP_SETTING_NAME */ -static NmcOutputField nmc_fields_setting_ppp[] = { +NmcOutputField nmc_fields_setting_ppp[] = { SETTING_FIELD ("name", 10), /* 0 */ SETTING_FIELD (NM_SETTING_PPP_NOAUTH, 10), /* 1 */ SETTING_FIELD (NM_SETTING_PPP_REFUSE_EAP, 10), /* 2 */ @@ -343,7 +349,7 @@ static NmcOutputField nmc_fields_setting_ppp[] = { SETTING_FIELD (NM_SETTING_PPP_MTU, 10), /* 16 */ SETTING_FIELD (NM_SETTING_PPP_LCP_ECHO_FAILURE, 17), /* 17 */ SETTING_FIELD (NM_SETTING_PPP_LCP_ECHO_INTERVAL, 18), /* 18 */ - {NULL, NULL, 0, NULL, 0} + {NULL, NULL, 0, NULL, FALSE, FALSE, 0} }; #define NMC_FIELDS_SETTING_PPP_ALL "name"","\ NM_SETTING_PPP_NOAUTH","\ @@ -367,13 +373,13 @@ static NmcOutputField nmc_fields_setting_ppp[] = { #define NMC_FIELDS_SETTING_PPP_COMMON NMC_FIELDS_SETTING_PPP_ALL /* Available fields for NM_SETTING_PPPOE_SETTING_NAME */ -static NmcOutputField nmc_fields_setting_pppoe[] = { +NmcOutputField nmc_fields_setting_pppoe[] = { SETTING_FIELD ("name", 10), /* 0 */ SETTING_FIELD (NM_SETTING_PPPOE_SERVICE, 12), /* 1 */ SETTING_FIELD (NM_SETTING_PPPOE_USERNAME, 15), /* 2 */ SETTING_FIELD (NM_SETTING_PPPOE_PASSWORD, 15), /* 3 */ SETTING_FIELD (NM_SETTING_PPPOE_PASSWORD_FLAGS, 20), /* 4 */ - {NULL, NULL, 0, NULL, 0} + {NULL, NULL, 0, NULL, FALSE, FALSE, 0} }; #define NMC_FIELDS_SETTING_PPPOE_ALL "name"","\ NM_SETTING_PPPOE_SERVICE","\ @@ -383,7 +389,7 @@ static NmcOutputField nmc_fields_setting_pppoe[] = { #define NMC_FIELDS_SETTING_PPPOE_COMMON NMC_FIELDS_SETTING_PPPOE_ALL /* Available fields for NM_SETTING_ADSL_SETTING_NAME */ -static NmcOutputField nmc_fields_setting_adsl[] = { +NmcOutputField nmc_fields_setting_adsl[] = { SETTING_FIELD ("name", 10), /* 0 */ SETTING_FIELD (NM_SETTING_ADSL_USERNAME, 15), /* 1 */ SETTING_FIELD (NM_SETTING_ADSL_PASSWORD, 15), /* 2 */ @@ -392,7 +398,7 @@ static NmcOutputField nmc_fields_setting_adsl[] = { SETTING_FIELD (NM_SETTING_ADSL_ENCAPSULATION, 10), /* 5 */ SETTING_FIELD (NM_SETTING_ADSL_VPI, 10), /* 6 */ SETTING_FIELD (NM_SETTING_ADSL_VCI, 10), /* 7 */ - {NULL, NULL, 0, NULL, 0} + {NULL, NULL, 0, NULL, FALSE, FALSE, 0} }; #define NMC_FIELDS_SETTING_ADSL_ALL "name"","\ NM_SETTING_ADSL_USERNAME","\ @@ -405,7 +411,7 @@ static NmcOutputField nmc_fields_setting_adsl[] = { #define NMC_FIELDS_SETTING_ADSL_COMMON NMC_FIELDS_SETTING_ADSL_ALL /* Available fields for NM_SETTING_GSM_SETTING_NAME */ -static NmcOutputField nmc_fields_setting_gsm[] = { +NmcOutputField nmc_fields_setting_gsm[] = { SETTING_FIELD ("name", 10), /* 0 */ SETTING_FIELD (NM_SETTING_GSM_NUMBER, 10), /* 1 */ SETTING_FIELD (NM_SETTING_GSM_USERNAME, 15), /* 2 */ @@ -418,7 +424,7 @@ static NmcOutputField nmc_fields_setting_gsm[] = { SETTING_FIELD (NM_SETTING_GSM_PIN, 10), /* 9 */ SETTING_FIELD (NM_SETTING_GSM_PIN_FLAGS, 20), /* 10 */ SETTING_FIELD (NM_SETTING_GSM_HOME_ONLY, 10), /* 11 */ - {NULL, NULL, 0, NULL, 0} + {NULL, NULL, 0, NULL, FALSE, FALSE, 0} }; #define NMC_FIELDS_SETTING_GSM_ALL "name"","\ NM_SETTING_GSM_NUMBER","\ @@ -435,13 +441,13 @@ static NmcOutputField nmc_fields_setting_gsm[] = { #define NMC_FIELDS_SETTING_GSM_COMMON NMC_FIELDS_SETTING_GSM_ALL /* Available fields for NM_SETTING_CDMA_SETTING_NAME */ -static NmcOutputField nmc_fields_setting_cdma[] = { +NmcOutputField nmc_fields_setting_cdma[] = { SETTING_FIELD ("name", 10), /* 0 */ SETTING_FIELD (NM_SETTING_CDMA_NUMBER, 15), /* 1 */ SETTING_FIELD (NM_SETTING_CDMA_USERNAME, 15), /* 2 */ SETTING_FIELD (NM_SETTING_CDMA_PASSWORD, 15), /* 3 */ SETTING_FIELD (NM_SETTING_CDMA_PASSWORD_FLAGS, 20), /* 4 */ - {NULL, NULL, 0, NULL, 0} + {NULL, NULL, 0, NULL, FALSE, FALSE, 0} }; #define NMC_FIELDS_SETTING_CDMA_ALL "name"","\ NM_SETTING_CDMA_NUMBER","\ @@ -451,11 +457,11 @@ static NmcOutputField nmc_fields_setting_cdma[] = { #define NMC_FIELDS_SETTING_CDMA_COMMON NMC_FIELDS_SETTING_CDMA_ALL /* Available fields for NM_SETTING_BLUETOOTH_SETTING_NAME */ -static NmcOutputField nmc_fields_setting_bluetooth[] = { +NmcOutputField nmc_fields_setting_bluetooth[] = { SETTING_FIELD ("name", 11), /* 0 */ SETTING_FIELD (NM_SETTING_BLUETOOTH_BDADDR, 19), /* 1 */ SETTING_FIELD (NM_SETTING_BLUETOOTH_TYPE, 10), /* 2 */ - {NULL, NULL, 0, NULL, 0} + {NULL, NULL, 0, NULL, FALSE, FALSE, 0} }; #define NMC_FIELDS_SETTING_BLUETOOTH_ALL "name"","\ NM_SETTING_BLUETOOTH_BDADDR","\ @@ -463,12 +469,12 @@ static NmcOutputField nmc_fields_setting_bluetooth[] = { #define NMC_FIELDS_SETTING_BLUETOOTH_COMMON NMC_FIELDS_SETTING_BLUETOOTH_ALL /* Available fields for NM_SETTING_OLPC_MESH_SETTING_NAME */ -static NmcOutputField nmc_fields_setting_olpc_mesh[] = { +NmcOutputField nmc_fields_setting_olpc_mesh[] = { SETTING_FIELD ("name", 18), /* 0 */ SETTING_FIELD (NM_SETTING_OLPC_MESH_SSID, 34), /* 1 */ SETTING_FIELD (NM_SETTING_OLPC_MESH_CHANNEL, 12), /* 2 */ SETTING_FIELD (NM_SETTING_OLPC_MESH_DHCP_ANYCAST_ADDRESS, 17), /* 3 */ - {NULL, NULL, 0, NULL, 0} + {NULL, NULL, 0, NULL, FALSE, FALSE, 0} }; #define NMC_FIELDS_SETTING_OLPC_MESH_ALL "name"","\ NM_SETTING_OLPC_MESH_SSID","\ @@ -477,13 +483,13 @@ static NmcOutputField nmc_fields_setting_olpc_mesh[] = { #define NMC_FIELDS_SETTING_OLPC_MESH_COMMON NMC_FIELDS_SETTING_OLPC_MESH_ALL /* Available fields for NM_SETTING_VPN_SETTING_NAME */ -static NmcOutputField nmc_fields_setting_vpn[] = { +NmcOutputField nmc_fields_setting_vpn[] = { SETTING_FIELD ("name", 6), /* 0 */ SETTING_FIELD (NM_SETTING_VPN_SERVICE_TYPE, 40), /* 1 */ SETTING_FIELD (NM_SETTING_VPN_USER_NAME, 12), /* 2 */ SETTING_FIELD (NM_SETTING_VPN_DATA, 30), /* 3 */ SETTING_FIELD (NM_SETTING_VPN_SECRETS, 15), /* 4 */ - {NULL, NULL, 0, NULL, 0} + {NULL, NULL, 0, NULL, FALSE, FALSE, 0} }; #define NMC_FIELDS_SETTING_VPN_ALL "name"","\ NM_SETTING_VPN_SERVICE_TYPE","\ @@ -493,11 +499,11 @@ static NmcOutputField nmc_fields_setting_vpn[] = { #define NMC_FIELDS_SETTING_VPN_COMMON NMC_FIELDS_SETTING_VPN_ALL /* Available fields for NM_SETTING_WIMAX_SETTING_NAME */ -static NmcOutputField nmc_fields_setting_wimax[] = { +NmcOutputField nmc_fields_setting_wimax[] = { SETTING_FIELD ("name", 6), /* 0 */ SETTING_FIELD (NM_SETTING_WIMAX_MAC_ADDRESS, 19), /* 1 */ SETTING_FIELD (NM_SETTING_WIMAX_NETWORK_NAME, 40), /* 2 */ - {NULL, NULL, 0, NULL, 0} + {NULL, NULL, 0, NULL, FALSE, FALSE, 0} }; #define NMC_FIELDS_SETTING_WIMAX_ALL "name"","\ NM_SETTING_WIMAX_MAC_ADDRESS","\ @@ -505,25 +511,29 @@ static NmcOutputField nmc_fields_setting_wimax[] = { #define NMC_FIELDS_SETTING_WIMAX_COMMON NMC_FIELDS_SETTING_WIMAX_ALL /* Available fields for NM_SETTING_INFINIBAND_SETTING_NAME */ -static NmcOutputField nmc_fields_setting_infiniband[] = { +NmcOutputField nmc_fields_setting_infiniband[] = { SETTING_FIELD ("name", 12), /* 0 */ SETTING_FIELD (NM_SETTING_INFINIBAND_MAC_ADDRESS, 61), /* 1 */ SETTING_FIELD (NM_SETTING_INFINIBAND_MTU, 6), /* 2 */ SETTING_FIELD (NM_SETTING_INFINIBAND_TRANSPORT_MODE, 12), /* 3 */ - {NULL, NULL, 0, NULL, 0} + SETTING_FIELD (NM_SETTING_INFINIBAND_P_KEY, 6), /* 4 */ + SETTING_FIELD (NM_SETTING_INFINIBAND_PARENT, 16), /* 5 */ + {NULL, NULL, 0, NULL, FALSE, FALSE, 0} }; #define NMC_FIELDS_SETTING_INFINIBAND_ALL "name"","\ NM_SETTING_INFINIBAND_MAC_ADDRESS","\ - NM_SETTING_INFINIBAND_MTU","\ - NM_SETTING_INFINIBAND_TRANSPORT_MODE -#define NMC_FIELDS_SETTING_INFINIBAND_COMMON NMC_FIELDS_SETTING_INFINIBAND_ALL + NM_SETTING_INFINIBAND_MTU"," \ + NM_SETTING_INFINIBAND_TRANSPORT_MODE"," \ + NM_SETTING_INFINIBAND_P_KEY"," \ + NM_SETTING_INFINIBAND_PARENT +#define NMC_FIELDS_SETTING_INFINIBAND_COMMON NMC_FIELDS_SETTING_INFINIBAND_ALL \ /* Available fields for NM_SETTING_BOND_SETTING_NAME */ -static NmcOutputField nmc_fields_setting_bond[] = { +NmcOutputField nmc_fields_setting_bond[] = { SETTING_FIELD ("name", 8), /* 0 */ SETTING_FIELD (NM_SETTING_BOND_INTERFACE_NAME, 15), /* 1 */ SETTING_FIELD (NM_SETTING_BOND_OPTIONS, 30), /* 2 */ - {NULL, NULL, 0, NULL, 0} + {NULL, NULL, 0, NULL, FALSE, FALSE, 0} }; #define NMC_FIELDS_SETTING_BOND_ALL "name"","\ NM_SETTING_BOND_INTERFACE_NAME","\ @@ -531,7 +541,7 @@ static NmcOutputField nmc_fields_setting_bond[] = { #define NMC_FIELDS_SETTING_BOND_COMMON NMC_FIELDS_SETTING_BOND_ALL /* Available fields for NM_SETTING_VLAN_SETTING_NAME */ -static NmcOutputField nmc_fields_setting_vlan[] = { +NmcOutputField nmc_fields_setting_vlan[] = { SETTING_FIELD ("name", 6), /* 0 */ SETTING_FIELD (NM_SETTING_VLAN_INTERFACE_NAME, 15), /* 1 */ SETTING_FIELD (NM_SETTING_VLAN_PARENT, 8), /* 2 */ @@ -539,7 +549,7 @@ static NmcOutputField nmc_fields_setting_vlan[] = { SETTING_FIELD (NM_SETTING_VLAN_FLAGS, 45), /* 4 */ SETTING_FIELD (NM_SETTING_VLAN_INGRESS_PRIORITY_MAP, 22), /* 5 */ SETTING_FIELD (NM_SETTING_VLAN_EGRESS_PRIORITY_MAP, 22), /* 6 */ - {NULL, NULL, 0, NULL, 0} + {NULL, NULL, 0, NULL, FALSE, FALSE, 0} }; #define NMC_FIELDS_SETTING_VLAN_ALL "name"","\ NM_SETTING_VLAN_INTERFACE_NAME","\ @@ -551,19 +561,21 @@ static NmcOutputField nmc_fields_setting_vlan[] = { #define NMC_FIELDS_SETTING_VLAN_COMMON NMC_FIELDS_SETTING_VLAN_ALL /* Available fields for NM_SETTING_BRIDGE_SETTING_NAME */ -static NmcOutputField nmc_fields_setting_bridge[] = { +NmcOutputField nmc_fields_setting_bridge[] = { SETTING_FIELD ("name", 8), /* 0 */ SETTING_FIELD (NM_SETTING_BRIDGE_INTERFACE_NAME, 15), /* 1 */ - SETTING_FIELD (NM_SETTING_BRIDGE_STP, 5), /* 2 */ - SETTING_FIELD (NM_SETTING_BRIDGE_PRIORITY, 6), /* 3 */ - SETTING_FIELD (NM_SETTING_BRIDGE_FORWARD_DELAY, 6), /* 4 */ - SETTING_FIELD (NM_SETTING_BRIDGE_HELLO_TIME, 6), /* 5 */ - SETTING_FIELD (NM_SETTING_BRIDGE_MAX_AGE, 6), /* 6 */ - SETTING_FIELD (NM_SETTING_BRIDGE_AGEING_TIME, 6), /* 7 */ - {NULL, NULL, 0, NULL, 0} + SETTING_FIELD (NM_SETTING_BRIDGE_MAC_ADDRESS, 19), /* 2 */ + SETTING_FIELD (NM_SETTING_BRIDGE_STP, 5), /* 3 */ + SETTING_FIELD (NM_SETTING_BRIDGE_PRIORITY, 6), /* 4 */ + SETTING_FIELD (NM_SETTING_BRIDGE_FORWARD_DELAY, 6), /* 5 */ + SETTING_FIELD (NM_SETTING_BRIDGE_HELLO_TIME, 6), /* 6 */ + SETTING_FIELD (NM_SETTING_BRIDGE_MAX_AGE, 6), /* 7 */ + SETTING_FIELD (NM_SETTING_BRIDGE_AGEING_TIME, 6), /* 8 */ + {NULL, NULL, 0, NULL, FALSE, FALSE, 0} }; #define NMC_FIELDS_SETTING_BRIDGE_ALL "name"","\ NM_SETTING_BRIDGE_INTERFACE_NAME","\ + NM_SETTING_BRIDGE_MAC_ADDRESS","\ NM_SETTING_BRIDGE_STP","\ NM_SETTING_BRIDGE_PRIORITY","\ NM_SETTING_BRIDGE_FORWARD_DELAY","\ @@ -573,12 +585,12 @@ static NmcOutputField nmc_fields_setting_bridge[] = { #define NMC_FIELDS_SETTING_BRIDGE_COMMON NMC_FIELDS_SETTING_BRIDGE_ALL /* Available fields for NM_SETTING_BRIDGE_PORT_SETTING_NAME */ -static NmcOutputField nmc_fields_setting_bridge_port[] = { +NmcOutputField nmc_fields_setting_bridge_port[] = { SETTING_FIELD ("name", 8), /* 0 */ SETTING_FIELD (NM_SETTING_BRIDGE_PORT_PRIORITY, 10), /* 1 */ SETTING_FIELD (NM_SETTING_BRIDGE_PORT_PATH_COST, 12), /* 2 */ SETTING_FIELD (NM_SETTING_BRIDGE_PORT_HAIRPIN_MODE, 15), /* 3 */ - {NULL, NULL, 0, NULL, 0} + {NULL, NULL, 0, NULL, FALSE, FALSE, 0} }; #define NMC_FIELDS_SETTING_BRIDGE_PORT_ALL "name"","\ NM_SETTING_BRIDGE_PORT_PRIORITY","\ @@ -586,15 +598,76 @@ static NmcOutputField nmc_fields_setting_bridge_port[] = { NM_SETTING_BRIDGE_PORT_HAIRPIN_MODE #define NMC_FIELDS_SETTING_BRIDGE_PORT_COMMON NMC_FIELDS_SETTING_BRIDGE_PORT_ALL +/* Available fields for NM_SETTING_TEAM_SETTING_NAME */ +NmcOutputField nmc_fields_setting_team[] = { + SETTING_FIELD ("name", 8), /* 0 */ + SETTING_FIELD (NM_SETTING_TEAM_INTERFACE_NAME, 15), /* 1 */ + SETTING_FIELD (NM_SETTING_TEAM_CONFIG, 30), /* 2 */ + {NULL, NULL, 0, NULL, FALSE, FALSE, 0} +}; +#define NMC_FIELDS_SETTING_TEAM_ALL "name"","\ + NM_SETTING_TEAM_INTERFACE_NAME","\ + NM_SETTING_TEAM_CONFIG +#define NMC_FIELDS_SETTING_TEAM_COMMON NMC_FIELDS_SETTING_TEAM_ALL + +/* Available fields for NM_SETTING_TEAM_PORT_SETTING_NAME */ +NmcOutputField nmc_fields_setting_team_port[] = { + SETTING_FIELD ("name", 8), /* 0 */ + SETTING_FIELD (NM_SETTING_TEAM_PORT_CONFIG, 30), /* 1 */ + {NULL, NULL, 0, NULL, FALSE, FALSE, 0} +}; +#define NMC_FIELDS_SETTING_TEAM_PORT_ALL "name"","\ + NM_SETTING_TEAM_PORT_CONFIG +#define NMC_FIELDS_SETTING_TEAM_PORT_COMMON NMC_FIELDS_SETTING_TEAM_PORT_ALL + +/* Available fields for NM_SETTING_DCB_SETTING_NAME */ +NmcOutputField nmc_fields_setting_dcb[] = { + SETTING_FIELD ("name", 8), /* 0 */ + SETTING_FIELD (NM_SETTING_DCB_APP_FCOE_FLAGS, 5), /* 1 */ + SETTING_FIELD (NM_SETTING_DCB_APP_FCOE_PRIORITY, 5), /* 2 */ + SETTING_FIELD (NM_SETTING_DCB_APP_FCOE_MODE, 8), /* 3 */ + SETTING_FIELD (NM_SETTING_DCB_APP_ISCSI_FLAGS, 5), /* 4 */ + SETTING_FIELD (NM_SETTING_DCB_APP_ISCSI_PRIORITY, 5), /* 5 */ + SETTING_FIELD (NM_SETTING_DCB_APP_FIP_FLAGS, 5), /* 6 */ + SETTING_FIELD (NM_SETTING_DCB_APP_FIP_PRIORITY, 5), /* 7 */ + SETTING_FIELD (NM_SETTING_DCB_PRIORITY_FLOW_CONTROL_FLAGS, 5), /* 8 */ + SETTING_FIELD (NM_SETTING_DCB_PRIORITY_FLOW_CONTROL, 10), /* 9 */ + SETTING_FIELD (NM_SETTING_DCB_PRIORITY_GROUP_FLAGS, 5), /* 10 */ + SETTING_FIELD (NM_SETTING_DCB_PRIORITY_GROUP_ID, 10), /* 11 */ + SETTING_FIELD (NM_SETTING_DCB_PRIORITY_GROUP_BANDWIDTH, 30), /* 12 */ + SETTING_FIELD (NM_SETTING_DCB_PRIORITY_BANDWIDTH, 30), /* 13 */ + SETTING_FIELD (NM_SETTING_DCB_PRIORITY_STRICT_BANDWIDTH, 10), /* 14 */ + SETTING_FIELD (NM_SETTING_DCB_PRIORITY_TRAFFIC_CLASS, 30), /* 15 */ + {NULL, NULL, 0, NULL, FALSE, FALSE, 0} +}; +#define NMC_FIELDS_SETTING_DCB_ALL "name"","\ + NM_SETTING_DCB_APP_FCOE_FLAGS","\ + NM_SETTING_DCB_APP_FCOE_PRIORITY","\ + NM_SETTING_DCB_APP_FCOE_MODE","\ + NM_SETTING_DCB_APP_ISCSI_FLAGS","\ + NM_SETTING_DCB_APP_ISCSI_PRIORITY","\ + NM_SETTING_DCB_APP_FIP_FLAGS","\ + NM_SETTING_DCB_APP_FIP_PRIORITY","\ + NM_SETTING_DCB_PRIORITY_FLOW_CONTROL_FLAGS","\ + NM_SETTING_DCB_PRIORITY_FLOW_CONTROL","\ + NM_SETTING_DCB_PRIORITY_GROUP_FLAGS","\ + NM_SETTING_DCB_PRIORITY_GROUP_ID","\ + NM_SETTING_DCB_PRIORITY_GROUP_BANDWIDTH","\ + NM_SETTING_DCB_PRIORITY_BANDWIDTH","\ + NM_SETTING_DCB_PRIORITY_STRICT_BANDWIDTH","\ + NM_SETTING_DCB_PRIORITY_TRAFFIC_CLASS +#define NMC_FIELDS_SETTING_DCB_COMMON NMC_FIELDS_SETTING_DCB_ALL + +/*----------------------------------------------------------------------------*/ static char * wep_key_type_to_string (NMWepKeyType type) { switch (type) { case NM_WEP_KEY_TYPE_KEY: - return g_strdup_printf (_("%d (hex-ascii-key)"), type); + return g_strdup_printf (_("%d (key)"), type); case NM_WEP_KEY_TYPE_PASSPHRASE: - return g_strdup_printf (_("%d (104/128-bit passphrase)"), type); + return g_strdup_printf (_("%d (passphrase)"), type); case NM_WEP_KEY_TYPE_UNKNOWN: default: return g_strdup_printf (_("%d (unknown)"), type); @@ -658,7 +731,7 @@ allowed_bands_to_string (guint32 bands) g_string_append (band_str, _("WCDMA 3GPP UMTS 2600 MHz, ")); if (band_str->str[band_str->len-1] == '(') - g_string_assign (band_str, _("unknown")); + g_string_append (band_str, _("unknown")); else g_string_truncate (band_str, band_str->len-2); /* chop off trailing ', ' */ @@ -686,7 +759,7 @@ vlan_flags_to_string (guint32 flags) g_string_append (flag_str, _("LOOSE_BINDING, ")); if (flag_str->str[flag_str->len-1] == '(') - g_string_assign (flag_str, _("unknown")); + g_string_append (flag_str, _("unknown")); else g_string_truncate (flag_str, flag_str->len-2); /* chop off trailing ', ' */ @@ -748,7 +821,7 @@ secret_flags_to_string (guint32 flags) g_string_append (flag_str, _("not required, ")); if (flag_str->str[flag_str->len-1] == '(') - g_string_assign (flag_str, _("unknown")); + g_string_append (flag_str, _("unknown")); else g_string_truncate (flag_str, flag_str->len-2); /* chop off trailing ', ' */ @@ -757,1335 +830,6504 @@ secret_flags_to_string (guint32 flags) return g_string_free (flag_str, FALSE); } -/*----------------------------------------------------------------------------*/ - -gboolean -setting_details (NMSetting *setting, NmCli *nmc) +static void +vpn_data_item (const char *key, const char *value, gpointer user_data) { - GType setting_type; + GString *ret_str = (GString *) user_data; - g_return_val_if_fail (NM_IS_SETTING (setting), FALSE); + if (ret_str->len != 0) + g_string_append (ret_str, ", "); - setting_type = G_OBJECT_TYPE (setting); - - if (setting_type == NM_TYPE_SETTING_CONNECTION) - return setting_connection_details (NM_SETTING_CONNECTION (setting), nmc); - else if (setting_type == NM_TYPE_SETTING_WIRED) - return setting_wired_details (NM_SETTING_WIRED (setting), nmc); - else if (setting_type == NM_TYPE_SETTING_802_1X) - return setting_802_1X_details (NM_SETTING_802_1X (setting), nmc); - else if (setting_type == NM_TYPE_SETTING_WIRELESS) - return setting_wireless_details (NM_SETTING_WIRELESS (setting), nmc); - else if (setting_type == NM_TYPE_SETTING_WIRELESS_SECURITY) - return setting_wireless_security_details (NM_SETTING_WIRELESS_SECURITY (setting), nmc); - else if (setting_type == NM_TYPE_SETTING_IP4_CONFIG) - return setting_ip4_config_details (NM_SETTING_IP4_CONFIG (setting), nmc); - else if (setting_type == NM_TYPE_SETTING_IP6_CONFIG) - return setting_ip6_config_details (NM_SETTING_IP6_CONFIG (setting), nmc); - else if (setting_type == NM_TYPE_SETTING_SERIAL) - return setting_serial_details (NM_SETTING_SERIAL (setting), nmc); - else if (setting_type == NM_TYPE_SETTING_PPP) - return setting_ppp_details (NM_SETTING_PPP (setting), nmc); - else if (setting_type == NM_TYPE_SETTING_PPPOE) - return setting_pppoe_details (NM_SETTING_PPPOE (setting), nmc); - else if (setting_type == NM_TYPE_SETTING_GSM) - return setting_gsm_details (NM_SETTING_GSM (setting), nmc); - else if (setting_type == NM_TYPE_SETTING_CDMA) - return setting_cdma_details (NM_SETTING_CDMA (setting), nmc); - else if (setting_type == NM_TYPE_SETTING_BLUETOOTH) - return setting_bluetooth_details (NM_SETTING_BLUETOOTH (setting), nmc); - else if (setting_type == NM_TYPE_SETTING_OLPC_MESH) - return setting_olpc_mesh_details (NM_SETTING_OLPC_MESH (setting), nmc); - else if (setting_type == NM_TYPE_SETTING_VPN) - return setting_vpn_details (NM_SETTING_VPN (setting), nmc); - else if (setting_type == NM_TYPE_SETTING_WIMAX) - return setting_wimax_details (NM_SETTING_WIMAX (setting), nmc); - else if (setting_type == NM_TYPE_SETTING_INFINIBAND) - return setting_infiniband_details (NM_SETTING_INFINIBAND (setting), nmc); - else if (setting_type == NM_TYPE_SETTING_BOND) - return setting_bond_details (NM_SETTING_BOND (setting), nmc); - else if (setting_type == NM_TYPE_SETTING_VLAN) - return setting_vlan_details (NM_SETTING_VLAN (setting), nmc); - else if (setting_type == NM_TYPE_SETTING_ADSL) - return setting_adsl_details (NM_SETTING_ADSL (setting), nmc); - else if (setting_type == NM_TYPE_SETTING_BRIDGE) - return setting_bridge_details (NM_SETTING_BRIDGE (setting), nmc); - else if (setting_type == NM_TYPE_SETTING_BRIDGE_PORT) - return setting_bridge_port_details (NM_SETTING_BRIDGE_PORT (setting), nmc); - else - /* should not be reached */ - return FALSE; + g_string_append_printf (ret_str, "%s = %s", key, value); } -gboolean -setting_connection_details (NMSettingConnection *s_con, NmCli *nmc) -{ - guint64 timestamp; - char *timestamp_str; - const char *perm_item; - const char *perm_type; - GString *perm = NULL; - GString *secondaries = NULL; - int i; - guint32 mode_flag = (nmc->print_output == NMC_PRINT_PRETTY) ? NMC_PF_FLAG_PRETTY : (nmc->print_output == NMC_PRINT_TERSE) ? NMC_PF_FLAG_TERSE : 0; - guint32 multiline_flag = nmc->multiline_output ? NMC_PF_FLAG_MULTILINE : 0; - guint32 escape_flag = nmc->escape_values ? NMC_PF_FLAG_ESCAPE : 0; - - g_return_val_if_fail (NM_IS_SETTING_CONNECTION (s_con), FALSE); - - nmc->allowed_fields = nmc_fields_setting_connection; - nmc->print_fields.indices = parse_output_fields (NMC_FIELDS_SETTING_CONNECTION_ALL, nmc->allowed_fields, NULL); - nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag | NMC_PF_FLAG_FIELD_NAMES; - print_fields (nmc->print_fields, nmc->allowed_fields); /* Print field names */ - - timestamp = nm_setting_connection_get_timestamp (s_con); - timestamp_str = g_strdup_printf ("%" G_GUINT64_FORMAT, timestamp); - /* get permissions */ - perm = g_string_new (NULL); - for (i = 0; i < nm_setting_connection_get_num_permissions (s_con); i++) { - nm_setting_connection_get_permission (s_con, i, &perm_type, &perm_item, NULL); - g_string_append_printf (perm, "%s:%s,", perm_type, perm_item); +/* === property get functions === */ +#define DEFINE_GETTER(func_name, property_name) \ + static char * \ + func_name (NMSetting *setting) \ + { \ + char *s; \ + GValue val = G_VALUE_INIT; \ + g_value_init (&val, G_TYPE_STRING); \ + g_object_get_property (G_OBJECT (setting), property_name, &val); \ + /* Getters return allocated values, and returning the string \ + * the GValue copied from the object without unsetting the \ + * GValue fulfills that requirement. */ \ + s = g_value_dup_string (&val); \ + g_value_unset (&val); \ + return s; \ } - if (perm->len > 0) - g_string_truncate (perm, perm->len-1); /* remove trailing , */ - /* get secondaries */ - secondaries = g_string_new (NULL); - for (i = 0; i < nm_setting_connection_get_num_secondaries (s_con); i++) { - const char *sec_uuid = nm_setting_connection_get_secondary (s_con, i); - g_string_append_printf (secondaries, "%s,", sec_uuid); +#define DEFINE_SECRET_FLAGS_GETTER(func_name, property_name) \ + static char * \ + func_name (NMSetting *setting) \ + { \ + guint v; \ + GValue val = G_VALUE_INIT; \ + g_value_init (&val, G_TYPE_UINT); \ + g_object_get_property (G_OBJECT (setting), property_name, &val); \ + v = g_value_get_uint (&val); \ + g_value_unset (&val); \ + return secret_flags_to_string (v); \ } - if (secondaries->len > 0) - g_string_truncate (secondaries, secondaries->len-1); /* remove trailing , */ - - nmc->allowed_fields[0].value = NM_SETTING_CONNECTION_SETTING_NAME; - nmc->allowed_fields[1].value = nm_setting_connection_get_id (s_con); - nmc->allowed_fields[2].value = nm_setting_connection_get_uuid (s_con); - nmc->allowed_fields[3].value = nm_setting_connection_get_connection_type (s_con); - nmc->allowed_fields[4].value = nm_setting_connection_get_autoconnect (s_con) ? _("yes") : _("no"); - nmc->allowed_fields[5].value = timestamp_str; - nmc->allowed_fields[6].value = nm_setting_connection_get_read_only (s_con) ? ("yes") : _("no"); - nmc->allowed_fields[7].value = perm->str; - nmc->allowed_fields[8].value = nm_setting_connection_get_zone (s_con); - nmc->allowed_fields[9].value = nm_setting_connection_get_master (s_con); - nmc->allowed_fields[10].value = nm_setting_connection_get_slave_type (s_con); - nmc->allowed_fields[11].value = secondaries->str; - - nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag | NMC_PF_FLAG_SECTION_PREFIX; - print_fields (nmc->print_fields, nmc->allowed_fields); /* Print values */ - - g_free (timestamp_str); - g_string_free (perm, TRUE); - g_string_free (secondaries, TRUE); - - return TRUE; -} - -gboolean -setting_wired_details (NMSettingWired *s_wired, NmCli *nmc) -{ - const GByteArray *mac; - const GSList *iter; - const GPtrArray *s390_channels; - int i; - char *speed_str, *mtu_str, *device_mac_str = NULL, *cloned_mac_str = NULL; - GString *mac_blacklist_s, *s390_channels_s, *s390_options_s; - guint32 mode_flag = (nmc->print_output == NMC_PRINT_PRETTY) ? NMC_PF_FLAG_PRETTY : (nmc->print_output == NMC_PRINT_TERSE) ? NMC_PF_FLAG_TERSE : 0; - guint32 multiline_flag = nmc->multiline_output ? NMC_PF_FLAG_MULTILINE : 0; - guint32 escape_flag = nmc->escape_values ? NMC_PF_FLAG_ESCAPE : 0; - - g_return_val_if_fail (NM_IS_SETTING_WIRED (s_wired), FALSE); - nmc->allowed_fields = nmc_fields_setting_wired; - nmc->print_fields.indices = parse_output_fields (NMC_FIELDS_SETTING_WIRED_ALL, nmc->allowed_fields, NULL); - nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag | NMC_PF_FLAG_FIELD_NAMES; - print_fields (nmc->print_fields, nmc->allowed_fields); /* Print field names */ - - speed_str = g_strdup_printf ("%d", nm_setting_wired_get_speed (s_wired)); - mtu_str = g_strdup_printf ("%d", nm_setting_wired_get_mtu (s_wired)); - mac = nm_setting_wired_get_mac_address (s_wired); - if (mac) - device_mac_str = nm_utils_hwaddr_ntoa (mac->data, ARPHRD_ETHER); - mac = nm_setting_wired_get_cloned_mac_address (s_wired); - if (mac) - cloned_mac_str = nm_utils_hwaddr_ntoa (mac->data, ARPHRD_ETHER); - - mac_blacklist_s = g_string_new (NULL); - iter = nm_setting_wired_get_mac_address_blacklist (s_wired); - while (iter) { - g_string_append_printf (mac_blacklist_s, "%s,", (char *) iter->data); - iter = iter->next; - } - g_string_truncate (mac_blacklist_s, mac_blacklist_s->len-1); /* chop off trailing ',' */ - - s390_channels_s = g_string_new (NULL); - s390_channels = nm_setting_wired_get_s390_subchannels (s_wired); - for (i = 0; s390_channels && i < s390_channels->len; i++) - g_string_append_printf (s390_channels_s, "%s,", (char *) g_ptr_array_index (s390_channels, i)); - g_string_truncate (s390_channels_s, s390_channels_s->len-1); /* chop off trailing ',' */ - - s390_options_s = g_string_new (NULL); - for (i = 0; i < nm_setting_wired_get_num_s390_options (s_wired); i++) { - const char *key, *value; - - nm_setting_wired_get_s390_option (s_wired, i, &key, &value); - g_string_append_printf (s390_options_s, "%s=%s,", key, value); +#define DEFINE_HWADDR_GETTER(func_name, property_name) \ + static char * \ + func_name (NMSetting *setting) \ + { \ + GValue val = G_VALUE_INIT; \ + GArray *array; \ + char *hwaddr = NULL; \ + g_value_init (&val, DBUS_TYPE_G_UCHAR_ARRAY); \ + g_object_get_property (G_OBJECT (setting), property_name, &val); \ + array = g_value_get_boxed (&val); \ + if (array && array->len) \ + hwaddr = nm_utils_hwaddr_ntoa_len (array->data, array->len); \ + g_value_unset (&val); \ + return hwaddr; \ } - g_string_truncate (s390_options_s, s390_options_s->len-1); /* chop off trailing ',' */ - - nmc->allowed_fields[0].value = NM_SETTING_WIRED_SETTING_NAME; - nmc->allowed_fields[1].value = nm_setting_wired_get_port (s_wired); - nmc->allowed_fields[2].value = speed_str; - nmc->allowed_fields[3].value = nm_setting_wired_get_duplex (s_wired); - nmc->allowed_fields[4].value = nm_setting_wired_get_auto_negotiate (s_wired) ? _("yes") : _("no"); - nmc->allowed_fields[5].value = device_mac_str; - nmc->allowed_fields[6].value = cloned_mac_str; - nmc->allowed_fields[7].value = mac_blacklist_s->str; - nmc->allowed_fields[8].value = strcmp (mtu_str, "0") ? mtu_str : _("auto"); - nmc->allowed_fields[9].value = s390_channels_s->str; - nmc->allowed_fields[10].value = nm_setting_wired_get_s390_nettype (s_wired); - nmc->allowed_fields[11].value = s390_options_s->str; - - nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag | NMC_PF_FLAG_SECTION_PREFIX; - print_fields (nmc->print_fields, nmc->allowed_fields); /* Print values */ - g_free (speed_str); - g_free (device_mac_str); - g_free (cloned_mac_str); - g_free (mtu_str); - g_string_free (mac_blacklist_s, TRUE); - g_string_free (s390_channels_s, TRUE); - g_string_free (s390_options_s, TRUE); +/* --- NM_SETTING_802_1X_SETTING_NAME property get functions --- */ +DEFINE_GETTER (nmc_property_802_1X_get_eap, NM_SETTING_802_1X_EAP) +DEFINE_GETTER (nmc_property_802_1X_get_identity, NM_SETTING_802_1X_IDENTITY) +DEFINE_GETTER (nmc_property_802_1X_get_anonymous_identity, NM_SETTING_802_1X_ANONYMOUS_IDENTITY) +DEFINE_GETTER (nmc_property_802_1X_get_pac_file, NM_SETTING_802_1X_PAC_FILE) +DEFINE_GETTER (nmc_property_802_1X_get_ca_path, NM_SETTING_802_1X_CA_PATH) +DEFINE_GETTER (nmc_property_802_1X_get_subject_match, NM_SETTING_802_1X_SUBJECT_MATCH) +DEFINE_GETTER (nmc_property_802_1X_get_altsubject_matches, NM_SETTING_802_1X_ALTSUBJECT_MATCHES) +DEFINE_GETTER (nmc_property_802_1X_get_phase1_peapver, NM_SETTING_802_1X_PHASE1_PEAPVER) +DEFINE_GETTER (nmc_property_802_1X_get_phase1_peaplabel, NM_SETTING_802_1X_PHASE1_PEAPLABEL) +DEFINE_GETTER (nmc_property_802_1X_get_phase1_fast_provisioning, NM_SETTING_802_1X_PHASE1_FAST_PROVISIONING) +DEFINE_GETTER (nmc_property_802_1X_get_phase2_auth, NM_SETTING_802_1X_PHASE2_AUTH) +DEFINE_GETTER (nmc_property_802_1X_get_phase2_autheap, NM_SETTING_802_1X_PHASE2_AUTHEAP) +DEFINE_GETTER (nmc_property_802_1X_get_phase2_ca_path, NM_SETTING_802_1X_PHASE2_CA_PATH) +DEFINE_GETTER (nmc_property_802_1X_get_phase2_subject_match, NM_SETTING_802_1X_PHASE2_SUBJECT_MATCH) +DEFINE_GETTER (nmc_property_802_1X_get_phase2_altsubject_matches, NM_SETTING_802_1X_PHASE2_ALTSUBJECT_MATCHES) +DEFINE_GETTER (nmc_property_802_1X_get_password, NM_SETTING_802_1X_PASSWORD) +DEFINE_SECRET_FLAGS_GETTER (nmc_property_802_1X_get_password_flags, NM_SETTING_802_1X_PASSWORD_FLAGS) +DEFINE_SECRET_FLAGS_GETTER (nmc_property_802_1X_get_password_raw_flags, NM_SETTING_802_1X_PASSWORD_RAW_FLAGS) +DEFINE_GETTER (nmc_property_802_1X_get_private_key_password, NM_SETTING_802_1X_PRIVATE_KEY_PASSWORD) +DEFINE_SECRET_FLAGS_GETTER (nmc_property_802_1X_get_private_key_password_flags, NM_SETTING_802_1X_PRIVATE_KEY_PASSWORD_FLAGS) +DEFINE_GETTER (nmc_property_802_1X_get_phase2_private_key_password, NM_SETTING_802_1X_PHASE2_PRIVATE_KEY_PASSWORD) +DEFINE_SECRET_FLAGS_GETTER (nmc_property_802_1X_get_phase2_private_key_password_flags, NM_SETTING_802_1X_PHASE2_PRIVATE_KEY_PASSWORD_FLAGS) +DEFINE_GETTER (nmc_property_802_1X_get_pin, NM_SETTING_802_1X_PIN) +DEFINE_SECRET_FLAGS_GETTER (nmc_property_802_1X_get_pin_flags, NM_SETTING_802_1X_PIN_FLAGS) +DEFINE_GETTER (nmc_property_802_1X_get_system_ca_certs, NM_SETTING_802_1X_SYSTEM_CA_CERTS) - return TRUE; -} - -gboolean -setting_802_1X_details (NMSetting8021x *s_8021X, NmCli *nmc) +static char * +nmc_property_802_1X_get_ca_cert (NMSetting *setting) { + NMSetting8021x *s_8021X = NM_SETTING_802_1X (setting); NMSetting8021xCKScheme scheme; - GString *eap_str, *alt_sub_match, *phase2_alt_sub_match; - char *ca_cert_str = NULL, *client_cert_str = NULL, *phase2_ca_cert_str = NULL; - char *phase2_client_cert_str = NULL, *private_key_str = NULL, *phase2_private_key_str = NULL, *pswd_raw_str = NULL; - char *pswd_flags, *pswd_raw_flags, *priv_key_pswd_flags, *phase2_priv_key_pswd_flags, *pin_flags; - int i; - guint32 mode_flag = (nmc->print_output == NMC_PRINT_PRETTY) ? NMC_PF_FLAG_PRETTY : (nmc->print_output == NMC_PRINT_TERSE) ? NMC_PF_FLAG_TERSE : 0; - guint32 multiline_flag = nmc->multiline_output ? NMC_PF_FLAG_MULTILINE : 0; - guint32 escape_flag = nmc->escape_values ? NMC_PF_FLAG_ESCAPE : 0; - - g_return_val_if_fail (NM_IS_SETTING_802_1X (s_8021X), FALSE); - - nmc->allowed_fields = nmc_fields_setting_8021X; - nmc->print_fields.indices = parse_output_fields (NMC_FIELDS_SETTING_802_1X_ALL, nmc->allowed_fields, NULL); - nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag | NMC_PF_FLAG_FIELD_NAMES; - print_fields (nmc->print_fields, nmc->allowed_fields); /* Print field names */ + char *ca_cert_str = NULL; - eap_str = g_string_new (NULL); - for (i = 0; i < nm_setting_802_1x_get_num_eap_methods (s_8021X); i++) { - if (i > 0) - g_string_append_c (eap_str, ','); - g_string_append (eap_str, nm_setting_802_1x_get_eap_method (s_8021X, i)); - } scheme = nm_setting_802_1x_get_ca_cert_scheme (s_8021X); if (scheme == NM_SETTING_802_1X_CK_SCHEME_BLOB) ca_cert_str = byte_array_to_string (nm_setting_802_1x_get_ca_cert_blob (s_8021X)); if (scheme == NM_SETTING_802_1X_CK_SCHEME_PATH) ca_cert_str = g_strdup (nm_setting_802_1x_get_ca_cert_path (s_8021X)); + return ca_cert_str; +} + +static char * +nmc_property_802_1X_get_client_cert (NMSetting *setting) +{ + NMSetting8021x *s_8021X = NM_SETTING_802_1X (setting); + NMSetting8021xCKScheme scheme; + char *client_cert_str = NULL; + scheme = nm_setting_802_1x_get_client_cert_scheme (s_8021X); if (scheme == NM_SETTING_802_1X_CK_SCHEME_BLOB) client_cert_str = byte_array_to_string (nm_setting_802_1x_get_client_cert_blob (s_8021X)); if (scheme == NM_SETTING_802_1X_CK_SCHEME_PATH) client_cert_str = g_strdup (nm_setting_802_1x_get_client_cert_path (s_8021X)); + return client_cert_str; +} + +static char * +nmc_property_802_1X_get_phase2_ca_cert (NMSetting *setting) +{ + NMSetting8021x *s_8021X = NM_SETTING_802_1X (setting); + NMSetting8021xCKScheme scheme; + char *phase2_ca_cert_str = NULL; + scheme = nm_setting_802_1x_get_phase2_ca_cert_scheme (s_8021X); if (scheme == NM_SETTING_802_1X_CK_SCHEME_BLOB) phase2_ca_cert_str = byte_array_to_string (nm_setting_802_1x_get_phase2_ca_cert_blob (s_8021X)); if (scheme == NM_SETTING_802_1X_CK_SCHEME_PATH) phase2_ca_cert_str = g_strdup (nm_setting_802_1x_get_phase2_ca_cert_path (s_8021X)); + return phase2_ca_cert_str; +} + +static char * +nmc_property_802_1X_get_phase2_client_cert (NMSetting *setting) +{ + NMSetting8021x *s_8021X = NM_SETTING_802_1X (setting); + NMSetting8021xCKScheme scheme; + char *phase2_client_cert_str = NULL; + scheme = nm_setting_802_1x_get_phase2_client_cert_scheme (s_8021X); if (scheme == NM_SETTING_802_1X_CK_SCHEME_BLOB) phase2_client_cert_str = byte_array_to_string (nm_setting_802_1x_get_phase2_client_cert_blob (s_8021X)); if (scheme == NM_SETTING_802_1X_CK_SCHEME_PATH) phase2_client_cert_str = g_strdup (nm_setting_802_1x_get_phase2_client_cert_path (s_8021X)); + return phase2_client_cert_str; +} + +static char * +nmc_property_802_1X_get_password_raw (NMSetting *setting) +{ + NMSetting8021x *s_8021X = NM_SETTING_802_1X (setting); + return byte_array_to_string (nm_setting_802_1x_get_password_raw (s_8021X)); +} + +static char * +nmc_property_802_1X_get_private_key (NMSetting *setting) +{ + NMSetting8021x *s_8021X = NM_SETTING_802_1X (setting); + NMSetting8021xCKScheme scheme; + char *private_key_str = NULL; + scheme = nm_setting_802_1x_get_private_key_scheme (s_8021X); if (scheme == NM_SETTING_802_1X_CK_SCHEME_BLOB) private_key_str = byte_array_to_string (nm_setting_802_1x_get_private_key_blob (s_8021X)); if (scheme == NM_SETTING_802_1X_CK_SCHEME_PATH) private_key_str = g_strdup (nm_setting_802_1x_get_private_key_path (s_8021X)); + return private_key_str; +} + +static char * +nmc_property_802_1X_get_phase2_private_key (NMSetting *setting) +{ + NMSetting8021x *s_8021X = NM_SETTING_802_1X (setting); + NMSetting8021xCKScheme scheme; + char *phase2_private_key_str = NULL; + scheme = nm_setting_802_1x_get_phase2_private_key_scheme (s_8021X); if (scheme == NM_SETTING_802_1X_CK_SCHEME_BLOB) phase2_private_key_str = byte_array_to_string (nm_setting_802_1x_get_phase2_private_key_blob (s_8021X)); if (scheme == NM_SETTING_802_1X_CK_SCHEME_PATH) phase2_private_key_str = g_strdup (nm_setting_802_1x_get_phase2_private_key_path (s_8021X)); - alt_sub_match = g_string_new (NULL); - for (i = 0; i < nm_setting_802_1x_get_num_altsubject_matches (s_8021X); i++) - g_string_append_printf (alt_sub_match, "%s,", nm_setting_802_1x_get_altsubject_match (s_8021X, i)); - g_string_truncate (alt_sub_match, alt_sub_match->len-1); /* chop off trailing ',' */ - - phase2_alt_sub_match = g_string_new (NULL); - for (i = 0; i < nm_setting_802_1x_get_num_phase2_altsubject_matches (s_8021X); i++) - g_string_append_printf (phase2_alt_sub_match, "%s,", nm_setting_802_1x_get_phase2_altsubject_match (s_8021X, i)); - g_string_truncate (phase2_alt_sub_match, phase2_alt_sub_match->len-1); /* chop off trailing ',' */ - - pswd_raw_str = byte_array_to_string (nm_setting_802_1x_get_password_raw (s_8021X)); - - pswd_flags = secret_flags_to_string (nm_setting_802_1x_get_password_flags (s_8021X)); - pswd_raw_flags = secret_flags_to_string (nm_setting_802_1x_get_password_raw_flags (s_8021X)); - priv_key_pswd_flags = secret_flags_to_string (nm_setting_802_1x_get_private_key_password_flags (s_8021X)); - phase2_priv_key_pswd_flags = secret_flags_to_string (nm_setting_802_1x_get_phase2_private_key_password_flags (s_8021X)); - pin_flags = secret_flags_to_string (nm_setting_802_1x_get_pin_flags (s_8021X)); - - nmc->allowed_fields[0].value = NM_SETTING_802_1X_SETTING_NAME; - nmc->allowed_fields[1].value = eap_str->str; - nmc->allowed_fields[2].value = nm_setting_802_1x_get_identity (s_8021X); - nmc->allowed_fields[3].value = nm_setting_802_1x_get_anonymous_identity (s_8021X); - nmc->allowed_fields[4].value = nm_setting_802_1x_get_pac_file (s_8021X); - nmc->allowed_fields[5].value = ca_cert_str; - nmc->allowed_fields[6].value = nm_setting_802_1x_get_ca_path (s_8021X); - nmc->allowed_fields[7].value = nm_setting_802_1x_get_subject_match (s_8021X); - nmc->allowed_fields[8].value = alt_sub_match->str; - nmc->allowed_fields[9].value = client_cert_str; - nmc->allowed_fields[10].value = nm_setting_802_1x_get_phase1_peapver (s_8021X); - nmc->allowed_fields[11].value = nm_setting_802_1x_get_phase1_peaplabel (s_8021X); - nmc->allowed_fields[12].value = nm_setting_802_1x_get_phase1_fast_provisioning (s_8021X); - nmc->allowed_fields[13].value = nm_setting_802_1x_get_phase2_auth (s_8021X); - nmc->allowed_fields[14].value = nm_setting_802_1x_get_phase2_autheap (s_8021X); - nmc->allowed_fields[15].value = phase2_ca_cert_str; - nmc->allowed_fields[16].value = nm_setting_802_1x_get_phase2_ca_path (s_8021X); - nmc->allowed_fields[17].value = nm_setting_802_1x_get_phase2_subject_match (s_8021X); - nmc->allowed_fields[18].value = phase2_alt_sub_match->str; - nmc->allowed_fields[19].value = phase2_client_cert_str; - nmc->allowed_fields[20].value = nm_setting_802_1x_get_password (s_8021X); - nmc->allowed_fields[21].value = pswd_flags; - nmc->allowed_fields[22].value = pswd_raw_str; - nmc->allowed_fields[23].value = pswd_raw_flags; - nmc->allowed_fields[24].value = private_key_str; - nmc->allowed_fields[25].value = nm_setting_802_1x_get_private_key_password (s_8021X); - nmc->allowed_fields[26].value = priv_key_pswd_flags; - nmc->allowed_fields[27].value = phase2_private_key_str; - nmc->allowed_fields[28].value = nm_setting_802_1x_get_phase2_private_key_password (s_8021X); - nmc->allowed_fields[29].value = phase2_priv_key_pswd_flags; - nmc->allowed_fields[30].value = nm_setting_802_1x_get_pin (s_8021X); - nmc->allowed_fields[31].value = pin_flags; - nmc->allowed_fields[32].value = nm_setting_802_1x_get_system_ca_certs (s_8021X) ? _("yes") : _("no"); - - nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag | NMC_PF_FLAG_SECTION_PREFIX; - print_fields (nmc->print_fields, nmc->allowed_fields); /* Print values */ - - g_free (ca_cert_str); - g_free (client_cert_str); - g_free (phase2_ca_cert_str); - g_free (phase2_client_cert_str); - g_free (private_key_str); - g_free (phase2_private_key_str); - g_free (pswd_flags); - g_free (pswd_raw_str); - g_free (pswd_raw_flags); - g_free (priv_key_pswd_flags); - g_free (phase2_priv_key_pswd_flags); - g_free (pin_flags); - g_string_free (eap_str, TRUE); - g_string_free (alt_sub_match, TRUE); - g_string_free (phase2_alt_sub_match, TRUE); - - return TRUE; + return phase2_private_key_str; } -gboolean -setting_wireless_details (NMSettingWireless *s_wireless, NmCli *nmc) -{ - int i; - const GByteArray *ssid, *bssid, *mac; - char *channel_str, *rate_str, *tx_power_str, *mtu_str; - char *device_mac_str = NULL, *cloned_mac_str = NULL, *ssid_str = NULL, *bssid_str = NULL; - GString *mac_blacklist, *seen_bssids; - const GSList *iter; - guint32 mode_flag = (nmc->print_output == NMC_PRINT_PRETTY) ? NMC_PF_FLAG_PRETTY : (nmc->print_output == NMC_PRINT_TERSE) ? NMC_PF_FLAG_TERSE : 0; - guint32 multiline_flag = nmc->multiline_output ? NMC_PF_FLAG_MULTILINE : 0; - guint32 escape_flag = nmc->escape_values ? NMC_PF_FLAG_ESCAPE : 0; - - g_return_val_if_fail (NM_IS_SETTING_WIRELESS (s_wireless), FALSE); - - nmc->allowed_fields = nmc_fields_setting_wireless; - nmc->print_fields.indices = parse_output_fields (NMC_FIELDS_SETTING_WIRELESS_ALL, nmc->allowed_fields, NULL); - nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag | NMC_PF_FLAG_FIELD_NAMES; - print_fields (nmc->print_fields, nmc->allowed_fields); /* Print field names */ +/* --- NM_SETTING_ADSL_SETTING_NAME property get functions --- */ +DEFINE_GETTER (nmc_property_adsl_get_username, NM_SETTING_ADSL_USERNAME) +DEFINE_GETTER (nmc_property_adsl_get_password, NM_SETTING_ADSL_PASSWORD) +DEFINE_SECRET_FLAGS_GETTER (nmc_property_adsl_get_password_flags, NM_SETTING_ADSL_PASSWORD_FLAGS) +DEFINE_GETTER (nmc_property_adsl_get_protocol, NM_SETTING_ADSL_PROTOCOL) +DEFINE_GETTER (nmc_property_adsl_get_encapsulation, NM_SETTING_ADSL_ENCAPSULATION) +DEFINE_GETTER (nmc_property_adsl_get_vpi, NM_SETTING_ADSL_VPI) +DEFINE_GETTER (nmc_property_adsl_get_vci, NM_SETTING_ADSL_VCI) - ssid = nm_setting_wireless_get_ssid (s_wireless); - if (ssid) - ssid_str = ssid_to_printable ((const char *) ssid->data, ssid->len); - channel_str = g_strdup_printf ("%d", nm_setting_wireless_get_channel (s_wireless)); - rate_str = g_strdup_printf ("%d", nm_setting_wireless_get_rate (s_wireless)); - bssid = nm_setting_wireless_get_bssid (s_wireless); - if (bssid) - bssid_str = nm_utils_hwaddr_ntoa (bssid->data, ARPHRD_ETHER); - tx_power_str = g_strdup_printf ("%d", nm_setting_wireless_get_tx_power (s_wireless)); - mtu_str = g_strdup_printf ("%d", nm_setting_wireless_get_mtu (s_wireless)); - mac = nm_setting_wireless_get_mac_address (s_wireless); - if (mac) - device_mac_str = nm_utils_hwaddr_ntoa (mac->data, ARPHRD_ETHER); - mac = nm_setting_wireless_get_cloned_mac_address (s_wireless); - if (mac) - cloned_mac_str = nm_utils_hwaddr_ntoa (mac->data, ARPHRD_ETHER); - - mac_blacklist = g_string_new (NULL); - iter = nm_setting_wireless_get_mac_address_blacklist (s_wireless); - while (iter) { - g_string_append_printf (mac_blacklist, "%s,", (char *) iter->data); - iter = iter->next; - } - g_string_truncate (mac_blacklist, mac_blacklist->len-1); /* chop off trailing ',' */ - - seen_bssids = g_string_new (NULL); - for (i = 0; i < nm_setting_wireless_get_num_seen_bssids (s_wireless); i++) { - if (i > 0) - g_string_append_c (seen_bssids, ','); - g_string_append (seen_bssids, nm_setting_wireless_get_seen_bssid (s_wireless, i)); - } - - nmc->allowed_fields[0].value = NM_SETTING_WIRELESS_SETTING_NAME; - nmc->allowed_fields[1].value = ssid_str; - nmc->allowed_fields[2].value = nm_setting_wireless_get_mode (s_wireless); - nmc->allowed_fields[3].value = nm_setting_wireless_get_band (s_wireless); - nmc->allowed_fields[4].value = channel_str; - nmc->allowed_fields[5].value = bssid_str; - nmc->allowed_fields[6].value = rate_str; - nmc->allowed_fields[7].value = tx_power_str; - nmc->allowed_fields[8].value = device_mac_str; - nmc->allowed_fields[9].value = cloned_mac_str; - nmc->allowed_fields[10].value = mac_blacklist->str; - nmc->allowed_fields[11].value = strcmp (mtu_str, "0") ? mtu_str : _("auto"); - nmc->allowed_fields[12].value = seen_bssids->str; - nmc->allowed_fields[13].value = nm_setting_wireless_get_security (s_wireless); - nmc->allowed_fields[14].value = nm_setting_wireless_get_hidden (s_wireless) ? _("yes") : _("no"); - - nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag | NMC_PF_FLAG_SECTION_PREFIX; - print_fields (nmc->print_fields, nmc->allowed_fields); /* Print values */ - - g_free (ssid_str); - g_free (channel_str); - g_free (bssid_str); - g_free (rate_str); - g_free (tx_power_str); - g_free (device_mac_str); - g_free (cloned_mac_str); - g_free (mtu_str); - g_string_free (seen_bssids, TRUE); - g_string_free (mac_blacklist, TRUE); +/* --- NM_SETTING_BLUETOOTH_SETTING_NAME property get functions --- */ +DEFINE_HWADDR_GETTER (nmc_property_bluetooth_get_bdaddr, NM_SETTING_BLUETOOTH_BDADDR) +DEFINE_GETTER (nmc_property_bluetooth_get_type, NM_SETTING_BLUETOOTH_TYPE) - return TRUE; -} +/* --- NM_SETTING_BOND_SETTING_NAME property get functions --- */ +DEFINE_GETTER (nmc_property_bond_get_interface_name, NM_SETTING_BOND_INTERFACE_NAME) -gboolean -setting_wireless_security_details (NMSettingWirelessSecurity *s_wireless_sec, NmCli *nmc) +static char * +nmc_property_bond_get_options (NMSetting *setting) { + NMSettingBond *s_bond = NM_SETTING_BOND (setting); + GString *bond_options_s; int i; - char *wep_tx_keyidx_str, *wep_key_type_str, *wep_flags, *psk_flags, *leap_flags; - GString *protos, *pairwises, *groups; - guint32 mode_flag = (nmc->print_output == NMC_PRINT_PRETTY) ? NMC_PF_FLAG_PRETTY : (nmc->print_output == NMC_PRINT_TERSE) ? NMC_PF_FLAG_TERSE : 0; - guint32 multiline_flag = nmc->multiline_output ? NMC_PF_FLAG_MULTILINE : 0; - guint32 escape_flag = nmc->escape_values ? NMC_PF_FLAG_ESCAPE : 0; - g_return_val_if_fail (NM_IS_SETTING_WIRELESS_SECURITY (s_wireless_sec), FALSE); + bond_options_s = g_string_new (NULL); + for (i = 0; i < nm_setting_bond_get_num_options (s_bond); i++) { + const char *key, *value; - nmc->allowed_fields = nmc_fields_setting_wireless_security; - nmc->print_fields.indices = parse_output_fields (NMC_FIELDS_SETTING_WIRELESS_SECURITY_ALL, nmc->allowed_fields, NULL); - nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag | NMC_PF_FLAG_FIELD_NAMES; - print_fields (nmc->print_fields, nmc->allowed_fields); /* Print field names */ - - wep_tx_keyidx_str = g_strdup_printf ("%d", nm_setting_wireless_security_get_wep_tx_keyidx (s_wireless_sec)); - protos = g_string_new (NULL); - for (i = 0; i < nm_setting_wireless_security_get_num_protos (s_wireless_sec); i++) { - if (i > 0) - g_string_append_c (protos, ','); - g_string_append (protos, nm_setting_wireless_security_get_proto (s_wireless_sec, i)); - } - pairwises = g_string_new (NULL); - for (i = 0; i < nm_setting_wireless_security_get_num_pairwise (s_wireless_sec); i++) { - if (i > 0) - g_string_append_c (pairwises, ','); - g_string_append (pairwises, nm_setting_wireless_security_get_pairwise (s_wireless_sec, i)); - } - groups = g_string_new (NULL); - for (i = 0; i < nm_setting_wireless_security_get_num_groups (s_wireless_sec); i++) { - if (i > 0) - g_string_append_c (groups, ','); - g_string_append (groups, nm_setting_wireless_security_get_group (s_wireless_sec, i)); - } - wep_key_type_str = wep_key_type_to_string (nm_setting_wireless_security_get_wep_key_type (s_wireless_sec)); - - wep_flags = secret_flags_to_string (nm_setting_wireless_security_get_wep_key_flags (s_wireless_sec)); - psk_flags = secret_flags_to_string (nm_setting_wireless_security_get_psk_flags (s_wireless_sec)); - leap_flags = secret_flags_to_string (nm_setting_wireless_security_get_leap_password_flags (s_wireless_sec)); - - nmc->allowed_fields[0].value = NM_SETTING_WIRELESS_SECURITY_SETTING_NAME; - nmc->allowed_fields[1].value = nm_setting_wireless_security_get_key_mgmt (s_wireless_sec); - nmc->allowed_fields[2].value = wep_tx_keyidx_str; - nmc->allowed_fields[3].value = nm_setting_wireless_security_get_auth_alg (s_wireless_sec); - nmc->allowed_fields[4].value = protos->str; - nmc->allowed_fields[5].value = pairwises->str; - nmc->allowed_fields[6].value = groups->str; - nmc->allowed_fields[7].value = nm_setting_wireless_security_get_leap_username (s_wireless_sec); - nmc->allowed_fields[8].value = nm_setting_wireless_security_get_wep_key (s_wireless_sec, 0); - nmc->allowed_fields[9].value = nm_setting_wireless_security_get_wep_key (s_wireless_sec, 1); - nmc->allowed_fields[10].value = nm_setting_wireless_security_get_wep_key (s_wireless_sec, 2); - nmc->allowed_fields[11].value = nm_setting_wireless_security_get_wep_key (s_wireless_sec, 3); - nmc->allowed_fields[12].value = wep_flags; - nmc->allowed_fields[13].value = wep_key_type_str; - nmc->allowed_fields[14].value = nm_setting_wireless_security_get_psk (s_wireless_sec); - nmc->allowed_fields[15].value = psk_flags; - nmc->allowed_fields[16].value = nm_setting_wireless_security_get_leap_password (s_wireless_sec); - nmc->allowed_fields[17].value = leap_flags; - - nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag | NMC_PF_FLAG_SECTION_PREFIX; - print_fields (nmc->print_fields, nmc->allowed_fields); /* Print values */ - - g_free (wep_tx_keyidx_str); - g_free (wep_key_type_str); - g_free (wep_flags); - g_free (psk_flags); - g_free (leap_flags); - g_string_free (protos, TRUE); - g_string_free (pairwises, TRUE); - g_string_free (groups, TRUE); + nm_setting_bond_get_option (s_bond, i, &key, &value); + g_string_append_printf (bond_options_s, "%s=%s,", key, value); + } + g_string_truncate (bond_options_s, bond_options_s->len-1); /* chop off trailing ',' */ - return TRUE; + return g_string_free (bond_options_s, FALSE); } -gboolean -setting_ip4_config_details (NMSettingIP4Config *s_ip4, NmCli *nmc) -{ - GString *dns_str, *dns_search_str, *addr_str, *route_str; - int i, num; - guint32 mode_flag = (nmc->print_output == NMC_PRINT_PRETTY) ? NMC_PF_FLAG_PRETTY : (nmc->print_output == NMC_PRINT_TERSE) ? NMC_PF_FLAG_TERSE : 0; - guint32 multiline_flag = nmc->multiline_output ? NMC_PF_FLAG_MULTILINE : 0; - guint32 escape_flag = nmc->escape_values ? NMC_PF_FLAG_ESCAPE : 0; - - g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (s_ip4), FALSE); - - nmc->allowed_fields = nmc_fields_setting_ip4_config; - nmc->print_fields.indices = parse_output_fields (NMC_FIELDS_SETTING_IP4_CONFIG_ALL, nmc->allowed_fields, NULL); - nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag | NMC_PF_FLAG_FIELD_NAMES; - print_fields (nmc->print_fields, nmc->allowed_fields); /* Print field names */ +/* --- NM_SETTING_BRIDGE_SETTING_NAME property get functions --- */ +DEFINE_GETTER (nmc_property_bridge_get_interface_name, NM_SETTING_BRIDGE_INTERFACE_NAME) +DEFINE_HWADDR_GETTER (nmc_property_bridge_get_mac_address, NM_SETTING_BRIDGE_MAC_ADDRESS) +DEFINE_GETTER (nmc_property_bridge_get_stp, NM_SETTING_BRIDGE_STP) +DEFINE_GETTER (nmc_property_bridge_get_priority, NM_SETTING_BRIDGE_PRIORITY) +DEFINE_GETTER (nmc_property_bridge_get_forward_delay, NM_SETTING_BRIDGE_FORWARD_DELAY) +DEFINE_GETTER (nmc_property_bridge_get_hello_time, NM_SETTING_BRIDGE_HELLO_TIME) +DEFINE_GETTER (nmc_property_bridge_get_max_age, NM_SETTING_BRIDGE_MAX_AGE) +DEFINE_GETTER (nmc_property_bridge_get_ageing_time, NM_SETTING_BRIDGE_AGEING_TIME) + +/* --- NM_SETTING_BRIDGE_PORT_SETTING_NAME property get functions --- */ +DEFINE_GETTER (nmc_property_bridge_port_get_priority, NM_SETTING_BRIDGE_PORT_PRIORITY) +DEFINE_GETTER (nmc_property_bridge_port_get_path_cost, NM_SETTING_BRIDGE_PORT_PATH_COST) +DEFINE_GETTER (nmc_property_bridge_port_get_hairpin_mode, NM_SETTING_BRIDGE_PORT_HAIRPIN_MODE) + +/* --- NM_SETTING_TEAM_SETTING_NAME property get functions --- */ +DEFINE_GETTER (nmc_property_team_get_interface_name, NM_SETTING_TEAM_INTERFACE_NAME) +DEFINE_GETTER (nmc_property_team_get_config, NM_SETTING_TEAM_CONFIG) + +/* --- NM_SETTING_TEAM_PORT_SETTING_NAME property get functions --- */ +DEFINE_GETTER (nmc_property_team_port_get_config, NM_SETTING_TEAM_PORT_CONFIG) + +/* --- NM_SETTING_CDMA_SETTING_NAME property get functions --- */ +DEFINE_GETTER (nmc_property_cdma_get_number, NM_SETTING_CDMA_NUMBER) +DEFINE_GETTER (nmc_property_cdma_get_username, NM_SETTING_CDMA_USERNAME) +DEFINE_GETTER (nmc_property_cdma_get_password, NM_SETTING_CDMA_PASSWORD) + +DEFINE_SECRET_FLAGS_GETTER (nmc_property_cdma_get_password_flags, NM_SETTING_CDMA_PASSWORD_FLAGS) + +/* --- NM_SETTING_CONNECTION_SETTING_NAME property get functions --- */ +DEFINE_GETTER (nmc_property_connection_get_id, NM_SETTING_CONNECTION_ID) +DEFINE_GETTER (nmc_property_connection_get_uuid, NM_SETTING_CONNECTION_UUID) +DEFINE_GETTER (nmc_property_connection_get_interface_name, NM_SETTING_CONNECTION_INTERFACE_NAME) +DEFINE_GETTER (nmc_property_connection_get_type, NM_SETTING_CONNECTION_TYPE) +DEFINE_GETTER (nmc_property_connection_get_autoconnect, NM_SETTING_CONNECTION_AUTOCONNECT) +DEFINE_GETTER (nmc_property_connection_get_timestamp, NM_SETTING_CONNECTION_TIMESTAMP) +DEFINE_GETTER (nmc_property_connection_get_read_only, NM_SETTING_CONNECTION_READ_ONLY) - dns_str = g_string_new (NULL); - num = nm_setting_ip4_config_get_num_dns (s_ip4); - for (i = 0; i < num; i++) { - char buf[INET_ADDRSTRLEN]; - guint32 ip; - - ip = nm_setting_ip4_config_get_dns (s_ip4, i); - memset (buf, 0, sizeof (buf)); - inet_ntop (AF_INET, (const void *) &ip, buf, sizeof (buf)); - if (i > 0) - g_string_append (dns_str, ", "); - g_string_append (dns_str, buf); - } - - dns_search_str = g_string_new (NULL); - num = nm_setting_ip4_config_get_num_dns_searches (s_ip4); - for (i = 0; i < num; i++) { - const char *domain; +static char * +nmc_property_connection_get_permissions (NMSetting *setting) +{ + NMSettingConnection *s_con = NM_SETTING_CONNECTION (setting); + GString *perm = NULL; + const char *perm_item; + const char *perm_type; + int i; - domain = nm_setting_ip4_config_get_dns_search (s_ip4, i); - if (i > 0) - g_string_append (dns_search_str, ", "); - g_string_append (dns_search_str, domain); + perm = g_string_new (NULL); + for (i = 0; i < nm_setting_connection_get_num_permissions (s_con); i++) { + if (nm_setting_connection_get_permission (s_con, i, &perm_type, &perm_item, NULL)) + g_string_append_printf (perm, "%s:%s,", perm_type, perm_item); } + if (perm->len > 0) + g_string_truncate (perm, perm->len-1); /* remove trailing , */ - addr_str = g_string_new (NULL); - num = nm_setting_ip4_config_get_num_addresses (s_ip4); - for (i = 0; i < num; i++) { - char buf[INET_ADDRSTRLEN]; - char *tmp; - NMIP4Address *addr; - guint32 ip; - - if (i > 0) - g_string_append (addr_str, "; "); - - g_string_append (addr_str, "{ "); - - addr = nm_setting_ip4_config_get_address (s_ip4, i); + return g_string_free (perm, FALSE); +} - memset (buf, 0, sizeof (buf)); - ip = nm_ip4_address_get_address (addr); - inet_ntop (AF_INET, (const void *) &ip, buf, sizeof (buf)); - g_string_append_printf (addr_str, "ip = %s", buf); +DEFINE_GETTER (nmc_property_connection_get_zone, NM_SETTING_CONNECTION_ZONE) +DEFINE_GETTER (nmc_property_connection_get_master, NM_SETTING_CONNECTION_MASTER) +DEFINE_GETTER (nmc_property_connection_get_slave_type, NM_SETTING_CONNECTION_SLAVE_TYPE) +DEFINE_GETTER (nmc_property_connection_get_secondaries, NM_SETTING_CONNECTION_SECONDARIES) +DEFINE_GETTER (nmc_property_connection_get_gateway_ping_timeout, NM_SETTING_CONNECTION_GATEWAY_PING_TIMEOUT) - tmp = g_strdup_printf ("/%u", nm_ip4_address_get_prefix (addr)); - g_string_append (addr_str, tmp); - g_free (tmp); +/* --- NM_SETTING_DCB_SETTING_NAME property get functions --- */ +static char * +dcb_flags_to_string (NMSettingDcbFlags flags) +{ + GString *flag_str; - memset (buf, 0, sizeof (buf)); - ip = nm_ip4_address_get_gateway (addr); - inet_ntop (AF_INET, (const void *) &ip, buf, sizeof (buf)); - g_string_append_printf (addr_str, ", gw = %s", buf); + if (flags == 0) + return g_strdup (_("0 (disabled)")); - g_string_append (addr_str, " }"); - } + flag_str = g_string_new (NULL); + g_string_printf (flag_str, "%d (", flags); - route_str = g_string_new (NULL); - num = nm_setting_ip4_config_get_num_routes (s_ip4); - for (i = 0; i < num; i++) { - char buf[INET_ADDRSTRLEN]; - char *tmp; - NMIP4Route *route; - guint32 ip; + if (flags & NM_SETTING_DCB_FLAG_ENABLE) + g_string_append (flag_str, _("enabled, ")); + if (flags & NM_SETTING_DCB_FLAG_ADVERTISE) + g_string_append (flag_str, _("advertise, ")); + if (flags & NM_SETTING_DCB_FLAG_WILLING) + g_string_append (flag_str, _("willing, ")); - if (i > 0) - g_string_append (route_str, "; "); + if (flag_str->str[flag_str->len-1] == '(') + g_string_append (flag_str, _("unknown")); + else + g_string_truncate (flag_str, flag_str->len-2); /* chop off trailing ', ' */ - g_string_append (route_str, "{ "); + g_string_append_c (flag_str, ')'); - route = nm_setting_ip4_config_get_route (s_ip4, i); + return g_string_free (flag_str, FALSE); +} - memset (buf, 0, sizeof (buf)); - ip = nm_ip4_route_get_dest (route); - inet_ntop (AF_INET, (const void *) &ip, buf, sizeof (buf)); - g_string_append_printf (route_str, "dst = %s", buf); +#define DEFINE_DCB_FLAGS_GETTER(func_name, property_name) \ + static char * \ + func_name (NMSetting *setting) \ + { \ + guint v; \ + GValue val = G_VALUE_INIT; \ + g_value_init (&val, G_TYPE_UINT); \ + g_object_get_property (G_OBJECT (setting), property_name, &val); \ + v = g_value_get_uint (&val); \ + g_value_unset (&val); \ + return dcb_flags_to_string (v); \ + } - tmp = g_strdup_printf ("/%u", nm_ip4_route_get_prefix (route)); - g_string_append (route_str, tmp); - g_free (tmp); +static char * +dcb_app_priority_to_string (gint priority) +{ + return (priority == -1) ? g_strdup (_("-1 (unset)")) : g_strdup_printf ("%d", priority); +} - memset (buf, 0, sizeof (buf)); - ip = nm_ip4_route_get_next_hop (route); - inet_ntop (AF_INET, (const void *) &ip, buf, sizeof (buf)); - g_string_append_printf (route_str, ", nh = %s", buf); +#define DEFINE_DCB_APP_PRIORITY_GETTER(func_name, property_name) \ + static char * \ + func_name (NMSetting *setting) \ + { \ + int v; \ + GValue val = G_VALUE_INIT; \ + g_value_init (&val, G_TYPE_INT); \ + g_object_get_property (G_OBJECT (setting), property_name, &val); \ + v = g_value_get_int (&val); \ + g_value_unset (&val); \ + return dcb_app_priority_to_string (v); \ + } - tmp = g_strdup_printf (", mt = %u", nm_ip4_route_get_metric (route)); - g_string_append (route_str, tmp); - g_free (tmp); +#define DEFINE_DCB_BOOL_GETTER(func_name, getter_func_name) \ + static char * \ + func_name (NMSetting *setting) \ + { \ + NMSettingDcb *s_dcb = NM_SETTING_DCB (setting); \ + GString *str; \ + guint i; \ + \ + str = g_string_new (NULL); \ + for (i = 0; i < 8; i++) { \ + if (getter_func_name (s_dcb, i)) \ + g_string_append_c (str, '1'); \ + else \ + g_string_append_c (str, '0'); \ +\ + if (i < 7) \ + g_string_append_c (str, ','); \ + } \ +\ + return g_string_free (str, FALSE); \ + } - g_string_append (route_str, " }"); +#define DEFINE_DCB_UINT_GETTER(func_name, getter_func_name) \ + static char * \ + func_name (NMSetting *setting) \ + { \ + NMSettingDcb *s_dcb = NM_SETTING_DCB (setting); \ + GString *str; \ + guint i; \ + \ + str = g_string_new (NULL); \ + for (i = 0; i < 8; i++) { \ + g_string_append_printf (str, "%u", getter_func_name (s_dcb, i)); \ + if (i < 7) \ + g_string_append_c (str, ','); \ + } \ +\ + return g_string_free (str, FALSE); \ } - nmc->allowed_fields[0].value = NM_SETTING_IP4_CONFIG_SETTING_NAME; - nmc->allowed_fields[1].value = nm_setting_ip4_config_get_method (s_ip4); - nmc->allowed_fields[2].value = dns_str->str; - nmc->allowed_fields[3].value = dns_search_str->str; - nmc->allowed_fields[4].value = addr_str->str; - nmc->allowed_fields[5].value = route_str->str; - nmc->allowed_fields[6].value = nm_setting_ip4_config_get_ignore_auto_routes (s_ip4) ? _("yes") : _("no"); - nmc->allowed_fields[7].value = nm_setting_ip4_config_get_ignore_auto_dns (s_ip4) ? _("yes") : _("no"); - nmc->allowed_fields[8].value = nm_setting_ip4_config_get_dhcp_client_id (s_ip4); - nmc->allowed_fields[9].value = nm_setting_ip4_config_get_dhcp_send_hostname (s_ip4) ? _("yes") : _("no"); - nmc->allowed_fields[10].value = nm_setting_ip4_config_get_dhcp_hostname (s_ip4); - nmc->allowed_fields[11].value = nm_setting_ip4_config_get_never_default (s_ip4) ? _("yes") : _("no"); - nmc->allowed_fields[12].value = nm_setting_ip4_config_get_may_fail (s_ip4) ? _("yes") : _("no"); +DEFINE_DCB_FLAGS_GETTER (nmc_property_dcb_get_app_fcoe_flags, NM_SETTING_DCB_APP_FCOE_FLAGS) +DEFINE_DCB_APP_PRIORITY_GETTER (nmc_property_dcb_get_app_fcoe_priority, NM_SETTING_DCB_APP_FCOE_PRIORITY) +DEFINE_GETTER (nmc_property_dcb_get_app_fcoe_mode, NM_SETTING_DCB_APP_FCOE_MODE) +DEFINE_DCB_FLAGS_GETTER (nmc_property_dcb_get_app_iscsi_flags, NM_SETTING_DCB_APP_ISCSI_FLAGS) +DEFINE_DCB_APP_PRIORITY_GETTER (nmc_property_dcb_get_app_iscsi_priority, NM_SETTING_DCB_APP_ISCSI_PRIORITY) +DEFINE_DCB_FLAGS_GETTER (nmc_property_dcb_get_app_fip_flags, NM_SETTING_DCB_APP_FIP_FLAGS) +DEFINE_DCB_APP_PRIORITY_GETTER (nmc_property_dcb_get_app_fip_priority, NM_SETTING_DCB_APP_FIP_PRIORITY) + +DEFINE_DCB_FLAGS_GETTER (nmc_property_dcb_get_pfc_flags, NM_SETTING_DCB_PRIORITY_FLOW_CONTROL_FLAGS) +DEFINE_DCB_BOOL_GETTER (nmc_property_dcb_get_pfc, nm_setting_dcb_get_priority_flow_control) + +DEFINE_DCB_FLAGS_GETTER (nmc_property_dcb_get_pg_flags, NM_SETTING_DCB_PRIORITY_GROUP_FLAGS) +DEFINE_DCB_UINT_GETTER (nmc_property_dcb_get_pg_group_id, nm_setting_dcb_get_priority_group_id) +DEFINE_DCB_UINT_GETTER (nmc_property_dcb_get_pg_group_bandwidth, nm_setting_dcb_get_priority_group_bandwidth) +DEFINE_DCB_UINT_GETTER (nmc_property_dcb_get_pg_bandwidth, nm_setting_dcb_get_priority_bandwidth) +DEFINE_DCB_BOOL_GETTER (nmc_property_dcb_get_pg_strict, nm_setting_dcb_get_priority_strict_bandwidth) +DEFINE_DCB_UINT_GETTER (nmc_property_dcb_get_pg_traffic_class, nm_setting_dcb_get_priority_traffic_class) + +/* --- NM_SETTING_GSM_SETTING_NAME property get functions --- */ +DEFINE_GETTER (nmc_property_gsm_get_number, NM_SETTING_GSM_NUMBER) +DEFINE_GETTER (nmc_property_gsm_get_username, NM_SETTING_GSM_USERNAME) +DEFINE_GETTER (nmc_property_gsm_get_password, NM_SETTING_GSM_PASSWORD) +DEFINE_SECRET_FLAGS_GETTER (nmc_property_gsm_get_password_flags, NM_SETTING_GSM_PASSWORD_FLAGS) +DEFINE_GETTER (nmc_property_gsm_get_apn, NM_SETTING_GSM_APN) +DEFINE_GETTER (nmc_property_gsm_get_network_id, NM_SETTING_GSM_NETWORK_ID) +DEFINE_GETTER (nmc_property_gsm_get_network_type, NM_SETTING_GSM_NETWORK_TYPE) - nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag | NMC_PF_FLAG_SECTION_PREFIX; - print_fields (nmc->print_fields, nmc->allowed_fields); /* Print values */ +static char * +nmc_property_gsm_get_allowed_bands (NMSetting *setting) +{ + NMSettingGsm *s_gsm = NM_SETTING_GSM (setting); +G_GNUC_BEGIN_IGNORE_DEPRECATIONS + return allowed_bands_to_string (nm_setting_gsm_get_allowed_bands (s_gsm)); +G_GNUC_END_IGNORE_DEPRECATIONS +} - g_string_free (dns_str, TRUE); - g_string_free (dns_search_str, TRUE); - g_string_free (addr_str, TRUE); - g_string_free (route_str, TRUE); +DEFINE_GETTER (nmc_property_gsm_get_pin, NM_SETTING_GSM_PIN) +DEFINE_SECRET_FLAGS_GETTER (nmc_property_gsm_get_pin_flags, NM_SETTING_GSM_PIN_FLAGS) +DEFINE_GETTER (nmc_property_gsm_get_home_only, NM_SETTING_GSM_HOME_ONLY) - return TRUE; -} +/* --- NM_SETTING_INFINIBAND_SETTING_NAME property get functions --- */ +DEFINE_HWADDR_GETTER (nmc_property_ib_get_mac_address, NM_SETTING_INFINIBAND_MAC_ADDRESS) +DEFINE_GETTER (nmc_property_ib_get_transport_mode, NM_SETTING_INFINIBAND_TRANSPORT_MODE) -gboolean -setting_ip6_config_details (NMSettingIP6Config *s_ip6, NmCli *nmc) +static char * +nmc_property_ib_get_mtu (NMSetting *setting) { - GString *dns_str, *dns_search_str, *addr_str, *route_str; - char *ip6_privacy_str; - int i, num; - guint32 mode_flag = (nmc->print_output == NMC_PRINT_PRETTY) ? NMC_PF_FLAG_PRETTY : (nmc->print_output == NMC_PRINT_TERSE) ? NMC_PF_FLAG_TERSE : 0; - guint32 multiline_flag = nmc->multiline_output ? NMC_PF_FLAG_MULTILINE : 0; - guint32 escape_flag = nmc->escape_values ? NMC_PF_FLAG_ESCAPE : 0; + NMSettingInfiniband *s_infiniband = NM_SETTING_INFINIBAND (setting); + int mtu; - g_return_val_if_fail (NM_IS_SETTING_IP6_CONFIG (s_ip6), FALSE); + mtu = nm_setting_infiniband_get_mtu (s_infiniband); + if (mtu == 0) + return g_strdup (_("auto")); + else + return g_strdup_printf ("%d", mtu); +} - nmc->allowed_fields = nmc_fields_setting_ip6_config; - nmc->print_fields.indices = parse_output_fields (NMC_FIELDS_SETTING_IP6_CONFIG_ALL, nmc->allowed_fields, NULL); - nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag | NMC_PF_FLAG_FIELD_NAMES; - print_fields (nmc->print_fields, nmc->allowed_fields); /* Print field names */ +static char * +nmc_property_ib_get_p_key (NMSetting *setting) +{ + NMSettingInfiniband *s_infiniband = NM_SETTING_INFINIBAND (setting); + int p_key; - dns_str = g_string_new (NULL); - num = nm_setting_ip6_config_get_num_dns (s_ip6); - for (i = 0; i < num; i++) { - char buf[INET6_ADDRSTRLEN]; - const struct in6_addr *ip; + p_key = nm_setting_infiniband_get_p_key (s_infiniband); + if (p_key == -1) + return g_strdup (_("default")); + else + return g_strdup_printf ("0x%04x", p_key); +} - ip = nm_setting_ip6_config_get_dns (s_ip6, i); - memset (buf, 0, sizeof (buf)); - inet_ntop (AF_INET6, (const void *) ip, buf, sizeof (buf)); - if (i > 0) - g_string_append (dns_str, ", "); - g_string_append (dns_str, buf); - } +DEFINE_GETTER (nmc_property_ib_get_parent, NM_SETTING_INFINIBAND_PARENT) + +/* --- NM_SETTING_IP4_CONFIG_SETTING_NAME property get functions --- */ +DEFINE_GETTER (nmc_property_ipv4_get_method, NM_SETTING_IP4_CONFIG_METHOD) +DEFINE_GETTER (nmc_property_ipv4_get_dns, NM_SETTING_IP4_CONFIG_DNS) +DEFINE_GETTER (nmc_property_ipv4_get_dns_search, NM_SETTING_IP4_CONFIG_DNS_SEARCH) +DEFINE_GETTER (nmc_property_ipv4_get_addresses, NM_SETTING_IP4_CONFIG_ADDRESSES) +DEFINE_GETTER (nmc_property_ipv4_get_routes, NM_SETTING_IP4_CONFIG_ROUTES) +DEFINE_GETTER (nmc_property_ipv4_get_ignore_auto_routes, NM_SETTING_IP4_CONFIG_IGNORE_AUTO_ROUTES) +DEFINE_GETTER (nmc_property_ipv4_get_ignore_auto_dns, NM_SETTING_IP4_CONFIG_IGNORE_AUTO_DNS) +DEFINE_GETTER (nmc_property_ipv4_get_dhcp_client_id, NM_SETTING_IP4_CONFIG_DHCP_CLIENT_ID) +DEFINE_GETTER (nmc_property_ipv4_get_dhcp_send_hostname, NM_SETTING_IP4_CONFIG_DHCP_SEND_HOSTNAME) +DEFINE_GETTER (nmc_property_ipv4_get_dhcp_hostname, NM_SETTING_IP4_CONFIG_DHCP_HOSTNAME) +DEFINE_GETTER (nmc_property_ipv4_get_never_default, NM_SETTING_IP4_CONFIG_NEVER_DEFAULT) +DEFINE_GETTER (nmc_property_ipv4_get_may_fail, NM_SETTING_IP4_CONFIG_MAY_FAIL) + +/* --- NM_SETTING_IP6_CONFIG_SETTING_NAME property get functions --- */ +DEFINE_GETTER (nmc_property_ipv6_get_method, NM_SETTING_IP6_CONFIG_METHOD) +DEFINE_GETTER (nmc_property_ipv6_get_dns, NM_SETTING_IP6_CONFIG_DNS) +DEFINE_GETTER (nmc_property_ipv6_get_dns_search, NM_SETTING_IP6_CONFIG_DNS_SEARCH) +DEFINE_GETTER (nmc_property_ipv6_get_addresses, NM_SETTING_IP6_CONFIG_ADDRESSES) +DEFINE_GETTER (nmc_property_ipv6_get_routes, NM_SETTING_IP6_CONFIG_ROUTES) +DEFINE_GETTER (nmc_property_ipv6_get_ignore_auto_routes, NM_SETTING_IP6_CONFIG_IGNORE_AUTO_ROUTES) +DEFINE_GETTER (nmc_property_ipv6_get_ignore_auto_dns, NM_SETTING_IP6_CONFIG_IGNORE_AUTO_DNS) +DEFINE_GETTER (nmc_property_ipv6_get_never_default, NM_SETTING_IP6_CONFIG_NEVER_DEFAULT) +DEFINE_GETTER (nmc_property_ipv6_get_may_fail, NM_SETTING_IP6_CONFIG_MAY_FAIL) +DEFINE_GETTER (nmc_property_ipv6_get_dhcp_hostname, NM_SETTING_IP6_CONFIG_DHCP_HOSTNAME) - dns_search_str = g_string_new (NULL); - num = nm_setting_ip6_config_get_num_dns_searches (s_ip6); - for (i = 0; i < num; i++) { - const char *domain; +static char * +nmc_property_ipv6_get_ip6_privacy (NMSetting *setting) +{ + NMSettingIP6Config *s_ip6 = NM_SETTING_IP6_CONFIG (setting); + return ip6_privacy_to_string (nm_setting_ip6_config_get_ip6_privacy (s_ip6)); +} - domain = nm_setting_ip6_config_get_dns_search (s_ip6, i); - if (i > 0) - g_string_append (dns_search_str, ", "); - g_string_append (dns_search_str, domain); - } +/* --- NM_SETTING_OLPC_MESH_SETTING_NAME property get functions --- */ +DEFINE_GETTER (nmc_property_olpc_get_channel, NM_SETTING_OLPC_MESH_CHANNEL) +DEFINE_HWADDR_GETTER (nmc_property_olpc_get_anycast_address, NM_SETTING_OLPC_MESH_DHCP_ANYCAST_ADDRESS) - addr_str = g_string_new (NULL); - num = nm_setting_ip6_config_get_num_addresses (s_ip6); - for (i = 0; i < num; i++) { - char buf[INET6_ADDRSTRLEN]; - char *tmp; - NMIP6Address *addr; - const struct in6_addr *ip; +static char * +nmc_property_olpc_get_ssid (NMSetting *setting) +{ + NMSettingOlpcMesh *s_olpc_mesh = NM_SETTING_OLPC_MESH (setting); + const GByteArray *ssid; + char *ssid_str = NULL; - if (i > 0) - g_string_append (addr_str, "; "); + ssid = nm_setting_olpc_mesh_get_ssid (s_olpc_mesh); + if (ssid) + ssid_str = nm_utils_ssid_to_utf8 (ssid); - g_string_append (addr_str, "{ "); + return ssid_str; +} - addr = nm_setting_ip6_config_get_address (s_ip6, i); +/* --- NM_SETTING_PPP_SETTING_NAME property get functions --- */ +DEFINE_GETTER (nmc_property_ppp_get_noauth, NM_SETTING_PPP_NOAUTH) +DEFINE_GETTER (nmc_property_ppp_get_refuse_eap, NM_SETTING_PPP_REFUSE_EAP) +DEFINE_GETTER (nmc_property_ppp_get_refuse_pap, NM_SETTING_PPP_REFUSE_PAP) +DEFINE_GETTER (nmc_property_ppp_get_refuse_chap, NM_SETTING_PPP_REFUSE_CHAP) +DEFINE_GETTER (nmc_property_ppp_get_refuse_mschap, NM_SETTING_PPP_REFUSE_MSCHAP) +DEFINE_GETTER (nmc_property_ppp_get_refuse_mschapv2, NM_SETTING_PPP_REFUSE_MSCHAPV2) +DEFINE_GETTER (nmc_property_ppp_get_nobsdcomp, NM_SETTING_PPP_NOBSDCOMP) +DEFINE_GETTER (nmc_property_ppp_get_nodeflate, NM_SETTING_PPP_NODEFLATE) +DEFINE_GETTER (nmc_property_ppp_get_no_vj_comp, NM_SETTING_PPP_NO_VJ_COMP) +DEFINE_GETTER (nmc_property_ppp_get_require_mppe, NM_SETTING_PPP_REQUIRE_MPPE) +DEFINE_GETTER (nmc_property_ppp_get_require_mppe_128, NM_SETTING_PPP_REQUIRE_MPPE_128) +DEFINE_GETTER (nmc_property_ppp_get_mppe_stateful, NM_SETTING_PPP_MPPE_STATEFUL) +DEFINE_GETTER (nmc_property_ppp_get_crtscts, NM_SETTING_PPP_CRTSCTS) +DEFINE_GETTER (nmc_property_ppp_get_baud, NM_SETTING_PPP_BAUD) +DEFINE_GETTER (nmc_property_ppp_get_mru, NM_SETTING_PPP_MRU) +DEFINE_GETTER (nmc_property_ppp_get_mtu, NM_SETTING_PPP_MTU) +DEFINE_GETTER (nmc_property_ppp_get_lcp_echo_failure, NM_SETTING_PPP_LCP_ECHO_FAILURE) +DEFINE_GETTER (nmc_property_ppp_get_lcp_echo_interval, NM_SETTING_PPP_LCP_ECHO_INTERVAL) + +/* --- NM_SETTING_PPPOE_SETTING_NAME property get functions --- */ +DEFINE_GETTER (nmc_property_pppoe_get_service, NM_SETTING_PPPOE_SERVICE) +DEFINE_GETTER (nmc_property_pppoe_get_username, NM_SETTING_PPPOE_USERNAME) +DEFINE_GETTER (nmc_property_pppoe_get_password, NM_SETTING_PPPOE_PASSWORD) +DEFINE_SECRET_FLAGS_GETTER (nmc_property_pppoe_get_password_flags, NM_SETTING_PPPOE_PASSWORD_FLAGS) + +/* --- NM_SETTING_SERIAL_SETTING_NAME property get functions --- */ +DEFINE_GETTER (nmc_property_serial_get_baud, NM_SETTING_SERIAL_BAUD) +DEFINE_GETTER (nmc_property_serial_get_bits, NM_SETTING_SERIAL_BITS) +DEFINE_GETTER (nmc_property_serial_get_parity, NM_SETTING_SERIAL_PARITY) +DEFINE_GETTER (nmc_property_serial_get_stopbits, NM_SETTING_SERIAL_STOPBITS) +DEFINE_GETTER (nmc_property_serial_get_send_delay, NM_SETTING_SERIAL_SEND_DELAY) + +/* --- NM_SETTING_VLAN_SETTING_NAME property get functions --- */ +DEFINE_GETTER (nmc_property_vlan_get_interface_name, NM_SETTING_VLAN_INTERFACE_NAME) +DEFINE_GETTER (nmc_property_vlan_get_parent, NM_SETTING_VLAN_PARENT) +DEFINE_GETTER (nmc_property_vlan_get_id, NM_SETTING_VLAN_ID) - memset (buf, 0, sizeof (buf)); - ip = nm_ip6_address_get_address (addr); - inet_ntop (AF_INET6, (const void *) ip, buf, sizeof (buf)); - g_string_append_printf (addr_str, "ip = %s", buf); - tmp = g_strdup_printf ("/%u", nm_ip6_address_get_prefix (addr)); - g_string_append (addr_str, tmp); - g_free (tmp); +static char * +nmc_property_vlan_get_flags (NMSetting *setting) +{ + NMSettingVlan *s_vlan = NM_SETTING_VLAN (setting); + return vlan_flags_to_string (nm_setting_vlan_get_flags (s_vlan)); +} - memset (buf, 0, sizeof (buf)); - ip = nm_ip6_address_get_gateway (addr); - inet_ntop (AF_INET6, (const void *) ip, buf, sizeof (buf)); - g_string_append_printf (addr_str, ", gw = %s", buf); +static char * +nmc_property_vlan_get_ingress_priority_map (NMSetting *setting) +{ + NMSettingVlan *s_vlan = NM_SETTING_VLAN (setting); + return vlan_priorities_to_string (s_vlan, NM_VLAN_INGRESS_MAP); +} - g_string_append (addr_str, " }"); - } +static char * +nmc_property_vlan_get_egress_priority_map (NMSetting *setting) +{ + NMSettingVlan *s_vlan = NM_SETTING_VLAN (setting); + return vlan_priorities_to_string (s_vlan, NM_VLAN_EGRESS_MAP); +} - route_str = g_string_new (NULL); - num = nm_setting_ip6_config_get_num_routes (s_ip6); - for (i = 0; i < num; i++) { - char buf[INET6_ADDRSTRLEN]; - char *tmp; - NMIP6Route *route; - const struct in6_addr *ip; +/* --- NM_SETTING_VPN_SETTING_NAME property get functions --- */ +DEFINE_GETTER (nmc_property_vpn_get_service_type, NM_SETTING_VPN_SERVICE_TYPE) +DEFINE_GETTER (nmc_property_vpn_get_user_name, NM_SETTING_VPN_USER_NAME) - if (i > 0) - g_string_append (route_str, "; "); +static char * +nmc_property_vpn_get_data (NMSetting *setting) +{ + NMSettingVPN *s_vpn = NM_SETTING_VPN (setting); + GString *data_item_str; - g_string_append (route_str, "{ "); + data_item_str = g_string_new (NULL); + nm_setting_vpn_foreach_data_item (s_vpn, &vpn_data_item, data_item_str); - route = nm_setting_ip6_config_get_route (s_ip6, i); + return g_string_free (data_item_str, FALSE); +} - memset (buf, 0, sizeof (buf)); - ip = nm_ip6_route_get_dest (route); - inet_ntop (AF_INET6, (const void *) ip, buf, sizeof (buf)); - g_string_append_printf (route_str, "dst = %s", buf); +static char * +nmc_property_vpn_get_secrets (NMSetting *setting) +{ + NMSettingVPN *s_vpn = NM_SETTING_VPN (setting); + GString *secret_str; - tmp = g_strdup_printf ("/%u", nm_ip6_route_get_prefix (route)); - g_string_append (route_str, tmp); - g_free (tmp); + secret_str = g_string_new (NULL); + nm_setting_vpn_foreach_secret (s_vpn, &vpn_data_item, secret_str); - memset (buf, 0, sizeof (buf)); - ip = nm_ip6_route_get_next_hop (route); - inet_ntop (AF_INET6, (const void *) ip, buf, sizeof (buf)); - g_string_append_printf (route_str, ", nh = %s", buf); + return g_string_free (secret_str, FALSE); +} - tmp = g_strdup_printf (", mt = %u", nm_ip6_route_get_metric (route)); - g_string_append (route_str, tmp); - g_free (tmp); +/* --- NM_SETTING_WIMAX_SETTING_NAME property get functions --- */ +DEFINE_GETTER (nmc_property_wimax_get_network_name, NM_SETTING_WIMAX_NETWORK_NAME) +DEFINE_HWADDR_GETTER (nmc_property_wimax_get_mac_address, NM_SETTING_WIMAX_MAC_ADDRESS) + +/* --- NM_SETTING_WIRED_SETTING_NAME property get functions --- */ +DEFINE_GETTER (nmc_property_wired_get_port, NM_SETTING_WIRED_PORT) +DEFINE_GETTER (nmc_property_wired_get_speed, NM_SETTING_WIRED_SPEED) +DEFINE_GETTER (nmc_property_wired_get_duplex, NM_SETTING_WIRED_DUPLEX) +DEFINE_GETTER (nmc_property_wired_get_auto_negotiate, NM_SETTING_WIRED_AUTO_NEGOTIATE) +DEFINE_HWADDR_GETTER (nmc_property_wired_get_mac_address, NM_SETTING_WIRED_MAC_ADDRESS) +DEFINE_HWADDR_GETTER (nmc_property_wired_get_cloned_mac_address, NM_SETTING_WIRED_CLONED_MAC_ADDRESS) +DEFINE_GETTER (nmc_property_wired_get_mac_address_blacklist, NM_SETTING_WIRED_MAC_ADDRESS_BLACKLIST) +DEFINE_GETTER (nmc_property_wired_get_s390_subchannels, NM_SETTING_WIRED_S390_SUBCHANNELS) +DEFINE_GETTER (nmc_property_wired_get_s390_nettype, NM_SETTING_WIRED_S390_NETTYPE) +DEFINE_GETTER (nmc_property_wired_get_s390_options, NM_SETTING_WIRED_S390_OPTIONS) - g_string_append (route_str, " }"); - } +static char * +nmc_property_wired_get_mtu (NMSetting *setting) +{ + NMSettingWired *s_wired = NM_SETTING_WIRED (setting); + int mtu; - ip6_privacy_str = ip6_privacy_to_string (nm_setting_ip6_config_get_ip6_privacy (s_ip6)); + mtu = nm_setting_wired_get_mtu (s_wired); + if (mtu == 0) + return g_strdup (_("auto")); + else + return g_strdup_printf ("%d", mtu); +} - nmc->allowed_fields[0].value = NM_SETTING_IP6_CONFIG_SETTING_NAME; - nmc->allowed_fields[1].value = nm_setting_ip6_config_get_method (s_ip6); - nmc->allowed_fields[2].value = dns_str->str; - nmc->allowed_fields[3].value = dns_search_str->str; - nmc->allowed_fields[4].value = addr_str->str; - nmc->allowed_fields[5].value = route_str->str; - nmc->allowed_fields[6].value = nm_setting_ip6_config_get_ignore_auto_routes (s_ip6) ? _("yes") : _("no"); - nmc->allowed_fields[7].value = nm_setting_ip6_config_get_ignore_auto_dns (s_ip6) ? _("yes") : _("no"); - nmc->allowed_fields[8].value = nm_setting_ip6_config_get_never_default (s_ip6) ? _("yes") : _("no"); - nmc->allowed_fields[9].value = nm_setting_ip6_config_get_may_fail (s_ip6) ? _("yes") : _("no"); - nmc->allowed_fields[10].value = ip6_privacy_str; - nmc->allowed_fields[11].value = nm_setting_ip6_config_get_dhcp_hostname (s_ip6); +/* --- NM_SETTING_WIRELESS_SETTING_NAME property get functions --- */ +DEFINE_GETTER (nmc_property_wireless_get_mode, NM_SETTING_WIRELESS_MODE) +DEFINE_GETTER (nmc_property_wireless_get_band, NM_SETTING_WIRELESS_BAND) +DEFINE_GETTER (nmc_property_wireless_get_channel, NM_SETTING_WIRELESS_CHANNEL) +DEFINE_HWADDR_GETTER (nmc_property_wireless_get_bssid, NM_SETTING_WIRELESS_BSSID) +DEFINE_GETTER (nmc_property_wireless_get_rate, NM_SETTING_WIRELESS_RATE) +DEFINE_GETTER (nmc_property_wireless_get_tx_power, NM_SETTING_WIRELESS_TX_POWER) +DEFINE_HWADDR_GETTER (nmc_property_wireless_get_mac_address, NM_SETTING_WIRELESS_MAC_ADDRESS) +DEFINE_HWADDR_GETTER (nmc_property_wireless_get_cloned_mac_address, NM_SETTING_WIRELESS_CLONED_MAC_ADDRESS) +DEFINE_GETTER (nmc_property_wireless_get_mac_address_blacklist, NM_SETTING_WIRELESS_MAC_ADDRESS_BLACKLIST) +DEFINE_GETTER (nmc_property_wireless_get_seen_bssids, NM_SETTING_WIRELESS_SEEN_BSSIDS) +DEFINE_GETTER (nmc_property_wireless_get_hidden, NM_SETTING_WIRELESS_HIDDEN) - nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag | NMC_PF_FLAG_SECTION_PREFIX; - print_fields (nmc->print_fields, nmc->allowed_fields); /* Print values */ +static char * +nmc_property_wireless_get_ssid (NMSetting *setting) +{ + NMSettingWireless *s_wireless = NM_SETTING_WIRELESS (setting); + const GByteArray *ssid; + char *ssid_str = NULL; - g_string_free (dns_str, TRUE); - g_string_free (dns_search_str, TRUE); - g_string_free (addr_str, TRUE); - g_string_free (route_str, TRUE); - g_free (ip6_privacy_str); + ssid = nm_setting_wireless_get_ssid (s_wireless); + if (ssid) + ssid_str = nm_utils_ssid_to_utf8 (ssid); - return TRUE; + return ssid_str; } -gboolean -setting_serial_details (NMSettingSerial *s_serial, NmCli *nmc) +static char * +nmc_property_wireless_get_mtu (NMSetting *setting) { - char *baud_str, *bits_str, *parity_str, *stopbits_str, *send_delay_str; - guint32 mode_flag = (nmc->print_output == NMC_PRINT_PRETTY) ? NMC_PF_FLAG_PRETTY : (nmc->print_output == NMC_PRINT_TERSE) ? NMC_PF_FLAG_TERSE : 0; - guint32 multiline_flag = nmc->multiline_output ? NMC_PF_FLAG_MULTILINE : 0; - guint32 escape_flag = nmc->escape_values ? NMC_PF_FLAG_ESCAPE : 0; - - g_return_val_if_fail (NM_IS_SETTING_SERIAL (s_serial), FALSE); + NMSettingWireless *s_wireless = NM_SETTING_WIRELESS (setting); + int mtu; - nmc->allowed_fields = nmc_fields_setting_serial; - nmc->print_fields.indices = parse_output_fields (NMC_FIELDS_SETTING_SERIAL_ALL, nmc->allowed_fields, NULL); - nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag | NMC_PF_FLAG_FIELD_NAMES; - print_fields (nmc->print_fields, nmc->allowed_fields); /* Print field names */ - - baud_str = g_strdup_printf ("%d", nm_setting_serial_get_baud (s_serial)); - bits_str = g_strdup_printf ("%d", nm_setting_serial_get_bits (s_serial)); - parity_str = g_strdup_printf ("%c", nm_setting_serial_get_parity (s_serial)); - stopbits_str = g_strdup_printf ("%d", nm_setting_serial_get_stopbits (s_serial)); - send_delay_str = g_strdup_printf ("%" G_GUINT64_FORMAT, nm_setting_serial_get_send_delay (s_serial)); + mtu = nm_setting_wireless_get_mtu (s_wireless); + if (mtu == 0) + return g_strdup (_("auto")); + else + return g_strdup_printf ("%d", mtu); +} - nmc->allowed_fields[0].value = NM_SETTING_SERIAL_SETTING_NAME; - nmc->allowed_fields[1].value = baud_str; - nmc->allowed_fields[2].value = bits_str; - nmc->allowed_fields[3].value = parity_str; - nmc->allowed_fields[4].value = stopbits_str; - nmc->allowed_fields[5].value = send_delay_str; +/* --- NM_SETTING_WIRELESS_SECURITY_SETTING_NAME property get functions --- */ +DEFINE_GETTER (nmc_property_wifi_sec_get_key_mgmt, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT) +DEFINE_GETTER (nmc_property_wifi_sec_get_wep_tx_keyidx, NM_SETTING_WIRELESS_SECURITY_WEP_TX_KEYIDX) +DEFINE_GETTER (nmc_property_wifi_sec_get_auth_alg, NM_SETTING_WIRELESS_SECURITY_AUTH_ALG) +DEFINE_GETTER (nmc_property_wifi_sec_get_proto, NM_SETTING_WIRELESS_SECURITY_PROTO) +DEFINE_GETTER (nmc_property_wifi_sec_get_pairwise, NM_SETTING_WIRELESS_SECURITY_PAIRWISE) +DEFINE_GETTER (nmc_property_wifi_sec_get_group, NM_SETTING_WIRELESS_SECURITY_GROUP) +DEFINE_GETTER (nmc_property_wifi_sec_get_leap_username, NM_SETTING_WIRELESS_SECURITY_LEAP_USERNAME) +DEFINE_SECRET_FLAGS_GETTER (nmc_property_wifi_sec_get_wep_key_flags, NM_SETTING_WIRELESS_SECURITY_WEP_KEY_FLAGS) +DEFINE_GETTER (nmc_property_wifi_sec_get_psk, NM_SETTING_WIRELESS_SECURITY_PSK) +DEFINE_SECRET_FLAGS_GETTER (nmc_property_wifi_sec_get_psk_flags, NM_SETTING_WIRELESS_SECURITY_PSK_FLAGS) +DEFINE_GETTER (nmc_property_wifi_sec_get_leap_password, NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD) +DEFINE_SECRET_FLAGS_GETTER (nmc_property_wifi_sec_get_leap_password_flags, NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD_FLAGS) - nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag | NMC_PF_FLAG_SECTION_PREFIX; - print_fields (nmc->print_fields, nmc->allowed_fields); /* Print values */ +static char * +nmc_property_wifi_sec_get_wep_key0 (NMSetting *setting) +{ + NMSettingWirelessSecurity *s_wireless_sec = NM_SETTING_WIRELESS_SECURITY (setting); + return g_strdup (nm_setting_wireless_security_get_wep_key (s_wireless_sec, 0)); +} - g_free (baud_str); - g_free (bits_str); - g_free (parity_str); - g_free (stopbits_str); - g_free (send_delay_str); +static char * +nmc_property_wifi_sec_get_wep_key1 (NMSetting *setting) +{ + NMSettingWirelessSecurity *s_wireless_sec = NM_SETTING_WIRELESS_SECURITY (setting); + return g_strdup (nm_setting_wireless_security_get_wep_key (s_wireless_sec, 1)); +} - return TRUE; +static char * +nmc_property_wifi_sec_get_wep_key2 (NMSetting *setting) +{ + NMSettingWirelessSecurity *s_wireless_sec = NM_SETTING_WIRELESS_SECURITY (setting); + return g_strdup (nm_setting_wireless_security_get_wep_key (s_wireless_sec, 2)); } -gboolean -setting_ppp_details (NMSettingPPP *s_ppp, NmCli *nmc) +static char * +nmc_property_wifi_sec_get_wep_key3 (NMSetting *setting) { - char *baud_str, *mru_str, *mtu_str, *lcp_echo_failure_str, *lcp_echo_interval_str; - guint32 mode_flag = (nmc->print_output == NMC_PRINT_PRETTY) ? NMC_PF_FLAG_PRETTY : (nmc->print_output == NMC_PRINT_TERSE) ? NMC_PF_FLAG_TERSE : 0; - guint32 multiline_flag = nmc->multiline_output ? NMC_PF_FLAG_MULTILINE : 0; - guint32 escape_flag = nmc->escape_values ? NMC_PF_FLAG_ESCAPE : 0; + NMSettingWirelessSecurity *s_wireless_sec = NM_SETTING_WIRELESS_SECURITY (setting); + return g_strdup (nm_setting_wireless_security_get_wep_key (s_wireless_sec, 3)); +} - g_return_val_if_fail (NM_IS_SETTING_PPP (s_ppp), FALSE); +static char * +nmc_property_wifi_sec_get_wep_key_type (NMSetting *setting) +{ + NMSettingWirelessSecurity *s_wireless_sec = NM_SETTING_WIRELESS_SECURITY (setting); + return wep_key_type_to_string (nm_setting_wireless_security_get_wep_key_type (s_wireless_sec)); +} - nmc->allowed_fields = nmc_fields_setting_ppp; - nmc->print_fields.indices = parse_output_fields (NMC_FIELDS_SETTING_PPP_ALL, nmc->allowed_fields, NULL); - nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag | NMC_PF_FLAG_FIELD_NAMES; - print_fields (nmc->print_fields, nmc->allowed_fields); /* Print field names */ - - baud_str = g_strdup_printf ("%d", nm_setting_ppp_get_baud (s_ppp)); - mru_str = g_strdup_printf ("%d", nm_setting_ppp_get_mru (s_ppp)); - mtu_str = g_strdup_printf ("%d", nm_setting_ppp_get_mtu (s_ppp)); - lcp_echo_failure_str = g_strdup_printf ("%d", nm_setting_ppp_get_lcp_echo_failure (s_ppp)); - lcp_echo_interval_str = g_strdup_printf ("%d", nm_setting_ppp_get_lcp_echo_interval (s_ppp)); - - nmc->allowed_fields[0].value = NM_SETTING_PPP_SETTING_NAME; - nmc->allowed_fields[1].value = nm_setting_ppp_get_noauth (s_ppp) ? _("yes") : _("no"); - nmc->allowed_fields[2].value = nm_setting_ppp_get_refuse_eap (s_ppp) ? _("yes") : _("no"); - nmc->allowed_fields[3].value = nm_setting_ppp_get_refuse_pap (s_ppp) ? _("yes") : _("no"); - nmc->allowed_fields[4].value = nm_setting_ppp_get_refuse_chap (s_ppp) ? _("yes") : _("no"); - nmc->allowed_fields[5].value = nm_setting_ppp_get_refuse_mschap (s_ppp) ? _("yes") : _("no"); - nmc->allowed_fields[6].value = nm_setting_ppp_get_refuse_mschapv2 (s_ppp) ? _("yes") : _("no"); - nmc->allowed_fields[7].value = nm_setting_ppp_get_nobsdcomp (s_ppp) ? _("yes") : _("no"); - nmc->allowed_fields[8].value = nm_setting_ppp_get_nodeflate (s_ppp) ? _("yes") : _("no"); - nmc->allowed_fields[9].value = nm_setting_ppp_get_no_vj_comp (s_ppp) ? _("yes") : _("no"); - nmc->allowed_fields[10].value = nm_setting_ppp_get_require_mppe (s_ppp) ? _("yes") : _("no"); - nmc->allowed_fields[11].value = nm_setting_ppp_get_require_mppe_128 (s_ppp) ? _("yes") : _("no"); - nmc->allowed_fields[12].value = nm_setting_ppp_get_mppe_stateful (s_ppp) ? _("yes") : _("no"); - nmc->allowed_fields[13].value = nm_setting_ppp_get_crtscts (s_ppp) ? _("yes") : _("no"); - nmc->allowed_fields[14].value = baud_str; - nmc->allowed_fields[15].value = mru_str; - nmc->allowed_fields[16].value = mtu_str; - nmc->allowed_fields[17].value = lcp_echo_failure_str; - nmc->allowed_fields[18].value = lcp_echo_interval_str; - - nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag | NMC_PF_FLAG_SECTION_PREFIX; - print_fields (nmc->print_fields, nmc->allowed_fields); /* Print values */ - - g_free (baud_str); - g_free (mru_str); - g_free (mtu_str); - g_free (lcp_echo_failure_str); - g_free (lcp_echo_interval_str); +/*----------------------------------------------------------------------------*/ - return TRUE; +static void +nmc_value_transform_bool_string (const GValue *src_value, + GValue *dest_value) +{ + dest_value->data[0].v_pointer = g_strdup (src_value->data[0].v_int ? "yes" : "no"); } -gboolean -setting_pppoe_details (NMSettingPPPOE *s_pppoe, NmCli *nmc) +static void +nmc_value_transform_char_string (const GValue *src_value, + GValue *dest_value) { - char *pswd_flags; - guint32 mode_flag = (nmc->print_output == NMC_PRINT_PRETTY) ? NMC_PF_FLAG_PRETTY : (nmc->print_output == NMC_PRINT_TERSE) ? NMC_PF_FLAG_TERSE : 0; - guint32 multiline_flag = nmc->multiline_output ? NMC_PF_FLAG_MULTILINE : 0; - guint32 escape_flag = nmc->escape_values ? NMC_PF_FLAG_ESCAPE : 0; - - g_return_val_if_fail (NM_IS_SETTING_PPPOE (s_pppoe), FALSE); + dest_value->data[0].v_pointer = g_strdup_printf ("%c", src_value->data[0].v_uint); +} - nmc->allowed_fields = nmc_fields_setting_pppoe; - nmc->print_fields.indices = parse_output_fields (NMC_FIELDS_SETTING_PPPOE_ALL, nmc->allowed_fields, NULL); - nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag | NMC_PF_FLAG_FIELD_NAMES; - print_fields (nmc->print_fields, nmc->allowed_fields); /* Print field names */ +static void __attribute__((constructor)) +register_nmcli_value_transforms (void) +{ + g_value_register_transform_func (G_TYPE_BOOLEAN, G_TYPE_STRING, nmc_value_transform_bool_string); + g_value_register_transform_func (G_TYPE_CHAR, G_TYPE_STRING, nmc_value_transform_char_string); +} - pswd_flags = secret_flags_to_string (nm_setting_pppoe_get_password_flags (s_pppoe)); +/*----------------------------------------------------------------------------*/ - nmc->allowed_fields[0].value = NM_SETTING_PPPOE_SETTING_NAME; - nmc->allowed_fields[1].value = nm_setting_pppoe_get_service (s_pppoe); - nmc->allowed_fields[2].value = nm_setting_pppoe_get_username (s_pppoe); - nmc->allowed_fields[3].value = nm_setting_pppoe_get_password (s_pppoe); - nmc->allowed_fields[4].value = pswd_flags; +/* Main hash table storing function pointer for manipulating properties */ +static GHashTable *nmc_properties = NULL; +typedef char * (*NmcPropertyGetFunc) (NMSetting *); +typedef gboolean (*NmcPropertySetFunc) (NMSetting *, const char *, const char *, GError **); +typedef gboolean (*NmcPropertyRemoveFunc) (NMSetting *, const char *, const char *, guint32, GError **); +typedef const char * (*NmcPropertyDescribeFunc) (NMSetting *, const char *); +typedef const char * (*NmcPropertyValuesFunc) (NMSetting *, const char *); +typedef char * (*NmcPropertyOut2InFunc) (const char *); + +typedef struct { + NmcPropertyGetFunc get_func; /* func getting property values */ + NmcPropertySetFunc set_func; /* func adding/setting property values */ + NmcPropertyRemoveFunc remove_func; /* func removing items from container options */ + NmcPropertyDescribeFunc describe_func; /* func returning property description */ + NmcPropertyValuesFunc values_func; /* func returning allowed property values */ + NmcPropertyOut2InFunc out2in_func; /* func converting property values from output to input format */ +} NmcPropertyFuncs; + +/* + * We need NmCli in some _set_property functions, and they aren't passed NmCli. + * So use the global variable. + */ +/* Global variable defined in nmcli.c */ +extern NmCli nm_cli; - nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag | NMC_PF_FLAG_SECTION_PREFIX; - print_fields (nmc->print_fields, nmc->allowed_fields); /* Print values */ +NMSetting * +nmc_setting_new_for_name (const char *name) +{ + GType stype; + NMSetting *setting = NULL; + + if (name) { + stype = nm_connection_lookup_setting_type (name); + if (stype != G_TYPE_INVALID) { + setting = g_object_new (stype, NULL); + g_warn_if_fail (NM_IS_SETTING (setting)); + } + } + return setting; +} - g_free (pswd_flags); +static gboolean +get_answer (const char *prop, const char *value) +{ + char *tmp_str; + char *question; + gboolean answer = FALSE; - return TRUE; + if (value) + question = g_strdup_printf (_("Do you also want to set '%s' to '%s'? [yes]: "), prop, value); + else + question = g_strdup_printf (_("Do you also want to clear '%s'? [yes]: "), prop); + tmp_str = nmc_get_user_input (question); + if (!tmp_str || matches (tmp_str, "yes") == 0) + answer = TRUE; + g_free (tmp_str); + g_free (question); + return answer; } -gboolean -setting_gsm_details (NMSettingGsm *s_gsm, NmCli *nmc) -{ - char *network_type_str, *allowed_bands_str, *pswd_flags, *pin_flags; - guint32 mode_flag = (nmc->print_output == NMC_PRINT_PRETTY) ? NMC_PF_FLAG_PRETTY : (nmc->print_output == NMC_PRINT_TERSE) ? NMC_PF_FLAG_TERSE : 0; - guint32 multiline_flag = nmc->multiline_output ? NMC_PF_FLAG_MULTILINE : 0; - guint32 escape_flag = nmc->escape_values ? NMC_PF_FLAG_ESCAPE : 0; +static void ipv4_method_changed_cb (GObject *object, GParamSpec *pspec, gpointer user_data); +static void ipv6_method_changed_cb (GObject *object, GParamSpec *pspec, gpointer user_data); - g_return_val_if_fail (NM_IS_SETTING_GSM (s_gsm), FALSE); +static void +ipv4_addresses_changed_cb (GObject *object, GParamSpec *pspec, gpointer user_data) +{ + static gboolean answered = FALSE; + static gboolean answer = FALSE; + + g_signal_handlers_block_by_func (object, G_CALLBACK (ipv4_method_changed_cb), NULL); + + /* If we have some IP addresses set method to 'manual'. + * Else if the method was 'manual', change it back to 'auto'. + */ + if (nm_setting_ip4_config_get_num_addresses (NM_SETTING_IP4_CONFIG (object))) { + if (g_strcmp0 (nm_setting_ip4_config_get_method (NM_SETTING_IP4_CONFIG (object)), NM_SETTING_IP4_CONFIG_METHOD_MANUAL)) { + if (!answered) { + answered = TRUE; + answer = get_answer ("ipv4.method", "manual"); + } + if (answer) + g_object_set (object, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL, NULL); + } + } else { + answered = FALSE; + if (!g_strcmp0 (nm_setting_ip4_config_get_method (NM_SETTING_IP4_CONFIG (object)), NM_SETTING_IP4_CONFIG_METHOD_MANUAL)) + g_object_set (object, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); + } + + g_signal_handlers_unblock_by_func (object, G_CALLBACK (ipv4_method_changed_cb), NULL); +} + +static void +ipv4_method_changed_cb (GObject *object, GParamSpec *pspec, gpointer user_data) +{ + static GValue value = G_VALUE_INIT; + static gboolean answered = FALSE; + static gboolean answer = FALSE; + + g_signal_handlers_block_by_func (object, G_CALLBACK (ipv4_addresses_changed_cb), NULL); + + /* If method != manual, remove addresses (save them for restoring them later when method becomes 'manual' */ + if (g_strcmp0 (nm_setting_ip4_config_get_method (NM_SETTING_IP4_CONFIG (object)), NM_SETTING_IP4_CONFIG_METHOD_MANUAL)) { + if (nm_setting_ip4_config_get_num_addresses (NM_SETTING_IP4_CONFIG (object))) { + if (!answered) { + answered = TRUE; + answer = get_answer ("ipv4.addresses", NULL); + } + if (answer) { + if (G_IS_VALUE (&value)) + g_value_unset (&value); + nmc_property_get_gvalue (NM_SETTING (object), NM_SETTING_IP4_CONFIG_ADDRESSES, &value); + g_object_set (object, NM_SETTING_IP4_CONFIG_ADDRESSES, NULL, NULL); + } + } + } else { + answered = FALSE; + if (G_IS_VALUE (&value)) { + nmc_property_set_gvalue (NM_SETTING (object), NM_SETTING_IP4_CONFIG_ADDRESSES, &value); + g_value_unset (&value); + } + } + + g_signal_handlers_unblock_by_func (object, G_CALLBACK (ipv4_addresses_changed_cb), NULL); +} + +static void +ipv6_addresses_changed_cb (GObject *object, GParamSpec *pspec, gpointer user_data) +{ + static gboolean answered = FALSE; + static gboolean answer = FALSE; + + g_signal_handlers_block_by_func (object, G_CALLBACK (ipv6_method_changed_cb), NULL); + + /* If we have some IP addresses set method to 'manual'. + * Else if the method was 'manual', change it back to 'auto'. + */ + if (nm_setting_ip6_config_get_num_addresses (NM_SETTING_IP6_CONFIG (object))) { + if (g_strcmp0 (nm_setting_ip6_config_get_method (NM_SETTING_IP6_CONFIG (object)), NM_SETTING_IP6_CONFIG_METHOD_MANUAL)) { + if (!answered) { + answered = TRUE; + answer = get_answer ("ipv6.method", "manual"); + } + if (answer) + g_object_set (object, NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_MANUAL, NULL); + } + } else { + answered = FALSE; + if (!g_strcmp0 (nm_setting_ip6_config_get_method (NM_SETTING_IP6_CONFIG (object)), NM_SETTING_IP6_CONFIG_METHOD_MANUAL)) + g_object_set (object, NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO, NULL); + } + + g_signal_handlers_unblock_by_func (object, G_CALLBACK (ipv6_method_changed_cb), NULL); +} + +static void +ipv6_method_changed_cb (GObject *object, GParamSpec *pspec, gpointer user_data) +{ + static GValue value = G_VALUE_INIT; + static gboolean answered = FALSE; + static gboolean answer = FALSE; + + g_signal_handlers_block_by_func (object, G_CALLBACK (ipv6_addresses_changed_cb), NULL); + + /* If method != manual, remove addresses (save them for restoring them later when method becomes 'manual' */ + if (g_strcmp0 (nm_setting_ip6_config_get_method (NM_SETTING_IP6_CONFIG (object)), NM_SETTING_IP6_CONFIG_METHOD_MANUAL)) { + if (nm_setting_ip6_config_get_num_addresses (NM_SETTING_IP6_CONFIG (object))) { + if (!answered) { + answered = TRUE; + answer = get_answer ("ipv6.addresses", NULL); + } + if (answer) { + if (G_IS_VALUE (&value)) + g_value_unset (&value); + nmc_property_get_gvalue (NM_SETTING (object), NM_SETTING_IP6_CONFIG_ADDRESSES, &value); + g_object_set (object, NM_SETTING_IP6_CONFIG_ADDRESSES, NULL, NULL); + } + } + } else { + answered = FALSE; + if (G_IS_VALUE (&value)) { + nmc_property_set_gvalue (NM_SETTING (object), NM_SETTING_IP6_CONFIG_ADDRESSES, &value); + g_value_unset (&value); + } + } + + g_signal_handlers_unblock_by_func (object, G_CALLBACK (ipv6_addresses_changed_cb), NULL); +} + +static void +wireless_band_channel_changed_cb (GObject *object, GParamSpec *pspec, gpointer user_data) +{ + const char *value = NULL, *mode; + char str[16]; + NMSettingWireless *s_wireless = NM_SETTING_WIRELESS (object); + + if (strcmp (g_param_spec_get_name (pspec), NM_SETTING_WIRELESS_BAND) == 0) { + value = nm_setting_wireless_get_band (s_wireless); + if (!value) + return; + } else { + guint32 channel = nm_setting_wireless_get_channel (s_wireless); + + if (channel == 0) + return; + + g_snprintf (str, sizeof (str), "%d", nm_setting_wireless_get_channel (s_wireless)); + value = str; + } + + mode = nm_setting_wireless_get_mode (NM_SETTING_WIRELESS (object)); + if (!mode || !*mode || strcmp (mode, NM_SETTING_WIRELESS_MODE_INFRA) == 0) { + printf (_("Warning: %s.%s set to '%s', but it might be ignored in infrastructure mode\n"), + nm_setting_get_name (NM_SETTING (s_wireless)), g_param_spec_get_name (pspec), + value); + } +} + +void +nmc_setting_ip4_connect_handlers (NMSettingIP4Config *setting) +{ + g_return_if_fail (NM_IS_SETTING_IP4_CONFIG (setting)); + + g_signal_connect (setting, "notify::" NM_SETTING_IP4_CONFIG_ADDRESSES, + G_CALLBACK (ipv4_addresses_changed_cb), NULL); + g_signal_connect (setting, "notify::" NM_SETTING_IP4_CONFIG_METHOD, + G_CALLBACK (ipv4_method_changed_cb), NULL); +} + +void +nmc_setting_ip6_connect_handlers (NMSettingIP6Config *setting) +{ + g_return_if_fail (NM_IS_SETTING_IP6_CONFIG (setting)); + + g_signal_connect (setting, "notify::" NM_SETTING_IP6_CONFIG_ADDRESSES, + G_CALLBACK (ipv6_addresses_changed_cb), NULL); + g_signal_connect (setting, "notify::" NM_SETTING_IP6_CONFIG_METHOD, + G_CALLBACK (ipv6_method_changed_cb), NULL); +} + +void +nmc_setting_wireless_connect_handlers (NMSettingWireless *setting) +{ + g_return_if_fail (NM_IS_SETTING_WIRELESS (setting)); + + g_signal_connect (setting, "notify::" NM_SETTING_WIRELESS_BAND, + G_CALLBACK (wireless_band_channel_changed_cb), NULL); + g_signal_connect (setting, "notify::" NM_SETTING_WIRELESS_CHANNEL, + G_CALLBACK (wireless_band_channel_changed_cb), NULL); +} + +/* + * Customize some properties of the setting so that the setting has sensible + * values. + */ +void +nmc_setting_custom_init (NMSetting *setting) +{ + g_return_if_fail (NM_IS_SETTING (setting)); + + if (NM_IS_SETTING_IP4_CONFIG (setting)) { + g_object_set (NM_SETTING_IP4_CONFIG (setting), + NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, + NULL); + nmc_setting_ip4_connect_handlers (NM_SETTING_IP4_CONFIG (setting)); + } else if (NM_IS_SETTING_IP6_CONFIG (setting)) { + g_object_set (NM_SETTING_IP6_CONFIG (setting), + NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO, + NULL); + nmc_setting_ip6_connect_handlers (NM_SETTING_IP6_CONFIG (setting)); + } else if (NM_IS_SETTING_WIRELESS (setting)) { + g_object_set (NM_SETTING_WIRELESS (setting), + NM_SETTING_WIRELESS_MODE, NM_SETTING_WIRELESS_MODE_INFRA, + NULL); + nmc_setting_wireless_connect_handlers (NM_SETTING_WIRELESS (setting)); + } +} + +/* === SetFunc, RemoveFunc, DescribeFunc, ValuesFunc functions === */ +static gboolean +verify_string_list (char **strv, + const char *prop, + gboolean (*validate_func) (const char *), + GError **error) +{ + char **iter; + + g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + + for (iter = strv; iter && *iter; iter++) { + if (**iter == '\0') + continue; + if (validate_func) { + if (!validate_func (*iter)) { + g_set_error (error, 1, 0, _("'%s' is not valid"), + *iter); + return FALSE; + } + } + } + return TRUE; +} + +/* Validate 'val' number against to int property spec */ +static gboolean +validate_int (NMSetting *setting, const char* prop, gint val, GError **error) +{ + GParamSpec *pspec; + GValue value = G_VALUE_INIT; + gboolean success = TRUE; + + g_value_init (&value, G_TYPE_INT); + g_value_set_int (&value, val); + pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (G_OBJECT (setting)), prop); + g_assert (G_IS_PARAM_SPEC (pspec)); + if (g_param_value_validate (pspec, &value)) { + GParamSpecInt *pspec_int = (GParamSpecInt *) pspec; + g_set_error (error, 1, 0, _("'%d' is not valid; use <%d-%d>"), + val, pspec_int->minimum, pspec_int->maximum); + success = FALSE; + } + g_value_unset (&value); + return success; +} + +/* Validate 'val' number against to uint property spec */ +static gboolean +validate_uint (NMSetting *setting, const char* prop, guint val, GError **error) +{ + GParamSpec *pspec; + GValue value = G_VALUE_INIT; + gboolean success = TRUE; + + g_value_init (&value, G_TYPE_UINT); + g_value_set_uint (&value, val); + pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (G_OBJECT (setting)), prop); + g_assert (G_IS_PARAM_SPEC (pspec)); + if (g_param_value_validate (pspec, &value)) { + GParamSpecUInt *pspec_uint = (GParamSpecUInt *) pspec; + g_set_error (error, 1, 0, _("'%u' is not valid; use <%d-%d>"), + val, pspec_uint->minimum, pspec_uint->maximum); + success = FALSE; + } + g_value_unset (&value); + return success; +} + +static gboolean +check_and_set_string (NMSetting *setting, + const char *prop, + const char *val, + const char **valid_strv, + GError **error) +{ + const char *checked_val; + + g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + + checked_val = nmc_string_is_valid (val, valid_strv, error); + if (!checked_val) + return FALSE; + + g_object_set (setting, prop, checked_val, NULL); + return TRUE; +} + +#define DEFINE_SETTER_STR_LIST_MULTI(def_func, s_macro, set_func) \ + static gboolean \ + def_func (NMSetting *setting, \ + const char *prop, \ + const char *val, \ + const char **valid_strv, \ + GError **error) \ + { \ + char **strv = NULL, **iter; \ + const char *item; \ + g_return_val_if_fail (error == NULL || *error == NULL, FALSE); \ + strv = nmc_strsplit_set (val, " \t,", 0); \ + for (iter = strv; iter && *iter; iter++) { \ + if (!(item = nmc_string_is_valid (g_strstrip (*iter), valid_strv, error))) { \ + g_strfreev (strv); \ + return FALSE; \ + } \ + set_func (s_macro (setting), item); \ + } \ + g_strfreev (strv); \ + return TRUE; \ + } + +#define DEFINE_SETTER_OPTIONS(def_func, s_macro, s_type, add_func, valid_func1, valid_func2) \ + static gboolean \ + def_func (NMSetting *setting, const char *prop, const char *val, GError **error) \ + { \ + char **strv = NULL, **iter; \ + const char **(*valid_func1_p) (s_type *) = valid_func1; \ + const char * (*valid_func2_p) (const char *, const char *, GError **) = valid_func2; \ + const char *opt_name, *opt_val; \ + \ + g_return_val_if_fail (error == NULL || *error == NULL, FALSE); \ + \ + strv = nmc_strsplit_set (val, ",", 0); \ + for (iter = strv; iter && *iter; iter++) { \ + char *left = g_strstrip (*iter); \ + char *right = strchr (left, '='); \ + if (!right) { \ + g_set_error (error, 1, 0, _("'%s' is not valid; use