[evolution-ews] Fix autodiscover to use POST, and to do so even after a redirect



commit fa9b1019de1223ae0c99de036a05c747e66827f0
Author: David Woodhouse <David Woodhouse intel com>
Date:   Thu Aug 18 13:05:17 2011 +0100

    Fix autodiscover to use POST, and to do so even after a redirect
    
    By default, libsoup will convert POST to GET on a 302 redirect.

 src/server/e-ews-connection.c |   26 +++++++++++++++++++++++---
 1 files changed, 23 insertions(+), 3 deletions(-)
---
diff --git a/src/server/e-ews-connection.c b/src/server/e-ews-connection.c
index b54dc7f..c827b8c 100644
--- a/src/server/e-ews-connection.c
+++ b/src/server/e-ews-connection.c
@@ -998,6 +998,7 @@ e_ews_autodiscover_ws_xml(const gchar *email)
 
 struct _autodiscover_data {
 	EEwsConnection *cnc;
+	xmlOutputBuffer *buf;
 	GSimpleAsyncResult *simple;
 	SoupMessage *msgs[2];
 	EEwsAutoDiscoverCallback cb;
@@ -1017,6 +1018,8 @@ static void autodiscover_done_cb (GObject *cnc, GAsyncResult *res,
 	if (!g_simple_async_result_propagate_error (simple, &error))
 		urls = g_simple_async_result_get_op_res_gpointer (simple);
 
+	xmlOutputBufferClose (ad->buf);
+
 	ad->cb (urls, ad->cbdata, error);
 	g_object_unref (G_OBJECT (ad->cnc));
 	g_free (ad);
@@ -1166,20 +1169,37 @@ failed:
 	g_simple_async_result_complete_in_idle (ad->simple);
 }
 
+static void post_restarted (SoupMessage *msg, gpointer data)
+{
+	xmlOutputBuffer *buf = data;
+
+	/* In violation of RFC2616, libsoup will change a POST request to
+	   a GET on receiving a 302 redirect. */
+	printf("Working around libsoup bug with redirect\n");
+	g_object_set (msg, SOUP_MESSAGE_METHOD, "POST", NULL);
+
+	soup_message_set_request(msg, "text/xml", SOUP_MEMORY_COPY,
+				 (gchar *)buf->buffer->content,
+				 buf->buffer->use);
+}
+
 static SoupMessage *
 e_ews_get_msg_for_url (const gchar *url, xmlOutputBuffer *buf)
 {
 	SoupMessage *msg;
 
-	msg = soup_message_new("GET", url);
+	msg = soup_message_new(buf?"POST":"GET", url);
 	soup_message_headers_append (msg->request_headers,
 				     "User-Agent", "libews/0.1");
 
 
-	if (buf)
+	if (buf) {
 		soup_message_set_request (msg, "application/xml", SOUP_MEMORY_COPY,
 					  (gchar *)buf->buffer->content,
 					  buf->buffer->use);
+		g_signal_connect (msg, "restarted",
+				  G_CALLBACK (post_restarted), buf);
+	}
 
 	if (g_getenv ("EWS_DEBUG") && (atoi (g_getenv ("EWS_DEBUG")) >= 1)) {
 		soup_buffer_free (soup_message_body_flatten (SOUP_MESSAGE (msg)->request_body));
@@ -1247,6 +1267,7 @@ e_ews_autodiscover_ws_url (EEwsAutoDiscoverCallback cb, gpointer cbdata,
 	ad->cb = cb;
 	ad->cbdata = cbdata;
 	ad->cnc = cnc;
+	ad->buf = buf;
 	ad->simple = g_simple_async_result_new (G_OBJECT (cnc), autodiscover_done_cb,
 					    ad, e_ews_autodiscover_ws_url);
 	ad->msgs[0] = e_ews_get_msg_for_url (url, buf);
@@ -1265,7 +1286,6 @@ e_ews_autodiscover_ws_url (EEwsAutoDiscoverCallback cb, gpointer cbdata,
 
 	g_object_unref (cnc); /* the GSimpleAsyncResult holds it now */
 
-	xmlOutputBufferClose (buf);
 	xmlFreeDoc (doc);
 }
 



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