commit 62ec17880c8103147869e46efc0c54f7197473aa
parent 460365d085aa234c13db292afb62f7267ef5265f
Author: Ricardo Mones <ricardo@mones.org>
Date: Fri, 21 Aug 2020 17:08:50 +0200
Restore behaviour of missing image mode "None"
Server defaults to a predefined image so it never "fails" unless
requested. That image is hiding failures and Face/X-Face default
handling was never triggered, so to avoid detecting such image (which
is prone to future error):
- Force a 404 error from server if not found
- Detect also HTTP errors on curl call
Also:
- Handle less-than-minimum files like errors and made it misses too
Diffstat:
2 files changed, 9 insertions(+), 8 deletions(-)
diff --git a/src/plugins/libravatar/libravatar.c b/src/plugins/libravatar/libravatar.c
@@ -208,7 +208,7 @@ static gchar *libravatar_url_for_md5(const gchar *base, const gchar *md5)
g_free(escaped);
return url;
} else if (libravatarprefs.default_mode == DEF_MODE_NONE) {
- return g_strdup_printf("%s/%s?s=%u",
+ return g_strdup_printf("%s/%s?s=%u&d=404",
base, md5, AVATAR_SIZE);
}
diff --git a/src/plugins/libravatar/libravatar_image.c b/src/plugins/libravatar/libravatar_image.c
@@ -110,27 +110,28 @@ static GdkPixbuf *pixbuf_from_url(const gchar *url, const gchar *md5, const gcha
curl_easy_setopt(curl, CURLOPT_MAXREDIRS, maxredirs);
}
curl_easy_setopt(curl, CURLOPT_FILE, file);
+ curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1L); /* fail on HTTP error */
debug_print("retrieving URL to file: %s -> %s\n", url, filename);
res = curl_easy_perform(curl);
if (res != CURLE_OK) {
- debug_print("curl_easy_perfom failed: %s", curl_easy_strerror(res));
+ debug_print("curl_easy_perfom failed: %s\n", curl_easy_strerror(res));
unlink(filename);
claws_fclose(file);
+ missing_add_md5(libravatarmisses, md5);
} else {
filesize = ftell(file);
claws_safe_fclose(file);
- if (filesize < MIN_PNG_SIZE)
+ if (filesize < MIN_PNG_SIZE) {
debug_print("not enough data for an avatar image: %ld bytes\n", filesize);
- else
+ missing_add_md5(libravatarmisses, md5);
+ } else {
image = image_pixbuf_from_filename(filename);
+ }
- if (!libravatarprefs.cache_icons || filesize == 0) {
+ if (!libravatarprefs.cache_icons || filesize < MIN_PNG_SIZE) {
if (g_unlink(filename) < 0)
g_warning("failed to delete cache file '%s'", filename);
}
-
- if (filesize == 0)
- missing_add_md5(libravatarmisses, md5);
}
curl_easy_cleanup(curl);