GdkPixbuf *image = NULL;
FILE *file;
CURL *curl;
+ CURLcode res;
long filesize;
file = claws_fopen(filename, "wb");
curl = curl_easy_init();
if (curl == NULL) {
g_warning("could not initialize curl to get image from URL");
+ unlink(filename);
claws_fclose(file);
return NULL;
}
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
if (libravatarprefs.allow_redirects) {
- long maxredirs = (libravatarprefs.default_mode == DEF_MODE_URL)? 3L
- : ((libravatarprefs.default_mode == DEF_MODE_MM)? 2L: 1L);
+ long maxredirs = (libravatarprefs.default_mode == DEF_MODE_URL)
+ ? libravatarprefs.max_redirects_url
+ : ((libravatarprefs.default_mode == DEF_MODE_MM)
+ ? libravatarprefs.max_redirects_mm
+ : libravatarprefs.max_redirects_url);
+ debug_print("setting max redirects to %ld\n", maxredirs);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
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);
- curl_easy_perform(curl);
- filesize = ftell(file);
- claws_safe_fclose(file);
- if (filesize < MIN_PNG_SIZE)
- debug_print("not enough data for an avatar image: %ld bytes\n", filesize);
- else
- image = image_pixbuf_from_filename(filename);
-
- if (!libravatarprefs.cache_icons || filesize == 0) {
- if (g_unlink(filename) < 0)
- g_warning("failed to delete cache file '%s'", filename);
- }
-
- if (filesize == 0)
+ res = curl_easy_perform(curl);
+ if (res != CURLE_OK) {
+ 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) {
+ debug_print("not enough data for an avatar image: %ld bytes\n", filesize);
+ missing_add_md5(libravatarmisses, md5);
+ } else {
+ image = image_pixbuf_from_filename(filename);
+ }
+
+ if (!libravatarprefs.cache_icons || filesize < MIN_PNG_SIZE) {
+ if (g_unlink(filename) < 0)
+ g_warning("failed to delete cache file '%s'", filename);
+ }
+ }
curl_easy_cleanup(curl);