1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-09-28 03:06:20 -04: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:
Kalle Olavi Niemitalo 2009-07-19 03:24:55 +03:00 committed by Kalle Olavi Niemitalo
parent b7d03f9b04
commit 075171c2c8
2 changed files with 11 additions and 7 deletions

View File

@ -511,6 +511,9 @@ struct lun_hop {
struct cmdw_hop {
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
* downloaded. This is initially NULL, but its address is
* 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 cmdw_hop *cmdw_hop = data;
struct uri *download_uri = cmdw_hop->download_uri;
unsigned char *file = cmdw_hop->real_file;
struct session *ses = cmdw_hop->ses;
struct stat buf;
@ -993,7 +997,7 @@ common_download_do(struct terminal *term, int fd, void *data,
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 init_file_download succeeds, it takes ownership of file
* and fd. */
@ -1011,6 +1015,7 @@ common_download_do(struct terminal *term, int fd, void *data,
finish:
mem_free_if(file);
if (fd != -1) close(fd);
done_uri(download_uri);
}
/** 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));
if (!cmdw_hop) return;
cmdw_hop->ses = ses;
cmdw_hop->download_uri = ses->download_uri;
ses->download_uri = NULL;
kill_downloads_to_file(file);
@ -1087,10 +1094,7 @@ transform_codw_to_cmdw(struct terminal *term, int fd,
if (!cmdw_hop) return;
cmdw_hop->ses = type_query->ses;
/* FIXME: Current ses->download_uri is overwritten here --witekfl */
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->download_uri = get_uri_reference(type_query->uri);
cmdw_hop->real_file = codw_hop->real_file;
codw_hop->real_file = NULL;

View File

@ -159,8 +159,8 @@ struct session {
struct document_view *doc_view;
LIST_OF(struct document_view) scrn_frames;
/** The URI from which start_download() or resume_download()
* should download.
/** The URI from which the next start_download() or resume_download()
* call should download, or NULL if no such call is pending.
*
* When the user requests a download, one of those functions
* is given as a callback to query_file(), which asks the user