[evolution-patches] soup fixes, part 2



This fixes the NTLM auth problems exposed by the previous patch. (It
shouldn't affect non-NTLM auth.)


Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/libsoup/ChangeLog,v
retrieving revision 1.303
diff -u -w -r1.303 ChangeLog
--- ChangeLog	7 May 2003 17:49:33 -0000	1.303
+++ ChangeLog	8 May 2003 15:59:11 -0000
@@ -1,3 +1,49 @@
+2003-05-08  Dan Winship  <danw ximian com>
+
+	* libsoup/soup-auth.c (ntlm_auth): If the auth status is PENDING,
+	return an NTLM request string. Otherwise return the "response"
+	field (which should include the NTLM authenticate message)
+	(ntlm_init): Don't bother setting "response" to the NTLM request
+	string. Just leave it NULL in that case.
+
+	* libsoup/soup-message.c (authorize_handler): Never try to reuse
+	an NTLM auth returned from soup_auth_lookup. Only set the auth on
+	the connection when it's SOUP_AUTH_STATUS_SUCCESSFUL. Otherwise,
+	call soup_auth_set_context() on it just like for non-NTLM auth.
+	The net effect of all of this is that now we record when a context
+	needs NTLM auth just like with non-NTLM auth, so that that info
+	gets preserved across connections.
+	(soup_message_requeue): No longer need the hackery here to
+	preserve the connection auth state.
+
 2003-05-07  Dan Winship  <danw ximian com>
 
 	* libsoup/soup-context.c (soup_connection_set_in_use): New, to
Index: libsoup/soup-auth.c
===================================================================
RCS file: /cvs/gnome/libsoup/libsoup/soup-auth.c,v
retrieving revision 1.19
diff -u -w -r1.19 soup-auth.c
--- libsoup/soup-auth.c	15 Nov 2002 16:26:42 -0000	1.19
+++ libsoup/soup-auth.c	8 May 2003 15:59:12 -0000
@@ -448,16 +448,16 @@
 	gchar    *header;
 } SoupAuthNTLM;
 
