network: Convert EAPMethod to an interface and make the subclasses GObjects

This commit is contained in:
Robert Ancell 2019-11-07 10:21:54 +13:00 committed by Georges Basile Stavracas Neto
parent 426896b7a2
commit 5006342308
14 changed files with 366 additions and 371 deletions

View file

@ -36,7 +36,7 @@
#define I_METHOD_COLUMN 1 #define I_METHOD_COLUMN 1
struct _EAPMethodFAST { struct _EAPMethodFAST {
EAPMethod parent; GObject parent;
GtkBuilder *builder; GtkBuilder *builder;
GtkEntry *anon_identity_entry; GtkEntry *anon_identity_entry;
@ -55,13 +55,20 @@ struct _EAPMethodFAST {
gboolean is_editor; gboolean is_editor;
}; };
static void eap_method_iface_init (EAPMethodInterface *);
G_DEFINE_TYPE_WITH_CODE (EAPMethodFAST, eap_method_fast, G_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE (eap_method_get_type (), eap_method_iface_init))
static void static void
destroy (EAPMethod *parent) eap_method_fast_dispose (GObject *object)
{ {
EAPMethodFAST *self = (EAPMethodFAST *) parent; EAPMethodFAST *self = EAP_METHOD_FAST (object);
g_clear_object (&self->builder); g_clear_object (&self->builder);
g_clear_object (&self->size_group); g_clear_object (&self->size_group);
G_OBJECT_CLASS (eap_method_fast_parent_class)->dispose (object);
} }
static gboolean static gboolean
@ -312,13 +319,37 @@ changed_cb (EAPMethodFAST *self)
wireless_security_notify_changed (self->sec_parent); wireless_security_notify_changed (self->sec_parent);
} }
static void
eap_method_fast_init (EAPMethodFAST *self)
{
}
static void
eap_method_fast_class_init (EAPMethodFASTClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->dispose = eap_method_fast_dispose;
}
static void
eap_method_iface_init (EAPMethodInterface *iface)
{
iface->validate = validate;
iface->add_to_size_group = add_to_size_group;
iface->fill_connection = fill_connection;
iface->update_secrets = update_secrets;
iface->get_widget = get_widget;
iface->get_default_field = get_default_field;
iface->get_password_flags_name = get_password_flags_name;
}
EAPMethodFAST * EAPMethodFAST *
eap_method_fast_new (WirelessSecurity *ws_parent, eap_method_fast_new (WirelessSecurity *ws_parent,
NMConnection *connection, NMConnection *connection,
gboolean is_editor, gboolean is_editor,
gboolean secrets_only) gboolean secrets_only)
{ {
EAPMethod *parent;
EAPMethodFAST *self; EAPMethodFAST *self;
GtkFileFilter *filter; GtkFileFilter *filter;
NMSetting8021x *s_8021x = NULL; NMSetting8021x *s_8021x = NULL;
@ -326,20 +357,7 @@ eap_method_fast_new (WirelessSecurity *ws_parent,
gboolean provisioning_enabled = TRUE; gboolean provisioning_enabled = TRUE;
g_autoptr(GError) error = NULL; g_autoptr(GError) error = NULL;
parent = eap_method_init (sizeof (EAPMethodFAST), self = g_object_new (eap_method_fast_get_type (), NULL);
validate,
add_to_size_group,
fill_connection,
update_secrets,
get_widget,
get_default_field,
get_password_flags_name,
NULL,
destroy);
if (!parent)
return NULL;
self = (EAPMethodFAST *) parent;
self->sec_parent = ws_parent; self->sec_parent = ws_parent;
self->is_editor = is_editor; self->is_editor = is_editor;

View file

@ -20,20 +20,19 @@
* (C) Copyright 2012 Red Hat, Inc. * (C) Copyright 2012 Red Hat, Inc.
*/ */
#ifndef EAP_METHOD_FAST_H #pragma once
#define EAP_METHOD_FAST_H
#include <NetworkManager.h>
#include "wireless-security.h" #include "wireless-security.h"
typedef struct _EAPMethodFAST EAPMethodFAST; G_BEGIN_DECLS
G_DECLARE_FINAL_TYPE (EAPMethodFAST, eap_method_fast, EAP, METHOD_FAST, GObject)
EAPMethodFAST *eap_method_fast_new (WirelessSecurity *ws_parent, EAPMethodFAST *eap_method_fast_new (WirelessSecurity *ws_parent,
NMConnection *connection, NMConnection *connection,
gboolean is_editor, gboolean is_editor,
gboolean secrets_only); gboolean secrets_only);
static void eap_method_fast_unref (EAPMethodFAST *method) { eap_method_unref (EAP_METHOD (method)); } G_END_DECLS
G_DEFINE_AUTOPTR_CLEANUP_FUNC (EAPMethodFAST, eap_method_fast_unref)
#endif /* EAP_METHOD_FAST_H */

View file

@ -33,7 +33,7 @@
#include "utils.h" #include "utils.h"
struct _EAPMethodLEAP { struct _EAPMethodLEAP {
EAPMethod parent; GObject parent;
GtkBuilder *builder; GtkBuilder *builder;
GtkGrid *grid; GtkGrid *grid;
@ -48,6 +48,11 @@ struct _EAPMethodLEAP {
gboolean editing_connection; gboolean editing_connection;
}; };
static void eap_method_iface_init (EAPMethodInterface *);
G_DEFINE_TYPE_WITH_CODE (EAPMethodLEAP, eap_method_leap, G_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE (eap_method_get_type (), eap_method_iface_init))
static void static void
show_toggled_cb (EAPMethodLEAP *self) show_toggled_cb (EAPMethodLEAP *self)
{ {
@ -183,15 +188,17 @@ widgets_unrealized (EAPMethodLEAP *self)
} }
static void static void
destroy (EAPMethod *parent) eap_method_leap_dispose (GObject *object)
{ {
EAPMethodLEAP *self = (EAPMethodLEAP *) parent; EAPMethodLEAP *self = EAP_METHOD_LEAP (object);
g_clear_object (&self->builder); g_clear_object (&self->builder);
g_signal_handlers_disconnect_by_data (self->grid, self); g_signal_handlers_disconnect_by_data (self->grid, self);
g_signal_handlers_disconnect_by_data (self->username_entry, self->ws_parent); g_signal_handlers_disconnect_by_data (self->username_entry, self->ws_parent);
g_signal_handlers_disconnect_by_data (self->password_entry, self->ws_parent); g_signal_handlers_disconnect_by_data (self->password_entry, self->ws_parent);
g_signal_handlers_disconnect_by_data (self->show_password_check, self); g_signal_handlers_disconnect_by_data (self->show_password_check, self);
G_OBJECT_CLASS (eap_method_leap_parent_class)->dispose (object);
} }
static void static void
@ -200,30 +207,41 @@ changed_cb (EAPMethodLEAP *self)
wireless_security_notify_changed (self->ws_parent); wireless_security_notify_changed (self->ws_parent);
} }
static void
eap_method_leap_init (EAPMethodLEAP *self)
{
}
static void
eap_method_leap_class_init (EAPMethodLEAPClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->dispose = eap_method_leap_dispose;
}
static void
eap_method_iface_init (EAPMethodInterface *iface)
{
iface->validate = validate;
iface->add_to_size_group = add_to_size_group;
iface->fill_connection = fill_connection;
iface->update_secrets = update_secrets;
iface->get_widget = get_widget;
iface->get_default_field = get_default_field;
iface->get_password_flags_name = get_password_flags_name;
}
EAPMethodLEAP * EAPMethodLEAP *
eap_method_leap_new (WirelessSecurity *ws_parent, eap_method_leap_new (WirelessSecurity *ws_parent,
NMConnection *connection, NMConnection *connection,
gboolean secrets_only) gboolean secrets_only)
{ {
EAPMethodLEAP *self; EAPMethodLEAP *self;
EAPMethod *parent;
NMSetting8021x *s_8021x = NULL; NMSetting8021x *s_8021x = NULL;
g_autoptr(GError) error = NULL; g_autoptr(GError) error = NULL;
parent = eap_method_init (sizeof (EAPMethodLEAP), self = g_object_new (eap_method_leap_get_type (), NULL);
validate,
add_to_size_group,
fill_connection,
update_secrets,
get_widget,
get_default_field,
get_password_flags_name,
NULL,
destroy);
if (!parent)
return NULL;
self = (EAPMethodLEAP *) parent;
self->editing_connection = secrets_only ? FALSE : TRUE; self->editing_connection = secrets_only ? FALSE : TRUE;
self->ws_parent = ws_parent; self->ws_parent = ws_parent;

View file

@ -20,19 +20,16 @@
* (C) Copyright 2007 - 2010 Red Hat, Inc. * (C) Copyright 2007 - 2010 Red Hat, Inc.
*/ */
#ifndef EAP_METHOD_LEAP_H #pragma once
#define EAP_METHOD_LEAP_H
#include "wireless-security.h" #include "wireless-security.h"
typedef struct _EAPMethodLEAP EAPMethodLEAP; G_BEGIN_DECLS
G_DECLARE_FINAL_TYPE (EAPMethodLEAP, eap_method_leap, EAP, METHOD_LEAP, GObject)
EAPMethodLEAP *eap_method_leap_new (WirelessSecurity *ws_parent, EAPMethodLEAP *eap_method_leap_new (WirelessSecurity *ws_parent,
NMConnection *connection, NMConnection *connection,
gboolean secrets_only); gboolean secrets_only);
static void eap_method_leap_unref (EAPMethodLEAP *method) { eap_method_unref (EAP_METHOD (method)); } G_END_DECLS
G_DEFINE_AUTOPTR_CLEANUP_FUNC (EAPMethodLEAP, eap_method_leap_unref)
#endif /* EAP_METHOD_LEAP_H */

View file

@ -35,7 +35,7 @@
#define I_METHOD_COLUMN 1 #define I_METHOD_COLUMN 1
struct _EAPMethodPEAP { struct _EAPMethodPEAP {
EAPMethod parent; GObject parent;
GtkBuilder *builder; GtkBuilder *builder;
GtkEntry *anon_identity_entry; GtkEntry *anon_identity_entry;
@ -55,19 +55,26 @@ struct _EAPMethodPEAP {
gboolean is_editor; gboolean is_editor;
}; };
static void eap_method_iface_init (EAPMethodInterface *);
G_DEFINE_TYPE_WITH_CODE (EAPMethodPEAP, eap_method_peap, G_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE (eap_method_get_type (), eap_method_iface_init))
static void static void
destroy (EAPMethod *parent) eap_method_peap_dispose (GObject *object)
{ {
EAPMethodPEAP *self = (EAPMethodPEAP *) parent; EAPMethodPEAP *self = EAP_METHOD_PEAP (object);
g_clear_object (&self->builder); g_clear_object (&self->builder);
g_clear_object (&self->size_group); g_clear_object (&self->size_group);
G_OBJECT_CLASS (eap_method_peap_parent_class)->dispose (object);
} }
static gboolean static gboolean
validate (EAPMethod *parent, GError **error) validate (EAPMethod *method, GError **error)
{ {
EAPMethodPEAP *self = (EAPMethodPEAP *) parent; EAPMethodPEAP *self = EAP_METHOD_PEAP (method);
GtkTreeModel *model; GtkTreeModel *model;
GtkTreeIter iter; GtkTreeIter iter;
g_autoptr(EAPMethod) eap = NULL; g_autoptr(EAPMethod) eap = NULL;
@ -102,9 +109,9 @@ ca_cert_not_required_toggled (EAPMethodPEAP *self)
} }
static void static void
add_to_size_group (EAPMethod *parent, GtkSizeGroup *group) add_to_size_group (EAPMethod *method, GtkSizeGroup *group)
{ {
EAPMethodPEAP *self = (EAPMethodPEAP *) parent; EAPMethodPEAP *self = EAP_METHOD_PEAP (method);
GtkTreeModel *model; GtkTreeModel *model;
GtkTreeIter iter; GtkTreeIter iter;
g_autoptr(EAPMethod) eap = NULL; g_autoptr(EAPMethod) eap = NULL;
@ -126,9 +133,9 @@ add_to_size_group (EAPMethod *parent, GtkSizeGroup *group)
} }
static void static void
fill_connection (EAPMethod *parent, NMConnection *connection, NMSettingSecretFlags flags) fill_connection (EAPMethod *method, NMConnection *connection, NMSettingSecretFlags flags)
{ {
EAPMethodPEAP *self = (EAPMethodPEAP *) parent; EAPMethodPEAP *self = EAP_METHOD_PEAP (method);
NMSetting8021x *s_8021x; NMSetting8021x *s_8021x;
NMSetting8021xCKFormat format = NM_SETTING_802_1X_CK_FORMAT_UNKNOWN; NMSetting8021xCKFormat format = NM_SETTING_802_1X_CK_FORMAT_UNKNOWN;
const char *text; const char *text;
@ -154,7 +161,7 @@ fill_connection (EAPMethod *parent, NMConnection *connection, NMSettingSecretFla
g_warning ("Couldn't read CA certificate '%s': %s", filename, error ? error->message : "(unknown)"); g_warning ("Couldn't read CA certificate '%s': %s", filename, error ? error->message : "(unknown)");
ca_cert_error = TRUE; ca_cert_error = TRUE;
} }
eap_method_ca_cert_ignore_set (parent, connection, filename, ca_cert_error); eap_method_ca_cert_ignore_set (method, connection, filename, ca_cert_error);
peapver_active = gtk_combo_box_get_active (self->version_combo); peapver_active = gtk_combo_box_get_active (self->version_combo);
switch (peapver_active) { switch (peapver_active) {
@ -286,31 +293,31 @@ inner_auth_combo_init (EAPMethodPEAP *self,
} }
static void static void
update_secrets (EAPMethod *parent, NMConnection *connection) update_secrets (EAPMethod *method, NMConnection *connection)
{ {
EAPMethodPEAP *self = (EAPMethodPEAP *) parent; EAPMethodPEAP *self = EAP_METHOD_PEAP (method);
eap_method_phase2_update_secrets_helper (parent, eap_method_phase2_update_secrets_helper (method,
connection, connection,
self->inner_auth_combo, self->inner_auth_combo,
I_METHOD_COLUMN); I_METHOD_COLUMN);
} }
static GtkWidget * static GtkWidget *
get_widget (EAPMethod *parent) get_widget (EAPMethod *method)
{ {
EAPMethodPEAP *self = (EAPMethodPEAP *) parent; EAPMethodPEAP *self = EAP_METHOD_PEAP (method);
return GTK_WIDGET (self->grid); return GTK_WIDGET (self->grid);
} }
static GtkWidget * static GtkWidget *
get_default_field (EAPMethod *parent) get_default_field (EAPMethod *method)
{ {
EAPMethodPEAP *self = (EAPMethodPEAP *) parent; EAPMethodPEAP *self = EAP_METHOD_PEAP (method);
return GTK_WIDGET (self->anon_identity_entry); return GTK_WIDGET (self->anon_identity_entry);
} }
static const gchar * static const gchar *
get_password_flags_name (EAPMethod *parent) get_password_flags_name (EAPMethod *method)
{ {
return NM_SETTING_802_1X_PASSWORD; return NM_SETTING_802_1X_PASSWORD;
} }
@ -321,33 +328,44 @@ changed_cb (EAPMethodPEAP *self)
wireless_security_notify_changed (self->sec_parent); wireless_security_notify_changed (self->sec_parent);
} }
static void
eap_method_peap_init (EAPMethodPEAP *self)
{
}
static void
eap_method_peap_class_init (EAPMethodPEAPClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->dispose = eap_method_peap_dispose;
}
static void
eap_method_iface_init (EAPMethodInterface *iface)
{
iface->validate = validate;
iface->add_to_size_group = add_to_size_group;
iface->fill_connection = fill_connection;
iface->update_secrets = update_secrets;
iface->get_widget = get_widget;
iface->get_default_field = get_default_field;
iface->get_password_flags_name = get_password_flags_name;
}
EAPMethodPEAP * EAPMethodPEAP *
eap_method_peap_new (WirelessSecurity *ws_parent, eap_method_peap_new (WirelessSecurity *ws_parent,
NMConnection *connection, NMConnection *connection,
gboolean is_editor, gboolean is_editor,
gboolean secrets_only) gboolean secrets_only)
{ {
EAPMethod *parent;
EAPMethodPEAP *self; EAPMethodPEAP *self;
GtkFileFilter *filter; GtkFileFilter *filter;
NMSetting8021x *s_8021x = NULL; NMSetting8021x *s_8021x = NULL;
const char *filename; const char *filename;
g_autoptr(GError) error = NULL; g_autoptr(GError) error = NULL;
parent = eap_method_init (sizeof (EAPMethodPEAP), self = g_object_new (eap_method_peap_get_type (), NULL);
validate,
add_to_size_group,
fill_connection,
update_secrets,
get_widget,
get_default_field,
get_password_flags_name,
NULL,
destroy);
if (!parent)
return NULL;
self = (EAPMethodPEAP *) parent;
self->sec_parent = ws_parent; self->sec_parent = ws_parent;
self->is_editor = is_editor; self->is_editor = is_editor;
@ -388,7 +406,7 @@ eap_method_peap_new (WirelessSecurity *ws_parent,
gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (self->ca_cert_button), filename); gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (self->ca_cert_button), filename);
} }
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->ca_cert_not_required_check), gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->ca_cert_not_required_check),
!filename && eap_method_ca_cert_ignore_get (parent, connection)); !filename && eap_method_ca_cert_ignore_get (EAP_METHOD (self), connection));
} }
inner_auth_combo_init (self, connection, s_8021x, secrets_only); inner_auth_combo_init (self, connection, s_8021x, secrets_only);

