[evolution-rss] fix fetching cached images
- From: Lucian Langa <lucilanga src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [evolution-rss] fix fetching cached images
- Date: Sat, 31 Oct 2009 20:09:28 +0000 (UTC)
commit 2ba3232497c711bfa4826d8408c0d7c6057aba14
Author: Lucian Langa <lucilanga gnome org>
Date: Sat Oct 31 22:03:35 2009 +0200
fix fetching cached images
src/misc.c | 22 +++++++++++--
src/misc.h | 13 +++++---
src/network-soup.c | 15 +++++----
src/org-gnome-evolution-rss.eplug.xml | 6 +++-
src/rss.c | 51 ++++++++++++++++++++++-----------
5 files changed, 73 insertions(+), 34 deletions(-)
---
diff --git a/src/misc.c b/src/misc.c
index bde905f..3017b2b 100644
--- a/src/misc.c
+++ b/src/misc.c
@@ -70,12 +70,26 @@ free_hash(gpointer key, gpointer value, gpointer user_data)
}
gboolean
+check_key_match (gpointer key, gpointer value, gpointer user_data)
+{
+ char *sf_href = (char *)key;
+ char *int_uri = (char *)user_data;
+
+ d(g_print("checking hay:%s for neddle:%s\n", sf_href, int_uri));
+
+ if (!strcmp (sf_href, int_uri))
+ return TRUE; /* Quit calling the callback */
+
+ return FALSE; /* Continue calling the callback till end of table */
+}
+
+gboolean
check_if_match (gpointer key, gpointer value, gpointer user_data)
{
char *sf_href = (char *)value;
char *int_uri = (char *)user_data;
- d(g_print("checking hay:%s for neddle:%s\n", sf_href, int_uri));
+ d(g_print("checking hay:%s for neddle:%s\n", sf_href, int_uri));
if (!strcmp (sf_href, int_uri))
return TRUE; /* Quit calling the callback */
@@ -89,9 +103,9 @@ strextr(gchar *text, const gchar *substr)
gchar *tmp, *string;
GString *str;
- g_return_val_if_fail( text != NULL, NULL);
+ g_return_val_if_fail( text != NULL, NULL);
- if (substr == NULL)
+ if (substr == NULL)
return g_strdup(text);
//first check if string contains the substring
if (!strstr(text, substr))
@@ -106,7 +120,7 @@ strextr(gchar *text, const gchar *substr)
g_free(tmp);
return string;
}
-
+
//prefixes uri with http:// if it's misssing
//resulting text should be freed when no longer needed
gchar *
diff --git a/src/misc.h b/src/misc.h
index db5db87..188ac53 100644
--- a/src/misc.h
+++ b/src/misc.h
@@ -1,16 +1,16 @@
/* Evoution RSS Reader Plugin
- * Copyright (C) 2007-2009 Lucian Langa <cooly gnome eu org>
- *
+ * Copyright (C) 2007-2009 Lucian Langa <cooly gnome eu org>
+ *
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
- *
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
@@ -23,6 +23,9 @@ gchar *gen_crc(const char *msg);
gchar *gen_md5(gchar *buffer);
gchar *strplchr(gchar *source);
gchar *markup_decode (gchar *str);
+gboolean check_key_match (gpointer key,
+ gpointer value,
+ gpointer user_data);
gboolean check_if_match (gpointer key, gpointer value, gpointer user_data);
gchar *get_server_from_uri(gchar *uri);
gchar *get_port_from_uri(gchar *uri);
diff --git a/src/network-soup.c b/src/network-soup.c
index c29d8c8..5dd5e7e 100644
--- a/src/network-soup.c
+++ b/src/network-soup.c
@@ -475,14 +475,14 @@ net_get_status(const char *url, GError **err)
gchar *agstr;
if (!rf->b_session)
- rf->b_session = soup_sess =
- soup_session_sync_new_with_options(SOUP_SESSION_TIMEOUT, SS_TIMEOUT, NULL);
+ rf->b_session = soup_sess =
+ soup_session_sync_new_with_options(SOUP_SESSION_TIMEOUT, SS_TIMEOUT, NULL);
else
soup_sess = rf->b_session;
req = soup_message_new(SOUP_METHOD_GET, url);
if (!req) {
- g_set_error(err, NET_ERROR, NET_ERROR_GENERIC, "%s",
+ g_set_error(err, NET_ERROR, NET_ERROR_GENERIC, "%s",
soup_status_get_phrase(2)); //invalid url
goto out;
}
@@ -545,8 +545,9 @@ net_get_unblocking(gchar *url,
gchar *agstr;
soup_sess =
-// soup_session_async_new_with_options(SOUP_SESSION_TIMEOUT, SS_TIMEOUT, NULL);
- soup_session_async_new();
+ soup_session_async_new_with_options(SOUP_SESSION_TIMEOUT, SS_TIMEOUT,
+ SOUP_SESSION_IDLE_TIMEOUT, SS_TIMEOUT, NULL);
+// soup_session_async_new();
#if LIBSOUP_VERSION > 2024000
@@ -640,8 +641,8 @@ net_post_blocking(gchar *url, GSList *headers, GString *post,
gchar *agstr;
if (!rf->b_session)
- rf->b_session = soup_sess =
- soup_session_sync_new_with_options(SOUP_SESSION_TIMEOUT, SS_TIMEOUT, NULL);
+ rf->b_session = soup_sess =
+ soup_session_sync_new_with_options(SOUP_SESSION_TIMEOUT, SS_TIMEOUT, NULL);
else
soup_sess = rf->b_session;
diff --git a/src/org-gnome-evolution-rss.eplug.xml b/src/org-gnome-evolution-rss.eplug.xml
index 9331cb0..8d62984 100644
--- a/src/org-gnome-evolution-rss.eplug.xml
+++ b/src/org-gnome-evolution-rss.eplug.xml
@@ -36,8 +36,12 @@ HTML can be displayed using the following engines: gtkHTML, Apple's Webkit or Fi
+RSS_MENU+
<hook class="org.gnome.evolution.mail.events:1.0">
- <event type="pass" target="message" id="message.reading" handle="org_gnome_cooly_article_show"/>
+ <event type="pass"
+ target="message"
+ id="message.reading"
+ handle="org_gnome_evolution_rss_article_show"/>
</hook>
+
<hook class="org.gnome.evolution.mail.events:1.0">
<event type="pass" target="folder" id="folder.customicon" handle="org_gnome_cooly_folder_icon"/>
</hook>
diff --git a/src/rss.c b/src/rss.c
index 9df4b89..02f82d9 100644
--- a/src/rss.c
+++ b/src/rss.c
@@ -264,6 +264,8 @@ gboolean display_folder_icon(GtkTreeStore *store, gchar *key);
typedef struct _FEED_IMAGE {
gchar *img_file;
CamelStream *feed_fs;
+ gchar *http_cache;
+ gchar *url;
gchar *key;
gpointer data;
} FEED_IMAGE;
@@ -2760,19 +2762,20 @@ out: g_free(main_folder);
#endif
#ifdef EVOLUTION_2_12
-void org_gnome_cooly_article_show(void *ep, EMEventTargetMessage *t);
+void org_gnome_evolution_rss_article_show(void *ep, EMEventTargetMessage *t);
#else
-void org_gnome_cooly_article_show(void *ep, void *t);
+void org_gnome_evolution_rss_article_show(void *ep, void *t);
#endif
#ifdef EVOLUTION_2_12
-void org_gnome_cooly_article_show(void *ep, EMEventTargetMessage *t)
+void org_gnome_evolution_rss_article_show(void *ep, EMEventTargetMessage *t)
{
+g_print("show\n");
if (rf && (!inhibit_read || !delete_op))
rf->current_uid = g_strdup(t->uid);
}
#else
-void org_gnome_cooly_article_show(void *ep, void *t)
+void org_gnome_evolution_rss_article_show(void *ep, void *t)
{
}
#endif
@@ -5285,9 +5288,12 @@ finish_image_feedback (SoupMessage *msg, FEED_IMAGE *user_data)
finish_image_feedback (SoupSession *soup_sess, SoupMessage *msg, FEED_IMAGE *user_data)
#endif
{
- finish_image(soup_sess, msg, user_data->feed_fs);
+ CamelStream *stream = NULL;
+ stream = camel_data_cache_add(user_data->http_cache, HTTP_CACHE_PATH, user_data->url, NULL);
+ finish_image(soup_sess, msg, stream);
if (user_data->data == current_pobject)
em_format_redraw((EMFormat *)user_data->data);
+ g_free(user_data->url);
g_free(user_data);
}
@@ -5304,6 +5310,7 @@ finish_image (SoupSession *soup_sess, SoupMessage *msg, CamelStream *user_data)
404 != msg->status_code && //NOT FOUND
400 != msg->status_code && //bad request
2 != msg->status_code && //STATUS_CANT_RESOLVE
+ 1 != msg->status_code && //TIMEOUT (CANCELLED) ?
7 != msg->status_code && // STATUS_IO_ERROR
#if LIBSOUP_VERSION < 2003000
msg->response.length) { //ZERO SIZE
@@ -5545,7 +5552,12 @@ fetch_image_redraw(gchar *url, gchar *link, gpointer data)
} else {
tmpurl = g_strdup(url);
}
- d(g_print("fetch_image_redraw() tmpurl:%s\n", tmpurl));
+ if (g_hash_table_find(rf->key_session,
+ check_key_match,
+ tmpurl)) {
+ goto working;
+ }
+ g_print("fetch_image_redraw() tmpurl:%s\n", tmpurl);
base_dir = rss_component_peek_base_directory();
feed_dir = g_build_path("/",
base_dir,
@@ -5555,34 +5567,39 @@ fetch_image_redraw(gchar *url, gchar *link, gpointer data)
if (!g_file_test(feed_dir, G_FILE_TEST_EXISTS))
g_mkdir_with_parents (feed_dir, 0755);
http_cache = camel_data_cache_new(feed_dir, 0, NULL);
- if (!http_cache)
- return NULL;
+ g_free(feed_dir);
+ if (!http_cache) {
+ result = NULL;
+ goto error;
+ }
// expire in a month max
// and one week if not accessed sooner
camel_data_cache_set_expire_age(http_cache, 24*60*60*30);
camel_data_cache_set_expire_access(http_cache, 24*60*60*7);
stream = camel_data_cache_get(http_cache, HTTP_CACHE_PATH, tmpurl, NULL);
if (!stream) {
- d(g_print("image cache MISS\n"));
- stream = camel_data_cache_add(http_cache, HTTP_CACHE_PATH, tmpurl, NULL);
+ g_print("image cache MISS\n");
fi = g_new0(FEED_IMAGE, 1);
- fi->feed_fs = stream;
+ fi->http_cache = http_cache;
+ fi->url = g_strdup(tmpurl);
fi->data = data;
fetch_unblocking(tmpurl,
textcb,
- NULL,
+ g_strdup(tmpurl),
(gpointer)finish_image_feedback,
fi,
- 0,
+ 1,
&err);
- if (err) return NULL;
+ if (err) {
+ result = NULL;
+ goto error;
+ }
} else {
d(g_print("image cache HIT\n"));
}
- result = data_cache_path(http_cache, FALSE, HTTP_CACHE_PATH, tmpurl);
- g_free(feed_dir);
- g_free(tmpurl);
+working:result = data_cache_path(http_cache, FALSE, HTTP_CACHE_PATH, tmpurl);
+error: g_free(tmpurl);
return result;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]