diff options
author | Dan Winship <danw@src.gnome.org> | 2004-04-20 14:22:36 +0000 |
---|---|---|
committer | Dan Winship <danw@src.gnome.org> | 2004-04-20 14:22:36 +0000 |
commit | 4dcba5c0a0f85d1407cdcec87f5d907e90a47adc (patch) | |
tree | ee9e097ea416c3172da51017d47a882c399fe409 | |
parent | 77cdfc03f7db7c20ac4981f35b11c691425d44c1 (diff) | |
download | libsoup-4dcba5c0a0f85d1407cdcec87f5d907e90a47adc.tar.gz |
if re-sending the message, call soup_message_restarted() (send_request):
* libsoup/soup-connection-ntlm.c (ntlm_authorize_post): if
re-sending the message, call soup_message_restarted()
(send_request): Connect to "restarted" signal, and remove the 401
handlers from there; doing it here didn't work because if the
connection was closed, the message would be re-sent on a new
connection, but would still have the handlers from the old
connection attached to it, which would make authentication fail.
* libsoup/soup-message-handlers.c (soup_message_run_handlers):
Copy the handler list before starting, to protect against handlers
that modify the handler list.
-rw-r--r-- | ChangeLog | 14 | ||||
-rw-r--r-- | libsoup/soup-connection-ntlm.c | 24 | ||||
-rw-r--r-- | libsoup/soup-message-handlers.c | 13 |
3 files changed, 44 insertions, 7 deletions
@@ -1,3 +1,17 @@ +2004-04-20 Dan Winship <danw@ximian.com> + + * libsoup/soup-connection-ntlm.c (ntlm_authorize_post): if + re-sending the message, call soup_message_restarted() + (send_request): Connect to "restarted" signal, and remove the 401 + handlers from there; doing it here didn't work because if the + connection was closed, the message would be re-sent on a new + connection, but would still have the handlers from the old + connection attached to it, which would make authentication fail. + + * libsoup/soup-message-handlers.c (soup_message_run_handlers): + Copy the handler list before starting, to protect against handlers + that modify the handler list. + 2004-04-15 Dan Winship <danw@ximian.com> * libsoup/soup-connection.c (soup_connection_connect_sync): diff --git a/libsoup/soup-connection-ntlm.c b/libsoup/soup-connection-ntlm.c index d49e1c5a..56e5b75c 100644 --- a/libsoup/soup-connection-ntlm.c +++ b/libsoup/soup-connection-ntlm.c @@ -165,10 +165,25 @@ ntlm_authorize_post (SoupMessage *msg, gpointer conn) soup_message_get_header (msg->request_headers, "Authorization")) { /* We just added the last Auth header, so restart it. */ ntlm->priv->state = SOUP_CONNECTION_NTLM_SENT_RESPONSE; + soup_message_restarted (msg); soup_connection_send_request (conn, msg); } } +static void +ntlm_cleanup_msg (SoupMessage *msg, gpointer user_data) +{ + SoupConnectionNTLM *ntlm = user_data; + + /* Do this when the message is restarted, in case it's + * restarted on a different connection. + */ + soup_message_remove_handler (msg, SOUP_HANDLER_PRE_BODY, + ntlm_authorize_pre, ntlm); + soup_message_remove_handler (msg, SOUP_HANDLER_POST_BODY, + ntlm_authorize_post, ntlm); +} + void send_request (SoupConnection *conn, SoupMessage *req) { @@ -185,18 +200,19 @@ send_request (SoupConnection *conn, SoupMessage *req) ntlm->priv->state = SOUP_CONNECTION_NTLM_SENT_REQUEST; } - soup_message_remove_handler (req, SOUP_HANDLER_PRE_BODY, - ntlm_authorize_pre, conn); soup_message_add_status_code_handler (req, SOUP_STATUS_UNAUTHORIZED, SOUP_HANDLER_PRE_BODY, ntlm_authorize_pre, conn); - soup_message_remove_handler (req, SOUP_HANDLER_POST_BODY, - ntlm_authorize_post, conn); soup_message_add_status_code_handler (req, SOUP_STATUS_UNAUTHORIZED, SOUP_HANDLER_POST_BODY, ntlm_authorize_post, conn); + g_signal_connect (req, "restarted", + G_CALLBACK (ntlm_cleanup_msg), ntlm); + g_signal_connect (req, "finished", + G_CALLBACK (ntlm_cleanup_msg), ntlm); + SOUP_CONNECTION_CLASS (parent_class)->send_request (conn, req); } diff --git a/libsoup/soup-message-handlers.c b/libsoup/soup-message-handlers.c index b7840280..e128dd8e 100644 --- a/libsoup/soup-message-handlers.c +++ b/libsoup/soup-message-handlers.c @@ -71,16 +71,23 @@ run_handler (SoupMessage *msg, void soup_message_run_handlers (SoupMessage *msg, SoupHandlerPhase invoke_phase) { - GSList *list; + GSList *copy, *list; g_return_if_fail (SOUP_IS_MESSAGE (msg)); - for (list = msg->priv->content_handlers; list; list = list->next) { + /* Jump through hoops to deal with callbacks that modify the list. */ + copy = g_slist_copy (msg->priv->content_handlers); + + for (list = copy; list; list = list->next) { + if (!g_slist_find (msg->priv->content_handlers, list->data)) + continue; run_handler (msg, invoke_phase, list->data); if (SOUP_MESSAGE_IS_STARTING (msg)) - return; + break; } + + g_slist_free (copy); } static void |