View file

@ -20,20 +20,17 @@
* (C) Copyright 2007 - 2010 Red Hat, Inc. * (C) Copyright 2007 - 2010 Red Hat, Inc.
*/ */
#ifndef EAP_METHOD_PEAP_H #pragma once
#define EAP_METHOD_PEAP_H
#include "wireless-security.h" #include "wireless-security.h"
typedef struct _EAPMethodPEAP EAPMethodPEAP; G_BEGIN_DECLS
G_DECLARE_FINAL_TYPE (EAPMethodPEAP, eap_method_peap, EAP, METHOD_PEAP, GObject)
EAPMethodPEAP *eap_method_peap_new (WirelessSecurity *ws_parent, EAPMethodPEAP *eap_method_peap_new (WirelessSecurity *ws_parent,
NMConnection *connection, NMConnection *connection,
gboolean is_editor, gboolean is_editor,
gboolean secrets_only); gboolean secrets_only);
static void eap_method_peap_unref (EAPMethodPEAP *method) { eap_method_unref (EAP_METHOD (method)); } G_END_DECLS
G_DEFINE_AUTOPTR_CLEANUP_FUNC (EAPMethodPEAP, eap_method_peap_unref)
#endif /* EAP_METHOD_PEAP_H */

View file

@ -33,7 +33,7 @@
#include "utils.h" #include "utils.h"
struct _EAPMethodSimple { struct _EAPMethodSimple {
EAPMethod parent; GObject parent;
GtkBuilder *builder; GtkBuilder *builder;
GtkGrid *grid; GtkGrid *grid;
@ -51,6 +51,11 @@ struct _EAPMethodSimple {
guint idle_func_id; guint idle_func_id;
}; };
static void eap_method_iface_init (EAPMethodInterface *);
G_DEFINE_TYPE_WITH_CODE (EAPMethodSimple, eap_method_simple, G_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE (eap_method_get_type (), eap_method_iface_init))
static void static void
show_toggled_cb (EAPMethodSimple *self) show_toggled_cb (EAPMethodSimple *self)
{ {
@ -68,9 +73,9 @@ always_ask_selected (GtkEntry *passwd_entry)
} }
static gboolean static gboolean
validate (EAPMethod *parent, GError **error) validate (EAPMethod *method, GError **error)
{ {
EAPMethodSimple *self = (EAPMethodSimple *)parent; EAPMethodSimple *self = EAP_METHOD_SIMPLE (method);
const char *text; const char *text;
gboolean ret = TRUE; gboolean ret = TRUE;
@ -101,9 +106,9 @@ validate (EAPMethod *parent, GError **error)
} }
static void static void
add_to_size_group (EAPMethod *parent, GtkSizeGroup *group) add_to_size_group (EAPMethod *method, GtkSizeGroup *group)
{ {
EAPMethodSimple *self = (EAPMethodSimple *) parent; EAPMethodSimple *self = EAP_METHOD_SIMPLE (method);
gtk_size_group_add_widget (group, GTK_WIDGET (self->username_label)); gtk_size_group_add_widget (group, GTK_WIDGET (self->username_label));
gtk_size_group_add_widget (group, GTK_WIDGET (self->password_label)); gtk_size_group_add_widget (group, GTK_WIDGET (self->password_label));
} }
@ -126,9 +131,9 @@ static const EapType eap_table[EAP_METHOD_SIMPLE_TYPE_LAST] = {
}; };
static void static void
fill_connection (EAPMethod *parent, NMConnection *connection, NMSettingSecretFlags prev_flags) fill_connection (EAPMethod *method, NMConnection *connection, NMSettingSecretFlags prev_flags)
{ {
EAPMethodSimple *self = (EAPMethodSimple *) parent; EAPMethodSimple *self = EAP_METHOD_SIMPLE (method);
NMSetting8021x *s_8021x; NMSetting8021x *s_8021x;
gboolean not_saved = FALSE; gboolean not_saved = FALSE;
NMSettingSecretFlags flags; NMSettingSecretFlags flags;
@ -140,11 +145,11 @@ fill_connection (EAPMethod *parent, NMConnection *connection, NMSettingSecretFla
/* If this is the main EAP method, clear any existing methods because the /* If this is the main EAP method, clear any existing methods because the
* user-selected on will replace it. * user-selected on will replace it.
*/ */
if (eap_method_get_phase2 (parent) == FALSE) if (eap_method_get_phase2 (method) == FALSE)
nm_setting_802_1x_clear_eap_methods (s_8021x); nm_setting_802_1x_clear_eap_methods (s_8021x);
eap_type = &eap_table[self->type]; eap_type = &eap_table[self->type];
if (eap_method_get_phase2 (parent)) { if (eap_method_get_phase2 (method)) {
/* If the outer EAP method (TLS, TTLS, PEAP, etc) allows inner/phase2 /* If the outer EAP method (TLS, TTLS, PEAP, etc) allows inner/phase2
* EAP methods (which only TTLS allows) *and* the inner/phase2 method * EAP methods (which only TTLS allows) *and* the inner/phase2 method
* supports being an inner EAP method, then set PHASE2_AUTHEAP. * supports being an inner EAP method, then set PHASE2_AUTHEAP.
@ -183,9 +188,9 @@ fill_connection (EAPMethod *parent, NMConnection *connection, NMSettingSecretFla
} }
static void static void
update_secrets (EAPMethod *parent, NMConnection *connection) update_secrets (EAPMethod *method, NMConnection *connection)
{ {
EAPMethodSimple *self = (EAPMethodSimple *) parent; EAPMethodSimple *self = EAP_METHOD_SIMPLE (method);
helper_fill_secret_entry (connection, helper_fill_secret_entry (connection,
self->password_entry, self->password_entry,
NM_TYPE_SETTING_802_1X, NM_TYPE_SETTING_802_1X,
@ -193,29 +198,29 @@ update_secrets (EAPMethod *parent, NMConnection *connection)
} }
static GtkWidget * static GtkWidget *
get_widget (EAPMethod *parent) get_widget (EAPMethod *method)
{ {
EAPMethodSimple *self = (EAPMethodSimple *) parent; EAPMethodSimple *self = EAP_METHOD_SIMPLE (method);
return GTK_WIDGET (self->grid); return GTK_WIDGET (self->grid);
} }
static GtkWidget * static GtkWidget *
get_default_field (EAPMethod *parent) get_default_field (EAPMethod *method)
{ {
EAPMethodSimple *self = (EAPMethodSimple *) parent; EAPMethodSimple *self = EAP_METHOD_SIMPLE (method);
return GTK_WIDGET (self->username_entry); return GTK_WIDGET (self->username_entry);
} }
static const gchar * static const gchar *
get_password_flags_name (EAPMethod *parent) get_password_flags_name (EAPMethod *method)
{ {
return NM_SETTING_802_1X_PASSWORD; return NM_SETTING_802_1X_PASSWORD;
} }
static const gboolean static const gboolean
get_phase2 (EAPMethod *parent) get_phase2 (EAPMethod *method)
{ {
EAPMethodSimple *self = (EAPMethodSimple *) parent; EAPMethodSimple *self = EAP_METHOD_SIMPLE (method);
return self->flags & EAP_METHOD_SIMPLE_FLAG_PHASE2; return self->flags & EAP_METHOD_SIMPLE_FLAG_PHASE2;
} }
@ -283,9 +288,9 @@ widgets_unrealized (EAPMethodSimple *self)
} }
static void static void
destroy (EAPMethod *parent) eap_method_simple_dispose (GObject *object)
{ {
EAPMethodSimple *self = (EAPMethodSimple *) parent; EAPMethodSimple *self = EAP_METHOD_SIMPLE (object);
g_clear_object (&self->builder); g_clear_object (&self->builder);
g_signal_handlers_disconnect_by_data (self->grid, self); g_signal_handlers_disconnect_by_data (self->grid, self);
@ -295,6 +300,8 @@ destroy (EAPMethod *parent)
g_signal_handlers_disconnect_by_data (self->show_password_check, self); g_signal_handlers_disconnect_by_data (self->show_password_check, self);
nm_clear_g_source (&self->idle_func_id); nm_clear_g_source (&self->idle_func_id);
G_OBJECT_CLASS (eap_method_simple_parent_class)->dispose (object);
} }
static void static void
@ -303,31 +310,43 @@ changed_cb (EAPMethodSimple *self)
wireless_security_notify_changed (self->ws_parent); wireless_security_notify_changed (self->ws_parent);
} }
static void
eap_method_simple_init (EAPMethodSimple *self)
{
}
static void
eap_method_simple_class_init (EAPMethodSimpleClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->dispose = eap_method_simple_dispose;
}
static void
eap_method_iface_init (EAPMethodInterface *iface)
{
iface->validate = validate;
iface->add_to_size_group = add_to_size_group;
iface->fill_connection = fill_connection;
iface->update_secrets = update_secrets;
iface->get_widget = get_widget;
iface->get_default_field = get_default_field;
iface->get_password_flags_name = get_password_flags_name;
iface->get_phase2 = get_phase2;
}
EAPMethodSimple * EAPMethodSimple *
eap_method_simple_new (WirelessSecurity *ws_parent, eap_method_simple_new (WirelessSecurity *ws_parent,
NMConnection *connection, NMConnection *connection,
EAPMethodSimpleType type, EAPMethodSimpleType type,
EAPMethodSimpleFlags flags) EAPMethodSimpleFlags flags)
{ {
EAPMethod *parent;
EAPMethodSimple *self; EAPMethodSimple *self;
NMSetting8021x *s_8021x = NULL; NMSetting8021x *s_8021x = NULL;
g_autoptr(GError) error = NULL; g_autoptr(GError) error = NULL;
parent = eap_method_init (sizeof (EAPMethodSimple), self = g_object_new (eap_method_simple_get_type (), NULL);
validate,
add_to_size_group,
fill_connection,
update_secrets,
get_widget,
get_default_field,
get_password_flags_name,
get_phase2,
destroy);
if (!parent)
return NULL;
self = (EAPMethodSimple *) parent;
self->ws_parent = ws_parent; self->ws_parent = ws_parent;
self->flags = flags; self->flags = flags;
self->type = type; self->type = type;

View file

@ -20,11 +20,14 @@
* (C) Copyright 2007 - 2010 Red Hat, Inc. * (C) Copyright 2007 - 2010 Red Hat, Inc.
*/ */
#ifndef EAP_METHOD_SIMPLE_H #pragma once
#define EAP_METHOD_SIMPLE_H
#include "wireless-security.h" #include "wireless-security.h"
G_BEGIN_DECLS
G_DECLARE_FINAL_TYPE (EAPMethodSimple, eap_method_simple, EAP, METHOD_SIMPLE, GObject)
typedef enum { typedef enum {
/* NOTE: when updating this table, also update eap_methods[] */ /* NOTE: when updating this table, also update eap_methods[] */
EAP_METHOD_SIMPLE_TYPE_PAP = 0, EAP_METHOD_SIMPLE_TYPE_PAP = 0,
@ -52,15 +55,9 @@ typedef enum {
EAP_METHOD_SIMPLE_FLAG_SECRETS_ONLY = 0x08 EAP_METHOD_SIMPLE_FLAG_SECRETS_ONLY = 0x08
} EAPMethodSimpleFlags; } EAPMethodSimpleFlags;
typedef struct _EAPMethodSimple EAPMethodSimple;
EAPMethodSimple *eap_method_simple_new (WirelessSecurity *ws_parent, EAPMethodSimple *eap_method_simple_new (WirelessSecurity *ws_parent,
NMConnection *connection, NMConnection *connection,
EAPMethodSimpleType type, EAPMethodSimpleType type,
EAPMethodSimpleFlags flags); EAPMethodSimpleFlags flags);
static void eap_method_simple_unref (EAPMethodSimple *method) { eap_method_unref (EAP_METHOD (method)); } G_END_DECLS
G_DEFINE_AUTOPTR_CLEANUP_FUNC (EAPMethodSimple, eap_method_simple_unref)
#endif /* EAP_METHOD_SIMPLE_H */

View file

@ -33,7 +33,7 @@
#include "utils.h" #include "utils.h"
struct _EAPMethodTLS { struct _EAPMethodTLS {
EAPMethod parent; GObject parent;
GtkBuilder *builder; GtkBuilder *builder;
GtkFileChooserButton *ca_cert_button; GtkFileChooserButton *ca_cert_button;
@ -56,12 +56,19 @@ struct _EAPMethodTLS {
gboolean editing_connection; gboolean editing_connection;
}; };
static void eap_method_iface_init (EAPMethodInterface *);
G_DEFINE_TYPE_WITH_CODE (EAPMethodTLS, eap_method_tls, G_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE (eap_method_get_type (), eap_method_iface_init))
static void static void
destroy (EAPMethod *parent) eap_method_tls_dispose (GObject *object)
{ {
EAPMethodTLS *self = (EAPMethodTLS *) parent; EAPMethodTLS *self = EAP_METHOD_TLS (object);
g_clear_object (&self->builder); g_clear_object (&self->builder);
G_OBJECT_CLASS (eap_method_tls_parent_class)->dispose (object);
} }
static void static void
@ -74,9 +81,9 @@ show_toggled_cb (EAPMethodTLS *self)
} }
static gboolean static gboolean
validate (EAPMethod *parent, GError **error) validate (EAPMethod *method, GError **error)
{ {
EAPMethodTLS *self = (EAPMethodTLS *) parent; EAPMethodTLS *self = EAP_METHOD_TLS (method);
NMSetting8021xCKFormat format = NM_SETTING_802_1X_CK_FORMAT_UNKNOWN; NMSetting8021xCKFormat format = NM_SETTING_802_1X_CK_FORMAT_UNKNOWN;
const char *password, *identity; const char *password, *identity;
g_autoptr(GError) ca_cert_error = NULL; g_autoptr(GError) ca_cert_error = NULL;
@ -146,9 +153,9 @@ ca_cert_not_required_toggled (EAPMethodTLS *self)
} }
static void static void
add_to_size_group (EAPMethod *parent, GtkSizeGroup *group) add_to_size_group (EAPMethod *method, GtkSizeGroup *group)
{ {
EAPMethodTLS *self = (EAPMethodTLS *) parent; EAPMethodTLS *self = EAP_METHOD_TLS (method);
gtk_size_group_add_widget (group, GTK_WIDGET (self->ca_cert_not_required_check)); gtk_size_group_add_widget (group, GTK_WIDGET (self->ca_cert_not_required_check));
gtk_size_group_add_widget (group, GTK_WIDGET (self->identity_label)); gtk_size_group_add_widget (group, GTK_WIDGET (self->identity_label));
@ -159,9 +166,9 @@ add_to_size_group (EAPMethod *parent, GtkSizeGroup *group)
} }
static void static void
fill_connection (EAPMethod *parent, NMConnection *connection, NMSettingSecretFlags flags) fill_connection (EAPMethod *method, NMConnection *connection, NMSettingSecretFlags flags)
{ {
EAPMethodTLS *self = (EAPMethodTLS *) parent; EAPMethodTLS *self = EAP_METHOD_TLS (method);
NMSetting8021xCKFormat format = NM_SETTING_802_1X_CK_FORMAT_UNKNOWN; NMSetting8021xCKFormat format = NM_SETTING_802_1X_CK_FORMAT_UNKNOWN;
NMSetting8021x *s_8021x; NMSetting8021x *s_8021x;
NMSettingSecretFlags secret_flags; NMSettingSecretFlags secret_flags;
@ -246,13 +253,12 @@ fill_connection (EAPMethod *parent, NMConnection *connection, NMSettingSecretFla
ca_cert_error = TRUE; ca_cert_error = TRUE;
} }
} }
eap_method_ca_cert_ignore_set (parent, connection, ca_filename, ca_cert_error); eap_method_ca_cert_ignore_set (method, connection, ca_filename, ca_cert_error);
} }
static void static void
private_key_picker_helper (EAPMethod *parent, const char *filename, gboolean changed) private_key_picker_helper (EAPMethodTLS *self, const char *filename, gboolean changed)
{ {
EAPMethodTLS *self = (EAPMethodTLS *) parent;
g_autoptr(NMSetting8021x) setting = NULL; g_autoptr(NMSetting8021x) setting = NULL;
NMSetting8021xCKFormat cert_format = NM_SETTING_802_1X_CK_FORMAT_UNKNOWN; NMSetting8021xCKFormat cert_format = NM_SETTING_802_1X_CK_FORMAT_UNKNOWN;
const char *password; const char *password;
@ -296,12 +302,12 @@ private_key_picker_helper (EAPMethod *parent, const char *filename, gboolean cha
static void static void
private_key_picker_file_set_cb (GtkWidget *chooser, gpointer user_data) private_key_picker_file_set_cb (GtkWidget *chooser, gpointer user_data)
{ {
EAPMethod *parent = (EAPMethod *) user_data; EAPMethodTLS *self = user_data;
g_autofree gchar *filename = NULL; g_autofree gchar *filename = NULL;
filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (chooser)); filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (chooser));
if (filename) if (filename)
private_key_picker_helper (parent, filename, TRUE); private_key_picker_helper (self, filename, TRUE);
} }
static void reset_filter (GtkWidget *widget, GParamSpec *spec, gpointer user_data) static void reset_filter (GtkWidget *widget, GParamSpec *spec, gpointer user_data)
@ -323,10 +329,10 @@ changed_cb (EAPMethodTLS *self)
} }
static void static void
setup_filepicker (GtkFileChooserButton *button, setup_filepicker (EAPMethodTLS *self,
GtkFileChooserButton *button,
const char *title, const char *title,
WirelessSecurity *ws_parent, WirelessSecurity *ws_parent,
EAPMethod *parent,
NMSetting8021x *s_8021x, NMSetting8021x *s_8021x,
SchemeFunc scheme_func, SchemeFunc scheme_func,
PathFunc path_func, PathFunc path_func,
@ -353,12 +359,12 @@ setup_filepicker (GtkFileChooserButton *button,
if (privkey) { if (privkey) {
g_signal_connect (button, "selection-changed", g_signal_connect (button, "selection-changed",
(GCallback) private_key_picker_file_set_cb, (GCallback) private_key_picker_file_set_cb,
parent); self);
if (filename) if (filename)
private_key_picker_helper (parent, filename, FALSE); private_key_picker_helper (self, filename, FALSE);
} }
g_signal_connect_swapped (button, "selection-changed", G_CALLBACK (changed_cb), parent); g_signal_connect_swapped (button, "selection-changed", G_CALLBACK (changed_cb), self);
filter = eap_method_default_file_chooser_filter_new (privkey); filter = eap_method_default_file_chooser_filter_new (privkey);
gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (button), filter); gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (button), filter);
@ -373,9 +379,9 @@ setup_filepicker (GtkFileChooserButton *button,
} }
static void static void
update_secrets (EAPMethod *parent, NMConnection *connection) update_secrets (EAPMethod *method, NMConnection *connection)
{ {
EAPMethodTLS *self = (EAPMethodTLS *) parent; EAPMethodTLS *self = EAP_METHOD_TLS (method);
NMSetting8021x *s_8021x; NMSetting8021x *s_8021x;
HelperSecretFunc password_func; HelperSecretFunc password_func;
SchemeFunc scheme_func; SchemeFunc scheme_func;
@ -407,33 +413,59 @@ update_secrets (EAPMethod *parent, NMConnection *connection)
} }
static GtkWidget * static GtkWidget *
get_widget (EAPMethod *parent) get_widget (EAPMethod *method)
{ {
EAPMethodTLS *self = (EAPMethodTLS *) parent; EAPMethodTLS *self = EAP_METHOD_TLS (method);
return GTK_WIDGET (self->grid); return GTK_WIDGET (self->grid);
} }
static GtkWidget * static GtkWidget *
get_default_field (EAPMethod *parent) get_default_field (EAPMethod *method)
{ {
EAPMethodTLS *self = (EAPMethodTLS *) parent; EAPMethodTLS *self = EAP_METHOD_TLS (method);
return GTK_WIDGET (self->identity_entry); return GTK_WIDGET (self->identity_entry);
} }
static const gchar * static const gchar *
get_password_flags_name (EAPMethod *parent) get_password_flags_name (EAPMethod *method)
{ {
EAPMethodTLS *self = (EAPMethodTLS *) parent; EAPMethodTLS *self = EAP_METHOD_TLS (method);
return self->password_flags_name; return self->password_flags_name;
} }
static gboolean static gboolean
get_phase2 (EAPMethod *parent) get_phase2 (EAPMethod *method)
{ {
EAPMethodTLS *self = (EAPMethodTLS *) parent; EAPMethodTLS *self = EAP_METHOD_TLS (method);
return self->phase2; return self->phase2;
} }
static void
eap_method_tls_init (EAPMethodTLS *self)
{
}
static void
eap_method_tls_class_init (EAPMethodTLSClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->dispose = eap_method_tls_dispose;
}
static void
eap_method_iface_init (EAPMethodInterface *iface)
{
iface->validate = validate;
iface->add_to_size_group = add_to_size_group;
iface->fill_connection = fill_connection;
iface->update_secrets = update_secrets;
iface->get_widget = get_widget;
iface->get_default_field = get_default_field;
iface->get_password_flags_name = get_password_flags_name;
iface->get_phase2 = get_phase2;
}
EAPMethodTLS * EAPMethodTLS *
eap_method_tls_new (WirelessSecurity *ws_parent, eap_method_tls_new (WirelessSecurity *ws_parent,
NMConnection *connection, NMConnection *connection,
@ -441,25 +473,11 @@ eap_method_tls_new (WirelessSecurity *ws_parent,
gboolean secrets_only) gboolean secrets_only)
{ {
EAPMethodTLS *self; EAPMethodTLS *self;
EAPMethod *parent;
NMSetting8021x *s_8021x = NULL; NMSetting8021x *s_8021x = NULL;
gboolean ca_not_required = FALSE; gboolean ca_not_required = FALSE;
g_autoptr(GError) error = NULL; g_autoptr(GError) error = NULL;
parent = eap_method_init (sizeof (EAPMethodTLS), self = g_object_new (eap_method_tls_get_type (), NULL);
validate,
add_to_size_group,
fill_connection,
update_secrets,
get_widget,
get_default_field,
get_password_flags_name,
get_phase2,
destroy);
if (!parent)
return NULL;
self = (EAPMethodTLS *) parent;
self->phase2 = phase2; self->phase2 = phase2;
self->password_flags_name = phase2 ? self->password_flags_name = phase2 ?
NM_SETTING_802_1X_PHASE2_PRIVATE_KEY_PASSWORD : NM_SETTING_802_1X_PHASE2_PRIVATE_KEY_PASSWORD :
@ -496,32 +514,35 @@ eap_method_tls_new (WirelessSecurity *ws_parent,
if (s_8021x && nm_setting_802_1x_get_identity (s_8021x)) if (s_8021x && nm_setting_802_1x_get_identity (s_8021x))
gtk_entry_set_text (self->identity_entry, nm_setting_802_1x_get_identity (s_8021x)); gtk_entry_set_text (self->identity_entry, nm_setting_802_1x_get_identity (s_8021x));
setup_filepicker (self->user_cert_button, setup_filepicker (self,
self->user_cert_button,
_("Choose your personal certificate"), _("Choose your personal certificate"),
ws_parent, parent, s_8021x, ws_parent, s_8021x,
phase2 ? nm_setting_802_1x_get_phase2_client_cert_scheme : nm_setting_802_1x_get_client_cert_scheme, phase2 ? nm_setting_802_1x_get_phase2_client_cert_scheme : nm_setting_802_1x_get_client_cert_scheme,
phase2 ? nm_setting_802_1x_get_phase2_client_cert_path : nm_setting_802_1x_get_client_cert_path, phase2 ? nm_setting_802_1x_get_phase2_client_cert_path : nm_setting_802_1x_get_client_cert_path,
FALSE, TRUE); FALSE, TRUE);
setup_filepicker (self->ca_cert_button, setup_filepicker (self,
self->ca_cert_button,
_("Choose a Certificate Authority certificate"), _("Choose a Certificate Authority certificate"),
ws_parent, parent, s_8021x, ws_parent, s_8021x,
phase2 ? nm_setting_802_1x_get_phase2_ca_cert_scheme : nm_setting_802_1x_get_ca_cert_scheme, phase2 ? nm_setting_802_1x_get_phase2_ca_cert_scheme : nm_setting_802_1x_get_ca_cert_scheme,
phase2 ? nm_setting_802_1x_get_phase2_ca_cert_path : nm_setting_802_1x_get_ca_cert_path, phase2 ? nm_setting_802_1x_get_phase2_ca_cert_path : nm_setting_802_1x_get_ca_cert_path,
FALSE, FALSE); FALSE, FALSE);
setup_filepicker (self->private_key_button, setup_filepicker (self,
self->private_key_button,
_("Choose your private key"), _("Choose your private key"),
ws_parent, parent, s_8021x, ws_parent, s_8021x,
phase2 ? nm_setting_802_1x_get_phase2_private_key_scheme : nm_setting_802_1x_get_private_key_scheme, phase2 ? nm_setting_802_1x_get_phase2_private_key_scheme : nm_setting_802_1x_get_private_key_scheme,
phase2 ? nm_setting_802_1x_get_phase2_private_key_path : nm_setting_802_1x_get_private_key_path, phase2 ? nm_setting_802_1x_get_phase2_private_key_path : nm_setting_802_1x_get_private_key_path,
TRUE, FALSE); TRUE, FALSE);
if (connection && eap_method_ca_cert_ignore_get (parent, connection)) if (connection && eap_method_ca_cert_ignore_get (EAP_METHOD (self), connection))
ca_not_required = !gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (self->ca_cert_button)); ca_not_required = !gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (self->ca_cert_button));
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->ca_cert_not_required_check), ca_not_required); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->ca_cert_not_required_check), ca_not_required);
/* Fill secrets, if any */ /* Fill secrets, if any */
if (connection) if (connection)
update_secrets (parent, connection); update_secrets (EAP_METHOD (self), connection);
g_signal_connect_swapped (self->private_key_password_entry, "changed", G_CALLBACK (changed_cb), self); g_signal_connect_swapped (self->private_key_password_entry, "changed", G_CALLBACK (changed_cb), self);

