[PATCH 21/25] Replace 'auth_type' and 'auth_subtype' operations with signals
- From: "Daniel P. Berrange" <berrange redhat com>
- To: gtk-vnc-list gnome org
- Cc: "Daniel P. Berrange" <berrange redhat com>
- Subject: [PATCH 21/25] Replace 'auth_type' and 'auth_subtype' operations with signals
- Date: Sat, 21 Nov 2009 13:28:10 +0000
Remove the 'auth_type' and 'auth_subtype' operation callbacks.
Introduce new 'vnc-auth-choose-type' and 'vnc-auth-choose-subtype'
signals
---
src/vncconnection.c | 92 +++++++++++++++++++++++++++++++++++++++++++-------
src/vncconnection.h | 4 +-
src/vncdisplay.c | 56 ++++++++++++++++++-------------
src/vncmarshal.txt | 1 +
4 files changed, 115 insertions(+), 38 deletions(-)
diff --git a/src/vncconnection.c b/src/vncconnection.c
index 3def590..0eb3100 100644
--- a/src/vncconnection.c
+++ b/src/vncconnection.c
@@ -203,13 +203,15 @@ enum {
VNC_AUTH_FAILURE,
VNC_AUTH_UNSUPPORTED,
VNC_AUTH_CREDENTIAL,
+ VNC_AUTH_CHOOSE_TYPE,
+ VNC_AUTH_CHOOSE_SUBTYPE,
VNC_LAST_SIGNAL,
};
static guint signals[VNC_LAST_SIGNAL] = { 0, 0, 0, 0,
0, 0, 0, 0,
- 0, 0, };
+ 0, 0, 0, 0};
#define nibhi(a) (((a) >> 4) & 0x0F)
#define niblo(a) ((a) & 0x0F)
@@ -396,6 +398,7 @@ struct signal_data
const char *authReason;
unsigned int authUnsupported;
GValueArray *authCred;
+ GValueArray *authTypes;
} params;
};
@@ -477,6 +480,21 @@ static gboolean do_vnc_connection_emit_main_context(gpointer opaque)
data->params.authCred);
break;
+ case VNC_AUTH_CHOOSE_TYPE:
+ g_signal_emit(G_OBJECT(data->conn),
+ signals[data->signum],
+ 0,
+ data->params.authTypes);
+ break;
+
+ case VNC_AUTH_CHOOSE_SUBTYPE:
+ g_signal_emit(G_OBJECT(data->conn),
+ signals[data->signum],
+ 0,
+ data->conn->priv->auth_type,
+ data->params.authTypes);
+ break;
+
}
coroutine_yieldto(data->caller, NULL);
@@ -3407,6 +3425,37 @@ static gboolean vnc_connection_has_auth_subtype(gpointer data)
return TRUE;
}
+static void vnc_connection_choose_auth(VncConnection *conn,
+ int signum,
+ unsigned int ntypes,
+ unsigned int *types)
+{
+ VncConnectionPrivate *priv = conn->priv;
+ struct signal_data sigdata;
+ GValueArray *authTypes;
+ GValue authType;
+
+ authTypes = g_value_array_new(0);
+
+ for (int i = 0 ; i < ntypes ; i++) {
+ memset(&authType, 0, sizeof(authType));
+
+ if (signum == VNC_AUTH_CHOOSE_TYPE) {
+ g_value_init(&authType, VNC_TYPE_CONNECTION_AUTH);
+ } else {
+ if (priv->auth_type == GVNC_AUTH_VENCRYPT)
+ g_value_init(&authType, VNC_TYPE_CONNECTION_AUTH_VENCRYPT);
+ else
+ g_value_init(&authType, VNC_TYPE_CONNECTION_AUTH);
+ }
+ g_value_set_enum(&authType, types[i]);
+ authTypes = g_value_array_append(authTypes, &authType);
+ }
+
+ sigdata.params.authCred = authTypes;
+ vnc_connection_emit_main_context(conn, signum, &sigdata);
+ g_value_array_free(authTypes);
+}
static gboolean vnc_connection_perform_auth_tls(VncConnection *conn)
{
@@ -3444,11 +3493,9 @@ static gboolean vnc_connection_perform_auth_tls(VncConnection *conn)
GVNC_DEBUG("Possible sub-auth %d", auth[i]);
}
- if (priv->has_error || !priv->ops.auth_subtype)
+ if (priv->has_error)
return FALSE;
-
- if (!priv->ops.auth_subtype(priv->ops_data, nauth, auth))
- priv->has_error = TRUE;
+ vnc_connection_choose_auth(conn, VNC_AUTH_CHOOSE_TYPE, nauth, auth);
if (priv->has_error)
return FALSE;
@@ -3519,11 +3566,9 @@ static gboolean vnc_connection_perform_auth_vencrypt(VncConnection *conn)
GVNC_DEBUG("Possible auth %d", auth[i]);
}
- if (priv->has_error || !priv->ops.auth_subtype)
+ if (priv->has_error)
return FALSE;
-
- if (!priv->ops.auth_subtype(priv->ops_data, nauth, auth))
- priv->has_error = TRUE;
+ vnc_connection_choose_auth(conn, VNC_AUTH_CHOOSE_SUBTYPE, nauth, auth);
if (priv->has_error)
return FALSE;
@@ -3637,11 +3682,9 @@ static gboolean vnc_connection_perform_auth(VncConnection *conn)
GVNC_DEBUG("Possible auth %u", auth[i]);
}
- if (priv->has_error || !priv->ops.auth_type)
+ if (priv->has_error)
return FALSE;
-
- if (!priv->ops.auth_type(priv->ops_data, nauth, auth))
- priv->has_error = TRUE;
+ vnc_connection_choose_auth(conn, VNC_AUTH_CHOOSE_TYPE, nauth, auth);
if (priv->has_error)
return FALSE;
@@ -3847,6 +3890,29 @@ static void vnc_connection_class_init(VncConnectionClass *klass)
1,
G_TYPE_VALUE_ARRAY);
+ signals[VNC_AUTH_CHOOSE_TYPE] =
+ g_signal_new ("vnc-auth-choose-type",
+ G_OBJECT_CLASS_TYPE (object_class),
+ G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET (VncConnectionClass, vnc_auth_choose_type),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__BOXED,
+ G_TYPE_NONE,
+ 1,
+ G_TYPE_VALUE_ARRAY);
+
+ signals[VNC_AUTH_CHOOSE_SUBTYPE] =
+ g_signal_new ("vnc-auth-choose-subtype",
+ G_OBJECT_CLASS_TYPE (object_class),
+ G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET (VncConnectionClass, vnc_auth_choose_subtype),
+ NULL, NULL,
+ g_cclosure_user_marshal_VOID__UINT_BOXED,
+ G_TYPE_NONE,
+ 2,
+ G_TYPE_UINT,
+ G_TYPE_VALUE_ARRAY);
+
g_type_class_add_private(klass, sizeof(VncConnectionPrivate));
}
diff --git a/src/vncconnection.h b/src/vncconnection.h
index 866d461..b5b52fc 100644
--- a/src/vncconnection.h
+++ b/src/vncconnection.h
@@ -62,14 +62,14 @@ struct _VncConnectionClass
void (*vnc_auth_failure)(VncConnection *conn, const char *reason);
void (*vnc_auth_unsupported)(VncConnection *conn, unsigned int authType);
void (*vnc_auth_credential)(VncConnection *conn, GValueArray *creds);
+ void (*vnc_auth_choose_type)(VncConnection *conn, GValueArray *types);
+ void (*vnc_auth_choose_subtype)(VncConnection *conn, unsigned int type, GValueArray *subtypes);
};
typedef void (rgb24_render_func)(void *, int, int, int, int, guint8 *, int);
struct vnc_connection_ops
{
- gboolean (*auth_type)(void *, unsigned int, unsigned int *);
- gboolean (*auth_subtype)(void *, unsigned int, unsigned int *);
gboolean (*set_color_map_entry)(void *, int, int, int, int);
gboolean (*render_jpeg)(void *, rgb24_render_func *render, void *,
int, int, int, int, guint8 *, int);
diff --git a/src/vncdisplay.c b/src/vncdisplay.c
index eeaf524..3a45401 100644
--- a/src/vncdisplay.c
+++ b/src/vncdisplay.c
@@ -1092,55 +1092,63 @@ static void on_auth_cred(VncConnection *conn G_GNUC_UNUSED,
g_signal_emit(G_OBJECT(obj), signals[VNC_AUTH_CREDENTIAL], 0, creds);
}
-static gboolean on_auth_type(void *opaque, unsigned int ntype, unsigned int *types)
+static void on_auth_choose_type(VncConnection *conn G_GNUC_UNUSED,
+ GValueArray *types,
+ gpointer opaque)
{
VncDisplay *obj = VNC_DISPLAY(opaque);
VncDisplayPrivate *priv = obj->priv;
GSList *l;
guint i;
- if (!ntype)
- return TRUE;
+ if (!types->n_values)
+ return;
for (l = priv->preferable_auths; l; l=l->next) {
int pref = GPOINTER_TO_UINT (l->data);
- for (i=0; i<ntype; i++) {
- if (pref == types[i]) {
- vnc_connection_set_auth_type(priv->conn, types[i]);
- return TRUE;
+ for (i=0; i< types->n_values; i++) {
+ GValue *type = g_value_array_get_nth(types, i);
+ if (pref == g_value_get_enum(type)) {
+ vnc_connection_set_auth_type(priv->conn, pref);
+ return;
}
}
}
- vnc_connection_set_auth_type(priv->conn, types[0]);
- return TRUE;
+ GValue *type = g_value_array_get_nth(types, 0);
+ vnc_connection_set_auth_type(priv->conn, g_value_get_enum(type));
}
-static gboolean on_auth_subtype(void *opaque, unsigned int ntype, unsigned int *types)
+static void on_auth_choose_subtype(VncConnection *conn G_GNUC_UNUSED,
+ unsigned int type,
+ GValueArray *subtypes,
+ gpointer opaque)
{
VncDisplay *obj = VNC_DISPLAY(opaque);
VncDisplayPrivate *priv = obj->priv;
-
GSList *l;
guint i;
- if (!ntype)
- return TRUE;
+ if (!subtypes->n_values)
+ return;
- for (l = priv->preferable_auths; l; l=l->next) {
- int pref = GPOINTER_TO_UINT (l->data);
+ if (type == GVNC_AUTH_TLS) {
+ for (l = priv->preferable_auths; l; l=l->next) {
+ int pref = GPOINTER_TO_UINT (l->data);
- for (i=0; i<ntype; i++) {
- if (pref == types[i]) {
- vnc_connection_set_auth_subtype(priv->conn, types[i]);
- return TRUE;
+ for (i=0; i< subtypes->n_values; i++) {
+ GValue *subtype = g_value_array_get_nth(subtypes, i);
+ if (pref == g_value_get_enum(subtype)) {
+ vnc_connection_set_auth_type(priv->conn, pref);
+ return;
+ }
}
}
}
- vnc_connection_set_auth_subtype(priv->conn, types[0]);
- return TRUE;
+ GValue *subtype = g_value_array_get_nth(subtypes, 0);
+ vnc_connection_set_auth_subtype(priv->conn, g_value_get_enum(subtype));
}
static void on_auth_failure(VncConnection *conn G_GNUC_UNUSED,
@@ -1274,8 +1282,6 @@ static gboolean on_render_jpeg(void *opaque G_GNUC_UNUSED,
}
static const struct vnc_connection_ops vnc_display_ops = {
- .auth_type = on_auth_type,
- .auth_subtype = on_auth_subtype,
.render_jpeg = on_render_jpeg,
};
@@ -1985,6 +1991,10 @@ static void vnc_display_init(VncDisplay *display)
G_CALLBACK(on_auth_unsupported), display);
g_signal_connect(G_OBJECT(priv->conn), "vnc-auth-credential",
G_CALLBACK(on_auth_cred), display);
+ g_signal_connect(G_OBJECT(priv->conn), "vnc-auth-choose-type",
+ G_CALLBACK(on_auth_choose_type), display);
+ g_signal_connect(G_OBJECT(priv->conn), "vnc-auth-choose-subtype",
+ G_CALLBACK(on_auth_choose_subtype), display);
}
gboolean vnc_display_set_credential(VncDisplay *obj, int type, const gchar *data)
diff --git a/src/vncmarshal.txt b/src/vncmarshal.txt
index fc3ca85..b60bcaf 100644
--- a/src/vncmarshal.txt
+++ b/src/vncmarshal.txt
@@ -1,2 +1,3 @@
VOID:INT,INT
VOID:INT,INT,INT,INT
+VOID:UINT,BOXED
--
1.6.5.2
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]