1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-11-04 08:17:17 -05:00

download: Add DOWNLOAD_EXTERNAL flag

Like in ELinks 0.13.GIT commit b3cfede1c1
made on 2007-11-07, only with more comments and a bit different names.
This commit is contained in:
Kalle Olavi Niemitalo 2009-07-24 18:09:59 +03:00 committed by Kalle Olavi Niemitalo
parent a2c8dc8c61
commit db128fecd9
3 changed files with 39 additions and 32 deletions

View File

@ -464,7 +464,9 @@ download_data(struct download *download, struct file_download *file_download)
* Comes directly from the @a data argument of lookup_unique_name().
*
* @param flags
* Whether the user chose to resume downloading an existing file.
* The same as the @a flags argument of create_download_file(),
* except the ::DOWNLOAD_RESUME_SELECTED bit will be changed to match
* what the user chose.
*
* @relates lun_hop */
typedef void lun_callback_T(struct terminal *term, unsigned char *file,
@ -496,10 +498,13 @@ struct lun_hop {
/** A pointer to be passed to #callback. */
void *data;
/** Whether the download can be resumed.
* The ::DOWNLOAD_RESUME_SELECTED bit should be clear
* because otherwise there would have been no reason to
* ask the user and initialize this structure. */
/** Saved flags to be passed to #callback.
* If the user chooses to resume, then lun_resume() sets
* ::DOWNLOAD_RESUME_SELECTED when it calls #callback.
*
* @invariant The ::DOWNLOAD_RESUME_SELECTED bit should be
* clear here because otherwise there would have been no
* reason to ask the user and initialize this structure. */
enum download_flags flags;
};
@ -543,11 +548,6 @@ struct cdf_hop {
* #callback does not care about the name. */
unsigned char **real_file;
/** If nonzero, give only the user herself access to the file
* (even if the umask is looser), and create the file with
* @c O_EXCL unless resuming. */
int safe;
/** This function will be called when the file has been opened,
* or when it is known that the file will not be opened. */
cdf_callback_T *callback;
@ -643,9 +643,13 @@ lun_resume(void *lun_hop_)
* lookup_unique_name() treats this original string as read-only.
*
* @param[in] flags
* Indicates if the user already chose to resume downloading,
* before ELinks even asked for the file name.
* See ::ACT_MAIN_LINK_DOWNLOAD_RESUME.
* Flags controlling how to download the file.
* ::DOWNLOAD_RESUME_ALLOWED adds a "Resume" button to the dialog.
* ::DOWNLOAD_RESUME_SELECTED means the user already chose to resume
* downloading (with ::ACT_MAIN_LINK_DOWNLOAD_RESUME), before ELinks
* even asked for the file name; thus don't ask whether to overwrite.
* Other flags, such as ::DOWNLOAD_EXTERNAL, have no effect at this
* level but they get passed to @a callback.
*
* @param callback
* Will be called when the user answers, or right away if the question
@ -765,7 +769,7 @@ create_download_file_do(struct terminal *term, unsigned char *file,
#ifdef NO_FILE_SECURITY
int sf = 0;
#else
int sf = cdf_hop->safe;
int sf = !!(flags & DOWNLOAD_EXTERNAL);
#endif
if (!file) goto finish;
@ -802,7 +806,7 @@ create_download_file_do(struct terminal *term, unsigned char *file,
} else {
set_bin(h);
if (!cdf_hop->safe) {
if (!(flags & DOWNLOAD_EXTERNAL)) {
unsigned char *download_dir = get_opt_str("document.download.directory");
int i;
@ -843,14 +847,14 @@ finish:
* file that was eventually opened. @a callback must then arrange for
* this string to be freed with mem_free().
*
* @param safe
* If nonzero, give only the user herself access to the file (even if
* the umask is looser), and create the file with @c O_EXCL unless
* resuming.
*
* @param flags
* Whether the download can be resumed, and whether the user already
* asked for it to be resumed.
* Flags controlling how to download the file.
* ::DOWNLOAD_RESUME_ALLOWED adds a "Resume" button to the dialog.
* ::DOWNLOAD_RESUME_SELECTED skips the dialog entirely.
* ::DOWNLOAD_EXTERNAL causes the file to be created with settings
* suitable for a temporary file: give only the user herself access to
* the file (even if the umask is looser), and create the file with
* @c O_EXCL unless resuming.
*
* @param callback
* This function will be called when the file has been opened,
@ -862,7 +866,7 @@ finish:
* @relates cdf_hop */
void
create_download_file(struct terminal *term, unsigned char *fi,
unsigned char **real_file, int safe,
unsigned char **real_file,
enum download_flags flags,
cdf_callback_T *callback, void *data)
{
@ -875,7 +879,6 @@ create_download_file(struct terminal *term, unsigned char *fi,
}
cdf_hop->real_file = real_file;
cdf_hop->safe = safe;
cdf_hop->callback = callback;
cdf_hop->data = data;
@ -1040,7 +1043,7 @@ common_download(struct session *ses, unsigned char *file,
kill_downloads_to_file(file);
create_download_file(ses->tab->term, file, &cmdw_hop->real_file, 0,
create_download_file(ses->tab->term, file, &cmdw_hop->real_file,
flags, common_download_do, cmdw_hop);
}
@ -1202,8 +1205,9 @@ continue_download(void *data, unsigned char *file)
create_download_file(type_query->ses->tab->term, file,
&codw_hop->real_file,
!!type_query->external_handler,
DOWNLOAD_RESUME_ALLOWED,
type_query->external_handler
? DOWNLOAD_RESUME_ALLOWED | DOWNLOAD_EXTERNAL
: DOWNLOAD_RESUME_ALLOWED,
continue_download_do, codw_hop);
}

View File

@ -20,7 +20,7 @@ struct download;
typedef void (download_callback_T)(struct download *, void *);
/** Whether to resume downloading to a file. This is a bit mask.
/** Flags controlling how to download a file. This is a bit mask.
* Unrecognized bits should be preserved and ignored. */
enum download_flags {
/** Downloading cannot be resumed; do not offer such an option
@ -31,8 +31,11 @@ enum download_flags {
DOWNLOAD_RESUME_ALLOWED = 1,
/** The user wants to resume downloading. This must not occur
* without DOWNLOAD_RESUME_ALLOWED. */
DOWNLOAD_RESUME_SELECTED = 2
* without #DOWNLOAD_RESUME_ALLOWED. */
DOWNLOAD_RESUME_SELECTED = 2,
/** The file will be opened in an external handler. */
DOWNLOAD_EXTERNAL = 4
};
struct download {
@ -188,7 +191,7 @@ typedef void cdf_callback_T(struct terminal *term, int fd,
void start_download(void *, unsigned char *);
void resume_download(void *, unsigned char *);
void create_download_file(struct terminal *, unsigned char *, unsigned char **,
int, enum download_flags, cdf_callback_T *, void *);
enum download_flags, cdf_callback_T *, void *);
void abort_all_downloads(void);
void destroy_downloads(struct session *);

View File

@ -1646,7 +1646,7 @@ save_formatted(void *data, unsigned char *file)
assert(doc_view && doc_view->document);
if_assert_failed return;
create_download_file(ses->tab->term, file, NULL, 0,
create_download_file(ses->tab->term, file, NULL,
DOWNLOAD_RESUME_DISABLED,
save_formatted_finish, doc_view->document);
}