View file

@ -20,20 +20,17 @@
* (C) Copyright 2007 - 2010 Red Hat, Inc. * (C) Copyright 2007 - 2010 Red Hat, Inc.
*/ */
#ifndef EAP_METHOD_TLS_H #pragma once
#define EAP_METHOD_TLS_H
#include "wireless-security.h" #include "wireless-security.h"
typedef struct _EAPMethodTLS EAPMethodTLS; G_BEGIN_DECLS
G_DECLARE_FINAL_TYPE (EAPMethodTLS, eap_method_tls, EAP, METHOD_TLS, GObject)
EAPMethodTLS *eap_method_tls_new (WirelessSecurity *ws_parent, EAPMethodTLS *eap_method_tls_new (WirelessSecurity *ws_parent,
NMConnection *connection, NMConnection *connection,
gboolean phase2, gboolean phase2,
gboolean secrets_only); gboolean secrets_only);
static void eap_method_tls_unref (EAPMethodTLS *method) { eap_method_unref (EAP_METHOD (method)); } G_END_DECLS
G_DEFINE_AUTOPTR_CLEANUP_FUNC (EAPMethodTLS, eap_method_tls_unref)
#endif /* EAP_METHOD_TLS_H */

View file

@ -35,7 +35,7 @@
#define I_METHOD_COLUMN 1 #define I_METHOD_COLUMN 1
struct _EAPMethodTTLS { struct _EAPMethodTTLS {
EAPMethod parent; GObject parent;
GtkBuilder *builder; GtkBuilder *builder;
GtkEntry *anon_identity_entry; GtkEntry *anon_identity_entry;
@ -55,19 +55,26 @@ struct _EAPMethodTTLS {
gboolean is_editor; gboolean is_editor;
}; };
static void eap_method_iface_init (EAPMethodInterface *);
G_DEFINE_TYPE_WITH_CODE (EAPMethodTTLS, eap_method_ttls, G_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE (eap_method_get_type (), eap_method_iface_init))
static void static void
destroy (EAPMethod *parent) eap_method_ttls_dispose (GObject *object)
{ {
EAPMethodTTLS *self = (EAPMethodTTLS *) parent; EAPMethodTTLS *self = EAP_METHOD_TTLS (object);
g_clear_object (&self->builder); g_clear_object (&self->builder);
g_clear_object (&self->size_group); g_clear_object (&self->size_group);
G_OBJECT_CLASS (eap_method_ttls_parent_class)->dispose (object);
} }
static gboolean static gboolean
validate (EAPMethod *parent, GError **error) validate (EAPMethod *method, GError **error)
{ {
EAPMethodTTLS *self = (EAPMethodTTLS *) parent; EAPMethodTTLS *self = EAP_METHOD_TTLS (method);
GtkTreeModel *model; GtkTreeModel *model;
GtkTreeIter iter; GtkTreeIter iter;
g_autoptr(EAPMethod) eap = NULL; g_autoptr(EAPMethod) eap = NULL;
@ -102,9 +109,9 @@ ca_cert_not_required_toggled (EAPMethodTTLS *self)
} }
static void static void
add_to_size_group (EAPMethod *parent, GtkSizeGroup *group) add_to_size_group (EAPMethod *method, GtkSizeGroup *group)
{ {
EAPMethodTTLS *self = (EAPMethodTTLS *) parent; EAPMethodTTLS *self = EAP_METHOD_TTLS (method);
GtkTreeModel *model; GtkTreeModel *model;
GtkTreeIter iter; GtkTreeIter iter;
g_autoptr(EAPMethod) eap = NULL; g_autoptr(EAPMethod) eap = NULL;
@ -126,9 +133,9 @@ add_to_size_group (EAPMethod *parent, GtkSizeGroup *group)
} }
static void static void
fill_connection (EAPMethod *parent, NMConnection *connection, NMSettingSecretFlags flags) fill_connection (EAPMethod *method, NMConnection *connection, NMSettingSecretFlags flags)
{ {
EAPMethodTTLS *self = (EAPMethodTTLS *) parent; EAPMethodTTLS *self = EAP_METHOD_TTLS (method);
NMSetting8021x *s_8021x; NMSetting8021x *s_8021x;
NMSetting8021xCKFormat format = NM_SETTING_802_1X_CK_FORMAT_UNKNOWN; NMSetting8021xCKFormat format = NM_SETTING_802_1X_CK_FORMAT_UNKNOWN;
const char *text; const char *text;
@ -157,7 +164,7 @@ fill_connection (EAPMethod *parent, NMConnection *connection, NMSettingSecretFla
g_warning ("Couldn't read CA certificate '%s': %s", filename, error ? error->message : "(unknown)"); g_warning ("Couldn't read CA certificate '%s': %s", filename, error ? error->message : "(unknown)");
ca_cert_error = TRUE; ca_cert_error = TRUE;
} }
eap_method_ca_cert_ignore_set (parent, connection, filename, ca_cert_error); eap_method_ca_cert_ignore_set (method, connection, filename, ca_cert_error);
model = gtk_combo_box_get_model (self->inner_auth_combo); model = gtk_combo_box_get_model (self->inner_auth_combo);
gtk_combo_box_get_active_iter (self->inner_auth_combo, &iter); gtk_combo_box_get_active_iter (self->inner_auth_combo, &iter);
@ -339,31 +346,31 @@ inner_auth_combo_init (EAPMethodTTLS *self,
} }
static void static void
update_secrets (EAPMethod *parent, NMConnection *connection) update_secrets (EAPMethod *method, NMConnection *connection)
{ {
EAPMethodTTLS *self = (EAPMethodTTLS *) parent; EAPMethodTTLS *self = EAP_METHOD_TTLS (method);
eap_method_phase2_update_secrets_helper (parent, eap_method_phase2_update_secrets_helper (method,
connection, connection,
self->inner_auth_combo, self->inner_auth_combo,
I_METHOD_COLUMN); I_METHOD_COLUMN);
} }
static GtkWidget * static GtkWidget *
get_widget (EAPMethod *parent) get_widget (EAPMethod *method)
{ {
EAPMethodTTLS *self = (EAPMethodTTLS *) parent; EAPMethodTTLS *self = EAP_METHOD_TTLS (method);
return GTK_WIDGET (self->grid); return GTK_WIDGET (self->grid);
} }
static GtkWidget * static GtkWidget *
get_default_field (EAPMethod *parent) get_default_field (EAPMethod *method)
{ {
EAPMethodTTLS *self = (EAPMethodTTLS *) parent; EAPMethodTTLS *self = EAP_METHOD_TTLS (method);
return GTK_WIDGET (self->anon_identity_entry); return GTK_WIDGET (self->anon_identity_entry);
} }
static const gchar * static const gchar *
get_password_flags_name (EAPMethod *parent) get_password_flags_name (EAPMethod *method)
{ {
return NM_SETTING_802_1X_PASSWORD; return NM_SETTING_802_1X_PASSWORD;
} }
@ -374,33 +381,44 @@ changed_cb (EAPMethodTTLS *self)
wireless_security_notify_changed (self->sec_parent); wireless_security_notify_changed (self->sec_parent);
} }
static void
eap_method_ttls_init (EAPMethodTTLS *self)
{
}
static void
eap_method_ttls_class_init (EAPMethodTTLSClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->dispose = eap_method_ttls_dispose;
}
static void
eap_method_iface_init (EAPMethodInterface *iface)
{
iface->validate = validate;
iface->add_to_size_group = add_to_size_group;
iface->fill_connection = fill_connection;
iface->update_secrets = update_secrets;
iface->get_widget = get_widget;
iface->get_default_field = get_default_field;
iface->get_password_flags_name = get_password_flags_name;
}
EAPMethodTTLS * EAPMethodTTLS *
eap_method_ttls_new (WirelessSecurity *ws_parent, eap_method_ttls_new (WirelessSecurity *ws_parent,
NMConnection *connection, NMConnection *connection,
gboolean is_editor, gboolean is_editor,
gboolean secrets_only) gboolean secrets_only)
{ {
EAPMethod *parent;
EAPMethodTTLS *self; EAPMethodTTLS *self;
GtkFileFilter *filter; GtkFileFilter *filter;
NMSetting8021x *s_8021x = NULL; NMSetting8021x *s_8021x = NULL;
const char *filename; const char *filename;
g_autoptr(GError) error = NULL; g_autoptr(GError) error = NULL;
parent = eap_method_init (sizeof (EAPMethodTTLS), self = g_object_new (eap_method_ttls_get_type (), NULL);
validate,
add_to_size_group,
fill_connection,
update_secrets,
get_widget,
get_default_field,
get_password_flags_name,
NULL,
destroy);
if (!parent)
return NULL;
self = (EAPMethodTTLS *) parent;
self->sec_parent = ws_parent; self->sec_parent = ws_parent;
self->is_editor = is_editor; self->is_editor = is_editor;
@ -441,7 +459,7 @@ eap_method_ttls_new (WirelessSecurity *ws_parent,
gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (self->ca_cert_button), filename); gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (self->ca_cert_button), filename);
} }
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->ca_cert_not_required_check), gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->ca_cert_not_required_check),
!filename && eap_method_ca_cert_ignore_get (parent, connection)); !filename && eap_method_ca_cert_ignore_get (EAP_METHOD (self), connection));
} }
if (s_8021x && nm_setting_802_1x_get_anonymous_identity (s_8021x)) if (s_8021x && nm_setting_802_1x_get_anonymous_identity (s_8021x))

