[libsoup/wip/tpopela/negotiate] soup-auth: Introduce the can_authenticate virtual method
- From: Tomas Popela <tpopela src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libsoup/wip/tpopela/negotiate] soup-auth: Introduce the can_authenticate virtual method
- Date: Fri, 19 Feb 2016 13:46:04 +0000 (UTC)
commit 0b34a7b1618459405d8e0ad05bda11a295742e55
Author: Tomas Popela <tpopela redhat com>
Date: Fri Feb 19 14:07:25 2016 +0100
soup-auth: Introduce the can_authenticate virtual method
It tests if the SoupAuth object is able to authenticate by providing credentials
to the soup_auth_authenticate() method. For every authentication method it is
true, but not for the soup-auth-negotiate where authentication with username and
password is not allowed.
libsoup/soup-auth-manager.c | 7 +++----
libsoup/soup-auth-negotiate.c | 7 +++++++
libsoup/soup-auth.c | 26 ++++++++++++++++++++++++++
libsoup/soup-auth.h | 4 ++++
4 files changed, 40 insertions(+), 4 deletions(-)
---
diff --git a/libsoup/soup-auth-manager.c b/libsoup/soup-auth-manager.c
index b38c6b5..9455265 100644
--- a/libsoup/soup-auth-manager.c
+++ b/libsoup/soup-auth-manager.c
@@ -13,7 +13,6 @@
#include "soup-auth-manager.h"
#include "soup.h"
-#include "soup-auth-negotiate.h"
#include "soup-connection-auth.h"
#include "soup-message-private.h"
#include "soup-message-queue.h"
@@ -469,6 +468,9 @@ authenticate_auth (SoupAuthManager *manager, SoupAuth *auth,
SoupAuthManagerPrivate *priv = manager->priv;
SoupURI *uri;
+ if (!soup_auth_can_authenticate (auth))
+ return;
+
if (proxy) {
SoupMessageQueue *queue;
SoupMessageQueueItem *item;
@@ -486,9 +488,6 @@ authenticate_auth (SoupAuthManager *manager, SoupAuth *auth,
} else
uri = soup_message_get_uri (msg);
- if (SOUP_IS_AUTH_NEGOTIATE (auth))
- return;
-
/* If a password is specified explicitly in the URI, use it
* even if the auth had previously already been authenticated.
*/
diff --git a/libsoup/soup-auth-negotiate.c b/libsoup/soup-auth-negotiate.c
index c2bc135..37caaa5 100644
--- a/libsoup/soup-auth-negotiate.c
+++ b/libsoup/soup-auth-negotiate.c
@@ -228,6 +228,12 @@ soup_auth_negotiate_is_authenticated (SoupAuth *auth)
return priv->is_authenticated;
}
+static gboolean
+soup_auth_negotiate_can_authenticate (SoupAuth *auth)
+{
+ return FALSE;
+}
+
static char *
soup_auth_negotiate_get_connection_authorization (SoupConnectionAuth *auth,
SoupMessage *msg,
@@ -270,6 +276,7 @@ soup_auth_negotiate_class_init (SoupAuthNegotiateClass *auth_negotiate_class)
auth_class->get_protection_space = soup_auth_negotiate_get_protection_space;
auth_class->authenticate = soup_auth_negotiate_authenticate;
auth_class->is_authenticated = soup_auth_negotiate_is_authenticated;
+ auth_class->can_authenticate = soup_auth_negotiate_can_authenticate;
conn_auth_class->create_connection_state = soup_auth_negotiate_create_connection_state;
conn_auth_class->free_connection_state = soup_auth_negotiate_free_connection_state;
diff --git a/libsoup/soup-auth.c b/libsoup/soup-auth.c
index 49d8df2..79aa7c3 100644
--- a/libsoup/soup-auth.c
+++ b/libsoup/soup-auth.c
@@ -129,6 +129,11 @@ soup_auth_get_property (GObject *object, guint prop_id,
}
}
+static gboolean
+auth_can_authenticate (SoupAuth *auth)
+{
+ return TRUE;
+}
static void
soup_auth_class_init (SoupAuthClass *auth_class)
@@ -137,6 +142,8 @@ soup_auth_class_init (SoupAuthClass *auth_class)
g_type_class_add_private (auth_class, sizeof (SoupAuthPrivate));
+ auth_class->can_authenticate = auth_can_authenticate;
+
object_class->finalize = soup_auth_finalize;
object_class->set_property = soup_auth_set_property;
object_class->get_property = soup_auth_get_property;
@@ -491,6 +498,25 @@ soup_auth_is_ready (SoupAuth *auth,
}
/**
+ * soup_auth_can_authenticate:
+ * @auth: a #SoupAuth
+ *
+ * Tests if @auth is able to authenticate by providing credentials to the
+ * soup_auth_authenticate().
+ *
+ * Return value: %TRUE if @auth is able to accept credentials.
+ *
+ * Since: 2.54
+ **/
+gboolean
+soup_auth_can_authenticate (SoupAuth *auth)
+{
+ g_return_val_if_fail (SOUP_IS_AUTH (auth), FALSE);
+
+ return SOUP_AUTH_GET_CLASS (auth)->can_authenticate (auth);
+}
+
+/**
* soup_auth_get_protection_space:
* @auth: a #SoupAuth
* @source_uri: the URI of the request that @auth was generated in
diff --git a/libsoup/soup-auth.h b/libsoup/soup-auth.h
index 7c56e67..fbf6616 100644
--- a/libsoup/soup-auth.h
+++ b/libsoup/soup-auth.h
@@ -48,6 +48,8 @@ typedef struct {
gboolean (*is_ready) (SoupAuth *auth,
SoupMessage *msg);
+ gboolean (*can_authenticate) (SoupAuth *auth);
+
/* Padding for future expansion */
void (*_libsoup_reserved2) (void);
void (*_libsoup_reserved3) (void);
@@ -92,6 +94,8 @@ gboolean soup_auth_is_authenticated (SoupAuth *auth);
SOUP_AVAILABLE_IN_2_42
gboolean soup_auth_is_ready (SoupAuth *auth,
SoupMessage *msg);
+SOUP_AVAILABLE_IN_2_54
+gboolean soup_auth_can_authenticate (SoupAuth *auth);
SOUP_AVAILABLE_IN_2_4
char *soup_auth_get_authorization (SoupAuth *auth,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]