[gedit-collaboration] Use new async sasl API for authentication
- From: Jesse van den Kieboom <jessevdk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit-collaboration] Use new async sasl API for authentication
- Date: Sun, 9 Jan 2011 15:05:02 +0000 (UTC)
commit 5b426f34ad4f0792f518b717acd109cdaebbe0ed
Author: Jesse van den Kieboom <jesse vandenkieboom epfl ch>
Date: Sun Jan 9 16:04:27 2011 +0100
Use new async sasl API for authentication
src/Makefile.am | 22 +++++-
src/gedit-collaboration-marshal.list | 1 +
src/gedit-collaboration-password-dialog.ui | 1 -
src/gedit-collaboration-user.c | 95 +++++++++++++--------------
src/gedit-collaboration-user.h | 4 +-
src/gedit-collaboration-window-helper.c | 100 ++++++++++++++++++++--------
6 files changed, 139 insertions(+), 84 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index a04c7ef..b510565 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,4 +1,4 @@
-# -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+# -*- Mode: Makefile; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
# collaboration plugin
plugindir = $(GEDIT_PLUGINS_LIBS_DIR)
@@ -12,7 +12,12 @@ INCLUDES = \
plugin_LTLIBRARIES = libcollaboration.la
+BUILT_SOURCES = \
+ gedit-collaboration-marshal.c \
+ gedit-collaboration-marshal.h
+
libcollaboration_la_SOURCES = \
+ $(BUILT_SOURCES) \
gedit-collaboration-plugin.h \
gedit-collaboration-plugin.c \
gedit-collaboration.h \
@@ -61,11 +66,22 @@ ui_DATA = \
plugin_DATA = $(plugin_in_files:.plugin.desktop.in=.plugin)
+gedit-collaboration-marshal.h: gedit-collaboration-marshal.list $(GLIB_GENMARSHAL)
+ $(AM_V_GEN) $(GLIB_GENMARSHAL) $< --header --prefix=gedit_collaboration_marshal > $@
+
+gedit-collaboration-marshal.c: gedit-collaboration-marshal.list $(GLIB_GENMARSHAL)
+ $(AM_V_GEN) echo "#include \"gedit-collaboration-marshal.h\"" > $@ && \
+ $(GLIB_GENMARSHAL) $< --body --prefix=gedit_collaboration_marshal >> $@
+
EXTRA_DIST = \
$(plugin_in_files) \
- $(ui_DATA)
+ $(ui_DATA) \
+ gedit-collaboration-marshal.list
-CLEANFILES = $(plugin_DATA)
+CLEANFILES = $(plugin_DATA) $(BUILT_SOURCES)
DISTCLEANFILES = $(plugin_DATA)
+dist-hook:
+ cd $(distdir); rm -f $(BUILT_SOURCES)
+
-include $(top_srcdir)/git.mk
diff --git a/src/gedit-collaboration-marshal.list b/src/gedit-collaboration-marshal.list
new file mode 100644
index 0000000..9ee12da
--- /dev/null
+++ b/src/gedit-collaboration-marshal.list
@@ -0,0 +1 @@
+BOOL:OBJECT
diff --git a/src/gedit-collaboration-password-dialog.ui b/src/gedit-collaboration-password-dialog.ui
index ff566d9..a12968a 100644
--- a/src/gedit-collaboration-password-dialog.ui
+++ b/src/gedit-collaboration-password-dialog.ui
@@ -4,7 +4,6 @@
<!-- interface-naming-policy project-wide -->
<object class="GtkDialog" id="dialog_password">
<property name="border_width">5</property>
- <property name="modal">True</property>
<property name="icon_name">dialog-password</property>
<property name="type_hint">normal</property>
<property name="urgency_hint">True</property>
diff --git a/src/gedit-collaboration-user.c b/src/gedit-collaboration-user.c
index a3a42d2..556bc6b 100644
--- a/src/gedit-collaboration-user.c
+++ b/src/gedit-collaboration-user.c
@@ -2,6 +2,7 @@
#include "gedit-collaboration-user.h"
#include "gedit-collaboration.h"
+#include "gedit-collaboration-marshal.h"
#include <string.h>
#include <math.h>
@@ -19,9 +20,10 @@ struct _GeditCollaborationUserPrivate
gchar *name;
gdouble hue;
- Gsasl *sasl_context;
+ InfSaslContext *sasl_context;
+ InfSaslContextSession *sasl_session;
+
gchar *password;
- gboolean waiting_for_password;
};
/* Properties */
@@ -62,7 +64,10 @@ random_hue ()
}
static void
-gedit_collaboration_user_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
+gedit_collaboration_user_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
GeditCollaborationUser *self = GEDIT_COLLABORATION_USER (object);
@@ -82,7 +87,10 @@ gedit_collaboration_user_set_property (GObject *object, guint prop_id, const GVa
}
static void
-gedit_collaboration_user_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
+gedit_collaboration_user_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
{
GeditCollaborationUser *self = GEDIT_COLLABORATION_USER (object);
@@ -132,65 +140,45 @@ gedit_collaboration_user_class_init (GeditCollaborationUserClass *klass)
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
0,
+ g_signal_accumulator_true_handled,
NULL,
- NULL,
- g_cclosure_marshal_VOID__POINTER,
- G_TYPE_NONE,
+ gedit_collaboration_marshal_BOOL__OBJECT,
+ G_TYPE_BOOLEAN,
1,
- G_TYPE_POINTER);
+ G_TYPE_OBJECT);
g_type_class_add_private (object_class, sizeof(GeditCollaborationUserPrivate));
}
-static gchar *
-get_password (GeditCollaborationUser *user,
- gpointer session_data)
-{
- gchar *password;
-
- user->priv->waiting_for_password = TRUE;
-
- g_free (user->priv->password);
- user->priv->password = NULL;
-
- g_signal_emit (user, signals[REQUEST_PASSWORD], 0, session_data);
- user->priv->waiting_for_password = FALSE;
-
- password = user->priv->password;
- user->priv->password = NULL;
-
- return password;
-}
-
-static int
-sasl_callback (Gsasl *context,
- Gsasl_session *session,
- Gsasl_property prop)
+static void
+sasl_callback (InfSaslContextSession *session,
+ Gsasl_property prop,
+ gpointer session_data,
+ GeditCollaborationUser *user)
{
- GeditCollaborationUser *user = gsasl_callback_hook_get (context);
- gpointer session_data = gsasl_session_hook_get (session);
-
int rc = GSASL_NO_CALLBACK;
switch (prop)
{
case GSASL_PASSWORD:
{
- gchar *password = get_password (user,
- session_data);
+ user->priv->sasl_session = session;
+ gboolean ret = FALSE;
+
+ g_signal_emit (user, signals[REQUEST_PASSWORD], 0, session_data, &ret);
- if (password)
+ if (ret)
{
- gsasl_property_set (session, prop, password);
- rc = GSASL_OK;
+ return;
}
-
- g_free (password);
}
break;
case GSASL_AUTHID:
case GSASL_ANONYMOUS_TOKEN:
- gsasl_property_set (session, prop, user->priv->name);
+ inf_sasl_context_session_set_property (session,
+ prop,
+ user->priv->name);
+
rc = GSASL_OK;
break;
case GSASL_VALIDATE_ANONYMOUS:
@@ -200,7 +188,7 @@ sasl_callback (Gsasl *context,
break;
}
- return rc;
+ inf_sasl_context_session_continue (session, rc);
}
static void
@@ -208,9 +196,11 @@ gedit_collaboration_user_init (GeditCollaborationUser *self)
{
self->priv = GEDIT_COLLABORATION_USER_GET_PRIVATE (self);
- gsasl_init (&self->priv->sasl_context);
- gsasl_callback_set (self->priv->sasl_context, sasl_callback);
- gsasl_callback_hook_set (self->priv->sasl_context, self);
+ self->priv->sasl_context = inf_sasl_context_new (NULL);
+
+ inf_sasl_context_set_callback (self->priv->sasl_context,
+ (InfSaslContextCallbackFunc)sasl_callback,
+ self);
}
GeditCollaborationUser *
@@ -331,7 +321,7 @@ gedit_collaboration_user_get_default ()
return default_user;
}
-Gsasl *
+InfSaslContext *
gedit_collaboration_user_get_sasl_context (GeditCollaborationUser *user)
{
g_return_val_if_fail (GEDIT_COLLABORATION_IS_USER (user), NULL);
@@ -344,7 +334,12 @@ gedit_collaboration_user_set_password (GeditCollaborationUser *user,
const gchar *password)
{
g_return_if_fail (GEDIT_COLLABORATION_IS_USER (user));
- g_return_if_fail (user->priv->waiting_for_password);
+ g_return_if_fail (user->priv->sasl_session);
+
+ inf_sasl_context_session_set_property (user->priv->sasl_session,
+ GSASL_PASSWORD,
+ password);
- user->priv->password = g_strdup (password);
+ inf_sasl_context_session_continue (user->priv->sasl_session,
+ password ? GSASL_OK : GSASL_NO_CALLBACK);
}
diff --git a/src/gedit-collaboration-user.h b/src/gedit-collaboration-user.h
index 2bd3505..e8b753d 100644
--- a/src/gedit-collaboration-user.h
+++ b/src/gedit-collaboration-user.h
@@ -4,7 +4,7 @@
#define __GEDIT_COLLABORATION_USER_H__
#include <glib-object.h>
-#include <gsasl.h>
+#include <libinfinity/common/inf-sasl-context.h>
G_BEGIN_DECLS
@@ -43,7 +43,7 @@ gdouble gedit_collaboration_user_get_hue (GeditCollaborationUser *user);
void gedit_collaboration_user_set_hue (GeditCollaborationUser *user,
gdouble hue);
-Gsasl *gedit_collaboration_user_get_sasl_context (GeditCollaborationUser *user);
+InfSaslContext *gedit_collaboration_user_get_sasl_context (GeditCollaborationUser *user);
void gedit_collaboration_user_set_password (GeditCollaborationUser *user,
const gchar *password);
diff --git a/src/gedit-collaboration-window-helper.c b/src/gedit-collaboration-window-helper.c
index 3c14634..a4bb9d2 100644
--- a/src/gedit-collaboration-window-helper.c
+++ b/src/gedit-collaboration-window-helper.c
@@ -624,7 +624,11 @@ get_chat_name (GeditCollaborationWindowHelper *helper,
return name;
}
- g_object_unref (browser);
+ if (browser != NULL)
+ {
+ g_object_unref (browser);
+ }
+
g_free (name);
} while (gtk_tree_model_iter_next (model, &iter));
@@ -894,7 +898,56 @@ name_info_free (NameInfo *info)
g_slice_free (NameInfo, info);
}
-static gchar *
+typedef struct
+{
+ GeditCollaborationWindowHelper *helper;
+ GeditCollaborationUser *user;
+ GtkEntry *entry;
+} PasswordInfo;
+
+static PasswordInfo *
+password_info_new (GeditCollaborationWindowHelper *helper,
+ GeditCollaborationUser *user,
+ GtkEntry *entry)
+{
+ PasswordInfo *info;
+
+ info = g_slice_new (PasswordInfo);
+
+ info->helper = helper;
+ info->user = user;
+ info->entry = entry;
+
+ return info;
+}
+
+static void
+password_info_free (PasswordInfo *info)
+{
+ g_slice_free (PasswordInfo, info);
+}
+
+static void
+on_password_dialog_response (GtkDialog *dialog,
+ gint response,
+ PasswordInfo *info)
+{
+ switch (response)
+ {
+ case GTK_RESPONSE_OK:
+ gedit_collaboration_user_set_password (info->user,
+ gtk_entry_get_text (info->entry));
+ break;
+ default:
+ gedit_collaboration_user_set_password (info->user,
+ NULL);
+ break;
+ }
+
+ gtk_widget_destroy (GTK_WIDGET (dialog));
+}
+
+static gboolean
show_password_dialog (GeditCollaborationWindowHelper *helper,
GeditCollaborationUser *user,
InfXmppConnection *connection)
@@ -903,13 +956,13 @@ show_password_dialog (GeditCollaborationWindowHelper *helper,
GtkWidget *dialog;
GtkWidget *label;
GtkWidget *entry;
- gchar *password;
gchar *remote;
gchar *text;
gchar *name;
gchar *username;
gchar *remotename;
gchar *datadir;
+ PasswordInfo *info;
datadir = peas_extension_base_get_data_dir (PEAS_EXTENSION_BASE (helper));
builder = gedit_collaboration_create_builder (datadir,
@@ -918,7 +971,7 @@ show_password_dialog (GeditCollaborationWindowHelper *helper,
if (!builder)
{
- return NULL;
+ return FALSE;
}
dialog = GTK_WIDGET (gtk_builder_get_object (builder, "dialog_password"));
@@ -956,39 +1009,30 @@ show_password_dialog (GeditCollaborationWindowHelper *helper,
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
- /* Need to do this modal/sync for now */
- if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK)
- {
- password = g_strdup (gtk_entry_get_text (GTK_ENTRY (entry)));
+ info = password_info_new (helper, user, GTK_ENTRY (entry));
- if (!*password)
- {
- g_free (password);
- password = NULL;
- }
- }
- else
- {
- password = NULL;
- }
+ gtk_window_set_transient_for (GTK_WINDOW (dialog),
+ GTK_WINDOW (info->helper->priv->window));
+
+ g_signal_connect_data (dialog,
+ "response",
+ G_CALLBACK (on_password_dialog_response),
+ info,
+ (GClosureNotify)password_info_free,
+ 0);
+ gtk_widget_show (dialog);
g_object_unref (builder);
- gtk_widget_destroy (dialog);
- return password;
+ return TRUE;
}
-static void
+static gboolean
user_request_password (GeditCollaborationUser *user,
- gpointer session_data,
+ InfXmppConnection *connection,
GeditCollaborationWindowHelper *helper)
{
- gchar *password;
-
- password = show_password_dialog (helper, user, session_data);
- gedit_collaboration_user_set_password (user, password);
-
- g_free (password);
+ return show_password_dialog (helper, user, connection);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]