static gboolean validate (CEPage *page, NMConnection *connection, GError **error) { GtkWidget *entry; GByteArray *ignore; gboolean invalid; gchar *security; NMSettingWireless *setting; gboolean ret = TRUE; entry = gtk_bin_get_child (GTK_BIN (gtk_builder_get_object (page->builder, "combo_bssid"))); ignore = ce_page_entry_to_mac (GTK_ENTRY (entry), ARPHRD_ETHER, &invalid); if (invalid) { widget_set_error (entry); ret = FALSE; } else { if (ignore) g_byte_array_free (ignore, TRUE); widget_unset_error (entry); } entry = gtk_bin_get_child (GTK_BIN (gtk_builder_get_object (page->builder, "combo_mac"))); ignore = ce_page_entry_to_mac (GTK_ENTRY (entry), ARPHRD_ETHER, &invalid); if (invalid) { widget_set_error (entry); ret = FALSE; } else { if (ignore) g_byte_array_free (ignore, TRUE); widget_unset_error (entry); } entry = GTK_WIDGET (gtk_builder_get_object (page->builder, "entry_cloned_mac")); ignore = ce_page_entry_to_mac (GTK_ENTRY (entry), ARPHRD_ETHER, &invalid); if (invalid) { widget_set_error (entry); ret = FALSE; } else { if (ignore) g_byte_array_free (ignore, TRUE); widget_unset_error (entry); } if (!ret) return ret; ui_to_setting (CE_PAGE_WIFI (page)); /* A hack to not check the wifi security here */ setting = CE_PAGE_WIFI (page)->setting; security = g_strdup (nm_setting_wireless_get_security (setting)); g_object_set (setting, NM_SETTING_WIRELESS_SEC, NULL, NULL); ret = nm_setting_verify (NM_SETTING (setting), NULL, error); g_object_set (setting, NM_SETTING_WIRELESS_SEC, security, NULL); g_free (security); return ret; }
static gboolean validate (CEPage *page, NMConnection *connection, GError **error) { CEPageWired *self = CE_PAGE_WIRED (page); CEPageWiredPrivate *priv = CE_PAGE_WIRED_GET_PRIVATE (self); gboolean invalid = FALSE; GByteArray *ignore; GtkWidget *entry; entry = gtk_bin_get_child (GTK_BIN (priv->device_mac)); if (entry) { ignore = ce_page_entry_to_mac (GTK_ENTRY (entry), &invalid); if (invalid) return FALSE; if (ignore) g_byte_array_free (ignore, TRUE); } ignore = ce_page_entry_to_mac (priv->cloned_mac, &invalid); if (invalid) return FALSE; if (ignore) g_byte_array_free (ignore, TRUE); ui_to_setting (self); return nm_setting_verify (NM_SETTING (priv->setting), NULL, error); }
static void ui_to_setting (CEPageEthernet *page) { GByteArray *device_mac = NULL; GByteArray *cloned_mac = NULL; GtkWidget *entry; entry = gtk_bin_get_child (GTK_BIN (page->device_mac)); if (entry) device_mac = ce_page_entry_to_mac (GTK_ENTRY (entry), ARPHRD_ETHER, NULL); cloned_mac = ce_page_entry_to_mac (page->cloned_mac, ARPHRD_ETHER, NULL); g_object_set (page->setting_wired, NM_SETTING_WIRED_MAC_ADDRESS, device_mac, NM_SETTING_WIRED_CLONED_MAC_ADDRESS, cloned_mac, NM_SETTING_WIRED_MTU, (guint32) gtk_spin_button_get_value_as_int (page->mtu), NULL); if (device_mac) g_byte_array_free (device_mac, TRUE); if (cloned_mac) g_byte_array_free (cloned_mac, TRUE); g_object_set (page->setting_connection, NM_SETTING_CONNECTION_ID, gtk_entry_get_text (page->name), NULL); entry = GTK_WIDGET (gtk_builder_get_object (CE_PAGE (page)->builder, "combo_zone")); firewall_ui_to_setting (page->setting_connection, entry); }
static gboolean validate (CEPage *page, NMConnection *connection, GError **error) { CEPageWireless *self = CE_PAGE_WIRELESS (page); CEPageWirelessPrivate *priv = CE_PAGE_WIRELESS_GET_PRIVATE (self); char *security; gboolean success; gboolean invalid = FALSE; GByteArray *ignore; ignore = ce_page_entry_to_mac (priv->bssid, &invalid); if (invalid) return FALSE; ignore = ce_page_entry_to_mac (priv->mac, &invalid); if (invalid) return FALSE; ui_to_setting (self); /* A hack to not check the wireless security here */ security = g_strdup (nm_setting_wireless_get_security (priv->setting)); g_object_set (priv->setting, NM_SETTING_WIRELESS_SEC, NULL, NULL); success = nm_setting_verify (NM_SETTING (priv->setting), NULL, error); g_object_set (priv->setting, NM_SETTING_WIRELESS_SEC, security, NULL); g_free (security); return success; }
static void ui_to_setting (CEPageWireless *self) { CEPageWirelessPrivate *priv = CE_PAGE_WIRELESS_GET_PRIVATE (self); GByteArray *ssid; GByteArray *bssid = NULL; GByteArray *mac = NULL; const char *mode; const char *band; ssid = ce_page_wireless_get_ssid (self); if (gtk_combo_box_get_active (priv->mode) == 1) mode = "adhoc"; else mode = "infrastructure"; switch (gtk_combo_box_get_active (priv->band)) { case 1: band = "a"; break; case 2: band = "bg"; break; case 0: default: band = NULL; break; } bssid = ce_page_entry_to_mac (priv->bssid, NULL); mac = ce_page_entry_to_mac (priv->mac, NULL); g_object_set (priv->setting, NM_SETTING_WIRELESS_SSID, ssid, NM_SETTING_WIRELESS_BSSID, bssid, NM_SETTING_WIRELESS_MAC_ADDRESS, mac, NM_SETTING_WIRELESS_MODE, mode, NM_SETTING_WIRELESS_BAND, band, NM_SETTING_WIRELESS_CHANNEL, gtk_spin_button_get_value_as_int (priv->channel), NM_SETTING_WIRELESS_RATE, gtk_spin_button_get_value_as_int (priv->rate), NM_SETTING_WIRELESS_TX_POWER, gtk_spin_button_get_value_as_int (priv->tx_power), NM_SETTING_WIRELESS_MTU, gtk_spin_button_get_value_as_int (priv->mtu), NULL); if (ssid) g_byte_array_free (ssid, TRUE); if (mac) g_byte_array_free (mac, TRUE); if (bssid) g_byte_array_free (bssid, TRUE); }
static void ui_to_setting (CEPageWired *self) { CEPageWiredPrivate *priv = CE_PAGE_WIRED_GET_PRIVATE (self); const char *port; guint32 speed; GByteArray *mac = NULL; /* Port */ switch (gtk_combo_box_get_active (priv->port)) { case PORT_TP: port = "tp"; break; case PORT_AUI: port = "aui"; break; case PORT_BNC: port = "bnc"; break; case PORT_MII: port = "mii"; break; default: port = NULL; break; } /* Speed */ switch (gtk_combo_box_get_active (priv->speed)) { case SPEED_10: speed = 10; break; case SPEED_100: speed = 100; break; case SPEED_1000: speed = 1000; break; case SPEED_10000: speed = 10000; break; default: speed = 0; break; } mac = ce_page_entry_to_mac (priv->mac, NULL); g_object_set (priv->setting, NM_SETTING_WIRED_MAC_ADDRESS, mac, NM_SETTING_WIRED_PORT, port, NM_SETTING_WIRED_SPEED, speed, NM_SETTING_WIRED_DUPLEX, gtk_toggle_button_get_active (priv->duplex) ? "full" : "half", NM_SETTING_WIRED_AUTO_NEGOTIATE, gtk_toggle_button_get_active (priv->autonegotiate), NM_SETTING_WIRED_MTU, (guint32) gtk_spin_button_get_value_as_int (priv->mtu), NULL); if (mac) g_byte_array_free (mac, TRUE); }
static gboolean validate (CEPage *page, NMConnection *connection, GError **error) { CEPageWifi *self = CE_PAGE_WIFI (page); CEPageWifiPrivate *priv = CE_PAGE_WIFI_GET_PRIVATE (self); char *security; gboolean success; gboolean invalid = FALSE; GByteArray *ignore; GtkWidget *entry; entry = gtk_bin_get_child (GTK_BIN (priv->bssid)); if (entry) { ignore = ce_page_entry_to_mac (GTK_ENTRY (entry), ARPHRD_ETHER, &invalid); if (invalid) return FALSE; if (ignore) g_byte_array_free (ignore, TRUE); } entry = gtk_bin_get_child (GTK_BIN (priv->device_mac)); if (entry) { ignore = ce_page_entry_to_mac (GTK_ENTRY (entry), ARPHRD_ETHER, &invalid); if (invalid) return FALSE; if (ignore) g_byte_array_free (ignore, TRUE); } ignore = ce_page_entry_to_mac (priv->cloned_mac, ARPHRD_ETHER, &invalid); if (invalid) return FALSE; if (ignore) g_byte_array_free (ignore, TRUE); ui_to_setting (self); /* A hack to not check the wifi security here */ security = g_strdup (nm_setting_wireless_get_security (priv->setting)); g_object_set (priv->setting, NM_SETTING_WIRELESS_SEC, NULL, NULL); success = nm_setting_verify (NM_SETTING (priv->setting), NULL, error); g_object_set (priv->setting, NM_SETTING_WIRELESS_SEC, security, NULL); g_free (security); return success; }
static void ui_to_setting (CEPageWifi *page) { GByteArray *ssid; GByteArray *bssid = NULL; GByteArray *device_mac = NULL; GByteArray *cloned_mac = NULL; GtkWidget *entry; const gchar *utf8_ssid; NMSettingConnection *sc; entry = GTK_WIDGET (gtk_builder_get_object (CE_PAGE (page)->builder, "entry_ssid")); utf8_ssid = gtk_entry_get_text (GTK_ENTRY (entry)); if (!utf8_ssid || !*utf8_ssid) ssid = NULL; else { ssid = g_byte_array_sized_new (strlen (utf8_ssid)); g_byte_array_append (ssid, (const guint8*)utf8_ssid, strlen (utf8_ssid)); } entry = gtk_bin_get_child (GTK_BIN (gtk_builder_get_object (CE_PAGE (page)->builder, "combo_bssid"))); bssid = ce_page_entry_to_mac (GTK_ENTRY (entry), ARPHRD_ETHER, NULL); entry = gtk_bin_get_child (GTK_BIN (gtk_builder_get_object (CE_PAGE (page)->builder, "combo_mac"))); device_mac = ce_page_entry_to_mac (GTK_ENTRY (entry), ARPHRD_ETHER, NULL); entry = GTK_WIDGET (gtk_builder_get_object (CE_PAGE (page)->builder, "entry_cloned_mac")); cloned_mac = ce_page_entry_to_mac (GTK_ENTRY (entry), ARPHRD_ETHER, NULL); sc = nm_connection_get_setting_connection (CE_PAGE (page)->connection); entry = GTK_WIDGET (gtk_builder_get_object (CE_PAGE (page)->builder, "combo_zone")); firewall_ui_to_setting (sc, entry); g_object_set (page->setting, NM_SETTING_WIRELESS_SSID, ssid, NM_SETTING_WIRELESS_BSSID, bssid, NM_SETTING_WIRELESS_MAC_ADDRESS, device_mac, NM_SETTING_WIRELESS_CLONED_MAC_ADDRESS, cloned_mac, NULL); if (ssid) g_byte_array_free (ssid, TRUE); if (bssid) g_byte_array_free (bssid, TRUE); if (device_mac) g_byte_array_free (device_mac, TRUE); if (cloned_mac) g_byte_array_free (cloned_mac, TRUE); }
static gboolean validate (CEPage *page, NMConnection *connection, GError **error) { CEPageEthernet *self = CE_PAGE_ETHERNET (page); gboolean invalid = FALSE; GByteArray *ignore; GtkWidget *entry; gboolean ret = TRUE; entry = gtk_bin_get_child (GTK_BIN (self->device_mac)); if (entry) { ignore = ce_page_entry_to_mac (GTK_ENTRY (entry), ARPHRD_ETHER, &invalid); if (invalid) { widget_set_error (entry); ret = FALSE; } else { if (ignore) g_byte_array_free (ignore, TRUE); widget_unset_error (entry); } } ignore = ce_page_entry_to_mac (self->cloned_mac, ARPHRD_ETHER, &invalid); if (invalid) { widget_set_error (GTK_WIDGET (self->cloned_mac)); ret = FALSE; } else { if (ignore) g_byte_array_free (ignore, TRUE); widget_unset_error (GTK_WIDGET (self->cloned_mac)); } if (!ret) return ret; ui_to_setting (self); return nm_setting_verify (NM_SETTING (self->setting_connection), NULL, error) && nm_setting_verify (NM_SETTING (self->setting_wired), NULL, error); }
static gboolean validate (CEPage *page, NMConnection *connection, GError **error) { CEPageWired *self = CE_PAGE_WIRED (page); CEPageWiredPrivate *priv = CE_PAGE_WIRED_GET_PRIVATE (self); gboolean invalid = FALSE; GByteArray *ignore; ignore = ce_page_entry_to_mac (priv->mac, &invalid); if (invalid) return FALSE; ui_to_setting (self); return nm_setting_verify (NM_SETTING (priv->setting), NULL, error); }
static gboolean validate (CEPage *page, NMConnection *connection, GError **error) { CEPageVlan *self = CE_PAGE_VLAN (page); CEPageVlanPrivate *priv = CE_PAGE_VLAN_GET_PRIVATE (self); gboolean invalid = FALSE; GByteArray *ignore; int parent_id; const char *parent; char *parent_iface; parent_id = gtk_combo_box_get_active (GTK_COMBO_BOX (priv->parent)); if (parent_id == -1) { gboolean valid; parent = gtk_entry_get_text (priv->parent_entry); parent_iface = g_strndup (parent, strcspn (parent, " ")); valid = nm_utils_iface_valid_name (parent_iface); g_free (parent_iface); if (!valid) return FALSE; } ignore = ce_page_entry_to_mac (priv->cloned_mac, ARPHRD_ETHER, &invalid); if (invalid) return FALSE; if (ignore) g_byte_array_free (ignore, TRUE); ui_to_setting (self); if ( priv->s_hw && !nm_setting_verify (priv->s_hw, NULL, error)) return FALSE; return nm_setting_verify (NM_SETTING (priv->setting), NULL, error); }
static void ui_to_setting (CEPageEthernet *self) { CEPageEthernetPrivate *priv = CE_PAGE_ETHERNET_GET_PRIVATE (self); const char *port; guint32 speed; GByteArray *device_mac = NULL; GByteArray *cloned_mac = NULL; GtkWidget *entry; /* Port */ switch (gtk_combo_box_get_active (priv->port)) { case PORT_TP: port = "tp"; break; case PORT_AUI: port = "aui"; break; case PORT_BNC: port = "bnc"; break; case PORT_MII: port = "mii"; break; default: port = NULL; break; } /* Speed */ switch (gtk_combo_box_get_active (priv->speed)) { case SPEED_10: speed = 10; break; case SPEED_100: speed = 100; break; case SPEED_1000: speed = 1000; break; case SPEED_10000: speed = 10000; break; default: speed = 0; break; } entry = gtk_bin_get_child (GTK_BIN (priv->device_mac)); if (entry) device_mac = ce_page_entry_to_mac (GTK_ENTRY (entry), ARPHRD_ETHER, NULL); cloned_mac = ce_page_entry_to_mac (priv->cloned_mac, ARPHRD_ETHER, NULL); g_object_set (priv->setting, NM_SETTING_WIRED_MAC_ADDRESS, device_mac, NM_SETTING_WIRED_CLONED_MAC_ADDRESS, cloned_mac, NM_SETTING_WIRED_PORT, port, NM_SETTING_WIRED_SPEED, speed, NM_SETTING_WIRED_DUPLEX, gtk_toggle_button_get_active (priv->duplex) ? "full" : "half", NM_SETTING_WIRED_AUTO_NEGOTIATE, gtk_toggle_button_get_active (priv->autonegotiate), NM_SETTING_WIRED_MTU, (guint32) gtk_spin_button_get_value_as_int (priv->mtu), NULL); if (device_mac) g_byte_array_free (device_mac, TRUE); if (cloned_mac) g_byte_array_free (cloned_mac, TRUE); }
static void ui_to_setting (CEPageVlan *self) { CEPageVlanPrivate *priv = CE_PAGE_VLAN_GET_PRIVATE (self); NMConnection *connection = CE_PAGE (self)->connection; NMSettingConnection *s_con = nm_connection_get_setting_connection (connection); GByteArray *cloned_mac = NULL; VlanParent *parent = NULL; int parent_id, vid; const char *parent_iface = NULL, *parent_uuid = NULL; const char *slave_type; const char *iface; char *tmp_parent_iface = NULL; GType hwtype; gboolean mtu_set; int mtu; parent_id = gtk_combo_box_get_active (GTK_COMBO_BOX (priv->parent)); if (parent_id == -1) { parent_iface = gtk_entry_get_text (priv->parent_entry); tmp_parent_iface = g_strndup (parent_iface, strcspn (parent_iface, " ")); parent_iface = tmp_parent_iface; } else { parent = priv->parents[parent_id]; if (parent->connection) parent_uuid = nm_connection_get_uuid (parent->connection); if (parent->device) parent_iface = nm_device_get_iface (parent->device); } g_assert (parent_uuid != NULL || parent_iface != NULL); slave_type = nm_setting_connection_get_slave_type (s_con); if (parent_uuid) { /* Update NMSettingConnection:master if it's set, but don't * set it if it's not. */ if (!g_strcmp0 (slave_type, NM_SETTING_VLAN_SETTING_NAME)) { g_object_set (s_con, NM_SETTING_CONNECTION_MASTER, parent_uuid, NULL); } } else if (!g_strcmp0 (slave_type, NM_SETTING_VLAN_SETTING_NAME)) { g_object_set (s_con, NM_SETTING_CONNECTION_MASTER, NULL, NM_SETTING_CONNECTION_SLAVE_TYPE, NULL, NULL); } if (parent && NM_IS_DEVICE_ETHERNET (parent->device)) hwtype = NM_TYPE_SETTING_WIRED; else hwtype = G_TYPE_NONE; if (priv->s_hw && G_OBJECT_TYPE (priv->s_hw) != hwtype) { nm_connection_remove_setting (connection, G_OBJECT_TYPE (priv->s_hw)); priv->s_hw = NULL; } iface = gtk_entry_get_text (priv->name_entry); vid = gtk_spin_button_get_value_as_int (priv->id_entry); g_object_set (priv->setting, NM_SETTING_VLAN_PARENT, parent_uuid ? parent_uuid : parent_iface, NM_SETTING_VLAN_INTERFACE_NAME, iface, NM_SETTING_VLAN_ID, vid, NULL); if (hwtype != G_TYPE_NONE) { cloned_mac = ce_page_entry_to_mac (priv->cloned_mac, ARPHRD_ETHER, NULL); mtu_set = g_ascii_isdigit (*gtk_entry_get_text (GTK_ENTRY (priv->mtu))); mtu = gtk_spin_button_get_value_as_int (priv->mtu); if (cloned_mac || mtu_set) { if (!priv->s_hw) { priv->s_hw = g_object_new (hwtype, NULL); nm_connection_add_setting (connection, priv->s_hw); } g_object_set (priv->s_hw, NM_SETTING_WIRED_CLONED_MAC_ADDRESS, cloned_mac, NM_SETTING_WIRED_MTU, (guint32) mtu, NULL); if (cloned_mac) g_byte_array_free (cloned_mac, TRUE); } else if (priv->s_hw) { nm_connection_remove_setting (connection, G_OBJECT_TYPE (priv->s_hw)); priv->s_hw = NULL; } } g_free (tmp_parent_iface); }
static void ui_to_setting (CEPageWifi *self) { CEPageWifiPrivate *priv = CE_PAGE_WIFI_GET_PRIVATE (self); GByteArray *ssid; GByteArray *bssid = NULL; GByteArray *device_mac = NULL; GByteArray *cloned_mac = NULL; const char *mode; const char *band; GtkWidget *entry; ssid = ce_page_wifi_get_ssid (self); if (gtk_combo_box_get_active (priv->mode) == 1) mode = "adhoc"; else mode = "infrastructure"; switch (gtk_combo_box_get_active (priv->band)) { case 1: band = "a"; break; case 2: band = "bg"; break; case 0: default: band = NULL; break; } entry = gtk_bin_get_child (GTK_BIN (priv->bssid)); /* BSSID is only valid for infrastructure not for adhoc */ if (entry && mode && strcmp (mode, "adhoc") != 0) bssid = ce_page_entry_to_mac (GTK_ENTRY (entry), ARPHRD_ETHER, NULL); entry = gtk_bin_get_child (GTK_BIN (priv->device_mac)); if (entry) device_mac = ce_page_entry_to_mac (GTK_ENTRY (entry), ARPHRD_ETHER, NULL); cloned_mac = ce_page_entry_to_mac (priv->cloned_mac, ARPHRD_ETHER, NULL); g_object_set (priv->setting, NM_SETTING_WIRELESS_SSID, ssid, NM_SETTING_WIRELESS_BSSID, bssid, NM_SETTING_WIRELESS_MAC_ADDRESS, device_mac, NM_SETTING_WIRELESS_CLONED_MAC_ADDRESS, cloned_mac, NM_SETTING_WIRELESS_MODE, mode, NM_SETTING_WIRELESS_BAND, band, NM_SETTING_WIRELESS_CHANNEL, gtk_spin_button_get_value_as_int (priv->channel), NM_SETTING_WIRELESS_RATE, gtk_spin_button_get_value_as_int (priv->rate), NM_SETTING_WIRELESS_TX_POWER, gtk_spin_button_get_value_as_int (priv->tx_power), NM_SETTING_WIRELESS_MTU, gtk_spin_button_get_value_as_int (priv->mtu), NULL); if (ssid) g_byte_array_free (ssid, TRUE); if (device_mac) g_byte_array_free (device_mac, TRUE); if (cloned_mac) g_byte_array_free (cloned_mac, TRUE); if (bssid) g_byte_array_free (bssid, TRUE); }