-/*
- * SoupAuthNTLMs are one time use. Just return the response, and set our
- * reference to NULL so future requests do not include this header.
- */
 static gchar *
 ntlm_auth (SoupAuth *sa, SoupMessage *msg)
 {
 	SoupAuthNTLM *auth = (SoupAuthNTLM *) sa;
 	gchar *ret;
 
+	if (sa->status == SOUP_AUTH_STATUS_PENDING)
+		return soup_ntlm_request ();
+
+	/* Otherwise, return the response; but only once */
 	ret = auth->response;
 	auth->response = NULL;
 
@@ -499,22 +499,22 @@
 ntlm_init (SoupAuth *sa, const SoupUri *uri)
 {
 	SoupAuthNTLM *auth = (SoupAuthNTLM *) sa;
+	gchar *host, *domain, *nonce;
 
 	if (strlen (auth->header) < sizeof ("NTLM"))
-		auth->response = soup_ntlm_request ();
-	else {
-		gchar *host, *domain, *nonce;
+		return;
+
+	if (auth->response)
+		g_free (auth->response);
 
 		host   = ntlm_get_authmech_token (uri, "host=");
 		domain = ntlm_get_authmech_token (uri, "domain=");
 
-		if (!soup_ntlm_parse_challenge (auth->header,
-						&nonce,
+	if (!soup_ntlm_parse_challenge (auth->header, &nonce,
 						domain ? NULL : &domain))
 			auth->response = NULL;
 		else {
-			auth->response = 
-				soup_ntlm_response (nonce,
+		auth->response = soup_ntlm_response (nonce,
 						    uri->user,
 						    uri->passwd,
 						    host,
@@ -530,7 +530,6 @@
 		 * probably means the password was incorrect).
 		 */
 		sa->status = SOUP_AUTH_STATUS_SUCCESSFUL;
-	}
 
 	g_free (auth->header);
 	auth->header = NULL;
Index: libsoup/soup-message.c
===================================================================
RCS file: /cvs/gnome/libsoup/libsoup/soup-message.c,v
retrieving revision 1.55
diff -u -w -r1.55 soup-message.c
--- libsoup/soup-message.c	6 May 2003 13:00:52 -0000	1.55
+++ libsoup/soup-message.c	8 May 2003 15:59:14 -0000
@@ -522,39 +522,10 @@
 	soup_queue_message (req, callback, user_data);
 }
 
-typedef struct {
-	SoupMessage *msg;
-	SoupAuth    *conn_auth;
-} RequeueConnectData;
-
-static void
-requeue_connect_cb (SoupContext          *ctx,
-		    SoupConnectErrorCode  err,
-		    SoupConnection       *conn,
-		    gpointer              user_data)
-{
-	RequeueConnectData *data = user_data;
-
-	if (conn && !conn->auth)
-		conn->auth = data->conn_auth;
-	else
-		soup_auth_free (data->conn_auth);
-
-	soup_queue_connect_cb (ctx, err, conn, data->msg);
-	if (data->msg->errorcode)
-		soup_message_issue_callback (data->msg);
-
-	g_free (data);
-}
-
 static void
 requeue_read_error (gboolean body_started, gpointer user_data)
 {
-	RequeueConnectData *data = user_data;
-	SoupMessage *msg = data->msg;
-	SoupContext *dest_ctx = msg->connection->context;
-
-	soup_context_ref (dest_ctx);
+	SoupMessage *msg = user_data;
 
 	soup_connection_set_keep_alive (msg->connection, FALSE);
 	soup_connection_release (msg->connection);
@@ -563,29 +534,19 @@
 	soup_queue_message (msg, 
 			    msg->priv->callback, 
 			    msg->priv->user_data);
-
-	msg->status = SOUP_STATUS_CONNECTING;
-
-	msg->priv->connect_tag =
-		soup_context_get_connection (dest_ctx, 
-					     requeue_connect_cb, 
-					     data);
-
-	soup_context_unref (dest_ctx);
 }
 
 static void
 requeue_read_finished (const SoupDataBuffer *buf,
 		       gpointer        user_data)
 {
-	RequeueConnectData *data = user_data;
-	SoupMessage *msg = data->msg;
+	SoupMessage *msg = user_data;
 	SoupConnection *conn = msg->connection;
 
+	soup_connection_set_used (msg->connection);
 	if (!soup_connection_is_keep_alive (msg->connection))
-		requeue_read_error (FALSE, data);
+		requeue_read_error (FALSE, msg);
 	else {
-		g_free (data);
 		msg->connection = NULL;
 
 		soup_queue_message (msg, 
@@ -608,18 +569,12 @@
 	g_return_if_fail (req != NULL);
 
 	if (req->connection && req->connection->auth && req->priv->read_tag) {
-		RequeueConnectData *data = NULL;
-
-		data = g_new0 (RequeueConnectData, 1);
-		data->msg = req;
-		data->conn_auth = req->connection->auth;
-
 		soup_transfer_read_set_callbacks (req->priv->read_tag,
 						  NULL,
 						  NULL,
 						  requeue_read_finished,
 						  requeue_read_error,
-						  data);
+						  req);
 		req->priv->read_tag = 0;
 	} else
 		soup_queue_message (req, 
@@ -719,6 +674,9 @@
 	if (!vals) goto THROW_CANT_AUTHENTICATE;
 
 	auth = soup_auth_lookup (ctx);
+	if (auth && auth->type == SOUP_AUTH_TYPE_NTLM)
+		auth = NULL;
+
 	if (auth) {
 		g_assert (auth->status != SOUP_AUTH_STATUS_INVALID);
 
@@ -793,13 +751,10 @@
 	 */
 	soup_auth_initialize (auth, uri);
 
-	if (auth->type == SOUP_AUTH_TYPE_NTLM) {
-		SoupAuth *old_auth = msg->connection->auth;
-
-		if (old_auth)
-			soup_auth_free (old_auth);
+	if (auth->type == SOUP_AUTH_TYPE_NTLM &&
+	    auth->status == SOUP_AUTH_STATUS_SUCCESSFUL)
 		msg->connection->auth = auth;
-	} else
+	else
 		soup_auth_set_context (auth, ctx);
 
 	soup_message_requeue (msg);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]