summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristophe Fergeau <cfergeau@redhat.com>2012-06-12 21:20:10 +0200
committerChristophe Fergeau <cfergeau@redhat.com>2012-06-28 12:33:48 +0200
commitdf70faadc3a40867b80c19c132998e5c5b9cd622 (patch)
treeef460e3eabaa1d2df5ff1f8910542ffdd0e8a43d
parent5e22174503a61a04f0335c691e526ac5770d22ab (diff)
Propagate RestProxyAuth object in ::authenticate signal
This will make it possible to pause/resume the current call during authentication callbacks to be able to get back to the mainloop to get authentication credentials. https://bugzilla.gnome.org/show_bug.cgi?id=658937
-rw-r--r--rest/rest-proxy.c27
-rw-r--r--rest/rest-proxy.h3
2 files changed, 23 insertions, 7 deletions
diff --git a/rest/rest-proxy.c b/rest/rest-proxy.c
index 1dc18bd..78dc6b0 100644
--- a/rest/rest-proxy.c
+++ b/rest/rest-proxy.c
@@ -28,6 +28,7 @@
#include <libsoup/soup-gnome.h>
#endif
+#include "rest-proxy-auth-private.h"
#include "rest-proxy.h"
#include "rest-private.h"
@@ -200,7 +201,9 @@ rest_proxy_dispose (GObject *object)
}
static gboolean
-default_authenticate_cb (RestProxy *self, gboolean retrying)
+default_authenticate_cb (RestProxy *self,
+ G_GNUC_UNUSED RestProxyAuth *auth,
+ gboolean retrying)
{
/* We only want to try the credentials once, otherwise we get in an
* infinite loop with failed credentials, retrying the same invalid
@@ -212,16 +215,19 @@ default_authenticate_cb (RestProxy *self, gboolean retrying)
static void
authenticate (RestProxy *self,
SoupMessage *msg,
- SoupAuth *auth,
+ SoupAuth *soup_auth,
gboolean retrying,
SoupSession *session)
{
RestProxyPrivate *priv = GET_PRIVATE (self);
+ RestProxyAuth *rest_auth;
gboolean try_auth;
- g_signal_emit(self, signals[AUTHENTICATE], 0, retrying, &try_auth);
- if (try_auth)
- soup_auth_authenticate (auth, priv->username, priv->password);
+ rest_auth = rest_proxy_auth_new (self, session, msg, soup_auth);
+ g_signal_emit(self, signals[AUTHENTICATE], 0, rest_auth, retrying, &try_auth);
+ if (try_auth && !rest_proxy_auth_is_paused (rest_auth))
+ soup_auth_authenticate (soup_auth, priv->username, priv->password);
+ g_object_unref (G_OBJECT (rest_auth));
}
static void
@@ -355,6 +361,14 @@ rest_proxy_class_init (RestProxyClass *klass)
* If these credentials fail, the signal will be
* emitted again, with @retrying set to %TRUE, which will
* continue until FALSE is returned from the callback.
+ *
+ * If you call rest_proxy_auth_pause() on @auth before
+ * returning, then you can the authentication credentials on
+ * the RestProxy object asynchronously. You have to make sure
+ * that @auth does not get destroyed with g_object_ref().
+ * You can then unpause the authentication with
+ * rest_proxy_auth_unpause() when everything is ready for it
+ * to continue.
**/
signals[AUTHENTICATE] =
g_signal_new ("authenticate",
@@ -362,7 +376,8 @@ rest_proxy_class_init (RestProxyClass *klass)
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (RestProxyClass, authenticate),
g_signal_accumulator_true_handled, NULL, NULL,
- G_TYPE_BOOLEAN, 1,
+ G_TYPE_BOOLEAN, 2,
+ REST_TYPE_PROXY_AUTH,
G_TYPE_BOOLEAN);
proxy_class->authenticate = default_authenticate_cb;
diff --git a/rest/rest-proxy.h b/rest/rest-proxy.h
index 077b134..9c60189 100644
--- a/rest/rest-proxy.h
+++ b/rest/rest-proxy.h
@@ -24,6 +24,7 @@
#define _REST_PROXY
#include <glib-object.h>
+#include <rest/rest-proxy-auth.h>
#include <rest/rest-proxy-call.h>
G_BEGIN_DECLS
@@ -77,7 +78,7 @@ struct _RestProxyClass {
RestProxyCall *(*new_call)(RestProxy *proxy);
gboolean (*simple_run_valist)(RestProxy *proxy, gchar **payload,
goffset *len, GError **error, va_list params);
- gboolean (*authenticate)(RestProxy *proxy, gboolean retrying);
+ gboolean (*authenticate)(RestProxy *proxy, RestProxyAuth *auth, gboolean retrying);
/*< private >*/
/* padding for future expansion */