[evolution-rss] Bug 643187 - url redirection for enclosures doesn't work as expected



commit 0e674286df47140790ad3aa0a14cfa8541fc5771
Author: Lucian Langa <lucilanga gnome org>
Date:   Fri Mar 4 23:10:03 2011 +0200

    Bug 643187 - url redirection for enclosures doesn't work as expected

 TODO               |    1 +
 src/network-soup.c |   21 ++++++++++++++++++---
 src/network.h      |    1 +
 src/rss.c          |    6 ++++--
 4 files changed, 24 insertions(+), 5 deletions(-)
---
diff --git a/TODO b/TODO
index 86f2e2b..4657e0e 100644
--- a/TODO
+++ b/TODO
@@ -44,3 +44,4 @@
 	* add configuration option to right click on status icon
 	* default render engine broken again
 	* detect rss-id changes (file changes) -> feeds downloaded all over again
+	* proxify async the download_* functions
diff --git a/src/network-soup.c b/src/network-soup.c
index 188c3d0..506a721 100644
--- a/src/network-soup.c
+++ b/src/network-soup.c
@@ -61,6 +61,8 @@ typedef struct {
 	gpointer user_data;
 	int current, total;
 	gchar *chunk;
+	gboolean reset;
+	SoupSession *ss;
 } CallbackInfo;
 
 typedef struct {
@@ -132,6 +134,10 @@ got_chunk_cb(SoupMessage *msg, SoupBuffer *chunk, CallbackInfo *info) {
 	progress->total = info->total;
 	progress->chunk = (gchar *)chunk->data;
 	progress->chunksize = (gint)chunk->length;
+	if (info->reset) {
+		progress->reset = info->reset;
+		info->reset = 0;
+	}
 	info->user_cb(NET_STATUS_PROGRESS, progress, info->user_data);
 	g_free(progress);
 }
@@ -705,7 +711,7 @@ static void
 redirect_handler (SoupMessage *msg, gpointer user_data)
 {
 	if (SOUP_STATUS_IS_REDIRECTION (msg->status_code)) {
-		SoupSession *soup_session = user_data;
+		CallbackInfo *info = user_data;
 		SoupURI *new_uri;
 		const gchar *new_loc;
 
@@ -713,6 +719,8 @@ redirect_handler (SoupMessage *msg, gpointer user_data)
 		if (!new_loc)
 			return;
 
+		info->reset=1;
+
 		new_uri = soup_uri_new_with_base (soup_message_get_uri (msg), new_loc);
 		if (!new_uri) {
 			soup_message_set_status_full (msg,
@@ -722,7 +730,7 @@ redirect_handler (SoupMessage *msg, gpointer user_data)
 		}
 
 		soup_message_set_uri (msg, new_uri);
-		soup_session_requeue_message (soup_session, msg);
+		soup_session_requeue_message (info->ss, msg);
 
 		soup_uri_free (new_uri);
 	}
@@ -759,6 +767,7 @@ net_get_unblocking(gchar *url,
 		info->user_data = data;
 		info->current = 0;
 		info->total = 0;
+		info->ss = soup_sess;
 	}
 	/*try to find upstream url to supply a password*/
 	if (data) {
@@ -811,7 +820,7 @@ net_get_unblocking(gchar *url,
 
 	soup_message_set_flags (msg, SOUP_MESSAGE_NO_REDIRECT);
 	soup_message_add_header_handler (msg, "got_body",
-		"Location", G_CALLBACK (redirect_handler), soup_sess);
+		"Location", G_CALLBACK (redirect_handler), info);
 
 	stnet = g_new0(STNET, 1);
 	stnet->ss = soup_sess;
@@ -868,6 +877,7 @@ download_unblocking(
 		info->user_data = data;
 		info->current = 0;
 		info->total = 0;
+		info->ss = soup_sess;
 	}
 
 	g_signal_connect (soup_sess, "authenticate",
@@ -910,6 +920,9 @@ download_unblocking(
 			G_CALLBACK(got_chunk_cb), info);	//FIXME Find a way to free this maybe weak_ref
 	}
 
+	soup_message_set_flags (msg, SOUP_MESSAGE_NO_REDIRECT);
+	soup_message_add_header_handler (msg, "got_body",
+		"Location", G_CALLBACK (redirect_handler), info);
 	soup_message_body_set_accumulate (msg->response_body, FALSE);
 	stnet = g_new0(STNET, 1);
 	stnet->ss = soup_sess;
@@ -917,6 +930,8 @@ download_unblocking(
 	stnet->cb2 = cb2;
 	stnet->cbdata2 = cbdata2;
 	stnet->url = g_strdup(url);
+
+
 	g_queue_push_tail (rf->stqueue, stnet);
 	rf->enclist = g_list_append (rf->enclist, url);
 
diff --git a/src/network.h b/src/network.h
index 05bcc17..26d4d20 100644
--- a/src/network.h
+++ b/src/network.h
@@ -111,6 +111,7 @@ typedef struct {
 	guint32 total;
 	gchar *chunk;
 	guint chunksize;
+	gboolean reset;		//signal to reset stream (usually because of redirect)
 } NetStatusProgress;
 
 typedef void (*NetStatusCallback)(NetStatusType status,
diff --git a/src/rss.c b/src/rss.c
index 21e23fa..2888c9e 100644
--- a/src/rss.c
+++ b/src/rss.c
@@ -584,7 +584,6 @@ download_chunk(
 	gpointer data)
 {
 	NetStatusProgress *progress;
-	//float fraction = 0;
 	switch (status) {
 	case NET_STATUS_PROGRESS:
 		progress = (NetStatusProgress*)statusdata;
@@ -595,7 +594,10 @@ download_chunk(
 				cancel_active_op((gpointer)data);
 				return;
 			}
-			//fraction = (float)progress->current / progress->total;
+			if (progress->reset) {
+				rewind(data);
+				progress->reset = 0;
+			}
 			fwrite(progress->chunk, 1, progress->chunksize, (FILE *)data);
 		}
 		break;



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