telepathy-gabble: auth-manager: clarify _challenge_async()
Will Thompson
wjt at kemper.freedesktop.org
Thu Dec 6 09:56:45 PST 2012
Module: telepathy-gabble
Branch: master
Commit: e33a5de2806bcf63543fdabb3e8607e9d699ca1c
URL: http://cgit.freedesktop.org/telepathy/telepathy-gabble/commit/?id=e33a5de2806bcf63543fdabb3e8607e9d699ca1c
Author: Will Thompson <will.thompson at collabora.co.uk>
Date: Tue Nov 20 16:02:04 2012 +0000
auth-manager: clarify _challenge_async()
Keeping our own GSimpleAsyncResult rather than leaving it up to the
channel means _finish() doesn't have to worry about what happens if the
channel closes.
The g_assert_not_reached () is not safe, but is equivalent to the
previous behaviour (wrongly chaining up to the parent class makes it
assert). Next, a fixâ¦
---
src/auth-manager.c | 57 +++++++++++++++++++++++++++++++++++++++++-----------
1 files changed, 45 insertions(+), 12 deletions(-)
diff --git a/src/auth-manager.c b/src/auth-manager.c
index d2e1af5..46400ca 100644
--- a/src/auth-manager.c
+++ b/src/auth-manager.c
@@ -398,6 +398,28 @@ gabble_auth_manager_start_auth_finish (WockyAuthRegistry *registry,
}
static void
+channel_challenge_cb (
+ GObject *source,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ GabbleServerSaslChannel *channel = GABBLE_SERVER_SASL_CHANNEL (source);
+ GSimpleAsyncResult *our_result = G_SIMPLE_ASYNC_RESULT (user_data);
+ GString *response_data = NULL;
+ GError *error = NULL;
+
+ if (gabble_server_sasl_channel_challenge_finish (channel, result,
+ &response_data, &error))
+ g_simple_async_result_set_op_res_gpointer (our_result, response_data,
+ (GDestroyNotify) wocky_g_string_free);
+ else
+ g_simple_async_result_take_error (our_result, error);
+
+ g_simple_async_result_complete (our_result);
+ g_object_unref (our_result);
+}
+
+static void
gabble_auth_manager_challenge_async (WockyAuthRegistry *registry,
const GString *challenge_data,
GAsyncReadyCallback callback,
@@ -405,17 +427,27 @@ gabble_auth_manager_challenge_async (WockyAuthRegistry *registry,
{
GabbleAuthManager *self = GABBLE_AUTH_MANAGER (registry);
- if (self->priv->channel != NULL && !self->priv->chaining_up)
- {
- gabble_server_sasl_channel_challenge_async (self->priv->channel,
- challenge_data, callback, user_data);
- }
- else
+ if (self->priv->chaining_up)
{
WOCKY_AUTH_REGISTRY_CLASS (
gabble_auth_manager_parent_class)->challenge_async_func (
registry, challenge_data, callback, user_data);
}
+ else
+ {
+ GSimpleAsyncResult *result = g_simple_async_result_new (G_OBJECT (self),
+ callback, user_data, gabble_auth_manager_challenge_async);
+
+ if (self->priv->channel != NULL)
+ {
+ gabble_server_sasl_channel_challenge_async (self->priv->channel,
+ challenge_data, channel_challenge_cb, result);
+ }
+ else
+ {
+ g_assert_not_reached ();
+ }
+ }
}
static gboolean
@@ -426,17 +458,18 @@ gabble_auth_manager_challenge_finish (WockyAuthRegistry *registry,
{
GabbleAuthManager *self = GABBLE_AUTH_MANAGER (registry);
- if (self->priv->channel != NULL && !self->priv->chaining_up)
- {
- return gabble_server_sasl_channel_challenge_finish (self->priv->channel,
- result, response, error);
- }
- else
+ if (self->priv->chaining_up)
{
return WOCKY_AUTH_REGISTRY_CLASS
(gabble_auth_manager_parent_class)->challenge_finish_func (
registry, result, response, error);
}
+ else
+ {
+ wocky_implement_finish_copy_pointer (self,
+ gabble_auth_manager_challenge_async,
+ wocky_g_string_dup, response);
+ }
}
static void
More information about the telepathy-commits
mailing list