diff options
author | Awal Garg <awalgarg@gmail.com> | 2020-03-30 13:14:18 +0530 |
---|---|---|
committer | Awal Garg <awalgarg@gmail.com> | 2020-03-30 13:14:18 +0530 |
commit | d2311c2332722ac0401e3441d9834c8b02491a82 (patch) | |
tree | 50f902c1b200b6d6552035b1df66eb3bb83d1e36 /src/imlib.c | |
parent | b89cf18dab68008de86d7461e800aae5e9d515b0 (diff) |
Enable re-using downloaded http cache
Diffstat (limited to 'src/imlib.c')
-rw-r--r-- | src/imlib.c | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/src/imlib.c b/src/imlib.c index b9f071a..1786876 100644 --- a/src/imlib.c +++ b/src/imlib.c @@ -258,10 +258,13 @@ int feh_load_image(Imlib_Image * im, feh_file * file) file->ed = exif_get_data(tmpname); #endif } - if ((image_source != SRC_HTTP) || !opt.keep_http) + if ((image_source != SRC_HTTP) || (!opt.keep_http && !opt.use_http_cache)) unlink(tmpname); + else if (opt.use_http_cache && !opt.keep_http) + add_file_to_rm_filelist(tmpname); - free(tmpname); + if (image_source != SRC_HTTP && !opt.use_http_cache) + free(tmpname); } if ((err) || (!im)) { @@ -542,6 +545,8 @@ static char *feh_magick_load_image(char *filename) #ifdef HAVE_LIBCURL +gib_hash* http_cache = NULL; + #if LIBCURL_VERSION_NUM >= 0x072000 /* 07.32.0 */ static int curl_quit_function(void *clientp, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow) #else @@ -576,6 +581,13 @@ static char *feh_http_load_image(char *url) char *basename; char *path = NULL; + if (opt.use_http_cache) { + if (!http_cache) + http_cache = gib_hash_new(); + if ((sfn = gib_hash_get(http_cache, url)) != NULL) + return sfn; + } + if (opt.keep_http) { if (opt.output_dir) path = opt.output_dir; @@ -648,6 +660,8 @@ static char *feh_http_load_image(char *url) free(ebuff); fclose(sfp); + if (opt.use_http_cache) + gib_hash_set(http_cache, url, sfn); return sfn; } else { weprintf("open url: fdopen failed:"); |