move-link-prev(next)-line: Typo with cut-n-paste. s/line/last/.
[elinks.git] / src / session / download.h
blob79923d2efbccb01e1a011ecdc0c33d9c1d0f59e1
1 #ifndef EL__SESSION_DOWNLOAD_H
2 #define EL__SESSION_DOWNLOAD_H
4 #include "main/object.h"
5 #include "network/state.h"
6 #include "util/lists.h"
7 #include "util/time.h"
9 /* Silly BFU stuff */
10 struct dialog_data;
11 struct listbox_item;
12 struct terminal;
14 struct cache_entry;
15 struct connection;
16 struct session;
17 struct uri;
19 struct download;
21 typedef void (download_callback_T)(struct download *, void *);
23 struct download {
24 /* XXX: order matters there, there's some hard initialization in
25 * src/session/session.c and src/viewer/text/view.c */
26 LIST_HEAD(struct download);
28 struct connection *conn;
29 struct cache_entry *cached;
30 /** The callback is called when connection gets into a progress state,
31 * after it's over (in a result state), and also periodically after
32 * the download starts receiving some data. */
33 download_callback_T *callback;
34 void *data;
35 struct progress *progress;
37 enum connection_state state;
38 enum connection_state prev_error;
39 enum connection_priority pri;
42 struct type_query {
43 LIST_HEAD(struct type_query);
44 struct download download;
45 struct cache_entry *cached;
46 struct session *ses;
47 struct uri *uri;
48 unsigned char *target_frame;
49 unsigned char *external_handler;
50 int block;
51 unsigned int copiousoutput:1;
52 /* int frame; */
55 struct file_download {
56 OBJECT_HEAD(struct file_download);
58 struct uri *uri;
59 unsigned char *file;
60 unsigned char *external_handler;
61 struct session *ses;
62 struct terminal *term;
63 time_t remotetime;
64 off_t seek;
65 int handle;
66 int redirect_cnt;
67 int notify;
68 struct download download;
70 /** Should the file be deleted when destroying the structure */
71 unsigned int delete:1;
73 /** Should the download be stopped/interrupted when destroying the structure */
74 unsigned int stop:1;
76 /** Whether to block the terminal when running the external handler. */
77 unsigned int block:1;
79 /** Whether copiousoutput mode is used by the mailcap entry */
80 unsigned int copiousoutput:1;
82 /** The current dialog for this download. Can be NULL. */
83 struct dialog_data *dlg_data;
84 struct listbox_item *box_item;
87 /** Stack of all running downloads */
88 extern LIST_OF(struct file_download) downloads;
90 static inline int
91 is_in_downloads_list(struct file_download *file_download)
93 struct file_download *down;
95 foreach (down, downloads)
96 if (file_download == down) return 1;
98 return 0;
101 int download_is_progressing(struct download *download);
103 int are_there_downloads(void);
105 void start_download(void *, unsigned char *);
106 void resume_download(void *, unsigned char *);
107 void create_download_file(struct terminal *, unsigned char *, unsigned char **,
108 int, int,
109 void (*)(struct terminal *, int, void *, int),
110 void *);
112 void abort_all_downloads(void);
113 void destroy_downloads(struct session *);
115 int setup_download_handler(struct session *, struct download *, struct cache_entry *, int);
117 void abort_download(struct file_download *file_download);
118 void done_type_query(struct type_query *type_query);
120 void tp_display(struct type_query *type_query);
121 void tp_save(struct type_query *type_query);
122 void tp_cancel(void *data);
123 struct file_download *init_file_download(struct uri *uri, struct session *ses, unsigned char *file, int fd);
125 #endif