View file

@ -20,20 +20,17 @@
* (C) Copyright 2007 - 2010 Red Hat, Inc. * (C) Copyright 2007 - 2010 Red Hat, Inc.
*/ */
#ifndef EAP_METHOD_TTLS_H #pragma once
#define EAP_METHOD_TTLS_H
#include "wireless-security.h" #include "wireless-security.h"
typedef struct _EAPMethodTTLS EAPMethodTTLS; G_BEGIN_DECLS
G_DECLARE_FINAL_TYPE (EAPMethodTTLS, eap_method_ttls, EAP, METHOD_TTLS, GObject)
EAPMethodTTLS *eap_method_ttls_new (WirelessSecurity *ws_parent, EAPMethodTTLS *eap_method_ttls_new (WirelessSecurity *ws_parent,
NMConnection *connection, NMConnection *connection,
gboolean is_editor, gboolean is_editor,
gboolean secrets_only); gboolean secrets_only);
static void eap_method_ttls_unref (EAPMethodTTLS *method) { eap_method_unref (EAP_METHOD (method)); } G_END_DECLS
G_DEFINE_AUTOPTR_CLEANUP_FUNC (EAPMethodTTLS, eap_method_ttls_unref)
#endif /* EAP_METHOD_TTLS_H */

View file

@ -33,18 +33,11 @@
#include "utils.h" #include "utils.h"
#include "helpers.h" #include "helpers.h"
GType G_DEFINE_INTERFACE (EAPMethod, eap_method, G_TYPE_OBJECT)
eap_method_get_type (void)
static void
eap_method_default_init (EAPMethodInterface *iface)
{ {
static GType type_id = 0;
if (!type_id) {
type_id = g_boxed_type_register_static ("CcEAPMethod",
(GBoxedCopyFunc) eap_method_ref,
(GBoxedFreeFunc) eap_method_unref);
}
return type_id;
} }
GtkWidget * GtkWidget *
@ -52,7 +45,7 @@ eap_method_get_widget (EAPMethod *self)
{ {
g_return_val_if_fail (self != NULL, NULL); g_return_val_if_fail (self != NULL, NULL);
return self->get_widget (self); return EAP_METHOD_GET_IFACE (self)->get_widget (self);
} }
GtkWidget * GtkWidget *
@ -60,7 +53,7 @@ eap_method_get_default_field (EAPMethod *self)
{ {
g_return_val_if_fail (self != NULL, NULL); g_return_val_if_fail (self != NULL, NULL);
return self->get_default_field (self); return EAP_METHOD_GET_IFACE (self)->get_default_field (self);
} }
const gchar * const gchar *
@ -68,8 +61,8 @@ eap_method_get_password_flags_name (EAPMethod *self)
{ {
g_return_val_if_fail (self != NULL, NULL); g_return_val_if_fail (self != NULL, NULL);
if (self->get_password_flags_name) if (EAP_METHOD_GET_IFACE (self)->get_password_flags_name)
return self->get_password_flags_name (self); return EAP_METHOD_GET_IFACE (self)->get_password_flags_name (self);
else else
return NULL; return NULL;
} }
@ -79,8 +72,8 @@ eap_method_get_phase2 (EAPMethod *self)
{ {
g_return_val_if_fail (self != NULL, FALSE); g_return_val_if_fail (self != NULL, FALSE);
if (self->get_phase2) if (EAP_METHOD_GET_IFACE (self)->get_phase2)
return self->get_phase2 (self); return EAP_METHOD_GET_IFACE (self)->get_phase2 (self);
else else
return FALSE; return FALSE;
} }
@ -92,8 +85,7 @@ eap_method_validate (EAPMethod *self, GError **error)
g_return_val_if_fail (self != NULL, FALSE); g_return_val_if_fail (self != NULL, FALSE);
g_assert (self->validate); result = (*(EAP_METHOD_GET_IFACE (self)->validate)) (self, error);
result = (*(self->validate)) (self, error);
if (!result && error && !*error) if (!result && error && !*error)
g_set_error_literal (error, NMA_ERROR, NMA_ERROR_GENERIC, _("undefined error in 802.1X security (wpa-eap)")); g_set_error_literal (error, NMA_ERROR, NMA_ERROR_GENERIC, _("undefined error in 802.1X security (wpa-eap)"));
return result; return result;
@ -105,8 +97,7 @@ eap_method_add_to_size_group (EAPMethod *self, GtkSizeGroup *group)
g_return_if_fail (self != NULL); g_return_if_fail (self != NULL);
g_return_if_fail (group != NULL); g_return_if_fail (group != NULL);
g_assert (self->add_to_size_group); return (*(EAP_METHOD_GET_IFACE (self)->add_to_size_group)) (self, group);
return (*(self->add_to_size_group)) (self, group);
} }
void void
@ -117,8 +108,7 @@ eap_method_fill_connection (EAPMethod *self,
g_return_if_fail (self != NULL); g_return_if_fail (self != NULL);
g_return_if_fail (connection != NULL); g_return_if_fail (connection != NULL);
g_assert (self->fill_connection); return (*(EAP_METHOD_GET_IFACE (self)->fill_connection)) (self, connection, flags);
return (*(self->fill_connection)) (self, connection, flags);
} }
void void
@ -141,72 +131,12 @@ eap_method_phase2_update_secrets_helper (EAPMethod *self,
g_autoptr(EAPMethod) eap = NULL; g_autoptr(EAPMethod) eap = NULL;
gtk_tree_model_get (model, &iter, column, &eap, -1); gtk_tree_model_get (model, &iter, column, &eap, -1);
if (eap && eap->update_secrets) if (eap && EAP_METHOD_GET_IFACE (eap)->update_secrets)
eap->update_secrets (self, connection); EAP_METHOD_GET_IFACE (eap)->update_secrets (self, connection);
} while (gtk_tree_model_iter_next (model, &iter)); } while (gtk_tree_model_iter_next (model, &iter));
} }
} }
EAPMethod *
eap_method_init (gsize obj_size,
EMValidateFunc validate,
EMAddToSizeGroupFunc add_to_size_group,
EMFillConnectionFunc fill_connection,
EMUpdateSecretsFunc update_secrets,
EMGetWidgetFunc get_widget,
EMGetWidgetFunc get_default_field,
EMGetStringFunc get_password_flags_name,
EMGetBooleanFunc get_phase2,
EMDestroyFunc destroy)
{
g_autoptr(EAPMethod) self = NULL;
g_return_val_if_fail (obj_size > 0, NULL);
self = g_slice_alloc0 (obj_size);
g_assert (self);
self->refcount = 1;
self->obj_size = obj_size;
self->validate = validate;
self->add_to_size_group = add_to_size_group;
self->fill_connection = fill_connection;
self->update_secrets = update_secrets;
self->get_widget = get_widget;
self->get_default_field = get_default_field;
self->get_password_flags_name = get_password_flags_name;
self->get_phase2 = get_phase2;
self->destroy = destroy;
return g_steal_pointer (&self);
}
EAPMethod *
eap_method_ref (EAPMethod *self)
{
g_return_val_if_fail (self != NULL, NULL);
g_return_val_if_fail (self->refcount > 0, NULL);
self->refcount++;
return self;
}
void
eap_method_unref (EAPMethod *self)
{
g_return_if_fail (self != NULL);
g_return_if_fail (self->refcount > 0);
self->refcount--;
if (self->refcount == 0) {
if (self->destroy)
self->destroy (self);
g_slice_free1 (self->obj_size, self);
}
}
gboolean gboolean
eap_method_validate_filepicker (GtkFileChooser *chooser, eap_method_validate_filepicker (GtkFileChooser *chooser,
guint32 item_type, guint32 item_type,

View file

@ -20,40 +20,28 @@
* Copyright 2007 - 2014 Red Hat, Inc. * Copyright 2007 - 2014 Red Hat, Inc.
*/ */
#ifndef EAP_METHOD_H #pragma once
#define EAP_METHOD_H
#include <glib-object.h>
#include <NetworkManager.h> #include <NetworkManager.h>
typedef struct _EAPMethod EAPMethod; G_BEGIN_DECLS
typedef void (*EMAddToSizeGroupFunc) (EAPMethod *method, GtkSizeGroup *group); G_DECLARE_INTERFACE (EAPMethod, eap_method, EAP, METHOD, GObject)
typedef void (*EMFillConnectionFunc) (EAPMethod *method, NMConnection *connection, NMSettingSecretFlags flags);
typedef void (*EMUpdateSecretsFunc) (EAPMethod *method, NMConnection *connection);
typedef void (*EMDestroyFunc) (EAPMethod *method);
typedef gboolean (*EMValidateFunc) (EAPMethod *method, GError **error);
typedef GtkWidget* (*EMGetWidgetFunc) (EAPMethod *method);
typedef const gchar* (*EMGetStringFunc) (EAPMethod *method);
typedef gboolean (*EMGetBooleanFunc) (EAPMethod *method);
struct _EAPMethod { struct _EAPMethodInterface {
guint32 refcount; GTypeInterface g_iface;
gsize obj_size;
EMAddToSizeGroupFunc add_to_size_group; void (*add_to_size_group) (EAPMethod *method, GtkSizeGroup *group);
EMFillConnectionFunc fill_connection; void (*fill_connection) (EAPMethod *method, NMConnection *connection, NMSettingSecretFlags flags);
EMUpdateSecretsFunc update_secrets; void (*update_secrets) (EAPMethod *method, NMConnection *connection);
EMValidateFunc validate; gboolean (*validate) (EAPMethod *method, GError **error);
EMGetWidgetFunc get_widget; GtkWidget* (*get_widget) (EAPMethod *method);
EMGetWidgetFunc get_default_field; GtkWidget* (*get_default_field) (EAPMethod *method);
EMGetStringFunc get_password_flags_name; const gchar* (*get_password_flags_name) (EAPMethod *method);
EMGetBooleanFunc get_phase2; gboolean (*get_phase2) (EAPMethod *method);
EMDestroyFunc destroy;
}; };
#define EAP_METHOD(x) ((EAPMethod *) x)
GtkWidget *eap_method_get_widget (EAPMethod *method); GtkWidget *eap_method_get_widget (EAPMethod *method);
GtkWidget *eap_method_get_default_field (EAPMethod *method); GtkWidget *eap_method_get_default_field (EAPMethod *method);
@ -70,25 +58,8 @@ void eap_method_fill_connection (EAPMethod *method,
NMConnection *connection, NMConnection *connection,
NMSettingSecretFlags flags); NMSettingSecretFlags flags);
EAPMethod *eap_method_ref (EAPMethod *method);
void eap_method_unref (EAPMethod *method);
GType eap_method_get_type (void);
/* Below for internal use only */ /* Below for internal use only */
EAPMethod *eap_method_init (gsize obj_size,
EMValidateFunc validate,
EMAddToSizeGroupFunc add_to_size_group,
EMFillConnectionFunc fill_connection,
EMUpdateSecretsFunc update_secrets,
EMGetWidgetFunc get_widget,
EMGetWidgetFunc get_default_field,
EMGetStringFunc get_password_flags_name,
EMGetBooleanFunc get_phase2,
EMDestroyFunc destroy);
GtkFileFilter * eap_method_default_file_chooser_filter_new (gboolean privkey); GtkFileFilter * eap_method_default_file_chooser_filter_new (gboolean privkey);
gboolean eap_method_is_encrypted_private_key (const char *path); gboolean eap_method_is_encrypted_private_key (const char *path);
@ -122,6 +93,4 @@ gboolean eap_method_ca_cert_ignore_get (EAPMethod *method, NMConnection *connect
void eap_method_ca_cert_ignore_save (NMConnection *connection); void eap_method_ca_cert_ignore_save (NMConnection *connection);
void eap_method_ca_cert_ignore_load (NMConnection *connection); void eap_method_ca_cert_ignore_load (NMConnection *connection);
G_DEFINE_AUTOPTR_CLEANUP_FUNC (EAPMethod, eap_method_unref) G_END_DECLS
#endif /* EAP_METHOD_H */