[evolution-rss] fix fetching of expired cache items
- From: Lucian Langa <lucilanga src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-rss] fix fetching of expired cache items
- Date: Mon, 24 May 2010 20:35:41 +0000 (UTC)
commit 895bf6e9cf457536f37d6ec92aac4530cb84acc6
Author: Lucian Langa <lucilanga gnome org>
Date: Mon May 24 22:06:30 2010 +0300
fix fetching of expired cache items
src/network-soup.c | 20 ----------------
src/parser.c | 8 +-----
src/rss-image.c | 64 +++++++++++++++++++++++++++++++++++++++------------
src/rss.c | 50 ++++++++++++++++++++++++----------------
4 files changed, 81 insertions(+), 61 deletions(-)
---
diff --git a/src/network-soup.c b/src/network-soup.c
index 1a759d4..ab51252 100644
--- a/src/network-soup.c
+++ b/src/network-soup.c
@@ -607,16 +607,6 @@ net_get_unblocking(gchar *url,
info->total = 0;
}
- if (!rf->session)
- rf->session = g_hash_table_new(
- g_direct_hash, g_direct_equal);
- if (!rf->abort_session)
- rf->abort_session = g_hash_table_new(
- g_direct_hash, g_direct_equal);
- if (!rf->key_session)
- rf->key_session = g_hash_table_new(
- g_direct_hash, g_direct_equal);
-
g_signal_connect (soup_sess, "authenticate",
G_CALLBACK (authenticate), (gpointer)url);
#if LIBSOUP_VERSION < 2003000
@@ -707,16 +697,6 @@ download_unblocking(
info->total = 0;
}
- if (!rf->session)
- rf->session = g_hash_table_new(
- g_direct_hash, g_direct_equal);
- if (!rf->abort_session)
- rf->abort_session = g_hash_table_new(
- g_direct_hash, g_direct_equal);
- if (!rf->key_session)
- rf->key_session = g_hash_table_new(
- g_direct_hash, g_direct_equal);
-
g_signal_connect (soup_sess, "authenticate",
G_CALLBACK (authenticate), (gpointer)url);
#if LIBSOUP_VERSION < 2003000
diff --git a/src/parser.c b/src/parser.c
index 3b5d2be..e7423c1 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -871,14 +871,10 @@ process_images(gchar *text, gchar *link, EMFormatHTML *format)
xmlChar *url = xmlGetProp(doc, (xmlChar *)"src");
if (url) {
if ((name = fetch_image_redraw((gchar *)url, link, format))) {
- gchar *tmp = g_strconcat(
- "file://",
- name, NULL);
- g_free(name);
xmlSetProp(
doc, (xmlChar *)"src",
- (xmlChar *)tmp);
- g_free(tmp);
+ (xmlChar *)name);
+ g_free(name);
}
xmlFree(url);
}
diff --git a/src/rss-image.c b/src/rss-image.c
index dfb1f6d..f67ae79 100644
--- a/src/rss-image.c
+++ b/src/rss-image.c
@@ -452,6 +452,20 @@ out: g_free(img_file);
}
#endif
+gchar *
+decode_image_cache_filename(gchar *name)
+{
+ gsize size;
+ gchar *tmp, *csum, *tname;
+ tmp = g_base64_decode(name+4, &size);
+ csum = g_compute_checksum_for_string(G_CHECKSUM_SHA1,
+ tmp, -1);
+ g_free(tmp);
+ tname = rss_cache_get_filename(csum);
+ g_free(csum);
+ return tname;
+}
+
/* validates if image is indeed an image file
* if image file is not found it tries to fetch it
* we need to check mime time against content
@@ -464,11 +478,16 @@ verify_image(gchar *uri, EMFormatHTML *format)
gsize length;
gchar *nurl, *turl;
gchar *base_dir, *feed_dir, *name;
- gchar *scheme, *result;
+ gchar *scheme, *result, *tname;
+ gchar *duri = NULL;
+ gsize size;
g_return_val_if_fail(uri != NULL, NULL);
- if (!g_file_test((gchar *)uri, G_FILE_TEST_EXISTS)) {
+ if (strstr(uri, "img:"))
+ duri = g_base64_decode(uri+4, &size);
+
+ if (!g_file_test((gchar *)duri, G_FILE_TEST_EXISTS)) {
camel_url_decode((gchar *)uri);
//FIXME lame method of extracting data cache path
//there must be a function in camel for getting data cache path
@@ -486,7 +505,7 @@ verify_image(gchar *uri, EMFormatHTML *format)
if (!scheme) {
nurl = strextr((gchar *)uri, feed_dir);
g_free(feed_dir);
- turl = nurl + 4;
+ turl = nurl + 4; // skip cache directory
name = fetch_image_redraw(turl, NULL, format);
g_free(nurl);
} else {
@@ -495,15 +514,19 @@ verify_image(gchar *uri, EMFormatHTML *format)
g_free(scheme);
}
g_free(base_dir);
- result = g_filename_to_uri (name, NULL, NULL);
+ tname = decode_image_cache_filename(name);
g_free(name);
+ result = g_filename_to_uri (tname, NULL, NULL);
+ g_free(tname);
+ if (duri)
+ g_free(duri);
return result;
} else {
/*need to get mime type via file contents or else mime type is
* bound to be wrong, especially on files fetched from the web
* this is very important as we might get quite a few images
* missing otherwise */
- g_file_get_contents (uri,
+ g_file_get_contents (duri ? duri:uri,
&contents,
&length,
NULL);
@@ -511,6 +534,8 @@ verify_image(gchar *uri, EMFormatHTML *format)
/*FIXME mime type here could be wrong */
if (g_ascii_strncasecmp (mime_type, "image/", 6)) {
result = g_filename_to_uri (pixfile, NULL, NULL);
+ if (duri)
+ g_free(duri);
return result;
}
g_free(mime_type);
@@ -521,7 +546,7 @@ verify_image(gchar *uri, EMFormatHTML *format)
* http://git.gnome.org/browse/evolution/commit/?id=d9deaf9bbc7fd9d0c72d5cf9b1981e3a56ed1162
*/
#if (EVOLUTION_VERSION >= 23000)
- return g_filename_to_uri(uri, NULL, NULL);
+ return g_filename_to_uri(duri?duri:uri, NULL, NULL);
#else
return NULL;
#endif
@@ -535,10 +560,16 @@ fetch_image_redraw(gchar *url, gchar *link, gpointer data)
GError *err = NULL;
gchar *tmpurl = NULL;
FEED_IMAGE *fi = NULL;
- gchar *result, *safe, *cache_file;
+ gchar *result, *cache_file;
+ gchar *intern, *burl;
+ gsize size;
g_return_val_if_fail(url != NULL, NULL);
+ if (strstr(url, "img:"))
+ tmpurl = g_base64_decode(url+4, &size);
+ else {
+
if (strstr(url, "://") == NULL) {
if (*url == '.') //test case when url begins with ".."
tmpurl = g_strconcat(
@@ -560,21 +591,23 @@ fetch_image_redraw(gchar *url, gchar *link, gpointer data)
if (!tmpurl)
return NULL;
+ }
- safe = g_compute_checksum_for_string (
- G_CHECKSUM_SHA1, tmpurl, -1);
+ intern = g_compute_checksum_for_string(G_CHECKSUM_SHA1,
+ tmpurl, -1);
if (g_hash_table_find(rf->key_session,
check_key_match,
tmpurl)) {
goto working;
}
- d("fetch_image_redraw() tmpurl:%s, safe url:%s\n", tmpurl, safe);
- cache_file = rss_cache_get_filename(safe);
+ d("fetch_image_redraw() tmpurl:%s, intern: %s\n",
+ tmpurl, intern);
+ cache_file = rss_cache_get_filename(intern);
if (!g_file_test (cache_file, G_FILE_TEST_EXISTS)) {
d("image cache MISS\n");
if (data) {
fi = g_new0(FEED_IMAGE, 1);
- fi->url = g_strdup(safe);
+ fi->url = g_strdup(intern);
fi->data = data;
fetch_unblocking(tmpurl,
textcb,
@@ -584,7 +617,7 @@ fetch_image_redraw(gchar *url, gchar *link, gpointer data)
1,
&err);
} else {
- CamelStream *stream = rss_cache_add(safe);
+ CamelStream *stream = rss_cache_add(intern);
fetch_unblocking(tmpurl,
textcb,
NULL,
@@ -603,9 +636,10 @@ fetch_image_redraw(gchar *url, gchar *link, gpointer data)
}
g_free(cache_file);
-working:result = rss_cache_get_path(FALSE, safe);
+working:burl = g_base64_encode(tmpurl, strlen(tmpurl));
+ result = g_strdup_printf("img:%s", burl);
+ g_free(burl);
error: g_free(tmpurl);
- g_free(safe);
return result;
}
diff --git a/src/rss.c b/src/rss.c
index ba1e511..66d6b74 100644
--- a/src/rss.c
+++ b/src/rss.c
@@ -1061,7 +1061,7 @@ rss_browser_update_content (
fi = g_new0(UB, 1);
stream = rss_cache_get(po->website);
if (!stream) {
- dp("HTTP cache miss\n");
+ d("HTTP cache miss\n");
stream = rss_cache_add(po->website);
fi->create = 1;
fi->stream = stream;
@@ -2463,7 +2463,6 @@ void org_gnome_cooly_folder_refresh(void *ep, EShellView *shell_view)
shell_view);
EActivity *taskid;
-
g_object_get (shell_sidebar, "folder-tree", &folder_tree, NULL);
folder = em_folder_tree_get_selected_folder (folder_tree);
g_return_if_fail (folder != NULL);
@@ -2771,6 +2770,27 @@ prepare_hashes(void)
g_str_equal,
g_free,
NULL);
+
+ if (!rf->activity) //keeping track of taskbar operations
+ rf->activity = g_hash_table_new_full(
+ g_str_hash,
+ g_str_equal,
+ NULL, NULL);
+ if (!rf->error_hash) //keeping trask of taskbar errors
+ rf->error_hash = g_hash_table_new_full(
+ g_str_hash,
+ g_str_equal,
+ g_free, NULL);
+
+ if (!rf->session)
+ rf->session = g_hash_table_new(
+ g_direct_hash, g_direct_equal);
+ if (!rf->abort_session)
+ rf->abort_session = g_hash_table_new(
+ g_direct_hash, g_direct_equal);
+ if (!rf->key_session)
+ rf->key_session = g_hash_table_new(
+ g_direct_hash, g_direct_equal);
}
void
@@ -3082,7 +3102,6 @@ setup_feed(add_feed *feed)
taskbar_op_message(tmsg, gen_md5(feed->feed_url));
check_folders();
- prepare_hashes();
rf->setup = 0;
rf->pending = TRUE;
@@ -4950,16 +4969,7 @@ e_plugin_lib_enable(EPlugin *ep, int enable)
/*D-BUS init*/
rf->bus = init_dbus ();
#endif
- if (!rf->activity) //keeping track of taskbar operations
- rf->activity = g_hash_table_new_full(
- g_str_hash,
- g_str_equal,
- NULL, NULL);
- if (!rf->error_hash) //keeping trask of taskbar errors
- rf->error_hash = g_hash_table_new_full(
- g_str_hash,
- g_str_equal,
- g_free, NULL);
+ prepare_hashes();
//there is no shutdown for e-plugin yet.
atexit(rss_finalize);
render = GPOINTER_TO_INT(
@@ -5766,9 +5776,9 @@ get_feed_age(RDF *r, gpointer name)
}
}
if (!match) {
- g_print("info\n");
+// g_print("info\n");
info = camel_folder_get_message_info(folder, uids->pdata[i]);
- g_print("info done\n");
+// g_print("info done\n");
flags = camel_message_info_flags(info);
if ((del_unread) && !(flags & CAMEL_MESSAGE_FLAGGED)) {
gchar *feed_dir, *feed_name;
@@ -5797,14 +5807,16 @@ get_feed_age(RDF *r, gpointer name)
}
if (del_feed == 2) {
guint del_days = GPOINTER_TO_INT(g_hash_table_lookup(rf->hrdel_days, key));
- g_print("feed ==2\n");
+ g_print("feed == 2\n");
uids = camel_folder_get_uids (folder);
camel_folder_freeze(folder);
for (i = 0; i < uids->len; i++) {
g_print("get info\n");
info = camel_folder_get_message_info(folder, uids->pdata[i]);
+ if (info == NULL)
+ continue;
g_print("got info\n");
- if (info && rf->current_uid && strcmp(rf->current_uid, uids->pdata[i])) {
+ if (rf->current_uid && strcmp(rf->current_uid, uids->pdata[i])) {
date = camel_message_info_date_sent(info);
if (date < now - del_days * 86400) {
flags = camel_message_info_flags(info);
@@ -5819,19 +5831,17 @@ get_feed_age(RDF *r, gpointer name)
camel_folder_delete_message(folder, uids->pdata[i]);
}
}
- camel_folder_free_message_info(folder, info);
}
+ camel_folder_free_message_info(folder, info);
}
camel_folder_free_uids (folder, uids);
camel_folder_sync (folder, TRUE, NULL);
camel_folder_thaw(folder);
camel_folder_expunge (folder, NULL);
- g_print("feed ==2 done\n");
}
if (del_feed == 1) {
guint del_messages = GPOINTER_TO_INT(g_hash_table_lookup(rf->hrdel_messages, key));
guint total = camel_folder_get_message_count(folder);
- g_print("del?\n");
i=1;
while (del_messages < camel_folder_get_message_count(folder)
- camel_folder_get_deleted_message_count(folder) && i <= total) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]