From: Dan Winship Date: Mon, 7 Jun 2010 21:03:19 +0000 (-0400) Subject: SoupSession, SoupAuthManagerNTLM: Use subfeatures for NTLM auth too X-Git-Tag: LIBSOUP_2_33_4~16 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=815066543f0b34cffacac60c46e22dd6705dc76d;p=platform%2Fupstream%2Flibsoup.git SoupSession, SoupAuthManagerNTLM: Use subfeatures for NTLM auth too Deprecate SoupSession:use-ntlm in favor of using soup_session_add_feature_by_type() with SOUP_TYPE_AUTH_NTLM. --- diff --git a/libsoup/soup-auth-manager-ntlm.c b/libsoup/soup-auth-manager-ntlm.c index 6e6956c..49db613 100644 --- a/libsoup/soup-auth-manager-ntlm.c +++ b/libsoup/soup-auth-manager-ntlm.c @@ -32,19 +32,14 @@ static void request_started (SoupSessionFeature *feature, SoupSession *session, SoupMessage *msg, SoupSocket *socket); static void request_unqueued (SoupSessionFeature *feature, SoupSession *session, SoupMessage *msg); +static gboolean add_feature (SoupSessionFeature *feature, GType type); +static gboolean remove_feature (SoupSessionFeature *feature, GType type); +static gboolean has_feature (SoupSessionFeature *feature, GType type); G_DEFINE_TYPE_WITH_CODE (SoupAuthManagerNTLM, soup_auth_manager_ntlm, SOUP_TYPE_AUTH_MANAGER, G_IMPLEMENT_INTERFACE (SOUP_TYPE_SESSION_FEATURE, soup_auth_manager_ntlm_session_feature_init)) -enum { - PROP_0, - - PROP_USE_NTLM, - - LAST_PROP -}; - typedef enum { SOUP_NTLM_NEW, SOUP_NTLM_SENT_REQUEST, @@ -81,11 +76,6 @@ static char *soup_ntlm_response (const char *nonce, const char *host, const char *domain); -static void set_property (GObject *object, guint prop_id, - const GValue *value, GParamSpec *pspec); -static void get_property (GObject *object, guint prop_id, - GValue *value, GParamSpec *pspec); - static void soup_auth_manager_ntlm_init (SoupAuthManagerNTLM *ntlm) { @@ -135,16 +125,6 @@ soup_auth_manager_ntlm_class_init (SoupAuthManagerNTLMClass *auth_manager_ntlm_c g_type_class_add_private (auth_manager_ntlm_class, sizeof (SoupAuthManagerNTLMPrivate)); object_class->finalize = finalize; - object_class->set_property = set_property; - object_class->get_property = get_property; - - g_object_class_install_property ( - object_class, PROP_USE_NTLM, - g_param_spec_boolean (SOUP_AUTH_MANAGER_NTLM_USE_NTLM, - "Use NTLM", - "Whether or not to use NTLM authentication", - FALSE, - G_PARAM_READWRITE)); } static void @@ -158,40 +138,9 @@ soup_auth_manager_ntlm_session_feature_init (SoupSessionFeatureInterface *featur feature_interface->request_queued = request_queued; feature_interface->request_started = request_started; feature_interface->request_unqueued = request_unqueued; -} - -static void -set_property (GObject *object, guint prop_id, - const GValue *value, GParamSpec *pspec) -{ - SoupAuthManagerNTLMPrivate *priv = - SOUP_AUTH_MANAGER_NTLM_GET_PRIVATE (object); - - switch (prop_id) { - case PROP_USE_NTLM: - priv->use_ntlm = g_value_get_boolean (value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -get_property (GObject *object, guint prop_id, - GValue *value, GParamSpec *pspec) -{ - SoupAuthManagerNTLMPrivate *priv = - SOUP_AUTH_MANAGER_NTLM_GET_PRIVATE (object); - - switch (prop_id) { - case PROP_USE_NTLM: - g_value_set_boolean (value, priv->use_ntlm); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } + feature_interface->add_feature = add_feature; + feature_interface->remove_feature = remove_feature; + feature_interface->has_feature = has_feature; } static void @@ -424,6 +373,45 @@ request_unqueued (SoupSessionFeature *ntlm, SoupSession *session, soup_auth_manager_parent_feature_interface->request_unqueued (ntlm, session, msg); } +static gboolean +add_feature (SoupSessionFeature *feature, GType type) +{ + SoupAuthManagerNTLMPrivate *priv = + SOUP_AUTH_MANAGER_NTLM_GET_PRIVATE (feature); + + if (type == SOUP_TYPE_AUTH_NTLM) { + priv->use_ntlm = TRUE; + return TRUE; + } + + return soup_auth_manager_parent_feature_interface->add_feature (feature, type); +} + +static gboolean +remove_feature (SoupSessionFeature *feature, GType type) +{ + SoupAuthManagerNTLMPrivate *priv = + SOUP_AUTH_MANAGER_NTLM_GET_PRIVATE (feature); + + if (type == SOUP_TYPE_AUTH_NTLM) { + priv->use_ntlm = FALSE; + return TRUE; + } + + return soup_auth_manager_parent_feature_interface->remove_feature (feature, type); +} + +static gboolean +has_feature (SoupSessionFeature *feature, GType type) +{ + SoupAuthManagerNTLMPrivate *priv = + SOUP_AUTH_MANAGER_NTLM_GET_PRIVATE (feature); + + if (type == SOUP_TYPE_AUTH_NTLM) + return priv->use_ntlm; + + return soup_auth_manager_parent_feature_interface->has_feature (feature, type); +} /* NTLM code */ diff --git a/libsoup/soup-auth-ntlm.h b/libsoup/soup-auth-ntlm.h index f494c02..1f56976 100644 --- a/libsoup/soup-auth-ntlm.h +++ b/libsoup/soup-auth-ntlm.h @@ -8,7 +8,6 @@ #include "soup-auth.h" -#define SOUP_TYPE_AUTH_NTLM (soup_auth_ntlm_get_type ()) #define SOUP_AUTH_NTLM(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), SOUP_TYPE_AUTH_NTLM, SoupAuthNTLM)) #define SOUP_AUTH_NTLM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SOUP_TYPE_AUTH_NTLM, SoupAuthNTLMClass)) #define SOUP_IS_AUTH_NTLM(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), SOUP_TYPE_AUTH_NTLM)) @@ -25,8 +24,6 @@ typedef struct { } SoupAuthNTLMClass; -GType soup_auth_ntlm_get_type (void); - SoupAuth *soup_auth_ntlm_new (const char *realm, const char *host); const char *soup_auth_ntlm_get_username (SoupAuth *auth); diff --git a/libsoup/soup-auth.h b/libsoup/soup-auth.h index 61a8236..0a26e8c 100644 --- a/libsoup/soup-auth.h +++ b/libsoup/soup-auth.h @@ -106,6 +106,8 @@ void soup_auth_has_saved_password (SoupAuth *auth, GType soup_auth_basic_get_type (void); #define SOUP_TYPE_AUTH_DIGEST (soup_auth_digest_get_type ()) GType soup_auth_digest_get_type (void); +#define SOUP_TYPE_AUTH_NTLM (soup_auth_ntlm_get_type ()) +GType soup_auth_ntlm_get_type (void); G_END_DECLS diff --git a/libsoup/soup-session.c b/libsoup/soup-session.c index ffefca8..bd6aa6a 100644 --- a/libsoup/soup-session.c +++ b/libsoup/soup-session.c @@ -181,9 +181,7 @@ soup_session_init (SoupSession *session) priv->features_cache = g_hash_table_new (NULL, NULL); - auth_manager = g_object_new (SOUP_TYPE_AUTH_MANAGER_NTLM, - SOUP_AUTH_MANAGER_NTLM_USE_NTLM, FALSE, - NULL); + auth_manager = g_object_new (SOUP_TYPE_AUTH_MANAGER_NTLM, NULL); g_signal_connect (auth_manager, "authenticate", G_CALLBACK (auth_manager_authenticate), session); soup_session_feature_add_feature (SOUP_SESSION_FEATURE (auth_manager), @@ -492,6 +490,14 @@ soup_session_class_init (SoupSessionClass *session_class) 0, G_MAXUINT, 0, G_PARAM_READWRITE)); /** + * SoupSession:use-ntlm: + * + * Whether or not to use NTLM authentication. + * + * Deprecated: use soup_session_add_feature_by_type() with + * #SOUP_TYPE_AUTH_NTLM. + **/ + /** * SOUP_SESSION_USE_NTLM: * * Alias for the #SoupSession:use-ntlm property. (Whether or @@ -851,9 +857,10 @@ set_property (GObject *object, guint prop_id, case PROP_USE_NTLM: feature = soup_session_get_feature (session, SOUP_TYPE_AUTH_MANAGER_NTLM); if (feature) { - g_object_set_property (G_OBJECT (feature), - SOUP_AUTH_MANAGER_NTLM_USE_NTLM, - value); + if (g_value_get_boolean (value)) + soup_session_feature_add_feature (feature, SOUP_TYPE_AUTH_NTLM); + else + soup_session_feature_remove_feature (feature, SOUP_TYPE_AUTH_NTLM); } else g_warning ("Trying to set use-ntlm on session with no auth-manager"); break; @@ -958,11 +965,9 @@ get_property (GObject *object, guint prop_id, break; case PROP_USE_NTLM: feature = soup_session_get_feature (session, SOUP_TYPE_AUTH_MANAGER_NTLM); - if (feature) { - g_object_get_property (G_OBJECT (feature), - SOUP_AUTH_MANAGER_NTLM_USE_NTLM, - value); - } else + if (feature) + g_value_set_boolean (value, soup_session_feature_has_feature (feature, SOUP_TYPE_AUTH_NTLM)); + else g_value_set_boolean (value, FALSE); break; case PROP_SSL_CA_FILE: diff --git a/tests/ntlm-test.c b/tests/ntlm-test.c index 3c555ee..cd74b15 100644 --- a/tests/ntlm-test.c +++ b/tests/ntlm-test.c @@ -338,10 +338,10 @@ do_ntlm_round (SoupURI *base_uri, gboolean use_ntlm, const char *user) g_return_if_fail (use_ntlm || !alice); - session = soup_test_session_new ( - SOUP_TYPE_SESSION_ASYNC, - SOUP_SESSION_USE_NTLM, use_ntlm, - NULL); + session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC, NULL); + if (use_ntlm) + soup_session_add_feature_by_type (session, SOUP_TYPE_AUTH_NTLM); + if (user) { g_signal_connect (session, "authenticate", G_CALLBACK (authenticate), (char *)user);