[evolution-rss/evolution-rss-0-2-0] Bug 643187 - url redirection for enclosures doesn't work as expected
- From: Lucian Langa <lucilanga src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-rss/evolution-rss-0-2-0] Bug 643187 - url redirection for enclosures doesn't work as expected
- Date: Fri, 4 Mar 2011 21:43:14 +0000 (UTC)
commit 8c81b9695b49e441fc29f78b81ff2f064f5d8c17
Author: Lucian Langa <lucilanga gnome org>
Date: Fri Mar 4 23:40:18 2011 +0200
Bug 643187 - url redirection for enclosures doesn't work as expected
src/network-soup.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
src/network.h | 9 +++++----
src/rss.c | 6 ++++--
3 files changed, 55 insertions(+), 6 deletions(-)
---
diff --git a/src/network-soup.c b/src/network-soup.c
index 91dab38..479f7d5 100644
--- a/src/network-soup.c
+++ b/src/network-soup.c
@@ -60,6 +60,8 @@ typedef struct {
gpointer user_data;
int current, total;
gchar *chunk;
+ gboolean reset;
+ SoupSession *ss;
} CallbackInfo;
typedef struct {
@@ -142,6 +144,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);
}
@@ -574,6 +580,36 @@ out:
return response;
}
+static void
+redirect_handler (SoupMessage *msg, gpointer user_data)
+{
+ if (SOUP_STATUS_IS_REDIRECTION (msg->status_code)) {
+ CallbackInfo *info = user_data;
+ SoupURI *new_uri;
+ const gchar *new_loc;
+
+ new_loc = soup_message_headers_get (msg->response_headers, "Location");
+ 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,
+ SOUP_STATUS_MALFORMED,
+ "Invalid Redirect URL");
+ return;
+ }
+
+ soup_message_set_uri (msg, new_uri);
+ soup_session_requeue_message (info->ss, msg);
+
+ soup_uri_free (new_uri);
+ }
+}
+
+
gboolean
net_get_unblocking(gchar *url,
NetStatusCallback cb, gpointer data,
@@ -605,6 +641,7 @@ net_get_unblocking(gchar *url,
info->user_data = data;
info->current = 0;
info->total = 0;
+ info->ss = soup_sess;
}
g_signal_connect (soup_sess, "authenticate",
@@ -646,6 +683,10 @@ net_get_unblocking(gchar *url,
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), soup_sess);
+
soup_session_queue_message (soup_sess, msg,
cb2, cbdata2);
@@ -695,6 +736,7 @@ download_unblocking(
info->user_data = data;
info->current = 0;
info->total = 0;
+ info->ss = soup_sess;
}
g_signal_connect (soup_sess, "authenticate",
@@ -736,6 +778,10 @@ 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;
diff --git a/src/network.h b/src/network.h
index ecf8790..636b30e 100644
--- a/src/network.h
+++ b/src/network.h
@@ -107,10 +107,11 @@ typedef enum {
} NetStatusType;
typedef struct {
- guint32 current;
- guint32 total;
- gchar *chunk;
- guint chunksize;
+ guint32 current;
+ 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 8b306e9..add4c6e 100644
--- a/src/rss.c
+++ b/src/rss.c
@@ -583,12 +583,14 @@ download_chunk(
gpointer data)
{
NetStatusProgress *progress;
- //float fraction = 0;
switch (status) {
case NET_STATUS_PROGRESS:
progress = (NetStatusProgress*)statusdata;
if (progress->current > 0 && progress->total > 0) {
- //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]