mirror of
https://github.com/rkd77/elinks.git
synced 2024-12-04 14:46:47 -05:00
Bug 770: Shorten lifetime of session.download_uri
In common_download(), move session.download_uri to the new member cmdw_hop.download_uri, which common_download_do() then reads. This shields the download request against possible session.download_uri changes made for other downloads. And transform_codw_to_cmdw() no longer needs to touch session.download_uri at all, solving a FIXME.
This commit is contained in:
parent
b7d03f9b04
commit
075171c2c8
@ -511,6 +511,9 @@ struct lun_hop {
|
|||||||
struct cmdw_hop {
|
struct cmdw_hop {
|
||||||
struct session *ses;
|
struct session *ses;
|
||||||
|
|
||||||
|
/** The URI from which the data will be downloaded. */
|
||||||
|
struct uri *download_uri;
|
||||||
|
|
||||||
/** The name of the local file to which the data will be
|
/** The name of the local file to which the data will be
|
||||||
* downloaded. This is initially NULL, but its address is
|
* downloaded. This is initially NULL, but its address is
|
||||||
* given to create_download_file(), which arranges for the
|
* given to create_download_file(), which arranges for the
|
||||||
@ -985,6 +988,7 @@ common_download_do(struct terminal *term, int fd, void *data,
|
|||||||
{
|
{
|
||||||
struct file_download *file_download;
|
struct file_download *file_download;
|
||||||
struct cmdw_hop *cmdw_hop = data;
|
struct cmdw_hop *cmdw_hop = data;
|
||||||
|
struct uri *download_uri = cmdw_hop->download_uri;
|
||||||
unsigned char *file = cmdw_hop->real_file;
|
unsigned char *file = cmdw_hop->real_file;
|
||||||
struct session *ses = cmdw_hop->ses;
|
struct session *ses = cmdw_hop->ses;
|
||||||
struct stat buf;
|
struct stat buf;
|
||||||
@ -993,7 +997,7 @@ common_download_do(struct terminal *term, int fd, void *data,
|
|||||||
|
|
||||||
if (!file || fstat(fd, &buf)) goto finish;
|
if (!file || fstat(fd, &buf)) goto finish;
|
||||||
|
|
||||||
file_download = init_file_download(ses->download_uri, ses, file, fd);
|
file_download = init_file_download(download_uri, ses, file, fd);
|
||||||
if (!file_download) goto finish;
|
if (!file_download) goto finish;
|
||||||
/* If init_file_download succeeds, it takes ownership of file
|
/* If init_file_download succeeds, it takes ownership of file
|
||||||
* and fd. */
|
* and fd. */
|
||||||
@ -1011,6 +1015,7 @@ common_download_do(struct terminal *term, int fd, void *data,
|
|||||||
finish:
|
finish:
|
||||||
mem_free_if(file);
|
mem_free_if(file);
|
||||||
if (fd != -1) close(fd);
|
if (fd != -1) close(fd);
|
||||||
|
done_uri(download_uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Begin or resume downloading from session.download_uri to the
|
/** Begin or resume downloading from session.download_uri to the
|
||||||
@ -1031,6 +1036,8 @@ common_download(struct session *ses, unsigned char *file,
|
|||||||
cmdw_hop = mem_calloc(1, sizeof(*cmdw_hop));
|
cmdw_hop = mem_calloc(1, sizeof(*cmdw_hop));
|
||||||
if (!cmdw_hop) return;
|
if (!cmdw_hop) return;
|
||||||
cmdw_hop->ses = ses;
|
cmdw_hop->ses = ses;
|
||||||
|
cmdw_hop->download_uri = ses->download_uri;
|
||||||
|
ses->download_uri = NULL;
|
||||||
|
|
||||||
kill_downloads_to_file(file);
|
kill_downloads_to_file(file);
|
||||||
|
|
||||||
@ -1087,10 +1094,7 @@ transform_codw_to_cmdw(struct terminal *term, int fd,
|
|||||||
if (!cmdw_hop) return;
|
if (!cmdw_hop) return;
|
||||||
|
|
||||||
cmdw_hop->ses = type_query->ses;
|
cmdw_hop->ses = type_query->ses;
|
||||||
/* FIXME: Current ses->download_uri is overwritten here --witekfl */
|
cmdw_hop->download_uri = get_uri_reference(type_query->uri);
|
||||||
if (cmdw_hop->ses->download_uri)
|
|
||||||
done_uri(cmdw_hop->ses->download_uri);
|
|
||||||
cmdw_hop->ses->download_uri = get_uri_reference(type_query->uri);
|
|
||||||
cmdw_hop->real_file = codw_hop->real_file;
|
cmdw_hop->real_file = codw_hop->real_file;
|
||||||
codw_hop->real_file = NULL;
|
codw_hop->real_file = NULL;
|
||||||
|
|
||||||
|
@ -159,8 +159,8 @@ struct session {
|
|||||||
struct document_view *doc_view;
|
struct document_view *doc_view;
|
||||||
LIST_OF(struct document_view) scrn_frames;
|
LIST_OF(struct document_view) scrn_frames;
|
||||||
|
|
||||||
/** The URI from which start_download() or resume_download()
|
/** The URI from which the next start_download() or resume_download()
|
||||||
* should download.
|
* call should download, or NULL if no such call is pending.
|
||||||
*
|
*
|
||||||
* When the user requests a download, one of those functions
|
* When the user requests a download, one of those functions
|
||||||
* is given as a callback to query_file(), which asks the user
|
* is given as a callback to query_file(), which asks the user
|
||||||
|
Loading…
Reference in New Issue
Block a user