[evolution-rss] better handle enclosures obey filesize if present
- From: Lucian Langa <lucilanga src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-rss] better handle enclosures obey filesize if present
- Date: Mon, 23 Feb 2015 21:17:34 +0000 (UTC)
commit 5a2f831431c032387db3523bd56d710093a28640
Author: Lucian Langa <lucilanga gnome org>
Date: Mon Feb 23 01:17:46 2015 +0100
better handle enclosures
obey filesize if present
src/parser.c | 24 +++++++++++----
src/rss.c | 94 ++++++++++++++++++++++++++++++++++++++++++++++++---------
src/rss.h | 5 ++-
3 files changed, 100 insertions(+), 23 deletions(-)
---
diff --git a/src/parser.c b/src/parser.c
index 1d7847d..e8b4fe6 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -1080,7 +1080,8 @@ parse_channel_line(xmlNode *top, gchar *feed_name, RDF *r, gchar **article_uid)
gchar *qsafe, *tcat;
GList *category = NULL;
create_feed *CF;
- GList *attachments = NULL;
+ GList *attachments = NULL, *attsizes = NULL, *l = NULL;
+ GHashTable *attlengths = NULL;
gchar *base = NULL, *main_date = NULL;
if (r) {
@@ -1220,10 +1221,20 @@ parse_channel_line(xmlNode *top, gchar *feed_name, RDF *r, gchar **article_uid)
}
//handle attatchments (can be multiple)
attachments = layer_find_tag_prop(top, "media", "url");
- if (!attachments)
+ attsizes = layer_find_tag_prop(top, "media", "fileSize");
+ if (!attachments) {
attachments = layer_query_find_all_prop (top,
"link", (xmlChar *)"rel",
"enclosure", (xmlChar *)"href");
+ attsizes = layer_query_find_all_prop (top,
+ "link", (xmlChar *)"rel",
+ "enclosure", (xmlChar *)"length");
+ }
+ attlengths = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
+ for (l = g_list_first(attsizes); l != NULL; l = l->next) {
+ gchar *c = get_url_basename(g_list_first(attachments)->data);
+ g_hash_table_insert(attlengths, g_strdup(c), g_strdup(l->data));
+ }
// char *comments = g_strdup(layer_find (top, "comments", NULL)); //RSS,
comments = (gchar *)layer_find_ns_tag(top, "wfw", "commentRss", NULL); //add slash:comments
@@ -1262,6 +1273,7 @@ parse_channel_line(xmlNode *top, gchar *feed_name, RDF *r, gchar **article_uid)
CF->website = g_strdup(link);
CF->encl = g_strdup(encl);
CF->attachments = attachments;
+ CF->attlengths = attlengths;
CF->comments = g_strdup(comments);
CF->feed_fname = g_strdup(feed_name); //feed file name
CF->feed_uri = g_strdup(feed); //feed uri (uid!)
@@ -1369,11 +1381,11 @@ display_channel_items_sync(AsyncData *asyncr)
if (g_settings_get_boolean(rss_settings, CONF_DOWNLOAD_ENCLOSURES)) {
#endif
if (CF->encl) {
- process_enclosure(CF);
- goto done;
+ if (process_enclosure(CF))
+ goto done;
} else if (g_list_length(CF->attachments)) {
- process_attachments(CF);
- goto done;
+ if (process_attachments(CF))
+ goto done;
}
}
diff --git a/src/rss.c b/src/rss.c
index 983434a..e80c549 100644
--- a/src/rss.c
+++ b/src/rss.c
@@ -3916,6 +3916,7 @@ create_mail(create_feed *CF)
GList *p, *l;
gchar *time_str, *buf;
gint offset;
+ guint c = 0;
mail_folder = check_feed_folder(CF->full_path);
if (!mail_folder)
@@ -4052,7 +4053,25 @@ create_mail(create_feed *CF)
#else
camel_object_unref(part);
#endif
+#if EVOLUTION_VERSION < 30304
+ GConfClient *client = gconf_client_get_default();
+#else
+ rss_settings = g_settings_new(RSS_CONF_SCHEMA);
+#endif
+ gdouble encl_max_size = g_settings_get_double(
+ rss_settings, CONF_ENCLOSURE_SIZE)*1024;
for (l = g_list_first(CF->attachedfiles); l != NULL; l = l->next) {
+ gdouble emax;
+ gchar *emaxstr = g_hash_table_lookup(CF->attlengths,
+ get_url_basename(l->data));
+ if (emaxstr)
+ emax = atof(emaxstr);
+ else
+ emax = 0;
+ if (emax > encl_max_size) {
+ continue;
+ }
+ c++;
msgp = file_to_message(l->data);
if (msgp) {
camel_multipart_add_part(mp, msgp);
@@ -4063,6 +4082,8 @@ create_mail(create_feed *CF)
#endif
}
}
+ if (!c)
+ goto out;
#if EVOLUTION_VERSION >= 23100
camel_medium_set_content((CamelMedium *)new, (CamelDataWrapper *)mp);
#else
@@ -4112,6 +4133,7 @@ create_mail(create_feed *CF)
camel_object_unref(mp);
#endif
} else
+out:
#if EVOLUTION_VERSION >= 23100
camel_medium_set_content(CAMEL_MEDIUM(new), CAMEL_DATA_WRAPPER(rtext));
#else
@@ -4292,11 +4314,14 @@ finish_attachment (
cfl *user_data);
#endif
-void
+gboolean
process_attachments(create_feed *CF)
{
cfl *CFL;
GList *l = g_list_first(CF->attachments);
+ gchar *emaxstr = NULL;
+ gdouble emax;
+ guint proc = 0;
g_return_if_fail(CF->attachments != NULL);
@@ -4306,6 +4331,25 @@ process_attachments(create_feed *CF)
if (g_list_find_custom(rf->enclist, l->data,
(GCompareFunc)strcmp))
continue;
+ //don't queue download if it exceeds max allowed size
+#if EVOLUTION_VERSION < 30304
+ GConfClient *client = gconf_client_get_default();
+#else
+ rss_settings = g_settings_new(RSS_CONF_SCHEMA);
+#endif
+ gdouble encl_max_size = g_settings_get_double(
+ rss_settings, CONF_ENCLOSURE_SIZE)*1024;
+ if (CF->encl) {
+ emaxstr = g_hash_table_lookup(CF->attlengths, get_url_basename(CF->encl));
+ }
+ if (emaxstr)
+ emax = atof(emaxstr);
+ else
+ emax = 0;
+ if (emax > encl_max_size) {
+ continue;
+ }
+ proc++;
CFL = g_new0(cfl, 1);
CFL->url = l->data;
CFL->CF = CF;
@@ -4320,6 +4364,9 @@ process_attachments(create_feed *CF)
1,
NULL);
} while ((l = l->next));
+ if (proc)
+ return TRUE;
+ return FALSE;
}
@@ -4378,27 +4425,44 @@ out: if (user_data->file)
NULL);
}
-void
+gboolean
process_enclosure(create_feed *CF)
{
cfl *CFL;
+ gdouble emax;
+ gchar *emaxstr;
if (g_list_find_custom(rf->enclist, CF->encl,
(GCompareFunc)strcmp)) {
- return;
+ return TRUE; //assume true for now
}
- d("enclosure file:%s\n", CF->encl)
- CFL = g_new0(cfl, 1);
- CFL->url = CF->encl;
- CFL->CF = CF;
- download_unblocking(
- CF->encl,
- download_chunk,
- CFL,
- (gpointer)finish_enclosure,
- CFL,
- 1,
- NULL);
+#if EVOLUTION_VERSION < 30304
+ GConfClient *client = gconf_client_get_default();
+#else
+ rss_settings = g_settings_new(RSS_CONF_SCHEMA);
+#endif
+ gdouble encl_max_size = g_settings_get_double(
+ rss_settings, CONF_ENCLOSURE_SIZE)*1024;
+ emaxstr = g_hash_table_lookup(CF->attlengths, get_url_basename(CF->encl));
+ if (emaxstr)
+ emax = atof(emaxstr);
+ else
+ emax = 0;
+ if (emax <= encl_max_size) {
+ d("enclosure file:%s\n", CF->encl)
+ CFL = g_new0(cfl, 1);
+ CFL->url = CF->encl;
+ CFL->CF = CF;
+ download_unblocking(
+ CF->encl,
+ download_chunk,
+ CFL,
+ (gpointer)finish_enclosure,
+ CFL,
+ 1,
+ NULL);
+ } else
+ return FALSE;
}
void
diff --git a/src/rss.h b/src/rss.h
index ae59d68..7b9ff42 100644
--- a/src/rss.h
+++ b/src/rss.h
@@ -339,6 +339,7 @@ typedef struct CREATE_FEED { /* used by create_mail function when called by unbl
gchar *encl; //feed enclosure
gchar *enclurl;
GList *attachments; //feed media files
+ GHashTable *attlengths; //feed media files
GList *attachedfiles; //list of downloaded media files
guint attachmentsqueue; //list of downloaded media files
FILE *efile; //enclosure file
@@ -500,8 +501,8 @@ void download_chunk(
gpointer statusdata,
gpointer data);
-void process_enclosure(create_feed *CF);
-void process_attachments(create_feed *CF);
+gboolean process_enclosure(create_feed *CF);
+gboolean process_attachments(create_feed *CF);
#ifdef HAVE_GECKO
void rss_mozilla_init(void);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]